<!-- Hide From the old browsers
function isProper(formField,fieldLabel) {
	var stringval = formField.value;
	var string = formField.value.length;
	var iChars = "*|,\"<>[]{}`';()&$#%";
	for (var i = 0; i < string; i++) {
		if (iChars.indexOf(stringval.charAt(i)) != -1) {
			alert('Please enter a proper value for the "' + fieldLabel +'" field');
			formField.focus();
			return false;
		}
	}
	return true;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function TextValidate(txtCtrl,val)
{
	var ctrName = val;
	if (trimAll(txtCtrl.value) == "")
	{
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	
		return false;		
	}
}

//To validate whether given date is in the form of dd/mm/yyyy
function DateFormatValidate(txtCtrl,val)
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
		var strarr = txtCtrl.value.split("-");
		var m = strarr[1];
		var d = strarr[2];
		var y = strarr[0];
		var len = strarr.length;
		
		date =new Date();
		if(len > 3 || isNaN(d) || isNaN(m) || isNaN(y) || d<1 || d>31 || m<1 || m>12 || y<date.getFullYear()-40)
		{
			alert("Please enter valid " + ctrName + ".");			
			txtCtrl.focus();
			txtCtrl.select();
			return false;
		}
	}
	else
	{
		alert("Please enter " + ctrName + ".");			
		txtCtrl.focus();
		txtCtrl.select();
		return false;	
	}
}

function DateFormateValidateCheck(txtCtrl,val)
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
		var strarr = txtCtrl.value.split("/");
		var m = strarr[0];
		var d = strarr[1];
		var y = strarr[2];
		var len = strarr.length;
		date =new Date();
		if(len > 3 || isNaN(d) || isNaN(m) || isNaN(y) || d<1 || m<1 || m>12 || y<date.getFullYear()-40)
		{
			alert("Please enter valid " + ctrName + "");			
			txtCtrl.focus();
			txtCtrl.select();
			return false;
		}
	}
}

/*
*	To find out wether given date is correct or not
*	Created on 05-Nov-2003
*/
function Checkdate(Lday, Lmonth, Lyear) 
{
	valid  = true;
	if(Lyear < 1970)
	{
		valid = false;
	}
	
	if(Lmonth > 12 || Lmonth < 1)
	{
		valid = false;
	}
	
	if(Lday < 1)
	{
		valid = false;
	}
	
	if( Lmonth == 2 )
	{
		if( (Lyear % 4) == 0 )
		{
			if(Lday > 29)
			{
				valid = false;
			}
		}
		else
		{
			if(Lday > 28 )
			{
				valid = false;
			}
		}
	}
	else if( Lmonth == 1 || Lmonth == 3 || Lmonth == 5 || Lmonth == 7 || Lmonth == 8 || Lmonth == 10 || Lmonth == 12)
	{
		if(Lday > 31)
		{
			valid = false;
		}
	}
	else
	{
		if(Lday > 30)
		{
			valid = false;
		}
	}

	if(valid == true)
	{
		return true;
	}
	else
	{
		alert ("Please enter valid date for "+ Lday +"-"+ Lmonth +"-"+ Lyear);
		return false;
	}
}

//validating the date with current date
function DateValidate(txtCtrl,val) 
{
	var ctrName = val;
//	alert (ctrName);		
	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
		var strarr = txtCtrl.value.split("/");
		var d = strarr[0];
		var m = strarr[1];
		var y = strarr[2];
		var len = strarr.length;
		var result = true;
		date =new Date();
		if(len > 3 || isNaN(d) || isNaN(m) || isNaN(y) || d<1 || m<1 || m>12 || y<date.getFullYear()-40 || y > date.getFullYear())
		{
			result = false;
		}

		if( y == date.getFullYear())
		{
			if(m == date.getMonth()+1)
			{
				if(d > date.getDate())
				{
					result = false;
				}
			}
			else if (m > date.getMonth()+1)
			{
				result = false;
			}
		}					

		if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
		{
			if(d>31 || d<=0)
			{
				result = false;
			}	
		}
		else if(m==2)
		{	
			if(y%4 ==0)
			{
				if(d >29 || d<1)
				{
					result = false;
				}
			}
			else
			{
				if(d >28 || d<1)
				{
					result = false;
				}
			}
		}
		else
		{	
			if(d >30 || d<=0)
			{
				result = false;
			}
		}	

		if(result == false)
		{
			alert("Please enter valid " + ctrName + "");		
			txtCtrl.focus();
			txtCtrl.select();
			return false;		
		}
	}
}

