var g_InvalidValueMsgHead = "Please check the following errors:";
/*
objArray Format => Array where i-th element is
		[i] = Array with format
				[0] => 	R|C|G|D
						R - Required field validation
						C - Compare two textbox values
						G - Regular Expression validations
						D - Date Validations / Accepts 3 select boxes in order YY, MM, DD and validates date
							[1] => Year select box
							[2] => Month select box
							[3] => Day select box
							[4] => true/false - check for mandatory
							[5] => Display Name
				[1] => 	Control to check
				[2] =>	Control display name for R
						2nd Control to compare with for C
						Regex expression or Constant for G
				[3] =>	Error Message for C
						Control display name for G
*/
//var g_rgx_Email = /^[a-z][a-z_0-9\.]+@[a-z_0-9\.]+\.[a-z]{2,4}$/i;
//var g_rgx_Email = /^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/i;
var g_rgx_Email = /^[a-zA-Z_]+(\w+)*((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/i;
var g_rgx_Phone = /^(\(\d{3}\))(\s)*(\d{3})-(\d{4})$/;
var g_rgx_SSNNo = /^\d{3}-\d{2}-\d{4}$/i;
var g_rgx_Currency = /^\d{1,3}(,?\d{3})*(\.\d{1,2})?$/;
var g_rgx_Url = /^(\w+):\/\/([\w.]+\/?)\S*(\w+) $/; ///^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|){1}([\w]+)(.[\w]+){1,2}$/;
///^(?\w+):\/\/(?[\w.]+\/?)\S*(?x) $/;
var g_rgx_CurrencyNum = /^.,0123456789$/;
var g_rgx_WholeNumber = /^0123456789$/;


function valdFlds(objArray, errMsg)
{
	var focusObj = null;
	var errIndex = -1;
	for (var i=0; i<objArray.length; i++)
	{
		var obj = objArray[i];
		var msg = null;
		if ('R' == obj[0])
		{
			if ('undefined' != typeof(obj[1].value))
			{
				if (0 >= obj[1].value.trim().length)
				{
					msg = "\r\n- " + obj[2] + " cannot be empty";
				}
			}
		}
		else if ('C' == obj[0])
		{
			if ((typeof(obj[1].value) != 'undefined') && (typeof(obj[2].value) != 'undefined'))
			{
				if (0 < obj[1].value.length || 0 < obj[2].value.length)
				{
					if (obj[1].value != obj[2].value)
					{
						msg = "\r\n- " + obj[3];
					}
				}
			}
		}
		else if ('G' == obj[0])
		{
			if (typeof(obj[1].value) != 'undefined')
			{
				if (0 < obj[1].value.length)
				{
					if (!obj[2].test(obj[1].value))
					{
						msg = "\r\n- " + "Invalid value for " + obj[3];
					}

				}
			}
		}
		else if ('D' == obj[0])
		{
			if (obj[1].options && obj[2].options && obj[3].options)
			{
				if (obj[1].options[obj[1].selectedIndex].value == '' &&
					obj[2].options[obj[2].selectedIndex].value == '' &&
					obj[3].options[obj[3].selectedIndex].value == '')
				{
					if (obj[4])	//Mandatory field
					{
						msg = "\r\n- " + obj[5] + " cannot be empty";
					}
				}
				else
				{
					var dtString =
						obj[1].options[obj[1].selectedIndex].value + "-" +
						obj[2].options[obj[2].selectedIndex].value + "-" +
						obj[3].options[obj[3].selectedIndex].value;

					if (!valdDate(dtString))
					{
						msg = "\r\n- " + "Invalid date entered for " + obj[5];
					}
				}
			}
		}

		if (null != msg)
		{
			if (null == focusObj)
			{
				focusObj = obj[1];
				errIndex = i;
			}
			if (null == errMsg)
				errMsg = g_InvalidValueMsgHead
			errMsg += msg;
		}
	}

	var status = true;
	if (null != focusObj)
	{
		status = false;
		focusObj.focus();
	}
	return Array(status, errIndex, errMsg, focusObj);
}

function GetDateFromString(dateString)
{
	var dateMatchExp = new RegExp("^(\\d{4})-(\\d{1,2})-(\\d{1,2})$");
	var match = dateMatchExp.exec(dateString);
	if (null == match) return null;	//Match failed, invalid date

	if (match[2] < 1 || match[2] > 12) return null;	//validate month
	if (match[3] < 1 || match[3] > 31) return null;	//validate day
	if (match[1] < 1) return null;	//validate year

	// valid day check
	if (match[2] == 2) 		// february check
	{
		if (match[3] > 29) return null;
		//Check for leap year.
		if (((match[1] % 100 == 0 || match[1] % 4 != 0) && (match[1] % 400 != 0))  // non-leap year checked
				&& match[3] > 28) return null;
	}
	else if ((match[2] == 4 || match[2] == 6 || match[2] == 9 || match[2] == 11) && (match[3] > 30))
		return null;

	return new Date(match[1], match[2]-1, match[3]);
}

function valdDate(dateString)
{
	var dateMatchExp = new RegExp("^(\\d{1,2})/(\\d{1,2})/(\\d{4})$");
	var match = dateMatchExp.exec(dateString);

	if (null == match) return false;	//Match failed, invalid date

	if (match[1] < 1 || match[1] > 12) return false;	//validate month
	if (match[2] < 1 || match[2] > 31) return false;	//validate day
	if (match[3] < 1) return false;	//validate year

	// valid day check
	if (match[1] == 2) 		// february check
	{
		if (match[2] > 29) return false;
		//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 false;
	}
	else if ((match[1] == 4 || match[1] == 6 || match[1] == 9 || match[1] == 11) && (match[2] > 30))
		return false;

	return true;
}

function ConfirmDeleteOp(displayEntity)
{
	var result = confirm('WARNING:\r\nThe ' + displayEntity + ' will be deleted permanently, do you want to continue?');
	if (!result)
	{
		event.returnValue = false;
		return false;
	}
	else return true;
}

function ValidateWebsite(websiteAddr)
{
	//regex = "(http|ftp|https)://([\w-]+\.)+(/[\w- ./?%&=]*)?"
	//regex = "(http://|)+([\w-]+\.)+[\w-]+(/[ ./?%&=\w-]*)?";
	//regex = "^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$";
	//regex = "^((ht|f)tp(s?)\:\/\/)?[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$"
	regex = "^((ht|f)tp(s?)\:\/\/)?[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z\/])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\?\,\'\/\\\+&amp;%\$#_=]*)?$"

	
	
	var webSiteExp = new RegExp(regex);
	if (websiteAddr.match(webSiteExp))
		return true;
	else
		return false;
	
	
}

//Standard Rules
var g_ruleUserName = ".0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
var g_ruleName = ".0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ_-abcdefghijklmnopqrstuvwxyz',";
var g_ruleZip = "0123456789- ";
var g_rulePhone = "0123456789- ()";
var g_rulePhoneNew = "0123456789- ()";
var g_ruleNumber = "0123456789";
var g_ruleFormatedNumber = ",0123456789";
var g_ruleInteger = "0123456789";
var g_ruleSSNNo = "-0123456789";
var g_ruleDate = "/-0123456789";
var g_ruleCtyStateCntry = " \&\\\/#\'()-.,:;?0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz\"";
var g_ruleAlphaNumeric = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var g_rulewebaddress = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
var g_ZipCodeList = "0123456789, \n\r";
var g_ruleFloat = "0123456789.";
var g_ruleAlphabetic = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

function isRule(oComp, sRule, nLength, fdecimal)
{

	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert('Error: No rule/maximum lenght for input object specified.');
		return false;
	}

	var noErrorFlg = true;

	//If object is specified and either of rule is specified,
	if(typeof(sRule) != 'undefined' && sRule != null)
	{
		var temp;
		sRule = sRule + "";
		var discardChars = false;
		if(sRule.length > 0 && sRule.charAt(0) == "~")
		{
			sRule = sRule.substring(1);
			discardChars = true;
		}

		if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i = 0;i < oComp.value.length;i++)
		{
			temp = oComp.value.charAt(i);

			if((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
			{
				//alert("here");
				alert("Enter only numeric value.");
				//alert(oComp.value.substring(0,i));
				oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
				noErrorFlg = false;
				break;
			}
		}
	}
	if(nLength)
	{
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
		}
	}
	return noErrorFlg;
}

// For checking Zip code

function isRuleZip(oComp, sRule)
{
	alert('In zip function');
	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert('Error: No rule/maximum lenght for input object specified.');
		return false;
	}

	var noErrorFlg = true;

	//If object is specified and either of rule is specified,
	if(typeof(sRule) != 'undefined' && sRule != null)
	{
		var temp;
		sRule = sRule + "";
		var discardChars = false;
		if(sRule.length > 0 && sRule.charAt(0) == "~")
		{
			sRule = sRule.substring(1);
			discardChars = true;
		}

		if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i = 0;i < oComp.value.length;i++)
		{
			temp = oComp.value.charAt(i);

			if((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
			{
				alert("Enter value in proper format.");
				oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
				noErrorFlg = false;
				break;
			}
		}
	}
	if(nLength)
	{
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
		}
	}
	return noErrorFlg;
}

