 /**************************************************************
   
result.php by Milfson (milf@milfcz.com) 17.04.2004

Milfson added preselect(parameters...) to pre-populate dropdowns with default values.

Thanks for the code! - Brent.
Call to AJAX.php on line 82 --- Hector bojorquez 
***************************************************************/

// constants
var noValue = '-99';
// default values
var IDCounty = noValue;
var IDDistrict = noValue;
var IDCampus = noValue;
var IDCOMPARE = noValue; //HB
//selects disabled true/false
var boolEnabled = true;

// globals
var curOption = new Array();
var isLoaded = new Array();

function initLists(){
  // initialize lists
  emptyList( 'lstCounty' );
  emptyList( 'lstDistrict');
  emptyList( 'lstCampus' );
  jsrsExecute( 'select_rs.php', cbFillCounty, 'makeList');
}

function preselect(idCounty,idDistrict,idCampus,selectable,COMPARE){
  boolEnabled = selectable;
  IDCounty = idCounty;
  IDDistrict = idDistrict;
  IDCampus = idCampus;
  IDCOMPARE = COMPARE;
  initLists();
}

function lstCounty_onChange(){
  var val = this.options[this.selectedIndex].value;
    IDCounty = val;
    IDDistrict = noValue;
    IDCampus = noValue;

  if(val == noValue){
    selectOption( this.name, curOption[this.name] )
  } else {
    curOption[this.name] = val;
    // init dependent lists
    emptyList( 'lstDistrict' );
    emptyList( 'lstCampus');
    window.status = 'Loading Model Selections...';
    jsrsExecute( 'select_rs.php', cbFillModel, 'modelList', val);
  }  
}

function lstDistrict_onChange(){

  var val = this.options[this.selectedIndex].value;
  if(val == noValue){
    selectOption( this.name, curOption[this.name] )

  }
  
  else {
    curOption[this.name] = val;
    emptyList( 'lstCampus');
    window.status = 'Loading Options Selections...';
    jsrsExecute( 'select_rs.php', cbFillCampus, 'optionsList', val); }  
	
}

function removeLoader()
	{
var d = document.getElementById('QForm'); 
var d_nested = document.getElementById('SEC'); 
 
var throwawayNode = d.removeChild(d_nested);
	var dd = document.getElementById('QForm'); 
	
var dd_nested = document.createElement('span'); 
dd_nested.setAttribute("id", "SEC");
dd_nested.setAttribute((document.all ? 'className' : 'class'), "drag-handleBIG"); 
//important.. HB-- the dealio is that I.E. doesn't set the Attribute 'class'  back the way is should...Firefox does... SOOO  thusly.. 
// the weird document.all ? 'className'  ... courtesy of http://www.digitalmediaminute.com/article/1394/the-browser-dom-and-the-class-attribute 

 var addDivNode = dd.appendChild(dd_nested);

	}
 
 
function lstCampus_onChange()

{

	var val = this.options[this.selectedIndex].value;
  IDCampus = val;
  if(val == noValue)
  {
   selectOption( this.name, curOption[this.name])
	} else {
  portalEvents(val);
  }  
  
}

function cbFillCounty ( strMakes ){ 
  window.status = '';
  fillList( 'lstCounty',  strMakes ); 
  if(IDCounty != noValue){
    jsrsExecute( 'select_rs.php', cbFillModel, 'modelList', ''+IDCounty+'');
  }
}

function cbFillModel ( strModels ){ 
  // callback for dependent listbox
  window.status = '';
  fillList( 'lstDistrict',  strModels ); 
  if(IDDistrict != noValue){
    jsrsExecute( 'select_rs.php', cbFillCampus, 'optionsList', ''+IDDistrict+'');
  }
}

function cbFillCampus( strCampus ){ 
  // callback for dependent listbox
  window.status = '';
  
  fillList( 'lstCampus', strCampus,''+IDCampus+'' ); 
if (strCampus== "")
{document.getElementById("SEC").innerHTML="No Secondary schools in area";}
	else 
	{document.getElementById("SEC").innerHTML=" ";}
}

