// JScript File


function validate_form ( )
{
    valid = true;
    
    
     if(!(validate_reasonvisit()))
    {
     valid = false;
    }
   

   else if(!(validate_chktype()))
    {
     valid = false;
    }
    else if(!(validate_chkboxareaofinterest()))
    {
    valid = false;
    }
    
 else if(!(validate_sltworkcountries()))
    {
    valid = false;
    }
    
    else if (!(validate_language1()))
    {
    valid = false;
    } 
     else if (!(validate_experience()))
    {
    valid = false;
    } 
   else if (!(validate_firstname()))
    {
    valid = false;
    } 
    else if(!(validate_lastname()))
    {
    valid = false;
    }
        else if(!(validate_email()))
	        {
	        valid = false;
	        }
      
      else if(!(validate_phone()))
            {
            valid = false;
        }
        else if(!(validate_country()))
            {
            valid = false;
        }
        
     else if(!(validate_chkhearaboutus()))
    {
     valid = false;
    }
     else if(!(validate_agreement()))
                      {
                      valid = false;
            }
    return valid;
}
function validate_firstname()
{

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

function validate_lastname()
{

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

function validate_email()
{

 valid = true;
    
    if (document.resume.txtEmail.value == "" )
    {
        alert ( "Please fill in your email." );
        valid = false;
    }
    
    return echeck(document.resume.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.resume.txtPhone.value == "" )
	        {
	            alert ( "Please fill in your phone." );
	            valid = false;
	        }
	        return valid;
	        
        }
         function validate_country()
	    {
	    
	     valid = true;
	        
	        if (document.resume.txtCountryResidence.value == "" )
	        {
	            alert ( "Please fill in your Country of Residence." );
	            valid = false;
	        }
	        return valid;
	        
        }
     
  /*validate_multipleselection function - Checks if none of the check box is selected hence hidden
  textbox value = 0. Thus, Raise alert for selection*/ 
  
  /*function validate_multipleselection()
  {
   valid = true;
   
   if(document.resume.txthidchk.value == 0)
    {    alert("Please select atleast one technology (checkbox)");    
         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 chkboxreasonvisit(box)
{

var nchkboxval = eval(document.resume.txthidchkreasonvisit.value);

if (nchkboxval == null)
{
    nchkboxval = 0;
}

if(box.checked) 
      {
        document.resume.txthidchkreasonvisit.value = eval(nchkboxval + 1);
      }
        else {
         document.resume.txthidchkreasonvisit.value = eval(nchkboxval - 1);
      }
 }
function chkboxhearaboutus(box)
{

var nchkboxval = eval(document.resume.txthidchkhearabout.value);

if (nchkboxval == null)
{
    nchkboxval = 0;
}

if(box.checked) 
      {
        document.resume.txthidchkhearabout.value = eval(nchkboxval + 1);
      }
        else {
         document.resume.txthidchkhearabout.value = eval(nchkboxval - 1);
      }
 }
 
function chkboxareaofinterest(box)
{

var nchkboxval = eval(document.resume.txthidchkareaofinterest.value);

if (nchkboxval == null)
{
    nchkboxval = 0;
}

if(box.checked) 
      {
        document.resume.txthidchkareaofinterest.value = eval(nchkboxval + 1);
      }
        else {
         document.resume.txthidchkareaofinterest.value = eval(nchkboxval - 1);
      }

        
 }
 function chkboxtype(box)
{

var nchkboxval = eval(document.resume.txthidchktype.value);

if (nchkboxval == null)
{
    nchkboxval = 0;
}

if(box.checked) 
      {
        document.resume.txthidchktype.value = eval(nchkboxval + 1);
      }
        else {
         document.resume.txthidchktype.value = eval(nchkboxval - 1);
      }

        
 }
  function validate_chktype()
  {
   valid = true;
   
   if(document.resume.txthidchktype.value == 0)
    {    alert("Please select atleast one option for employement type (checkbox)");    
         valid = false;
    }
   return valid;
   
   }  
 function validate_chkboxareaofinterest(box)
 {
   valid = true;
   
   if(document.resume.txthidchkareaofinterest.value == 0)
    {    alert("Please select atleast one option for Area of interest (checkbox)");    
         valid = false;
    }
   return valid;
   
 }
 function validate_chkhearaboutus()
  {
   valid = true;
   
   if(document.resume.txthidchkhearabout.value == 0)
    {    alert("Please select atleast one option in hear about us (checkbox)");    
         valid = false;
    }
   return valid;
   
   }   
   function validate_reasonvisit()
  {
   valid = true;
   
   var found_it;

    for (var i=0; i <document.resume.rdoReasonVisit.length; i++)  
        { 
            if (document.resume.rdoReasonVisit[i].checked)  
            {
             found_it = document.resume.rdoReasonVisit[i].value;
                     break;

            } 
        } 
       
        if (found_it == undefined)
        {
          valid = false;
            
             alert("Please select either first-time entry or updated information");    
        }
       
       return valid;
  
  
   
   }
   
  function validate_language1()
  {
   valid = true;
     if(document.resume.txtLanguage1.value == "")
    {    alert("Please enter atleast one language proficiency");    
         valid = false;
    }
   return valid;
   
   }   
  
  function validate_experience()
  {
   valid = true;
   
   var found_it;

    for (var i=0; i <document.resume.rdoCred.length; i++)  
        { 
            if (document.resume.rdoCred[i].checked)  
            {
             found_it = document.resume.rdoCred[i].value;
                     break;

            } 
        } 
       
        if (found_it == undefined)
        {
          valid = false;
            
             alert("Please select experience level option");
        }
       
       return valid;
   
   }   
  function validate_sltworkcountries() 
   {
      valid = true;

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

       var counter = 0;
       var selectedItems = "";
       
      
       for(var i=0; i < document.resume.sltcountry.options.length; i++) 
       
       {
       
             if ((document.resume.sltcountry[i].selected) && (document.resume.sltcountry[i].value != -1))
                     {
                       counter++;     
                       selectedItems += document.resume.sltcountry[i].value + "|";    
                     }
        }
        
        if (counter == 0)
         {
           
            valid = "false";
         }
    
        selectedItems;
       
	return selectedItems;
   }
    function  validate_agreement()
   	
            {
   	    
   	     valid = true;
   	       
   	        if(!document.resume.chkagreement.checked)
   	        {
   	            alert ( "Please click on agree to privacy policy to submit interest form." );
   	            valid = false;
   	        }
   	        return valid;
   	        
        }
   
