// JavaScript Document
/**
* formvalidation.js
* This Javascript file holds functions that are need to validate form fields.
* @access   public
* @author   Tarun
* @version  v1.0 
* @copyright 2009 Spacelocker
*/
function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

<!-- Hide From the old browsers
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;
	//Remove_Spaces(txtCtrl);
	if (trimAll(txtCtrl.value) == "")
	{
		alert("Please enter " + ctrName);
		txtCtrl.focus();
		return false;		
	}
	/*if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName );		
		txtCtrl.focus();   	
		return false;		
	}*/	
	return true;
}

function SecurityValidate1(contentvalue)
{
	var contentvalue = trimAll(contentvalue);
	var errorflag = "";	
	if (contentvalue!="" && contentvalue.length>0){
		var is_less_question = contentvalue.indexOf('<?');
		var is_great_question = contentvalue.indexOf('?>');
		var is_less_percentage = contentvalue.indexOf('<%');
		var is_great_percentage = contentvalue.indexOf('%>');
		var is_frame = contentvalue.indexOf('<iframe');
		if ((is_less_question>=0) || (is_great_question>=0) || (is_less_percentage>=0) || (is_great_percentage>=0) || (is_frame>=0)) {
			errorflag = "1";		
		}
	}
	if(errorflag=="1") {
		return false;		
	}else {
		return true;	
	}		
}


function SecurityValidate(txtCtrl,val)
{
	var ctrName = val;
	var contentvalue = trimAll(txtCtrl.value);
	var errorflag = "";	
	if (contentvalue!="" && contentvalue.length>0){
		var is_less_question = contentvalue.indexOf('<?');
		var is_great_question = contentvalue.indexOf('?>');
		var is_less_percentage = contentvalue.indexOf('<%');
		var is_great_percentage = contentvalue.indexOf('%>');
		var is_frame = contentvalue.indexOf('<iframe');
		if ((is_less_question>=0) || (is_great_question>=0) || (is_less_percentage>=0) || (is_great_percentage>=0) || (is_frame>=0)) {
			errorflag = "1";		
		}

	}
	if(errorflag=="1") {
		alert("Please enter valid "+ctrName);
		txtCtrl.focus();
		return false;		
	}
	
	return true;
}

function isProperText(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.');
			return false;
		}
	}
	return true;
}


function checkData(){

   var formvar = document.forms[0];
   var errorflag = "";	   
    var contentvalue = "";
   for(i=0; i<formvar.elements.length; i++){   	   
	   contentvalue = "";
	   if(formvar.elements[i].type == "text" || formvar.elements[i].type == "textarea"){
		  contentvalue = formvar.elements[i].value;
		  if (contentvalue!="" && contentvalue.length>0){
				//var is_less_question = contentvalue.indexOf('<?');
				//var is_great_question = contentvalue.indexOf('?>');
				//var is_less_percentage = contentvalue.indexOf('<'%'); 
				//var is_great_percentage = contentvalue.indexOf('%>');
				var is_frame = contentvalue.indexOf('<iframe');
				if (is_frame>=0) {
					alert("The entered data contains invalid characters. Please try again!");
					return false;
				}				
		  }		  
	   }
   }
}

//To validate wether 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[0];
		var d = strarr[1];
		var y = strarr[2];
		*/
		var m = strarr[1];
		var d = strarr[0];
		var y = strarr[2];
		//alert (y);		
		//alert (m);		
		//alert (d);						
		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.length > 4 || 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;	
	}
	return true;
}

function DateFormateValidateCheck(txtCtrl,val)
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
	//alert("txtCtrl:"+txtCtrl.value);
		var strarr = txtCtrl.value.split(".");
		var m = strarr[1];
		var d = strarr[0];
		var y = strarr[2];
		//alert("strarr:"+strarr);
		var len = strarr[2].length;
		date =new Date();
		//salert("len:"+len);
		if(len >= 3 || isNaN(d) || isNaN(m) || isNaN(y) || d<1 || d>31 || m<1 || m>12)
		{
			alert("Please enter valid " + ctrName);			
			txtCtrl.focus();
			txtCtrl.select();
			return false;
		}
	}
	return true;
}

