	// JavaScript Document
	
	//-------------------------------------
	function GetControlByName(controlName){
		totalForms = document.forms.length;
		for(i = 0 ; i < totalForms; i++)
		{
			control = eval("document.forms[" + i + "]." + controlName);
			if(control)
			{
				break;
			}
		}
		return control;
	}
	
	//-------------------------------------
	function GetControlsByMatchedName(matchedName){
		matchedControls = new Array();
		myForm = document.forms[0];
		totalControls = myForm.elements.length;
		counter = 0;
		for(i = 0; i < totalControls; i++){
			if(myForm.elements[i].name){
				if(myForm.elements[i].name.indexOf(matchedName) != -1){
					matchedControls[counter] = myForm.elements[i];
					counter++;
				}
			}
		}
		return matchedControls;
	}
	
	//------------------------------------
	function SetFocus(controlName) {
		control = GetControlByName(controlName);
		if(control.type){
			if(control.type == "text" || control.type == "password"){
				control.select();
				control.focus();
			}else{
				control.focus();
			}
		}
		else if(control.length)
		{
			control[0].focus();
		}
	}
	
	
	//------------------------------------
	function GetDropDownListValue(control){
		return control.options[control.selectedIndex].value;
	}
	
	//-----------------------------------
	function SetDropDownListValue(control, value){
		totalOptions = control.options.length;
		for(i = 0; i < totalOptions; i++){
			if(control.options[i].value == value){
				control.options.selectedIndex = i;
				return;
			}
		}
	}
	
	//--------------------------------
	function GetRadioButtonValue(control){
		totalOptions = control.length;
		for(i = 0; i < totalOptions; i++){
			if(control[i].checked){
				return control[i].value;
			}
		}
		return "";
	}
	
	//------------------------------
	function SetRadioButtonValue(control, value){
		totalOptions = control.length;
		for(i = 0; i < totalOptions; i++){
			if(control[i].value == value){
				control[i].checked = true;
				return;
			}
		}
	}
	
	
	//-----------------------------
	function SetCheckBoxValue(control, value)
	{
		control.checked = (control.value == value);
	}
	
	
	
