function checkemail(){
  var xmlHttp;
  var email = document.getElementById('email').value;
  if(email.length > 0){
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
      	 	check_fields_wemail(xmlHttp.responseText);
        }
      }          
    xmlHttp.open("GET","emailcheck.php?email="+email,true);
    xmlHttp.send(null);
  }
  }

function update(i)
{
	clear_all();
	if(i>0){
	toggleLayer(i,'block');
	toggleLayer("submit",'block');
	}
}

function clear_all()
{
// Collapse all non-used blocks.
toggleLayer("1",'none');
toggleLayer("2",'none');
toggleLayer("3",'none');
toggleLayer("4",'none');
toggleLayer("5",'none');
toggleLayer("6",'none');
toggleLayer("7",'none');
toggleLayer("8",'none');
toggleLayer("submit",'none');

}


function toggleLayer( whichLayer, way )  //way=none, block
{  
var elem, vis;  

if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  
else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  
vis = elem.style;  // if the style.display value is blank we try to figure it out here  

if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
	vis.display = way;
vis.display = way; //(vis.display==''||vis.display=='block')?'none':'block';
}


function IsNumeric(sText)

{
   var ValidChars = "0123456789.,$";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   if(sText.length==0)
     	IsNumber = false;
   return IsNumber;
   
   }


function check_fields(){
	var email = document.getElementById('email').value;
  	if(email.length > 0)
		checkemail();
	else
		check_fields_wemail(email);
	
} 
  
function check_fields_wemail(email_exist){			
		var Err = "";
		
		
		with (document.signup_form.email)
		{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
				Err += "Please enter a correct email address.\n";
			}		
		}
		
		if(email_exist.length > 0)
			Err += email_exist;
		
		if(document.signup_form.fname.value.length<1)
			Err += "Please enter your first name.\n";
		
		if(document.signup_form.lname.value.length<2)
			Err += "Please enter your last name.\n";
		
		if(document.signup_form.telday.value<7)
			Err += "Please enter your telephone number with country code (if applicable), area code and extension.\n";
		
		var account_type = document.getElementById('type').value;
		var Err_Account = "";
		
		if(account_type==1){			
			if(document.getElementById('networth').value.length<=0){
				Err_Account += 'You must enter your net worth.\n';
			}
			if(document.getElementById('avgsalary').value.length<=0){
				Err_Account += 'You must enter your average salary.\n';
			}
			if(document.getElementById('1_1').checked==false&&document.getElementById('1_2').checked==false){
				Err_Account += 'You must select one of the choices.\n';
			}
		}
		if(account_type==2){
			if(document.getElementById('2_1').checked==false&&document.getElementById('2_2').checked==false)
				Err_Account += 'You must select one of the choices.\n';
		}
		if(account_type==3){
			if(document.getElementById('3_1').checked==false&&document.getElementById('3_2').checked==false&&document.getElementById('3_3').checked==false)
				Err_Account += 'You must select one of the choices.\n';
		}
		if(account_type==4){
			if(document.getElementById('4_1').checked==false)
				Err_Account += 'You must select the item to continue.\n';
		}
		if(account_type==5){
			if(document.getElementById('5_1').checked==false)
				Err_Account += 'You must select the item to continue.\n';
		}
		if(account_type==6){
			if(document.getElementById('6_1').checked==false&&document.getElementById('6_2').checked==false&&document.getElementById('6_3').checked==false)
				Err_Account += 'You must select one of the choices.\n';
				
			if(document.getElementById('6_1').checked){
				if(document.getElementById('fiduciary').value.length<=0)
					Err_Account += 'Please enter the plan fiduciary.\n';	
			}
		}
		if(account_type==7){
			if(document.getElementById('7_1').checked==false)
				Err_Account += 'You must select the item to continue.\n';
		}
		var Err_tc = "";
		if(document.getElementById('tc_agree').checked==false)
				Err_tc = 'You must agree to the terms.';
			
		if(Err_Account.length>0)
			Err = Err + Err_Account;
		
		if(Err_tc.length>0)
			Err = Err + Err_tc;

		if(Err.length>0){
			alert(Err);
			return false;
		}
		
		document.signup_form.submit();
		

	}
	
	function clear_checkboxes(type, curr){
		if(type==1){
			document.getElementById('1_1').checked = false;
			document.getElementById('1_2').checked = false;
		}
		if(type==2){
			document.getElementById('2_1').checked = false;
			document.getElementById('2_2').checked = false;
		}
		if(type==3){
			document.getElementById('3_1').checked = false;
			document.getElementById('3_2').checked = false;
			document.getElementById('3_3').checked = false;
		}
		if(type==6){
			document.getElementById('6_1').checked = false;
			document.getElementById('6_2').checked = false;
			document.getElementById('6_3').checked = false;
		}
		
		document.getElementById(type + '_' + curr).checked = true;
	}
	
	function div_collapse(div){
		var objDrop = document.getElementById(div); 
		if(objDrop.style.display=="none") 
		{ 
			objDrop.style.display="block";
		}	
		else
		{ 	
			objDrop.style.display="none";
		} 		
	}
	

