// JavaScript Document
function checkEmail(email) {
var regExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
return regExp.test(email);
}



//start validation for tellafriends form
function tell(frmtell)
{
	if (document.frmtell.friendsname.value == "")
   	{
	  alert("Friend's name Should not be blanked");
	  document.frmtell.friendsname.select();
	  document.frmtell.friendsname.focus();
  	  return false;
   	}
	if (document.frmtell.name.value == "")
   	{
	  alert("Name Should not be blanked");
	  document.frmtell.name.select();
	  document.frmtell.name.focus();
  	  return false;
   	}	
	if (document.frmtell.friendsemail.value == "")
   	{
	  alert("Friend email is blank");
	  document.frmtell.friendsemail.select();
	  document.frmtell.friendsemail.focus();
  	  return false;
   	}
	else if(document.frmtell.friendsemail.value!="")
   {

		var temp1 =1
		inputStr3=document.frmtell.friendsemail.value
		lenth3=inputStr3.length
		a=inputStr3.indexOf("@")
		e=inputStr3.indexOf("@")
		b=inputStr3.lastIndexOf(".")        
		c=inputStr3.lastIndexOf("@")
			if(inputStr3=="")
			{
			temp1=0
			}
			else
				{
		  		for(var i=0; i<lenth3; i++)
					{
					if(a > e)
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
							else
								{
								 temp1=0
								}       
						}	
					else
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
								else
								{
								temp1=0
								}       
				}
			}       
		}               
		if(temp1==0)
				{       
	
                alert("Mail ID is Not Correct");
	  			document.frmtell.friendsemail.select();
	  			document.frmtell.friendsemail.focus();
  	  			return false;                 
		
				}       
	}
	
	if (document.frmtell.email.value  == "")
   	{
	  alert("Email is blank");
	  document.frmtell.email.select();
		document.frmtell.email.focus();
  	  return false;
   	}		
	else if(document.frmtell.email.value!="")
   {

		var temp1 =1
		inputStr3=document.frmtell.email.value
		lenth3=inputStr3.length
		a=inputStr3.indexOf("@")
		e=inputStr3.indexOf("@")
		b=inputStr3.lastIndexOf(".")        
		c=inputStr3.lastIndexOf("@")
			if(inputStr3=="")
			{
			temp1=0
			}
			else
				{
		  		for(var i=0; i<lenth3; i++)
					{
					if(a > e)
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
							else
								{
								 temp1=0
								}       
						}	
					else
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
								else
								{
								temp1=0
								}       
				}
			}       
		}               
		if(temp1==0)
				{       
	
                alert("Mail ID is Not Correct");
	  			document.frmtell.email.select();
	  			document.frmtell.email.focus();
  	  			return false;                 
		
				}       
	}
	if (document.frmtell.comments.value == "")
   	{
	  alert("Message should not be blanked");
	  document.frmtell.comments.select();
	  document.frmtell.comments.focus();
  	  return false;
   	}

}
//end validation for tellafriends form

//start validation for helpus form
function validation(frmmail)
{
	re = /^\d{1,2}:\d{2}( [ap]m)?$/;	
	if (document.frmmail.name.value == "")
   	{
	  alert("Name must be filled");
	  document.frmmail.name.select();
	  document.frmmail.name.focus();
  	  return false;
   	}
	if (document.frmmail.phone.value == "")
   	{
	  alert("Contact No should not be blanked");
	  document.frmmail.phone.select();
	  document.frmmail.phone.focus();
  	  return false;
   	}	
	if (document.frmmail.time_to_call.value == "")
   	{
	  alert("Calling time should not be blanked");
	  document.frmmail.time_to_call.select();
	  document.frmmail.time_to_call.focus();
  	  return false;
   	}
	if(document.frmmail.time_to_call.value != '' && !document.frmmail.time_to_call.value.match(re)) 
		{ 
			alert("Invalid time format:  " + document.frmmail.time_to_call.value + "\n Format should be: 9:30 am"); 
			document.frmmail.time_to_call.focus(); 
			return false;
		}
	if (document.frmmail.country.value == "")
   	{
	  alert("Please specify your country");
	  document.frmmail.country.select();
	  document.frmmail.country.focus();
  	  return false;
   	}
	if (document.frmmail.email.value == "")
   	{
	  alert("Email ID is blanked");
	  document.frmmail.email.select();
	  document.frmmail.email.focus();
  	  return false;
   	}
	else if(document.frmmail.email.value!="")
   {

		var temp1 =1
		inputStr3=document.frmmail.email.value
		lenth3=inputStr3.length
		a=inputStr3.indexOf("@")
		e=inputStr3.indexOf("@")
		b=inputStr3.lastIndexOf(".")        
		c=inputStr3.lastIndexOf("@")
			if(inputStr3=="")
			{
			temp1=0
			}
			else
				{
		  		for(var i=0; i<lenth3; i++)
					{
					if(a > e)
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
							else
								{
								 temp1=0
								}       
						}	
					else
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
								else
								{
								temp1=0
								}       
				}
			}       
		}               
		if(temp1==0)
				{       
	
                alert("Mail ID is Not Correct");
	  			document.frmmail.email.select();
	  			document.frmmail.email.focus();
  	  			return false;                 
		
				}       
	}
	if (document.frmmail.message.value == "")
   	{
	  alert("Requirements should not be blanked");
	  document.frmmail.message.select();
	  document.frmmail.message.focus();
  	  return false;
   	}

}
//end validation for helpus form

