/**	Validate for editclient form.
 * 
 * Created and commented by Girish Nambiar.
 * 
 * This validation function (frmValidatedetails(frm)) is used on form submission.
 */
//This function is using for \admin\edit_details.php , \edit_client_details.php ...
function frmValidatedetails(frm)
{
	with(frm)	  
	{
		if(person.value == 0)
		{
			if(address.value == '')	
			{
				alert("-Please enter address."); 
				address.focus(); 
				return  false;  
			}	// end if
			if(postcode.value == '') 
			{
				alert("-Please enter postcode.");	
				postcode.focus();	
				return  false;
			} 
			/*if(postcode.value != '')
			{
				var str = (dept.value).indexOf("_");
				var pcode = (dept.value).substring(0,str);
				var dcode =	'dept_code['+pcode+']';
				var dcodeObj =	document.getElementById(dcode);
				//alert(dcodeObj.value);
				if((postcode.value).substring(0,2) != dcodeObj.value)
				{
					alert("The first 2 numbers of your Post Code must match your Department Code");
					postcode.focus();
					return false;
				}
			}*/
			var ValidChars = "0123456789";
			if(postcode.value != '')
			{
				for (j = 0; j < postcode.value.length; j++)
				{
					var Char = postcode.value.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Post code must be integer");
						postcode.focus();
						return  false;
					} 
				} 
			}	
			if(town.value == '') 
			{
				alert("-Please enter town.");	
				town.focus();	
				return  false;
			} 
			if(telephone.value == '') 
			{
				alert("-Please enter telephone number.");	
				telephone.focus();	
				return  false;
			} 
			
			if(email.value != '')	// if email field is not empty
			{
				//	set the regular expression
				var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
				var membermailid = eval("email.value"); // get the email address from the email field
	
				result1=membermailid.search(emails);	// look for improper email address in email field
				if(result1==-1)	// email address in email field is not proper
				{
					alert("-Please enter valid email address."); // Display the alert box
					eval("email.focus()");	// set focus to email field
					return false;
				}
			} // email validation ends here
			else	
			{
				alert("-Please enter your email address.");	
				eval("email.focus()");		
				return false;	
			}	
			//	Compare the email address in email field with that of remail field
			/*if(email.value != remail.value)
			{
				alert("-Please re input email should match with email.");
				eval("remail.focus()");
				return false;
			}	*/
		}//end of if(person == 0)cpamno
			
			var cpamlength=cpamno.value;
			var cpamlen = cpamlength.length;
			if(cpamno.value == "")	
			{
				alert("-Please enter CPAM no."); 
				cpamno.focus(); 
				return  false;
			}	
			if(cpamlen > 0)
			{
				if(cpamlen != 15)
				{
					alert("-Cpam no. must be fifteen digit long.");
					cpamno.focus();
					return  false;
				}
			}
			var ValidChars = "0123456789";
			if(cpamlen > 0)
			{
				for (j = 0; j < cpamlength.length; j++)
				{
					var Char = cpamlength.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Cpam no. must be integer.");
						cpamno.focus();
						return  false;
					}
				}
			}
			if(height.value == "")	
			{
				alert("-Please enter height."); 
				height.focus(); 
				return  false;
			}	
			
			if(!DigitsAndDot(height))
			{
				alert("-Height : Only 0 to 9, '.' is allowed.");
				height.focus();
				return  false;
			}	
			if(weight.value == "")	
			{
				alert("-Please enter weight."); 
				weight.focus(); 
				return  false;
			}	
			if(!DigitsAndDot(weight))
			{
				alert("-Weight : Only 0 to 9, '.' is allowed.");
				weight.focus();
				return  false;
			}	
			if(occupation.value == "")	
			{
				alert("-Enter occupation."); 
				occupation.focus(); 
				return  false;
			}	
			if(!CharAndSpace(occupation))
			{
	       		alert("-Occupation : Only a to z, A to Z, and space is allowed.");
	 	 		return  false;  
			}
		return true;
	}  // with ends here
}	//	validation for client details edition ends here 


function validateclientdetails(frm)
{
	with(frm)	
	{
		if(person.value == 0)
		{
			if(address.value == '')	
			{
				alert("-Please enter address."); 
				address.focus(); 
				return  false;
			}	// end if
			if(postcode.value == '') 
			{
				alert("-Please enter postcode.");	
				postcode.focus();	
				return  false;
			} 
			var ValidChars = "0123456789";
			if(postcode.value != '')
			{
				for (j = 0; j < postcode.value.length; j++)
				{
					var Char = postcode.value.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Post code must be integer");
						postcode.focus();
						return  false;
					} 
				} 
			}	
			if(town.value == '') 
			{
				alert("-Please enter town.");	
				town.focus();	
				return  false;
			} 
			if(telephone.value == '') 
			{
				alert("-Please enter telephone number.");	
				telephone.focus();	
				return  false;
			} 
			
			if(email.value != '')	// if email field is not empty
			{
				//	set the regular expression
				var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
				var membermailid = eval("email.value"); // get the email address from the email field
	
				result1=membermailid.search(emails);	// look for improper email address in email field
				if(result1==-1)	// email address in email field is not proper
				{
					alert("-Please enter valid email address."); // Display the alert box
					eval("email.focus()");	// set focus to email field
					return false;
				}
			} // email validation ends here
			else	
			{
				alert("-Please enter your email address.");	
				eval("email.focus()");		
				return false;	
			}	
			//	Compare the email address in email field with that of remail field
			/*if(email.value != remail.value)
			{
				alert("-Please re input email should match with email.");
				eval("remail.focus()");
				return false;
			}	*/
		}//end of if(person == 0)cpamno
			
			if(height.value == "")	
			{
				alert("-Please enter height."); 
				height.focus(); 
				return  false;
			}	
			
			if(!DigitsAndDot(height))
			{
				alert("-Height : Only 0 to 9, '.' is allowed.");
				height.focus();
				return  false;
			}	
			if(weight.value == "")	
			{
				alert("-Please enter weight."); 
				weight.focus(); 
				return  false;
			}	
			if(!DigitsAndDot(weight))
			{
				alert("-Weight : Only 0 to 9, '.' is allowed.");
				weight.focus();
				return  false;
			}	
			if(occupation.value == "")	
			{
				alert("-Enter occupation."); 
				occupation.focus(); 
				return  false;
			}	
			if(!CharAndSpace(occupation))
			{
	       		alert("-Occupation : Only a to z, A to Z, and space is allowed.");
	 	 		return  false;  
			}
		return true;
	}  // with ends here
}	//	validation for client details edition ends here 

