//returns the diff betn two dates for month 1=jan,12=Dec
function GetDays(toyear, tomonth, today, fromyear, frommonth, fromday)
{
	DDate= new Date(toyear,tomonth-1,today);
	NDate=	new Date(fromyear,frommonth-1,fromday);
	
	var Days = new String((NDate-DDate)/86400000);   	
	
	return Math.floor(Days);
}

//This function is used for checking main applicant's age in broker/agentwhole.php......
function checkdobage() 
{ 
 	var d= new Date();
 	var chkage = 0;
	var cdate = 0;
	var cmonth= 0;
	
	cdate	=	d.getDate();
	cmonth	=	d.getMonth();
	with(document.frmdirectquot)   
	{	
		//	Check the age or main applicant.
		chkage = displayage(year.value, month.value, day.value);	//Age validation.
		
		if((chkage == 18) && (parseInt(day.value) > cdate) && (parseInt(month.value) >= cmonth+1)) 
		{	    
			chkage = chkage -1;
		}
		if(chkage < 18) 
		{	  
			alert("The Main Applicant's Age calculated from the \nDate of Birth just entered can't be less than 18.");
			day.focus();   
			return false;
		}	
	}	//	End of with.
}	//	End

//This function is using for \broker\template\  main_interface\broker_index_interface.php...
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


  
function displayage(yr, mon, day){ 
 
	today	 = new Date();
	 
	nextdate = new Date(today.getFullYear(),today.getMonth(),today.getDate()+1);
	
	yearspast=nextdate.getFullYear()-yr;
	
	if(parseInt(nextdate.getMonth()+1)<parseInt(mon))
	{
		yearspast=yearspast-1;
		 
	}  
	else 
	{
		if(parseInt(nextdate.getMonth()+1) == parseInt(mon))
		{
			if(parseInt(nextdate.getDate())<parseInt(day))
			{ 
				yearspast=yearspast-1;
				
			}	
		}  		  
	} 
return yearspast; 

/*		var nextdate=new Date()
		nextdate.setDate(nextdate.getDate()+1); 
		 
		d = new Date();
		if(eval(d.getMonth()+1)<10)
		{	 var presmonth = "0"+eval(d.getMonth());	}
		else
		{	 var presmonth = eval(d.getMonth());	}
		if(d.getDate()<10)
		{	var presdate = "0"+d.getDate();		}
		else
		{	var presdate = d.getDate();		}
		  
		
		var todaysdate = d.getFullYear()+"-"+presmonth+"-"+presdate;
		
		todaysdate = new Date(d.getFullYear(), presmonth, presdate+1, 00, 00, 00);

		start_date = new Date(yr,mon, day, 00, 00, 00);
		 
		var sdate=new Date(2006,1,1); 
		var edate= new Date(2006,12,31);

		var year =edate.getTime()-sdate.getTime();
		
		alert(year);
		
		var one_day=1000*60*60*24*30*12;
				
		alert(one_day);
		
		alert(nextdate+"="+start_date);
		
		//var date_diff = ((nextdate.getTime()-start_date.getTime())/(year));
		
		var date_diff = Math.ceil((todaysdate.getTime()-start_date.getTime())/(year));
		
		alert(date_diff);
		
		return date_diff;*/
}

var dtCh= "/";
var minotifyyear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to 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){
	// 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){
	var daysInotifymonth = 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 > daysInotifymonth[month]){
		alert("Please enter a valid day");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minotifyyear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minotifyyear+" and "+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
}


// Check email address
function validate_clientmgmt(noofrecord,noofpages,LastNo,frmname)
{
	if(document.clientmgm.Clicked.value == "Show")
	{
		with(clientmgm)
            	{
            		if(cno.value != null)
            		{
            			if(isNaN(cno.value))
            			{
            				alert("-Please enter proper client number.");
            				cno.focus();
            				return false;
            			}	
            		}
            	}
		return true;		
	}
	else if(document.clientmgm.Clicked.value == "Set")
	{
		return true;	
	}
	else  
	{
		return callpathNew(noofrecord,noofpages,LastNo,frmname);	
		
	}
  
}  

function checkemail(email){
	var str=email ;
	var filter="/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i" ;
	if (filter.test(str))
	testresults=true ;
	else{
		alert( email+ " is not a valid Email.\nPlease input a valid email address!" );
		testresults=false ;
	}
	return (testresults)
}

// Check the valid email
function isValidEmail(strEmail)
{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = document.users_info.Email.value;
	if (strEmail.search(validRegExp) == -1)
	{
		alert("A valid e-mail address is required.\nPlease amend and retry.");
		document.users_info.Email.value = '';
		document.users_info.Email.focus();
		return false;
	}
	return true;
}

function checkvalidemail(formname,fieldname,message)
{
	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("document."+formname+"."+fieldname+".value");

	result1=membermailid.search(emails);
	if(result1==-1)
	{
		alert(message);
		eval("document."+formname+"."+fieldname+".focus()");
		//eval("document."+formname+"."+fieldname+".value") = '';
		return false;
	}
	return true;
	/* if(eval("document."+formname+"."+fieldname+".value") != '')
	{
	alert(message);
	eval("document."+formname+"."+fieldname+".focus()");
	return false;
	}*/
}

function CheckingNull(formname,fieldname,message)
{

	if(eval("document."+formname+"."+fieldname+".value") == '')
	{
		alert(message);
		eval("document."+formname+"."+fieldname+".focus()");
		return false;
	}
	return true;
}
function Trim(Value)
{
	return Value.replace(/^\s+|\s+$/g, "");
}
function openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-350)/2);
	var top			= parseInt((screen.height-300)/2)
	var win_options = 'height='+height+',width='+width+',resizable=no,'
	+ 'scrollbars=no,left=' + left + ',top=' + top;
	window.open(url,popup_name,win_options);
}

