function toggle(a,b,curItem,usertyp){ // show/hide forms based on radio button click
	
	turnOn = document.getElementById(a);	
	turnOff = document.getElementById(b);

	if (usertyp != '') {
	
	window.location.href = "smpl_custInfo_action.cfm?usertype="+ usertyp +"&zip=" + userInfo.zip.value;
	}
	
    else 
		{
		if(turnOn.style.display == "none"){	// if a is hiding, show it
			turnOn.style.display = 'inline';
			turnOn.style.visibility = 'visible';
		}else{ // if a is showing, hide it and uncheck curitem
			
			turnOn.style.display = 'none';
			turnOn.style.visibility = 'hidden';
			curItem.checked = false;
		}
		turnOff.style.display = 'none';
		turnOff.style.visibility = 'hidden';
	}
}

function extractIFrameBody(iFrameEl) {  // get the body of our iframe

  var doc = null;
  if (iFrameEl.contentDocument) { // For NS6
    doc = iFrameEl.contentDocument; 
  } else if (iFrameEl.contentWindow) { // For IE5.5 and IE6
    doc = iFrameEl.contentWindow.document;
  } else if (iFrameEl.document) { // For IE5
    doc = iFrameEl.document;
  } else {
    alert("Error: could not find sumiFrame document");
    return null;
  }
  return doc.body;
}





function checkThis(theField,theForm, server){  // check zip field, execute server call
		
	numChars = theField.value.length;
	if(numChars > 4){
	
		document.forms[theForm.name].school.options.length = 0;
		document.forms[theForm.name].school.options[0] = new Option("Loading...","Loading...",false,false);
	
		//get data from server and send it to the iframe		
		theHiddenFrame = document.getElementById("theFrame");
		//theHiddenFrame.src = "schoolfinder.cfm?zip=" + theField.value;
		theHiddenFrame.src = "http://" + server + "/schlfinder_snippet/localschoolfinder.cfm?zip=" + theField.value;	
	
			
		// temporary fix to develop with data on same server
		// theHiddenFrame = $("theFrame");
		//$("iFrame").src = "recordlist.txt";
		
		// hide any other forms showing (if user goes back and changes zip after clicking a radio button)
		formB = document.getElementById("alpha");
		formC = document.getElementById("beta");

		formB.style.visibility = "hidden";
		formC.style.visibility = "hidden";

		
		
		// uncheck corresponding radios
		for(q=0;q<theForm.schoolToggle.length;q++){ 
			theForm.schoolToggle[q].checked=false;
		}
		
		
		//theOutputDiv = document.getElementById("response");  
		//theOutputDiv.innerHTML = '<b class="loader">LOADING</b>';
	}
}


function handleResponse(doc)
{
	showit();	
}

function showit(){  // populate the dropdown
	browser=getBrowser();
	os=getOS();
	
	if(os == "Mac" && browser == "IE"){		
		var serverResponse = extractIFrameBody(document.frames["theFrame"]).innerHTML;
	}else{		
		// This will *NOT* work if file contained in iFrame is not on the same server as our script
		robert = document.getElementById("theFrame");
		var serverResponse = extractIFrameBody(robert).innerHTML;	
	}
	//theOutputDiv = document.getElementById("foot");
	//theOutputDiv.innerHTML = serverResponse;
		
	rawRecords = serverResponse.replace(/record=/g,"");
	rawRecords = rawRecords.replace(/&amp;/g,"&");
	recordList = rawRecords.split(";");


	//theOutput = "";
	//theOutput = '<select type="multiple" class="selectbox" name="school" size="8" autocomplete="off" style="width:350px;" onclick="populateHiddenForm(this.value,this.form);">';
	//theOutput = '<select name="school" onchange="populateHiddenForm(this.value,this.form);">';
	// multi select does not work in mac ie
	
	//clear existing options
	document.forms['userInfo'].school.options.length = 0;
	
  /*added by Jessie Lin*/
  /*give an error message if no school found*/
  
	if (recordList.length == 1)
	  { 
	  document.forms['userInfo'].school.options[0] = new Option("Sorry! No record found!","No Record",false,false);
	  }
	
	else {
	
	   for(i=0;i<recordList.length;i++){ 
		   if(recordList[i] != ""){
			   record = recordList[i];
			   items = record.split(",");
			   for(j=0;j<items.length;j++){ 
				
				   if(j == 2){
					   //theOutput +=  '<option value="' + record + '">' + items[j] + '</option>';
					
					   document.forms['userInfo'].school.options[i] = new Option(items[j],record,false,false);
					
				  }
			  }
		  }
	   }
	}
	//theOutput += '</select>';
	//theOutputDiv = document.getElementById("response");  
	//theOutputDiv.innerHTML = theOutput;
	
	
}


