function validateform(chk)
{
	fm=document.apply;

	 if(fm.title.value=="")
		{
		alert("Please Select Title");
			fm.title.focus();
			return false;
		} 

		if(fm.name.value=="")
		{
			alert("Please Enter Name");
			fm.name.focus();
			return false;
		}
		
		if(fm.surname.value=="")
		{
			alert("Please Enter Surname");
			fm.surname.focus();
			return false;
		}
		
		if(fm.address.value=="")
		{
			alert("Please Enter Address");
			fm.address.focus();
			return false;
		}
		var pos=fm.address.value.indexOf("@");
		
		if(pos!=-1)
	{
			alert("Please Enter valid Address");
			fm.address.focus();
			return false;
	}
		if(fm.postal.value=="")
		{
			alert("Please Enter Postal Code");
			fm.postal.focus();
			return false;
		}
				  function checkspace(str)
		  {  var i=0;
		  	while (i<str.length)
			{
			 
				if(str.charAt(i)==' ')
				{  
					return true;
					break;
				}	
				else
				{
					i=i+1;
				}	
									 
			}	
			
			return false;
		}	

		 if((!checkspace(fm.postal.value)) && (pos4!=-1))
		{
		 alert("Please enter Postal Code in correct format. ex:- NN16 9RT");
		fm.postal.focus();
		 return false;
		 }
		var pos4=fm.postal.value.indexOf("@");
		if(pos4!=-1)
	{
			alert("Please Enter valid Postalcode");
			fm.postal.focus();
			return false;
	}
		
		//Email validation
		if(fm.email.value=="")
		{
			alert("Please Enter Email Id");
			fm.email.focus();
			return false;
		}

		if(isEmail(fm.email.value)==false){
			alert("Please Enter Valid Email-id") ;
			fm.email.focus();
			return false;
		}
		
		homeno1 = fm.homeno.value
		
		if(homeno1=="")
		{
			alert("Please Enter Phone Number");
			fm.homeno.focus();
			return false;
		}
	if(isNaN(homeno1))
	{
		alert("Phone Number should be Numeric");
			fm.homeno.focus();
			return false;
	}
		if(fm.workno.value=="")
		{
			alert("Please Enter Work Number");
			fm.workno.focus();
			return false;
		}
if(isNaN(fm.workno.value))
	{
	alert("Work Number should be Numeric");
			fm.workno.focus();
			return false;
	}
		if(fm.day1.value=="")
		{
			alert("Please Specify Day");
			fm.day1.focus();
			return false;
		}
		if(isNaN(fm.day1.value))
	{
			alert("Day should be Numeric");
			fm.day1.focus();
			return false;
	}
		if(fm.mon1.value=="")
		{
			alert("PleaseSpecify Month");
			fm.mon1.focus();
			return false;
		}
		if(isNaN(fm.mon1.value))
	{
			alert("Month should be Numeric");
			fm.mon1.focus();
			return false;
	}
		if(fm.year1.value=="")
		{
			alert("Please Specify Year");
			fm.year1.focus();
			return false;
		}

		if(isNaN(fm.year1.value))
	{
			alert("Year should be Numeric");
			fm.year1.focus();
			return false;
	}
			var d=fm.day1.value;
			
			var m=fm.mon1.value;
			
			var y=fm.year1.value;
			
	
	   if (d<1 || d>31)
		   {
				alert("Please Check Day"); 
				fm.day1.focus(); 
				return false ; 
			}
	   if (m<1 || m>12)
		   { 
				alert("Please Check Month");
				fm.mon1.focus(); 
				return false; 
			}		
		if(y<10 || y>99)
			{
				alert("Please Enter a valid 2 digit year between 1910 and 1999"); 
				fm.year1.focus(); 
				return false;
			}
		   
			 if (m==4 || m==6 || m==9 || m==11) 
			 if (d==31) 
				 {
					alert("Please Check Date"); 
					fm.day1.focus();
					return false; 
				}
			 
			 if (m==2)//validation for he of feburary
				 {
					 var b=parseInt(y/4); 
					if (isNaN(b))
						{
							alert("Please Check Date"); fm.day1.focus();return false ; 
						}

					 if (d>29) 
						{
							alert("Please Check Date"); fm.day1.focus();return false ; 
						}

						if (d==29 && ((y/4)!=parseInt(y/4))) 
							{
								alert("Please Check Date");
								fm.day1.focus();
								return false; 
							}
			 	 } 
//		return true;


	
		if(fm.occupation.value=="")
		{
			alert("Please Enter Occupation");
			fm.occupation.focus();
			return false;
		}
var pos1=fm.occupation.value.indexOf("@");
		
		if(pos1!=-1)
	{
			alert("Please Enter valid Occupation");
			fm.occupation.focus();
			return false;
	}
		 if(fm.relqulif.value=="")
		{
			alert("Please Enter Relevant Qualification");
			fm.relqulif.focus();
			return false;
		}
		var pos2=fm.relqulif.value.indexOf("@");
		
		if(pos2!=-1)
	{
			alert("Please Enter valid  Relevant Qualification");
			fm.relqulif.focus();
			return false;
	}
		if(fm.getinfo.value=="-1")
		{
			alert("Please Select Where did you hear about the Foundation");
			fm.getinfo.focus()
			return false;
		}

		if(fm.terms.checked==false)
		{
			alert("Please Select Terms and Conditions");
			fm.terms.focus()
			return false;
		}

	    if (form.pmethod.value == 0) {
		    alert("Please choose your Payment Method.");
		    return false;
		}
  
		if(fm.information.checked==false)
		{
			alert("Please tick this box if the above information is correct");
			fm.information.focus()
			return false;
		}

	if(!isNaN(chk))
	{  
		//alert("hi");
		 fm.sub.value=chk; 
		 fm.submit();
          //window.open('apply_print.php');
		  //window.open("apply_print.php?id="+chk,"mywindow","menubar=0,resizable=1,width=350,height=350");
		  //document.apply.submit();
	}
}

function isEmail ( string ) 
{			
	if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
else
	return false;
}

function compareDates (value1, value2) {
   var date1, date2;
   var month1, month2;
   var year1, year2;

	date1  = value1.substring (0, value1.indexOf ("-"));
	month1  = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
	year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);
	date2  = value2.substring (0, value2.indexOf ("-"));
	month2  = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
	year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);
	

if( year1 < year2 ){
         return 1;
        }
		else if( year1 == year2 )
			{
                if( month1 < month2 )
					{
                        return 1;
                }
				else if( month1 == month2 )
					{
                        if( date1 <= date2 )
                                return 1;
                        else 
                                return -1;
                }
				else
                        return -1;
        }
		else 
                return -1;


if((year1 <= year2) && (month1 <= month2) && (date1 <= date2)) return 1;
	else if((date1 > date2) && ((month1 < month2) || (year1 < year2))) return 1;
	else if((date1 > date2) && (month1 > month2) && (year1 < year2)) return 1;
	else if((date1 < date2) && (month1 > month2) && (year1 < year2)) return 1;
	else return -1;
} 


