
  function changeDisplay(id, visibility, display)
  {		
	  obj = document.getElementsByTagName("div");
	  if(obj[id] != null)
	  {
		     obj[id].style.visibility = visibility;
		     obj[id].style.display = display;
	  }
   }
	
	function changeObjDisplay(id,objType, visibility, display)
	{
	    if(objType =="select")		
		   obj = document.getElementsByTagName("select");
		else if(objType =="radio")
		   obj = document.getElementsByTagName("radio");
		   
		if(obj[id] != null)
		{
		     obj[id].style.visibility = visibility;
		     obj[id].style.display = display;
		}
		
	}
	
	
  function changeSpanDisplay(id, visibility, display)
  {	
  
 	  //alert(" changeSpanDisplay span id: "+id);
	  obj = document.getElementsByTagName("span");
	  if(obj[id] != null)
	  {
		     obj[id].style.visibility = visibility;
		     obj[id].style.display = display;
	  }
  }
 
  function showObject(form)	
  {
  		var href="http://ca.lightspeedpanel.com/fr/register/join.html";
        var i=0;
        if(document.registerForm.country_id != null)
		    i = document.registerForm.country_id.options.selectedIndex;	    
		
		if(i == "2"){
			location.replace(href);			
		}
  }
 	

  function openURL(form) 
  {
		var country = registerForm.country_id.options.selectedIndex;
		var day = registerForm.birth_day.options.selectedIndex;
		var month = registerForm.birth_month.options.selectedIndex;
		var year = registerForm.birth_year.options.selectedIndex;
		
		if((day!="") || (month!="") || (year!=""))
		{
			if(country != 0) 
			{
				window.location="http://designer-us/x/new/registration2.html";
				return true;
			}
			else 
			{
				alert('select country');
				return false;
			}
		}
		else 
		{
			alert('Please select the day, month and year');
			return false;
		}
		
		return false;
  }
	
	
	function showHHSize(form) {
    var i=0;
    if(form.household_size_id != null)
	     i = form.household_size_id.value;
	if (i > 1 && i != 255)
	{	
		changeDisplay('r2id1','visible','block');
		showChildSection(form);
	}
	else 
	{
		changeDisplay('r2id1','hidden','none');
		changeDisplay('r2id3','hidden','none');
		form.child_id.value=255;
		changeDisplay('child_id_div_1','hidden','none');
		changeDisplay('child_id_div_2','hidden','none');
		changeDisplay('child_id_div_3','hidden','none');
		changeDisplay('child_id_div_4','hidden','none');
		changeDisplay('child_id_div_5','hidden','none');
		changeDisplay('child_id_div_6','hidden','none');
		return false;
	}
}
	

	
function showChildSection(form)
	{
	var num = 255;
    if(form.child_id != null) {
		num = form.child_id.value;
    }
    //alert("showChildSection: num : "+num); 

    if (num != 255) {
		var numChild =  form.household_size_id.value - 1;
		if(document.getElementById("child_id") != null && num > numChild) {
            form.child_id.value = numChild
			num = numChild;
        }
    } 

    //alert("showChildSection : final num: "+num);    
    if(num > 0 && num < 255) {
		//changeDisplay('r2id2','visible','block');
		changeDisplay('r2id3','visible','block');
		//changeDisplay('child_take_survey_div','visible','block');
		//calcAllowedNumChild(form);
	} else {
        //changeDisplay('r2id2','hidden','none');
        changeDisplay('r2id3','hidden','none');
         //changeDisplay('child_take_survey_div','hidden','none');
    }  
	showChildStats(form); //change number of children displayed
}
	

function calcAllowedNumChild(form) {
   var maxChild=5;
   var numChild=0;
   var hhSize =0;

   if(document.getElementById("child_id") != null) {	    
        numChild = form.child_id.value;
   }
   if (numChild != 255) {
	   if(document.getElementById("household_size_id") != null) {  
	        hhSize = form.household_size_id.value;
	   }
	   if(numChild >= hhSize) {
	        numChild = hhSize -1;
	   }
	   if(numChild < 0) {
	       numChild=0;
	   }
   }
   return numChild;
}	