//start validation for contactus form
function contact(frmcontact)
{
	if (document.frmcontact.name.value == "")
   	{
	  alert("Name must be filled");
	  document.frmcontact.name.select();
	  document.frmcontact.name.focus();
  	  return false;
   	}
	if (document.frmcontact.email.value == "")
   	{
	  alert("Email ID is blanked");
	  document.frmcontact.email.select();
	  document.frmcontact.email.focus();
  	  return false;
   	}
	else if(document.frmcontact.email.value!="")
   {

		var temp1 =1
		inputStr3=document.frmcontact.email.value
		lenth3=inputStr3.length
		a=inputStr3.indexOf("@")
		e=inputStr3.indexOf("@")
		b=inputStr3.lastIndexOf(".")        
		c=inputStr3.lastIndexOf("@")
			if(inputStr3=="")
			{
			temp1=0
			}
			else
				{
		  		for(var i=0; i<lenth3; i++)
					{
					if(a > e)
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
							else
								{
								 temp1=0
								}       
						}	
					else
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
								else
								{
								temp1=0
								}       
				}
			}       
		}               
		if(temp1==0)
				{       
	
                alert("Mail ID is Not Correct");
	  			document.frmcontact.email.select();
	  			document.frmcontact.email.focus();
  	  			return false;                 
		
				}       
	}
	
	if (document.frmcontact.phone.value == "")
   	{
	  alert("Contact No should not be blanked");
	  document.frmcontact.phone.select();
	  document.frmcontact.phone.focus();
  	  return false;
   	}
		if (document.frmcontact.country.value == "")
   	{
	  alert("Please specify your country");
	  document.frmcontact.country.select();
	  document.frmcontact.country.focus();
  	  return false;
   	}
	if (document.frmcontact.message.value == "")
   	{
	  alert("Requirements should not be blanked");
	  document.frmcontact.message.select();
	  document.frmcontact.message.focus();
  	  return false;
   	}

}

//end validation for contactus form



//start validation for feedback form
function feed(frmfeedback)
{
	if (document.frmfeedback.name.value == "")
   	{
	  alert("Name must be filled");
	  document.frmfeedback.name.select();
	  document.frmfeedback.name.focus();
  	  return false;
   	}
	if (document.frmfeedback.country.value == "")
   	{
	  alert("Please give your Country Name");
	  document.frmfeedback.country.select();
	  document.frmfeedback.country.focus();
  	  return false;
   	}
	if (document.frmfeedback.email.value == "")
   	{
	  alert("Email ID is blanked");
	  document.frmfeedback.email.select();
	  document.frmfeedback.email.focus();
  	  return false;
   	}
	else if(document.frmfeedback.email.value!="")
   {

		var temp1 =1
		inputStr3=document.frmfeedback.email.value
		lenth3=inputStr3.length
		a=inputStr3.indexOf("@")
		e=inputStr3.indexOf("@")
		b=inputStr3.lastIndexOf(".")        
		c=inputStr3.lastIndexOf("@")
			if(inputStr3=="")
			{
			temp1=0
			}
			else
				{
		  		for(var i=0; i<lenth3; i++)
					{
					if(a > e)
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
							else
								{
								 temp1=0
								}       
						}	
					else
						{
							if((a+1)<b && a==c && a>0 && b<(lenth3-1))
							{
							}
								else
								{
								temp1=0
								}       
				}
			}       
		}               
		if(temp1==0)
				{       
	
                alert("Mail ID is Not Correct");
	  			document.frmfeedback.email.select();
	  			document.frmfeedback.email.focus();
  	  			return false;                 
		
				}       
	}
	
	if (document.frmfeedback.subject.value == "")
   	{
	  alert("Subject should not be blanked");
	  document.frmfeedback.subject.select();
	  document.frmfeedback.subject.focus();
  	  return false;
   	}
	if (document.frmfeedback.message.value == "")
   	{
	  alert("Query should not be blanked");
	  document.frmfeedback.message.select();
	  document.frmfeedback.message.focus();
  	  return false;
   	}

}