// End of Zip code function


// For check dateformat

function isRuleDate(oComp, sRule, nLength, fdecimal)
{

	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert('Error: No rule/maximum lenght for input object specified.');
		return false;
	}

	var noErrorFlg = true;

	//If object is specified and either of rule is specified,
	if(typeof(sRule) != 'undefined' && sRule != null)
	{
		var temp;
		sRule = sRule + "";
		var discardChars = false;
		if(sRule.length > 0 && sRule.charAt(0) == "~")
		{
			sRule = sRule.substring(1);
			discardChars = true;
		}

		if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i = 0;i < oComp.value.length;i++)
		{
			temp = oComp.value.charAt(i);

			if((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
			{
				alert("Enter date in mm/dd/yyyy format.");
				oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
				noErrorFlg = false;
				break;
			}
		}
	}
	if(nLength)
	{
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
		}
	}
	return noErrorFlg;
}

// Check Telephone No. format 
function isRuleTelephone(oComp, sRule, nLength, fdecimal)
{

	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert('Error: No rule/maximum lenght for input object specified.');
		return false;
	}

	var noErrorFlg = true;

	//If object is specified and either of rule is specified,
	if(typeof(sRule) != 'undefined' && sRule != null)
	{
		var temp;
		sRule = sRule + "";
		var discardChars = false;
		if(sRule.length > 0 && sRule.charAt(0) == "~")
		{
			sRule = sRule.substring(1);
			discardChars = true;
		}

		if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i = 0;i < oComp.value.length;i++)
		{
			temp = oComp.value.charAt(i);

			if((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
			{
				alert("Enter phone no. in 999-999-9999 format.");
				oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
				noErrorFlg = false;
				break;
			}
		}
	}
	if(nLength)
	{
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
		}
	}
	return noErrorFlg;
}


