// JavaScript Document
function formValidator()
{
// Make quick references to our fields
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	var country = document.getElementById('country');	
	var prob = document.getElementById('prob');		
	
	// Check each input in the order that it appears in the form!
if(isAlphabet(name, "Please enter a valid first name")){
if(isEmpty(name, "Please enter your first name")){
if(emailValidator(email, "Please enter a valid email address")){
if(isEmpty(prob, "Please enter the Problem Description")){
if(!document.form_query.checkbox.checked){alert("Please accept the Terms of Use"); 
 return false;} 

document.form_query.submit();
return true;

}
}
}
}
return false;
}

function validate_info()
{
	var name = document.getElementById('name').value;	
	var email = document.getElementById('email').value ;
	var comment = document.getElementById('comment').value ;
	if ( name == "" )
	{
		alert("Please enter your name");
		document.getElementById('name').focus();
		return(false);
	}
	else if ( email == "" )
	{
		alert("Please enter the Email Address ");
		document.getElementById('email').focus();
		return(false);
	}
	else if (checkemail(email)== false)
	{
		alert("Please enter a valid Email Address.");
		document.getElementById('email').focus();
		return(false);
	}
	else if ( comment == "" )
	{
		alert("Please enter your Feedback / Comments ");
		document.getElementById('comment').focus();
		return(false);
	}
}

function checkEmail(email)
{
	var test1 = "@" ;
	var test2 = "." ;
	var count1 = 0 ;
	var count2 = 0 ;
	
	
	for( i=0;i< email.length ; i++)
    {
     var  ch1 = email.charAt(i);
     if ( count1 != 0 )
     break;
     for(j=0;j < test1.length ; j++)
     {
       if( ch1 == test1.charAt(j) )
       {
         count1 = count1+1;
         break; 
       }
     } 
    }
	for( i=0;i< email.length ; i++)
    {
     var  ch2 = email.charAt(i);
     if ( count2 != 0 )
     break;
     for(j=0;j < test2.length ; j++)
     {
       if( ch2 == test2.charAt(j) )
       {
         count2 = count2+1;
         break; 
       }
     } 
    }
    if( count1 == 0 )
    {
      //alert("Invalid Email Address  must contain '@'");
      //document.getElementById('emailId').focus()
      return true;
    } 
    if( count2 == 0 )
    {
      //alert("Invalid Email Address must contain '.'");
      //document.getElementById('emailId').focus()
		return true;
    } 
	if((email.charAt(0) == "@") || ( email.charAt(0) == ".")  )
	{
	  //alert("Invalid Email Address ");
	//  document.getElementById('emailId').value="";
     // document.getElementById('emailId').focus()
      return true; 
	}
	else
	{
		return false
	}
}
function isNumeric(pin)
{
	var test = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+|." ;
	var count = 0 ;            
    for( i=0;i< pin.length ; i++)
    {
        var  ch = pin.charAt(i);
         if ( count != 0 )
             break;
         for(j=0;j < test.length ; j++)
          {
              if( ch == test.charAt(j) )
               {
                  count = count+1;
                   break; 
                 }
           } 
    }
    if( count != 0 )
    {
		return (true);
    }
	else
	{
		return false
	}
}
var testresults
function checkemail(email)
{
	var str=email
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	{
		testresults=true
	}
	else
	{		
		testresults=false
	}
	return (testresults)
}
function isEmpty(elem, helperMsg){
	if(elem.value.length > 0){
				return true;
	}else{
	alert(helperMsg);
		elem.focus(); // set the focus to this input
	return false;
    }
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z/ ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}

}

function displayTerms() 
{
		divObj = document.getElementById('termsuse');		
		//divObj.style.display = '';			
		divObj.style.visibility = 'visible';			
	
}
function closeMessage() 
{
		divObj = document.getElementById('termsuse');		
		divObj.style.visibility = 'hidden';	
		checkboxObj = document.getElementById('checkbox');		
		checkboxObj.checked = true ;
		
		//divObj.style.display = 'none';			
	
}
/* example to use
function formValidator()
{


// Make quick references to our fields
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	var country = document.getElementById('country');
	var timezone = document.getElementById('timezone');
	var prob = document.getElementById('prob');		
	
	// Check each input in the order that it appears in the form!
if(isAlphabet(name, "Please enter a valid first name")){
if(isEmpty(name, "Please enter your first name")){
if(emailValidator(email, "Please enter a valid email address")){
if(isEmpty(timezone, "Please enter your Time Zone")){
if(isEmpty(prob, "Please enter a Query")){
if(!document.form_query.checkbox.checked){alert("Please Read the guidelines and check the box below"); 
 return false;} 

document.form_query.submit();
return true;
}
}
}
}
}
return false;
}
*/