function uncheckRadio(field){ // uncheck the radio buttons on page load/reload
	for(i=0;i<field.length;i++){
		field[i].checked=false;
	}
}


function populateHiddenForm(data,theForm){ 
	hiddenOutput = "";
	currentRecord = data;
	currentItems = currentRecord.split(",");
	for(k=0;k<currentItems.length;k++){ 
		if(k == 0){
			//hiddenOutput += '<input type="hidden" name="curPid" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curPid.value = currentItems[k];					
		}
		if(k == 1){					
			//hiddenOutput += '<input type="hidden" name="curQed" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curQed.value = currentItems[k];
		}
		if(k == 2){
			//hiddenOutput += '<input type="hidden" name="curInstitution_name" value="' + currentItems[k] + '">';	
			document.forms['userInfo'].curInstitution_name.value = currentItems[k];				
		}
		if(k == 3){					
			//hiddenOutput += '<input type="hidden" name="curInstitution_type" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curInstitution_type.value = currentItems[k]; 
		}
		if(k == 4){
			//hiddenOutput += '<input type="hidden" name="curAddress1" value="' + currentItems[k] + '">';	
			document.forms['userInfo'].curAddress1.value = currentItems[k];				
		}
		if(k == 5){					
			//hiddenOutput += '<input type="hidden" name="curAddress2" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curAddress2.value = currentItems[k];
		}
		if(k == 6){					
			//hiddenOutput += '<input type="hidden" name="curCity" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curCity.value = currentItems[k];
		}
		if(k == 7){
			//hiddenOutput += '<input type="hidden" name="curState" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curState.value = currentItems[k];					
		}
		if(k == 8){					
			//hiddenOutput += '<input type="hidden" name="curZip" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curZip.value = currentItems[k];
		}
		if(k == 9){
			//hiddenOutput += '<input type="hidden" name="curCounty" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curCounty.value = currentItems[k];					
		}
		if(k == 10){					
			//hiddenOutput += '<input type="hidden" name="curPhone" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curPhone.value = currentItems[k];
		}
		if(k == 11){					
			//hiddenOutput += '<input type="hidden" name="curPhone" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curFax.value = currentItems[k];
		}
		if(k == 12){					
			//hiddenOutput += '<input type="hidden" name="curPhone" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curDistrict_pid.value = currentItems[k];
		}
		if(k == 13){					
			//hiddenOutput += '<input type="hidden" name="curPhone" value="' + currentItems[k] + '">';
			document.forms['userInfo'].curDistqed.value = currentItems[k];
		}
		
		
	}
	//hiddenForms = document.getElementById("hiddenFormInputs");
	//hiddenForms.innerHTML = hiddenOutput; 
	//alert(hiddenForms.innerHTML);
	
	// hide any forms showing
	formB = document.getElementById("alpha"); 
	formC = document.getElementById("beta");	
	formB.style.visibility = 'hidden';
	formB.style.display = 'none';
	formC.style.visibility = 'hidden';
	formC.style.display = 'none';
	
	// deselect any selected radios
	for(q=0;q<document.forms['userInfo'].schoolToggle.length;q++){ 
		document.forms['userInfo'].schoolToggle[q].checked=false;
	}
	
}