function fillList( listName, strOptions ){
  // fill any list with options
  emptyList( listName );
  
  // always insert selection prompt
  var lst = document.forms['QForm'][listName];
  lst.disabled = true;
  lst.options[0] = new Option('  Please Select  ', noValue);
  
  // options in form "value~displaytext|value~displaytext|..."
  var aOptionPairs = strOptions.split('|');
  for( var i = 0; i < aOptionPairs.length; i++ ){
    if (aOptionPairs[i].indexOf('~') != -1) {
      var aOptions = aOptionPairs[i].split('~');
      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
    }  
  }
  switch(listName){
  	case 'lstCounty':
		  ID = IDCounty;
		break;
  	case 'lstDistrict':
		  ID = IDDistrict;
		break;
	case 'lstCampus':
		  ID = IDCampus;
		break;
	}
  // init to no value
  selectOption( listName, ID );
  isLoaded[listName] = true;
  lst.disabled = !boolEnabled;
  lst.onchange = eval( listName + "_onChange" );
  eval( "document.forms['QForm']['" + listName + "'].onchange=" + listName + "_onChange;" );
}

function emptyList( listName ){
  var lst = document.forms['QForm'][listName];
  lst.options.length = 0;
  lst.onchange = null;
  lst.disabled = !boolEnabled;
  isLoaded[listName] = false;
  curOption[listName] = noValue;
}

function selectOption( listName, optionVal ){
  // set list selection to option based on value
  var lst = document.forms['QForm'][listName];
  for( var i = 0; i< lst.options.length; i++ ){
    if( lst.options[i].value == optionVal ){
      lst.selectedIndex = i;
      curOption[listName] = optionVal;
      return;
    }  
  }
}

function showLoader()
{
  document.getElementById('SEC').innerHTML='<img src=\"images/ajax-loader.gif\" width=\"16\" height=\"16\">';
}




function  portalEvents(val)
{
 //  var msg = "You have selected: \n\n";
   // msg += this.form.lstCounty.options[this.form.lstCounty.selectedIndex].text + "\n";
   // msg += this.form.lstDistrict.options[this.form.lstDistrict.selectedIndex].text + "\n";
    //msg += this.options[this.selectedIndex].text + "\n";
	//  msg += val; 
	CHECKIT=getCookie('SCHOOLID');
CHECKTWO=getCookie('WHAT');
CHECKMEM=getCookie('MEM');
showLoader();
showUser(val);  
 showID(val,0);
showAddress(val,CHECKMEM);

showDISP (val,0);
showPREP(val,0);
showACC(val,0); 
showAYPread(val,0);
showAYPCOMP(val);
showCOMPARE(val);
showDISPCOMP (val);
showACCCOMP(val);
showPREPCOMP(val);
showTEACH(val,0);
showTEACHComp(val);
showCOMM(val);
showQualCur(val);
showQualCurCOMP(val);
showENG(val);

showLINKS(val,CHECKMEM);

if (CHECKIT != val )
{ 
setCookie('SCHOOLID',val,365);   
opacity('disp', 0, 100, 500); // transforms the opacity of the first on
opacity('disptwo', 0, 100, 500); // transforms the opacity of the first on
opacity('school', 0, 25, 500); // transforms the opacity of the first on
//opacity('schooltwo', 0, 25, 500); // transforms the opacity of the first on
opacity('collegepreps', 0, 25, 500); // transforms the opacity of the first on
//opacity('collegeprepstwo', 0, 25, 500); // transforms the opacity of the first on
opacity('college', 0, 25, 500); // transforms the opacity of the first on
//opacity('collegetwo', 0, 25, 500); // transforms the opacity of the first on
delete_cookie('WHAT'); 
}

if (CHECKTWO == 1 && CHECKIT != val )
{ reInsertDescripDiv();
 
toggleLayer('college'); 
toggleLayer('collegetwo');
toggleLayer('collegepreps');
toggleLayer('collegeprepstwo');
toggleLayer('school');
toggleLayer('schooltwo');
opacity('collegeup', 100,0, 0);
opacity('collegeprepsup', 100,0, 0);
opacity('schoolup', 100,0, 0);
opacity('teachingquality', 100,0, 0);
opacity('parentengagement', 100,0, 0);
opacity('studentengagement', 100,0, 0); 
opacity('curriculum', 100,0, 0);
   delete_cookie('WHAT');
}

delete_cookie('WHAT');


if(boolEnabled)
{
//    document.getElementById('cmdSubmit').disabled="";
//  document.getElementById('show').style.backgroundColor="#FFCC99";
}
}




function reInsertDescripDiv()
{ 	

var dde = document.getElementById('container'); 
	
var dde_nested = document.createElement('div'); 
dde_nested.setAttribute("id", "disptwo");
dde_nested.setAttribute((document.all ? 'className' : 'class'), "recentdisptwo"); 
 
 var addDivNodetwo	 = dde.appendChild(dde_nested);
}
















