//function to remove spaces from front and end of string
function trimAll(sString){

    while (sString.substring(0,1) == ' '){
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' '){
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}


//function to check special character in string
function checkSpecialChars(parValue){ //alert(parValue);
     var receivedValue = parValue;
  //   var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~`";   
    var iChars = "$%^+={}~\“\”\‘\’`";
     //var iChars = "\\\';";
     for (var i = 0; i < receivedValue.length; i++) {
        if (iChars.indexOf(receivedValue.charAt(i)) != -1) {
            //alert(false);
            return false;              	
      	}
    }
    //alert(true);
    return true;    
}


// Function for email check.
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var lastdot=str.lastIndexOf(dot)
		
    temp = (str.substring(lastdot+1,lstr));
		//alert(temp);
		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(isNaN(temp))
		 {
        return true;
     }
     else
     {
        return false;
     }

 		 return true					
}


function ValidateEntries(formid) {
  var email  = document.getElementById('email').value;
  var frmObj = document.getElementById(formid);
  
  var error_msg = '';
  
  /* check Email is blank or not */
  if(trimAll(email) == '') {
    error_msg += "Enter Email address to 'Subscribe Newsletter'.\n";
  }
  /* check Email format */
  if(trimAll(email) != "") {
    /* if(checkSpecialChars(email)==-1){
	 error_msg += "\n Email can not take special characters(\\\';/).";
    } */
    if(echeck(email) != true)
    {
	    error_msg += "Please enter valid email address.";
    }
  }

  if(error_msg != "") {
    alert (error_msg);
    document.getElementById('email').focus();
    return false;
  }
  else {
    document.getElementById(formid).submit();
    /*return true;*/
  }

}