//config

var http_base='http://degreefinders.com/';


//globals
var subject_category_1 ='';
var subject_category_2 ='';
var edu_type_2 ='';
var edu_type_1 ='';
var school = '';
var edu_type_2_placeholder=''; //used in 'NA' logic as option text 
var edu_type_2_valueholder=''; //used in 'NA' logic as option value 

function getXmlHttp(){
     var xmlHttp;
      try
        {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        }
      catch (e)
        {
        // Internet Explorer
        try
          {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          catch (e)
            {
            alert("Your browser does not support AJAX.");
            return false;
            }
          }
        }
        
        return xmlHttp;
  } //end function


function popSubCatOptions(parentid){
 
    
  var xmlHttp=getXmlHttp();
  
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      //alert(xmlHttp.responseText);
      //document.getElementById("resultsdiv").innerHTML=xmlHttp.responseText;
      //alert("response="+xmlHttp.responseText);
       var catbox=document.getElementById('subject_category_2');
      catbox.options.length = 0;
      catbox.options[catbox.options.length]=new Option("Select a sub category",'',true);
      //alert(catbox.options.length);
      var opt_arr= xmlHttp.responseText.split('|');
      
      for ( i=0; i < opt_arr.length; i++){
          
          parts=opt_arr[i].split(',');
          opt_value=parts[0];
          opt_text=parts[1];
          catbox.options[catbox.options.length]=new Option(opt_text,opt_value);
      
      }
      
      //catbox.options[catbox.options.length]=new Option("test",1);
      
      }
    }

  //xmlHttp.open("GET","assets/snippets/ajax_test/back_snip2.php",true);
  var params="cat1="+subject_category_1;
  
  
  var url="custom/edu_unit_filter_gui/pop_sub_cat.php?"+params;
  //alert(url);
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);

}

function setSubject(subid){
 
  //alert(subid);
  subject_category_1=subid;
  popSubCatOptions(subid);
}

function setSubCat(subcatid){

  //alert(subcatid);
   subject_category_2=subcatid;
}

function setDegreeLevel(levelid){

   edu_type_2=levelid;
}

function setEduGoal(goalid){

   edu_type_1=goalid;
    
    //alert(edu_type_2_placeholder);
   
   var box3=document.getElementById('edu_type_2');
   
   if (edu_type_1 != 2){
      //alert("document.getElementById('edu_type_2').disabled");
       box3.enabled="";
       if (box3.options[box3.selectedIndex].text != " NA "){
          edu_type_2_placeholder=box3.options[box3.selectedIndex].text;
          edu_type_2_valueholder=box3.options[box3.selectedIndex].value;
          box3.options[box3.selectedIndex].text=" NA ";
          box3.options[box3.selectedIndex].value='';
       }
       
      box3.disabled="disabled";
      
   }else{
      box3.disabled="";
      
      box3.enabled="enabled";
      
      if(edu_type_2_placeholder == " NA"){
          edu_type_2_placeholder=""; //must be option[0].text
          edu_type_2_valueholder=""
      }
      box3.options[box3.selectedIndex].text=edu_type_2_placeholder;
      box3.options[box3.selectedIndex].text=edu_type_2_valueholder;
   }
   
   //alert(edu_type_2_placeholder);
}

function setSchool(schoolid){

   school=schoolid
}



function search(){

 //var msg="Find it clicked with params: ";
 
 var msg='';
  //msg +="?cat1="+subject_category_1;
   
   var box1=document.getElementById('subject_category_1');
   var box2=document.getElementById('edu_type_1');
   var box3=document.getElementById('edu_type_2');
   
   var cat1=box1.options[box1.selectedIndex].value;
   msg +="?cat1="+cat1;
   
   var type1=box2.options[box2.selectedIndex].value;
   msg +="&type1="+type1;
   
   var type2 = box3.options[box3.selectedIndex].value;
   msg +="&type2="+type2;
   
   //alert(msg);
   // msg +="&cat2="+subject_category_2;
  
 //msg +="&type1="+edu_type_1;
  //msg +="&type1="+document.getElementById('edu_type_1').value;
  //msg +="&type2="+edu_type_2;
  //msg +="&type1="+document.getElementById('edu_type_2').value;
  //msg +="&school="+school;
  
  var hrefstr=location.href;
  //alert(location.href);
  var parts_arr = hrefstr.split('?');
  
  var base_url=parts_arr[0];
  
  //*****************************************//
  //  Filter  Redirecting
  //****************************************//
  
  if(base_url.indexOf("accredited-online-colleges") < 0){ //not a school page
      //alert("*no school - doing switch() type1="+type1);
      switch (type1){
         
         case  '1': // course
                base_url='online-college-courses.html';
                break; 
                
         case  '2': // degree
                
                //alert("WTF");
                //alert("degree- type2="+type2);
                
                base_url='online-degree-programs.html';
                
                switch (type2){
                    
                    case '1':
                          base_url='online-degree-programs/online-associate-degrees.html';
                          break;
                          
                    case '2':
                          base_url='online-degree-programs/online-bachelor-degrees.html';
                          break;      
                    
                    case '3':
                          base_url='online-degree-programs/online-masters-degrees.html';
                          break; 
                    
                    case '4':
                          base_url='online-degree-programs/online-doctorate-degrees.html';
                          break; 
                               
                }//end switch type2
                              
                break;
                
         case  '3': // cert
                base_url='online-certificates.html';
                break;
                       
      }//end switch
    
      var target_url=http_base+base_url+msg;
  
      
  }else{ //end if school page
  
      var target_url=base_url+msg;
       
  
  } //end else
  //*****************************************//
  //  END Filter  Redirecting
  //****************************************//
  
   location.href=target_url;
   
} //end function














