	var errFocus = "";
  function validateRegister()
  {   errFocus = "";
  	   var errBlank = "";
   var otherErr = "";
   var frmReg = document.frmRegister;
   var loginId = document.getElementById("txtUserId");
   var email = document.getElementById("txtEmail");
  
   if(document.getElementById("hidEmailReadOnly").value !="readonly"){
   		var reemail = document.getElementById("txtReEmail");			   		
   }
   var pass = document.getElementById("txtPass");
   var name = document.getElementById("txtName");
   
   var month = document.getElementById("ddMonth");
   var dt = document.getElementById("ddDate");
   var year = document.getElementById("ddYear");
   var city = document.getElementById("txtCity");
   var contry = document.getElementById("ddCountry");
   var postCode = document.getElementById("txtPostCode");

   // CHECKING FOR BLANK
   if (loginId.value.trim() == ""){ errBlank = errBlank + "- User ID\n"; setFocusOnForm(loginId); }
   if (email.value.trim() == ""){ errBlank = errBlank + "- Email address\n"; setFocusOnForm(email);}
   if(document.getElementById("hidEmailReadOnly").value != "readonly"){
  	 if (reemail.value.trim() == ""){ errBlank = errBlank + "- Re-type Email\n";setFocusOnForm(reemail); }
   }
   if (pass.value == ""){ errBlank = errBlank + "- Password\n"; setFocusOnForm(pass);}
   if (name.value.trim() == ""){ errBlank = errBlank + "- Name\n"; setFocusOnForm(name);}
   if (city.value.trim() == ""){ errBlank = errBlank + "- City\n"; setFocusOnForm(city);}

   //  REMOVING LAST ,
   if (errBlank.length>1)
   { 
   }else{  // fields are not blank
   		if (loginId.value.length < 4 || loginId.value.length >18){otherErr= otherErr + "- Psst! User ID should be of 4-18 characters \n"; setFocusOnForm(loginId);}
		if(!validateEmail(email.value)){otherErr=otherErr + "- Hey! Invalid Email address \n"; setFocusOnForm(email);}
		if(document.getElementById("hidEmailReadOnly").value != "readonly"){
			if(email.value != reemail.value){otherErr=otherErr + "- E-Mail and Re-type E-Mail do not match \n";  setFocusOnForm(reemail);}
		}
		if(pass.value.length<6){otherErr=otherErr + "- Password cannot be less than 6 characters \n";  setFocusOnForm(pass);}
		if(pass.value == loginId.value){otherErr=otherErr + "- Password cannot be same as User ID \n";  setFocusOnForm(pass);}
		
	    if(!(frmReg.rdGender[0].checked || frmReg.rdGender[1].checked))
			{otherErr=otherErr + "- Hey! Please select a gender. \n"; setFocusOnForm(frmReg.rdGender[0].checked);}
		if(dt.options[dt.selectedIndex].value == "0" || month.options[month.selectedIndex].value == "0"  || year.options[year.selectedIndex].value == "0"){otherErr=otherErr + "- Come on! Invalid Date of Birth \n";  setFocusOnForm(dt);}
			else{ if(!validateDate(dt.options[dt.selectedIndex].value,month.options[month.selectedIndex].value,year.options[year.selectedIndex].value))
					{ 
						otherErr=otherErr + "- Come on! Invalid Date of Birth \n";  setFocusOnForm(dt);
					}
					
					else{
					  //if(findage(year.options[year.selectedIndex].value) <=13){ otherErr=otherErr + "- Come on! You need to be of 13 years to sign up on dekhona.com  \n";  setFocusOnForm(dt);}	
					  if(findage(year.options[year.selectedIndex].value,month.options[month.selectedIndex].value,dt.options[dt.selectedIndex].value)==0){ otherErr=otherErr + "- Invalid Date of Birth!  \n";  setFocusOnForm(dt);}	
					}
				}
		if(contry.value == "0"){otherErr=otherErr + "- Invalid country selected \n";  setFocusOnForm(contry);} 
   }

   if (errBlank.length>1)
   { errBlank = errBlank.substring(0,errBlank.length-1);
	 alert("Hey! The following fields cannot be blank: \n\n" + errBlank);
   }else if(otherErr.length>1)
   { otherErr = otherErr.substring(0,otherErr.length-2);  // REMOVE \N FROM LAST STATEMENT
     alert(otherErr);
   }
   
  	   if(errFocus)
   { errFocus.focus(); 
   	 return false;
   }else if(otherErr.length>1)
   { return false;}				   
   else{
	   HideRegister();
	   return true;
   	}
  }
  
  function setFocusOnForm(id)
  {
  		if (errFocus == "") errFocus=id;
  }
  function findage(yr,mn,da)
{
	var d = new Date()
	var thisYear = d.getFullYear()
	var thisMonth = d.getMonth()+1
	var thisDay=d.getDate()
	if (thisYear==yr)
	{
	  if(thisMonth==mn)
	  {
	  	if(thisDay<da)
	  	{
	    	  return(0)	
	  	}
	  return(1)	
	  }
	 if(thisMonth<mn)
         {
           return(0)
	 }  
	return(1) 
	}	
}