function showChildStats(form) {
	var numChild = calcAllowedNumChild(form);
	form.child_id.value = numChild;
	//alert("numChild: "+numChild);
	if(numChild == "1") {			
		changeDisplay('child_id_div_1','visible','block');
		changeDisplay('child_id_div_2','hidden','none');
		form.first_name_2.value = '';
		form.gender_2[0].checked = false;
		form.gender_2[1].checked = false;
		form.birth_month_2.value = 255;
		form.birth_year_2.value = 255;
		
		changeDisplay('child_id_div_3','hidden','none');
		form.first_name_3.value = '';
		form.gender_3[0].checked = false;
		form.gender_3[1].checked = false;
		form.birth_month_3.value = 255;
		form.birth_year_3.value = 255;

		changeDisplay('child_id_div_4','hidden','none');
		form.first_name_4.value = '';
		form.gender_4[0].checked = false;
		form.gender_4[1].checked = false;
		form.birth_month_4.value = 255;
		form.birth_year_4.value = 255;

		changeDisplay('child_id_div_5','hidden','none');
		form.first_name_5.value = '';
		form.gender_5[0].checked = false;
		form.gender_5[1].checked = false;
		form.birth_month_5.value = 255;
		form.birth_year_5.value = 255;

		//changeDisplay('child_id_div_6','hidden','none');
		return true;
	}
	if(numChild == "2") {	
		changeDisplay('child_id_div_1','visible','block');
		changeDisplay('child_id_div_2','visible','block');
		changeDisplay('child_id_div_3','hidden','none');
		form.first_name_3.value = '';
		form.gender_3[0].checked = false;
		form.gender_3[1].checked = false;
		form.birth_month_3.value = 255;
		form.birth_year_3.value = 255;

		changeDisplay('child_id_div_4','hidden','none');
		form.first_name_4.value = '';
		form.gender_4[0].checked = false;
		form.gender_4[1].checked = false;
		form.birth_month_4.value = 255;
		form.birth_year_4.value = 255;

		changeDisplay('child_id_div_5','hidden','none');
		form.first_name_5.value = '';
		form.gender_5[0].checked = false;
		form.gender_5[1].checked = false;
		form.birth_month_5.value = 255;
		form.birth_year_5.value = 255;

		//changeDisplay('child_id_div_6','hidden','none');
		return true;
	}
	if(numChild == "3") {
		changeDisplay('child_id_div_1','visible','block');
		changeDisplay('child_id_div_2','visible','block');
		changeDisplay('child_id_div_3','visible','block');
		changeDisplay('child_id_div_4','hidden','none');
		form.first_name_4.value = '';
		form.gender_4[0].checked = false;
		form.gender_4[1].checked = false;
		form.birth_month_4.value = 255;
		form.birth_year_4.value = 255;

		changeDisplay('child_id_div_5','hidden','none');
		form.first_name_5.value = '';
		form.gender_5[0].checked = false;
		form.gender_5[1].checked = false;
		form.birth_month_5.value = 255;
		form.birth_year_5.value = 255;

		//changeDisplay('child_id_div_6','hidden','none');
		return true;
	}
	if(numChild == "4") {
		changeDisplay('child_id_div_1','visible','block');
		changeDisplay('child_id_div_2','visible','block');
		changeDisplay('child_id_div_3','visible','block');
		changeDisplay('child_id_div_4','visible','block');
		changeDisplay('child_id_div_5','hidden','none');
		form.first_name_5.value = '';
		form.gender_5[0].checked = false;
		form.gender_5[1].checked = false;
		form.birth_month_5.value = 255;
		form.birth_year_5.value = 255;

		//changeDisplay('child_id_div_6','hidden','none');
		return true;
	}
	if(numChild == "5") {
		changeDisplay('child_id_div_1','visible','block');
		changeDisplay('child_id_div_2','visible','block');
		changeDisplay('child_id_div_3','visible','block');
		changeDisplay('child_id_div_4','visible','block');
		changeDisplay('child_id_div_5','visible','block');
		//changeDisplay('child_id_div_6','hidden','none');
		return true;
	}
	else {
		changeDisplay('child_id_div_1','hidden','none');
		form.first_name_1.value = '';
		form.gender_1[0].checked = false;
		form.gender_1[1].checked = false;
		form.birth_month_1.value = 255;
		form.birth_year_1.value = 255;

		changeDisplay('child_id_div_2','hidden','none');
		form.first_name_2.value = '';
		form.gender_2[0].checked = false;
		form.gender_2[1].checked = false;
		form.birth_month_2.value = 255;
		form.birth_year_2.value = 255;
		
		changeDisplay('child_id_div_3','hidden','none');
		form.first_name_3.value = '';
		form.gender_3[0].checked = false;
		form.gender_3[1].checked = false;
		form.birth_month_3.value = 255;
		form.birth_year_3.value = 255;

		changeDisplay('child_id_div_4','hidden','none');
		form.first_name_4.value = '';
		form.gender_4[0].checked = false;
		form.gender_4[1].checked = false;
		form.birth_month_4.value = 255;
		form.birth_year_4.value = 255;

		changeDisplay('child_id_div_5','hidden','none');
		form.first_name_5.value = '';
		form.gender_5[0].checked = false;
		form.gender_5[1].checked = false;
		form.birth_month_5.value = 255;
		form.birth_year_5.value = 255;

		//changeDisplay('child_id_div_6','hidden','none');
		return true;					
    }
}	     	    
      
	
	

    function hideChildren()
    {
	     var maxChild=7;
         for (var i=1;  i < maxChild; i++){
	         var childDivBaseLbl="child_id_div_";
	         if(document.getElementById(childDivBaseLbl+i) != null)
	         {
	               //alert("hideChildren: hiding child: "+i);
                   document.getElementById(childDivBaseLbl+i).value="hide";
             }
            
         }
    }

       
       

	function isParent(form) 
	{
		var sParent = document.registerForm.presence_children_id[0].checked;
		//alert("isParent: value:"+sParent+":");
		if(sParent == true) 
        {
		    //alert("isParent: "+sParent);
            //flickChildSectionOnOff();
			changeDisplay('r2id3','visible','block');
			changeDisplay('child_take_survey_div','visible','block');
			showChildStats(form); //change number of children displayed
			return true;
		}
		else 
        {
        	changeDisplay('r2id3','hidden','none');
        	changeDisplay('child_id_div_1','hidden','none');
        	changeDisplay('child_id_div_2','hidden','none');
        	changeDisplay('child_id_div_3','hidden','none');
        	changeDisplay('child_id_div_4','hidden','none');
        	changeDisplay('child_id_div_5','hidden','none');
        	changeDisplay('child_id_div_6','hidden','none');
        	changeDisplay('child_take_survey_div','hidden','none');
            //alert("isParent :"+sParent+":- hiding children and child section");
          //  hideChildren();
			//flickChildSectionOnOff();
			//changeDisplay('child_take_survey_div','hidden','none');
                       // changeDisplay('r2id3','hidden','none');    
                        //resetRegForm(form);  
			//return true;
			
		}
		
		//return false;
    }
	


    function resetRegForm(form) 
    {
           
          var isParent = document.registerForm.presence_children_id[0].checked;
          //alert("resetRegForm()  isParent value:"+isParent+":");  
          
          if(isParent == false)
          {
            
            //preserve current form object values
            var maritalStatus = form.marital_status_id.options.selectedIndex; 
            var hhSize = document.registerForm.household_size_id.options.selectedIndex;
            var numChild = document.registerForm.child_id.options.selectedIndex;
            //alert("resetRegForm - maritalStatus : "+maritalStatus+" hhSize: "+hhSize+" numChild: "+numChild+" isParent"+isParent);
            //reload form
            window.location.reload();
            //alert("resetRegForm after reload - maritalStatus : "+maritalStatus+" hhSize: "+hhSize+" numChild: "+numChild+" isParent"+isParent);
            //reset form values
          
            document.registerForm.marital_status_id.options.selectedIndex=maritalStatus; 
            document.registerForm.household_size_id.options.selectedIndex=hhSize;
            document.registerForm.child_id.options.selectedIndex=numChild;
            document.registerForm.presence_children_id[0].checked=false;
            document.registerForm.presence_children_id[1].checked=true;
            reDisplayHHSections(form);
          }
             

    }


	
    function flickChildSectionOnOff()
    {
          changeDisplay('r2id3', 'visible','block');
          hideChildren();
          changeDisplay('r2id3', 'hidden', 'none');
    }


	
	function showHHSections(form)
	{
	   //alert('showHHSections household sections');	
	   //isParent(form);
	   showHHSize(form); 
	   showChildSection(form);
	   //testWriteMacros();
	}
	
	function showDivAfterValidationPageFour(form) {
		showHouseholdPageFour(form);
		showPersonalIncomePageFour(form);
		showMobileAddressPageFour(form);
//		showChiefRelatedSectionPageFour(form);
	}
	
	function showHouseholdPageFour(form) {
		var household = document.registerForm.household_income_id_1.value;
		
		if( household == "99" || household == "100"){
			changeDisplay('r2id4', 'visible','block');
		}else {
			changeDisplay('r2id4', 'hidden','none');
		}
	}
	
	function showPersonalIncomePageFour(form) {
		var personalincome = document.registerForm.personal_income_id_1.value;
	
		if( personalincome == "99" || personalincome == "100"){
			changeDisplay('r2id5', 'visible','block');
		}else {
			changeDisplay('r2id5', 'hidden','none');
		}
	}
	
	function showMobileAddressPageFour(form) {
		if(document.registerForm.flag_mobile_contact[0].checked || document.registerForm.flag_sms_alert[0].checked){
			changeDisplay('mpnmpc','visible','block');
	 	}
 		else
 		{
 			changeDisplay('mpnmpc','hidden','none');
 		}
	}
	
	function showChiefRelatedSectionPageFour(form) {
		var chief_employment_id = document.registerForm.chief_employment_id.value;
	
		if( chief_employment_id == "255"){
			changeDisplay('Chief_Describe_Activity', 'visible','block');
			changeDisplay('Chief_Industry_Section', 'visible','block');
			changeDisplay('Chief_Industry_Section', 'visible','block');			
			
		}
	}
	
	function showDivAfterValidation(form) {
		if (document.registerForm.chief_wage_earner[0].checked) {
		showOccOrUnemploymentDivAfterValidation(form); 
 		showOccIfUnemploymentisNoRecode(form);
		showIndustryDescribeActivityAfterValidation(form);
		} else if (document.registerForm.chief_wage_earner[1].checked) {
			changeDisplay('r2id6', 'visible','block');
			changeDisplay('r2id6_Emp', 'visible','block');
			changeDisplay('Education_Section','hidden','none');
			changeDisplay('Employment_Section','hidden','none');
		
		 var empid;
		  empid = document.registerForm.employment_id.options.value;
		  // This means that She is Employed but not chief earner so the above logic follows
		  
		  if (empid == "4" || empid == "5" || empid == "6" || empid == "7" || empid == "8" || empid == "9" || empid == "10" ) {
			changeDisplay('Chief_Employment_Section', 'visible','block');
 			showChiefOccOrUnemploymentDivAfterValidation(form); 
  			showChiefOccIfUnemploymentisNoRecode(form);
 			showChiefIndustryDescribeActivityAfterValidation(form);		  	
		  } else if (empid == "0" || empid == "1" || empid == "2" || empid == "3" || empid == "11"  || empid == "100" || empid == "101" ) {
			showOccOrUnemploymentDivAfterValidation(form); 
 			showOccIfUnemploymentisNoRecode(form);
			showIndustryDescribeActivityAfterValidation(form);		  			  
		  }
		
		}
	}
	
	function showOccIfUnemploymentisNoRecode(form) {
	  var val;
       if(document.registerForm.unemploy_id != null) {
		  val = document.registerForm.unemploy_id.options.value;
		 }
	   if (val == "NoRecode") {
	 		changeDisplay('Occupation_Section', 'visible','block');
 		} else if (val == "255"){
	 	  //	changeDisplay('Occupation_Section', 'hidden','none');
	 	} else {
		 	changeDisplay('Occupation_Section', 'hidden','none');
	//	 	document.registerForm.occupation_id.value = "255";
			document.registerForm.occupation_id[0].checked = true;
	 	}
	
	}
	
	function showOccOrUnemploymentDivAfterValidation(form) {
	  var val;
       if(document.registerForm.employment_id != null) {
		  val = document.registerForm.employment_id.options.value;
		 }
		if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) 
		{	
			changeDisplay('Unemployment_Section','visible','block');
		} else if (val == "0" || val == "1" || val == "2" || val == "3"  || val == "100" || val == "101" || val == "11"){
			changeDisplay('Occupation_Section','visible','block');			
		}
	}
	
	function showIndustryDescribeActivityAfterValidation(form) {
		var val;
		var occid;
		if(document.registerForm.occupation_id != null) {
		//	occid = document.registerForm.occupation_id.options.value;
			occid = getOccupationIdFromRadioButton(form);
			val   = (occid.substring(0,1));
		}
		if (val == "3" || val == "4" || val == "5") {
			changeDisplay('Describe_Activity', 'visible','block');
			changeDisplay('Industry_Section', 'visible','block');
		}
		 else if (occid == "255"){
			//changeDisplay('Describe_Activity', 'hidden','none');
			//changeDisplay('Industry_Section', 'hidden','none');		
		
		} else {
			changeDisplay('Describe_Activity', 'hidden','none');
			changeDisplay('Industry_Section', 'visible','block');		
		}	
	}
	
	////////////////////////////Loading After Validation if No Chief and Not Employed///////////////////////////////////////////////////
	function showChiefOccIfUnemploymentisNoRecode(form) {
	  var val;
       if(document.registerForm.chief_unemploy_id != null) {
		  val = document.registerForm.chief_unemploy_id.options.value;
		 }
	   if (val == "NoRecode") {
	 		changeDisplay('Chief_Occupation_Section', 'visible','block');
 		} else if (val == "255"){
	 	  //	changeDisplay('Occupation_Section', 'hidden','none');
	 	} else {
		 	changeDisplay('Chief_Occupation_Section', 'hidden','none');
		 //	document.registerForm.chief_occupation_id.value = "255";
			document.registerForm.chief_occupation_id[0].checked = true;
	 	}
	
	}
	
    function showChiefOccOrUnemploymentDivAfterValidation(form) {
	  var val;
       if(document.registerForm.chief_employment_id != null) {
		  val = document.registerForm.chief_employment_id.options.value;
		 }
		if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) 
		{	
			changeDisplay('Chief_Unemployment_Section','visible','block');
		} else if (val == "0" || val == "1" || val == "2" || val == "3" || val == "100" || val == "101" || val == "11"){
			changeDisplay('Chief_Occupation_Section','visible','block');			
		}
	}
	
	function showChiefIndustryDescribeActivityAfterValidation(form) {
		var val;
		var occid;
		if(document.registerForm.chief_occupation_id != null) {
//			occid = document.registerForm.chief_occupation_id.options.value;
			occid = getChiefOccupationIdFromRadioButton(form);
			val   = (occid.substring(0,1));
		}
		if (val == "3" || val == "4" || val == "5") {
			changeDisplay('Chief_Describe_Activity', 'visible','block');
			changeDisplay('Chief_Industry_Section', 'visible','block');
		}
		 else if (occid == "255"){
			//changeDisplay('Describe_Activity', 'hidden','none');
			  changeDisplay('Industry_Section', 'hidden','none');		
		
		} else {
			changeDisplay('Chief_Describe_Activity', 'hidden','none');
			changeDisplay('Chief_Industry_Section', 'visible','block');		
		}	
	}	
	///////////////////////////////////////////////////////////////////////////////
	
    function reDisplayHHSections(form)
    {
	   //alert('redisplaying household sections');	
	   //isParent(form);
	   showChildSection(form);
	   showHHSize(form); 
	   
	   //testWriteMacros();
	}
	
	
	function validateRegPageOne()
	{
	    var countryId=0;
	    if(document.registerForm.country_id != null)
		   countryId = document.registerForm.country_id.options.selectedIndex;
		
		//alert("validateCountry countryId: "+countryId);
		if(countryId == 255){
		     alert("Please select a country.");
		     return false; 
		}else
		  return true;
	}
	
	function showHispSection(form)
	{
	   var i=0;
	   if(document.registerForm.ethnicity_id.options != null)
		    i=document.registerForm.ethnicity_id.options.selectedIndex;
		if (i > 1){
			changeDisplay('hispbox','visible','block');
		}		
		else {

			changeDisplay('hispbox','hidden','none');
			return false;

		}
	}

	function popup (url) {
  		window.open(url, 'new', 'scrollbars=yes, width=420, height=375');
	}
	
	
	function checkAgreeTerms() {	
		if (!document.registerForm.rules.checked){
			alert('To complete your registration, please check the box and agree to the Website Terms and Conditions and Privacy Policy');
			return false;
			}
		else {
			return true;
		}
	}
	
	
	function openUsHispanic() 
	{
		window.location="http://us.lightspeedpanel.com/es/join/register";
	}
	
	
	function openFrca() 
	{
		window.location="http://ca.lightspeedpanel.com/fr/register/join.html";
	}

	function showNotStated(form)
	{
	  if(document.registerForm.household_income_id_1.options.selectedIndex == 14) {
		//alert('Hello' + document.registerForm.household_income_id.options.selectedIndex);
		changeDisplay('r2id4', 'visible','block');
		} 	
		else 
		{
		changeDisplay('r2id4','hidden','none');	
		}
	}

  	function showNotStatedPI(form)
	{
	  if(document.registerForm.personal_income_id_1.options.selectedIndex == 9 || document.registerForm.personal_income_id_1.options.selectedIndex == 10) {
		//alert('Hello' + document.registerForm.personal_income_id.options.selectedIndex);
		changeDisplay('r2id5', 'visible','block');
		} 	
		else 
		{
			changeDisplay('r2id5','hidden','none');	
		}
	}
    function ctsshow(form) {
    	document.registerForm.cts_id.value = "1";
    }
	function showNotChiefWageEarner(form)
	{
		
	  if(document.registerForm.chief_wage_earner[1].checked) {
		//alert('Hello' + document.registerForm.household_income_id.options.selectedIndex);
		changeDisplay('r2id6', 'visible','block');
		changeDisplay('r2id6_Emp', 'visible','block');
		changeDisplay('Education_Section','hidden','none');
		changeDisplay('Employment_Section','hidden','none');
		changeDisplay('Chief_Employment_Section', 'hidden','none');
		document.registerForm.education_id.value = "255" ;
		document.registerForm.employment_id.value = "255" ;
		document.registerForm.chief_employment_id.value = "255" ;					
		document.registerForm.chief_DescrActivity.value = "";
		document.registerForm.DescrActivity.value = "";
		showNotUnemployment(form);
		showNotDescActivity(form);
		showNotOccupation(form);
		showNotIndustry(form);
				
		} 	
		else 
		{
			changeDisplay('r2id6','hidden','none');	
			changeDisplay('r2id6_Emp','hidden','none');	
			changeDisplay('Education_Section','visible','block');
			changeDisplay('Employment_Section','visible','block');
			changeDisplay('Chief_Employment_Section', 'hidden','none');
			document.registerForm.education_id.value = "255" ;
			document.registerForm.employment_id.value = "255" ;
			document.registerForm.chief_employment_id.value = "255" ;
			document.registerForm.chief_DescrActivity.value = "";
			document.registerForm.DescrActivity.value = "";			
			showNotUnemployment(form);
			showNotDescActivity(form);
			showNotOccupation(form);
			showNotIndustry(form);

		}
		// Reset to original value
		// document.registerForm.employment_id.value = "255";
		// document.registerForm.education_id.value = "255";
	}
	
	function showNotUnemployment(form) {
		changeDisplay('Unemployment_Section','hidden','none');	
		changeDisplay('Chief_Unemployment_Section','hidden','none');
		document.registerForm.unemploy_id.value = "255" ;
		document.registerForm.chief_unemploy_id.value = "255" ;
	}
	function showNotDescActivity(form) {
		changeDisplay('Describe_Activity','hidden','none');	
		changeDisplay('Chief_Describe_Activity','hidden','none');	
	}
	function showNotOccupation(form) {
		changeDisplay('Occupation_Section','hidden','none');
		changeDisplay('Chief_Occupation_Section','hidden','none');	
	//	document.registerForm.occupation_id.value = "255" ;
		document.registerForm.occupation_id[0].checked = true;
	//	document.registerForm.chief_occupation_id.value = "255" ;	
		document.registerForm.chief_occupation_id[0].checked = true;	
	}
	function showNotIndustry(form) {
		changeDisplay('Industry_Section','hidden','none');	
		changeDisplay('Chief_Industry_Section','hidden','none');	
		document.registerForm.industry_id.value = "255" ;
		document.registerForm.chief_industry_id.value = "255" ;
		document.registerForm.chief_DescrActivity.value = "";
		document.registerForm.DescrActivity.value = "";		
	}
	function showNotChiefEmploymentSection(form) {
		changeDisplay('Chief_Employment_Section','hidden','none');	
		document.registerForm.chief_employment_id.value = "255" ;
	}
				
  function showFrenchIsEmployed(form,input) {
	var val;
	if(input == "yes") {
	 val = document.registerForm.employment_id.value;
	} else {
	val = document.registerForm.chief_employment_id.value;
	}
	// Check if the Person is the Chief Income Earner of the Family, if yes it goes to the first block or else second
	if (document.registerForm.chief_wage_earner[0].checked == true){
	 if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) {
		 changeDisplay('Unemployment_Section', 'visible','block');
		 changeDisplay('Occupation_Section', 'hidden','none');
		 changeDisplay('Describe_Activity', 'hidden','none');
		 changeDisplay('Industry_Section', 'hidden','none');
	//	 document.registerForm.occupation_id.value = "255";
		 document.registerForm.occupation_id[0].checked = true;
		 document.registerForm.industry_id.value = "255";
		 document.registerForm.chief_DescrActivity.value = "";
		 document.registerForm.DescrActivity.value = "";
		 
	  }
	  else {
		changeDisplay('Occupation_Section', 'visible','block');
 		changeDisplay('Unemployment_Section', 'hidden','none');
 		document.registerForm.unemploy_id.value = "255";
	  }
	} else {
	 if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) {
		 // Do Something Else ...
		 changeDisplay('Chief_Employment_Section', 'visible','block');
		 changeDisplay('Occupation_Section', 'hidden','none');
		 changeDisplay('Describe_Activity', 'hidden','none');
		 changeDisplay('Industry_Section', 'hidden','none');
		 changeDisplay('Chief_Occupation_Section', 'hidden','none');
		 changeDisplay('Chief_Describe_Activity', 'hidden','none');
		 changeDisplay('Chief_Industry_Section', 'hidden','none');
//		 document.registerForm.occupation_id.value = "255";
		 document.registerForm.occupation_id[0].checked = true;	 
		 document.registerForm.industry_id.value = "255";
   		 document.registerForm.chief_DescrActivity.value = "";
	 	 document.registerForm.DescrActivity.value = "";
		 
	  }	 
	  else {
		changeDisplay('Occupation_Section', 'visible','block');
 		changeDisplay('Unemployment_Section', 'hidden','none');
 		changeDisplay('Chief_Employment_Section', 'hidden','none');
 		
 		document.registerForm.unemploy_id.value = "255";
 		document.registerForm.chief_employment_id.value = "255" ;
	  }	
	}
	 if(val == "255") {
	 	// This will Change the prior selected value to 'Please Select' and others to default
	 	// document.registerForm.occupation_id.value = "255";
		document.registerForm.occupation_id[0].checked = true;	 	
	 	document.registerForm.industry_id.value = "255";
	 	document.registerForm.DescrActivity.value = "";
	 	document.registerForm.chief_DescrActivity.value = "";
		//	 	document.registerForm.chief_occupation_id.value = "255";
		document.registerForm.chief_occupation_id[0].checked = true;
	 	document.registerForm.chief_industry_id.value = "255";
	 	document.registerForm.chief_DescrActivity.value = "";	 	
	   	changeDisplay('Occupation_Section', 'hidden','none');
	   	changeDisplay('Industry_Section', 'hidden','none');
	  	changeDisplay('Describe_Activity', 'hidden','none');
	  	changeDisplay('Chief_Employment_Section', 'hidden','none');	
	  	changeDisplay('Chief_Occupation_Section', 'hidden','none');
	  	changeDisplay('Chief_Industry_Section', 'hidden','none');
		changeDisplay('Chief_Describe_Activity', 'hidden','none');	  	
		changeDisplay('Chief_Unemployment_Section', 'hidden','none');	  	
	 }  
	}

  function showFrenchChiefIsEmployed(form,input) {
	var val;
	if(input == "yes") {
	 val = document.registerForm.employment_id.value;
	} else {
	val = document.registerForm.chief_employment_id.value;
	}
	
	// Check if the Person is the Chief Income Earner of the Family, if yes it goes to the first block or else second
	if (document.registerForm.chief_wage_earner[1].checked == true){
	 if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) {
		 changeDisplay('Chief_Unemployment_Section', 'visible','block');
		 changeDisplay('Chief_Occupation_Section', 'hidden','none');
		 changeDisplay('Chief_Describe_Activity', 'hidden','none');
		 changeDisplay('Chief_Industry_Section', 'hidden','none');
		// document.registerForm.chief_occupation_id.value = "255";
  		 document.registerForm.chief_occupation_id[0].checked = true;
		 document.registerForm.chief_industry_id.value = "255";
		 document.registerForm.chief_DescrActivity.value = "";
		 document.registerForm.DescrActivity.value = "";
		 
	  }
	  else {
		changeDisplay('Chief_Occupation_Section', 'visible','block');
 		changeDisplay('Chief_Unemployment_Section', 'hidden','none');
 		changeDisplay('Chief_Describe_Activity', 'hidden','none');
 		changeDisplay('Chief_Industry_Section', 'hidden','none');
 		document.registerForm.chief_unemploy_id.value = "255";
 		
	  }
	} else {
	 if(val == "4" || val == "5" || val == "6" || val == "7" || val == "8" || val == "9" || val == "10" ) {
		 // Do Something Else ...
		 //changeDisplay('Chief_Employment_Section', 'visible','block');
		 changeDisplay('Chief_Occupation_Section', 'hidden','none');
		// document.registerForm.chief_occupation_id.value = "255";
 		document.registerForm.chief_occupation_id[0].checked = true;
	  }	 
	  else {
		changeDisplay('Chief_Occupation_Section', 'visible','block');
 		changeDisplay('Chief_Unemployment_Section', 'hidden','none');
 		changeDisplay('Chief_Industry_Section', 'hidden','none');
 		changeDisplay('Chief_Describe_Activity', 'hidden','none');
 		document.registerForm.chief_unemploy_id.value = "255";
 		//changeDisplay('Chief_Employment_Section', 'hidden','none');
	  }	
	}
	 if(val == "255") {
	   	changeDisplay('Chief_Occupation_Section', 'hidden','none');
	   	changeDisplay('Chief_Industry_Section', 'hidden','none');
	  	changeDisplay('Chief_Describe_Activity', 'hidden','none');
	  	changeDisplay('Chief_Unemployment_Section', 'hidden','none');
	//	document.registerForm.chief_occupation_id.value = "255";
		document.registerForm.chief_occupation_id[0].checked = true;
		document.registerForm.chief_industry_id.value = "255";
		document.registerForm.chief_DescrActivity.value = "";	  	
		document.registerForm.chief_unemploy_id.value = "255";
		document.registerForm.DescrActivity.value = "";	  	
	 }  
	}
	
	function showFrenchOccupation() {
		var uid = document.registerForm.unemploy_id.value;
	 		changeDisplay('Industry_Section', 'hidden','none');
	 		changeDisplay('Describe_Activity', 'hidden','none');
	 		
	 		document.registerForm.industry_id.value = "255";
	 				
		if (uid == "NoRecode") {
	 		changeDisplay('Occupation_Section', 'visible','block');
 		} else {
	 		changeDisplay('Occupation_Section', 'hidden','none');
			// document.registerForm.occupation_id.value = "255";
			document.registerForm.occupation_id[0].checked = true;
 		}
 		if(uid == "255") {
			//document.registerForm.occupation_id.value = "255";
	  		document.registerForm.occupation_id[0].checked = true;
	  		document.registerForm.industry_id.value = "255";
	 		document.registerForm.DescrActivity.value = ""; 
	 		document.registerForm.chief_DescrActivity.value = "";
	 		changeDisplay('Occupation_Section', 'hidden','none');
	 		changeDisplay('Industry_Section', 'hidden','none');
	 		changeDisplay('Describe_Activity', 'hidden','none');	 		
 		}
	}

	function showChiefFrenchOccupation() {
		var uid = document.registerForm.chief_unemploy_id.value;
	 		changeDisplay('Chief_Industry_Section', 'hidden','none');
	 		changeDisplay('Chief_Describe_Activity', 'hidden','none');
	 		//document.registerForm.chief_occupation_id.value = "255";
	 		document.registerForm.chief_occupation_id[0].checked = true;		
		if (uid == "NoRecode") {
	 		changeDisplay('Chief_Occupation_Section', 'visible','block');
 		} else {
	 		changeDisplay('Chief_Occupation_Section', 'hidden','none');
	 		

 		}
 		if(uid == "255") {
	  	//	document.registerForm.chief_occupation_id.value = "255";
	  		document.registerForm.chief_occupation_id[0].checked = true;
	  		document.registerForm.chief_industry_id.value = "255";
	  		document.registerForm.chief_DescrActivity.value = "";
			document.registerForm.DescrActivity.value = ""; 		
	 		changeDisplay('Chief_Occupation_Section', 'hidden','none');
	 		changeDisplay('Chief_Industry_Section', 'hidden','none');
	 		changeDisplay('Chief_Describe_Activity', 'hidden','none');	 		
 		}
	}

	
	function showDescrActivity(form) {
//		var occid = document.registerForm.occupation_id.value;
		var occid = getOccupationIdFromRadioButton(form);
		var res = (occid.substring(0,1));
		
		if (res == "3" || res == "4" || res == "5") {
			changeDisplay('Describe_Activity', 'visible','block');
			changeDisplay('Industry_Section', 'visible','block');
		} else {
			changeDisplay('Describe_Activity', 'hidden','none');
			changeDisplay('Industry_Section', 'visible','block');
			
		}	
		if(occid == "255"){
	  		document.registerForm.industry_id.value = "255";
	  		document.registerForm.DescrActivity.value = "";
	  		document.registerForm.chief_DescrActivity.value = "";
			changeDisplay('Describe_Activity', 'hidden','none');
			changeDisplay('Industry_Section', 'hidden','none');
		}
	}

	function showDescrActivityTest(form) {
	var i;
	var occid;
	
	 for(i=0;i < document.registerForm.occupation_id.length; i++) {
      if(document.registerForm.occupation_id[i].checked == true) {
		occid = document.registerForm.occupation_id[i].value ;
  	   }      
 	 }
		var res = (occid.substring(0,1));
		
		if (res == "3" || res == "4" || res == "5") {
			changeDisplay('Describe_Activity', 'visible','block');
			changeDisplay('Industry_Section', 'visible','block');
		} else {
			changeDisplay('Describe_Activity', 'hidden','none');
			changeDisplay('Industry_Section', 'visible','block');
			
		}	
		if(occid == "255"){
	  		document.registerForm.industry_id.value = "255";
	  		document.registerForm.DescrActivity.value = "";
	  		document.registerForm.chief_DescrActivity.value = "";
			changeDisplay('Describe_Activity', 'hidden','none');
			changeDisplay('Industry_Section', 'hidden','none');
		}
	}
	
	function showChiefDescrActivity(form) {
	//	var occid = document.registerForm.chief_occupation_id.value;
		var occid = getChiefOccupationIdFromRadioButton(form);
		var res = (occid.substring(0,1));
		document.registerForm.chief_DescrActivity.value = "";
		if (res == "3" || res == "4" || res == "5") {
			changeDisplay('Chief_Describe_Activity', 'visible','block');
			changeDisplay('Chief_Industry_Section', 'visible','block');
		} else {
			changeDisplay('Chief_Describe_Activity', 'hidden','none');
			changeDisplay('Chief_Industry_Section', 'visible','block');
			
		}	
		if(occid == "255"){
	  		document.registerForm.chief_industry_id.value = "255";
	  		document.registerForm.chief_DescrActivity.value = "";
			document.registerForm.DescrActivity.value = ""; 		
			changeDisplay('Chief_Describe_Activity', 'hidden','none');
			changeDisplay('Chief_Industry_Section', 'hidden','none');
		}
	}

  function getOccupationIdFromRadioButton(form){
	var i;
 	var retVal;
 	var b = 999;
  	 for(i=0;i<document.registerForm.occupation_id.length;i++) {
      if(document.registerForm.occupation_id[i].checked == true) {
		b= document.registerForm.occupation_id[i].value;
		retVal = document.registerForm.occupation_id[i].value;
     }      
  	}
   	if(b == 999) {
		document.registerForm.occupation_id[0].checked = true;
		retVal = document.registerForm.occupation_id[0].value;
 	}
 	return retVal ;   
   }

  function getChiefOccupationIdFromRadioButton(form){
	var i;
 	var retVal;
 	var b = 999;
  	 for(i=0;i< document.registerForm.chief_occupation_id.length;i++) {
      if(document.registerForm.chief_occupation_id[i].checked == true) {
		b= document.registerForm.chief_occupation_id[i].value;
		retVal = document.registerForm.chief_occupation_id[i].value;
     }      
  	}
   	if(b == 999) {
		document.registerForm.chief_occupation_id[0].checked = true;
		retVal = document.registerForm.chief_occupation_id[0].value;
 	}
 	return retVal ;   
   }

   		 
	function isChildrenYes(form) 
	{
		var sChildren = document.registerForm.presence_children_id[0].checked;
		//alert("isParent: value:"+sParent+":");
		if(sChildren == true) 
        {
		    //alert("isParent: "+sParent);
            //flickChildSectionOnOff();
			changeDisplay('r2id2','visible','block');
			//alert(document.registerForm.child_0005.options.selectedIndex);
			//document.registerForm.child_0005.options.selectedIndex=0;
			//changeDisplay('r2id3','visible','none');
			//changeDisplay('child_take_survey_div','visible','block');
			//showChildStats(); //change number of children displayed
			return true;
		}
		else 
        {
        	changeDisplay('r2id2','hidden','none');
			changeDisplay('r2id3','hidden','none');
        	document.registerForm.presence_children_id[0].checked = false;
			document.registerForm.child_0005.options.selectedIndex = 0;
			document.registerForm.child_0609.options.selectedIndex = 0;
			document.registerForm.child_1012.options.selectedIndex = 0;
			document.registerForm.child_1317.options.selectedIndex = 0;
        	//changeDisplay('child_take_survey_div','hidden','none');
            //alert("isParent :"+sParent+":- hiding children and child section");
          //  hideChildren();
			//flickChildSectionOnOff();
			//changeDisplay('child_take_survey_div','hidden','none');
                       // changeDisplay('r2id3','hidden','none');    
                        //resetRegForm(form);  
			//return true;
			
		}
		
		return false;
    }
	function numberChildren1(form)
	{
        //var i=0;
        if(	document.registerForm.child_0005 != null)
		     i1 = document.registerForm.child_0005.options.selectedIndex;
		 if(document.registerForm.child_0609 != null)
		     i2 = document.registerForm.child_0609.options.selectedIndex;
		 if(document.registerForm.child_1012 != null)
		     i3= document.registerForm.child_1012.options.selectedIndex;
		  if(document.registerForm.child_1317 != null)
		     i4 = document.registerForm.child_1317.options.selectedIndex;
		hhSize = document.registerForm.household_size_id.options.selectedIndex;
		i = i1 + i2 + i3 + i4;
		if (i >= hhSize) {
			i = hhSize - (1 +  i2 + i3 + i4 );
			document.registerForm.child_0005.options.selectedIndex = i;
		}
		showChildDetails(form)
  }