function isGreaterthan(datestr1,delim1,dd1,mm1,yy1,datestr2,delim2,dd2,mm2,yy2)
{
	datestr1 = datestr1.trim();
	delim1 = delim1.trim();
	datestr2 = datestr2.trim();
	delim2 = delim2.trim();

	var dt1=Array();
	var dt2=Array();
	var v1=0;
	var v2=0;
	var v3=0;
	var v4=0;
	var v5=0;
	var v6=0;
	dt1 = datestr1.split(delim1);
	dt2 = datestr2.split(delim2);

	v1=dt1[yy1];
	v2=dt2[yy2];
	v3=dt1[mm1];
	v4=dt2[mm2];
	v5=dt1[dd1];
	v6=dt2[dd2];
	if(v1*10 > v2*10)
		return false;
	else
		if((v1*10 == v2*10) && (v3*10 > v4*10))
			return false;
		else
			if((v1*10 == v2*10) && (v3*10 == v4*10) && (v5*10 > v6*10))
				return false;
			else
				return true;
}


function isValidRealNumber(val)
{
	//var realNoRegEx = /^([0123456789,]+([\.]?[0123456789,]+)*)*$/i;
	var realNoRegEx = /^([0123456789,]+([\.]?[0123456789,]+)?)?$/i;
	if (!realNoRegEx.test(val))
		return false;
	return true;
	/*	
	var i = val.indexOf(".");
	var str = val.substring(i+1);
	i = str.indexOf(".");
	if(i>0 || str.length==0 )
		return false;
	else
		return true;
	*/
}
/**
 * This function checks that particular date is after another date
 * @param datestr1 String representing the Date the should come first
 * @param datestr2 String representing the Date the should come later
 * @return Returns the boolean value true if the precedence is maintained
 */
