//Phone Validation
function isValidPhoneNo(strng)
{
//strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\+\-\ ]/g, '');
	return !isNaN(stripped);
}

function is_empty(str)
	{
  		 str=trim(str);
		 if ((str.length==0)||(str==null))
			return true;
		 return false;
	}

	function trim(inputString) 
	{
	   // Removes leading and trailing spaces from the passed string. Also removes
	   // consecutive spaces and replaces it with one space. If something besides
	   // a string is passed in (null, custom object, etc.) then return the input.
	   if (typeof inputString != "string") { return inputString; }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Check for spaces at the beginning of the string
		  retValue = retValue.substring(1, retValue.length);
		  ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
		  retValue = retValue.substring(0, retValue.length-1);
		  ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	   }
	   return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function


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
		 }
	if ((str.match("yahoo.com"))|| (str.match("sify.com")) || (str.match("rediffmail.com"))|| (str.match("gmail.com")))
		{
		    alert("Please enter your business E-mail ID.")
		    return false
		 }
	 
 		 return true					
	}

function frm_Validate(){
	if(document.krishna.client_name.value==""){
	alert("Please enter your name.");
	document.krishna.client_name.focus();
	return false;
	}

// Email Validation 

	var emailID=document.krishna.email;
	
	if ((emailID.value==null)||(emailID.value==""))
		{
			alert("Please enter your E-mail ID.");
			emailID.focus();
			return false;
		}
	
	if (echeck(emailID.value)==false)
		{
			emailID.value="";
			emailID.focus();
			return false;
		}



// end of valid email-id check	
	if(document.getElementById('client_country').value=="")
	{
	alert("Please select Country Name.");
	document.krishna.client_country.focus();
	return false;
	}
    if(document.krishna.client_contact.value=="")
	{
	alert("Please enter Contact Number.");
	document.krishna.client_contact.focus();
	return false;
	}
	if(document.krishna.client_url.value=="")
	{
	alert("Please enter Website URL.");
	document.krishna.client_url.focus();
	return false;
	}
	
	if(document.getElementById('wp1').checked==false && document.getElementById('wp2').checked==false && document.getElementById('wp3').checked==false && document.getElementById('wp4').checked==false)
	{
	alert("Please select Directory Submission Packages");
	return false;
	}
	
	if(document.krishna.client_message.value=="")
	{
	alert("Please enter Message.");
	document.krishna.client_message.focus();
	return false;
	}
	
	if(document.krishna.captcha.value=="")
	{
	alert("Please enter Verification Code.");
	document.krishna.captcha.focus();
	return false;
	}
}

///#### Call form validation
function callfrm_Validate(){
	if(is_empty(document.callform.name.value)){
    document.callform.name.value="";
	alert("Please enter your name.");
	document.callform.name.focus();
	return false;
	}

// Email Validation 

	var emailID=document.callform.email;
	
	if ((emailID.value==null)||(emailID.value==""))
		{
			alert("Please enter your E-mail ID.");
			emailID.focus();
			return false;
		}
	
	if (echeck(emailID.value)==false)
		{
			emailID.value="";
			emailID.focus();
			return false;
		}



// end of valid email-id check	
    if(is_empty(document.callform.phone.value))
	{
	document.callform.phone.value="";
	alert("Please enter your phone number.");
	document.callform.phone.focus();
	return false;
	}
	if(!isValidPhoneNo(document.callform.phone.value))
	{
     alert("Please enter a valid phone number.");
	 document.callform.phone.focus();
	 return false;
	}
	
	if(is_empty(document.callform.calltime.value))
	{
	document.callform.calltime.value="";
	alert("Please enter best time to call.");
	document.callform.calltime.focus();
	return false;
	}
	
	if(is_empty(document.callform.cmnts.value))
	{
	document.callform.cmnts.value="";
	alert("Please enter your comments.");
	document.callform.cmnts.focus();
	return false;
	}
	
	if(document.callform.captcha.value=="")
	{
	alert("Please enter verification code.");
	document.callform.captcha.focus();
	return false;
	}
}

