// global "req" (request) and "pos" (POST) is required to pass among xmlHttpRequest functions
var req; // branch for getting information
var pos; // branch for posting information
function loadXMLPosDoc(url,posData) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        pos = new XMLHttpRequest();
        pos.onreadystatechange = processPosChange;
        pos.open("POST", url, false);
		pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        pos.send(posData);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        pos = new ActiveXObject("Microsoft.XMLHTTP");
        if (pos) {
            pos.onreadystatechange = processPosChange;
            pos.open("POST", url, false);
			pos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            pos.send(posData);
        }
    }
}

function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function grabXML(tagName) {
	return req.responseXML.documentElement.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
}

function grabPosXML(tagName) {
	return pos.responseXML.documentElement.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
}

function processPosChange() 
{
    // page loaded "complete"
    if (pos.readyState == 4) {
        // page is "OK"
        if (pos.status == 200) {
		if ( grabPosXML("posStatus") == 'NOTOK' ) { 
			alert('There were problems Sending Email. Please check back in a couple minutes');
		} else {
			// confirmation
			alert('Temporarily making some changes to this form. If you see this alert, you caught me testing live!');
		}
	} 
	else {
		alert('The Mail server is failing at this time (Error !200). Please try back at another time.');
	}
    }
    else {
		alert('The Mail server is failing at this time (Error !4). Please try back at another time.');
    }
}