function isStdateGreaterthanEnddt(datestr1,datestr2)
{
		return isGreaterthan(datestr1,"-",2,1,0,datestr2,"-",2,1,0);
}
function validateEMail(str)
{
	//var emailexp = /^[a-z][a-z_0-9\.]+@[a-z_0-9\.]+\.[a-z]{2,4}$/i
	
	//Check that the email entry is valid
	if (!g_rgx_Email.test(str) || str.indexOf("..") >= 0)
	{
		return false;
	}
	return true;
}
function validateUSPhone(str)
{
	alert("here");
	var usPhoneExp = /^\([0-9]{3}\)+(\s)[0-9]{3}\-[0-9]{4}$/
	//var usPhoneExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
	if (!usPhoneExp.test(str))
	{
		return false;
	}
	return true;
//	var usPhoneExp = /^([0-9]{3})-([0-9]{3})-([0-9]{4})$/
//	if (!usPhoneExp.test(str))
//	{
//		return false;
//	}
//	return true;
//	var usPhoneExp = /^\([0-9]{3}\)+([0-9]{3})-([0-9]{4})$/
//	if (!usPhoneExp.test(str))
//	{
//		return false;
//	}
//	return true;
}
function validateCCNo(str)
{
	var CCNo = /^[0-9]{10}$/
	if (!CCNo.test(str))
	{
		return false;
	}
	return true;
}


function formatUSPhoneNo(control,e)
{
	var key;
	
	if (window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which;
	}
	
	if((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 8))
	{

		if ((control.value.length == 1) && ('(' != control.value.charAt(0)))
			control.value = "(" + control.value;
		if(control.value.length == 0)
			if(key != 8)
				control.value = control.value + "(";
		if(control.value.length == 4)
			if(key != 8)
				control.value = control.value + ") ";
		if(control.value.length == 9)
			if(key != 8)
				control.value = control.value + "-";
		if(control.value.length == 9)
			if(key != 8)
				control.value = control.value + " ";
	}

}
/*

var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value

if ('(' != p.charAt(0))
{
	pp = p;
	pp = "(" + pp;
	document.frmPhone.txtphone.value="";
	document.frmPhone.txtphone.value=pp;
}

if(p.length==4){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+") ";
	}
	//pp="("+pp+")";
	document.frmPhone.txtphone.value="";
	document.frmPhone.txtphone.value=pp;
}
if(p.length>4){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+") "
		p31=p.substring(5,l30);
		pp=p30+p31;
		//alert(p31);
		document.frmPhone.txtphone.value="";
		document.frmPhone.txtphone.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.frmPhone.txtphone.value="";
	pp="("+p13+") "+p14+p15;
	document.frmPhone.txtphone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3 && p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+5);
		p18=p.substring(d2+5,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.frmPhone.txtphone.value="";
	document.frmPhone.txtphone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,100)
}
function getIt(m, e){
	if (window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which;
	}

	n=m.name;
	//p1=document.forms[0].elements[n]
	p1=m
	
	if((key >= 48 && key <= 57) || (key == 44) || (key == 46)  || (key == 8) || (key == 0))
		ValidatePhone()
}
function formatUSPhoneNo(control,e){
	n=control.name;
	//p1=document.forms[0].elements[n]
	p1=control;
	ValidatePhone();
}
*/

function formatSSNo(control,e)
{
	var key;
	
	if (window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which;
	}
	if((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 8))
	{
		if(control.value.length == 3 || control.value.length == 6 )
			if(key != 8)
				control.value = control.value + "-";

	}
}

function formatAmount(control,e)
{
	var key;
	
	if (window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which;
	}
	if((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 8))
	{
		if(control.value.length == 10)
			if(key != 8)
				control.value = control.value + ".";
	}
}

function formatDate(control,e)
{
	var key;
	
	if (window.event)
	{
		key = e.keyCode;
	}
	else
	{
		key = e.which;
	}
	if((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 8))
	{
		if(control.value.length == 2)
			if(key != 8)
				control.value = control.value + "/";
	}
}