// check the length of comment for photo/tripreport
function checklength()
{
	var commentlength = document.frmphotocomment.txtphotocomment.value.length;
	if(commentlength > 2000)
	{
		alert("-Comment should allow maximum 2000 characters.");
		document.frmphotocomment.txtphotocomment.focus();
		return false;
	}
	return true;
}

//Store Value of parent url
function geturl()
{
	document.frmAddfavourite.TxtAlias.value = opener.location;
	document.frmAddfavourite.urlalias.value = opener.location;//opener.location;
}

//Close the window
function closewindow()
{
	window.close();
}

//Function To compare Url Alias & print Message
function ChkStatus(aliasval)
{
	var urlalias=document.frmAddfavourite.TxtAlias.value;
	splitString = aliasval.split(",");
	arrlength		= splitString.length;
	for(i=0;i<arrlength;i++){
		if(splitString[i].toLowerCase() == urlalias.toLowerCase()) {
			alert("The name you have entered for the shortcut already exist in favorites menu.");
			return false;
		}
	}

}

function ChkValidation()
{
	if(document.FrmTripreport2.TxtDistanceMiles.value == '')
	{
		alert("Enter Approx Distance");
		document.FrmTripreport2.TxtDistanceMiles.focus();
		return  false;
	}
	if(document.FrmTripreport2.TxtDistanceKm.value == '') {
		alert("Enter Approx Distance");
		document.FrmTripreport2.TxtDistanceKm.focus();
		return  false;
	}
	if(document.FrmTripreport2.TxtAscentMeters.value == ''){
		alert("Enter Approx Ascent");
		document.FrmTripreport2.TxtAscentMeters.focus();
		return  false;
	}
	if(document.FrmTripreport2.TxtAscentFeet.value == '') {
		alert("Enter Approx Ascent");
		document.FrmTripreport2.TxtAscentMeters.focus();
		return  false;
	}
	return true;
}

function ValidateLogin() {

	if(document.frmLogin.UserName.value == '')
	{
		alert("Enter User Name");
		document.frmLogin.UserName.focus();
		return  false;
	}
	if(document.frmLogin.PassWord.value == '')
	{
		alert("Enter Password");
		document.frmLogin.PassWord.focus();
		return  false;
	}
	var Passlength=document.frmLogin.PassWord.value;
	var passlen = Passlength.length;
	if(passlen < 6)
	{
		alert("Password must be minimum six character long");
		document.frmLogin.PassWord.focus();
		return  false;
	}
	/*if(document.frmLogin.code.value == '')
	{
	alert('Enter Code');
	document.frmLogin.code.focus();
	return  false;
	}*/
	return true;
}

function ValidateSignUp(frm) {

	with(frm)
	{

		if(PassWord.value == '')
		{
			alert("Enter Password");
			PassWord.focus();
			return  false;
		}
		var Passlength=PassWord.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			PassWord.focus();
			return  false;
		}
		if(PassWord.value != RePassWord.value)
		{
			alert("Retyped Password should match with original password");
			RePassWord.focus();
			return  false;
		}

	}
	return true;
}


function ValidateChng_Pwd() {

	with(document.frmChng_Pwd)
	{
		if(User_Name.value == '')
		{
			alert("Enter User Name");
			User_Name.focus();
			return  false;
		}
		if(Pass_Word.value == '')
		{
			alert("Enter Old Password");
			Pass_Word.focus();
			return  false;
		}
		var Passlength=Pass_Word.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			Pass_Word.focus();
			return  false;
		}
		if(New_PassWord.value == '')
		{
			alert("Enter New Password");
			New_PassWord.focus();
			return  false;
		}
		var Passlength=New_PassWord.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			NewPassWord.focus();
			return  false;
		}
		if(CPassWord.value == '')
		{
			alert("Enter Confirm Password");
			CPassWord.focus();
			return  false;
		}
		var Passlength=CPassWord.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			CPassWord.focus();
			return  false;
		}
		if(New_PassWord.value != CPassWord.value)
		{
			alert("Confirm password should be same as new password");
			CPassWord.focus();
			return false;
		}

	}
	return true;
}

function clientchng_Pwd() {

	with(document.frmChng_Pwd)
	{
		if(Pass_Word.value == '')
		{
			alert("Enter Old Password");
			Pass_Word.focus();
			return  false;
		}
		var Passlength=Pass_Word.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			Pass_Word.focus();
			return  false;
		}
		if(New_PassWord.value == '')
		{
			alert("Enter New Password");
			New_PassWord.focus();
			return  false;
		}
		var Passlength=New_PassWord.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			NewPassWord.focus();
			return  false;
		}
		if(CPassWord.value == '')
		{
			alert("Enter Confirm Password");
			CPassWord.focus();
			return  false;
		}
		var Passlength=CPassWord.value;
		var passlen = Passlength.length;
		if(passlen < 6)
		{
			alert("Password must be minimum six character long");
			CPassWord.focus();
			return  false;
		}
		if(New_PassWord.value != CPassWord.value)
		{
			alert("Confirm password should be same as new password");
			CPassWord.focus();
			return false;
		}

	}
	return true;
}

