
var AlphabeticFilter =/^[a-zA-Z\ ]*$/;
var AlphabeticSpacialFilter =/^[a-zA-Z\ \_\.\-\#\&\,\''\/]*$/;
var AlphaNumericFilter =/^[a-zA-Z0-9]*$/
var AlphaNumericSpacialFilter =/^[a-zA-Z0-9\ \_\.\-\#\&\,\''\/]*$/;
var NumericFilter =/^[0-9]*$/;
var FloatingNumberFilter =/^[0-9]*[.]*[0-9]*$/;
var NumericSpacialFilter =/^[0-9\ \_\.\-]*$/;
var NumericSpacialSlashFilter =/^[0-9\/]*$/;
var AlphaNumericSpaceFilter = /^[a-zA-Z0-9\ ]*$/;
var AlphabeticWithOutSpaceFilter = /^[a-zA-Z]*$/;
var AlphaNumericExeFilter = /^[a-zA-Z0-9\ \?\-\.]*$/;
var AddressFilter =/^[a-zA-Z0-9\ \_\.\-\#\&\,\''\@\(\)\/]*$/;
var SSNFilter = /^(\d{3})-?\d{2}-?\d{4}$/;
var EmailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var UserIdFilter = /^([a-zA-Z0-9_\.\-])+$/;
var DimensionFilter = /^([a-zA-Z0-9\ \-\*])+$/;
//var ZipFilter =/^[a-zA-Z0-9\ ]*$/;
var CategoryNameFilter = /^[a-zA-Z0-9\-\ ]*$/;
var ZipFilter =/^([0-9]{4})([\ ]{1})([a-zA-Z]{2})$/;
var ZeroFilter = /^[0]*$/;
var PhoneFilter =/^(\+|[0-9]{1})+([0-9\ \-]){6,15}$/;
var URLFilter = /^(www|WWW)(.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(COM|com|EDU|edu|GOV|gov|MIL|mil|NET|net|ORG|org|BIZ|biz|INFO|info|NAME|name|MUSEUM|museum|US|us|CA|ca|UK|uk|CO|co|nl|NL)+([\w\W])*$/;
var FullURLFilter = /^((HTTP|http|HTTPS|https|FTP|ftp)\:\/\/)+(www|WWW)(.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(COM|com|EDU|edu|GOV|gov|MIL|mil|NET|net|ORG|org|BIZ|biz|INFO|info|NAME|name|MUSEUM|museum|US|us|CA|ca|UK|uk|CO|co)+([\w\W])*$/;
var ColorCodeFilter =/^([\#]{1})([a-fA-F0-9]{6})$/;


function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}



function IntegerKeyPress(objInput)
{ 
	if((event.keyCode >= 48 && event.keyCode <=59) || (event.keyCode==45) || (event.keyCode==13))
		return true;
	else 
		return false;
}

// added: 21-01-2009 by Gert Timmerman (V12)

function isValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || 
      (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n)
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : MM/DD/YYYY")
		return false
	}
	if (strMonth.length<1 || month<0 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<0 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (year<0){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	/*if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}*/
	return true
}

function trim(strComp)
{
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}

function CheckFirstChar(strCheck)
{
	if(strCheck.value!="")
	{
		var Value = strCheck
		Value = Value.substring(0,1);
		if (!AlphaNumericFilter.test(Value))
			return false;
		return true;	
	}
	else
		return true;
}

/**********************************************************
* This function is used for opening new window
 **********************************************************/
function showPopupWindow(pageName, pageTitle, winHeight, winWidth)
{
	var winTopPos = eval(screen.height - winHeight) / 2;
	var winLeftPos = eval(screen.width - winWidth) / 2;

	return  window.open(pageName,"","top=" + winTopPos + ",left=" + winLeftPos + ",height=" + winHeight + ",width=" + winWidth + ",toolbar=none,scrollbars=1,resizable=1");
}
function showPopupWindowPDF(pageName, pageTitle, winHeight, winWidth)
{
	var winTopPos = 3;
	var winLeftPos = eval(screen.width - winWidth) / 2;

	return  window.open(pageName,"","top=" + winTopPos + ",left=" + winLeftPos + ",height=" + winHeight + ",width=" + winWidth + ",toolbar=none,scrollbars=1");
}

/**********************************************************
 * This function is used for opening new window
 **********************************************************/
function openPopWin(winURL, winWidth, winHeight, moveX, moveY, winFeatures,winName){
	var winDefaultFeatures;
	var popWin;
	if(openPopWin.arguments.length != 7)		
 		winName = "popUnder" + winCount++ //unique name for each pop-up window
	//winName = "popUnder"
	try{
 		if(moveX == '' || moveY=='')
 		{
 			moveX = (screen.width-winWidth)/2 ; 
 			moveY = (screen.height-winHeight)/2;
 		}
 	}catch(exc){
 		moveX = 0;
 		moveY = 0;
 	} 	
 	try
 	{
 		if(winWidth == '' || winHeight == '')
 		{
	 		winWidth = screen.width;
 			winHeight = screen.height;
 		}
 	}
 	catch(exc)
 	{
 		winWidth = screen.width;
 		winHeight = screen.height;
 	}
 	winDefaultFeatures ="width=" + winWidth + ",height=" + winHeight + ",Top=" + moveY + ",Left=" + moveX;
 	if (winFeatures.length>0) //any additional features? 
   		winFeatures =  winDefaultFeatures + "," + winFeatures ;
   	else
   		winFeatures = winDefaultFeatures;
 	// open the new browser window
 	if (openPopWin.arguments.length == 6) //any additional features? 
	 	popWin = window.open(winURL, winName,winFeatures,true)	
	else
		popWin = window.open(winURL,'1',winFeatures,true)	
	popWin.focus();	
	return(popWin);
}
/****************************************************************************************
 * This function is used trimming the input string.
 ****************************************************************************************/
 
function Trim(strInput)
{
	var ltrim = /^\s+/;
	var rtrim = /\s+$/;
	strInput = strInput.replace(ltrim,'');
	strInput = strInput.replace(rtrim,'');
	return strInput;
}

/****************************************************************************************
 * This function is used to enforce that atleast one checkbox should be checked in grid
 * when none of the checkboxes are selected in grid, it will return false
 ****************************************************************************************/
function validateGridSelection(oSource, oArgs)
{
	//var checkedFlag = false;
	oArgs.IsValid = false;
	var frm = document.forms[0];
	
	for(i=0; i<frm.elements.length; i++)
	{
		if(frm.elements[i].type == "checkbox")
		{
			if(frm.elements[i].checked == true)
			{
				//checkedFlag = true;
				//break;
				oArgs.IsValid = true;
				break;
			}
		}
	}
	return;
/*	if(!checkedFlag)
	{
		alert('Please select atleast one checkbox');
	}*/
}


function SelectedRecordCount()
{
	var count = 0;
	var frm = document.forms[0];
	
	for(i=0; i<frm.elements.length; i++)
	{
		if(frm.elements[i].type == "checkbox")
		{
			if(frm.elements[i].checked == true)
			{
				count++;
			}
		}
	}
	return count;
}

 /*********************************************************************************
 * Function Name	: setStatusScript
 * Parameters		: strStatusbarHeading - Left Heading of Status Bar
					  strNoOfPages - No of links to be displayed (Excluding sublinks)
					  strCurrentPage - Current Page No
					  strPageHeading - Right Heading of Status Bar
					  blnIsFrame - true: frame; false: no frame
					  strNoOfSubPages - No of sublinks to be displayed
 * Description		: Used to set status bar values
 * Revision History	: Initial Revision by Paras Shah on 20/jul/2004
					  Modified by Parthiv for adding strNoOfSubPages on 
 *********************************************************************************/
function setStatusScript(strStatusbarHeading, strNoOfPages, strCurrentPage, strPageHeading, blnIsFrame,strNoOfSubPages)
{
	try{
		if (blnIsFrame == 'true')
			parent.parent.setStatusData(strStatusbarHeading, strNoOfPages, strCurrentPage, strPageHeading, blnIsFrame,strNoOfSubPages);
		else
			parent.setStatusData(strStatusbarHeading, strNoOfPages, strCurrentPage, strPageHeading, blnIsFrame);
	}catch(Exc){
		//Do Nothing
	}	
}
/**********************************************************
 * This function is used to replace contents from the existing string.
 **********************************************************/
function Replace(strValue,strFind,strReplace){
	if(trim(strValue)=="") return strValue;
	if(strValue.indexOf(strFind)==-1) return strValue;
	var reg = new RegExp(strFind,"g");//g stands for Global replcement.i can be used for ignoring case.
	var strReturn;		
	try{
		strReturn = strValue;
		strReturn = strReturn.replace(reg,strReplace);
	}catch(exc){
		strReturn = strValue;
		alert("Unable to replace string '" + strFind + "' with '"+ strReplace +"' in\n" + strValue+"\n\nError Information: " + exc.name + " \nError Details: " + exc.message);
	}	
	return strReturn;		
}
/**********************************************************
 * This function is used for debugging purpose
 **********************************************************/
function displayProperties(obj) {
	var str = ""; 	var arrProp = new Array();
	var prop;
	var arrIndex = 0;

	if(typeof(obj) == "undefined"){
		alert('displayProperties: Parameter is not an object!');
		return false; 	
	}
	
	if(typeof(obj[0]) != "undefined") {
		for(prop = 0;prop < obj.length;prop++) {
			str += "\n" + prop + "=" + obj[prop];
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}else{
		for(prop in obj){
			str += "\n" + prop + "=" + eval("obj." + prop);
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}
	alert(arrProp.sort()); 
}

 /*********************************************************************************
 * Function Name	: showUploadProgress
 * Parameters		: -
 * Description		: Used to show upload progress bar
 * Revision History	: Initial Revision by Paras Shah on 06/sep/2004
 *********************************************************************************/
function showUploadProgress()
{
	if(Page_ClientValidate())
	{
		document.getElementById("lblMessage").style.display ='none';					
		document.getElementById("divUploadProgress").style.display = '';
		return true;
	}
	return false;	
}
 /*********************************************************************************
 * Function Name	: RedirectUser
 * Parameters		: -
 * Description		: Authorize Page Level Access
 * Revision History	: Initial Revision by Nimesh Dhruve on 04/Oct/2004
 *********************************************************************************/
function RedirectUser(){
	try{
		//alert('ok');
		var blnValidUser = false;	
		
		//Remove below 2 lines after implementing the security server side
		if(typeof(strAuthorizedUser) == 'undefined')
			blnValidUser = false;
			
		if(typeof(strAuthorizedUser)!='undefined' && strAuthorizedUser == true)
			blnValidUser = true;
		if(typeof(parent.strAuthorizedUser) !='undefined' && parent.strAuthorizedUser==true)
			blnValidUser = true;
		if(typeof(parent.parent.strAuthorizedUser) !='undefined' && parent.parent.strAuthorizedUser==true)
			blnValidUser = true;
		
		//alert(blnValidUser);
		if(!blnValidUser){			
			
		}
	}catch(Exc){
		alert("An error occured while validating user.\nAdditional Details: -\nFunction Name RedirectUser()\nError Message: " + Exc.message);
	}
}

 /*********************************************************************************
 * Function Name	: checkLength
 * Parameters		: oSrc - source control; donot pass; automatically passed by validator
						args - arguments passed by validator control
 * Description		: Custom JS function to check the length of characters in a control; returns false if control
						contains more characters, otherwise true.  Used when setting property ClientValidationFunction
						length 1000 hardcoded
 * Revision History	: Initial Revision by Murtaza Tinwala on 5-10-04
 *********************************************************************************/
function CheckLength(oSrc, args)
{	
	var ctrlObject = document.getElementById(oSrc.controltovalidate);
	try{
		args.IsValid = false;
		if(typeof(ctrlObject) != 'undefined'){ 
			var desclength = ctrlObject.innerText.length;
			//alert(oSrc.MaxLength);
			if(desclength<oSrc.MaxLength)
				args.IsValid = true;
			else
				args.IsValid = false;
		}
		else{
			alert("Unable to find control");
			args.IsValid = false;
			
		}
	}catch(Exc){
		alert(Exc.message);
	}
}
 /*********************************************************************************
 * Function Name	: GenerateThumbNail
 * Parameters		: strFrameId   - Id of the Iframe in which we want to load thumb nail image.
					  strImagePath - File Path. 
 * Revision History	: Initial Revision by Rizwan Mirza on 08-Oct-04
 *********************************************************************************/


function loadCal(){ 
//alert();
	  new Calendar(new Date());
	  if (browser.ns4){
	    if (typeof document.NSfix == 'undefined'){
		  document.NSfix = new Object();
	      document.NSfix.initWidth=window.innerWidth;
		  document.NSfix.initHeight=window.innerHeight;
		}
	  }
	}
	
//returns true if one checkbox is selected, otherwise false
function ValidateGridSelection()
{
	var frm = document.forms[0];
	
	for(i=0; i<frm.elements.length; i++)
	{
		if(frm.elements[i].type == "checkbox")
		{
			if(frm.elements[i].checked == true)
			{
				return true;
			}
		}
	}	
	
	return false;
	
}


/***** Date Validation function *****/
/* Checks if the date string is valid and returns null if not valid.
	If valid, converts it to the appropriate date object, and returns it */
function ValidateDate(dateString)
{
	var dateMatchExp = new RegExp("^(\\d{1,2})/(\\d{1,2})/(\\d{4})$");
	var match = dateMatchExp.exec(dateString);
	if (null == match) return null;	//Match failed, invalid date

	if (match[1] < 1 || match[1] > 12) return null;	//validate month
	if (match[2] < 1 || match[2] > 31) return null;	//validate day
	if (match[3] < 1) return null;	//validate year

	// valid day check
	if (match[1] == 2) 		// february check
	{
		if (match[2] > 29) return null;
		//Check for leap year.
		if (((match[3] % 100 == 0 || match[3] % 4 != 0) && (match[3] % 400 != 0))  // non-leap year checked
				&& match[2] > 28) return null;
	}
	else if ((match[1] == 4 || match[1] == 6 || match[1] == 9 || match[1] == 11) && (match[2] > 30))
		return null;

	return new Date(match[3], match[1]-1, match[2]);
}

function ValidateDate(dateString,monthPosition,yearPosition)
{
	var regExpressionString = "";
	var datePosition = 6 - parseInt(yearPosition) - parseInt(monthPosition);
		
	if ((monthPosition == 1 || monthPosition == 2) && yearPosition == 3)
	{
		regExpressionString = "^(\\d{1,2})/(\\d{1,2})/(\\d{4})$";
	}	
	if ((monthPosition == 3 || monthPosition == 2) && yearPosition == 1)
	{
		regExpressionString = "^(\\d{4})/(\\d{1,2})/(\\d{1,2})$";
	}
	if ((monthPosition == 3 || monthPosition == 1) && yearPosition == 2)
	{
		regExpressionString = "^(\\d{1,2})/(\\d{4})/(\\d{1,2})$";
	}
	
	var dateMatchExp = new RegExp(regExpressionString); // new RegExp("^(\\d{1,2})/(\\d{1,2})/(\\d{4})$");
	var match = dateMatchExp.exec(dateString);
	if (null == match) return null;	//Match failed, invalid date

	if (match[monthPosition] < 1 || match[monthPosition] > 12) return null;	//validate month
	if (match[datePosition] < 1 || match[datePosition] > 31) return null;	//validate day
	if (match[yearPosition] < 1) return null;	//validate year

	// valid day check
	if (match[monthPosition] == 2) 		// february check
	{
		if (match[datePosition] > 29) return null;
		//Check for leap year.
		if (((match[yearPosition] % 100 == 0 || match[yearPosition] % 4 != 0) && (match[yearPosition] % 400 != 0))  // non-leap year checked
				&& match[datePosition] > 28) return null;
	}
	else if ((match[monthPosition] == 4 || match[monthPosition] == 6 || match[monthPosition] == 9 || match[monthPosition] == 11) && (match[datePosition] > 30))
		return null;
	
	return new Date(match[yearPosition], match[monthPosition]-1, match[datePosition]);
}
/***** Date Validation function *****/


/**
 * This function validates the date in any format
 * @author Ishan
 * @param datestr String representing the Date to be checked
 * @param delim String representing the delimiter that separates, date, month and year
 * date string
 * @param dd Integer value (0 to 2) indicating the position of the date field in the date String
 * @param mm Integer value (0 to 2) indicating the position of the month field in the date String
 * @param yy Integer value (0 to 2) indicating the position of the year field in the date String
 * @return Returns the boolean value true if the date is valid, false otherwise
 */
function dateCheck(datestr,delim,dd,mm,yy)
{
	if(dd < 0 || dd > 2 || mm < 0 || mm > 2 || yy < 0 || yy > 2 || dd == mm || mm == yy || dd == yy) return false;
	datestr = datestr.trim();
	delim = delim.trim();
	if(datestr.length <= 0 || delim.length <= 0) return false;
	var dt = datestr.split(delim);
	if(dt.length != 3) return false;
	if(isNaN(dt[dd]) || isNaN(dt[mm]) || isNaN(dt[yy])) return false;
	if(Math.floor(dt[dd]) != Math.ceil(dt[dd]) || Math.floor(dt[mm]) != Math.ceil(dt[mm]) || Math.floor(dt[yy]) != Math.ceil(dt[yy])) return false;
	if(dt[mm] < 1 || dt[mm] > 12 || dt[dd] < 1 || dt[dd] > 31 || dt[yy] < 1) return false;

	if(dt[mm] == 2)
	{

		if(dt[dd] > 29) return false;
		//	Check for leap year.
		if(dt[yy] % 100 == 0 && dt[yy] % 400 != 0 && dt[dd] > 28) return false;
		if(dt[yy] % 4 != 0 && dt[dd] > 28) return false;
	}

	if((dt[mm] == 4 || dt[mm] == 6 || dt[mm] == 9 || dt[mm] == 11) && dt[dd] > 30) return false;
	return true;
}

/**
 * This function validates the date in dd/mm/yyyy format
 * @author Ishan
 * @param datestr String representing the Date to be checked
 * @return Returns the boolean value true if the date is valid, false otherwise
 */
function dateCheckMain(datestr)
{
	return dateCheck(datestr,"-",2,1,0);
}

/****************************
Function to check validity of any key press for float value according to specified locale
The function supports only two locales at present; (1)Dutch (2)Non-dutch
For dutch culture, it will allow number in the format 1222,45
For other cultures, it will allow number in the format 1222.45
The function assumes the culture code to be present in "hdnCultureCode" variable
*****************************/
function FloatKeyPress(objInput)
{ 
	var strCultureCode = document.getElementById("hdnCultureCode").value;
	var iDotCode ;
	
	if(strCultureCode.toLowerCase() == "nl-NL".toLowerCase())
		iDotCode = 44;//non-dutch decimal point
	else
		iDotCode = 46;//dutch decimal point
	
	if((event.keyCode >= 48 && event.keyCode <=59) || 
		(event.keyCode==13) || (event.keyCode==iDotCode) )
		return true;
	else 
		return false;
}

function IntegerKeyPress(objInput)
{ 
	if((event.keyCode >= 48 && event.keyCode <=59) || (event.keyCode==13))
		return true;
	else 
		return false;
}

function DateKeyPress(objInput)
{ 
	if((event.keyCode >= 48 && event.keyCode <=59) || (event.keyCode==45) || (event.keyCode==13))
		return true;
	else 
		return false;
}

function CurrencyKeyPress(objInput)
{ 
	var iCommaCode = 44;
	var iDotCode = 46;
	if((event.keyCode >= 48 && event.keyCode <=59) || 
		(event.keyCode==13) || (event.keyCode==iCommaCode) || (event.keyCode==iDotCode) )
		return true;
	else 
		return false;
}

function ClearControls()
{
	//var checkedFlag = false;
	var frm = document.forms[0];
	for(i=0; i<frm.elements.length; i++)
	{
		if(frm.elements[i].type == "text")
		{
			frm.elements[i].value = "";
		}
	}
	return;
	
}

function EnterZero(ctrl)
{
	if(ctrl.value == "")
		ctrl.value = "0";
}

/****************************
Function to check validity of currency according to specified locale
The function supports only two locales at present; (1)Dutch (2)Non-dutch
For dutch culture, it will allow currency in the format 1.222.333.44,45
For other cultures, it will allow currency in the format 1,222,333,44.45
The function assumes the culture code to be present in "hdnCultureCode" variable
*****************************/
function ValidateLocalizedCurrency(src, arg)
{
	/*
	^\d+ = The number must start with 1 or more digit
	(\,\d{3})* = followed by optional groups of (single comma and 3 digits)
	(\.\d{2})*$ = It must end with optional one group of (single dot and 2 digits)
	*/
	var strCultureCode = document.getElementById("hdnCultureCode").value;
	var regExp ;
	
	if(strCultureCode.toLowerCase() == "nl-NL".toLowerCase())
		regExp = new RegExp('^\\d+(\\.\\d{3})*(\\,\\d{0,2})?$');
	else
		regExp = new RegExp('^\\d+(\\,\\d{3})*(\\.\\d{0,2})?$');
	
	arg.IsValid = regExp.test(arg.Value);
}

/****************************
Function to check validity of any numeric value according to specified locale
The function supports only two locales at present; (1)Dutch (2)Non-dutch
For dutch culture, it will allow number in the format 1222,45
For other cultures, it will allow number in the format 1222.45
The function assumes the culture code to be present in "hdnCultureCode" variable
*****************************/
function ValidateLocalizedNumber(src, arg)
{
	/*
	^\d+ = The number must start with 1 or more digit
	(\,\d{3})* = followed by optional groups of (single comma and 3 digits)
	(\.\d{2})*$ = It must end with optional one group of (single dot and 2 digits)
	*/
	var strCultureCode = document.getElementById("hdnCultureCode").value;
	var regExp ;
	
	if(strCultureCode.toLowerCase() == "nl-NL".toLowerCase())
		regExp = new RegExp('^\\d+(\\,\\d{0,2})?$');
	else
		regExp = new RegExp('^\\d+(\\.\\d{0,2})?$');
		
	arg.IsValid = regExp.test(arg.Value);
}

/****************************
Function to convert any localized numeric value to pure number
The function supports only two locales at present; (1)Dutch (2)Non-dutch
*****************************/
function GetPureNumber(localizedNumber, cultureCode)
{
	if(cultureCode.toLowerCase() == "nl-NL".toLowerCase())
	{
		localizedNumber		=	localizedNumber.replace(".", "").replace(".", "").replace(".", "").replace(".", "").replace(".", "");//remove dot
		localizedNumber		=	localizedNumber.replace(",", ".");//convert comma to dot
	}
	else
		localizedNumber		=	localizedNumber.replace(",", "").replace(",", "").replace(",", "").replace(",", "").replace(",", "");//remove comma
	
	return localizedNumber;
}

/****************************
Function to convert any pure number value to localized numeric 
The function supports only two locales at present; (1)Dutch (2)Non-dutch
*****************************/
function GetPureNumberReverse(localizedNumber, cultureCode)
{
	if(cultureCode.toLowerCase() == "nl-NL".toLowerCase())
	{
	    localizedNumber		=	localizedNumber.replace(".", ",").replace(".", ",").replace(".", ",").replace(".", ",").replace(".", ",");//remove dot
	}
//	else
//	{
////	    localizedNumber		=	localizedNumber.replace(".", ",").replace(".", ",").replace(".", ",").replace(".", ",").replace(".", ",");//remove dot
//		//localizedNumber		=	localizedNumber.replace(",", ".");//convert comma to dot
//	}		
	
	return localizedNumber;
}

function GetLocalizedNumber(purenumber, culturecode)
{
	var iPos = 0;
	var strWholeNumber = "";
	var strWholeNumber2 = "";
	var strLocalizedNumber = "";
	var decimalchar = '.';
	var seperatorchar = ',';
	
	strWholeNumber = purenumber.split('.');
	strWholeNumber2 = strWholeNumber[0];
	
	if (culturecode.toLowerCase() == "nl-NL".toLowerCase())
	{
		decimalchar = ',';
		seperatorchar = '.';
	}	
	var cnt = 0;
	for (i=strWholeNumber2.length-1;i>=0;i--)
	{
		cnt++;
		if((cnt-1)%3 == 0)
		{
			if((cnt-1) == 0)
				strLocalizedNumber = strWholeNumber2.charAt(i) + strLocalizedNumber;
			else
				strLocalizedNumber = strWholeNumber2.charAt(i) + seperatorchar + strLocalizedNumber;
		}
		else
		{
			strLocalizedNumber = strWholeNumber2.charAt(i) + strLocalizedNumber;
		}
	}
	
	return strLocalizedNumber+decimalchar+strWholeNumber[1];
}

function getkey(e,ctrl)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}
function FormatRegistrationID(e,ctrl)
{
	var key, keychar;
	key = getkey(e,ctrl);
	if (key == null) return true;
	if (key == 13) return true;
	//if(ctrl.value.length>13)
	//	return false;
	if((key>=48 && key<=57) || (key>=65 && key<=70) || (key>=97 && key<=102))
	{
	 	if(ctrl.value.length==8)
	 		ctrl.value = ctrl.value + '-';
	 	else if(ctrl.value.length==13)
	 		ctrl.value = ctrl.value + '-';
	 	return true;
	}
 	else
 		return false;	
}
function FormatZipCode(e,ctrl)
{
	var key, keychar;
	key = getkey(e,ctrl);
	if (key == null) return true;
	if (key == 13) return true;
	if(ctrl.value.length<4)
	{
		if((key>=48 && key<=57))
	 		return true;
 		else
 			return false;	
	}
 	else
 	{
		if((key>=65 && key<=90) || (key>=97 && key<=122))
		{
	 		if(ctrl.value.length==4)
	 			ctrl.value = ctrl.value + ' ';
	 		return true;
	 	}
		else if(key==32)
		{
			if(ctrl.value.length==4)
				return true;
 			else
 				return false;	
 		}
 		else
 			return false;	
 	}
}
/*
function FormatRegistrationID(ctrl)
{
	SaveCursorPosition(ctrl);//save cursor position
	var CursorPos = GetCursorPosition(ctrl);
	
	var key = event.keyCode;//which key was pressed?
	if(key == 37 || key == 39 || key == 8 || key == 36 || key == 35 || key == 46)//leave control keys
		return;
	
	//do all necessary formatting
	var RegId = ctrl.value;
	var regExp = new RegExp("^([A-Fa-f0-9]{8}){1}-{0,1}([A-Fa-f0-9]{4}){1}-{0,1}([A-Fa-f0-9]{4})*-{0,1}?$");
	if(RegId.charAt(RegId.length-1) != "-")//if last character is not "-"
		ctrl.value = RegId.replace(regExp, "$&-");
	//do all necessary formatting
	
	if(ctrl.value.charAt(CursorPos) == "-")//if char next to cursor is -, then put cursor after it
		CursorPos++;
	MoveCursor(ctrl, CursorPos);
	
}
*/
/********************************

SaveCursorPosition(elem)
elem - the control whose cursor position is to be saved

The function to save the current cursor position.
It saves the cursor position in a property named caretPos
To save cursor position, this function must be called on the following three
events: onkeyup, onselect, onclick

Remove maxlength property before using this function
********************************/
function SaveCursorPosition(elem)
{
  //isTextEdit property indicates whether a TextRange object can be created for an element
  if ( elem.isTextEdit ) 
  {
	
	elem.caretPos = document.selection.createRange();//save the TextRange object in expando type property
	}

}


/***********************************
GetCursorPosition(elem)
elem - the control whose cursor position is sought

This function must be used in combination with SaveCursorPosition() given above, otherwise it would not work.  
The current cursor position must be saved.  The function returns the position of cursor in the given control using
caretPos property which is set by SaveCursorPosition() function.  

Remove maxlength property before using this function
***********************************/
function GetCursorPosition(elem)
{
  if ( elem.isTextEdit && elem.caretPos )
  {
    //alert("getting pos");
    var bookmark = "~";
    var orig = elem.value;
    var caretPos = elem.caretPos;
    caretPos.text = bookmark;
    var i = elem.value.search( bookmark );
    //window.status = "Caret is at character " + i;
    elem.value = orig;//cursor will lose its position here
    MoveCursor(elem, i);//so reset it
    return i;
  }
}

/*******************************************************
MoveCursor(ctrl, cursorPosition)
ctrl - the control in which cursor is to be moved
cursorPosition - the new cursor position

The function moves cursor in the given control

Remove maxlength property before using this function
********************************************************/

function MoveCursor(ctrl, cursorPosition)
{
	//creates a TextRange over the whole input
	var objRange=ctrl.createTextRange ();

	//collapse it an move the insertion point to the beginning
	objRange.collapse (true);

	//moves the insertion point by the given range
	objRange.move("character",cursorPosition);

	//makes the insertion point become the active selection. so it's the cursor.
	objRange.select ();
	
	ctrl.focus();
}


/* Function for specifying maximum length the textarea*/
function textAreaLimit(element,maxLength) 
{
	field = element;
	var str = new String(field.value);
	maxlen=parseInt(maxLength);
	if (str.length > maxlen)
	{
		field.value = str.substr(0, maxlen);
	}
}

function ConfirmAndGoToPage(msg, pageToGo, flagAsk)
{
	if(flagAsk)
	{
		if(confirm(msg))
			window.location = pageToGo;
	}
	else
		window.location = pageToGo;
}

function ShowAlert(pageToGo,msg)
{
	alert(msg);
	window.location = pageToGo;
}

/**/


function MaxLength(ctrl, len)
{
	if(ctrl.value.length > len)
		return false;
	else
		return true;	
}

function ValidateNumericPrice(Value)
{		
	var strCultureCode = document.getElementById("hdnCultureCode").value;
	var dMaxLimit = '999999.99';
	var regExp ;
	
	if(parseFloat((GetPureNumber(Value, strCultureCode) * 1)) > parseFloat(dMaxLimit))
		return false;
	else
		return true;
}

function ValidateName(src, arg)
{
	var regExp ;
	
	regExp = new RegExp('^[a-zA-Z\ ]*$');
	
	arg.IsValid = regExp.test(arg.Value);
}