//TWC
//05/01/2008


/***********************************************************************************************************

			get XML Object function

***********************************************************************************************************/
var xmlHttp;

//this function creates the XMLHttp Object
function GetXmlHttpObject()
{
var x=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  x=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    x=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    x=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return x;
}



function getContent(page_id, divID)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	alert ("Your browser does not support AJAX!");
	return;
	} 
	var url=page_id+".html";
	url=url+"&sid="+Math.random();
	alert(url)
	xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		{
		document.getElementById(divID).innerHTML=xmlHttp.responseText;
		}
		}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//function will show "loading..." message and GIF
function showLoader(divID,divIDh1,divIDh2,divIDh3,divIDh4, divIDh5, divIDh6)
{
	document.getElementById(divID).style.display="block";
	document.getElementById(divID).innerHTML='<p style="margin-bottom: 6px; margin-top: 6px;"><small>loading...</small><br><img src="lookups/loading.gif"></p>'
	if (divIDh1)
	{
		document.getElementById(divIDh1).style.display = "none";
	}
	if (divIDh2)
	{	
		document.getElementById(divIDh2).style.display = "none";
	}	
	if (divIDh3)
	{	
		document.getElementById(divIDh3).style.display = "none";
	}	
	if (divIDh4)
	{	
		document.getElementById(divIDh4).style.display = "none";
	}	
	if (divIDh5)
	{	
		document.getElementById(divIDh5).style.display = "none";
	}
	if (divIDh6)
	{	
		document.getElementById(divIDh6).style.display = "none";
	}	
}

function showDIV(divID)
{
	document.getElementById(divID).style.visibility="visible";
	document.getElementById(divID).style.display="block";

}

function hideDIV(divID)
{
	document.getElementById(divID).innerHTML="";
	document.getElementById(divID).style.display="none";
	document.getElementById(divID).style.visibility="hidden";
}

/*this function is used to prevent the user from striking the enter key when filling
	out a form*/
function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}


/************************************************************************************************************

			DATA FUNCTIONS
			
************************************************************************************************************/			

function getData(dataName,divID,menu1ID,menu2ID,prog_type,menu3ID,menu4ID,menu5ID, showAll)
{ 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="lookups/getData.asp";
url=url+"?dataName="+dataName;
url=url+"&menu1ID="+menu1ID;
url=url+"&menu2ID="+menu2ID;
url=url+"&menu3ID="+menu3ID;
url=url+"&menu4ID="+menu4ID;
url=url+"&menu5ID="+menu5ID;
url=url+"&prog_type="+prog_type;
url=url+"&showAll="+showAll
url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var str=xmlHttp.responseText
				if(str.search(/error/) != -1)
				{
					var start=str.search(/&/)
					alert(str.slice(start+1));
					document.getElementById(divID).innerHTML='';
				}
				else
				{				
					document.getElementById(divID).innerHTML=xmlHttp.responseText;
				}
			}
		}
xmlHttp.open("GET",url,true);
xmlHttp.send(url);
}



/*this function takes a form object and returns a queryString*/
function makeQuery(theForm) {
    //initialize the querystring
    var queryString = "";
    
    var radios = new Array();
    var selects = new Array();
    //loop through all the elements
    for(i=0;i<theForm.elements.length;i++) {
        //get the current element
        elem = theForm.elements[i];

        switch(elem.type) {
            case "text":
            case "textarea":
            case "hidden":
            case "password":
                queryString += escape(elem.name) + 
                    "=" + escape(elem.value) + "&";
                break;

            //if it's a checkbox
            case "checkbox":
                queryString += escape(elem.name) + "=";
                if(elem.checked) queryString += escape(elem.value);
                queryString += "&";
                break;

            //radio element
            case "radio":

                if(elem.checked) {
                    queryString += escape(elem.name) + "=" + 
                    escape(elem.value) + "&";
                    radios[elem.name] = true;
                }
                else if(!radios[elem.name]) { radios[elem.name] = false; }
                break;

            //a drop down menu that allows only one option to be selected
            case "select-one":
                queryString += escape(elem.name) + "=";
                for(x=0;x<elem.options.length;x++) {
                    if(elem.options[x].selected) { 
                        queryString += elem.options[x].value; }
                }
                queryString += "&";
                break;            
        }
    }
    
    var elemname;
    for(elemname in radios) {
        if(!radios[elemname]) { 
            queryString += escape(elemname) + "=" + "&"; }
    }
    
    return queryString;
}