function frmValidateAddDep(frm,no,paymentType)
{
	with(frm)
	{		  
		var dateObj = new Date();
		  
		if(policy_no.value == "") /* if policy number is not input. */
		{
			alert("Enter a Policy Number before submitting.");	/* show an alert message. */
			policy_no.focus();
			pay[0].checked=false;
			pay[1].checked=false;
			return false;	/* go back to the form. */
		}
		
		if(policy_no.value!='' && no!="0")
		{
			//alert(no);
			//alert(dep.options[dep.selectedIndex].value);
			
			if(parseInt(dep.options[dep.selectedIndex].value) > 0)
			{
				var i;
				for(i=1; i<=parseInt(dep.options[dep.selectedIndex].value); i++)
				{
					var sname = 'ad_surname['+i+']';
					var SurnameObj = document.getElementById(sname);
					if(SurnameObj.value == '')
					{
						alert("-Enter Surname of Dependant"+i);
						SurnameObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}
	
					var fname = 'ad_firstname['+i+']';
					var FirstnameObj = document.getElementById(fname);
					if(FirstnameObj.value == '')
					{
						alert("-Enter Firstname of Dependant"+i);
						FirstnameObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}
					
					var arelation = 'ad_relation['+i+']';
					var arelationobj = document.getElementById(arelation);
					if(arelationobj.value=='')
					{
						alert("-Enter dependant's relation with mail applicant.");
						arelationobj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return false;
					}
					if(!CharAndSpace(arelationobj))
					{
			         		alert('-Relationship for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
				 	 		arelationobj.focus();
				 	 		pay[0].checked=false;
							pay[1].checked=false;
				 	 		return  false;
				 	 		
					}
					var ValidChars = "0123456789.";
					var aheight = 'ad_height['+i+']';
					var aheightObj = document.getElementById(aheight);
					
					var dday			=	'ad_day['+i+']';
					var dmonth			=	'ad_month['+i+']';
					var dyear			=	'ad_year['+i+']';
					//var d				=	new Date(); 
				
					
					dayobj			=	document.getElementById(dday);
					monthobj		=	document.getElementById(dmonth);
					yearobj			=	document.getElementById(dyear);
				
					if(!isDate(monthobj.value+"/"+dayobj.value+"/"+yearobj.value))
					{
						dayobj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return false;
					}
					if(aheightObj.value=='')
					{
						alert("-Enter dependant's height.");
						aheightObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return false;
					}
					else if(!DigitsAndDot(aheightObj))
					{
						alert("-Height : Only 0 to 9, '.' is allowed for dependent "+i);
						aheightObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}	
					var aweight = 'ad_weight['+i+']';
					var aweightObj = document.getElementById(aweight);
					if(aweightObj.value=='')
					{
						alert("-Enter dependant's weight.");
						aweightObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return false;
					}
					else if(!DigitsAndDot(aweightObj))
					{
						alert("-Weight : Only 0 to 9, '.' is allowed for dependent "+i);
						aweightObj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}
					var aoccupation = 'ad_occupation['+i+']';
					var aoccupationobj = document.getElementById(aoccupation);
					if(aoccupationobj.value=='')
					{
						alert("-Enter dependant's occupation.");
						aoccupationobj.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return false;
					}
					if(!CharAndSpace(aoccupationobj))
					{
			         		alert('-Occupation for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
				 	 		aoccupationobj.focus();
				 	 		pay[0].checked=false;
							pay[1].checked=false;
				 	 		return  false;
					}
					
					var cname = 'ad_cpamno['+i+']';
					var CpamObj = document.getElementById(cname);
					var cpamlength=CpamObj.value;
					var cpamlen = cpamlength.length;
					var ValidsChars = "0123456789";
					//var ename = 'ad_ehcino['+i+']';
					//var EhciObj = document.getElementById(ename);
					//var echilength=EhciObj.value;
					//var ehcilen = echilength.length;
					
					/*if((cpamlen > 0) && (EhciObj.value ==''))
					{
						if(cpamlen >0)
						{
							if(cpamlen != 15)
							{
								alert("-Cpam No. must be fifteen digit long for Dependant "+i);
								CpamObj.focus();
								return  false;
							}
						}	
					}*/
					if(cpamlen > 0)
						{
							for (j = 0; j < cpamlen; j++)
							{
								Char = cpamlength.charAt(j);
								if (ValidChars.indexOf(Char) == -1)
								{
									alert("-Cpam No. must be integer for Dependant "+i);
									CpamObj.focus();
									pay[0].checked=false;
									pay[1].checked=false;
									return  false;
									
								}
							}
						} 
						/*if(cpamlen > 0 && ehcilen > 0)
						{
							alert("-Please enter either CPAM or EHCI number for dependant"+i);
							CpamObj.focus();
							return  false;
						}*/
						
						/*if((ehcilen > 0) && (CpamObj.value == ''))
						{
							for (j = 0; j < ehcilen; j++)
							{
								Char = echilength.charAt(j);
								/*if (ValidChars.indexOf(Char) == -1)
								{
									alert("Ehci No. must be integer for Dependant"+i);
									EhciObj.focus();
									return  false;
								}*/
							//}
							/*if(ehcilen < 8 || ehcilen > 20)
							{
								alert("Ehci No. must be minimum 8 digit and maximum 20 digit long for Dependant "+i);
								EhciObj.focus();
								return  false;
							}
							
						}*/
									
				} // end of for
				
			//	Check for valid cancellation date.
			if((pay.value == "other") ) 
			{
				if(otherpay.value == "SSD")
				{
					if(!DigitsAndDot(ssdamt))
					{
						alert("-Amount : Only 0 to 9, '.' is allowed.");
						ssdamt.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}
				}
				else
				{
					if(!DigitsAndDot(chqamt))
					{
						alert("-Amount : Only 0 to 9, '.' is allowed.");
						chqamt.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;
					}
				}
				
			}
			//check if atleast one dependent is checked as birth as child
			var count =frm.elements.length;

			var i=0,k=0;

			for(i=1;i<count;i++)
			{
				if(frm.elements[i].type=="checkbox")
				{
					if(frm.elements[i].checked)
					{ 
						k=k+1;
					}
				}
			}
			if(k > 0)
			{
				//dates validation here
				if(!isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value)) 
					{
						alert("Enter valid notification date.");
						notifyday.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;			
					}		
				else{
					if(!isDate(authmonth.value+'/'+authday.value+'/'+authyear.value)) 
					{
						alert("Enter valid authorization date.");
						authday.focus();
						pay[0].checked=false;
						pay[1].checked=false;
						return  false;							
					}	
					else
					{
						/*if(!isDate(month.value+'/'+day.value+'/'+year.value)) 
						{
							alert("Enter valid addition date.");
							day.focus();
							return  false;					
						}
						else		*/		
						//{
							
							if(!ValidateOperationDate(notifyyear,notifymonth,notifyday,regyear,regmonth,regday)) 
						  	{
						  		alert('Notification Date must be a date after policy registration date.');
						  		notifyday.focus();
						  		pay[0].checked=false;
								pay[1].checked=false;
						  		return  false;
						  	}
						  	if(!ValidateNotifyDate(notifyyear,notifymonth,notifyday,endyear,endmonth,endday)) 
						  	{
						  		alert('Notification Date must be a date before policy expiry date.');
						  		notifyday.focus();
						  		pay[0].checked=false;
								pay[1].checked=false;
						  		return  false;
						  	}
						  	/*if(!NotFutureDate(authyear, authmonth, authday)) 
						  	{
						  		alert('Authorization Date can\'t be a future date.');
						  		notifyday.focus();
						  		return false;
							}*/
						  	if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday)) 
						  	{
						  		alert('Authorization Date should be same or after the notification date.');
						  		notifyday.focus();
						  		pay[0].checked=false;
								pay[1].checked=false;
						  		return false;
						  	}	  	
						  	/*if(!ValidateOperationDate(year,month,day,startyear,startmonth,startday)) 
					  		{
					  			alert('Addition Date must be a date after policy start date.');
					  			day.focus();
					  			return false;
					  		}		*/
					  		/*if(!ValidateNotifyDate(year,month,day,endyear,endmonth,endday)) 
					  		{
					  			alert('Addition Date must be a date before policy expiry date.');
					  			day.focus();
					  			return false;
							}	*/
							/*if(parseInt(GetDays(notifyyear.value,notifymonth.value,notifyday.value,year.value,month.value,day.value)) < 30)
							{
								alert('There should be atleast 30 days span between notification date and Addition date.');
								day.focus();
								return false;
							}	*/
						
						//}
					}
				}
			}
			}// end of dependants			
		}
	}
		return true;
}

function Select_Single()
{	
	//	alert(document.aquote.commencemonth.value);
	//check  month's value and disable radio button
	if(parseInt(document.frmdirectquot.commencemonth.value)>9)
	{
		document.frmdirectquot.payment_type[0].checked=true;
	}
}