function validateform(titlelen,notelen) {

	if(document.FrmAddItinerary.itinerarytitle.value==''){
		alert("Title is required");
		document.FrmAddItinerary.itinerarytitle.focus();
		return false;
	}
	if(document.FrmAddItinerary.itinerarytitle.value.length > titlelen){
		alert("Itinerary Title should allow maximum "+ titlelen +" character");
		document.FrmAddItinerary.itinerarytitle.focus();
		return false;
	}

	if(document.FrmAddItinerary.itinerarynote.value==''){
		alert("Note is required");
		document.FrmAddItinerary.itinerarynote.focus();
		return false;
	}

	if(document.FrmAddItinerary.itinerarynote.value.length > notelen){
		alert("Itinerary Note should allow maximum "+ notelen +" character");
		document.FrmAddItinerary.itinerarynote.focus();
		return false;
	}
	return true;
}

function checkimage(formname,fieldname)
{
	if(eval("document."+formname+"."+fieldname+".value") != ''){
		imagename=eval("document."+formname+"."+fieldname+".value");
		splitimagename	= imagename.split(".");
		imagenamelen   	= splitimagename.length;
		imageextention	= splitimagename[imagenamelen-1];
		if((imageextention != 'jpg') & (imageextention != 'gif') & (imageextention != 'jpeg') & (imageextention != 'png')) {
			alert("Upload Proper Image");
			return false;
		}
	}
	return true;
}

function getFileExtension(filename)
{
	var ext = filename.slice(filename.lastIndexOf(".")).toLowerCase();
	if(ext == ''){
		return false;
	}
	return ext;
}

//common function to check and uncheck check box....
function alterCheckBox(frm, checkboxid, obj)
{
	var count = frm.elements.length;
	for(i=1;i<count;i++)
	if(frm.elements[i].type=="checkbox" && frm.elements[i].id==checkboxid)
	frm.elements[i].checked=obj.checked;

}

//check wheather any record is seleced bfore performing action
function checkselect(frm,checkboxid,obj,name)
{
	var count = frm.elements.length;
	for(i=1;i<count;i++)
	{
		if(frm.elements[i].type=="checkbox" && frm.elements[i].id==checkboxid)
		{
			//alert(frm.elements[i].checked);
			if(frm.elements[i].checked)
			{
				if(obj.name == 'Delete')
				{
					if(confirm("Are you sure you want to delete ?"))
					{return true;}
					else
					{return false;}
				}
				else
				{return true;}
			}
		}
	}
	if(obj.name == 'Delete')
	{
		alert("Please select "+ name +" to "+ obj.name);
	}
	else
	{
		alert("Please select "+ name +" to make "+ obj.name);
	}

	return 	false;
}

// check entered value is numeric or not
function numeric(frmobj)
{
	Val = new Number(frmobj.value);
	if(Val && isNaN(Val))
	{
		alert("Enter valid records limit");
		return false;
	}
	return true;
}

//Common function to redirect....
function backToMain(frm)
{
	with(frm)
	{
		document.location	=	module_name.value;
	}
}

//This function is using for transfer policy... /transfer_policy.php...
function transpolicy()
{
	with(document.transferpolicy)
	{
		var dateObj = new Date();

			if(isDate(month.value+"/"+day.value+"/"+year.value))
			{  		
				if(description.value == '')	
				{
					alert("-Please enter description.");
					description.focus();
					return false;
				}  
			}
			else
			{
				day.focus();
				return false;
			}
			
			//dates validation here
			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(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 Transfer date.');
							day.focus();
							return false;
						}

					}
				}
	}
	  
}
}

