
// check box
function boxCheck(frm,stat)
		{
			   var frm_el=frm.elements; 
			   for(var i=0;i<frm_el.length;i++)
						{
			   if(frm_el[i].type=="checkbox")frm_el[i].checked=stat;
   			}
 		}


function go()
{
	if (document.selector.select1.options[document.selector.select1.selectedIndex].value != "none") 
	{
		location = document.selector.select1.options[document.selector.select1.selectedIndex].value
		
	}
}

// restricting a user to enter space
			
function nospace(e)
	{
		if (!e) var e = window.event;  //for IE
				
		var code;
		if(e.keyCode) code = e.keyCode; //for IE
		if(e.which) code = e.which;  //for other browsers
			
		if (code == " ".charCodeAt(0)) return false;
		else return true;
	}

function VerifyMsg(f) {
	if (window.document.sendsmsindv.chkEngArabic.checked == false)
		{ 	 
	
	var len = f.value.length
	var cl
	if ((len == 1) && (f.value.substring(0, 1) == " ")) {
		f.value = ""
		len = 0
	}
	if (len > 160) {
		f.value = f.value.substring(0, 160)
		cl = 0
	}
	else {
		cl = 160 - len
	}
	document.sendsmsindv.AVCHR.value = cl
}
else
{
   
   var len = f.value.length
	var cl

	if ((len == 1) && (f.value.substring(0, 1) == " ")) {
		f.value = ""
		len = 0
	}
	if (len > 70) {
		if (event.keyCode !=8)	f.value = f.value.substring(0, 70)
		cl = 0
	}
	else {
		cl = 70 - len
	}
	document.sendsmsindv.AVCHR.value = cl

}


}
function refreshCharCounter(thisForm) {
		var smsMaxLen = 160;
	var useTaglineDiscount = false;

	var currLen = smsMaxLen-thisForm.elements['message'].value.length;
		if (useTaglineDiscount) currLen -= 17;
		thisForm.elements['AVCHR'].value = currLen;
	}




	function setpropertybackup()
	{
		var strStatusEnable;
		strStatusEnable = window.document.NewCustomer.SelCountry.options[window.document.NewCustomer.SelCountry.selectedIndex].value;
		for (var i=0; i < window.document.NewCustomer.SelCountry.length; i++)
		{ 
			if (strStatusEnable == window.document.NewCustomer.SelCountry.options[i].value  )
			{
				window.document.NewCustomer.SelCountry.options[i].selected=true ;  
				if (window.document.NewCustomer.SelCountry.options[i].selected)
				{
					strStatusEnable = window.document.NewCustomer.SelCountry.options[i].value;
				}
			}
			if((strStatusEnable == 'Bahrain'))
			{	
				window.document.NewCustomer.txtCPRCRNo.disabled=false;
				window.document.NewCustomer.optCPRCR.disabled=false;
			}
			if (strStatusEnable != 'Bahrain')
			{	
				window.document.NewCustomer.txtCPRCRNo.value='';
				window.document.NewCustomer.txtCPRCRNo.disabled=true;
				window.document.NewCustomer.optCPRCR.disabled=true;
			}
		}
		
	}
	
	
	function setproperty()
	{
		var strStatusEnable;
		var blnVisible;
		var isIE=document.all?true:false;
		var isDOM=document.getElementById?true:false;
		var isNS4=document.layers?true:false;
		
		strStatusEnable = window.document.NewCustomer.SelCountry.options[window.document.NewCustomer.SelCountry.selectedIndex].value;
			if((strStatusEnable == 'Bahrain'))
			{	
			/*	if(isIE)
				{
					eval("document.all.divt1.style.visibility='visible';");
					eval("document.all.divt2.style.visibility='visible';");
					eval("document.all.divt3.style.visibility='visible';");
				}
				else
				{
					window.document.NewCustomer.txtCPRCRNo.disabled=false;
					window.document.NewCustomer.optCPRCR.disabled=false;				
				}
			*/
			show('myLayer1');
			show('myLayer11');
				
			}
			if (strStatusEnable != 'Bahrain')
			{	
			/*	if(isIE)
				{
					eval("document.all.divt1.style.visibility='hidden';");
					eval("document.all.divt2.style.visibility='hidden';");
					eval("document.all.divt3.style.visibility='hidden';");
				}
				else
				{
					window.document.NewCustomer.txtCPRCRNo.value='';
					window.document.NewCustomer.txtCPRCRNo.disabled=true;
					window.document.NewCustomer.optCPRCR.disabled=true;
				}
			*/
			hide('myLayer1');
			hide('myLayer11');
				
			}
			
			
			
					
	}
	
	function setproperty2()
	{
		var strCategory;
		strCategory = window.document.NewCustomer.SelCategory.options[window.document.NewCustomer.SelCategory.selectedIndex].value;
		for (var i=0; i < window.document.NewCustomer.SelCategory.length; i++)
		{ 
			if (strCategory == window.document.NewCustomer.SelCategory.options[i].value  )
			{
				window.document.NewCustomer.SelCategory.options[i].selected=true ;  
				if (window.document.NewCustomer.SelCategory.options[i].selected)
				{
					strCategory = window.document.NewCustomer.SelCategory.options[i].value;
				}
			}
		}
	}
	
	function setlength(ival)
	{
		if (ival == 0)
		{	
			window.document.NewCustomer.txtCPRCRNo.value='';
			window.document.NewCustomer.txtCPRCRNo.maxLength=9;
		}
		if (ival == 1)
		{	
			window.document.NewCustomer.txtCPRCRNo.value='';
			window.document.NewCustomer.txtCPRCRNo.maxLength=11;
		}
	}

	var strMissingInformation = '';
	function checkFields()
	{
		strMissingInformation ='';
		if (window.document.NewCustomer.txtCustId.value == '')			strMissingInformation += '\nUsername\t Cannot be blank';
		if (window.document.NewCustomer.txtCustId.value.length < 6)		strMissingInformation += '\nUsername\t Must be between 6 and 10 characters long';
		if (window.document.NewCustomer.txtCustId.value != '') 
		{
			var LoginNamePat = /[^A-Za-z0-9]/;
			var matchArray = document.NewCustomer.txtCustId.value.match(LoginNamePat);
			if (matchArray != null) 
			{
				strMissingInformation += '\nUsername \t Must contain only alphanumeric characters ';
		    }
		}
		var strPin = window.document.NewCustomer.txtPin.value
		if (strPin == '')				strMissingInformation += '\nPassword\t\t Cannot be blank';
		if (strPin.length < 6)			strMissingInformation += '\nPassword\t\t Must be between 6 and 10 characters long';
		var strVerifyPassword = window.document.NewCustomer.txtVerifyPassword.value
		if (strVerifyPassword == '')	strMissingInformation += '\nVerify Password\t Cannot be blank';
		if (window.document.NewCustomer.txtPin.value !== window.document.NewCustomer.txtVerifyPassword.value) strMissingInformation += ' \nVerify Password\t Must match with the password '
		if (window.document.NewCustomer.txtFirstName.value == "") 
		{ 
			strMissingInformation += '\nFirst Name \t Cannot be blank';
		}
		if (window.document.NewCustomer.txtLastName.value == "") 
		{ 
			strMissingInformation += '\nLast Name \t Cannot be blank';
		}
		
		if (window.document.NewCustomer.txtCompanyName.value == "") 
		{ 
			strMissingInformation += '\nCompany Name \t Cannot be blank';
		}
		if (window.document.NewCustomer.SelCountry.value == 'Bahrain') 
		{ 
			if (window.document.NewCustomer.txtCPRCRNo.value == '')
			{
				strMissingInformation += '\nCPR/CR No \t Cannot be blank';
			}
		}
		if (window.document.NewCustomer.txtMobile.value == "") 
		{ 
			strMissingInformation += '\nMobile No \t Cannot be blank';
		}
		if (window.document.NewCustomer.txtEmail.value == "") 
		{ 
			strMissingInformation += '\nE-mail ID \t\t Cannot be blank';
		}
		if (window.document.NewCustomer.txtEmail.value != "") 
		{	
			var checkEmail = "@.";
			var checkStr = window.document.NewCustomer.txtEmail.value;
			var EmailValid = false;
			var EmailAt = false;
			var EmailPeriod = false;
			for (i = 0;  i < checkStr.length;  i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkEmail.length;  j++)
				{
					if (ch == checkEmail.charAt(j) && ch == "@")
						EmailAt = true;
					if (ch == checkEmail.charAt(j) && ch == ".")
						EmailPeriod = true;
					if (EmailAt && EmailPeriod)
						break;
					if (j == checkEmail.length)
						break;
				}// if both the @ and . were in the string
			}
			if  (!(EmailAt && EmailPeriod))
			{
				//	EmailValid = true
				//	break;
				strMissingInformation += '\nE-mail ID \t\t Must be entered in abc@xyz.com format';
			}
		}
		//if (window.document.NewCustomer.txtAddress1.value == "") 
		//{ 
		//	strMissingInformation += '\nAddress #1 Cannot be blank';
		//}
		if (window.document.NewCustomer.txtCity.value == "") 
		{ 
			strMissingInformation += "\nCity   \t\t Cannot be blank";
		}
		if (window.document.NewCustomer.txtQ1.value == "") 
		{ 
			strMissingInformation += "\nPersonal ID number  Cannot be blank";
		}
		if (window.document.NewCustomer.txtQ2.value == "") 
		{ 
			strMissingInformation += '\nDate of Birth \t Cannot be blank';
		}
		else
		{
			if (!validDate(document.NewCustomer.txtQ2,"Date of Birth"))
				return false;
			if (!validFromDate(document.NewCustomer.txtQ2,document.NewCustomer.hdnnowdate,0))
				return false;
			
		}
		if (window.document.NewCustomer.txtQ3.value == "") 
		{ 
			strMissingInformation += '\nCity of Birth\t Cannot be blank';
		}
		if (strMissingInformation != '')
		{	
			strMissingInformation   = 'Incorrect values entered.\n_____________________________\n' +
									  'Items\t\tRemarks\n' +
									  '_____________________________' +
									  strMissingInformation +
									  '\n_____________________________\nPlease enter correct values and submit again.';
			alert(strMissingInformation);
			window.document.NewCustomer.reg.value = 0;
			return false ;
		}
		else 
		{
			window.document.NewCustomer.reg.value = 1;
			return true;
		}	
	}
	
	
	var dtCh= "/";
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,fieldLabel){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=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 (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert('Please enter a valid day in the "' + fieldLabel +'" field.')
		return false
		}
	
return true
}