//This function is using for \broker\agentwhole.php, \staticform\static_aquote.php, \templates\top_content\aquote.php...
function ValidateCommencmentDateFromBroker(val_month,val_year,val_date,objRadio,not_allowed_month,first_month,first_date)
{
	
	var not_allowed_moth_temp =  not_allowed_month.split("_");
	
	var presentYear = document.getElementById(val_year).value;
	
	var presentMonth = document.getElementById(val_month).value;
	
	var presentDate =  document.getElementById(val_date).value;
	
	var part_num=0;
	
	objRadioElement = document.getElementById(objRadio);
	
	//objRadioElement.disabled="enabled";
	
	today = new Date();
	
	objRadioElement.disabled=false;

	var currentYear = today.getFullYear();
	
	while (part_num < not_allowed_moth_temp.length)
	{
		if(currentYear == presentYear)
		{
		  if(presentMonth == not_allowed_moth_temp[part_num])
		  {
			if(first_month == presentMonth)
			{
				if(presentDate >= first_date)
				{
					objRadioElement.disabled=true;	
				}
			}
			objRadioElement.disabled=true;
		  }
		}
		 part_num+=1;
	}
}
function validateCompReg(frm)
{
	with(frm)
	{
		if(trans_number.value == '')
		{
			alert("-Please Enter Reference Number.");
			trans_number.focus();
			return false;
		}
		else
		{
			if(parseInt(trans_number.value.length)>6 || parseInt(trans_number.value.length)<6)
			{
				alert("-Please Enter 6 Digit Reference Number.");
				trans_number.focus();
				return false;
			}
		}
	}
	return true;
}

//This function is using for \admin\add_edit_department.php, \admin\dept_mgmt.php...
function frmValidateDept(frm)
{
	with(frm)
	{
		if(department_name.value=='')
		{
			alert("-Please enter department name.");
			department_name.focus();
			return false;
		}
		else if(department_code.value=='')
		{
			alert("-Please enter department code.");
			department_code.focus();
			return false;
		}
		else if(department_loading.value=='')
		{
			alert("-Please enter department loading.");
			department_loading.focus();
			return false;
		} 
		else if(department_loading.value!='')
		{
			var ValidChars = "0123456789.";
			if(department_loading.value != '')
				{
					for (j = 0; j < department_loading.value.length; j++)
					{
						var Char = department_loading.value.charAt(j);
						if (ValidChars.indexOf(Char) == -1)
						{
							alert("-Departmental loading must be Numeric.");
							department_loading.focus();
							return  false;
						} 
					} 
				}	
				
		}		
	}
	return true;
}
//This function is using for \admin\add_edit_configuration.php...
function frmValidateConf(frm)
{
	with(frm)
	{
		if(config_value.value=='')
		{
			alert("-Please enter value.");
			config_value.focus();
			return false;
		}
	}
	return true;
}

//The function showreasondate is used to show reason date in the endorsement module.
function showreasondate(frm, rowid, labelid) 
{
	with(frm) 
	{
		var reasonrow = document.getElementById(rowid);
		var reasonlabel = document.getElementById(labelid);
		
		switch(ShortOperation.value) 
		{
			case "Death":
						{
							reasonrow.style.display = "inline";
							reasonlabel.innerText = "Death Date";
							break;
						}
						
			case "Divorce":
						{
							reasonrow.style.display = "inline";
							reasonlabel.innerText = "Divorce Date";
							break;
						}
						
			case "Split":
						{
							reasonrow.style.display = "inline";
							reasonlabel.innerText = "Split Date";
							break;
						}
						
			case "CMU":
						{
							reasonrow.style.display = "inline";
							reasonlabel.innerText = "Company Cover Date";
							break;
						}
						
			case "Other":
						{
							reasonrow.style.display = "none";
							reasonlabel.innerText = "";
							break;
						}
			default:
						{
							reasonrow.style.display = "none";
							reasonlabel.innerText = "";
							break;
						}
						
		}	//	End of switch.
	} //	End of with.
} //	End of function.

//This function for show and hide of all details....
function showhidedetails(showhideid)
{
	var showhideid = document.getElementById(showhideid);
	var style = showhideid.style.display;
	
	if (style=='none')
	{
		showhideid.style.display = "block";
		
	}
    else
	{
		showhideid.style.display = "none";
		
	}
}

//This function for show and hide of all details....
function ShowHideDetailsForTwoBlocks(BlockToShow,BlockToHide)
{
	var BlockToShowObj = document.getElementById(BlockToShow);
	var BlockToHideObj = document.getElementById(BlockToHide);
	
	BlockToShowObj.style.display = "block";
	BlockToHideObj.style.display = "none";
}



function showhidesearchdiv1(image,image1,divElement)
{
	sdiv=document.getElementById(divElement);
	image=document.getElementById(image);
	image1=document.getElementById(image1);

	if(sdiv.style.display == 'none')
	{
		sdiv.style.display='block';
		image1.style.display='none';
		image.style.display='block';
	}
	else
	{
		sdiv.style.display='none';
		image1.style.display='block';
		image.style.display='none';
	}
}

function trimValue(Value)
{
		if (typeof Value == 'undefined') {
			return "";
		}

		return Value.replace(/^\s+|\s+$/g, "");
}
	
//	The function ValidateOperationDate() checks the cancellation date.
function ValidateOperationDate(year, month, day, startyear, startmonth, startday) 
{
	
	//	Check for cancellation date.
	if( parseInt(year.value) < parseInt(startyear.value))
	{
		//alert("-Date of Cancellation must be a date after the Policy Start Date."+year.value);
		return false;
	}	//	End of if year.
	else if(parseInt(year.value) == parseInt(startyear.value))
	{	
		//alert("compare"+month.value+" "+startmonth.value);
		
		if(parseInt(month.value) < parseInt(startmonth.value))
		{
			//alert("-Date of Cancellation must be a date after the Policy Start Date."+month.value);
			return false;
		}	//	End of if month.
		else if(parseInt(month.value) == parseInt(startmonth.value))
		{
			if(parseInt(day.value) <= parseInt(startday.value))
			{
				//alert("-Date of Cancellation must be a date after the Policy Start Date."+day.value);
				return false;
			}	//	End of if day.
			else 
			{return true;}
		}	//	End of if month.
		else
		{return true;}
	}	//	End of else if month.
	else 
	{
		return true;
	}	//	End of else.
}	//	End of function.

//	The function SameOrAfterDate() checks the authorization date and notification date.
function SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday) 
{
	
	//	Check for authorization date.
	if( parseInt(authyear.value) > parseInt(notifyyear.value))
	{
		//alert("-Date of notification must be a date after the Policy Start Date.");
		return true;
	}	//	End of if year.
	else if(parseInt(authyear.value) == parseInt(notifyyear.value))
	{	
		//alert("compare"+month.value+" "+startmonth.value);
		
		if(parseInt(authmonth.value) > parseInt(notifymonth.value))
		{
			//alert("-Date of notification must be a date after the Policy Start Date.");
			return true;
		}	//	End of if month.
		else if(parseInt(authmonth.value) == parseInt(authmonth.value))
		{
			if(parseInt(authday.value) >= parseInt(notifyday.value))
			{
				//alert("-Date of notification must be a date after the Policy Start Date.");
				return true;
			}	//	End of if day.
			else 
			{return false;}
		}	//	End of if month.
		else
		{return false;}
	}	//	End of else if month.
	else 
	{
		return false;
	}	//	End of else.
}	//	End of function.