function getTSData(dataName,divID,prog_type,dataID1, dataID2, dataID3, dataID4)
{ 

	if (dataID1 == ""){
		document.getElementById("testname").visibility = "hidden";
		hideDIV("divResults");
		hideDIV("testcity");
		hideDIV("sites_returned");
		document.getElementById("testType").value="";
	} 
	else{
		showDIV("testname");
		showDIV("divResults");
		showDIV("testcity");
		showDIV("sites_returned");		
		document.getElementById("testcity").innerHTML= "<small>loading...</small><br><img src='lookups/loading.gif' alt='Loading...'>"		
		document.getElementById("divResults").innerHTML= "<small>loading...</small><br><img src='lookups/loading.gif' alt='Loading...'>"
		
		document.getElementById(divID).innerHTML='';
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		alert ("Your browser does not support AJAX!");
		return;
		} 
		var url="lookups/getData.asp";
		url=url+"?dataName="+dataName;
		url=url+"&prog_type="+prog_type;
		url=url+"&menu1ID="+dataID1;
		url=url+"&menu2ID="+dataID2;
		url=url+"&menu3ID="+dataID3;
		url=url+"&menu4ID="+dataID4;
		url=url+"&sid="+Math.random();
	//	alert(url)
				xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
					{
						var str=xmlHttp.responseText
						if(str.search(/error/) != -1)
						{
							var start=str.search(/&/)
							alert(str.slice(start+1));
							document.getElementById(divID).innerHTML='';
							//document.getElementById(divID).innerHTML=xmlHttp.responseText;
						}
						else
						{	
							if(dataName=="testcity"){
								document.getElementById("sites_returned").style.display="block";
								document.getElementById('testname').style.display="block";
								document.getElementById('testcity').style.display="block";							
								document.getElementById('divResults').style.display="block";
							}
							document.getElementById(divID).innerHTML=xmlHttp.responseText;
						}
					}
				}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(url);
	}
}


function getResults(stateName, cityName, testType)
{ 
	if (document.getElementById('testType')){
		testType = document.getElementById('testType').value;
	}
	if (stateName == "") {
		document.getElementById("sites_returned").style.display="none";
		document.getElementById('testname').style.display="none";
		document.getElementById('testcity').style.display="none";							
		document.getElementById('divResults').style.display="none";	
	} else {
		document.getElementById("divResults").innerHTML= "<small>loading...</small><br><img src='lookups/loading.gif' alt='Loading...'>"		
	}

//	document.getElementById(divID).innerHTML='';
	xmlHttpRes=GetXmlHttpObject();
	if (xmlHttpRes==null)
	{
	alert ("Your browser does not support AJAX!");
	return;
	} 
	var url="lookups/getResults.asp";
	url=url+"?stateName="+stateName;
	url=url+"&cityName="+cityName;
	url=url+"&testType="+testType;
			xmlHttpRes.onreadystatechange=function()
			{
				if(xmlHttpRes.readyState==4)
				{
					var str=xmlHttpRes.responseText
					if(str.search(/error/) != -1)
					{
						var start=str.search(/&/)
						alert(str.slice(start+1));
						document.getElementById("divResults").innerHTML='';
					}
					else
					{	
						start_pos = str.search(/TT:/)+3;
						end_pos = str.search(/:ETT/);							
						total_sites = str.substr(start_pos,end_pos-3);
						document.getElementById("sites_returned").innerHTML="Total Sites Returned:"+total_sites;
						document.getElementById("divResults").innerHTML=str.substr(end_pos+4,str.length);
					}
				}
			}
	xmlHttpRes.open("GET",url,true);
	xmlHttpRes.send(url);

}



function socSubmit(cn, si, sn, sad,sc,ss,sz){
	if (cn==""){
		alert("Please enter your name.")
		document.getElementById('con_name').focus();
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="lookups/socSubmit.asp?";
	url=url+"cn="+cn;
	url=url+"&schID="+si;
	url=url+"&sn="+sn;	
	url=url+"&sad="+sad;
	url=url+"&sc="+sc;
	url=url+"&ss="+ss;
	url=url+"&sz="+sz;			
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4)
			{
			var str=xmlHttp.responseText
			if(str.search(/error/) != -1)
			{
				var start=str.search(/&/)
				alert(str.slice(start+1));
			}
			else
			{				
				document.getElementById('sch').innerHTML='<table><tr><td valign="top">Your request for the complimentary copy of <em>Staying on Course</em> has been submitted to Duke TIP.</td>';
				document.getElementById('sch').innerHTML=document.getElementById('sch').innerHTML+'<td valign="top" align="right"><span style="z-index:100;cursor:pointer; float:right;" onClick="closeSch();"><img src="../../assets/images/ui/close.gif" alt="Close"></img>Close</span></td></tr>';
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(url);
}

function incorrectSubmit(f,nl,n2){
	if (f){
		if (!nl){
			alert('You are being taken to a form where you can update the school contact information, and request a complimentary copy of Staying on Course.');	
		}
		else{
			alert('You are being taken to a form where you can enter your school contact information, and request a complimentary copy of Staying on Course.');	
		}
		document.getElementById('sch').style.display='none';
		f.method="POST"
		f.action="../../forms/schoolUpdateform.asp?u=4&c="+nl+"&d="+n2;
		f.submit();
	}
}

function closeSch(){
	document.getElementById('sch').style.display="none";
	location.reload(true);
}

	var divShowing;

	function toggleQT(divID,page){
		ypos="0px";	
		
		if(document.getElementById(divID).style.display == "block"){
			document.getElementById(divID).style.display="none";
		}
		else if(document.getElementById(divID).style.display == "none"){
			if (divShowing){
				document.getElementById(divShowing).style.display="none";
			}
			document.getElementById(divID).style.display="block";
			document.getElementById(divID).style.marginTop = ypos;
			divShowing=divID;
		}		
	}
	

	

	
