 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_recruiter ( )
{
    var errors=0;

    if ( document.recruiterregistration.fldRecruiterFirstName.value == "" )
    {
        alert ( "Please specify your First name." );
        errors ++;
    }
	
    if ( document.recruiterregistration.fldRecruiterSurname.value == "" )
    {
        alert ( "Please specify your Surname." );
        errors ++;
    } 

	 if ( document.recruiterregistration.fldRecruiterAddr1.value == "" )
    {
        alert ( "Please specify your address." );
       errors ++;
    }
var emailID=document.recruiterregistration.fldRecruiterEmail
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}
	

     if(!errors)
   {

   document.candidateregistration.submit();
   document.candidateregistration.action='recruiter_registration2.php';
   }
}
	  
function validate_candidate ( )
{
    var errors=0;

    if ( document.candidateregistration.CandidateFirstName.value == "" )
    {
        alert ( "Please specify your First name." );
        errors ++;
    }
	
    if ( document.candidateregistration.CandidateSurname.value == "" )
    {
        alert ( "Please specify your Surname." );
        errors ++;
    } 
   /* if ( document.candidateregistration.CandidateSex.value == "" )
    {
        alert ( "Please specify your Sex. (used for statistical analysis only)" );
        errors ++;
    } 
	 if ( document.candidateregistration.CandidateDOB.value == "" )
    {
        alert ( "Please specify your year of birth.(used for statistical analysis only)" );
       errors ++;
    }*/

 if ( document.candidateregistration.CandidateCountry.value == "" )
    {
        alert ( "Please specify your country." );
        errors ++;
    }
 if ( document.candidateregistration.CandidateEmail.value != document.candidateregistration.CandidateEmail2.value)
    {
        alert ( "Your email address does not match" );
        valid = false;
    }
 if ( document.candidateregistration.CandidateSectorID.value == "" )
    {
        alert ( "Please specify your Sector." );
        errors ++;
    }
 if ( document.candidateregistration.CandidateTypeID.value == "" )
    {
        alert ( "Please specify your Candidate Type." );
        errors ++;
    }
 if ( document.candidateregistration.CandidateJobAreaID.value == "" )
    {
        alert ( "Please specify your Job Area." );
        errors ++;
    }
 if ( document.candidateregistration.CandidateLevelID.value == "" )
    {
        alert ( "Please specify your Candidate Level." );
        errors ++;
    }
 if ( document.candidateregistration.password.value == document.candidateregistration.username.value )
    {
        alert ( "Password and username can not be the same." );
        errors ++;
    } 
 if ( document.candidateregistration.username.value == "" )
    {
        alert ( "Please specify your username." );
        errors ++;
    }
 if ( document.candidateregistration.password.value.length < 8 )
    {
        alert ( "Password must be at least 8 digits." );
        errors ++;
    } 
 if ( document.candidateregistration.password.value != document.candidateregistration.password2.value)
    {
        alert ( "Your passwords do not match" );
        valid = false;
    }
 if ( !document.candidateregistration.tandc.checked )
    {
        alert ( "Please confirm you accept the terms and conditions." );
        errors ++;
    }
 if ( document.candidateregistration.referraltype.value=="" )
    {
        alert ( "Please state how you found us." );
        errors ++;
    }
 if (document.candidateregistration.referraltype.value=="Magazine or Paper - specify" || document.candidateregistration.referraltype.value=="On-line - specify" ||  document.candidateregistration.referraltype.value=="Other")
    {
        if(document.candidateregistration.referral.value=='')
         {
        alert ( "Please note specifically how you found us." );
        errors ++;
    	}	
    }
var emailID=document.candidateregistration.CandidateEmail
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}
	 // regular expression to match alphanumeric characters and spaces 
 var re = /^[\w ]+$/; 
 // validation fails if the input doesn't match the regular expression 
 if(!re.test(document.candidateregistration.password.value)) 
    {
        alert ( "Your password contains invalid characters - numbers or letters only please" );
        errors ++;
    }

     if(!errors)
   {

   document.candidateregistration.submit();
   document.candidateregistration.action='candidate_registration2.php';
   }
}
  
function change_settings(select)
  {
   switch(select.options[select.selectedIndex].value)
   {
    case "Magazine or Paper - specify" :
	case "On-line - specify" :
	case "Other" :

    document.candidateregistration.referral.disabled=false;
     break;
 
   }
   switch(select.options[select.selectedIndex].value)
   {
    case "PCG" :
	
     alert ( "If you are a PCG member you have your own dedicated set up via the member only area of the PCG site.  Please register via this so as to ensure you gain access to PCG member benefits and features." );
     break;
 
   }
   switch(select.options[select.selectedIndex].value)
   {
    case "Google" :
	case "Yahoo" :
	case "Other Search Engine" : 
	case "We contacted you":
	case "Referral":

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


  } 


