

/////////////////////////////////////////////////
	 
 
/////////////////////////////////////////////////

 
///////////////////////////
//Start this function will call on body onload
function bodyonload()
{
	if(FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value=="U")
	{
	FrmReg1.rbtnChildNo.disabled=true;
	FrmReg1.rbtnChildYesLT.disabled=true;
	FrmReg1.rbtnChildYesLS.disabled=true;
	
	 
	
	}
	else 
	{
	FrmReg1.rbtnChildNo.disabled=false;
	FrmReg1.rbtnChildYesLT.disabled=false;
	FrmReg1.rbtnChildYesLS.disabled=false;
	}

}

//End this function will call on body onload

// start Check valid format of email

function ValidateEmail( Email )
	{
		var atCharPresent = false;
		var dotPresent = false;

		for ( var Idx = 0; Idx < Email.length; Idx++ )
		{
			if ( Email.charAt ( Idx ) == '@' )
				atCharPresent = true;
			if ( Email.charAt ( Idx ) == '.' )
				dotPresent = true;
		}

		if ( !atCharPresent || !dotPresent )
			return false;

		return true;
	}
	
// End Check valid format of email	

// start function for check IS Empty

function IsEmpty(obj, obj_type)
{
	if (obj_type == "text" || obj_type == "password" || obj_type == "textarea" || obj_type == "file")	{
		var objValue;
		
		objValue = obj.value.replace(/\s+$/,"");
		
		if (objValue.length == 0) {
			//obj.focus();
			return true;
		} else {
			return false;
		}
	} else if (obj_type == "select") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[i].selected) {
				if(obj.options[i].value == "") {
					obj.focus();
					return true;
				} else {
					return false;
				}
			}
			
		}
		return true;	
	} else if (obj_type == "radio" || obj_type == "checkbox") {
		if (!obj[0] && obj) {
			if (obj.checked) {
				return false;
			} else {
				obj.focus();
				return true;	
			}
		} else {
			for (i=0; i < obj.length; i++) {
				if (obj[i].checked) {
					return false;
				}
			}
			obj[0].focus();
			return true;
		}
	} else {
		return false;
	}
}
// End of  function for check ISEmpty


//start Date and Month Changes
function updateDay(change,formName,yearName,monthName,dayName)
{	
	
	var form = document.forms[formName];
	var yearSelect = form[yearName];
	var monthSelect = form[monthName];
	var daySelect = form[dayName];
	var year = yearSelect[yearSelect.selectedIndex].value;
	var month = monthSelect[monthSelect.selectedIndex].value;
	var day = daySelect[daySelect.selectedIndex].value;

	if (change == 'month' || (change == 'year' && month == 2))
	{
		var i = 31;
		var flag = true;
		while(flag)
		{
			var date = new Date(year,month-1,i);
			if (date.getMonth() == month - 1)
			{
				flag = false;
			}
			else
			{
				i = i - 1;
			}
		}

		daySelect.length = 0;
		daySelect.length = i;
		var j = 0;
		while(j < i)
		{
			daySelect[j] = new Option(j+1,j+1);
			j = j + 1;
		}
		if (day <= i)
		{
			daySelect.selectedIndex = day - 1;
		}
		else
		{
			daySelect.selectedIndex = daySelect.length - 1;
		}
	}
}

//End Date and Month Changes