//	The function NotFutureDate(...) checks if the entered date is not a future date.
function NotFutureDate(year, month, day)
{
	//	Get Current Date in variables.
	dateobj	= new Date();
	yearobj = dateobj.getFullYear();
	monthobj= dateobj.getMonth()+1;
	dayobj	= dateobj.getDate();
	
	//	Compare if entered year is a future year.
	if(parseInt(year.value) > parseInt(yearobj)) 
	{
		return false;
	}
	else if(parseInt(year.value) == parseInt(yearobj)) // if current year.
	{
		//	Compare if entered month is a future month.
		if(parseInt(month.value) > parseInt(monthobj)) 
		{
			return false;
		}
		else if(parseInt(month.value) == parseInt(monthobj)) //	current month.
		{
			//	Compare if entered date is not a future date.
			if(parseInt(day.value) > parseInt(dayobj)) 
			{return false;}
			else {return true;}
		}
		else {return true;}
	}
	else {return true;}
}


//	The function ValidateNotifyDate() checks the cancellation date.
function ValidateNotifyDate(year, month, day, endyear, endmonth, endday) 
{
	
	//	Check for cancellation date.
	if( parseInt(year.value) < parseInt(endyear.value))
	{
		//alert("-Date of Cancellation must be a date after the Policy Start Date.");
		return true;
	}	//	End of if year.
	else if(parseInt(year.value) == parseInt(endyear.value))
	{	
		//alert("compare"+month.value+" "+startmonth.value);
		
		if(parseInt(month.value) < parseInt(endmonth.value))
		{
			//alert("-Date of Cancellation must be a date after the Policy Start Date.");
			return true;
		}	//	End of if month.
		else if(parseInt(month.value) == parseInt(endmonth.value))
		{
			if(parseInt(day.value) < parseInt(endday.value))
			{
				//alert("-Date of Cancellation must be a date after the Policy Start Date.");
				return true;
			}	//	End of if day.
			else 
			{return false;}
		}	//	End of if month.
		else
		{return false;}
	}	//	End of else if month.
	else 
	{
		return false;
	}	//	End of else.
}	//	End of function.


function frmValidate(frm)
{
	with(frm)
	{ 
		if(subval.value == "Go") 
		{
			if(policy_no.value == "")
			{
				alert("-Enter a Policy Number before submitting.");
				policy_no.focus();
				return false;
			}	//	end of if policy_no.
		}	//	end of if subval.
		else if(subval.value == "Update")
		{
			if(policy_no.value == "")
			{
				alert("-Enter a Policy Number before submitting.");
				policy_no.focus();
				return false;
			}

			
			var dateObj = new Date();
			if(isDate(mimonth.value+"/"+miday.value+"/"+miyear.value))
			{
				if((parseInt(mimonth.value) < parseInt(dateObj.getMonth())+1) && (parseInt(miyear.value) == parseInt(dateObj.getFullYear())))
				{
					alert("please check the monthly installment start date.");
					miday.focus();
					return false;
				}	//	end of if.
				else if(parseInt(miday.value) < parseInt(dateObj.getDate()))
				{
					if((parseInt(mimonth.value) <= parseInt(dateObj.getMonth())+1) && (parseInt(miyear.value) == parseInt(dateObj.getFullYear())))
					{
						alert("please check the monthly installment start date.");
						miday.focus();
						return false;
					}
				}
			}
			else{
				miday.focus();
				return false;
			}

			if(subval.value=="Update")
			{
				var count =frm.elements.length;
				var i=0;
				for(i=1;i<count;i++)
				{
					if(frm.elements[i].type=="checkbox" && frm.elements[i].id=="dep_list")
					{
						if(frm.elements[i].checked)
						{
							i=1;
							break;
						}
					}
				}
				if(i==1)
				{
					//return true;
				}
				else
				{
					alert("-Please Select dependant to remove.");
					return false;
				}
			}
			
			if(isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value) && isDate(month.value+'/'+day.value+'/'+year.value))
			{  
				if(parseInt(GetDays(notifyyear.value,notifymonth.value,notifyday.value,year.value,month.value,day.value)) < 30)
				{
					alert("There should be atleast 30 days span between notification date and cancellation date.");
					day.focus();
					return false;
				}
			} 
			if(isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value)) 
			{
				if(!NotFutureDate(notifyyear, notifymonth, notifyday)) 
			  	{
			  		alert('Notification date can\'t be a future date.');
			  		notifyday.focus();
			  		return false;
				}
				if(!ValidateOperationDate(notifyyear,notifymonth,notifyday,regyear,regmonth,regday))
				{
					alert('Notification Date must be a date after policy registration date.'); 
					return false;
				}
				if(!ValidateNotifyDate(notifyyear,notifymonth,notifyday,endyear,endmonth,endday))
				{
					alert('Notification Date must be a date before policy expiry date.');
					return false;
				}
				if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday))
				{
					alert('Authorization Date should be a same of after the Notification date.'); 
					return false;
				}
			}
			if(isDate(month.value+'/'+day.value+'/'+year.value)) 
			{
				if(!ValidateOperationDate(year,month,day,startyear,startmonth,startday))
				{
					alert('Cancellation Date must be a date after policy start date.'); 
					return false;
				}
				if(!ValidateNotifyDate(year,month,day,endyear,endmonth,endday))
				{
					alert('Cancellation Date must be a date before policy expiry date.'); 
					return false;
				} 
				if(!SameOrAfterDate(year, month, day, authyear, authmonth, authday))
				{
					alert('Cancellation Date should be a same of after the authorization date.'); 
					return false;
				}
			}
			if(isDate(authmonth.value+'/'+authday.value+'/'+authyear.value)) 
			{
				if(!ValidateOperationDate(authyear,authmonth,authday,regyear,regmonth,regday))
				{
					alert('Authorization Date must be a date after policy registration date.'); 
					return false;
				}
				if(!ValidateNotifyDate(authyear,authmonth,authday,endyear,endmonth,endday))
				{
					alert('Authorization Date must be a date before policy expiry date.'); 
					return false;
				}
				if(!NotFutureDate(authyear,authmonth, authday))
				{
					alert('Authorization Date can\'t be a future date.'); 
					return false;
				}
				if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday))
				{
					alert('Authorization Date should be a same of after the notification date.'); 
					return false;
				}
			}
			if(isDate(mimonth.value+'/'+miday.value+'/'+miyear.value)) 
			{
				if(!ValidateOperationDate(miyear,mimonth,miday,startyear,startmonth,startday)) 
				{
					alert('Monthly Installment Start Date must be a date after policy start date.');
					return false;
				}
				if(!ValidateNotifyDate(miyear,mimonth,miday,endyear,endmonth,endday))
				{
					alert('Monthly Installment Start Date must be a date before policy expiry date.');
					return false;
				}
			}
		}
	}	//	end of with.
	return true;
}	//	end of function.

function validation(frm)
{
	with(frm)
	{
		if(name.value =='')
		{
			alert("-Enter Client name.");
			name.focus();
			return false
		}
		if(email.value != '')
		{
			var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			var membermailid = eval("email.value");

			result1=membermailid.search(emails);
			if(result1==-1)
			{
				alert("-Enter valid Email-id");
				eval("email.focus()");
				return false;
			}
		} // email validation ends here
		else
		{
			alert("-Enter your email address.");
			eval("email.focus()");
			return false;	
		}
		if(postcode.value == "")
		{
			alert("-Please enter postcode.");
			postcode.focus();
			return  false;
		}
		if(postcode.value != '')
		{
			var str = (dept.value).indexOf("_");
			var pcode = (dept.value).substring(0,str);
			var dcode =	'dept_code['+pcode+']';
			//alert(dcode);
			var dcodeObj =	document.getElementById(dcode);
			
			if((postcode.value).substring(0,2) != dcodeObj.value)
			{
				alert("The first 2 numbers of your Post Code must match your Department Code");
				postcode.focus();
				return false;
			}
		}
		var ValidChars = "0123456789";
		if(postcode.value != '')
		{
		for (j = 0; j < postcode.value.length; j++)
		{
			var Char = postcode.value.charAt(j);
			if (ValidChars.indexOf(Char) == -1)
			{
				alert("-Post code must be integer");
				postcode.focus();
				return  false;
			} 
		} 
		}
	}
	return true;
}