function FormatCurrency(fld,e)
{
   	var val = fld.value;
   	var decimalVal = "";

	if (window.event)
		key = e.keyCode;
	else
		key = e.which;

	//alert(fld.selectionStart + " :: " + fld.selectionEnd);
//alert (val.indexOf(".") + " != " + val.lastIndexOf("."));	

	if (val.indexOf(".") != val.lastIndexOf("."))
	{
		fld.value = val.substr(0, val.indexOf(".")+1) + RemoveDot(val.substr(val.indexOf(".")+1, val.length)); //val.substr(0, val.length-1);
		return;
	}

	
	//if(key != 35 && key != 36 && key != 37 && key != 39) //key Home, End, Left, Right arrow
	if ((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 8 || key ==46)) //48..57 : 0..1; 96..105 : keypad 0..1 ; 190 : . ; 110 : keypad .
	{
    	var numWithoutComma = RemoveComma(val);
    	
		if (-1 != val.indexOf("."))
		{

			if (((val.indexOf(".")+1) - val.length) != 0)
				decimalVal = val.substr(val.indexOf(".")+1, val.length);
			else
				decimalVal = "";

			numWithoutComma = RemoveComma(val.substr(0, val.length - (val.length - val.indexOf("."))));				
		}
		//alert(numWithoutComma + " :: " + decimalVal);
		
    	var numWithComma = InsertComma(numWithoutComma,decimalVal);
    	fld.value = numWithComma; 
	}
}

function InsertComma(val,decimalVal)
{
	var grp3Array = Array();
	if("" != decimalVal)
	{
		if (decimalVal.length > 2)
			decimalVal = decimalVal.substr(0, 2);
		//val = val.substr(0, val.indexOf("."));
	}

	var valLength = val.length;
	val = stringReverse(val);

	var str;
	var formattedStr = "";
	var n = 0;
	for (var i = valLength,k=0; i > 0; i -= 3, k++)		
	{
		var tmpstr = val.substr(n, 3);

		if (val.length>3 && tmpstr.length >= 3 && ((val.length-n) >3))
		    tmpstr = "," + stringReverse(val.substr(n, 3));
		else
		    tmpstr = stringReverse(val.substr(n, 3));
		grp3Array[k] = tmpstr;
		n = n+3;
	
	}
	
	
	for (a=grp3Array.length-1; a>=0; a--)
	{
		formattedStr += grp3Array[a];
	}
	
	if ("" != decimalVal)
		formattedStr += "." + decimalVal;
	
	return formattedStr;
}

function RemoveComma(val)
{
	val = String(val);
	return val.replace(/,/g, "");
}

function RemoveDot(val)
{
	val = String(val);
	return val.replace(/\./g, "");
}

/************************************************************************
  Function: PositiveNumOnly(control,e)
  Purpose: will allow positive only numbers to be entered into field
  Parameters:
			control : field to be validated
			      e : event
************************************************************************/
function PositiveNumOnly(control)
{
	if (Number(RemoveComma(control.value)) > 0)
		return true;
	else
		return false;
}

function stringReverse (str) 
{
    var s = str; //typeof this.valueOf() == 'string' ? this : str;
    var r = '';
    for (var i = s.length - 1; i >= 0; i--)
      r += s.charAt(i);
    return r;
}

function valdMonthYear(dateString)
{
	dateString = "01/" + dateString;
	
	var dateMatchExp = new RegExp("^(\\d{1,2})/(\\d{1,2})/(\\d{4})$");
	var match = dateMatchExp.exec(dateString);

	

	if (null == match) return false;	//Match failed, invalid date
	
	var now = new Date();
	curyear = now.getFullYear();
	curmonth = now.getMonth();
	if(curmonth < 10)	curmonth = '0'+curmonth;
	
	if (match[3]==curyear && match[2] >= curmonth) return false;	//validate current month & year
	if (match[3] < 1 || match[3] > curyear) return false;	//validate year
	if (match[2] < 1 || match[2] > 12) return false;	//validate month
	if (match[1] < 1 || match[1] > 31) return false;	//validate day

	// valid day check
	if (match[2] == 2) 		// february check
	{
		if (match[1] > 29) return false;
		//Check for leap year.
		if (((match[3] % 100 == 0 || match[3] % 4 != 0) && (match[3] % 400 != 0))  // non-leap year checked
				&& match[1] > 28) return false;
	}
	else if ((match[2] == 4 || match[2] == 6 || match[2] == 9 || match[2] == 11) && (match[1] > 30))
		return false;

	return true;
}
function isBlank(val)
{
	if(val==null)
		return true;

	for(var i=0;i<val.length;i++)
	{
		if((val.charAt(i)!='') && (val.charAt(i)!="\t")	&& (val.charAt(i)!="\n") && (val.charAt(i)!="\r"))
			return false;
	}

	return true;
}