
var req11; //variable used to establish an XML Http Request object

//this javascript function establishes a socket connection in which  
//php script communication takes place - it passes user input and 
//communicates back XML document results built by the php script
function loadXMLDoc11(url) {
		    // branch for native XMLHttpRequest object
		    if (window.XMLHttpRequest) {
		    	
		        req11 = new XMLHttpRequest();
		        req11.onreadystatechange = processReqChange11;
		        req11.open("GET", url, true);
		        req11.send(null);
		        
		    // branch for IE/Windows ActiveX version
		    } else if (window.ActiveXObject) {
		    	
		        req11 = new ActiveXObject("Microsoft.XMLHTTP");
		        
		        if (req11) {
		        	
		            req11.onreadystatechange = processReqChange11;
		            req11.open("GET", url, true);
		            req11.send();
		        }
		        
		    }
		    
		}
		
		
//this JavaScript function processes the response from the php
//script - basically it parses the XML response into useable strings 		
function processReqChange11() {
    // only if req shows "complete"
    if (req11.readyState == 4) {  //redyState of 4 siginifies a completed script
    	
        // only if "OK"
        
        if (req11.status == 200) {  //status of 200 means that we have no errors in communication
    	 	
        	response = req11.responseXML.documentElement;
	      	id = response.getElementsByTagName('result')[0].firstChild.data;
	      	
	      	if(id > 0)
	      		alert("Thank You, your email address has been received.");
	      		//document.getElementById('email').value = "";
	      	else
	      		alert("We are sorry but you email address could not be processed, please submit again.");
      
        } else {  //if status not 200 then we need to alert the error
            alert("There was a problem submitting the data:\n" + req11.statusText);  
        }
    } //end our "only process when finished" check
} 

	function set_email(email) {
		//alert(email);
		var emailok = "";
		var the_at = email.indexOf("@");
		var the_dot = email.lastIndexOf(".");
		var a_space = email.indexOf(" ");
		
		
		if ((the_at != -1) && (the_at != 0) && (the_dot != -1) && (the_dot > the_at +1) && (the_dot < email.length -1) && (a_space == -1)){
			
	 		url = '../setudtemailajax.php?v='+email;  
	    	loadXMLDoc11(url); 
		
		} else {
			
			alert("Your email address is not in the correct format.\n");
			document.forms['udtemail'][email].focus();
		}
	}	
	