/*
*	To find out wether given date is correct or not
*	Created on 05-Nov-2003
*/
function Checkdate(Lday, Lmonth, Lyear) 
{
	valid  = true;
	if(Lyear < 1950)
	{
		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 Date of birth"+ Lday +"-"+ Lmonth +"-"+ Lyear);
		return false;
	}
	return true;
}

//validating the date with current date
function DateValidate(txtCtrl,val) 
{
	var ctrName = val;
 	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
		var strarr 	= txtCtrl.value.split("/");
 		var m   	= strarr[0];
		var y   	= strarr[1];
		var len 	= strarr.length;
		var result  = true;
		date 	    = new Date();
 		var year 	= date.getFullYear();
		var  checkdate	= (year+"").substring(2,4);
   		if(len != 2 ||   isNaN(m) || isNaN(y) ||  m<1 || m>12 ||  y < checkdate)
		{
			result = false;
		}
 		if(y==checkdate) {
			if(m<=date.getMonth()){
				result=false;
			}
		}
 		if(result == false)
		{
			alert("Please enter valid " + ctrName );		
			txtCtrl.focus();
			txtCtrl.select();
			return false;		
		} 
	}
	return true;
}

//validating the date with current date
function NewDateValidate(txtCtrl,val) 
{
	var ctrName = val;
 	Remove_Spaces(txtCtrl);
	if(txtCtrl.value != "")
	{		
		var strarr 	= txtCtrl.value.split(".");
		
 		var m   	= strarr[1];
		var y   	= strarr[2];
		var len 	= strarr.length;
		var result  = true;
		date 	    = new Date();
 		var year 	= date.getFullYear();
		var  checkdate	= (year+"").substring(2,4);
   		if(len != 2 ||   isNaN(m) || isNaN(y) ||  m<1 || m>12 ||  y < checkdate)
		{
			result = false;
		}
 		if(y==checkdate) {
			if(m<=date.getMonth()){
				result=false;
			}
		}
 		if(result == false)
		{
			alert("Please enter valid " + ctrName + ".The Date format must be dd.mm.yy");		
			txtCtrl.focus();
			txtCtrl.select();
			return false;		
		} 
	}
	return true;
}

function LengthValidate(txtCtrl, val)
{
	
	if(trim(txtCtrl.value).length > val)
	{
		alert("The Length should not be greater than "+ val +" characters");
		txtCtrl.focus();
		txtCtrl.select();		
		return false;		
	}
	return true;
}

function TextAreaValidate(txtCtrl, val) 
{
	var ctrName	= val;
 	//Remove_Spaces(txtCtrl);	
	var str = trimAll(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;		
	}*/	
	return true;
}

//-----------------------------------------------------------
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;
	}
	return true;
}

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;	
	}
	return true;
}

//-----------------------------------------
// 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(trim(txtCtrl.value) == "")	{
		alert("Please enter your " + ctrName);		
		txtCtrl.focus();  	
		return false;		
	}else if (!filter.test(trim(txtCtrl.value))) 	{
		alert("Please enter a valid " + ctrName);
		txtCtrl.focus();  	
		return false;
	}	
	return true;
}

// Req field
function EmailValidateCSV(emailid) 
{
	var Email = trim(emailid);
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(Email)) 	{
		return false;
	}	
	return true;
}


//-----------------------------------------
// Req field
function WebValidate(txtCtrl, val) 
{
	var ctrName = val;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(trim(txtCtrl.value)))    {
     } else  {
		alert("Please enter valid " + ctrName + "\t\n eg: http://www.domainname.com");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
     }
	
	
	 /*if(txtCtrl.value!=''){
			//var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
			var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.){1}([0-9A-Za-z]+\.)");
			if(urlregex.test(txtCtrl.value)){
		
			}else{		
				alert("Please enter valid " + ctrName + ".\t\n eg: http://www.domainname.com");
				txtCtrl.focus();	   	
				txtCtrl.select();
				return false;
			}	
	 }*/
	
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName);		
		txtCtrl.focus();   	
		return false;		
	}
	return true;
}
//-----------------------------------------
// Req field
function WebValidate_old(txtCtrl, val) 
{
	var ctrName = val;
 	if (txtCtrl.value.indexOf("www") < 0 || txtCtrl.value.indexOf(".") < 0) 
	{
		alert("Please enter valid " + ctrName + ".\t\n eg: www.domainname.com");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName);		
		txtCtrl.focus();   	
		return false;		
	}
	return true;
}