// This function is using for Complate-app.php...
function frmValidateappl(frm, no, paymentType)
{
	//strMsg ="The Age(s) calculated from the Date of Birth(s) entered do not match that entered when asking for your Quotation. Do you want to recheck the Quotation at Step 3?";
		strMsg ="The Age(s) calculated from the Date of Birth(s) entered do not match that entered when asking for your Quotation. Click OK to go back to Step 3 and re-run the quotation with the correct ages.Click Cancel to continue on using the Date(s) of Birth you entered above."; 
	
	with(frm)
	{
		var d= new Date();
		var cyear = d.getFullYear();

		var chkage = 0;
		if(surname.value == '')
		{
			alert("-Please enter surname.");
			surname.focus();
			return  false;
		}
		if(firstname.value == '')
		{
			alert("-Please enter first name.");
			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 != '')
		{
			if((postcode.value).substring(0,2) != dcode.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("-Please enter valid email address.");
				eval("email.focus()");
				return false;
			}
		} 
		else
		{
			alert("-Please 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;
		}
			
		  
		
		chkage = displayage(year.value, month.value, day.value);//cyear - main_age.value; //Age validation //Age validation
		if(isDate(month.value+"/"+day.value+"/"+year.value))
		{
			if(main_age.value != chkage)//if(year.value != chkage)
			{
				//alert("Enter valid age for the main applicant.");
				
				var retVal = confirm(strMsg);//callMsgBox2(strMsg);
				//var response = retVal
		
				if (retVal)
				{
					document.complateapp.action = 'aquote.php'
					return true;			
				}
				else
				{
					return true;
				}
				
			}
		}
		else
		{
			day.focus();
			return false;
		}
		
		
		/*if(pay.value == "other") 
		{
			if(Trim(payer.value) == "") 
			{
				alert("-Please enter the payer's name");
				payer.focus();
				return false;
				//var Passlength=CPassWord.value;
				//var passlen = Passlength.length;
			}	//	End of if payer.
		}*/	//	End of if pay.
		
		if(paymentType == 0)
		{
			var cpamlength = cpamno.value;
			var cpamlen = cpamlength.length;
			var ehcilength=ehicno.value;
			var ehcilen = ehcilength.length;
			if(cpamno.value == '' && ehicno.value == '')
			{
				alert("-Please enter CPAM number.");
				cpamno.focus();
				return  false;
			}
			if(cpamlen > 0 && ehcilen > 0)
			{
				alert("-Please enter either CPAM or EHCI number.");
				cpamno.focus();
				return  false;
			}
			if(cpamno.value == '' && ehcilen > 0)
			{
				/*if(ehcilen < 8)
				{
					alert("-Ehci no. must be minimum 8 digit and maximum 20 digit long.");
					ehicno.focus();
					return  false;
				}*/
			}
			if(cpamlen > 0)
			{
				if(cpamlen != 15)
				{
					alert("-Cpam no. must be fifteen digits long.");
					cpamno.focus();
					return  false;
				}
			}
			var ValidChars = "0123456789";
			if(cpamlen > 0 && ehicno.value == '')
			{
				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(cpamno.value == '' && ehcilen > 0)
			{
				for (j = 0; j < ehcilength.length; j++)
				{
					var Char = ehcilength.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						//alert("-Ehci no. must be integer.");
						//ehicno.focus();
						//return  false;
					} //end if
				} 
			} 
		} // payment 0


		if(paymentType == 1)
		{
			if(cpamno.value == '')
			{
				alert("-Enter CPAM number.");
				cpamno.focus();
				return  false;
			}
			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;
				}
			}

			var ValidChars = "0123456789";
			if(cpamlen > 0)
			{
				for (j = 0; j < cpamlen; j++)
				{
					var Char = cpamlength.charAt(j);
					if (ValidChars.indexOf(Char) == -1)
					{
						alert("-Cpam no. must be integer.");
						cpamno.focus();
						return  false;
					} 
				} 
			}	

		} //end of payment 1
		
		if(height.value == '')
		{
			alert("-Please enter Height of main applicant.");
			height.focus();
			return false;
		}
		else if(!DigitsAndDot(height))
			{
				alert("Height must be integer");
				height.focus();
				return  false;
			}	
		if(weight.value == '')
		{
			alert("-Please enter weight of mail applicant.");
			weight.focus();
			return false;
		}
		else if(!DigitsAndDot(weight))
			{
				alert("Weight must be integer");
				weight.focus();
				return  false;
			}	

		if(occupation.value == '')
		{
			alert("-Please enter occupation of mail applicant.");
			occupation.focus();
			return false;
		}
		if(!CharAndSpace(occupation))
		{
       		alert("-Occupation : Only a to z, A to Z, and space is allowed.");
       		occupation.focus();
 	 		return  false;
		}
	
		if(no > 0)
		{
			var i;
			for(i=1; i<=no; i++)
			{
				var sname = 'ad_surname['+i+']';
				var SurnameObj = document.getElementById(sname);
				if(SurnameObj.value == '')
				{
					alert("-Please enter Surname of Dependant"+i);
					SurnameObj.focus();
					return  false;
				}

				var fname = 'ad_firstname['+i+']';
				var FirstnameObj = document.getElementById(fname);
				if(FirstnameObj.value == '')
				{
					alert("-Please enter Firstname of Dependant"+i);
					FirstnameObj.focus();
					return  false;
				}
				var arelation = 'ad_relation['+i+']';
				var arelationobj = document.getElementById(arelation);
				if(arelationobj.value=='')
				{
					alert("-Please enter dependant's relation with mail applicant.");
					arelationobj.focus();
					return false;
				}
				if(!CharAndSpace(arelationobj))
				{
		         		alert('-Relationship for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
			 	 		arelationobj.focus();
			 	 		return  false;
				}
				
				//age validation
				var d= new Date();
				var cyear = d.getFullYear();
				var chkage = 0;			//Age validation
				var dep = 'dep_age['+i+']';
				var dep_year = 'ad_year['+i+']';
				var dep_day = 'ad_day['+i+']';
				var dep_month = 'ad_month['+i+']';
				var depObj = document.getElementById(dep);
				var dep_yearObj = document.getElementById(dep_year);
				var dep_dayObj = document.getElementById(dep_day);
				var dep_monObj = document.getElementById(dep_month);
				
				var ValidChars = "0123456789.";
				var aheight = 'ad_height['+i+']';
				var aheightObj = document.getElementById(aheight);
				
				if(aheightObj.value=='')
				{
					alert("-Please enter dependant's height.");
					aheightObj.focus();
					return false;
				}
				else if(!DigitsAndDot(aheightObj))
				{
					alert('Height must be integer for Dependant '+i);
					aheightObj.focus();
					return  false;
				}	
				
				var aweight = 'ad_weight['+i+']';
				var aweightObj = document.getElementById(aweight);
				if(aweightObj.value=='')
				{
					alert("-Please enter dependant's weight.");
					aweightObj.focus();
					return false;
				}
				else if(!DigitsAndDot(aweightObj))
				{
					alert("Weight must be integer for Dependant "+i);
					aweightObj.focus();
					return  false;
				}	
				var aoccupation = 'ad_occupation['+i+']';
				var aoccupationobj = document.getElementById(aoccupation);
				if(aoccupationobj.value=='')
				{
					alert("-Please enter dependant's occupation.");
					aoccupationobj.focus();
					return false;
				}
				if(!CharAndSpace(aoccupationobj))
				{
		         		alert('-Occupation for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
			 	 		aoccupationobj.focus();
			 	 		return  false;
				}
				
				
				//alert(dep_yearObj.value);
				chkage = cyear - dep_yearObj.value;
				//alert(chkage);
				var dep_age = 'dep_age['+i+']';
				var dep_ageObj = document.getElementById(dep_age);
				//var dep_year = 'ad_year['+i+']';
				//var dep_month = 'ad_month['+i+']';
				//var dep_day = 'ad_day['+i+']';
								
				//var dep_dayObj = document.getElementById(dep_day);
				//var dep_monthObj = document.getElementById(dep_month);
				//var dep_yearObj = document.getElementById(dep_year);
				//alert(dep_ageObj.value);
				if(isDate(dep_monObj.value+"/"+dep_dayObj.value+"/"+dep_yearObj.value))
				{
				//if((dep_ageObj.value != chkage) && ((dep_ageObj.value < (chkage - 1)) || (dep_ageObj.value > (chkage + 1))))
					if(dep_ageObj.value != chkage)
					{
						//alert("Enter valid age for the dependant "+i);
						//var retVal = callMsgBox2(strMsg);
					//	var response = retVal
						var retVal = confirm(strMsg);//callMsgBox2(strMsg);
						//var response = retVal
					//if (response == 6)
						if (retVal)
						{
							document.complateapp.action = 'aquote.php'
							return true;			
						}
						else
						{
							return true;
						}
						//dep_dayObj.focus();
						//return false;
					}
				}
				else
				{
					dep_dayObj.focus();
					return false;
				}
				
				if(paymentType == 0) //means its a annual payment type
				{
					var ename = 'ad_ehcino['+i+']';
					var EhciObj = document.getElementById(ename);
					var cname = 'ad_cpamno['+i+']';
					var CpamObj = document.getElementById(cname);
					var cpamlength=CpamObj.value;
					var cpamlen = cpamlength.length;
					var ehcilength=EhciObj.value;
					var ehcilen = ehcilength.length;
					var ValidChars = "0123456789";
					/*
					if(CpamObj.value == '' && EhciObj.value == '')
					{
					alert('Enter CPAM Number for Dependant'+i);
					CpamObj.focus();
					return  false;
					}
					if((CpamObj.value != '') && (EhciObj.value != ''))
					{
					alert('Enter Either CPAM Number or EHCI Number for Dependant'+i);
					CpamObj.focus();
					return  false;
					} */
					
					if(CpamObj.value != '' && cpamno.value != '' && CpamObj.value == cpamno.value)
					{
						//alert("CPAM Number of Main Applicant and Dependant "+i+" should not be same.");
						//return false;
					}
					if(EhciObj.value != '' && ehicno.value != '' && EhciObj.value == ehicno.value)
					{
						//alert("EHIC Number of Main Applicant and Dependant "+i+" should not be same.");
						//return false;
					}
					if(cpamlen > 0 && EhciObj.value == '')
					{
						if(cpamno.value == '')
						{
							alert('CPAM Number for Dependant'+i+' should be entered \nonly if Main Applicant\'s CPAM Number is input.');
							return false;
						}
						if(cpamlen != 15)
						{
							alert("Cpam No. must be fifteen digit long for Dependant"+i);
							CpamObj.focus();
							return  false;
						}
					}
					if(CpamObj.value == '' && ehcilen > 0)
					{
						if(ehicno.value == '')
						{
							alert('EHIC Number for Dependant'+i+' should be entered \nonly if Main Applicant\'s EHIC Number is input.');
							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;
						}*/
					}
					if(cpamlen > 0 && EhciObj.value == '')
					{
						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();
								return  false;
							}
						}
					}
					if(CpamObj.value == '' && ehcilen > 0)
					{
						for (j = 0; j < ehcilen; j++)
						{
							Char = ehcilength.charAt(j);
							if (ValidChars.indexOf(Char) == -1)
							{
								//alert("Ehci No. must be integer for Dependant"+i);
								//EhciObj.focus();
								//return  false;
							}
						}
					}
					if(cpamlen > 0 && ehcilen > 0)
					{
						alert("-Please enter either CPAM or EHCI number for dependant"+i);
						CpamObj.focus();
						return  false;
					}
				}

				if(paymentType == 1)
				{
					var cname = 'ad_cpamno['+i+']';
					var CpamObj = document.getElementById(cname);
					var cpamlength=CpamObj.value;
					var cpamlen = cpamlength.length;
					var ValidsChars = "0123456789";
					/*if(CpamObj.value == '')
					{
					alert('Enter Cpam No. for Dependant '+i);
					CpamObj.focus();
					return  false;
					}*/
					if(CpamObj.value != '' && cpamno.value != '' && CpamObj.value == cpamno.value)
					{
						//alert("CPAM Number of Main Applicant and Dependant "+i+" should not be same.");
						//return false;
					}
					if(cpamlen > 0)
					{
						if(cpamlen != 15)
						{
							alert("Cpam No. must be fifteen digit long for Dependant "+i);
							CpamObj.focus();
							return  false;
						}
					}
					if(!DigitsOnly(CpamObj) && cpamlen > 0)
					{
						alert("Cpam No. must be integer for Dependant "+i);
						CpamObj.focus();
						return  false;
					} 
				} //end of payment= 1
			} // end of for
		}// end of dependants

		for (var c=0; c < 3; c++)
		{
			if (R1[c].checked)
			{
				if (R1[c].value == "acc")
				{
					return true;
				}
				else
				{
					alert("-You should accept to terms and conditions to proceed further.");
					return false;
				}
			} 
		}  
		/*if(!R1.checked)
		{
		alert("-I have read and understand the above Certificate of Insurance Terms and Conditions.");
		return false;
 		}*/

	} //end of with(frm)
	return true;
} // validation for complate-app.php ends here


