/************************************
* File : register.js                * 
* Created : 25 dec 2009             *
* Edited : 22 jan 2010              *
* Author : Palak Bhalala            *
* Email : palak.bhalala@gmail.com   *
*************************************/

function validateform(theform)
		{

			var emailId = theform.email.value;
			var apos=emailId.indexOf("@");
			var dotpos=emailId.lastIndexOf(".");
			var lastpos=emailId.length-1;		
			if (emailId.indexOf(' ')==-1 && 0 < emailId.indexOf('@') && 0 < emailId.indexOf('.') && emailId.indexOf('@')+1 < emailId.length && emailId.length >= 5)
		{
	    }
	    else
	    {
	      alert("Please provide a valid email address");
	      theform.email.focus();
	      return false;
		}
			
			if(theform.profileid.value == "")
			{
				alert("please enter Profile ID");
				theform.profileid.focus();
				return false;
			}
			
			else if(theform.email.value == "")
			{
				alert("Please enter Email");
				theform.email.focus();
				return false;
			}
			
			
			
			else if(theform.retypeemail.value == "")
			{
				alert("Please Re-type Email");
				theform.retypeemail.focus();
				return false;
			}
			
			else if(theform.retypeemail.value != theform.email.value)
			{
				alert("Email Mismatch! Please Re-type correct Email");
				theform.retypeemail.focus();
				theform.retypeemail.select();
				return false;
			}			
			
			else if(theform.password1.value == "")
			{
				alert("Please enter Password");
				theform.password1.focus();
				return false;
			}
	
			else if(theform.password2.value == "")
			{
				alert("Please Retype Password");
				theform.password2.focus();
				return false;
			}
			
			else if(theform.password2.value != theform.password1.value)
			{
				alert("Password Mismatch! Please Retype Correct Password");
				theform.password2.focus();
				theform.password2.select();
				return false;
			}
			
			else if(theform.name.value == "")
			{
				alert("Please enter your name");
				theform.name.focus();
				return false;
			}
			
			
			
			else if(theform.gender[1].checked == false && theform.gender[0].checked == false)
			{
				alert("Please select gender");
				theform.gender[1].focus();
				return false;
			}
			
			else if(theform.day.options[theform.day.selectedIndex].value == "")
			{
				alert("Please select your date of birth");
				theform.day.focus();
				return false;
			}
			
			else if(theform.month.options[theform.month.selectedIndex].value == "")
			{
				alert("Please select your date of birth");
				theform.day.focus();
				return false;
			}
			
			else if(theform.year.options[theform.year.selectedIndex].value == "")
			{
				alert("Please select your date of birth");
				theform.day.focus();
				return false;
			}
			
			else if(theform.MARITAL_STATUS[0].checked == false 
					&& theform.MARITAL_STATUS[1].checked == false
					&& theform.MARITAL_STATUS[2].checked == false
					&& theform.MARITAL_STATUS[3].checked == false
					&& theform.MARITAL_STATUS[4].checked == false)
			{
				alert("Please select Marital Status");
				theform.MARITAL_STATUS[0].focus();
				return false;
			}
			
			else if(theform.MARITAL_STATUS[0].checked == false && theform.NOOFCHILDREN.options[theform.NOOFCHILDREN.selectedIndex].value == "")
			{
				alert( "Please select the number of children" );
				theform.NOOFCHILDREN.focus( );
				return false;
			}
			
			else if(theform.MARITAL_STATUS[0].checked == false && 
					theform.NOOFCHILDREN.selectedIndex > 1 && 
					theform.CHILDLIVINGWITHME[0].checked == false	&& 
					theform.CHILDLIVINGWITHME[1].checked == false)
			{
				alert("Please indicate whether the child /children is/are living with you.");
				theform.CHILDLIVINGWITHME[0].focus( );
				return false;	
			}
			
			else if(theform.Language.options[theform.Language.selectedIndex].value == "")
			{
				alert("Please select your Mother Tongue");
				theform.Language.focus();
				return false;
			}
			
			else if(theform.community.options[theform.community.selectedIndex].value == "")
			{
				alert("Please select your Religion/Community");
				theform.community.focus();
				return false;
			}
			
			else if(theform.caste.options[theform.caste.selectedIndex].value == "0")
			{
				alert("Please select your Caste");
				theform.caste.focus();
				return false;
			}
			
			else if(theform.profilec.options[theform.profilec.selectedIndex].value == "")
			{
				alert("Please select Profile Created For");
				theform.profilec.focus();
				return false;
			}
			
			else if(theform.confirm_policy.checked == false)
			{
				alert("You need to be agree with our privacy policy and terms and conditions");
				theform.confirm_policy.focus();
				return false;
			}

			
			return true;
		}


var result;
var xmlhttp;
var theurl;
function loadXMLDoc(url)
{
theurl = url;
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=caste_Change
today =  new Date();
rnd = today.getTime( );  
url = url + "?rnd=" + rnd;
var i=0;
var Temp=document.frm_registration.community.options[document.frm_registration.community.selectedIndex].value;
url = url + "&id=" + Temp;
xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}
function caste_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
		result = xmlhttp.responseText
		document.getElementById('castespan').innerHTML = result;
    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}