//end validation for feedback form


//---------------for checking integer -------------
function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) 
			{
			return false;
			break;
			}
			return true;
		 }
	}

//--------------email validation -------------------
	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;				
	}

	/*************** Phone number validation **************/

		// Declaring required variables
		var digits = "0123456789";
		// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()- ";
		// characters which are allowed in international phone numbers
		// (a leading + is OK)
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 10;

		function stripCharsInBag(s, bag)
		{   
			var i;
			var returnString = "";
			// Search through string's characters one by one.
			// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++)
			{   
				// Check that current character isn't whitespace.
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
		}

		function checkInternationalPhone(strPhone)
		{
			s=stripCharsInBag(strPhone,validWorldPhoneChars);
			return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
		}

//-------------------------------

function applyjob()
{	
	if(document.frmapply.First_Name.value=="")
	{
		alert("Please Enter Your First Name");
		document.frmapply.First_Name.focus();
		return false;
	}
	if(document.frmapply.Last_Name_APP.value=="")
	{
		alert("Please Enter Your Last Name");
		document.frmapply.Last_Name_APP.focus();
		return false;
	}
	if(document.frmapply.Email.value=="")
	{
		alert("Please Enter Your Email Address");
		document.frmapply.Email.focus();
		return false;
	}
	if(!echeck(document.frmapply.Email.value))
	{
		document.frmapply.Email.value='';
		document.frmapply.Email.focus();
		return false;
	}
	if(document.frmapply.Phone.value=="")
	{
		alert("Please Enter Your Phone Number");
		document.frmapply.Phone.focus();
		return false;
	}
	if(checkInternationalPhone(document.frmapply.Phone.value)==false)
	{
		alert("Enter The Correct Contact Number");
		document.frmapply.Phone.value='';
		document.frmapply.Phone.focus();
		return false;
	}
	if(document.frmapply.DD.value=="")
	{
		alert("Please Enter Your Date Of Birth");
		document.frmapply.DD.focus();
		return false;
	}
	if(!isInteger(document.frmapply.DD.value))
	{
		alert("Please Enter Your Date Of Birth Correct");
		document.frmapply.DD.value='';
		document.frmapply.DD.focus();
		return false;
	}
	if(document.frmapply.MM.value=="")
	{
		alert("Please Enter Your Month Of Birth");
		document.frmapply.MM.focus();
		return false;
	}
	if(!isInteger(document.frmapply.MM.value))
	{
		alert("Please Enter Your Date Of Birth Correct");
		document.frmapply.MM.value='';
		document.frmapply.MM.focus();
		return false;
	}
	if(document.frmapply.YY.value=="")
	{
		alert("Please Enter Your Year Of Month");
		document.frmapply.YY.focus();
		return false;
	}
	if(!isInteger(document.frmapply.YY.value))
	{
		alert("Please Enter Your Date Of Year Correct");
		document.frmapply.YY.value='';
		document.frmapply.YY.focus();
		return false;
	}
	if(document.frmapply.Job_Position.value=="")
	{
		alert("Please Select Job Position");
		document.frmapply.Job_Position.focus();
		return false;
	}
	if(document.frmapply.Educational.value=="")
	{
		alert("Choose Your Educational Qualifications");
		document.frmapply.Educational.focus();
		return false;
	}
	if(document.frmapply.Roles.value=="")
	{
		alert("Choose Sigificant Roles Played");
		document.frmapply.Roles.focus();
		return false;
	}
	if(document.frmapply.Experience.value=="")
	{
		alert("Please Enter Your IT Experience");
		document.frmapply.Experience.focus();
		return false;
	}
	if(document.frmapply.Current_Employer.value=="")
	{
		alert("Please Enter Current Employer");
		document.frmapply.Current_Employer.focus();
		return false;
	}
	if(document.frmapply.Present_Salary.value=="")
	{
		alert("Please Enter Your Present Salary");
		document.frmapply.Present_Salary.focus();
		return false;
	}
	
	if(document.frmapply.Expect_Salary.value=="")
	{
		alert("Please Enter Your Expected Salary");
		document.frmapply.Expect_Salary.focus();
		return false;
	}
	if((document.frmapply.Text_Resume.value=="") && (document.frmapply.Resume.value==""))
	{
		alert("Please Paste Your Updated Resume\n OR Upload your Resume.");
		document.frmapply.Text_Resume.focus();
		return false;
	}
	if(document.frmapply._vCapt_APP.value=="")
	{
		alert("Please Enter Verification Code Here");
		document.frmapply._vCapt_APP.focus();
		return false;
	}
}