function LengthValidate(txtCtrl, val)
{
	Remove_Spaces(txtCtrl);	
	if(txtCtrl.value.length < val)
	{
		alert("The Length should be "+  val +" characters!");
		txtCtrl.focus();
		txtCtrl.select();		
		return false;		
	}
}
function TextAreaValidate(txtCtrl, val) 
{
	var ctrName	= val;

	var str = txtCtrl.value;
	if(str.length == 0)
	{
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	   	
		return false;
	}		
	/*if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + "");		
		txtCtrl.focus();   	
		return false;		
	}*/			
}
function TextAreaValidateS(txtCtrl, val) 
{
	var ctrName	= val;

	var str = txtCtrl.value;
	if(str.length == 0)
	{
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	   	
		return false;
	}
	if (trimAll(txtCtrl.value) == "")
	{
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	
		return false;		
	}
			
}

//-----------------------------------------------------------
function NumberValidate(txtCtrl, val) 
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	/*if (txtCtrl.value == "" )
	{
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}*/
	if(isNaN(txtCtrl.value)) 
	{
		alert("Please enter numeric value for " + ctrName + "");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}
}

function NumberPriceValidate(txtCtrl, val) 
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	if(isNaN(txtCtrl.value)) 
	{
		alert("Please enter numeric value for " + ctrName + "");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}
}

function NumberValidateCheck(txtCtrl) 
{
	Remove_Spaces(txtCtrl);
	var fLength = txtCtrl.value.length;
	if (fLength == 0) 
	{
 		return false;
	}		

	if (txtCtrl.value == "" || isNaN(txtCtrl.value))
	{
		alert("The value " + txtCtrl.value + " is not a valid data.\n\r" +  
			"Enter numeric values !");		
		txtCtrl.focus();
		txtCtrl.select();
		return false;	
	}		
}

//-----------------------------------------
// Req field
function EmailValidate(txtCtrl, val) 
{
	var ctrName = val;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(txtCtrl.value == "")
	{
		alert("Please enter " + ctrName + "");		
		txtCtrl.focus();   	
		return false;		
	}	else if (!filter.test(txtCtrl.value)) 	{
		alert("Please enter a valid email\t\n eg: username@domainname.com");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + "");		
		txtCtrl.focus();   	
		return false;		
	}			
}

function EmailValidateSubscriber(txtCtrl, val) 
{
	var ctrName = val;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(txtCtrl.value == "")
	{
		alert("You need to provide your E-mail in order to subscribe!");		
		txtCtrl.focus();   	
		return false;		
	}	else if (!filter.test(txtCtrl.value)) 	{
		alert("Please enter a valid email.\t\n eg: username@domainname.com");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + "");		
		txtCtrl.focus();   	
		return false;		
	}			
}


// Not req, but check format - use onblur
function EmailValidateCheck(txtCtrl) {
	var xlogus = txtCtrl.value.length;
	if (xlogus != 0) 
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(txtCtrl.value)) 	{
			alert("Please enter a valid email.\t\n eg: username@domainname.com");
			txtCtrl.focus();	   	
			txtCtrl.select();
			return false;
		}		
	}
}

//-----------------------------------------
function PhoneValidate(txtCtrl,val) 
{
	var ctrName = val;

	var strarr = txtCtrl.value.split("-");
	var first = strarr[0];
	var last = strarr[1];
	if (txtCtrl.value.indexOf("-") < 3 || isNaN(first) || isNaN(last)|| txtCtrl.value.indexOf(".") != -1 || first.length < 3 || last.length < 4 ) 
	{
		alert("Please enter a valid phone number.");
		txtCtrl.focus();	   	
		return false;
	}		

	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + ".");		
		txtCtrl.focus();   	
		return false;		
	}			
}


// Not req, but check format - use onblur
function PhoneValidateCheck(txtCtrl) 
{
	var xlogus = txtCtrl.value.length;
	if (xlogus == 0) 
	{
 		return false;
	}
	var strarr = txtCtrl.value.split("-");
	var first = strarr[0];
	var last = strarr[1];
    if(txtCtrl.value.indexOf("-") < 3 || isNaN(first) || isNaN(last)|| txtCtrl.value.indexOf(".") != -1 || first.length < 3 || last.length < 4 )
	{
		alert("Please enter a valid phone number.");
		txtCtrl.focus();	   	
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + "");		
		txtCtrl.focus();   	
		return false;		
	}			
}

 // 000 use onblur 