function validDate(formField,fieldLabel)
	{
		var result = true;
		var monthresult = true;
		var dayresult = true;
		if (result)
		{
			var elems = formField.value.split("/");     
			result = (elems.length == 3); // should be three components     
			if (result)
			{
				var year = parseInt(elems[0]);
				var month;
				if(elems[1].charAt(0) == '0')
				{
					month = parseInt(elems[1].charAt(1));
				}
				else
				{	
					month = parseInt(elems[1]);
				}	
				var day;
				if(elems[2].charAt(0) == '0')
				{
					day = parseInt(elems[2].charAt(1));
				}
				else
				{	
					day = parseInt(elems[2]);
				}	
				monthresult = !isNaN(month) && (month > 0) && (month < 13);
				dayresult = !isNaN(day) && (day > 0) && (day < 32);
				result = !isNaN(year) && (elems[0].length == 4) &&
						 !isNaN(month) && (month > 0) && (month < 13) &&
						 !isNaN(day) && (day > 0) && (day < 32); 
			}
			if ((!monthresult) && (!dayresult)) 
			{
				alert('Please enter a valid month and day in the "' + fieldLabel +'" field.');
				formField.focus();    
				return false;
			}      
			else if (!monthresult)
			{
				alert('Please enter a valid month in the "' + fieldLabel +'" field.');
				formField.focus();    
				return false;
			}   
			else if (!dayresult)
			{
				alert('Please enter a valid day in the "' + fieldLabel +'" field.');
				formField.focus();    
				return false;
			}      
			else if (!result)
			{
				alert('Please enter the date in YYYY/MM/DD format in the "' + fieldLabel +'" field.');
				formField.focus();    
				return false;
			}
			
			
		}   
		
		if (isDate(formField.value,fieldLabel)==false)
			{
				formField.focus();
				return false
			}
		
		
		return result;
	}


	function validFromDate(formFromdate,formTodate,ieu)
	{
		var validdate = true;
		var fromdateelems = formFromdate.value.split("/");     
		var fromyear = parseInt(fromdateelems[0]);
		var frommonth;
		
		frommonth = parseInt(fromdateelems[1]);			
		if (fromdateelems[1].charAt(0) == '0')
		{
			frommonth = parseInt(fromdateelems[1].charAt(1));
		}
		else
		{
			frommonth = parseInt(fromdateelems[1]);
		}						
		var fromday;
		fromday = parseInt(fromdateelems[2]);
		if (fromdateelems[2].charAt(0) == '0')
		{
			fromday = parseInt(fromdateelems[2].charAt(1));
		}
		else
		{
			fromday = parseInt(fromdateelems[2]);
		}
		var todateelems = formTodate.value.split("/");
		var tomonth;
		tomonth = parseInt(todateelems[1]);			
		if (todateelems[1].charAt(0) == '0')
		{
			tomonth = parseInt(todateelems[1].charAt(1));
		}
		else
		{
			tomonth = parseInt(todateelems[1]);
		}						
		var today;
		today = parseInt(todateelems[2]);
		if (todateelems[2].charAt(0) == '0')
		{
			today = parseInt(todateelems[2].charAt(1));
		}
		else
		{
			today = parseInt(todateelems[2]);
		}						
		var toyear = parseInt(todateelems[0]);
		if (fromyear == toyear)
		{			
			if (frommonth < tomonth)
			{	
				validdate = true;					
			}
			else
			{	
				if (frommonth == tomonth)
				{
					if (fromday <= today) 
					{
						validdate = true;
					}
					else
					{
						validdate = false;
					}
				}
				else
				{
					if (frommonth > tomonth)
					{
						validdate = false;
					}
				}
			}						   
		}
		else 
		{
			if ( fromyear < toyear )
			{
				validdate = true;
			}
			else
			{
				validdate = false;
			}		
		}
		if(!validdate)
		{
			if (ieu == 0) {
			    	alert('The "Date Of Birth" value cannot be later than your current system date.');
		    	}
		   
			formFromdate.focus();
		}	
		return validdate;   
	} 

	

	function getkey(e)
	{
		if (window.event)
		return window.event.keyCode;
		else if (e)
		return e.which;
		else
		return null;
	}

	function goodchars(e, goods)
	{
		var key, keychar;
		key = getkey(e);
		if (key == null) return true;
		// get character
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		goods = goods.toLowerCase();
		// check goodkeys
		if (goods.indexOf(keychar) != -1)
		return true;
		// control keys
		if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
		// else return false
		return false;
	}



