 
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() {
	// check if it is a valid email adress before posting
	var sendMail = true;
	if(document.getElementById("txtname").value==""){
		sendMail = false;
		alert("Du har inte fyllt i någon epost adress.");
		document.getElementById("txtname").select();
	}else if(!checkmail(document.getElementById("txtname"))){
		sendMail = false;
	}

	if(sendMail==true) {
		var getdate = new Date();  //Used to prevent caching during ajax call
		if(xmlhttp) { 
			var txtname = document.getElementById("txtname");
			xmlhttp.open("POST","newsletter/send.php",true); //calling testing.php using POST method
			xmlhttp.onreadystatechange  = handleServerResponse;
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlhttp.send("txtname=" + txtname.value); //Posting txtname to PHP File
		}
	}
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element 
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
  /***********************************************
        * Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
        * This notice must stay intact for legal use.
        * Visit http://www.dynamicdrive.com/ for full source code
        ***********************************************/
        
        var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
        
        function checkmail(e){
            var returnval=emailfilter.test(e.value)
            if (returnval==false){
                alert("Var vänlig skriv in en existerande e-post adress.")
                e.select()
            }
            return returnval
        }