function ZeroValidate(txtCtrl , val)
{
		var xlogus = txtCtrl.value.length;
		if (xlogus == 0) 
		{
			return false;
		}
		 
	 if (NumberValidateCheck(txtCtrl, 'Quantity') == false) return false;
				
		var txtValue = txtCtrl.value;		

		if (txtValue == 0 || txtValue == 0.00)
		{
			alert('Zero value is not allowed for '+val);
			txtCtrl.focus();
			return false;	
		}
}

//-------------------------
// Req
function SelValidate(selCtrl,msg) 
{
	if (selCtrl.value == "" || selCtrl.value == "0" || selCtrl.value == "-1" || selCtrl.value.indexOf("Please") != -1) 
	{
		alert(msg);
		selCtrl.focus();	   	
		return false;
	}		
}



function SelectValidate(selCtrl,msg) 
{
	if (selCtrl.value == "" || selCtrl.value == "0" || selCtrl.value == "-1" || selCtrl.value.indexOf("Please") != -1) 
	{
		alert("Please select " + msg +"");
		selCtrl.focus();	   	
		return false;
	}		
}


/*function OptValidate(optCtrl,msg) 
{
    var el = document.forms[0].elements;
	for(var i = 0 ; i < el.length ; ++i)
	{
		if(el[i].type == "radio")
		{
			var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			var itemchecked = false;
			for(var j = 0 ; j < radiogroup.length ; ++j) 
			{
				if(radiogroup[j].checked)
				{
				  itemchecked = true;
				  break;
				}
    		}
			if(!itemchecked) 
			{
				alert("Please choose an option for "+msg+"");
				if(el[i].focus)
					el[i].focus();
				return false;
			}
	   	}
  	}
} // Function End
*/


function OptValidate(optCtrl,msg) 
{
    var ele = optCtrl;
   	var itemchecked = false;
	for(var j=0; j<ele.length;j++) 
	{
 		if(ele[j].checked)
		{
			  itemchecked = true;
			  break;
		}
	}
	if(!itemchecked) 
	{
		alert("Please choose an option for "+msg+"");
		return false;
	}
 } // Function End


function CloseWindow() 
{
	window.close();
	window.opener.focus();
} 

function Remove_Spaces(txtCtrl)
{
  txtCtrl.value = txtCtrl.value.replace(/\r/g, " ");

  txtCtrl.value = txtCtrl.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");

 // txtCtrl.value = txtCtrl.value.replace(/'/g, "");

  txtCtrl.value = txtCtrl.value.replace(/ +/g, " ");

  txtCtrl.value = txtCtrl.value.replace(/^\s/g, "");

  txtCtrl.value = txtCtrl.value.replace(/\s$/g, "");
  
  if (txtCtrl.value == ' ')
  {
	 txtCtrl.value = '';
   }
 
 }
//-->

// Function for Compare Two passwords
function Comparetextboxes(txtCtrl1, txtCtrl2) 
{
	Remove_Spaces(txtCtrl1);
	Remove_Spaces(txtCtrl2);
	if (txtCtrl1.value == "")
	{
		alert("Please enter the password");
		txtCtrl1.focus();	
		return false;		
	}
	else if(txtCtrl1.value.length < 6)
	{
		alert("The password should be atleast 6 characters !");
		txtCtrl1.focus();	
		return false;
	}
	
	if (txtCtrl2.value == "")
	{
		alert("Please enter the confirm password");
		txtCtrl2.focus();	
		return false;		
	}
	else if(txtCtrl2.value.length <6)
	{
		alert("The confirm password should be atleast 6 characters !");
		txtCtrl2.focus();	
		return false;
	}		

	if (txtCtrl1.value != txtCtrl2.value) 
	{
		alert("The password and confirmation password do not match !");
		txtCtrl1.focus();	   	
		return false;
	}
}
function Compareemail(txtCtrl1, txtCtrl2) 
{
	Remove_Spaces(txtCtrl1);
	Remove_Spaces(txtCtrl2);
	if (txtCtrl1.value != txtCtrl2.value) 
	{
		alert("The Email address and Confirmation email address do not match !");
		txtCtrl1.focus();	   	
		return false;
	}
}

function chkFile(frmName)	
{
	if(frmName.file.value != "")	
	{
		var strarr = frmName.file.value.split(".");
		var len = strarr.length;
		if(len != 2)
		{
			alert("Please check file name !");
			frmName.file.focus();
			frmName.file.select();
			return false;
		}
		var type = strarr[1];						
		if (type < 3) {							
			alert("Please check file format !");
			frmName.file.select();
			return 1;
		}						
	}		
}