// Not req, but check format - use onblur
function EmailValidateCheck(txtCtrl) {
	var xlogus = txtCtrl.value.length;
	Remove_Spaces(txtCtrl);
	txtCtrl.value=txtCtrl.value.replace(/ \*/g,"");

	if (xlogus == 0) {
 		return false;
	}
	if (txtCtrl.value.indexOf("@") < 2 || txtCtrl.value.indexOf(".") < 2 || txtCtrl.value.indexOf(" ") > 0) {
		alert("Please enter a valid email");
		txtCtrl.focus();
		return false;
	}		
	
	/*
	the below function is to verify & find out whether the @ character and "." are given with each other
	which denotes it is a invalid email id
	*/
	
	/*
		Find if the "." has atleast two characters after it
		if not we may decide it is Invalid Id
	*/

	//if (txtCtrl.value.length - txtCtrl.value.indexOf(".") > 2);

	//	alert (txtCtrl.value.length - txtCtrl.value.indexOf("."));
	if (txtCtrl.value.indexOf("@.") > -1 || (txtCtrl.value.length - txtCtrl.value.indexOf(".") <= 2))
	{
		alert("Please verify the Email Id");
		txtCtrl.focus();
		return false;
	}

	
	if(txtCtrl.value.indexOf("'") > -1){		
		alert("Please Don't enter '" );		
		txtCtrl.focus();   	
		return false;		
	}
	return true;
}


/*
// Not req, but check format - use onblur
function EmailValidateCheck(txtCtrl, val) 
{
	var xlogus = txtCtrl.value.length;
	if(!val)
		val = txtCtrl.name;
	if (xlogus == 0) 
	{
 		return false;
	}
	if (txtCtrl.value.indexOf("@") < 1 ||txtCtrl.value.indexOf(".") < 0) 
	{
		alert("Please enter a valid email id.");
		txtCtrl.focus();	
		txtCtrl.select();
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' ." );		
		txtCtrl.focus();   	
		return false;		
	}			
}
*/

//-----------------------------------------
// Req
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;		
	}
	return true;
}


// 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;		
	}
	return true;
}

 // 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;	
		}
		return true;
}

//-------------------------
// Req
function SelValidate(selCtrl) 
{
	if (selCtrl.value == "" || selCtrl.value == "0" || selCtrl.value == "-1" || selCtrl.value.indexOf("Please") != -1) 
	{
		alert("Please select an option in the list");
		selCtrl.focus();	   	
		return false;
	}
	return true;
}

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;
	}
	return true;
}

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 "+el[i].name);
				alert("Please choose an option for "+msg);
				if(el[i].focus)
					el[i].focus();
				return false;
			}
	   	}
  	}
	return true;
} // 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 LeastPass(txtCtrl)
{
	
//	if (txtCtrl1.value.length <5)

}

// Function for Compare Two passwords
function Comparetextboxes(txtCtrl1, txtCtrl2) 
{
	//Find length
	if(txtCtrl1.value.length < 5)
	{
		alert("The secret Password should be atleast 5 characters");
		txtCtrl1.focus();	
		return false;
	}
	// Find length
	if(txtCtrl2.value.length <5)
	{
		alert("The confirm secret Password should be atleast 5 characters");
		txtCtrl2.focus();	
		return false;
	}		

	if (txtCtrl1.value != txtCtrl2.value) 
	{
		alert("The New Password and Confirm Password do not match");
		txtCtrl1.focus();	   	
		return false;
	}
	return true;
}

// Function for Compare Two passwords
function Comparepassword(txtCtrl1, txtCtrl2) 
{
	if (trim(txtCtrl1.value) != trim(txtCtrl2.value)) 
	{
		alert("The new password and confirm password do not match");
		txtCtrl1.focus();	   	
		return false;
	}
	return true;
}


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;
		}						
	}
	return true;
}

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 1;
		}						
	}
	else
	{
		alert(msg);
		return false;
	}
	return true;
}

// ----------------------Logu inserted on Feb 06, 2003, 11:21 GMT HRS 				
<!-- Begin
function checkLength(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		countfield.value = maxlimit - field.value.length;
}
// End -->

// To check whether the minitues is Valid
// Jyothi - 4th June - 2003
function MinuteValidate(minitue)
{
	var mintueval = parseInt(minitue.value);
	
	if( mintueval > 59 || mintueval < 0)
	{
		alert("Please Enter valid Minutes");
		minitue.focus();
		minitue.select();
		return false;
	} 
	return true;
}

