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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function showSections(){
     var regPage1 = document.getElementById('usRegPage1');
     var regPage2 = document.getElementById('usRegPage2');
     var regPage3 = document.getElementById('usRegPage3');
     //var coRegPage = document.getElementById('usCoRegPage');
     var coRegPage = document.getElementById('updateProfileForm');
     
     if(regPage1 != null){
       showMobile(document.registerForm);
     }
     else if(regPage2 != null){
       showHHSections(document.registerForm);
     }
     else if(regPage3 != null){
       showNotChiefWageEarner(document.registerForm);
       showNotStatedPI(document.registerForm);
       showNotStated(document.registerForm);
       showWorkFulltime(document.registerForm);
     }
     else if(coRegPage != null){
     	showUpdateMobile(document.updateProfileForm); 
     }
    else { }
}


	
	
	
	 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 ;
    }


	
	

    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(); //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 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 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 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 showUpdateMobile(form) {
	 
 	if(document.updateProfileForm.mobile_contact[0].checked || document.updateProfileForm.flag_sms_alert[0].checked)
 	{
 			changeDisplay('mob_text','visible','block');
 	}
 	else
 	{
 		changeDisplay('mob_text','hidden','none');

 	}
	}

 	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 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 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 validatePostalCode() {
		if (document.registerForm.postal_code1.value=="") {
			alert('Please enter postal code.');
			document.registerForm.postal_code1.focus();
			return false;
		}
		else if (document.registerForm.postal_code2.value=="") {
			alert('Please enter postal code.');
			document.registerForm.postal_code2.focus();
			return false;
		}
		else {
	  		document.registerForm.submit();
		}
}

//used by multi-language registration
function showChiefOccupation(form) {
	if (form.chief_employment_id.value==5) {
		form.chief_occupation_id_1.value = 15;
		changeDisplay('chiefocc', 'hidden','none');
	}
	else if (form.chief_employment_id.value==6) {
		form.chief_occupation_id_1.value = 15;
		changeDisplay('chiefocc', 'hidden','none');
	}
	else if (form.chief_employment_id.value==7) {
		form.chief_occupation_id_1.value = 16;
		changeDisplay('chiefocc', 'hidden','none');
	}
	else if (form.chief_employment_id.value==8) {
		form.chief_occupation_id_1.value = 18;
		changeDisplay('chiefocc', 'hidden','none');
	}
	else if (form.chief_employment_id.value==255) {
		form.chief_occupation_id_1.value = 255;
		changeDisplay('chiefocc', 'hidden','none');
	}
	else {
		if(form.chief_occupation_id_1.value.length == 0) {
			form.chief_occupation_id_1.value = 255;
		}
		changeDisplay('chiefocc', 'visible','block');
	}
}

function showOccupation(form) {
	//alert("employment: "+form.employment_id.value);
	if (form.employment_id.value==5) {
		//since 15,16 are not displayed in dropdown list, this assignment zeros out the field
		form.occupation_id_1.value = 15;
		changeDisplay('occ', 'hidden','none');
	}
	else if (form.employment_id.value==6) {
		form.occupation_id_1.value = 15;
		changeDisplay('occ', 'hidden','none');
	}
	else if (form.employment_id.value==7) {
		form.occupation_id_1.value = 16;
		changeDisplay('occ', 'hidden','none');
	}
	else if (form.employment_id.value==8) {
		form.occupation_id_1.value = 18;
		changeDisplay('occ', 'hidden','none');
	}
	else if (form.employment_id.value==255) {
		form.occupation_id_1.value = 255;
		changeDisplay('occ', 'hidden','none');
	}
	else {	
		if (form.occupation_id_1.value.length == 0) {
			form.occupation_id_1.value = 255;
		}
		changeDisplay('occ', 'visible','block');	
	}
	showIndustry(form);
}

function showIndustry(form) {
	//alert("occupation: "+form.occupation_id_1.value);
	//alert("occupation length: "+form.occupation_id_1.value.length);
	if (form.occupation_id_1.value.length > 0 && form.occupation_id_1.value!=15 && form.occupation_id_1.value!=16 && form.occupation_id_1.value!=17 && form.occupation_id_1.value!=255) {
		changeDisplay('ind', 'visible','block');
	}
	else {
		form.industry_id.value = 255;
		changeDisplay('ind', 'hidden','none');
	}
}