// Start Form Validation
function validateform(  )
	{
	
	if(document.getElementById)
{

  document.getElementById('divProfileIdExist').className="hide";
  document.getElementById('divEmailExist').className="hide";
document.getElementById('sp_ProfileId').className="spanErrorNot";
document.getElementById('sp_Gender').className="spanErrorNot";
document.getElementById('sp_DOB').className="spanErrorNot";
document.getElementById('sp_MotherTongue').className="spanErrorNot";
document.getElementById('sp_MaritalStatus').className="spanErrorNot";
document.getElementById('sp_ChildStatus').className="spanErrorNot";
document.getElementById('sp_CountryLiving').className="spanErrorNot";
document.getElementById('sp_EmployedIn').className="spanErrorNot";
document.getElementById('sp_Religion').className="spanErrorNot";
document.getElementById('sp_Citizenship').className="spanErrorNot";
document.getElementById('sp_Email').className="spanErrorNot";
document.getElementById('sp_Password').className="spanErrorNot";
document.getElementById('sp_ConfirmPassword').className="spanErrorNot";

//document.getElementById('divProfileIdExist').className="spanErrorNot";
//document.getElementById('divEmailExist').className="spanErrorNot";


}
	
	
	var FrmReg1 = this.document.FrmReg1;
		
			  
		     
		// check empty of txtProfId
		if ( FrmReg1.txtProfId.value == "" )
		{
			alert( "Please enter the Profile Id" );
			if(document.getElementById) 
			document.getElementById('sp_ProfileId').className="spanError";
			FrmReg1.txtProfId.focus( );
			return false;
		}	
		
		if (FrmReg1.txtProfId.value.length < 4 )
		{
			alert( "Length of Profile Id should not be less than 4" );
			if(document.getElementById) 
			document.getElementById('sp_ProfileId').className="spanError";
			FrmReg1.txtProfId.focus( );
			return false;
		}	
		
		if (FrmReg1.txtProfId.value.length > 20 )
		{
			alert( "Length of Profile Id should not be greater than 20" );
			if(document.getElementById) 
			document.getElementById('sp_ProfileId').className="spanError";
			FrmReg1.txtProfId.focus( );
			return false;
		}	
			
		
		// for check priofileId doesn't contain any characters except than a-z,A-Z,0-9
		
		tmpProfleId = FrmReg1.txtProfId.value;
		validProfileId = 1;		
		for( var idx=0; idx< tmpProfleId.length; idx++ )
		{
			ch = tmpProfleId.charAt(idx);
			if( !((ch>='a') && (ch<='z')) && !((ch>='A') && (ch<='Z')) && !((ch>=0) && (ch <=9)) )
			{
				validProfileId = 0;
				break;						
			}					
		}
				
		if( validProfileId ==0 )
		{
				alert( "Invalid ProfileID "+ FrmReg1.txtProfId.value + "\nProfileID should contain only characters and digits." );
				if(document.getElementById) 
				document.getElementById('sp_ProfileId').className="spanError";
				FrmReg1.txtProfId.focus();
				return false;
		}

		 for ( var Idx = 0; Idx < FrmReg1.txtProfId.value.length; Idx++ )
			{
				if ( FrmReg1.txtProfId.value.charAt(Idx) == '	'
					|| FrmReg1.txtProfId.value.charAt(Idx) == ' '
					|| FrmReg1.txtProfId.value.charAt(Idx) == ','
					|| FrmReg1.txtProfId.value.charAt(Idx) == '/'
					|| FrmReg1.txtProfId.value.charAt(Idx) == '\\'
					|| FrmReg1.txtProfId.value.charAt(Idx) == ';' )
				{
					alert( "Blanks or spaces or other invalid characters are not allowed in the Profile ID" );
					if(document.getElementById) 
					document.getElementById('sp_ProfileId').className="spanError";
					FrmReg1.txtProfId.focus( );
					return false;
				}
			}
		
		// check empty of rbtnGMale and  rbtnGFemale
		if ( !FrmReg1.rbtnGMale.checked && !FrmReg1.rbtnGFemale.checked)
		{
			alert( "Please select the Gender." );
			if(document.getElementById) 
			document.getElementById('sp_Gender').className="spanError";
			FrmReg1.rbtnGMale.focus( );
			return false;
		}
		
		// check empty of DOBMONTH , DOBDAY , DOBYEAR
		if(document.FrmReg1.DOBMONTH.options[document.FrmReg1.DOBMONTH.selectedIndex].text=="-Month-" && document.FrmReg1.DOBDAY.options[document.FrmReg1.DOBDAY.selectedIndex].text=="-Date-" && document.FrmReg1.DOBYEAR.options[document.FrmReg1.DOBYEAR.selectedIndex].text=="-Year-") 
		{
			alert("Select Date of Birth of Profile Holder");
			if(document.getElementById)
			document.getElementById('sp_DOB').className="spanError";
			FrmReg1.DOBMONTH.focus();
			return false;
  		}
  		
  		if (document.FrmReg1.DOBMONTH.options[document.FrmReg1.DOBMONTH.selectedIndex].text=="-Month-")	
			  	{
				  	alert("Select Month of Date of Birth");
				  	if(document.getElementById)
					document.getElementById('sp_DOB').className="spanError";
					FrmReg1.DOBMONTH.focus();
					return false;
			  	}
			  if (document.FrmReg1.DOBDAY.options[document.FrmReg1.DOBDAY.selectedIndex].text=="-Date-")	
			  	{
				  	alert("Select DATE of Date of Birth");
				  	if(document.getElementById)
					document.getElementById('sp_DOB').className="spanError";
					FrmReg1.DOBDAY.focus();
					return false;
			  	}
			  if (document.FrmReg1.DOBYEAR.options[document.FrmReg1.DOBYEAR.selectedIndex].text=="-Year-")		
			  	{
				  	alert("Select Year of Date of Birth");
				  	if(document.getElementById)
					document.getElementById('sp_DOB').className="spanError";
					FrmReg1.DOBYEAR.focus();
					return false;
			  	}
			  	
			  	// calculating year for female atleast 18 and male of atleast 21
		var calyear = displayage(FrmReg1.DOBYEAR.value,FrmReg1.DOBMONTH.value,FrmReg1.DOBDAY.value, 'years', 0, 'rounddown')
			//alert (calyear);
						 
			
			if (  calyear < 21 && FrmReg1.rbtnGMale.checked)
				{
					alert("You Should be 21 years to Register");
					if(document.getElementById)
					document.getElementById('sp_DOB').className="spanError";
					FrmReg1.DOBYEAR.focus();
					return false;
				}
		 
			
			if (  calyear < 18 && FrmReg1.rbtnGFemale.checked)
				{
					alert("You Should be 18 years to Register");
					if(document.getElementById)
					document.getElementById('sp_DOB').className="spanError";
					FrmReg1.DOBYEAR.focus();
					return false;
				}	
			
	
			if ( FrmReg1.ddlmothertongue.options[FrmReg1.ddlmothertongue.selectedIndex].value== "" )
			{
			alert( "Please select Mother Tongue" );
			if(document.getElementById)  
			document.getElementById('sp_MotherTongue').className="spanError";
			FrmReg1.ddlmothertongue.focus( );
			return false;
			}	
			
			if ( FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value== "" )
			{
			alert( "Please select Marital Status " );
			if(document.getElementById) 
			document.getElementById('sp_MaritalStatus').className="spanError";
			FrmReg1.ddlMaritalStatus.focus( );
			return false;
			}	
			
			if(FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value != "U")
			{
				if((FrmReg1.rbtnChildNo.checked==false)&&(FrmReg1.rbtnChildYesLT.checked==false)&&(FrmReg1.rbtnChildYesLS.checked==false))
				{
					alert("Please indicate whether the child is/are living with you.");
					if(document.getElementById) 
					document.getElementById('sp_ChildStatus').className="spanError";
					FrmReg1.rbtnChildNo.focus( );
					return false;
				
				}			
			}
	
			 
			
			if(FrmReg1.ddlCouResidence.options[FrmReg1.ddlCouResidence.selectedIndex].value == "") 
			{
				alert("Please select country of living of profile holder ");
				if(document.getElementById) 
				document.getElementById('sp_CountryLiving').className="spanError";
				FrmReg1.ddlCouResidence.focus( );
				return false;			
			}
			
			if((FrmReg1.rbtnGEmployed.checked==false)&&(FrmReg1.rbtnPEmployed.checked==false)&&(FrmReg1.rbtnBEmployed.checked==false)&&(FrmReg1.rbtnDEmployed.checked==false)&&(FrmReg1.rbtnNEmployed.checked==false))
			{
				alert("Please Indicate on which category profile holder Employed");
				if(document.getElementById) 
				document.getElementById('sp_EmployedIn').className="spanError";
				FrmReg1.rbtnGEmployed.focus( );
				return false;			
			
			}
			
			if(FrmReg1.ddlReligion.options[FrmReg1.ddlReligion.selectedIndex].value == "") 
			{
				alert("Please select Religion of profile holder ");
				if(document.getElementById) 
				document.getElementById('sp_Religion').className="spanError";
				FrmReg1.ddlReligion.focus( );
				return false;			
			}
			
			if(FrmReg1.ddlCitizenship.options[FrmReg1.ddlCitizenship.selectedIndex].value == "") 
			{
				alert("Please select Citizenship of  profile holder ");
				if(document.getElementById) 
				document.getElementById('sp_Citizenship').className="spanError";
				FrmReg1.ddlCitizenship.focus( );
				return false;
			
			}
			
			// Check E-mail
			if(FrmReg1.txtEmail.value=="")
			{
				alert("Please Insert a valid Email Id ");
				if(document.getElementById) 
				document.getElementById('sp_Email').className="spanError";
				FrmReg1.txtEmail.focus( );
				return false;
			}
			
		else
		{
			if ( !ValidateEmail( FrmReg1.txtEmail.value ) )
			{
				alert( "Invalid E-mail " + FrmReg1.txtEmail.value );
				document.getElementById('sp_Email').className="spanError";
				FrmReg1.txtEmail.focus( );
				return false;
			}
			for ( var Idx = 0; Idx < FrmReg1.txtEmail.value.length; Idx++ )
			{
				if ( FrmReg1.txtEmail.value.charAt(Idx) == '	'
					|| FrmReg1.txtEmail.value.charAt(Idx) == ' '
					|| FrmReg1.txtEmail.value.charAt(Idx) == ','
					|| FrmReg1.txtEmail.value.charAt(Idx) == '/'
					|| FrmReg1.txtEmail.value.charAt(Idx) == '\\'
					|| FrmReg1.txtEmail.value.charAt(Idx) == ';' )
				{
					alert( "Invalid characters or Blanks are not allowed in the E-mail ID.\nPlease enter only one E-mail ID." );
					document.getElementById('sp_Email').className="spanError";
					FrmReg1.txtEmail.focus( );
					return false;
				}
			}
		}
			
			
			if(FrmReg1.txtPass.value=="")
			{
				alert("Please Insert Password ");
				if(document.getElementById) 
				document.getElementById('sp_Password').className="spanError";
				FrmReg1.txtPass.focus( );
				return false;
			}
			
			if ( FrmReg1.txtPass.value.length < 4 )
			{
				alert( "Password must be atleast 4 characters." );
				if(document.getElementById) 
				document.getElementById('sp_Password').className="spanError";
				FrmReg1.txtPass.focus( );
				return false;
			}
			
			
			if ( FrmReg1.txtPass.value.length > 20 )
			{
				alert( "Password should not be greater than 20 characters." );
				if(document.getElementById) 
				document.getElementById('sp_Password').className="spanError";
				FrmReg1.txtPass.focus( );
				return false;
			}
			
		tmpPass = FrmReg1.txtPass.value;

		validPassword = 1;

		
		for( var idx=0; idx< tmpPass.length; idx++ )
		{
			ch = tmpPass.charAt(idx);

			if( !((ch>='a') && (ch<='z')) && !((ch>='A') && (ch<='Z')) && !((ch>=0) && (ch <=9)) )
			{
				validPassword = 0;
				break;
			}
		}

		if( validPassword ==0 )
		{
			alert( "Password should contain only characters and digits." );
			if(document.getElementById) 
			document.getElementById('sp_Password').className="spanError";
			FrmReg1.txtPass.value="";
			FrmReg1.txtConPass.value="";
			FrmReg1.txtPass.focus();
			return false;
		}
			
			
			if(FrmReg1.txtConPass.value=="")
			{
				alert("Please confirm Password ");
				if(document.getElementById) 
				document.getElementById('sp_ConfirmPassword').className="spanError";
				FrmReg1.txtConPass.focus( );
				return false;
			}
			
			if ( FrmReg1.txtPass.value != FrmReg1.txtConPass.value )
			{
			alert( "Password does not match, please re-enter password" );
			if(document.getElementById) 
			document.getElementById('sp_Password').className="spanError";
			document.getElementById('sp_ConfirmPassword').className="spanError";
			FrmReg1.txtPass.value = "";
			FrmReg1.txtConPass.value = "";
			FrmReg1.txtPass.focus( );
			return false;
			}
			
			if (FrmReg1.chkTerms.checked==false)
			{
				alert( "You have to agree to the Terms and Condition before continuing" );
				FrmReg1.chkTerms.focus();
				return false;
			}
		 
		 
		 //funChkEmailProflieId();
		 
		  	
			return true;				
	
	}