function ValidateManualEntry(frm)
{
	with(frm)
	{
		if(policynumber.value == "")
		{
			alert("-Enter policy number.");
			policynumber.focus();
			return false;
		}
		if(amount.value == "")
		{
			alert("-Please enter amount.");
			amount.focus();
			return  false;
		}
		var ValidChars = "0123456789.";
		if(amount.value != '')
		{
			for (j = 0; j < amount.value.length; j++)
			{
				var Char = amount.value.charAt(j);
				if (ValidChars.indexOf(Char) == -1)
				{
					alert("-Amount must be integer");
					amount.focus();
					return  false;
				} 
			} 
		}
		var payfor = ManualEntry.selectedIndex;
		if(payfor == "0")
		{
			alert("-Please select pay for.");
			ManualEntry.focus();
			return  false;
		}
		if(payfor == "1") 
		{ 
			if(month.value == "")
			{
				alert("-Please enter month.");
				month.focus();
				return  false;
			}
			var ValidChars = "0123456789";
			if(month.value != '')
			{
				for (j = 0; j < month.value.length; j++)
				{
					var Char = month.value.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Month must be integer");
						month.focus();
						return  false;
					} 
				} 
			}
			if(month.value > 12)
			{
				alert("-Please enter valid month.");
				month.focus();
				return  false;
			}
			if(year.value == "")
			{
				alert("-Please enter year.");
				year.focus();
				return  false;
			}
			if(year.value.length < 4)
			{
				alert("-Please enter valid year.");
				year.focus();
				return  false;
			}
			var ValidChars = "0123456789";
			if(year.value != '')
			{
				for (j = 0; j < year.value.length; j++)
				{
					var Char = year.value.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Year must be integer");
						year.focus();
						return  false;
					} 
				} 
			}
		} 
		if(payer.value == "")
		{
			alert("-Please enter payer.");
			payer.focus();
			return  false;
		}
		if(description.value == "")
		{
			alert("-Please enter description.");
			description.focus();
			return  false;
		}
	}
	return true;
}


function ChkSelDep(frm, value)
{
	with(frm)
	{
		if(value == "Update") {subval.value="Update";}	
		else if(value == "Go") {subval.value="Go";}
	} // End of with.
}	//	End of Function.


// This function is to hide policy documents links.....
function hidedocuments(hideid, count)
{
	var row;
	var style;
	var inc;
	for(inc=0; inc<= count; inc++)
	{  
		row= document.getElementById(hideid+"["+inc+"]");
		style = row.style.display;
		
		if(style == 'block')
		{
			row.style.display = "none";
		}
	}return(false);
}
  
/* The function frmquote(frm) checks whether the quotation is for a past date. */
function frmaquote(frm)
{  
	with(frm)
	{
		var dateObj = new Date();
		
		/*
			If agent then check for commencement date.
		*/
		if(UserLevel.value == "3") 
		{
			/*
				if commencement date is not current date and either the month is past month of the same year
				or the year is past year then, quotation should not be allowe d.
			*/
			if(isDate(commencemonth.value+"/"+commenceday.value+"/"+commenceyear.value))
			{  		
				if((parseInt(commencemonth.value) < parseInt(dateObj.getMonth())+1) && (parseInt(commenceyear.value) == parseInt(dateObj.getFullYear())))
				{
					alert("Cannot get quotation for a past date.");
					commenceday.focus();
					return false;
				}	//	end of if.
				else if(parseInt(commenceday.value) < parseInt(dateObj.getDate()))
				{
					if((parseInt(commencemonth.value) <= parseInt(dateObj.getMonth())+1) && (parseInt(commenceyear.value) == parseInt(dateObj.getFullYear())))
					{
						alert("Cannot get quotation for a past date.");
						commenceday.focus();
						return false;
					}
				}			
			}
			else{
				commenceday.focus();
				return false;
			}
			
			
		}
	}	//	end of with.
}	//	end of function.



/*********************************************************/
/* Start Setup boxrow handlers                                 */
/*********************************************************/

/*function CheckUnCheckRadio(RadioId)
{
	var RadioObj = document.getElementById(RadioId);
	//alert(RadioId);
	if(RadioObj)
	{
		if(RadioObj.checked == false)
		{
			RadioObj.checked = true;
			//RadioObj.checked = !RadioObj.checked;
		}	
	}	
}*/

function CheckUnCheckCheckBox(RadioId)
{
	var RadioObj = document.getElementById(RadioId);
	//alert(RadioId);
	if(RadioObj)
	{
		RadioObj.checked = RadioObj.checked;
	}	
}

function boxrow_init()
{
	var obj = document.body.getElementsByTagName("DIV");
	
	for (var i=0; i < obj.length; i++)
	{
		if (obj[i].className == 'boxrow')
		{
			obj[i].onmouseover = boxrow_over;
			obj[i].onmouseout = boxrow_leave;
			obj[i].onclick = boxrow_click;

			// Check for 1st generation childs -- input tags
			j = 0;

			while (j < obj[i].childNodes.length)
			{
				if (obj[i].childNodes[j].tagName == 'INPUT')
				obj[i].childNodes[j].onclick = boxrow_nonbubble;

				j++;
			}
		}
	}
}

function boxrow_over(e)
{
	if (!e && window.event)
		e = window.event;

	if (e.srcElement)
		o = e.srcElement;
	else
		o = e.target;

	// Find the DIV
	while (o.tagName != "DIV")
		o = o.parentNode;

		o.style.backgroundColor='#F6F6F6';
}

function boxrow_leave(e)
{
	if (!e && window.event)
		e = window.event;

	if (e.srcElement)
		o = e.srcElement;
	else
		o = e.target;

	// Find the DIV
	while (o.tagName != "DIV")
		o = o.parentNode;

	o.style.backgroundColor='#FFFFFF';
}

function boxrow_click(e)
{
	//alert(o.childNodes.length); 
	
	if (!e && window.event)
		e = window.event;

	if (e.srcElement)
		o = e.srcElement;
	else
		o = e.target;

	// Find the DIV
	while (o.tagName != "DIV")
		o = o.parentNode;

	// Find the checkbox
	i = 0;
	while (i < o.childNodes.length)
	{
		//alert(o.childNodes.tagName);
		if (o.childNodes[i].tagName == 'INPUT')
		{
			o.childNodes[i].checked = !o.childNodes[i].checked;
			return true;
		}

		i++;
	}
}

function boxrow_nonbubble(e)
{
	if (!e && window.event)
    e = window.event;
  
	if (e.stopPropagation) 
		e.stopPropagation(); 
	else 
		e.cancelBubble = true;
		
	//alert(e.cancelBubble);
}

function cascadebox_change(o)
{
	var sel = o.options[o.selectedIndex].value;
	var baseid = o.id + '_';
	var matchid = baseid + (sel ? sel + '_' : '');
	var obj = document.body.getElementsByTagName("DIV");
	
	for (var i=0; i < obj.length; i++)
	{
		if (obj[i].id.indexOf(baseid) == 0)
		{
			obj[i].style.display = obj[i].id.indexOf(matchid) == 0 ? '' : 'none';
		}
	}
}

/*********************************************************/
/* End Setup boxrow handlers                                 */
/*********************************************************/