//This function is using for \staticform\static_online-payment.php ...
//script for validating the CC Number, CCV
function frmonline_payment(frm)  //created by Girish Nambiar
{
	
	with(frm)
	{
		if(paymode.value == "ONLINE")
		{
			action="call_request.php";
			
		} // if ends here
		else // validation done for cheque payment received by agent
		{
			// Cheque Number
			var val = new Number(Chqnum.value);
			if(val && isNaN(val))
			{
				alert("Enter appropriate numeric value\n for the Cheque Number field.");
				Chqnum.focus();
				return false;
			}
			if(Chqnum.value == '')
			{
				alert("Cheque Number field cannot be left empty.");
				Chqnum.focus();
				return false;
			}
			// Cheque Bank
			if(chqbank.value == '')
			{
				alert("Enter appropriate value for the Cheque Bank field.");
				chqbank.focus();
				return false;
			}
			if(chqamt.value=='')
			{
				alert("Cheque Amount field cannot be left empty.");
				chqamt.focus();
				return false;
			}
			else if(eval("chqamt.value") <= 0) 
			{
				alert("Cheque Amount can't be zero or negative.");
				return false;
			}
			else
			{
				var ValidChars = "0123456789.";
				if(chqamt.value != '')
				{
					for (j = 0; j < chqamt.value.length; j++)
					{
						var Char = chqamt.value.charAt(j);
						if (ValidChars.indexOf(Char) == -1)
						{
							alert("Amount must be integer.");
							chqamt.focus();
							return  false;
						} 
					} 
				}	
			}
			
		} // end of elseif
		/*else if(eval(otherpay[1].checked) == true)
		{
			//alert(document.getElementById('payer1').value);
			//return false;
			if(document.getElementById('payer1').value == '')
			{
				alert("Payer should not be left empty.");
				payer1.focus();
				return false;
			}
			
			if(document.getElementById('accno').value == '')
			{
				alert("Account number should not be left empty.");
				accno.focus();
				return false;
			}
		}*/
		submit();
	} //end of with
}

