﻿var ActiveMenu;
var ActiveLink;
var NoClose = true;
function openMenu(MenuName) {
	if (ActiveLink) {
		ActiveLink.attr('class', '');
	}
	if (ActiveMenu) {
		ActiveMenu.hide();
	}

	ActiveLink = $('#L_' + MenuName);
	ActiveMenu = $('#M_' + MenuName);
	ActiveLink.attr('class', 'LiActive');
	ActiveMenu.show();
}
function closeMenu() {
	if (ActiveMenu) {
		ActiveMenu.hide();
		ActiveLink.attr('class', '');
		NoClose = true;
	}
}
$(function () {
	$("div.SubMenu").mouseover(function () {
		NoClose = true;
	});
	$("div.SubMenu").mousemove(function () {
		NoClose = true;
	});
	$("div.SubMenu").mouseout(function () {
		NoClose = false;
	});
	$("#MainMenu li").mouseout(function () {
		NoClose = false;
	});
	$("#MainMenu li").mousemove(function () {
		NoClose = true;
	});
	$(document).mousemove(function () {
		if (!NoClose) {
			closeMenu();
		}
	});


	/*TABS*/
	$("#TabContainer li").click(function () {
		$("#TabContainer li").removeClass("Active");
		$(this).addClass("Active");
		var TabAction = $(this).attr("id");
		getTabData(TabAction);
		return false;
	});

});

function getTabData(tabAction) {
	var DataPath = '/' + tabAction.replace('_', 'UC/');
	$.ajax({
		url: DataPath,
		success: function (data) {
			$('#TabData').html(data);
		},
		error: function (errdata, errdata1, errdata2) {
			$('#TabData').html('ERRROR!!! ' + errdata + '<br>' + errdata1 + '<br>' + errdata2);
		}
	});
}

/*VALIDATION FUNCTIONS*/
var ValidationSummery = '';
var IsFormValid = true;
var ButtonKeys = { "EnterKey": 13 };

function CheckFormValidations(FormID) {
	IsFormValid = true;
	var ParentFormObject = $('#' + FormID);
	var AllChilds = ParentFormObject.find("input,select[a_validation$='Required'],textarea");
	for (var itemIndex = 0; itemIndex < AllChilds.length; itemIndex++) {
		var InputObj = $(AllChilds[itemIndex]);
		var TagName = InputObj.get(0).tagName;
		//$("#tmp1").html($("#tmp1").html() + TagName + "<br />");
		switch (TagName.toLowerCase()) {
			case 'input':
				if (InputObj.attr('type') == 'text' || InputObj.attr('type') == 'password') {
					CheckTextValidation(InputObj);
				}
				if (InputObj.attr('type') == 'checkbox') {
					CheckCheckBoxValidation(InputObj);
				}
				break;
			case 'textarea':
				CheckTextValidation(InputObj);
				break;
			case 'select':
				CheckDropDownValidation(InputObj);
				break;
		}
	}
}

function CheckValidations(ButtonName) {
	IsFormValid = true;
	var ParentFormObject = $('#' + ButtonName).parents('form');
	var AllChilds = ParentFormObject.find("input,select[a_validation$='Required'],textarea");
	for (var itemIndex = 0; itemIndex < AllChilds.length; itemIndex++) {
		var InputObj = $(AllChilds[itemIndex]);
		var TagName = InputObj.get(0).tagName;
		//$("#tmp1").html($("#tmp1").html() + TagName + "<br />");
		switch (TagName.toLowerCase()) {
			case 'input':
				if (InputObj.attr('type') == 'text' || InputObj.attr('type') == 'password') {
					CheckTextValidation(InputObj);
				}
				if (InputObj.attr('type') == 'checkbox') {
					CheckCheckBoxValidation(InputObj);
				}
				break;
			case 'textarea':
				CheckTextValidation(InputObj);
				break;
			case 'select':
				CheckDropDownValidation(InputObj);
				break;
		}
	}

}
function FormSubmit(ButtonName) {
	var ParentFormObject = $('#' + ButtonName).parents('form');
	if (IsFormValid) {
		ParentFormObject.submit();
	}

}