function showNotStated(form) {
	if (form.household_income_id_1.value == 99 || form.household_income_id_1.value == 100) {
  		changeDisplay('r2id4', 'visible','block');
	} 	
	else {
		changeDisplay('r2id4','hidden','none');	
	}
}

function showNotStatedPI(form) {
	if(form.personal_income_id_1.value == 99 || form.personal_income_id_1.value == 100) {
		changeDisplay('r2id5', 'visible','block');
	} 	
	else {
		changeDisplay('r2id5','hidden','none');	
	}
}

function keyRestrictMobile(form, e, validchars) {
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) 
		return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
  	if (form.mobile_address.value.length==0 && keychar!="0")
		return false;
  	if (form.mobile_address.value.length==1 && keychar!="4")
		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 validateHouseholdAndOccupation(form) {
	//alert('form.household_income_id_1.value: '+form.household_income_id_1.value);
	if (form.household_income_id_1.value == 99 || form.household_income_id_1.value == 100) {
			form.household_income_id.value = form.household_income_id_2.value;
	}
	else {
			form.household_income_id.value = form.household_income_id_1.value;
	}
	//alert('household_income_id: '+form.household_income_id.value);	
	
	//alert('form.personal_income_id_1.value: '+form.household_income_id_1.value);
	
	if (form.personal_income_id_1.value == 99 || form.personal_income_id_1.value == 100) {
		form.personal_income_id.value = form.personal_income_id_2.value;
	}
	else {
		form.personal_income_id.value = form.personal_income_id_1.value;
	}
	//alert('personal_income_id: '+form.personal_income_id.value);
	
	if (form.employment_id.value==5) {
		form.occupation_id.value = 15;
	}
	else if (form.employment_id.value==6) {
		form.occupation_id.value = 15;
	}
	else if (form.employment_id.value==7) {
		form.occupation_id.value = 16;
	}
	else {
		form.occupation_id.value = form.occupation_id_1.value
	}
	//alert('occupation_id: '+form.occupation_id.value);
	
	if (form.chief_employment_id.value==5) {
		form.chief_occupation_id.value = 15;
	}
	else if (form.chief_employment_id.value==6) {
		form.chief_occupation_id.value = 15;
	}
	else if (form.chief_employment_id.value==7) {
		form.chief_occupation_id.value = 16;
	}
	else {
		form.chief_occupation_id.value = form.chief_occupation_id_1.value
	}
	//alert('chief_occupation_id: '+form.chief_occupation_id.value);
	
	if(form.chief_wage_earner_1 != null && form.chief_wage_earner_1[1].checked) {
		form.chief_wage_earner.value = 0;
	}
	
}

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('r2id2','hidden','none');
		changeDisplay('r2id3','hidden','none');
		//changeDisplay('child_take_survey_div','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 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_id_2[0].checked = false;
		form.gender_id_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_id_3[0].checked = false;
		form.gender_id_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_id_4[0].checked = false;
		form.gender_id_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_id_5[0].checked = false;
		form.gender_id_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_id_3[0].checked = false;
		form.gender_id_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_id_4[0].checked = false;
		form.gender_id_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_id_5[0].checked = false;
		form.gender_id_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_id_4[0].checked = false;
		form.gender_id_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_id_5[0].checked = false;
		form.gender_id_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_id_5[0].checked = false;
		form.gender_id_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_id_1[0].checked = false;
		form.gender_id_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_id_2[0].checked = false;
		form.gender_id_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_id_3[0].checked = false;
		form.gender_id_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_id_4[0].checked = false;
		form.gender_id_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_id_5[0].checked = false;
		form.gender_id_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 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 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 showNotChiefWageEarner(form) {
  //alert(form.chief_wage_earner[1].checked);
  if(form.chief_wage_earner_1 != null && form.chief_wage_earner_1[1].checked) {
	changeDisplay('r2id6', 'visible','block');
	showChiefOccupation(form);
  } 	
  else {
	changeDisplay('r2id6','hidden','none');	
  }
}

function showMobile(form) {
 
	if(form.mobile_contact[0].checked || form.flag_sms_alert[0].checked) {
		changeDisplay('mpnmpc','visible','block');
	}
	else{
		changeDisplay('mpnmpc','hidden','none');
	}
}

function doShowMobileAddress(flagMobile, flagSMS) {
		if (flagMobile==1 || flagSMS == 1)  {
			changeDisplay('mpnmpc', 'visible', 'block');
		} else {
			changeDisplay('mpnmpc','hidden','none');
		}
		
	}