function createHTTPObject(){
	var oHTTP;
	if(window.XMLHttpRequest) {
    	try {
			oHTTP = new XMLHttpRequest();
        } catch(e) {
			oHTTP = false;
        }
    }
	else if(window.ActiveXObject) {
       	try {
        	oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		oHTTP = false;
        	}
		}
    }
    return oHTTP;
}

function loadTarget(sURL, divID) 
{
	//create a new HTTP request
    var oHTTP = createHTTPObject();
	    
	if(oHTTP) {
		document.getElementById(divID).innerHTML = "Loading...	";
		oHTTP.onreadystatechange = function()
	    { 
	    	processResponse(oHTTP, divID);
	    }
	    oHTTP.open('GET', sURL, true);
        oHTTP.send(null);
	}
	else
		alert('Cannot create request.');
}

function processResponse(oHTTP, divID)
{
	if (oHTTP.readyState == 4 || oHTTP.readyState=="complete") {
		if (oHTTP.status == 200) {
		   document.getElementById(divID).innerHTML = oHTTP.responseText;
		}
		else
		{
		   document.getElementById(divID).innerHTML = '<p>Error: cannot retrieve information from server.</p>';
		}
	}
}

function sendEmail(url, divID)
{
	//create a new HTTP request
    var oHTTP = createHTTPObject();
	    
	if(oHTTP) {
		document.getElementById(divID).innerHTML = "sending...";
		oHTTP.onreadystatechange = function()
	    { 
	    	processResponseEmail(oHTTP, divID);
	    }
	    oHTTP.open('GET', url, true);
        oHTTP.send(null);
	}
	else
		alert('Cannot create request.');
}

function processResponseEmail(oHTTP, divID)
{
	if (oHTTP.readyState == 4 || oHTTP.readyState=="complete") {
		if (oHTTP.status == 200)
		{
			if(oHTTP.responseText != "Error"){
				alert("Thank you for contacting us!");
				document.getElementById("txtName").value = "your name";
				document.getElementById("txtEmail").value = "your email";
				document.getElementById("txtComments").value = "your comments";
			}
			else
				alert("We are sorry, but there seems to be some problem. Please try again later.");
		}
		else
		{
			alert("We are sorry, but there seems to be some problem. Please try again later.");
		}
		 document.getElementById(divID).innerHTML = "<a href=\"javascript:;\" onclick=\"checkAndSendMail('txtName', 'txtComments', 'txtEmail')\">send</a>";
	}
}