var expphone = /[^\d|\-|\+|\,]+/;
var expaddress = /[^\w|\s|\~|\!|\@|\#|\&|\(|\)|\_|\-|\+|\{|=|\[|\]|\:|\,|\.|\/]+/;	
var expurl = /http:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/; 
var emailexp  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var expname = /[^\w|\s|\!|\=|\&|\$|\'|\?|\.|\/|\_|\)|\(|\[|\]|\:|\-]+/;
var expvarchar  =/[^\w|\s|\~|\!|\@|\#|\&|\(|\)|\{|\}|=|\[|\]|\:|\;|\.|\'|\?|\/|\$|\*|\,|\-|\+|\%]+/;
var explevelvarchar =/[\~|\!|\@|\_|\{|\}|=|\[|\]|\:|\"]+/;
var expValueDomain  =/[^\w|\s|\~|\!|\@|\#|\&|\(|\)|\{|\}|=|\[|\]|\:|\.|\'|\?|\/|\$|\*|\,|\-|\+|\%]+/;
var Userexp = /(\s)/ ; 
var expMassage = '(\",%,;,~,@,#,^,*,{,},(,)\)';
var expVDomainMassage = '(\",~,{,}\)';

function FormatTime(str)
{
	if (str.length>0)
	{
		if ((str.length!=8) && (str.length!=5))
		{
			alert("Time is not in desired format. Enter in 24HH:MI:SS or 24HH:MI format 33");
			return false;
		}
		for(i=0;i<str.length;i++)
		{
			var posChar = str.charAt(i);
			if((i==2)&&(posChar != ':' ))
			{
				alert(posChar + "Time is not in desired format. Enter in 24HH:MI:SS or 24HH:MI  format 22");
				return false;
			}
			if(( (i==5)&&(posChar != ':') )&& (str.length!=5) )
			{
				alert("Time is not in desired format. Enter in 24HH:MI:SS or 24HH:MI  format 11");
				return false;
			}
			if((i!=2)&&(i!=5))
			{
				if (isNaN(posChar))
				{
					alert("Time is not in desired format. Enter in 24HH:MI:SS or 24HH:MI  format 00");
					return false;
				}
			}
		}
		var td = str.substring(0,2);
		var tm = str.substring(3,5);
		var ty = str.substring(6,8);

		if ((td<0)||(td>24))
		{
			alert("Hours is not correct");
			return false;
		}
		if ((tm<0)||(tm>60))
		{
			alert("Minutes value is not correct");
			return false;
		}
		if (((ty<0)||(ty>60)) && (str.length==8))
		{
			alert("Second value is not correct");
			return false;
		}
	}
	return true;
}

//Function to Check the Characters length of the TextArea Fields
function checkCharLength(strObj,strName,maxlen)
{
	strTestObj = "document.form1."+strObj 
	if (eval(strTestObj+".value.length")>maxlen)
	{
	  eval(strTestObj+".value="+strTestObj+".value.substring(0,"+maxlen+")");
	  alert(strName+" can only be "+ maxlen +" characters long");
	}
}

//Function To alown the Attachments like .pdf or .zip
function isOnlyFIle(obj,msg)
{
	var nam = obj.value;
	//nam = nam.trim();
	
	var arr=new Array();
	arr=obj.value.split('.');
	if(arr[arr.length-1].toUpperCase() != "PDF" && arr[arr.length-1].toUpperCase()!="ZIP" )		
	{
		alert(msg);
		obj.focus();
		return 0;
	}			

} 

	
//Function To Limit the Attachments like .doc or .xls or .txt
function LimitAttach(form,file,fileext)
{
	 var strExt = new String();
		 strExt = fileext;	 
	   extArray = strExt.split(",")	 
	var allowSubmit = false;
	if (!file) return;
		while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
		
		//ext  = file.slice(file.indexOf(".")).toLowerCase();
		srt_len = file.length;
		ext  = file.substring(srt_len-4,srt_len).toLowerCase();
					
			for (var i = 0; i < extArray.length; i++)
			{	
				if (extArray[i] == ext) { allowSubmit = true; break; }
			}			
			if (allowSubmit) 
			{
				return true;
			}					
			else
			{
				alert("Only (" + (extArray.join("  ")) + ") files are allowed to upload," +
				"\nPlease select a new "
				+ "file and upload again.");				
				return false;
			} 
}

function FormatDate(str,field_name)
{
	if (str.length>0)
	{
		if(str.length!=10)
		{
			alert("Date is not in desired format. Enter in DD/MM/YYYY format ");
			//field_name.value="";
			field_name.focus();
			return false;
		}
		for(i=0;i<str.length;i++)
		{
			var posChar = str.charAt(i);
			if((i==2)&&(posChar != '/' ))
			{
				alert(posChar + "Date is not in desired format. Enter in DD/MM/YYYY format ");
				//field_name.value="";
				field_name.focus();
				return false;
			}
			if((i==5)&&(posChar != '/'))
			{
				alert("Date is not in desired format. Enter in DD-MM-YYYY format ");
				//field_name.value="";
				field_name.focus();
				return false;
			}
			if((i!=2)&&(i!=5))
			{
				if (isNaN(posChar))
				{
					alert("Date is not in desired format. Enter in DD/MM/YYYY format ");
					//field_name.value="";
					field_name.focus();
					return false;
				}
			}
		}

		var td = str.substring(0,2);
		var tm = str.substring(3,5);
		var ty = str.substring(6,10);
		
		if ((td<1)||(td>31))
		{
			alert("Day value is not correct");
			//field_name.value="";
			field_name.focus();
			return false;
		}
		if ((tm<1)||(tm>12))
		{
			alert("Month value is not correct");
			//field_name.value="";
			field_name.focus();
			return false;
		}
		if((tm == '04') || (tm == '06') || (tm == '09') || (tm == '11'))
		{
			if(td>30)
			{
				alert("Day value cannot be greater than 30 for this Month");
				//field_name.value="";
				field_name.focus();
				return false;
			}
		}
		if ( modulus(ty) == 0 )
		{
			if(tm == 2)
			{
				if(td>29)
				{
					alert("Day should be less than 29 for February in a leap year");
					//field_name.value="";
					field_name.focus();
					return false;
				}
			}
		}
		else  //not a leap year
		{
			if(tm ==2 )
			{
				if(td>28)
				{
					alert("Day should be less than 28 for February");
					//field_name.value="";
					field_name.focus();
					return false;
				}
			}
		}
		if(ty<"1901")
		{
			alert("Date should be greater than 1901");
			//field_name.value="";
			field_name.focus();
			return false;
		}
	}
	return true;
}

function modulus(x)
{
	var y;
	y= ((x%400==0) || ((x%4==0)&&(x%100!=0)))
	if (y==1)
		return 0;
	else
		return 1;
}

function validateThis_old()
{
	 if(event.keyCode==46){
	 }
	 else{
		 if(event.keyCode < 48 || event.keyCode > 57){
          event.returnValue = false; 
    	 }
	 }
}

function validateThis()
{
	if(event.keyCode < 48 || event.keyCode > 57)
	{
		event.returnValue = false; 
	}
}

function validatePhone()
{
	 if(event.keyCode==44||event.keyCode==45){
	 }
	 else{
		 if(event.keyCode < 48 || event.keyCode > 57){
          event.returnValue = false; 
    	 }
	 }
}

function check(strString1,fcs)
{
	var strValidChars = "0123456789.";

	var strString;
	var blnResult = true;
	strString=strString1;
	if (strString != "")
	{
		for (i = 0; i < strString.length && blnResult == true; i++)
		{
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1)
			{
				blnResult = false;
				return blnResult;
			}
		}
		return true;
	}
}

function check1(strString1,fcs)
{
	var strValidChars = "0123456789.";
	var cnt=0;

	var strString;
	var blnResult = true;
	strString=strString1;
	if (strString != "")
	{
		for (i = 0; i < strString.length && blnResult == true; i++)
		{
			strChar = strString.charAt(i);
			if (strChar==".")
			{
				cnt=cnt+1;
				if (cnt > 1)
				{
					alert("Decimal point can not be repeated");
					eval(fcs).focus();
					blnResult = false;
					return blnResult;
				}
			}
		}
		return true;
	}
}

function check2(strString1,fcs,ext)
{
	
	var strString;
	var cnt=0;
	var strext;
	strext=ext;
	strString=strString1;
	if (strString != "")
	{
		
		for (i = 0; i < strString.length; i++)
		{
			strChar = strString.charAt(i);
			if (strChar==".")
			{
				cnt=cnt+1;
			}
		}
		if (cnt == 1)
		{
			
			strVal = strString.split(".");
			strVal1 = strVal[0];
			strVal2 = strVal[1];
			if (strVal1.length>12)
			{
				alert("You are exceeding the limit of digits.\nBefore decimal point, the whole number part can accept only upto 12 digits.")
				eval(fcs).focus();
				return false;
			}
			if (strVal2.length>strext)
			{
				alert("You are exceeding the limit of digits.\nAfter decimal point, the decimal number part can accept only "+strext+" digits.")
				eval(fcs).focus();
				return false;
			}
		}
		if (cnt == 0 && strString.length>12)
		{
			alert("You are exceeding the limit of digits.\nWithout decimal point, it can accept only upto 12 digits.")
			eval(fcs).focus();
			return false;
		}
	}
	return true;
}
function isint(field_value, form_focus)
{
	var strValidChars = "0123456789";
	if (field_value.length>0)
	{
		for (i = 0; i < field_value.length; i++)
		{
			strChar = field_value.charAt(i);
			if (strValidChars.indexOf(strChar) == -1)
			{
				alert("Please enter positive integer only");
				form_focus.focus(); 
				return false;
			}
		}
	}
	return true;
}
function onlyAlfaNumeric(e)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if((keynum==32) || (keynum>=48 && keynum<=57)|| (keynum>=65 && keynum<=90) || (keynum>=97 && keynum<=122) )
	{
		
	}
	else
	{
		e.keyCode=0;
	}
}

function onlyAlfaSpace(e)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if((keynum==32) || (keynum>=65 && keynum<=90) || (keynum>=97 && keynum<=122) )
	{
		
	}
	else
	{
		e.keyCode=0;
	}
}

function onlyAlfaNumericS(e)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if((keynum==13) || (keynum==32) || (keynum==38) || (keynum==40) || (keynum==41) || (keynum>=45 && keynum<=57) || (keynum>=65 && keynum<=90) || (keynum==92) || (keynum>=97 && keynum<=122) )
	{
		
	}
	else
	{
		e.keyCode=0;
	}
}

function onlyAlfaNumericTR(e)
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if((keynum==38) || (keynum==40) || (keynum==41) || (keynum==45) || (keynum>=47 && keynum<=57) || (keynum>=65 && keynum<=90) || (keynum==92) || (keynum>=97 && keynum<=122) )
	{
		
	}
	else
	{
		e.keyCode=0;
	}
}


function onKeyDownfunc()
{
	// current pressed key
	var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
	if (event.ctrlKey && (pressedKey == "c" || pressedKey == "v"))
	{
		// disable key press porcessing
		alert("You may not cut and paste text here.")
		event.returnValue = false;
	}
} // onKeyDown

function validateKeyv (evt) 
{
	if (evt.keyCode == '17')
	{
		alert("You may not cut and paste text here.")
		return false
	}
	return true
}
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
		alert ("You are exceeding the maximum length of this field!");
		return false;
	}
}