function show(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.visibility='visible';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
}

function hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.visibility='hidden';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
         document.all[object].style.visibility = 'hidden';
}

 function downloadagree()
 {
	_init();	
	 
 }
 
function popUp(height, width, url)
{
	var thisWin;
	var sParams = 'height='+height+','; 
	    sParams += 'width='+width+','; 
		sParams += 'toolbar=no,'; 
		sParams += 'status=no,'; 
		sParams += 'scrollbars=no,'; 
		sParams += 'directories=no,'; 
		sParams += 'location=no,'; 
		sParams += 'menubar=no'; 
	if(!thisWin)
	{	
		thisWin = window.open(url,"mdhducont",sParams); 
	}
	else
	{	thisWin.document.location = url;
		thisWin.focus()
	}
}

/*	function _init()
	{
		popUp(600, 900, 'AgreementDownload.asp');
					// window.showModalDialog("Popuppage.asp","Dialog Arguments Value","dialogHeight: 278px; dialogWidth: 508px; dialogTop: 74px; dialogLeft: 677px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
	}
*/

	function getkeyName(e)
	{
		if (window.event)
		return window.event.keyCode;
		else if (e)
		return e.which;
		else
		return null;
	}

	function goodcharsName(e, goods)
	{
		var key, keychar;
		key = getkeyName(e);
		//alert(key);
		if (key == null) return true;
		// get character
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		goods = goods.toLowerCase();
		// check goodkeys
		goods = goods + "?.!-()[]/;,:'\""
		//alert(goods);
		if (goods.indexOf(keychar) != -1)
		return true;
		// control keys
		if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
		// else return false
		return false;
	}

	function setDate(frm,mydate1, mydate2,flag)
{
	// set day/month/year
	var mymonth, myday, myyear;
	if(flag>1)
	{
		if (mydate1 == '')
		{
			mydate1 = new Date();
			myyear	= mydate1.getFullYear();
			mymonth = mydate1.getMonth() + 1;
			myday	= mydate1.getDate();
		}
		else
		{
			myyear	= mydate1.substr(0,4);
			mymonth = mydate1.substr(5,2);
			myday	= mydate1.substr(8,2);
		}
		
		
		eval("document."+frm+".cboFromYear.selectedIndex =  myyear -  document."+frm+".cboFromYear.options[0].value;");
		if(mymonth == 1)
		{
			eval('document.'+frm+'.cboFromMonth.selectedIndex = mymonth - 1;');	
		}
		else
		{
		eval('document.'+frm+'.cboFromMonth.selectedIndex = mymonth - 2;');
		}
		eval("document."+frm+".cboFromDay.selectedIndex =  myday - 1;");	

		if(frm == 'ARSQuote' || frm == 'ARSInv' || frm == 'ARSOrder' || frm == 'CustomerMaster' || frm == 'YrEndClosing' || frm == 'APOrder' )
		{
			var cboYear,cboMonth,cboday;
			
			if (mydate2 == '')
			{
				mydate2 = new Date();
				myyear = mydate2.getFullYear();
				mymonth = mydate2.getMonth() + 1;
				myday = mydate2.getDate();
			}
			else
			{
				myyear = mydate2.substr(0,4);
				mymonth = mydate2.substr(5,2);
				myday = mydate2.substr(8,2);
			}
			
			if(frm == 'CustomerMaster')
			{
				cboYear  = "cboExpFromYear";
				cboMonth = "cboExpFromMonth"; 
				cboDay   = "cboExpFromDay";
			}
			else if(frm == 'YrEndClosing')
			{
				cboYear  = "cboToYear";
				cboMonth = "cboToMonth"; 
				cboDay   = "cboToDay";
			}
			else			
			{
				cboYear  = "cboDueFromYear";
				cboMonth = "cboDueFromMonth"; 
				cboDay   = "cboDueFromDay";
			}
			
			eval("document."+frm+"."+cboYear+".selectedIndex  =  + myyear - document."+frm+"."+cboYear+".options[0].value;");
			eval("document."+frm+"."+cboMonth+".selectedIndex =  mymonth - 1;");	
			eval("document."+frm+"."+cboDay+".selectedIndex =  myday - 1;");	
		}
	}
}