//This function is using for \admin\cancel_main_applicant.php, \edit_client_details.php, \templates\top_content\complate-app.php...
/* to check main applicant's age */
function ageValidate()
{		
	var d= new Date();
	var cyear = d.getFullYear();
	
	var chkage = 0;
	
	with(document.complateapp) 
	{
		if(isDate(month.value+"/"+day.value+"/"+year.value))
		{
			chkage = displayage(year.value, month.value, day.value);//cyear - main_age.value; //Age validation
			//alert(chkage);
			//if((year.value != chkage) && ((year.value < (chkage - 1)) || (year.value > (chkage + 1))))
			if(main_age.value != chkage && age_valid_status.value != 1)
			{
				alert("The Age calculated from the Date of Birth just entered doesn't match that entered when asking for a quotation.");
				age_valid_status.value = 1;
				day.focus();
				return false;
			}
		}
		else
		{
			day.focus();
			return false;
		}
	}
}

//This function is using for /admin/add_notes.php...
function addnote()
{
	with(document.addnotes) 
	{ 
		var dateObj = new Date();
		
		
		if(isDate(cansmonth.value+"/"+cansday.value+"/"+cansyear.value))
		{	
			if(!ValidateOperationDate(cansyear, cansmonth, cansday, startyear, startmonth, startday)) 
			{
				alert("-Date of Notes must be a date after the Policy Start Date.");
				return false;
			}
			if(Remarks.value == '')
			{
				alert("-Please enter description.")
				Remarks.focus();
				return false;
			}
		}
		else
		{
			cansday.focus();
			return false;
		}	
	}
}

//This function is using for \templates\top_content\complate-app.php...
//To check dependant's age...
function ageValidateDep(no)
{	 
	var d= new Date(); 
	var cyear = d.getFullYear();
	var chkage = 0;
	
	if(no > 0)
		{
			var i;
			for(i=1; i<=no; i++)
			{
				 
				var dep_year = 'ad_year['+i+']';
				var dep_month = 'ad_month['+i+']';
				var dep_day = 'ad_day['+i+']';
				var age_valid_status1 = 'age_valid_status['+i+']';
				
				var dep_dayObj = document.getElementById(dep_day);
				var dep_monthObj = document.getElementById(dep_month);
				var dep_yearObj = document.getElementById(dep_year);
				var age_valid_status1_obj = document.getElementById(age_valid_status1);
				
				chkage = displayage(dep_yearObj.value, dep_monthObj.value, dep_dayObj.value);//cyear - dep_yearObj.value;
							
				var dep_age = 'dep_age['+i+']';
				
				var dep_ageObj = document.getElementById(dep_age);
							
				// if((dep_ageObj.value != chkage) && ((dep_ageObj.value < (chkage - 1)) || (dep_ageObj.value > (chkage + 1))))
				//alert(dep_ageObj.value);
				//alert(chkage);
				if(isDate(dep_monthObj.value+"/"+dep_dayObj.value+"/"+dep_yearObj.value))
				{
					if(dep_ageObj.value != chkage && age_valid_status1_obj.value != 1)
					{
						//alert("The Age calculated from the Date of Birth just entered doesn't match that entered when asking for a quotation. Do you wish to re-enter the date of Birth for Dependant "+i+" ?");
						alert("The Age calculated from the Date of Birth just entered doesn't match that entered when asking for a quotation");
						age_valid_status1_obj.value = 1;
						dep_dayObj.focus();
						return false;
					}
				}
				else
				{
					dep_dayObj.focus();
					return false;
				}
			}
		}
}

