function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

//Create Request Object
	var xmlObject = createXmlHttpRequestObject();

function validate() {
	//check a field to make sure it has something filled in
	if(document.newsletter.txtFName.value == '' || document.newsletter.txtFName.value == 'First Name') {
		alert('Please fill out textFieldName.');
		document.newsletter.txtFName.focus();
		return false;
	}
	//offer the person the option of leaving a field blank
	//if(document.newsletter.txtLName.value == '' || document.newsletter.txtFName.value == 'Last Name') {
	if(document.newsletter.txtLName.value == '') {
		alert('Please fill out textFieldName.');
		document.newsletter.txtLName.focus();
		return false;
	}

	//check email field (to make sure it's not blank)
	//if(document.newsletter.txtEmail.value == '' || document.newsletter.txtEmail.value == 'email@host.com' ) {
	if(document.newsletter.txtEmail.value == '') {
		alert('You must enter in your email address.');
		document.newsletter.txtEmail.focus();
		return false;
	} else {
	//Now check if email is valid
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.newsletter.txtEmail.value))) {
			alert("A valid email address has not been entered.\nPlease try again.");
			document.newsletter.txtEmail.focus();
			return false;
		}
	}
	//if we made it this far - then everything must be filled out okay
	var fileStr = 'processNewsLetter.php?fname=' + document.newsletter.txtFName.value + '&lname=' + document.newsletter.txtLName.value + '&email=' + document.newsletter.txtEmail.value;
	alert('File string =' + fileStr);
	ajaxReadNewsLetter(fileStr);

} // end validate function

function ajaxReadNewsLetter(file){	
	
	//proceed only if the HTTP request object isn't busy
	//if (xmlObject.readyState == 4 || xmlObject.readyState == 0)
	//{
		alert("About to call open method with file = " + file);
		xmlObject.open ("GET", file, true);
		alert ("Returned from xmlObject.open call");
		xmlObject.onreadystatechange = processNewsLetter;
		alert ("Returned from xmlObject.onreadystatechange call to processNewsletter");
	    xmlObject.send (null);
	//}
	//else
		//if the connection is busy, try again after 1 second
		//setTimeout('ajaxReadNewsLetter(file)'),1000);
}

function processNewsLetter(){			
 // move forward only if the transaction has completed
  if (xmlObject.readyState == 4) 
  {
	alert('xmlObject.readyState == ' + xmlObject.readyState);
	//alert('xmlObject.statusText == ' + xmlObject.statusText);
    // status of 200 indicates the transaction completed successfully
    if (xmlObject.status == 200) 
    {
      
	   // extract the XML retrieved from the server
      xmlResponse = xmlObject.responseXML;
      alert(xmlObject.responseText);
      // obtain the document element (the root element) of the XML structure
      xmlDocumentElement = xmlResponse.documentElement;
      // get the text message, which is in the first child of the the document element
      txtResponse = xmlDocumentElement.firstChild.data;
      alert('Response = ' + txtResponse);
      // update the client display using the data received from the server
      //document.getElementById("divMessage").innerHTML = '<i>' + helloMessage + '</i>';
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlObject.statusText);
    }
  }
}

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}