function selectDate ( frm,day, month, year)
{
	// Get currently selected month/year
	objMonth = eval ( 'document.'+frm+ '.' + month );
	curMonth = objMonth.options[objMonth.selectedIndex].value;
	objYear = eval ( 'document.'+frm+'.' + year );
	curYear = objYear.options[objYear.selectedIndex].value;
	date = curYear;
	
	if ( curMonth < 10 )
	date += "0";
	date += curMonth;
	date += "01";
	if(frm == 'BudgList' || frm == 'CurrencyMaster')
		url = "DateSel.php?form="+frm+"&day=" + day + "&month=" + month + "&year=" + year + "&date=" + date;	
	else
		url = "../DateSel.php?form="+frm+"&day=" + day + "&month=" + month + "&year=" + year + "&date=" + date;

	
	// Show the calendar window positioned according to the button clicked
	var appName=navigator.appName;
	if(appName=="Netscape")
	{
		if (month=="cboFromMonth")
			var popupWin = window.open(url,"DateSelection","width=165,height=150,left=248,top=183,resizable=yes,scrollbars=no");
		else if (month=="cboBFromMonth")
			var popupWin = window.open(url,"DateSelection","width=165,height=150,left=380,top=300,resizable=yes,scrollbars=no");
		else if (month=="cboEFromMonth")
			var popupWin = window.open(url,"DateSelection","width=165,height=150,left=567,top=300,resizable=yes,scrollbars=no");
		else if (month=="cboFiscalFromMonth")
			var popupWin = window.open(url,"DateSelection","width=165,height=150,left=600,top=300,resizable=yes,scrollbars=no");
	}
	else
	{
		var sx=event.x;
		var sy=event.y;

		if(sx>600)
			sx=sx-185;
		else
			sx=sx+10;
		
		sy=sy+100;
		var popupWin = eval("window.open(url,'DateSelection','width=165,height=150,left="+sx+",top="+sy+",resizable=yes,scrollbars=no')");
	}

	if(popupWin.focus) popupWin.focus();
}