function forgotPwd(frm)
{
	with(frm)
	{
		if(username.value == '')
		{
			alert("-Enter user name.");
			username.focus();
			return false;
		}
	}
	return true;
}
function cancelapplicant(obj,frm)
{ 
	with(frm)
	{ 
		if(obj.value=='Go')
		{
			if(policy_no.value=='')	
			{
				alert("-Please enter policy number.");
				policy_no.focus();
				return false;
			}
		}
		if(obj.value == "Update") 
		{
			if(policy_no.value !='')
			{
				if(frm.operation[1].checked)
				{
					if(surname.value == "")
					{
						alert("-Please enter surname.");
						surname.focus();
						return false;
					}
					if(firstname.value == "")
					{
						alert("-Please enter firstname.");
						firstname.focus();
						return false;
					}
					if(address.value == "")
					{
						alert("-Please enter address.");
						address.focus();
						return false;
					}
					if(postcode.value == "")
					{
						alert("-Please enter postcode.");
						postcode.focus();
						return  false;
					}
					if(postcode.value != '')
					{
						/*var str = (dept.value).indexOf("_");
						var pcode = (dept.value).substring(0,str);
						var dcode =	'dept_code['+pcode+']';
						//alert(dcode);
						var dcodeObj =	document.getElementById(dcode);
						
						if((postcode.value).substring(0,2) != dcodeObj.value)
						{
							alert("The first 2 numbers of your Post Code must match your Department Code");
							postcode.focus();
							return false;
						}*/
					}
					var ValidChars = "0123456789";
					if(postcode.value != '')
					{
					for (j = 0; j < postcode.value.length; j++)
					{
						var Char = postcode.value.charAt(j);
						if (ValidChars.indexOf(Char) == -1)
						{
							alert("-Post code must be integer");
							postcode.focus();
							return  false;
						} 
					} 
					}
					if(town.value == "")
					{
						alert("-Please enter town.");
						town.focus();
						return false;
					}
					if(telephone.value == "")
					{
						alert("-Please enter telephone number.");
						telephone.focus();
						return false;
					}
					if(!DigitsPlusMinus(telephone))
					{
						alert("-Telephone : Only 0 to 9, '-' , ' +' , and space is allowed.");
						telephone.focus();
						return  false;
					}
					if(email.value != '')
					{
						var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
						var membermailid = eval("email.value");

						result1=membermailid.search(emails);
						if(result1==-1)
						{
							alert("-Enter valid Email-id.");
							eval("email.focus()");
							return false;
						}
					} // email validation ends here
					else
					{
						alert("-Enter your email address.");
						eval("email.focus()");
						return false;
					}
					if(email.value != remail.value)
					{
						alert("-Re input email should match with email.");
						eval("remail.focus()");
						return false;
					}
					
					var count =frm.elements.length;
					var i=0,k="CPAM";
	
					for(i=1;i<count;i++)
					{
						if(frm.elements[i].type=="text" && frm.elements[i].id=="ehicno")
						{
							k="EHIC";
						}
					}
					
					if(k=="CPAM"){
						var cpamlength = cpamno.value;
						var cpamlen = cpamlength.length
						
						if(cpamlen > 0)
						{
							if(cpamlen != 15)
							{
								alert("-Cpam no. must be fifteen digits long.");
								cpamno.focus();
								return  false;
							}
						}else
						{
							alert("-Please enter CPAM number.");
							cpamno.focus();
							return  false;
						}
					}else
					{
						var ehcilength=ehicno.value;
						var ehcilen = ehcilength.length;
						
						if(ehicno.value =='')
						{
							alert("-Please enter EHIC number.");
							ehicno.focus();
							return  false;
						}
					}
					
					if(height.value == "")
					{
						alert("-Please enter height.");
						height.focus();
						return false;
					}
					if(!DigitsAndDot(height))
					{
						alert("-Height : Only 0 to 9, '.' is allowed.");
						height.focus();
						return  false;
					}
					if(weight.value == "")
					{
						alert("-Please enter weight.");
						weight.focus();
						return false;
					}
					if(!DigitsAndDot(weight))
					{
						alert("-Weight : Only 0 to 9, '.' is allowed.");
						weight.focus();
						return  false;
					}
  
					if(occupation.value == "")
					{
						alert("-Please enter occupation.");
						occupation.focus();
						return false;
					}
					if(!CharAndSpace(occupation))
					{
						alert("-Occupation : Only a to z, A to Z, and space is allowed.");
						occupation.focus();
						return  false;
					}
				}
			}   //ddfsdf
			if(!isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value)) 
				{
					alert("Enter valid notification date.");
					notifyday.focus();
					return  false;			
				}		
			else{
				if(!isDate(authmonth.value+'/'+authday.value+'/'+authyear.value)) 
				{
					alert("Enter valid authorization date.");
					authday.focus();
					return  false;							
				}	
				else
				{
					if(!isDate(month.value+'/'+day.value+'/'+year.value)) 
					{
						alert("Enter valid cancellation date.");
						day.focus();
						return  false;					
					}
					else				
					{
						
						if(!ValidateOperationDate(notifyyear,notifymonth,notifyday,regyear,regmonth,regday)) 
					  	{
					  		alert('Notification Date must be a date after policy registration date.');
					  		notifyday.focus();
					  		return  false;
					  	}
					  	if(!NotFutureDate(notifyyear, notifymonth, notifyday)) 
					  	{
					  		alert('Notification date can\'t be a future date.');
					  		notifyday.focus();
					  		return false;
						}
					  	if(!ValidateNotifyDate(notifyyear,notifymonth,notifyday,endyear,endmonth,endday)) 
					  	{
					  		alert('Notification Date must be a date before policy expiry date.');
					  		notifyday.focus();
					  		return  false;
					  	}
					  	if(!NotFutureDate(authyear, authmonth, authday)) 
					  	{
					  		alert('Authorization Date can\'t be a future date.');
					  		authday.focus();
					  		return false;
						}
					  	if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday)) 
					  	{
					  		alert('Authorization Date should be same or after the notification date.');
					  		notifyday.focus();
					  		return false;
					  	}	  	
					  	if(!ValidateOperationDate(year,month,day,startyear,startmonth,startday)) 
				  		{
				  			alert('Cancellation Date must be a date after policy start date.');
				  			day.focus();
				  			return false;
				  		}		
				  		if(!ValidateNotifyDate(year,month,day,endyear,endmonth,endday)) 
				  		{
				  			alert('Cancellation Date must be a date before policy expiry date.');
				  			day.focus();
				  			return false;
						}	
						if(parseInt(GetDays(notifyyear.value,notifymonth.value,notifyday.value,year.value,month.value,day.value)) < 30)
						{
							alert('There should be atleast 30 days span between notification date and cancellation date.');
							day.focus();
							return false;
						}
						if(!NotFutureDate(reasonyear, reasonmonth, reasonday)) 
					  	{
					  		alert('Date of reason can\'t be a future date.');
					  		reasonday.focus();
					  		return false;
						}	
					
					}
				}
				  	
			  }			  
		}
			
	}	
}