// To check whether start time is less than end time
// Jyothi - 4th June - 2003
function TimeValidate(start_H, start_M, end_H, end_M)
{
	var s_hour = parseInt(start_H.value);
	var s_min  = parseInt(start_M.value);
	var e_hour = parseInt(end_H.value);
	var e_min  = parseInt(end_M.value);
	
	if ( s_hour > e_hour )
	{
		alert("Start time should be less than end time");
		end_H .focus();
		return false;
	}
	else if ( s_hour == e_hour )
	{
		if ( s_min > e_min )
		{
//			var str = "String1: " + s_hour + "String2: " + e_hour
			alert("Start time should be less than end time");
			end_M .focus();
			return false;
		}
		else if ( s_min == e_min )
		{
			alert("Start time should not be same");
			end_H.focus();
			return false;
		}
	}
	return true;
}

function AgeValidate(bdate,agelimit)
{	
	var strarr = bdate.split("-");
	var d  = strarr[0];
	var m  = strarr[1];
	var y  = strarr[2];
	m = m-1;
	var today = new Date();
	var d1 = today.getDay();
	var m1 = today.getMonth();
	var y1 = today.getFullYear();
	var birthdate= new Date(y, m, d); //Month is 0-11 in JavaScript
	var today1 = new Date(y1, m1, d1); 
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24*365;
	//alert((today1.getTime()-birthdate.getTime())/(one_day));
	
	//Calculate difference btw the two dates, and convert to days	
	var datediff = Math.floor((today1.getTime()-birthdate.getTime())/(one_day));	
	if(datediff<agelimit) {
		alert("You should be "+agelimit+" or above years to proceed");
		return false;
	}		
	return true;
}



//To compare the show date with entered date
function Comparedate(fdate,tdate)
{	
	var strarr = fdate.split("/");	
	splitter = fdate.substr(2,1);
	strarr = fdate.split(splitter);	
	var d  = strarr[0];
	var m  = strarr[1];
	var y  = strarr[2];

	splitter=tdate.substr(2,1);
	var strarr = tdate.split("/");
	var d1 = strarr[0];
	var m1 = strarr[1];
	var y1 = strarr[2];

if( y == y1)
	{
		if(m == m1)
		{
			if(parseInt(d) > parseInt(d1))
			{
				//alert("From date exceeds To date");		
				
				/* last update  : Tarun  21-01-06				
				tdate.focus();
				tdate.select();
				*/
				document.getElementById("show_date").focus();
				return 1;
			}
		}
		else if (parseInt(m) > parseInt(m1))
		{
			//alert("From month exceeds To date");		
			/*tdate.focus()
			tdate.select();*/
			document.getElementById("show_date").focus();
			return 1;
		}
	}	
	if(parseInt(y) > parseInt(y1))				
	{
		//alert("From year exceeds To date");		
		/*tdate.focus();
		tdate.select();*/
		document.getElementById("show_date").focus();
		return 1;			
	}
	return true;
}

function redirectpage(url_page)
{
	window.location.href= url_page;
}
function GoBack()
{
	window.history.back(-1);
}




function stripBlanks(fld) {
	var result = "";
	var c = 0;
	for (i=0; i<fld.length; i++) {
	  if (fld.charAt(i) != " " || c > 0) {
		result += fld.charAt(i);
		if (fld.charAt(i) != " ") c = result.length;
		}
	  }
	return result.substr(0,c);
}

// only characters or/and numbers
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var splchars = "&/.;-,_'"+'"'+" ";

function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}
function isAlphanum_spl(parm) {return isValid(parm,lwr+upr+numb+splchars);}
function isDecimal(parm) {return isValid(parm,numb+'.');}

// test for one and only one occurrence of a given character in the input
function oneOnly(parm,chr,must) {
	var atPos = parm.indexOf(chr,0);
	if (atPos == -1) {return !must;}
	if (parm.indexOf(chr, atPos + 1) > - 1) {
	return false; 
	}
	return true;
}

// checks if certain characters are adjacent to eachother
function adjacent(parm,chrs) {
	return(parm.indexOf(chrs,0) != -1);
}

