function trim(str) 
{ 
    return str.replace(/^\s+|\s+$/g,''); 
}

function SetFocus(element)
{
	document.getElementById(element).focus();
}

//Level indepenncy
function levelInDep(le,en)
{
	var res = eval('document.'+le.name+'.'+en.name);
	//var res = eval('document.getElementById('+en.name+')');
	return res;	
}

//Level indepenncy
function levelInDep1(le,en)
{
	var res = eval('document.'+le.name+'.'+'mulUserType');
	//var res = eval('document.getElementById("mulUserType")');
	return res;	
}


// Check whether atleast one radio button is checked or not
function SelectRadioBotton(frm,ctrl,msg)
{
	radioCount =ctrl.length;
	for(loopCount = 0; loopCount < radioCount; loopCount++)
	{
		if(ctrl[loopCount].checked)	
		{
			return true;
		}
	}
	ctrl[0].focus();
	alert(msg);
	return false;
}

// Check whether atleast one radio button is checked or not
function SelectMultiCheckBox(frm,ctrl,msg)
{
	chkBxCount =ctrl.length;
	for(loopCount = 0; loopCount < chkBxCount; loopCount++)
	{
		if(ctrl[loopCount].checked)	
		{
			return true;
		}
	}
	ctrl[0].focus();
	alert(msg);
	return false;
}

function SelectCheckBox(frm,ctrl,msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (checked==false || checked=="")
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}







// Check whether the value of an object is empty/null 
function isNotEmpty(frm,ctrl,msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value==null || trim(value)=="")
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the value of an object is numeric
function isNumeric(frm,ctrl,msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (isNaN(value) == true)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the value of an object is numeric
function isOfExactLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length < num || value.length > num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// Check whether the value of an object is numeric
function isOfMinLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length < num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// Check whether the value of an object is numeric
function isOfMaxLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length > num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// Check whether the value of either of the two control blank or not
function isAtleastOneNotEmpty(frm,ctrl1,ctrl2,msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj1)
	{
		if (value=="" && obj2.value=="")
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the value of two control equals or not
function isNotEqual(frm,ctrl1,ctrl2,msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj2)
	{
		if (value!=obj1.value)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether an Email address is valid
function isValidEmail(frm,ctrl,msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		// this regular expression borrowed from jQuery form validation =========================================
		var regexp =  /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;  
		
		if (regexp.test(trim(value)) != true)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the something is selected in the list or not
function isSingleSel(level,entered, alertbox) 
{ 
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (selectedIndex != 0)
		{
			return true;
		}
		else 
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
	}
} 

// Check whether the something is selected in the multi select list or not
function isMultipleSel(level,entered, alertbox) 
{ 
	var obj = levelInDep1(level,entered);
	with (obj)
	{
		if (selectedIndex != 0)
		{
			return true;
		}
		else 
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
	}
} 
function isValidURL(frm,ctrl,msg)
    { 
 		var obj = levelInDep(frm,ctrl);
		with (obj)
		{
			// this regular expression borrowed from jQuery form validation =========================================
 			var regexp =  /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
			if (regexp.test(trim(value)) != true)
			{
				if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
				focus();
				return false;
			}
		return true;
		}
   }