function FileValidate(ctrl,msg)	
{
	if(ctrl.value != "")	
	{
		var strarr = ctrl.value.split(".");
		var len = strarr.length;
		if(len != 2)
		{
			alert("Please check file name!");
			ctrl.focus();
			ctrl.select();
			return false;
		}
		var type = strarr[1];						
		if (type < 3) {							
			alert("Please check file format!");
			ctrl.select();
			return false;
		}						
	}
	else
	{
		alert(msg);
		return false;
	}
}

function File_Extentsion_Validate_Doc(ctrl,msg)	
{ //alert('image');
	if(ctrl.value != "")	
	{
		var strarr = ctrl.value.split(".");
		var len = strarr.length;
		if(len != 2)
		{
			alert("Please check file name !");
			ctrl.focus();
			ctrl.select();
			return false;
		}
		var type = strarr[1].toLowerCase();								
 		if (type!='doc' && type!='pdf' && type!='txt' && type!='odt') {							
			alert("Please check file format !");
			ctrl.select();
			return false;
		}						
	}
}
<!-- Begin
//To compare the from date with to date
function Comparedate(fdate,tdate)
{
	var strarr = fdate.value.split("/");
	
	splitter=fdate.value.substr(2,1);
	strarr = fdate.value.split(splitter);	
	var d = strarr[1];
	var m = strarr[0];
	var y = strarr[2];

	splitter=tdate.value.substr(2,1);
	var strarr = tdate.value.split(splitter);
	var d1 = strarr[1];
	var m1 = strarr[0];
	var y1 = strarr[2];
	if( y == y1)
	{
		if(m == m1)
		{
			if(d > d1)
			{
				alert("From date exceeds To date");		
				tdate.focus();
				tdate.select();
				return false;
			}
		}
		else if (m > m1)
		{
			alert("From date exceeds To date");		
			tdate.focus();
			tdate.select();
			return false;
		}
	}	
	if(y > y1)				
	{
		alert("From date exceeds To date");		
		tdate.focus();
		tdate.select();
		return false;			
	}
}

function redirectpage(url_page)
{
	window.location.href= url_page;
}
function GoBack()
{
	window.history.back(-1);
}


function replaceChecks() {
	var check=document.form1.check;
	if(document.form1.checkall.checked == true) {
		if(document.form1.check.value) document.form1.check.checked = true;
		else {
			for (var i=0;i<check.length;i++){ check[i].checked = true; }
		}
	}else {
		if(document.form1.check.value) document.form1.check.checked = false;
		else {
			for (var i=0;i<check.length;i++){ check[i].checked = false; }
		}
	}
}

function deleteRecord(page,args) {
	var count =0;
	if(document.form1.check.checked) {
		var check = new Array(document.form1.check.value);
		count = 1;		
	}else {	var check=document.form1.check; }
	for (var i=0;i<check.length;i++){
		if(check[i].checked == true) count++;
	}
	if(count <= 0) {
		alert("Please select the records to delete");
	}else {
		if(confirm("Are you sure you want to delete the selected record(s)?")) {
			document.form1.action = page+"?action=delete&"+args;
			var url = page+"?action=delete";
			if(args) { url += "&"+args}
			document.form1.submit();
		}
	}
}

function isDecimal(txtCtrl){
	decimalRegExp = /^([1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/
	if (trimAll(txtCtrl.value) == "") {
		alert("Please enter " + ctrName + "");
		txtCtrl.focus();	
		return false;		
	} else if(!decimalRegExp.test(txtCtrl.value)) {
		alert("Please enter a valid amount.");
		txtCtrl.focus();	
		return false;		
	}
	
}

function fileValidate(txtCtrl,msg) {
	alert(txtCtrl.value);
  if(txtCtrl.value == '' || txtCtrl.value=='undefined' ) {
 		alert("Please select "+msg);
		txtCtrl.focus();	
		return false;	
   } else {
		var OK = new Array ('jpg', 'gif', 'jpeg', 'png', 'jpe', 'tif');
		var filename = txtCtrl.value;
		var ext = getExt(filename);
		var fileOK = 0;
		
		for (i = 0; i < OK.length; i++) {
		 if (OK[i] == ext) {
		  fileOK = 1; // one of the file extensions found
		 } 
		}
		
		if (fileOK == 0) { 
		 alert ("The file is not an image file");
		 return false;
		}	
  }
}

function getExt(filename) {
   var dot_pos = filename.lastIndexOf(".");
   if(dot_pos == -1)
      return "";
   return filename.substr(dot_pos+1).toLowerCase();
}
function CheckCard() {
	if(CheckCardNumber(document.payment) == true) {
		document.payment.hdnPay.value="Pay";
		document.payment.action="payment.php";
		document.payment.method="post";
		document.payment.submit();
	}
}








/**    Wesite Validation ends
**/
// End -->