// SMS JavaScript Document

var time_variable;
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") }// For Old Microsoft Browsers
   
   catch (e) {
	try {  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") }// For Microsoft IE 6.0+
     
    catch (e2) {  xmlHttp = false }// No Browser accepts the XMLHTTP Object then false
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); }//For Mozilla, Opera Browsers
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
 
function ajaxFunction() {
var d=document.nlsform;
if(isEmail(d.email.value)==false){alert("Please Enter Your E-Mail ID!"); d.email.focus(); return false;}

  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) { 
	var nl_email = document.getElementById("email").value;
    xmlhttp.open("POST","includes/post.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send("params=" + nl_email); //Posting txtname to PHP File 
  }
}
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.getElementById("succmsg").innerHTML=xmlhttp.responseText; //Update the HTML Form element 
	   document.getElementById("subsdiv").style.display='none';
	   document.getElementById("succmsg").style.display='block';
	   document.getElementById("email").value="Subscribe Newsletter";
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}

function isEmail( string ) {		
	if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;	else		return false;	}