function setDefDate(frm,sdate)
{
  myday = sdate.substr(0,2);
  mymonth	= sdate.substr(3,2);
  myyear =  sdate.substr(6,4);

  eval('document.'+frm+'.cboFromDay.selectedIndex = myday-1;');
  eval('document.'+frm+'.cboFromMonth.selectedIndex = mymonth-1;');
  eval('document.'+frm+'.cboFromYear.selectedIndex = myyear - document.'+frm+'.cboFromYear.options[0].value;');

  today = new Date();
  d = today.getDate() ;
  m = today.getMonth();
  y = today.getFullYear();

  //setting end default date to current date
  eval('document.'+frm+'.cboToDay.selectedIndex = d-1;');
  eval('document.'+frm+'.cboToMonth.selectedIndex = m;');
  eval('document.'+frm+'.cboToYear.selectedIndex = y - document.'+frm+'.cboToYear.options[0].value;');
}


function setDDate(frm,dateFrom,dateTo,db)
{
  if(db==1)
  {
    m1 = dateFrom.substr(0,2);
	d1	= dateFrom.substr(3,2);
	y1 =  dateFrom.substr(6,4);

    m2 = dateTo.substr(0,2);
	d2	= dateTo.substr(3,2);
	y2 =  dateTo.substr(6,4);
  }
  else
  {
	y1 = dateFrom.substr(0,4);
	m1 = dateFrom.substr(5,2);
	d1	= dateFrom.substr(8,2);

	y2 = dateTo.substr(0,4);
	m2 = dateTo.substr(5,2);
	d2	= dateTo.substr(8,2);
  }
  eval('document.'+frm+'.cboFromDay.selectedIndex = d1-1;');
  eval('document.'+frm+'.cboFromMonth.selectedIndex = m1-1;');
  eval('document.'+frm+'.cboFromYear.selectedIndex = y1 - document.'+frm+'.cboFromYear.options[0].value;');

  eval('document.'+frm+'.cboToDay.selectedIndex = d2-1;');
  eval('document.'+frm+'.cboToMonth.selectedIndex = m2-1;');
  eval('document.'+frm+'.cboToYear.selectedIndex = y2 - document.'+frm+'.cboToYear.options[0].value;');
}

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{   
       var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
     return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function daysInFebruary (year)
{
      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
}

var mo,da,ye;
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

theDate=new Date();
da=theDate.getDate();
mo=theDate.getMonth();
ye=theDate.getFullYear();      

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<1 || month>12)
	{
		alert("Please enter a valid month")
		return false
	}

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
       return false                 
	}
	
	if (strYear.length != 4 || year==0 || year<minYear || year>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 DaysDelta(v1,v2) 
{
	var delta=0;
	var a1=v1;
	var a2=v2;
	delta=a1.getTime()-a2.getTime();
	delta /=(1000*60*60*24);
	return delta;
}

function ValidateForm(frm,cboDay,cboMonth,cboYear,dtChkFlag)
{
	var d,m,y,diffDt,dt,year;
	eval('m=document.'+frm+'.'+cboMonth+'.value;');
	eval('d=document.'+frm+'.'+cboDay+'.value;');
	eval('y=document.'+frm+'.'+cboYear+'.value;');
	dt=m+"/"+d+"/"+y;

	var d2=new Date();
	var d1=new Date();

	d1.setMonth(m-1);
    d1.setDate(d);
    d1.setYear(y);	

	diffDt=DaysDelta(d1,d2);//Recent changes

	var mo1,da1,ye1,flag;
	da1=d2.getDate();
	mo1=d2.getMonth();
	ye1=d2.getFullYear(); 

	flag = isDate(dt);
	if(flag==false || ((diffDt>=32 || ((y==ye) && (m>mo+1))) && dtChkFlag==0))
	{
		eval('document.'+frm+'.'+cboDay+'.value=da;');
		eval('document.'+frm+'.'+cboMonth+'.value=mo+1;');
		eval('document.'+frm+'.'+cboYear+'.value=ye;');
	}
}	