/* 
	This function, frmValidateBankDetail is used to validate the add_edit_bankdetails.php.
	It is created by Mr. Girish Nambiar.
*/
function frmValidateBankDetail(frm) 
{
	with(frm) 
	{
		//	If payer is not specified.
		if(payer.value == "") 
		{
			alert("-Payer should not be empty.");
			payer.focus();
			return false;
		}
		//	If payment bank is not specified.
		if(payment_bank.value == "") 
		{
			alert("-Payment Bank should not be empty.");
			payment_bank.focus()
			return false;
		}
		//	If payment branch is not specified.
		if(payment_branch.value == "") 
		{
			alert("-Payment Branch should not be empty.");
			payment_branch.focus();
			return false;
		}
		
		//	If account number is not specified.
		var ValidChars = "0123456789.";
		
		if(acc_no.value == "") 
		{
			alert("-Account Number should not be empty.");
			acc_no.focus();
			return false;
		}
		if(acc_no.value != '')
		{
			for (j = 0; j < acc_no.value.length; j++)
			{
				var Char = acc_no.value.charAt(j);
				if (ValidChars.indexOf(Char) == -1)
				{
					alert("-Account number must be integer");
					acc_no.focus();
					return  false;
				} 
			} 
		}	
		
		//	If no is not specified.
		if(no.value == "") 
		{
			alert("No should not be empty.");
			no.focus();
			return false;
		}
		if(no.value != '')
		{
			for (j = 0; j < no.value.length; j++)
			{
				var Char = no.value.charAt(j);
				if (ValidChars.indexOf(Char) == -1)
				{
					alert("-Number must be integer");
					no.focus();
					return  false;
				} 
			} 
		}	
		//	If IBAN is not specified.
		if(iban.value == "")
		{
			alert("-IBAN should not be empty.");
			iban.focus();
			return false;
		}
		submit();
	}	//	end of with.
}	// end of function.

/* 
	This function frmValidateBank() is used for bank_add_edit page.
	This is created by Girish Nambiar.
*/
function FrmValidateBank(frm) 
{
	with(frm) 
	{
		if(bank_code.value	== '') //	if bank name is empty.
		{
			alert("-Field Bank Code can't be empty."); //	Show alert box.
			bank_code.focus();
			return false;	//	don't submit.
		}	//	
		if(bank_name.value	== '') //	if bank name is empty.
		{
			alert("-Field Bank Name can't be empty."); //	Show alert box.
			bank_name.focus();
			return false;	//	don't submit.
		}	
	}	//	End of with.
	return true;
}	//	End of function.


function getCode()
{
	with(document.addbankdetail)
	{
		var str = (bank_name.options[bank_name.selectedIndex].value).indexOf("_");
		//alert (str);
		payment_bank.value = (bank_name.options[bank_name.selectedIndex].value).substring(str+1);
	}
}

/*function frmsourcevalidate(frm)
{
	with(frm)
	{
		if(source_name.value == '')
		{
			alert("Please enter the policy source name.");
			source_name.focus();
			return false;
		}
	}
}*/


//This function is using for cancel_policy.php....
function validateFrmCancelPolicy(obj,frm)
{ 
	with(frm)
	{
		//alert(obj.value);
		if(obj.value=='Go') 
		{
			if(policy_no.value=='')	
			{
				alert("-Please enter policy number.");
				policy_no.focus();
				return false;
			}
		}
		if(obj.value == "Update") 
		{
			if(policy_no.value !='')  
			{
			var dateObj = new Date();
			
			if(isDate(month.value+'/'+day.value+'/'+year.value))
			{
				if(!ValidateOperationDate(year,month,day,startyear,startmonth,startday))
				{
					alert('Cancellation Date must be a date after policy start date.');
					return false;
				}
				if(!ValidateNotifyDate(year,month,day,endyear,endmonth,endday))
				{
					alert('Cancellation Date must be a date before policy expiry date.');
					return false;
				}
			}
			else
			{
				day.focus();
				return false;
			}
			
			if(isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value)) 
			{
				if(!ValidateOperationDate(notifyyear,notifymonth,notifyday,regyear,regmonth,regday))
				{
					alert('Notification Date must be a date after policy registration date.'); 
					return false;
				}
				if(!ValidateNotifyDate(notifyyear,notifymonth,notifyday,endyear,endmonth,endday))
				{
					alert('Notification Date must be a date before policy expiry date.'); 
					return false;
				}
				if(!NotFutureDate(notifyyear,notifymonth, notifyday))
				{
					alert('Authorization Date can\'t be a future date.'); 
					return false;
				}
				if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday))
				{
					alert('Authorization Date should be a same of after the notification date.');
					return false;
				}
			}
			
			if(isDate(authmonth.value+'/'+authday.value+'/'+authyear.value))
			{
				if(!ValidateOperationDate(authyear,authmonth,authday,regyear,regmonth,regday))
				{
					alert('Authorization Date must be a date after policy registration date.');
					return false;
				}
				if(!ValidateNotifyDate(authyear,authmonth,authday,endyear,endmonth,endday))
				{
					alert('Authorization Date must be a date before policy expiry date.');
					return false;
				}
				if(!NotFutureDate(authyear,authmonth, authday))
				{
					alert('Authorization Date can\'t be a future date.');
					return false;
				}
				if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear, notifymonth, notifyday))
				{
				alert('Authorization Date should be a same of after the notification date.');
				return false;
				}
			}
			else
			{
				authday.focus();
				return false;
			}
			
			if(description.value == '')
			{
				alert("-Please enter reason of policy cancellation.");
				description.focus();
				return false;
			}
			
		  }
		}
	}
return true;
}    

function passwdprompt()    
{
	
	name = (prompt("Enter super administrator password","Type super administrator password"));
	document.location="add_edit_configuration.php?Configuration_Name=DEFAULT_AGENCY_CODE&Pass_Word="+hex_md5(name);
	
}

function ValidateFrmTransferDep(obj, frm)
{
	with(frm)
	{
		if(obj.value == "Get Details")    
		{
			if(from_policy_no.value == '')
			{
				alert("-Please enter Policy Number[From].");
				from_policy_no.focus();
				return false;
			}
			if(to_policy_no.value == '')
			{
				alert("-Please enter Policy Number[To].");
				to_policy_no.focus();
				return false;
			}
			if(from_policy_no.value == to_policy_no.value)
			{
				alert("-Please enter the policy number correctly.");
				from_policy_no.focus();
				return false;
			}

		}
		else if(obj.value == "Transfer")
		{
			if(from_policy_no.value == '')
			{
				alert("-Please enter Policy Number[From].");
				from_policy_no.focus();
				return false;
			}
			if(to_policy_no.value == '')
			{
				alert("-Please enter Policy Number[To].");
				to_policy_no.focus();
				return false;
			}
			if(from_policy_no.value == to_policy_no.value)
			{
				alert("-Please enter the policy number correctly.");
				from_policy_no.focus();
				return false;
			}
			if(FromDependentCount.value!='')
			{
				var count =frm.elements.length;

				var i=0,k=0;

				for(i=1;i<count;i++)
				{
					if(frm.elements[i].type=="checkbox" && frm.elements[i].id=="dep_list")
					{
						if(frm.elements[i].checked)
						{
							k=k+1;
						}
					}
				}
				if(k > 0)
				{
					if((parseInt(ToDependentCount.value)+k)>=8)
					{
						alert("-More than 7 dependents are not allowed in single policy.");
						return false;
					}
					return true;
				}
				else
				{
					alert("-Please Select dependant to transfer.");
					return false;
				}
			}	//	End of FromDependentCount.
			if(!isDate(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value))
			{
				alert("Enter valid notification date.");
				notifyday.focus();
				return  false;
			}
			else{
				if(!isDate(authmonth.value+'/'+authday.value+'/'+authyear.value))
				{
					alert("Enter valid authorization date.");
					authday.focus();
					return  false;
				}
				else
				{
					if(!isDate(month.value+'/'+day.value+'/'+year.value))
					{
						alert("Enter valid transfer date.");
						day.focus();
						return  false;
					}
					else
					{

						if(!ValidateOperationDate(notifyyear,notifymonth,notifyday,regyear,regmonth,regday))
						{
							alert('Notification Date must be a date after policy registration date.');
							notifyday.focus();
							return  false;
						}
						if(!ValidateNotifyDate(notifyyear,notifymonth,notifyday,endyear,endmonth,endday))
						{
							alert('Notification Date must be a date before policy expiry date.');
							notifyday.focus();
							return  false;
						}
						/*if(!NotFutureDate(authyear, authmonth, authday))
						{
						alert('Authorization Date can\'t be a future date.');
						notifyday.focus();
						return false;
						}*/
						if(!SameOrAfterDate(authyear, authmonth, authday, notifyyear,notifymonth,notifyday))
						{
							alert('Authorization Date should be same or after the notification date.');
							notifyday.focus();
							return false;
						}
						if(!ValidateOperationDate(year,month,day,startyear,startmonth,startday))
						{
							alert('Transfer Date must be a date after policy start date.');
							day.focus();
							return false;
						}
						if(!ValidateNotifyDate(year,month,day,endyear,endmonth,endday))
						{
							alert('Transfer Date must be a date before policy expiry date.');
							day.focus();
							return false;
						}
						if(parseInt(GetDays(notifymonth.value+'/'+notifyday.value+'/'+notifyyear.value,year.value,month.value,day.value)) < 30)
						{
							alert('There should be atleast 30 days span between notification date and Transfer date.');
							day.focus();
							return false;
						}

					}	//	end of else.
				}	//	end of else.
			}	//	end of else.
			if(description.value =='') 
			{
				alert("Please fill in the Description field.");
				return false;
			}	//	end of if description.
		}	//	end of else if Transfer.
		return true;
	}	//	end of with.
}	//	end of function.