//This function is using for broker/agentwhole.php......
function validatefrmdirectquot(frm)
{
	with(frm)
	{
		var dateObj = new Date();
		/*
			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('-Can not register policy with past date.');
				commenceday.focus();
				return false;
			}	
			else if(parseInt(commenceday.value) < parseInt(dateObj.getDate()))
			{
				if((parseInt(commencemonth.value) <= parseInt(dateObj.getMonth())+1) && (parseInt(commenceyear.value) == parseInt(dateObj.getFullYear())))
				{
					alert("-Can not register policy with past date.");
					commenceday.focus();
					return false;
				}
			}
		}
		else
		{
			commenceday.focus();
			return false;
		}
		//validation for declaration of date... for agentwhole.php....
		if(isDate(decmonth.value+"/"+decday.value+"/"+decyear.value))
		{
			/*if((parseInt(decmonth.value) < parseInt(dateObj.getMonth())+1) && (parseInt(decyear.value) == parseInt(dateObj.getFullYear())))
			{
				alert('-Cannot get quotation for a past date.');
				decday.focus();
				return false;
			}	
			else if(parseInt(decday.value) < parseInt(dateObj.getDate()))
			{
				if((parseInt(decmonth.value) <= parseInt(dateObj.getMonth())+1) && (parseInt(decyear.value) == parseInt(dateObj.getFullYear())))
				{
					alert("-Cannot get quotation for a past date."); 
					decday.focus(); 
					return false;
				}
			}*/
		}
		else
		{
			decday.focus();
			return false;
		}		
		
		//validation for Date of birth... for main applicant in agentwhole.php....
		if(isDate(month.value+"/"+day.value+"/"+year.value))
		{
			if((parseInt(month.value) < parseInt(dateObj.getMonth())+1) && (parseInt(year.value) == parseInt(dateObj.getFullYear())))
			{
				alert('-Cannot get quotation for a past date.');
				day.focus();
				return false;
			}	
			else if(parseInt(day.value) < parseInt(dateObj.getDate()))
			{
				if((parseInt(month.value) <= parseInt(dateObj.getMonth())+1) && (parseInt(year.value) == parseInt(dateObj.getFullYear())))
				{
					alert("-Cannot get quotation for a past date.");  
					day.focus();
					return false;
				}
			}
		}
		else
		{
			day.focus();
			return false;
		}		
		
		/*if(pay.value == "other") 
		{
			if(Trim(payer.value) == "") 
			{
				alert("-Please enter the payer's name");
				payer.focus();
				return false;
			}	//	End of if payer.
		}	//	End of if pay.*/
		if(Trim(surname.value) == "")
		{
			alert("-Please enter your surname.");
			surname.focus();
			return  false;
		}
		if(Trim(firstname.value) == "")
		{
			alert("-Please enter your 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 == '')
		{
			alert("-Please enter your email address.");
			eval("email.focus()"); 
			return false;	
		}  
		if(!validemail(email))
		{
			alert("-Please enter valid 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 cpamlength = cpamno.value;
		var cpamlen = cpamlength.length;
		var ehcilength = ehicno.value;
		var ehcilen = ehcilength.length;
		if(cpamno.value == '' && ehicno.value == '') 
		{
			alert("-Please enter CPAM number.");
			cpamno.focus();
			return  false;
		}
		if(cpamlen > 0  && ehcilen > 0)
		{
			alert("-Please enter either CPAM or EHCI number.");
			cpamno.focus();
			return  false;
		}
		if(cpamno.value == '' && ehcilen > 0)
		{
			if(payment_type.value	==	"monthly") 
			{
				alert("-No monthly scheme is allowed\nfor registration under EHCI number.");
				return false;
			}
			
			/*if((ehcilen < 8) || (ehcilen > 20))
			{
				alert("-Ehci no. must be minimum 8 digit and maximum 20 digit long.");
				ehicno.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 && ehicno.value == '')
		{
			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(cpamno.value == '' && ehcilen > 0)
		{
			for (j = 0; j < ehcilength.length; j++)
			{
				var Char = ehcilength.charAt(j);
				if (ValidChars.indexOf(Char) == -1)
				{
					//alert("-Ehci no. must be integer.");
					//ehicno.focus();
					//return  false;
				}
			} 
		} 
		if(Trim(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;
		}	// end if
		if(Trim(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;
		}	// end if	
		if(Trim(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;
		}  
		var i;
		for(i = 1; i< 8; i++)
		{
			var dfirstname		=	'ad_firstname['+i+']';
			var dsurname		=	'ad_surname['+i+']';
			var dheight			=	'ad_height['+i+']';
			var dweight			=	'ad_weight['+i+']';
			var doccupation		=	'ad_occupation['+i+']';
			var drelation		=	'ad_relation['+i+']';
			var dehcino			=	'ad_ehcino['+i+']';
			var dcpamno			=	'ad_cpamno['+i+']';
			var dday			=	'ad_day['+i+']';
			var dmonth			=	'ad_month['+i+']';
			var dyear			=	'ad_year['+i+']';
			var d				=	new Date(); 
			
			firstnameobj	=	document.getElementById(dfirstname);
			surnameobj		=	document.getElementById(dsurname);
			heightobj		=	document.getElementById(dheight);
			weightobj		=	document.getElementById(dweight);
			occupationobj	=	document.getElementById(doccupation);
			relationobj		=	document.getElementById(drelation);
			cpamnoobj		=	document.getElementById(dcpamno);
			ehcinoobj		=	document.getElementById(dehcino);
			
			/* get dependent age objects. */
			dayobj			=	document.getElementById(dday);
			monthobj		=	document.getElementById(dmonth);
			yearobj			=	document.getElementById(dyear);
			
			//	get current date, month and 4 digit year in separate variables.
				var cyear = d.getFullYear();
				var cmonth= d.getMonth();
				var cday  = d.getDate();
				var chkage = 0;
				
				//	Check for age difference.
				chkage	=	displayage(yearobj.value, monthobj.value, dayobj.value);
				if(isDate(monthobj.value+"/"+dayobj.value+"/"+yearobj.value))
				{
					//	If month is greater than current month and also the year selected is 
					//	same as current year or any future year then return false.
					if((parseInt(monthobj.value) >	cmonth+1) && (chkage <= 0)) 
					{
						alert("Date of Birth can't be a future date.");
						//	Set focus to day control for that dependent.
						dayobj.focus();
						return false;
					} //	end of if.
					//	Else check for month and date w.r.t. current year.
					else if((parseInt(monthobj.value) == cmonth+1) && (chkage <= 0)) 
					{
						//	If month is greater than current month and the year is current year.
						if(parseInt(dayobj.value) > cday) 
						{
							//	If date of month is greater than current date of month then return false.
							alert("Date of Birth can't be a future date.");
							//	Set focus to day control for that dependent.
							dayobj.focus();
							return false;
						} 
					} 
				}
				else
				{
					dayobj.focus();
					return false;
				}
			
			/* If firstname and surname of a dependant is not entered then check. */
			if((firstnameobj.value	==	'') || (surnameobj.value	==	'')) 
			{
				/* then the following data should not be entered. */
				if((heightobj.value != '') || (weightobj.value != '') || (occupationobj.value != '') || (relationobj.value != '')) 
				{
					alert('-No firstname or surname for Dependant['+i+'] .');
					surnameobj.focus();
					return false;
				}
			}	
			/* If firstname and surname of a dependant is entered then check. */
			else if((firstnameobj.value	!=	'') && (surnameobj.value	!=	'')) 
			{
				if(relationobj.value == '') 
				{
					alert('-Relation for Dependant['+i+'] is missing.');
					relationobj.focus();
					return false;
				}
				if(!CharAndSpace(relationobj))
				{
		         		alert('-Relationship for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
			 	 		relationobj.focus();
			 	 		return  false;
				}
				/* then the following data should be entered. */
				if(heightobj.value == '') 
				{
					alert("-Height for Dependant["+i+"] is missing.");
					heightobj.focus();
					return false;
				}
				
				if(!DigitsAndDot(heightobj))
				{
					alert("-Height : Only 0 to 9, '.' is allowed for dependant ["+i+"].");
					heightobj.focus();
					return  false;
				}	
				if(weightobj.value == '') 
				{
					alert('-Weight for Dependant['+i+'] is missing.');
					weightobj.focus();
					return false;
				}
				if(!DigitsAndDot(weightobj))
				{
					alert("-Weight : Only 0 to 9, '.' is allowed for dependant ["+i+"].");
					weightobj.focus();
					return  false;
				}	
				if(occupationobj.value == '')  
				{
					alert('-Occupation for Dependant['+i+'] is missing.');
					occupationobj.focus();
					return false;
				}
				if(!CharAndSpace(occupationobj))
				{
		         		alert('-Occupation for Dependant['+i+'] : Only a to z, A to Z, and space is allowed.');
			 	 		occupationobj.focus();
			 	 		return  false;
				}
				var ehcilength = ehicno.value;
				var ehcilen = ehcilength.length;
				var cpamlength = cpamnoobj.value;
				var cpamlen = cpamlength.length;
				if((ehcilen > 0) && (cpamlen > 0))
				{
					alert("-CPAM Number of Dependant is only required\n when Main Applicant\'s CPAM Number is entered.");
					cpamnoobj.focus();
					return false;
				}
				if((cpamlen > 0) && (ehcilen > 0))
				{
					alert("-EHIC Number of Dependant is only required\n when Main Applicant\'s EHIC Number is entered.");
					ehcinoobj.focus();
					return false;
				} 
				var cpam = parseInt(cpamnoobj.value);
				if(cpamno.value != '' && cpamnoobj.value != '' && cpam == cpamno.value)
				{
					//alert('-CPAM Number of Main Applicant and Dependant '+i+' can\'t be same.');
					//cpamnoobj.focus();
					//return  false;
				}
				var ehci = parseInt(ehcinoobj.value);
				if(ehicno.value != '' && ehcinoobj.value != '' && ehicno.value == ehci)
				{
					/*alert('-EHIC Number of Main Applicant and Dependant '+i+' can\'t be same.');
					ehcinoobj.focus();
					return  false;*/
				} 
				if(cpamlen > 0 && ehcilen > 0)
				{
					alert("-Enter Either CPAM or EHCI Number.");
					cpamnoobj.focus();
					return  false;
				}
				var dehcilength=ehcinoobj.value;
				var dehcilen = dehcilength.length;
				if(cpamnoobj.value == '' && ehcinoobj.value != '')
				{
					/*if((dehcilen < 8) || (dehcilen > 20))
					{
						alert("-Ehci No. must be minimum 8 digit and maximum 20 digit long.");
						ehcinoobj.focus();
						return  false;
					}*/
				}
				var dcpamlength=cpamnoobj.value;
				var dcpamlen = dcpamlength.length;
				var dehcilength = ehcinoobj.value;
				var dehcilen = dehcilength.length;
				if(dcpamlen > 0)
				{
					if(dcpamlen != 15)
					{
						alert("-Cpam No. must be fifteen digit long.");
						cpamnoobj.focus();
						return  false;
					}
				}
				var ValidChars = "0123456789";
				if(dcpamlen > 0 && ehcinoobj.value == '')
				{
					for (j = 0; j < dcpamlength.length; j++)
					{
						var Char = dcpamlength.charAt(j);
						if (ValidChars.indexOf(Char) == -1)
						{
							alert("-Cpam No. must be integer.");
							cpamnoobj.focus();
							return  false;
						}
					}
				}
				if(cpamnoobj.value == '' && dehcilen > 0)
				{
					for (j = 0; j < dehcilength.length; j++)
					{
						var Char = dehcilength.charAt(j);
						if (ValidChars.indexOf(Char) == -1)
						{
							//alert("-Ehci No. must be integer.");
							//ehicno.focus();
							//return  false;
						} 
					} 
				} 
			}	
		}	
	 }	// end of with.
}	// end of f
