// JScript File

var sltvalues = "";
function validate_form ( )
{
    valid = true;
   if(!(validate_reasonvisit()))
  {
   valid = false;
  }
    
  else if(!(validate_sltworkcountries()))
    {
    valid = false;
    }
    
    else if(!(validate_lastname()))
    {
    valid = false;
    }
        else if(!(validate_email()))
	        {
	        valid = false;
	        }
      
      else if(!(validate_phone()))
            {
            valid = false;
        }
   /*  else if(!(validate_comment()))
            {
            valid = false;
        }*/
           else if(!(validate_agreement()))
            {
            valid = false;
        }
  
    
        
    return valid;
}
function validate_firstname()
{

  valid = true;
    
  if (document.careercontact.txtFirstName.value == "" )
    {
        alert ( "Please fill in your first name." );
        valid = false;
    }
        return valid;
}

function validate_lastname()
{

  valid = true;  
    if (document.careercontact.txtLastName.value == "" )
    {
        alert ( "Please fill in your last name." );
        valid = false;
    }
return valid;
}

function validate_email()
{

 valid = true;
    
    if (document.careercontact.txtEmail.value == "" )
    {
        alert ( "Please fill in your email." );
        valid = false;
    }
    
    return echeck(document.careercontact.txtEmail.value);
    
    
    }
 
 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 ID")
 		   return false
 		}
 
 		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
 		   alert("Invalid E-mail ID")
 		   return false
 		}
 
 		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
 		    alert("Invalid E-mail ID")
 		    return false
 		}
 
 		 if (str.indexOf(at,(lat+1))!=-1){
 		    alert("Invalid E-mail ID")
 		    return false
 		 }
 
 		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
 		    alert("Invalid E-mail ID")
 		    return false
 		 }
 
 		 if (str.indexOf(dot,(lat+2))==-1){
 		    alert("Invalid E-mail ID")
 		    return false
 		 }
 		
 		 if (str.indexOf(" ")!=-1){
 		    alert("Invalid E-mail ID")
 		    return false
 		 }
 
  		 return true					
	}
        function validate_phone()
	    {
	    
	     valid = true;
	        
	        if (document.careercontact.txtPhone.value == "" )
	        {
	            alert ( "Please fill in your phone." );
	            valid = false;
	        }
	        return valid;
	        
        }
        /* function  validate_comment()
	    {
	    
	     valid = true;
	        
	        if (document.careercontact.txtComments.value == "" )
	        {
	        alert(document.careercontact.txtComments.value);
	            alert ( "Please fill in your question/change in personal information." );
	            valid = false;
	        }
	        return valid;
	        
        }*/
        
            function  validate_agreement()
	
         {
	    
	     valid = true;
	       
	        if(!document.careercontact.chkagreement.checked)
	        {
	            alert ( "Please click on agree to submit contact us form." );
	            valid = false;
	        }
	        return valid;
	        
        }
  
  
/* chkbox function - Adding 1 for each checkbox selection and -1 for each checkbox de-selection in
txthidchkcounter hidden text field
*/   
 
function chkboxagreement(box)
{


/*if(box.checked) 
      {
       //  document.careercontact.txthidchkareaofinterest.value = sltworkcountries();

      }
        else {
       //  document.careercontact.txthidchkareaofinterest.value = "";

      }
*/
        
 }
   
/* function validate_chkboxareaofinterest(box)
 {
   valid = true;
   
   if(document.careercontact.txthidchkareaofinterest.value == 0)
    {    alert("Please select atleast one option for Area of interest (checkbox)");    
         valid = false;
    }
   return valid;
   
 }
 */
   
   function validate_reasonvisit()
  {
   valid = true;
   
   var found_it;

    for (var i=0; i <document.careercontact.rdoReasonVisit.length; i++)  
        { 
            if (document.careercontact.rdoReasonVisit[i].checked)  
            {
             found_it = document.careercontact.rdoReasonVisit[i].value;
                     break;

            } 
        } 
       
        if (found_it == undefined)
        {
          valid = false;
            
             alert("Please select reason for contact us");    
        }
       
       return valid;
  
  
   
   }
   
  function validate_sltworkcountries() 
   {
      valid = true;

       var counter = 0;
       var selectedItems = "";
       
      
       for(var i=0; i < document.careercontact.sltcountry.options.length; i++) 
       
       {
       
             if ((document.careercontact.sltcountry[i].selected) && (document.careercontact.sltcountry[i].value != -1))
                     {
                       counter++;     
                       selectedItems += document.careercontact.sltcountry[i].value + "|";    
                     }
        }
        
        if (counter == 0)
         {
            alert("Please select country(s) of interest"); 
            valid =false;
         }
    
         document.careercontact.txthidchkareaofinterest.value = selectedItems;

       
	return valid;
   }
 function sltworkcountries() 
   {
      valid = "true";

       var counter = 0;
       var selectedItems = "";
       
      
       for(var i=0; i < document.careercontact.sltcountry.options.length; i++) 
       
       {
       
             if ((document.careercontact.sltcountry[i].selected) && (document.careercontact.sltcountry[i].value != -1))
                     {
                       counter++;     
                       selectedItems += document.careercontact.sltcountry[i].value + "|";    
                     }
        }
        
        if (counter == 0)
         {
            alert("Please select country(s) of interest"); 
            valid = "false";
         }
    
        selectedItems;
       
	return selectedItems;
   }
   