function numberChildren2(form)
	{
        //var i=0;
        if(	document.registerForm.child_0005 != null)
		     i1 = document.registerForm.child_0005.options.selectedIndex;
		 if(document.registerForm.child_0609 != null)
		     i2 = document.registerForm.child_0609.options.selectedIndex;
		 if(document.registerForm.child_1012 != null)
		     i3= document.registerForm.child_1012.options.selectedIndex;
		  if(document.registerForm.child_1317 != null)
		     i4 = document.registerForm.child_1317.options.selectedIndex;
		hhSize = document.registerForm.household_size_id.options.selectedIndex;
		i = i1 + i2 + i3 + i4;
		if (i >= hhSize) {
			i = hhSize - (1 +  i1 + i3 + i4);
			document.registerForm.child_0609.options.selectedIndex = i;
		}
		showChildDetails(form)
    }

	function numberChildren3(form)
	{
        //var i=0;
        if(	document.registerForm.child_0005 != null)
		     i1 = document.registerForm.child_0005.options.selectedIndex;
		 if(document.registerForm.child_0609 != null)
		     i2 = document.registerForm.child_0609.options.selectedIndex;
		 if(document.registerForm.child_1012 != null)
		     i3= document.registerForm.child_1012.options.selectedIndex;
		  if(document.registerForm.child_1317 != null)
		     i4 = document.registerForm.child_1317.options.selectedIndex;
		hhSize = document.registerForm.household_size_id.options.selectedIndex;
		i = i1 + i2 + i3 + i4;
		if (i >= hhSize) {
			i = hhSize - (1 +  i2 + i1 + i4);
			document.registerForm.child_1012.options.selectedIndex = i;
		}
		showChildDetails(form)
	 }

	function numberChildren4(form)
	{
        //var i=0;
        if(	document.registerForm.child_0005 != null)
		     i1 = document.registerForm.child_0005.options.selectedIndex;
		 if(document.registerForm.child_0609 != null)
		     i2 = document.registerForm.child_0609.options.selectedIndex;
		 if(document.registerForm.child_1012 != null)
		     i3= document.registerForm.child_1012.options.selectedIndex;
		  if(document.registerForm.child_1317 != null)
		     i4 = document.registerForm.child_1317.options.selectedIndex;
		hhSize = document.registerForm.household_size_id.options.selectedIndex;
		i = i1 + i2 + i3 + i4;
		if (i >= hhSize) {
			i = hhSize - (1 +  i2 + i3 + i1);
			document.registerForm.child_1317.options.selectedIndex = i;	
		}
		showChildDetails(form)
    }
    
    function showChildSections(form)
	{
	   //alert('showHHSections household sections');	
	   //isParent(form);
	   showHHSize();
	   isChildrenYes(form) ;
	   //showChildDetails(form); 
	   if ( document.registerForm.presence_children_id[0].checked == true )
	   {
		   numberChildren1(form);
		   numberChildren2(form);
		   numberChildren3(form);
		   numberChildren4(form);
	   }
	   
	   //showChildDetails(form);
	   //changeDisplay('r2id3','visible','block');
	   //testWriteMacros();
	}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function showChildDetails(form)
	{
		//alert(s);
	   //var numChild = calcAllowedNumChild();
	 
	    var s =   document.registerForm.child_id.options.selectedIndex ;
	  //  var i = 1;
	   // var h = document.registerForm.household_size_id.options.selectedIndex;
	   // if (s >= h) 
	   // 	s = h - i;	
	    var numChild = s;
	    	 
			if(numChild == "1") {
				changeDisplay('r2id3','visible','block');
				changeDisplay('child_id_div_1','visible','block');
				changeDisplay('child_id_div_2','hidden','none');
				changeDisplay('child_id_div_3','hidden','none');
				changeDisplay('child_id_div_4','hidden','none');
				changeDisplay('child_id_div_5','hidden','none');
				return true;
			}
			 if(numChild == "2") {
				changeDisplay('r2id3','visible','block');
				changeDisplay('child_id_div_1','visible','block');
				changeDisplay('child_id_div_2','visible','block');
				changeDisplay('child_id_div_3','hidden','none');
				changeDisplay('child_id_div_4','hidden','none');
				changeDisplay('child_id_div_5','hidden','none');
				return true;
			}
			if(numChild == "3") {
				changeDisplay('r2id3','visible','block');
				changeDisplay('child_id_div_1','visible','block');
				changeDisplay('child_id_div_2','visible','block');
				changeDisplay('child_id_div_3','visible','block');
				changeDisplay('child_id_div_4','hidden','none');
				changeDisplay('child_id_div_5','hidden','none');
				return true;
			}
			if(numChild == "4") {
				changeDisplay('r2id3','visible','block');
				changeDisplay('child_id_div_1','visible','block');
				changeDisplay('child_id_div_2','visible','block');
				changeDisplay('child_id_div_3','visible','block');
				changeDisplay('child_id_div_4','visible','block');
				changeDisplay('child_id_div_5','hidden','none');
				return true;
			}
			if(numChild == "5" || numChild == "6") {
				changeDisplay('r2id3','visible','block');
				changeDisplay('child_id_div_1','visible','block');
				changeDisplay('child_id_div_2','visible','block');
				changeDisplay('child_id_div_3','visible','block');
				changeDisplay('child_id_div_4','visible','block');
				changeDisplay('child_id_div_5','visible','block');
				return true;
			}
		
  		     else
	           {
				changeDisplay('r2id3','hidden','none');
				changeDisplay('child_id_div_1','hidden','none');
				changeDisplay('child_id_div_2','hidden','none');
				changeDisplay('child_id_div_3','hidden','none');
				changeDisplay('child_id_div_4','hidden','none');
				changeDisplay('child_id_div_5','hidden','none');
				return true;					
	           }
	 }	     	    
      
