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("innn1")
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("innn2")
            alert("Invalid E-mail ID")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
         alert("innn3")
            alert("Invalid E-mail ID")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
         alert("innn4")
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
         alert("innn5")
            alert("Invalid E-mail ID")
            return false
         }
        
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }

          return true			
}

function apply_Validation() 
{ 
		var hh = document.sunlexis;
		if(hh.txtFirstName.value=="")
		{
			alert("Please enter your Name.");
			hh.txtFirstName.focus();
			return false;
		}
		if(hh.txtEmail.value=="")
		{
			alert("Please enter Email address.");
			hh.txtEmail.focus();
		return false;
		}
	
		if (echeck(hh.txtEmail.value)==false)
		{
			alert("Invalid email Address.");
			hh.txtEmail.focus();
		    return false;
		}
		if(hh.query.value==""){
		alert("Please enter your query.");
		hh.query.focus();
		return false;
	}
	return true;
}

function apply_Validation_bottom() 
{ 
		var hh = document.qsearch;
		if(hh.txtFirstName.value=="" || hh.txtFirstName.value=='Name')
		{
			alert("Please enter your Name.");
			hh.txtFirstName.focus();
			return false;
		}
		if(hh.txtEmail.value=="" || hh.txtEmail.value=='Email')
		{
			alert("Please enter Email address.");
			hh.txtEmail.focus();
		return false;
		}
	
		if (echeck(hh.txtEmail.value)==false)
		{
			alert("Invalid email Address.");
			hh.txtEmail.focus();
		    return false;
		}
		if(hh.query.value=="" || hh.query.value=="Query"){
		alert("Please enter your query.");
		hh.query.focus();
		return false;
	}
	return true;
}

function Comp_Validation() 
{ 
        var hh = document.frm_comp_pro;
        if(document.getElementById('msg').style.display=='')
              document.getElementById('msg').style.display='none';
        if(trimspace(hh.user_name.value)=="" || hh.user_name.value=="Name")
        {
            alert("Please Enter Name.");
            hh.user_name.focus();
            
            return false;
        }
        else if(trimspace(hh.user_email.value)=="" || hh.user_email.value=="Email")
        {
            alert("Please Enter Email address.");
            hh.user_email.focus();
            return false;
        }
       
        else if (validateEmail(trimspace(hh.user_email.value))==false)
        {
            alert("Invalid Email Address."); 
            hh.user_email.focus();
            return false;
        }
        else if(trimspace(hh.company.value)=="" || hh.company.value=='Company')
        {
            alert("Please Enter Company.");
            hh.company.focus();
            return false;
        }
        else if(trimspace(hh.reason.value)=="" || hh.reason.value=='Reason')
        {
            alert("Please Enter Reason.");
            hh.reason.focus();
            return false;
        }
      
        name = hh.user_name.value;
        email = hh.user_email.value;
        company = hh.company.value;
        reason = hh.reason.value;
        var url = 'pdf_request.php?name='+name+"&email="+email+"&company="+company+"&reason="+reason;
       
        process_ajax_register(url, 'msg')
        return false;
}
function validateEmail(elementValue){   
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
    
   return emailPattern.test(elementValue);   
 }
function trimspace(str){

 if (str == ''){
    return '';
  }
  var len= str.length;
  if (len != 0)
  {
  for (var i=0;i<len;i++)
  {
    if(str.indexOf(" ")==0)
      str=str.substring(1,len);
  }
  strtrim=str;
  return strtrim;
  }
}
