var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function subSurvey(f,l,p,z,e,send) {
   	createXMLHttpRequest();
   // var queryString = "/mtcvb07/surveyAJAX.cfm?fname=" + f + "&lname=" + l + "&phone=" + p + "&zip=" + z + "&email=" + e + "&send=" + send + "&homesurv=1" + "&timeStamp=" + new Date().getTime();
   var queryString = "/surveyAJAX.cfm?fname=" + f + "&lname=" + l + "&phone=" + p + "&zip=" + z + "&email=" + e + "&send=" + send + "&homesurv=1" + "&timeStamp=" + new Date().getTime();
	xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", queryString, true);
    xmlHttp.send(null);
}
    
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() {
	var newText;
	//var suc =  xmlHttp.responseText;
	var suc = parseInt(xmlHttp.responseText);
	var parDiv = document.getElementById('survDiv');
	var mainDiv = document.getElementById('survey2');
	
	if(suc == "1"){
		var survWin = window.open('http://tourvey.com/eSurvey/default.aspx?CID=TU&MID=1&SID=W1C', 'newWin',  'scrollbars,resizable,dependent,width=640,height=550,left=50,top=50');
		parDiv.style.display='none';
	} else {
		newText = "<br><br><br><br><br><br><br><br>";
		newText += "&nbsp;&nbsp;&nbsp;&nbsp;There was a problem with your Registration!";
		mainDiv.innerHTML = newText;
	}
	/*var newText;
	parDiv = document.getElementById('survDiv');
	parDiv.style.width = "840px";
	parDiv.style.height = "640px";
   	mainDiv = document.getElementById('survey2');
	mainDiv.className = "survey2b";
	mainDiv.innerHTML = "";
	newText = '<iframe name="MTCVB Survey" width="800" height="550" scrolling="auto" src="http://benchmark.rpts.tamu.edu/survey/default.aspx?CID=TACVB&SID=1"></iframe>';
	newText += '<br><br><div align="center"><input type="button" onClick="slideBack(\'survDiv\');" value="close window"></div>';
	//alert(newText);
	mainDiv.innerHTML = newText; */
}

function closeDiv(){
	document.getElementById('survey2').style.display='none';
}
