function processForm(obj,id){
	if(id == 'supercategoryid'){
		if(obj.value=='' || document.getElementById('degreetypeid').value=='')
			return false;
		else
			document.form1.submit();
	}
	else if(id == 'parentdegreeid'){
		if(obj.value=='' || document.getElementById('supercategoryid').value=='' || document.getElementById('degreetypeid').value=='')
			return false;
		else
			document.form1.submit();
	}
	else{
		if(obj.value=='')
			return false;
		else
			document.form1.submit();
	}
}

function IsNumeric(input)
{
	return (input - 0) == input && input.length > 0;
}

function zipProcess(obj,zip){
	if(!IsNumeric(zip) || zip.length > 5){
		obj.value = '';
	} else if (zip.length == 5){
		makePOSTRequest("ThreeSelectsRelated/ThreeSelectsAjax.cfm","zipcode="+zip+"&action=getDegreeTypes",zipcodeCallbackHandler);
		return false;
	}
}

function zipBlur(obj){
	var zip = obj.value;
	if (!IsNumeric(zip) && zip.length ==0){
		obj.value = 'Enter your Zip Code';
		obj.style.fontWeight = "Bold";
		obj.style.color = "Red";
	}
}

function degreeTypeProcess(obj){
	makePOSTRequest("ThreeSelectsRelated/ThreeSelectsAjax.cfm","degreeTypeID="+obj.value+"&action=getSuperCategories",degreeTypeCallbackHandler);
}

function superCategoryProcess(obj){
	degreeTypeID = document.getElementById("degreetypeid").value;
	makePOSTRequest("ThreeSelectsRelated/ThreeSelectsAjax.cfm","supercategoryid="+obj.value+"&action=getParentDegrees&degreeTypeID="+degreeTypeID,superCatCallbackHandler);
}

/// AJAX Functions ///
var http_request = false;

   function makePOSTRequest(url, parameters,callbackHandler) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
     
      http_request.onreadystatechange = callbackHandler;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   
   
   function zipcodeCallbackHandler(){
	   if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            
			var degreeTypeContainer = document.getElementById("degreeTypeContainer");
			degreeTypeContainer.innerHTML = http_request.responseText;
			degreeTypeContainer.style.display = '';
			//hide super category dropdown
			document.getElementById("superCategoryContainer").style.display = 'none';
			//hide parent degree dropdown
			document.getElementById("parentDegreeContainer").style.display = 'none';
			//set the focus on the degree type dropdowsn
			document.getElementById("degreetypeid").focus();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function degreeTypeCallbackHandler(){
	   if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //do your stuff here
			//alert(http_request.responseText);
			var degreeTypeContainer = document.getElementById("superCategoryContainer");
			degreeTypeContainer.innerHTML = http_request.responseText;
			degreeTypeContainer.style.display = '';
			//hide parent degree dropdown
			document.getElementById("parentDegreeContainer").style.display = 'none';
			document.getElementById("supercategoryid").focus();
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
    function superCatCallbackHandler(){
	   if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //do your stuff here
			//alert(http_request.responseText);
			var degreeTypeContainer = document.getElementById("parentDegreeContainer");
			degreeTypeContainer.innerHTML = http_request.responseText;
			degreeTypeContainer.style.display = '';
			document.getElementById("parentdegreeid").focus();
         } else {
            alert('There was a problem with the request.');
         }
      }
	}