//PUBLIC FUNCTIONS : -------------------------	
	
	//------------------------------------
	function GetValue(controlName){
		control = GetControlByName(controlName);
		if(control.type) {
			if(control.type == "text" || control.type == "password" || control.type == "hidden" || control.type == "textarea"){
				return control.value;
			}else if(control.type == "select-one"){
				return GetDropDownListValue(control);
			}else if(control.type == "radio"){
				return GetRadioButtonValue(control);
			}
		}
		if (control.length)
		{
			if(control.length > 0)
			{
				if (control[0].type == "radio")
				{
					return GetRadioButtonValue(control);
				}
			}
		}
	}
	
	
	//-------------------------------------
	function SetValue(controlName, value){
		control = GetControlByName(controlName);
		if(!control.length)
		{
			if(control.type){
				if(control.type == "text" || control.type == "password" || control.type == "hidden" || control.type == "textarea"){
					control.value = value;
				}else if(control.type == "select-one"){
					SetDropDownListValue(control,value);
				}else if(control.type == "radio"){
					SetRadioButtonValue(control,value);
				}else if(control.type == "checkbox"){
					SetCheckBoxValue(control,value);
				}
			}
		}
		else
		{
			if(control.length > 0)
			{
				if(control[0].type == "radio")
				{
					SetRadioButtonValue(control,value);
				}
				else if(control.type == "select-one")
				{
					SetDropDownListValue(control,value);
				}
			}
		}	
	}
	
	
	//------------------------------------
	function IsEmpty(controlName){
		if(GetValue(controlName) == ""){
			return true;
		}else{
			return false;
		}
	}
	
	
	//------------------------------------
	function IsNumber(ctlValue){
		number = "0123456789";
		ln = ctlValue.length;
		for(i = 0; i < ln; i++) {
			singleChar = ctlValue.charAt(i);
			pos = number.indexOf(singleChar);
			if(pos == -1){
				return false;
			}
		}
		return true;
	}
	
	
	//------------------------------------
	function IsNumeric(value) {
		return !isNaN(value);
	}
	
	//--------------------------------
	function CheckAll(matchName){
		controls = GetControlsByMatchedName(matchName);
		if(controls.length && controls.length > 0){
			totalControls = controls.length;
			for(i = 0;i < totalControls; i++){
				control = controls[i];
				if(control.type = "checkbox"){
					control.checked = true;
				}
			}
		}
	}
	
	//-------------------------------
	function UnCheckAll(matchName){
		controls = GetControlsByMatchedName(matchName);
		if(controls.length && controls.length > 0){
			totalControls = controls.length;
			for(i = 0;i < totalControls; i++){
				control = controls[i];
				if(control.type = "checkbox"){
					control.checked = false;
				}
			}
		}
	}
	
	//--------------------------------
	function IsAllChecked(matchName){
		controls = GetControlsByMatchedName(matchName);
		if(controls.length && controls.length > 0){
			totalControls = controls.length;
			for(i = 0;i < totalControls; i++){
				control = controls[i];
				if(control.type = "checkbox" && control.checked == false){
					return false;
				}
			}
		}
		return true;
	}
	
	//--------------------------------
	function ValidateEmptyValue(controlNameList, messageList){
		if(controlNameList.length){
			totalControls = controlNameList.length;
			for(i = 0;i < totalControls; i++){
				if(GetValue(controlNameList[i]) == ""){
					alert(messageList[i]);
					SetFocus(controlNameList[i]);
					return false;
				}
			}
		}else{
			if(GetValue(controlNameList) == ""){
				alert(messageList);
				SetFocus(controlNameList);
				return false;
			}
		}
		return true;
	}
	
	function ConfirmLogout()
	{
		return confirm("Are you sure that you want to logout?");
	}
	
	function ConfirmDelete(itemType)
	{
		return confirm("Are you sure that you want to delete this " + itemType + "?");
	}
	
	function IsDuplicateValue(firstControlName, secondControlName)
	{
		if(GetValue(firstControlName) == GetValue(secondControlName))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function IsValidEmail(str)
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true
	}
	
	function ValidateEmail(ctlName)
	{
		if(!IsValidEmail(GetValue(ctlName)))
		{
			alert("Enter valid email address");
			SetFocus(ctlName);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function ConfirmPassword(ctlPasswordName, ctlConfirmName)
	{
		if(!IsDuplicateValue(ctlPasswordName, ctlConfirmName))
		{
			alert("Please confirm your password again.");
			SetFocus(ctlConfirmName);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function TransferAllOptions(from, to, startFrom)
	{
		ctlFrom = GetControlByName(from)
		ctlTo = GetControlByName(to)
		
		totalFrom = ctlFrom.options.length
		totalTo = ctlTo.options.length
		for(i = startFrom; i < totalFrom; i++)
		{
			opt = new Option(ctlFrom.options[startFrom].text,ctlFrom.options[startFrom].value);
			ctlTo.options[totalTo+(i-startFrom)] = opt;
			ctlFrom.options[startFrom] = null
		}
	}
	
	function TransferSelectedOptions(from, to, startFrom)
	{
		ctlFrom = GetControlByName(from)
		ctlTo = GetControlByName(to)
		
		totalFrom = ctlFrom.options.length
		totalTo = ctlTo.options.length
		for(i = startFrom; i < ctlFrom.options.length; i++)
		{
			if (ctlFrom.options[i].selected)
			{
				opt = new Option(ctlFrom.options[i].text,ctlFrom.options[i].value);
				ctlTo.options[ctlTo.options.length] = opt;
				ctlFrom.options[i] = null
				i--;
			}
		}
	}
	
	function SelectAllOptions(ctlName, startFrom)
	{
		ctl = GetControlByName(ctlName)
		total = ctl.options.length
		for(i = startFrom; i < total; i++)
		{
			ctl.options[i].selected = true;
		}
		for(i = 0 ; i < startFrom; i++)
		{
			ctl.options[i].selected = false;
		}
	}
	
	function SelectMultipleOptions(ctlName, commaDelimatedValue)
	{
		valueArray = commaDelimatedValue.split(",")
		ctl = GetControlByName(ctlName)
		for(i = 0; i < valueArray.length; i++)
		{
			currentValue = valueArray[i];
			for(j = 0; j < ctl.options.length; j++)
			{
				if (ctl.options[j].value != "" && (ctl.options[j].value == currentValue.replace(" ","")))
				{
					ctl.options[j].selected = true;
				}	
			}
			
		}
	}
	
	function UnselectAllOptions(ctlName)
	{
		ctl = GetControlByName(ctlName);
		for(i = 0; i < ctl.options.length; i++)
		{
			ctl.options[i].selected = false;
		}
	}
	
	function GetCommaListFromOptions(ctlName, startFrom)
	{
		rslt = "";
		ctl = GetControlByName(ctlName);
		for(i = startFrom ; i < ctl.options.length; i++)
		{
			rslt += ctl.options[i].value + ",";
		}
		rslt = rslt.substring(0,rslt.length-1);
		return rslt;
	}
	
	function OpenWindow(pagePath)
	{
		wd = parseInt(screen.width/2);
		ht = parseInt(screen.height/2);
		l = parseInt((screen.width - wd)/2);
		t = parseInt((screen.height - ht)/2);
		win = window.open(pagePath,'','width=' + wd + ',height=' + ht + ',scrollbars=yes,resizable=yes');
		win.moveTo(l,t);
		return false;
	}
	
	function OpenDefaultWindow(pagePath)
	{
		win = window.open(pagePath,'','scrollbars=yes,resizable=yes');
		return false;
	}
	
	function GoUrl(url)
	{
		document.location = url
	}
	
	function SubmitForm()
	{
		ln = document.forms.length;
		document.forms[ln-1].submit();
	}
	
	function ResetForm()
	{
		ln = document.forms.length;
		document.forms[ln-1].reset();
		return false;
	}