//------------------------  Trim function ----------------------------------
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function
function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While

	return strTemp;
} //End Function

//Function for field name that only allowed Character and Space not Digits...
function CharAndSpace(FieldName)
{
	if(FieldName.value != "")
	{
		var ValidChar = "0123456789~`!@#$%^&*()_+|\\=-][{}:';?><,./'";
		var ValidChars = ValidChar+'"';
		for (j = 0; j < FieldName.value.length; j++) 
 	 	{ 
 		 var Char = FieldName.value.charAt(j); 
 		 if (ValidChars.indexOf(Char) != -1) 
 		 {
	 		return  false;
 		 }  
       }
       return true;
	}
}  

//Function for field name that only allowed Digits and Dot...
function DigitsAndDot(FieldName)
{
	if(FieldName.value != "")
	{
		var ValidChars = "0123456789.";
		for (j = 0; j < FieldName.value.length; j++)
		{
			var Char = FieldName.value.charAt(j);
			if (ValidChars.indexOf(Char) == -1)
			{
				return  false;
			}
		}
		return true;
	}
}

//Function for field name that only allowed Digits...
function DigitsOnly(FieldName)
{
	if(FieldName.value != '')
	{
		var ValidChars = "0123456789";
		for (j = 0; j < FieldName.value.length; j++)
		{
			var Char = FieldName.value.charAt(j);
			if (ValidChars.indexOf(Char) == -1)
			{
				return  false;
			} 
		} 
	}	
}

//Function for field name that only allowed Digits, +, and -(for eg. telephone no: +91-222-111-3456)...
function DigitsPlusMinus(FieldName)
{
	if(FieldName.value != "")
	{
		var ValidChars = "0123456789-+  ";
		for (j = 0; j < FieldName.value.length; j++)
		{
			var Char = FieldName.value.charAt(j);
			if (ValidChars.indexOf(Char) == -1)
			{
				return  false;
			}
		}
		return true;
	}
}

function validemail(FieldName)  
{
	if(FieldName.value != "") 
		{
			var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			var membermailid = eval("FieldName.value");

			result1=membermailid.search(emails);
			if(result1==-1)
			{
				return false;
			}
			return true;
		} 
}

function ShowHideDetails(fieldid,style,image,site_url)
{
	var fieldidObj = document.getElementById(fieldid);
	
	fieldidObj.style.display = style;
	
	if(style="none")
	{
		image.src=site_url+'image/exp_minus.gif';
	}
	else
	{
		image.src=site_url+'image/exp_plus.gif';
	}
}

//This function is used to change the innertext of an anchor.
function showhidesearchdiv(image,divElement,site_url)
{
	sdiv=document.getElementById(divElement);
	image=document.getElementById(image);
	
	if(sdiv.style.display == 'none')
	{
		sdiv.style.display='block';
		image.src=site_url+'image/exp_minus.gif';
	}
	else
	{
		sdiv.style.display='none';
		image.src=site_url+'image/exp_plus.gif';
	}
}	

function OpenBlocks(url)
{
	showhidesearchdiv('img','note',url+'/admin/');
	showhidesearchdiv('img1','policydocument',url+'/admin/');
	showhidesearchdiv('img2','premium',url+'/admin/');
	showhidesearchdiv('img3','paymentmethod',url+'/admin/');
	showhidesearchdiv('img4','premiumhistory',url+'/admin/');
	showhidesearchdiv('img5','policyhistory',url+'/admin/');
	showhidesearchdiv('img6','remarks',url+'/admin/');	
}

/* This function opencloseall() is used for closing and opening all the sections of policy_details. */
function opencloseall(object, url) 
{
	with(object) 
	{
		//	change the innerText in the tag and call the show-hide function.
		if(object.innerText	==	" Open All Boxes ") 
		{
			object.innerText = " Close All Boxes ";
			ShowHideDetails('note','none','img',url+'/admin/');
			showhidesearchdiv('img','note',url+'/admin/');
			ShowHideDetails('policydocument','none','img1',url+'/admin/');
			showhidesearchdiv('img1','policydocument',url+'/admin/');
			ShowHideDetails('premium','none','img2',url+'/admin/');
			showhidesearchdiv('img2','premium',url+'/admin/');
			ShowHideDetails('paymentmethod','none','img3',url+'/admin/');
			showhidesearchdiv('img3','paymentmethod',url+'/admin/');
			ShowHideDetails('premiumhistory','none','img4',url+'/admin/');
			showhidesearchdiv('img4','premiumhistory',url+'/admin/');
			ShowHideDetails('policyhistory','none','img5',url+'/admin/');
			showhidesearchdiv('img5','policyhistory',url+'/admin/');
			ShowHideDetails('remarks','none','img6',url+'/admin/');
			showhidesearchdiv('img6','remarks',url+'/admin/');
			 
		}
		else 
		{
			
			object.innerText = " Open All Boxes "; 
			ShowHideDetails('note','block','img',url+'/admin/');
			showhidesearchdiv('img','note',url+'/admin/');
			ShowHideDetails('policydocument','block','img1',url+'/admin/');
			showhidesearchdiv('img1','policydocument',url+'/admin/');
			ShowHideDetails('premium','block','img2',url+'/admin/');
			showhidesearchdiv('img2','premium',url+'/admin/');
			ShowHideDetails('paymentmethod','block','img3',url+'/admin/');
			showhidesearchdiv('img3','paymentmethod',url+'/admin/');
			ShowHideDetails('premiumhistory','block','img4',url+'/admin/');
			showhidesearchdiv('img4','premiumhistory',url+'/admin/');
			ShowHideDetails('policyhistory','block','img5',url+'/admin/');
			showhidesearchdiv('img5','policyhistory',url+'/admin/');
			ShowHideDetails('remarks','block','img6',url+'/admin/');
			showhidesearchdiv('img6','remarks',url+'/admin/');
		}	
	}	//	End of with.
}	//	End of function.

function ShowNotificationArea(frm)
{
	var count =frm.elements.length;

		var i=0,k=0;
  
		for(i=1;i<count;i++)
		{
			//alert(frm.elements[i].id);
			if(frm.elements[i].type=="checkbox")
			{
				if(frm.elements[i].checked)
				{
					k=k+1;
				}
			}
		}
	
		if(k > 0)
		{
			var showhideid = document.getElementById("NotificationArea");
			var style = showhideid.style.display;
		
			showhideid.style.display = "block";
		}
		else
		{
			var showhideid = document.getElementById("NotificationArea");
			var style = showhideid.style.display;
		
			showhideid.style.display = "none";
		}
}