// End Form Validation

// Start ChildStatus

function ChildStatus()
{
if(FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value=="U")
{
	FrmReg1.rbtnChildNo.disabled=true;
	FrmReg1.rbtnChildYesLT.disabled=true;
	FrmReg1.rbtnChildYesLS.disabled=true;
	FrmReg1.rbtnChildNo.checked=false;
	FrmReg1.rbtnChildYesLT.checked=false;
	FrmReg1.rbtnChildYesLS.checked=false;
}
else if((FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value=="W")||(FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value=="D") || (FrmReg1.ddlMaritalStatus.options[FrmReg1.ddlMaritalStatus.selectedIndex].value=="S"))
{
	FrmReg1.rbtnChildNo.disabled=false;
	FrmReg1.rbtnChildYesLT.disabled=false;
	FrmReg1.rbtnChildYesLS.disabled=false;
}

}

// start function for calculataing age using DOB
 function displayage(yr, mon, day, unit, decimal, round){

var one_day=1000*60*60*24
var one_month=1000*60*60*24*30
var one_year=1000*60*60*24*30*12


today=new Date()
var pastdate=new Date(yr, mon-1, day)

var countunit=unit
var decimals=decimal
var rounding=round

finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
decimals=(decimals<=0)? 1 : decimals*10

if (unit!="years"){
if (rounding=="rounddown")
//document.write(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
alert (Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+' '+countunit)
else
//document.write(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
alert (Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+' '+countunit)
}
else
{
yearspast=today.getFullYear()-yr-1
tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
pastdate.setFullYear(today.getFullYear())
pastdate2=new Date(today.getFullYear()-1, mon-1, day)
tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
//document.write(yearspast+tail+" "+countunit)
//alert (yearspast+tail+' '+countunit)
var calyear=yearspast+tail;
}
return calyear;
}