// Builds a post and submits an Ajax request

// Get all the variables from the form for the post
function buildPOST(theFormName) {
    theForm = document.forms[theFormName];
    var qs = ''
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].name!='') {
            var name = theForm.elements[e].name;
            qs+=(qs=='')?'':'&'
            qs+= name+'='+escape(theForm.elements[e].value);
        }
    }
    qs+="\n";
    return qs
} 

// use Ajax to get the results
function getResults(formName, myURL, responseLayer, googleGoal) {
	
	//var myURL = "http://www.veritasprep.com/predictor/selector.php";
	var ajax; 
	var params = buildPOST(formName);
	
	/* try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {
    alert("Permission UniversalBrowserRead denied.");
   }*/
   // Check to see what form of an HTTP request we have to use
    if (window.XMLHttpRequest) {                     // Does this browser have an XMLHttpRequest object?
      ajax=new XMLHttpRequest();                    // Yes -- initialize it.
   } else {                                         // No, try IE style
      ajax=new ActiveXObject("Microsoft.XMLHTTP");  // Active X
   }                                                // 
   if (ajax==null) {                                // Can't initialize Ajax...
      alert("Your browser doesn't support AJAX.");  // Sorry msg.                                               
      return false                                  // Return false, couldn't set up ajax
   }
		
	
	var myURL = window.location.protocol + "//" + window.location.host  + myURL;	

	ajax.open("POST", myURL, true);
	
	//Send the proper header information along with the request
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);
	ajax.setRequestHeader("Connection", "close");

			
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			writeWidgetToDiv(ajax.responseText, responseLayer, googleGoal);
		}
	}
	
	
	ajax.send(params);
	
}

// function to display the data
function writeWidgetToDiv(textToWrite, theLayer, googleGoal) {
	var theDiv = document.getElementById(theLayer);
	theDiv.innerHTML = textToWrite;
	setGoogleGoal(googleGoal);
}


function setGoogleGoal(theGoal) {

        theGoal = "/" + theGoal;     	
		pageTracker._trackPageview(theGoal);	
}