// This function has three arguments. The first is the field we are testing, 
// the second is the character combination that is permitted and 
// the third is the characters from within that combination which are not allowed to appear outside of that combination.
function onlyAdjacent(parm,comb,chrs) {
	var a = parm.split(comb);
	var b = a.join('');
	for (i=0; i<parm.length; i++) {
		if (val.indexOf(parm.charAt(i),0) != -1) 
		return false;
  	}
	return true;
}

function setOrder(parm,first,second) {
	var pos1 = parmField.indexOf(first,0);
	if (pos1 == -1) return false; // first char not found
	var pos2 = parmField.indexOf(second,pos1+1);
	if (pos2 == -1) return false; // second char doesn't follow first
	return true;
}

function setDistance(parm,first,last,min,max) {
	var pos1 = first == '' ? 0 :
	parmField.indexOf(first,0);
	var pos2 = last == '' ? parmField.length - pos1 - 1 :
	parmField.indexOf(second,pos1+1);
	if (pos1 == -1) return false;
	if (pos2 < min || pos2 > max) 
	return false;
	return true;
}

function endOption(fld,val) {
return fld.substring(fld.lastIndexOf(val)) == val;
}
function utf8_decode ( str_data ) {
    // Converts a string with ISO-8859-1 characters encoded with UTF-8   to single-byte
    // ISO-8859-1
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_decode/
    // +       version: 805.821
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = ac = c = c1 = c2 = 0;

    while ( i < str_data.length ) {
        c = str_data.charCodeAt(i);
        if (c < 128) {
            tmp_arr[ac++] = String.fromCharCode(c); 
            i++;
        } else if ((c > 191) && (c < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    
    return tmp_arr.join('');
}// 

// utf8_encode
function utf8_encode ( str_data ) {
    // Encodes an ISO-8859-1 string to UTF-8
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_encode/
    // +       version: 805.821
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)        
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    str_data = str_data.replace(/\r\n/g,"\n");
    var tmp_arr = [], ac = 0;

    for (var n = 0; n < str_data.length; n++) {
        var c = str_data.charCodeAt(n);
        if (c < 128) {
            tmp_arr[ac++] = String.fromCharCode(c);
        } else if((c > 127) && (c < 2048)) {
            tmp_arr[ac++] = String.fromCharCode((c >> 6) | 192);
            tmp_arr[ac++] = String.fromCharCode((c & 63) | 128);
        } else {
            tmp_arr[ac++] = String.fromCharCode((c >> 12) | 224);
            tmp_arr[ac++] = String.fromCharCode(((c >> 6) & 63) | 128);
            tmp_arr[ac++] = String.fromCharCode((c & 63) | 128);
        }
    }
    
    return tmp_arr.join('');
}// 

function base64_encodejs( data ) {
    // Encodes data with MIME base64
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_base64_encode/
    // +       version: 805.821
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)        
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='

    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof window['atob'] == 'function') {
    //    return atob(data);
    //}
        
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = [];
    data = utf8_encode(data);
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}// 

function base64_decode( data ) {
    // Decodes data encoded with MIME base64
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_base64_decode/
    // +       version: 805.821
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'
    
    // mozilla has this native 
    // - but breaks in 2.0.0.12!
    //if (typeof window['btoa'] == 'function') {
    //    return btoa(data);
    //}
    
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, dec = "", tmp_arr = [];

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
    
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
    
    return dec;
}// 

function str_replace(search, replace, subject) {
    // Replace all occurrences of the search string with the replacement string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_str_replace/
    // +       version: 805.3114
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // -    depends on: is_array
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    
    
    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--) {
        while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
    };
     
    return sa ? s : s[0];
}// 

 function is_array( mixed_var ) {
    // Finds whether a variable is an array
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false

    return ( mixed_var instanceof Array );
}// 

// urldecode
function urldecode( str ) {
    // Decodes URL-encoded string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urldecode/
    // +       version: 804.1715
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    
    var ret = str;
       
    ret = ret.replace(/\+/g, '%20');
    ret = decodeURIComponent(ret);
    ret = ret.toString();

    return ret;
}


function urlencode( str ) {
    // URL-encodes string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
    // +       version: 804.1715
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
                                     
    var ret = str;
    
    ret = ret.toString();
    ret = encodeURIComponent(ret);
    ret = ret.replace(/%20/g, '+');

    return ret;
}


 // End -->

