var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function optIn(e,f,l,fID,gID,send) {
   	createXMLHttpRequest();
	var url = "rfpOptIn.cfm?timeStamp=" + new Date().getTime();
    var queryString = "&fld_398=" + f + "&fld_399=" + l + "&fld_400=" + e + "&fld_401=" + send + "&formID=" + fID + "&groupID=" + gID;
	xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlHttp.send(queryString);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
           // document.getElementById("loading").style.display = 'none';
			parseResults();
			
        } else {
            alert('There was a problem retrieving the XML data:\n' + xmlHttp.statusText);
        }
    } else {
		//document.getElementById('btn_submit').value='Sending Information...';
		//document.getElementById('btn_submit').disabled=true;
	}
}

function parseResults() {
	//alert(xmlHttp.responseText);
	var newText;
	//var suc =  xmlHttp.responseText;
	var suc = parseInt(xmlHttp.responseText);
	var mainDiv = document.getElementById('rfpOpt');
	
	if(suc == "1"){
		newText = "<br><br>Thank you for your submission.<br>";
		mainDiv.innerHTML = newText;
	} else {
		newText = "<br><br>There was a problem with your submission!";
		mainDiv.innerHTML = newText;
	}
	
	
}

function closeDiv(){
	document.getElementById('survey2').style.display='none';
}
