var menuClassName = "";
function menu_Hover(item) {
  menuClassName = item.className;
  item.className += " ga-topnavhover"; 
}
function menu_Unhover(item) {
  item.className = menuClassName
}
/* String Functions */
function trim(value) {
	return value.replace(/^\s+|\s+$/g, "");
}
function findObj(id) {
  return document.getElementById(id);
}
function checkEnter(event, clientFunction) {
	if (event.keyCode == 13)
		clientFunction.apply(this);
	else
		return;
}
function isDigit(event) {
	if (!event) var event = window.event
	if (event.keyCode) code = event.keyCode;
	else if (event.which) code = event.which;
	
	if (((code < 48)||(code > 57 ))) 
		if (code != 46 && code != 37 && code != 39 && code != 8 && code != 9) 
			return false;
}
function setValue(id, value) {

	var ctrl = findObj(id);
	if (ctrl) {
		switch (ctrl.type) {
			case "select-multiple":
				setSelectMultipleValue(id, value);
				break;
			case "radio":
				setRadioValue(id, value);
				break;
			case "checkbox":
				setCheckBoxValue(id, value);
				break;
			case "password":
				break;
			default:
				ctrl.value = value.replace(/<br>/g, "\r\n");
				break;
		}
	}
	else {
		ctrl = findObj(id + "1");
		if (ctrl) {
			if (ctrl.type == "radio") 
				setRadioValue(id, value);
			else if (ctrl.type == "checkbox") 
				setCheckboxListValue(id, value);
		}
	}
}
function setSelectMultipleValue(id, value) {
	var value_array = value.split("|");
	var ctrl = findObj(id);
	for (var i = 0; i < ctrl.length; i++) {
		for (var j = 0; j < value_array.length; j++) {
			if (ctrl.options[i].value == value_array[j])
				ctrl.options[i].selected = true;
		}
	}		
}
function getRadioValue(id) {
	var ctrl = document.forms[0].elements[id];
	
	if(!ctrl) return "";
	var ctrlLength = ctrl.length;
	if (ctrlLength == undefined)
		if (ctrl.checked) return ctrl.value; else return "";
	for (var i = 0; i < ctrlLength; i++) {
		if(ctrl[i].checked) 
			return ctrl[i].value;
	}
	return "";
}
function setRadioValue(id, value) {
	var index = 1;
	var ctrl = findObj(id + index);
	while (ctrl) {
		if (ctrl.value == value) {
			ctrl.checked = true;
			break;
		}
		index++;
		ctrl = findObj(id + index);
	}
}
function setCheckBoxValue(id, value) {
	var ctrl = findObj(id);
	if (ctrl) { ctrl.checked = (value != ""); }
}
function setCheckboxListValue(id, value) {
	var arr_value = value.split("|");
	var index = 1;
	var ctrl = findObj(id + index);
	while (ctrl) {
		ctrl.checked = in_array(ctrl.value, arr_value);
		index++;
		ctrl = findObj(id + index);
	}
}
function setFocus(controlID) {
	window.setTimeout("findObj('" + controlID + "').focus()", 1); 
}
function validateLogin() {
	IsValid = true;
	if (IsValid)
		IsValid = RequiredField("LoginUserID", "Please enter User ID.");
	if (IsValid)
		IsValid = RequiredField("LoginPassword", "Please enter Password.");
	if (IsValid) {
		document.formLogin.action = "login_action.php";
		document.formLogin.submit();
	}
}
function logout() {
	document.location = "logout_action.php";
}
function in_array (needle, haystack, argStrict) {
   var key = '', strict = !!argStrict;
	 if (strict) {
		for (key in haystack) {
			if (haystack[key] === needle) {
				return true;
      }
		}
  } 
	else {
		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
	}
	return false;
}
 function textareaLimit(control, max_length) {
	// if (control.value.length > max_length + 1)
		// alert("Your input has been truncated!");
	if (control.value.length > max_length)
		control.value = control.value.substring(0, max_length);
	if (findObj(control.id + "Span")) {
		findObj(control.id + "Span").innerHTML = control.value.length + " characters";
	}
} 
function moveListItem(controlID, to) {
	var list = findObj(controlID);
	var index = list.selectedIndex;
	var total = list.options.length - 1;
	if (index == -1) {
		alert("Please select an item first.");
		list.focus();
		return false;
	}
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;
	
	var texts = new Array;
	var values = new Array;
	texts[0] = list.options[index].text;
	texts[1] = list.options[index + to].text;
	values[0] = list.options[index].value;
	values[1] = list.options[index + to].value;
	
	list.options[index + to] = new Option(texts[0],values[0], 0, 1);
	list.options[index] = new Option(texts[1], values[1]);

	list.focus();
}