var d=document;
var isCountryChange,otherSchoolLabel,rowstyle;
var partnerRgistrationUrl="";
var eduDD=
{
 init:function()
 {
  if(!window.XMLHttpRequest&&!window.ActiveXObject)
  {
   return ;
  }
  YEvent.on(d.getElementById(locationCodeID),"change",function()
  {
   eduDD.updateDropdowns(true);
  }
  ,false);
  YEvent.on(d.getElementById(provinceCodeID),"change",function()
  {
   eduDD.updateDropdowns(false);
  }
  ,false);
  YEvent.on(d.getElementById(schoolID),"change",eduDD.showOtherBox,false);
  otherSchoolLabel=d.getElementById("row-other").getElementsByTagName("label")[0];
  rowstyle=eduDD.getRowDisplayStyle("row-other","display");

  var X=0;
  try{
	X=parseInt(existingUniversityID);
  }catch(e){}

/******************************
 *  00   00   000
 * |__| |__| |___|
 *  X1   X2    X3
 * X1 for country code, like CN : 00
 * X2 for province code
 * X3 for university code
 ******************************/
  if(X>0){
    var X1=0, Xt=X;
    if(X>100000){
        X1=parseInt(X/100000);
        Xt=Xt%100000;
    }
    var X2=0, X3=Xt;
    if(Xt>1000){
        X2=parseInt(Xt/1000);
        X3=X3%1000;
    }

    if(X1<10)
        X1="0"+X1;
    var S=d.getElementById(locationCodeID).options;
	for(var ii=1;ii<S.length;ii++){
	   var N=S[ii];
	   if(N.value==X1){
        N.selected=true;
       }
	}
	eduDD.show("row-location");
	
	eduDD.updateDropdowns(true);
	if(X2==0){
	   eduDD.hide("row-province");
	}else{
	   var S=d.getElementById(provinceCodeID).options;
	   for(var ii=1;ii<S.length;ii++){
	       var N=S[ii];
	       if(N.value==X2){
            N.selected=true;
        }
	   }
	   eduDD.show("row-province");
        eduDD.updateDropdowns(false);
	}
	
	if(X3==0){
        var S=d.getElementById(schoolID).options;
        S[S.length-1].selected=true;
        eduDD.show("row-other");
	}else{
        var S=d.getElementById(schoolID).options;
        for(var ii=1;ii<S.length;ii++){
            var N=S[ii];
            if(N.value==X){
                N.selected=true;
            }
        }
	
	}
    eduDD.show("row-school");
	
  
  }else{
    eduDD.hide("row-other");
    eduDD.show("row-location");
  }
 }
 ,updateDropdowns:function(B)
 {
  var E=function(F)
  {
   var H=allUnivList;
   for(var ii=0;ii<H.length;ii++){
    if(H[ii]["id"]==F)
        var G=H[ii];
   }
   if(typeof G["univs"]=="object")
   {
     G=G["univs"];
     if(G[0]["id"]!="")
        G.unshift({id:"",name:"\u8bf7\u9009\u62e9\u5927\u5b66\u002e\u002e\u002e"});
     if(G.length>0 && G[G.length-1]["id"]!="0")
        G.push({id:NLZ(F)+"00000",name:"\u5176\u4ed6\u002e\u002e\u002e"});
     if(isCountryChange)
     {
      eduDD.clearOptions(schoolID);
     }
     eduDD.updateProvinceLabel();
     eduDD.buildOptions(schoolID,G);
     eduDD.hide("row-province");
     eduDD.show("row-school");
     eduDD.hide("row-other");

   }
   else
   {
    G=G["provs"];
    if(G[0]["id"]!="")
        G.unshift({id:"",name:"\u8bf7\u9009\u62e9\u7701\u4efd\u002e\u002e\u002e"});
    eduDD.clearOptions(schoolID);
    eduDD.buildOptions(provinceCodeID,G);
    eduDD.show("row-province");
    eduDD.hide("row-school");
    eduDD.hide("row-other");
   }
   eduDD.toggleProgress("off",isCountryChange);
  }
  ;
  var F=function(F,D){
   var H=allUnivList;
   for(var ii=0;ii<H.length;ii++){
    if(H[ii]["id"]==F)
        var G=H[ii]["provs"];
   }
   for(var ii=0;ii<G.length;ii++){
    if(G[ii]["id"]==D){
     G=G[ii]["univs"];
     if(G[0]["id"]!="")
        G.unshift({id:"",name:"\u8bf7\u9009\u62e9\u5927\u5b66\u002e\u002e\u002e"});
     if(G.length>0 && G[G.length-1]["id"]!="0")
	G.push({id:NLZ(F)+(D<10?"0"+D:D)+"000",name:"\u5176\u4ed6\u002e\u002e\u002e"});
     if(isCountryChange)
     {
      eduDD.clearOptions(schoolID);
     }
     eduDD.updateProvinceLabel();
     eduDD.buildOptions(schoolID,G);
     eduDD.show("row-province");
     eduDD.show("row-school");
     eduDD.hide("row-other");
     break;
    }
   }
  };
  
  isCountryChange=B;
  if(isCountryChange&&eduDD.getSelectValue(locationCodeID)=="")
  {
   eduDD.hide("row-province");
   eduDD.hide("row-school");
   eduDD.hide("row-other");
  }
  else
  {
   //var A="wsSchoolDir?q=";
   //if(partnerRgistrationUrl!="")
   //{
   // A=partnerRgistrationUrl+"/wsSchoolDir?q=";
   //}
   if(!isCountryChange)
   {
    var D=eduDD.getSelectValue(provinceCodeID);
   }
   eduDD.toggleProgress("on",isCountryChange);
   //eduDD.ajaxRequest(A,E);
   if(D&&D!=""&&!isCountryChange){
    F(eduDD.getSelectValue(locationCodeID),D);
   }else{
    E(eduDD.getSelectValue(locationCodeID));
   }
  }
 }
 ,showOtherBox:function(B)
 {
  var A=window.event?window.event.srcElement:B?B.target:null;
  if(!A)
  {
   return ;
  }
  var A_=A.options[A.selectedIndex].value;
  if(A_.indexOf("0")==0)A_=A_.substr(1);
  if(parseInt(A_)%1000==0)
  {
   eduDD.show("row-other");
   d.getElementById(otherSchoolNameID).focus();
  }
  else
  {
   eduDD.hide("row-other");
  }
 }
 ,buildOptions:function(D,C)
 {
  eduDD.clearOptions(D);
  for(var B=0;B<C.length;B++)
  {
   var A=new Option(C[B].name,C[B].id);
   d.getElementById(D).options[B]=A;
  }
 }
 ,clearOptions:function(A)
 {
  d.getElementById(A).options.length=0;
 }
 ,updateProvinceLabel:function()
 {
 }
 ,toggleProgress:function(C,A)
 {
  //var B=A?"progress-location":"progress-province";
  //d.getElementById(B).style.display=(C=="on")?"inline":"none";
 }
 ,hide:function(A)
 {
  d.getElementById(A).style.display="none";
 }
 ,show:function(A)
 {
  d.getElementById(A).style.display=rowstyle;
 }
 ,getNodeValue:function(B,A)
 {
  return B.getElementsByTagName(A)[0].firstChild.nodeValue;
 }
 ,getNodeAttribute:function(C,A,B)
 {
  return C.getElementsByTagName(A)[0].firstChild.getAttribute(B);
 }
 ,getSelectValue:function(A)
 {
  return d.getElementById(A).options[d.getElementById(A).selectedIndex].value;
 }
 ,setSelectValue:function(B,A)
 {
  return d.getElementById(B).options[d.getElementById(B).selectedIndex].value=A;
 }
 ,getRowDisplayStyle:function(C,B)
 {
  var A=document.getElementById(C);
  if(A.currentStyle)
  {
   return A.currentStyle[B];
  }
  else
  {
   if(A.nodeName=="TR")
   {
    return"table-row";
   }
   else
   {
    return"block";
   }
  }
 }
 ,revertToTextField:function()
 {
  eduDD.hide("row-location");
  eduDD.hide("row-province");
  eduDD.hide("row-school");
  eduDD.show("row-other");
 }
 ,ajaxRequest:function(A,D)
 {
  var B=false;
  if(window.XMLHttpRequest)
  {
   try
   {
    B=new XMLHttpRequest();
   }
   catch(C)
   {
    B=false;
   }
  }
  else
  {
   if(window.ActiveXObject)
   {
    try
    {
     B=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(C)
    {
     try
     {
      B=new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch(C)
     {
      B=false;
     }
    }
   }
  }
  if(B)
  {
   B.open("GET",A,true);
   B.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");B.send("");
   B.onreadystatechange=function()
   {
    if(B.readyState==4)
    {
     if(B.status==200)
     {
      D(B);
     }
     else
     {
      eduDD.revertToTextField();
     }
    }
   }
   ;
  }
 }
}
;
YEvent.on(window,"load",eduDD.init,false);