//Mobile questions scripts added.

function showMobile(form) {
	 
 	if(document.registerForm.flag_mobile_contact[0].checked || document.registerForm.flag_sms_alert[0].checked)
 	{
 			changeDisplay('mpnmpc','visible','block');
 	}
 	else
 	{
 		changeDisplay('mpnmpc','hidden','none');
		document.registerForm.mobile_address.value = '';
 	}
}
function showUpdateMobile(form) {
	 
 	if(document.updateProfileForm.flag_mobile_contact[0].checked || document.updateProfileForm.flag_sms_alert[0].checked)
 	{
 			changeDisplay('mob_text','visible','block');
 	}
 	else
 	{
 		changeDisplay('mob_text','hidden','none');
		document.updateProfileForm.mobile_address.value = '';
 	}
}

 	function keyRestrictPhone1(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
		 //alert(document.registerForm.postal_code.value.length);
	  if (document.registerForm.phone1.value.length==4)
				document.registerForm.phone2.focus();
	  if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}
	function keyRestrictPhone2(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
	  if (document.registerForm.phone2.value.length==3)
				document.registerForm.phone3.focus();
	 if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}
	function keyRestrictMobile(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
	  if (document.registerForm.mobile_address1.value.length==3)
				document.registerForm.mobile_address2.focus();
	 if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}
	function keyRestrictPhone3(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
	 if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}

	function keyRestrictPostcode(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
	 if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}
  function keyRestrictMobileFrench(e, validchars,currval) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase();
		 validchars = validchars.toLowerCase();
  		if(currval.length == 0 && keychar == 0) {
		return true;
          } else if (currval.length == 0 && keychar != 0) {
		return false;
		 }

		if(currval.length == 1 && keychar == 6) {
		return true;
          } else if (currval.length == 1 && keychar != 6) {
		return false;
		 }		 
	 if (validchars.indexOf(keychar) != -1)
		  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		 return true;
	 return false;
	}
	
	function keyRestrictEmailAddress(e, validchars) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) 
			return true;
		 keychar = String.fromCharCode(key);
		 keychar = keychar.toLowerCase(); 
		 validchars = validchars.toLowerCase();
		if(key == 34)
			return false ;	
	 	if (validchars.indexOf(keychar) != -1)
		 	return false;	
	
	}
	
	
	function showOther(form)
	{
		//alert('Hello' + document.registerForm.mobile_company_id.options.selectedIndex);
	  if(document.registerForm.mobile_company_id.options.selectedIndex == 7) {
		//alert('Hello' + document.registerForm.mobile_company_id.options.selectedIndex);
		changeDisplay('mobileother', 'visible','block');
		} 	
		else 
		{
			changeDisplay('mobileother','hidden','none');	

		}
	}

	 function getKeyCode(e)
		{
		 if (window.event)
			return window.event.keyCode;
		 else if (e)
			return e.which;
		 else
			return null;
		}

	function showWorkFulltime(form)
	{
	  if(document.registerForm.employment_id.options.selectedIndex == 0 || document.registerForm.employment_id.options.selectedIndex == 1 || document.registerForm.employment_id.options.selectedIndex == 4) {
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('fulltimework', 'hidden','none');
		} 	
		else 
		{
			changeDisplay('fulltimework','visible','block');	
		}
	}

	function cieOccupation(form)
	{
	  if(document.registerForm.chief_occupation_id.options.selectedIndex == 1)
		{
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('cieself', 'visible','block');
		} 	
		else 
		{
			changeDisplay('cieself','hidden','none');	
		}
		if(document.registerForm.chief_occupation_id.options.selectedIndex == 8)
		{
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('ciearmed', 'visible','block');
		} 	
		else 
		{
			changeDisplay('ciearmed','hidden','none');	
		}
		if(document.registerForm.chief_occupation_id.options.selectedIndex == 14)
		{
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('cieowner', 'visible','block');
		} 	
		else 
		{
			changeDisplay('cieowner','hidden','none');	
		}
		if(document.registerForm.chief_occupation_id.options.selectedIndex == 16)
		{
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('cieengineer', 'visible','block');
		} 	
		else 
		{
			changeDisplay('cieengineer','hidden','none');	
		}
		if(document.registerForm.chief_occupation_id.options.selectedIndex == 18)
		{
		//alert('Hello' + document.registerForm.employment_id.options.selectedIndex);
		changeDisplay('ciehosp', 'visible','block');
		} 	
		else 
		{
			changeDisplay('ciehosp','hidden','none');	
		}
	}
	
	function showNoActivity(form) {
		if(document.registerForm.chief_wage_earner.value == 0) {
			changeDisplay('noactivity-chief-no','visible','block');
			changeDisplay('noactivity-chief-yes','hidden','none');
			changeDisplay('r2id12','visible','block');
			
		}
		else {
			changeDisplay('noactivity-chief-no','hidden','none');
			changeDisplay('noactivity-chief-yes','visible','block');
			changeDisplay('r2id11','visible','block');
			
		}		
	}
	
	function showCandidateDetail(form) {
			changeDisplay('showDetails','visible','block');
			changeDisplay('showDetailsHideButton','visible','block');
			changeDisplay('showDetailsButton','hidden','none');
	}
	
	function showCandidateHideDetail(form) {
			changeDisplay('showDetails','hidden','none');
			changeDisplay('showDetailsHideButton','hidden','none');
			changeDisplay('showDetailsButton','visible','block');
	}
	
	 function calcAllowedChildID()
    {
    
         if(document.getElementById("household_size_id") != null)  
	            hhSize = document.registerForm.household_size_id.options.selectedIndex;
		 if(document.getElementById("child_id") != null)  
	            numChild = document.registerForm.child_id.options.selectedIndex;
	     if(hhSize == 255)
				hhSize=0;
	    if(numChild >= hhSize)
	             numChild = hhSize -1;
		if(numChild < 0)
	       numChild=0;
       document.registerForm.child_id.options.selectedIndex = numChild ;
    }	
    