 function echeck(str) {

  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		  return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		   return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		   return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		   return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		   return false
		 }
		   return true	
}	

function validate_employer ( )
{
    var errors=0;

    if ( document.employerregistration.fldEmployerName.value == "" )
    {
        alert ( "Please specify your name." );
        errors ++;
    }
	
    if ( document.employerregistration.fldEmployerContactName.value == "" )
    {
        alert ( "Please specify your contact name." );
        errors ++;
    } 

	 if ( document.employerregistration.fldEmployerAddr1.value == "" )
    {
        alert ( "Please specify your address." );
       errors ++;
    }
	 if ( document.employerregistration.fldEmployerAddr4.value == "" )
    {
        alert ( "Please specify your town." );
       errors ++;
    }
	 if ( document.employerregistration.fldEmployerAddr5.value == "" )
    {
        alert ( "Please specify your county." );
       errors ++;
    }
	 if ( document.employerregistration.fldEmployerCountry.value == "" )
    {
        alert ( "Please specify your country." );
       errors ++;
    }
	 if ( document.employerregistration.fldEmployerTel1.value == "" )
    {
        alert ( "Please specify your Contact telephone number." );
       errors ++;
    }
 if ( document.employerregistration.fldEmployerEmail.value != document.employerregistration.fldEmployerEmail2.value)
    {
        alert ( "Your email address does not match" );
        valid = false;
    }			   
	 if ( document.employerregistration.fldEmployerSectorID.value == "" )
    {
        alert ( "Please specify your industry sector." );
       errors ++;
    }	
	 if ( document.employerregistration.fldEmployerEmployeeGrpID.value == "" )
    {
        alert ( "Please specify the number of employees." );
       errors ++;
    }			 	
 if ( document.employerregistration.fldEmployerTypeID.value == "" )
    {
        alert ( "Please specify your Manager type." );
        errors ++;
    }
 if ( document.employerregistration.username.value == "" )
    {
        alert ( "Please specify your username." );
        errors ++;
    }
 if ( document.employerregistration.password.value.length < 8 )
    {
        alert ( "Password must be at least 8 digits." );
        errors ++;
    }
 if ( document.employerregistration.password.value == document.employerregistration.username.value )
    {
        alert ( "Password and username can not be the same." );
        errors ++;
    } 		 
 if ( document.employerregistration.password.value != document.employerregistration.password2.value)
    {
        alert ( "Your passwords do not match" );
        valid = false;
    }
 if ( !document.employerregistration.tandc.checked )
    {
        alert ( "Please confirm your acceptance of the terms and conditions." );
        errors ++;
    }
if ( document.employerregistration.referraltype.value=="" )
    {
        alert ( "Please state how you found us." );
        errors ++;
    }
 if (document.employerregistration.referraltype.value=="Magazine or Paper - specify" || document.employerregistration.referraltype.value=="On-line - specify" ||  document.employerregistration.referraltype.value=="Other")
    {
        if(document.employerregistration.referral.value=='')
         {
        alert ( "Please note specifically how you found us." );
        errors ++;
    	}	
    }
	
var emailID=document.employerregistration.fldEmployerEmail
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}
	

     if(!errors)
   {

   document.employerregistration.submit();
   document.employerregistration.action='employer-registration2.php';
   }
}

   
function change_settings(select)
  {
   switch(select.options[select.selectedIndex].value)
   {
    case "Magazine or Paper - specify" :
	case "On-line - specify" :
	case "Other" :

    document.employerregistration.referral.disabled=false;
     break;
 
   }
   switch(select.options[select.selectedIndex].value)
   {
    case "Google" :
	case "Yahoo" :
	case "Other Search Engine" : 
	case "We contacted you":
	case "Referral":

    document.employerregistration.referral.disabled=true;
     break;
 
   }


  } 


