
/**************this is for eval.php page*****************************/

var xmlHttp
var destobj
var mycase

var formertext;
var formervalue;

function stripURL(myform, stripme) {
  URLArr = myform.action.split("?");
  myfilename = URLArr[0];

  if (URLArr.length > 1) {
    myParam = URLArr[1];
    URLArr2 = myParam.split("&");

    for (myx = 0; myx < URLArr2.length; myx++) {
      URLArr3 = URLArr2[myx].split("=");
      if (URLArr3[0] != stripme) {
        if (myfilename.indexOf("?") == -1) {
          myfilename = myfilename + "?";
        }
        else {
          myfilename = myfilename + "&";
        }
        myfilename = myfilename + URLArr3[0] + "=" + URLArr3[1];
      }
    }
  }
  myform.action = myfilename;
}

function addURL(myform, addme) {
  myfilename = myform.action;

  if (myform.action.indexOf("?") == -1) {
    myfilename = myfilename + "?";
  }
  else {
    myfilename = myfilename + "&";
  }
  myfilename = myfilename + addme;

  myform.action = myfilename;
}

function getRegion(mysrc, mydest, loadingtext) {
  destobj = mydest;
  xmlHttp = GetXmlHttpObject();

  if (xmlHttp==null) {
    //alert ("Your browser does not support AJAX!");
    doLoad(mysrc); //old style
    return;
  }

  //don't delete the first line which is "Select"
  formertext = mydest.options[0].text;
  formervalue = mydest.options[0].value;

  while (mydest.length > 1) {
    mydest.remove(mydest.length - 1);
  }

  mydest.disabled = true;
  mydest.options[0].text = loadingtext;

  document.getElementById("RegionIDimg").style.display = "";

  document.form1.CityID.disabled = true;
  document.form1.CityName.disabled = true;
  document.form1.CityFirst3Char.disabled = true;

  document.form1.EmployerID.disabled = true;
  document.form1.EmployerName.disabled = true;
  document.form1.EmpFirst3Char.disabled = true;

  document.form1.CityID.value = "";
  document.form1.CityName.value = "";
  document.form1.CityFirst3Char.value = "";

  document.form1.EmployerID.value = "";
  document.form1.EmployerName.value = "";
  document.form1.EmpFirst3Char.value = "";
  
  while (document.form1.BranchID.length > 2) {
    document.form1.BranchID.remove(document.form1.BranchID.length - 1);
  }

  document.form1.BranchID.disabled = true;
  document.form1.BranchID.selectedIndex = 0;

  document.form1.GroupName.disabled = true;
  document.form1.FormerName.disabled = true;
  document.form1.GroupName.value = "";
  document.form1.FormerName.value = "";

  document.form1.StartYearID.disabled = true;
  document.form1.EndYearID.disabled = true;
  document.form1.JobStatusID.disabled = true;
  document.form1.IndustryID.disabled = true;
  document.form1.IndustryID.selectedIndex = 0;

  document.form1.JobCategoryID.disabled = true;

  stripURL(document.form1, "Type");
  
  var url = "/ajax.php?CountryID=" + mysrc.options[mysrc.selectedIndex].value;
  xmlHttp.onreadystatechange = RegionChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function RegionChanged() {
  if (xmlHttp.readyState==4) {
    if (xmlHttp.status==200) {
      var xmlDoc = xmlHttp.responseXML;
      var totalrow = xmlDoc.getElementsByTagName("total")[0].childNodes[0].nodeValue;

      for (var cnt = 1; cnt <= totalrow; cnt++) {
        myID = xmlDoc.getElementsByTagName("regionid" + cnt)[0].childNodes[0].nodeValue;
        myName = xmlDoc.getElementsByTagName("regionname" + cnt)[0].childNodes[0].nodeValue;
        myShortName = xmlDoc.getElementsByTagName("shortregionname" + cnt)[0].childNodes[0].nodeValue;
        insertOption2(destobj, myName, myShortName, myID);
      }

      destobj.options[0].text = formertext;
    }
    else {
      alert("Problem retrieving XML data: " + xmlHttp.statusText);
    }

    if (document.form1.CountryID.selectedIndex > 0) {
      destobj.disabled = false;
    }
  
    document.getElementById("RegionIDimg").style.display = "none";

    addURL(document.form1, "Type=CountryID");
  }
}

function getCity(mysrc, mydest, loadingtext) {
  destobj = mydest;
  xmlHttp = GetXmlHttpObject();

  if (xmlHttp==null) {
    //alert ("Your browser does not support AJAX!");
    doLoad(mysrc); //old style
    return;
  }

  document.form1.CityName.disabled = false;
  document.form1.CityID.disabled = false;
  document.form1.CityFirst3Char.disabled = false;

  document.form1.EmployerName.disabled = false;
  document.form1.EmployerID.disabled = false;
  document.form1.EmpFirst3Char.disabled = false;

  document.form1.CityID.value = "";
  document.form1.CityName.value = "";
  document.form1.CityFirst3Char.value = "";

  document.form1.EmployerID.value = "";
  document.form1.EmployerName.value = "";
  document.form1.EmpFirst3Char.value = "";

  while (document.form1.BranchID.length > 2) {
    document.form1.BranchID.remove(document.form1.BranchID.length - 1);
  }

  document.form1.BranchID.disabled = true;
  document.form1.BranchID.selectedIndex = 0;

  document.form1.GroupName.disabled = true;
  document.form1.FormerName.disabled = true;
  document.form1.GroupName.value = "";
  document.form1.FormerName.value = "";

  document.form1.StartYearID.disabled = true;
  document.form1.EndYearID.disabled = true;
  document.form1.JobStatusID.disabled = true;
  document.form1.IndustryID.disabled = true;
  document.form1.IndustryID.selectedIndex = 0;

  document.form1.JobCategoryID.disabled = true;

  stripURL(document.form1, "Type");
}

function getBranch(mysrc, mydest, loadingtext) {
  destobj = mydest;
  xmlHttp = GetXmlHttpObject();

  if (xmlHttp==null) {
    //alert ("Your browser does not support AJAX!");
    doLoad(mysrc); //old style
    return;
  }

  //alert("still running");
  //don't delete the first 2 line
  formertext = mydest.options[0].text;
  formervalue = mydest.options[0].value;

  while (mydest.length > 2) {
    mydest.remove(mydest.length - 1);
  }

  mydest.selectedIndex = 0;

  mydest.disabled = true;
  mydest.options[0].text = loadingtext;

  document.getElementById("BranchIDimg").style.display = "";

  document.form1.GroupName.disabled = true;
  document.form1.FormerName.disabled = true;
  document.form1.GroupName.value = "";
  document.form1.FormerName.value = "";

  document.form1.StartYearID.disabled = true;
  document.form1.EndYearID.disabled = true;
  document.form1.JobStatusID.disabled = true;
  document.form1.IndustryID.disabled = true;
  document.form1.IndustryID.selectedIndex = 0;

  document.form1.JobCategoryID.disabled = true;

  stripURL(document.form1, "Type");

  var url = "/ajax.php?EmployerID=" + mysrc.value;
  xmlHttp.onreadystatechange = BranchChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function BranchChanged() {
  if (xmlHttp.readyState==4) {
    if (xmlHttp.status==200) {
      if (document.form1.EmployerID.value != "") {
        var xmlDoc = xmlHttp.responseXML;
        var totalrow = xmlDoc.getElementsByTagName("total")[0].childNodes[0].nodeValue;

        for (var cnt = 1; cnt <= totalrow; cnt++) {
          myID = xmlDoc.getElementsByTagName("branchid" + cnt)[0].childNodes[0].nodeValue;
          myName = xmlDoc.getElementsByTagName("branchname" + cnt)[0].childNodes[0].nodeValue;
          insertOption(destobj, myName, myID);
        }

        var myInd = xmlDoc.getElementsByTagName("industry");
        var myGroup = xmlDoc.getElementsByTagName("groupname");
        var myFormer = xmlDoc.getElementsByTagName("formername");

        if (myInd[0].childNodes.length > 0) {
          for (var cnt2 = 0; cnt2 < document.form1.IndustryID.length; cnt2++) {
            if (document.form1.IndustryID.options[cnt2].value == myInd[0].childNodes[0].nodeValue) {
              document.form1.IndustryID.selectedIndex = cnt2;
              break;
            }
          }
        }

        if (myGroup[0].childNodes.length > 0) {
          document.form1.GroupName.value = trimAll(myGroup[0].childNodes[0].nodeValue);
        }

        if (myFormer[0].childNodes.length > 0) {
          document.form1.FormerName.value = trimAll(myFormer[0].childNodes[0].nodeValue);
        }
      }

      destobj.options[0].text = formertext;
    }
    else {
      alert("Problem retrieving XML data: " + xmlHttp.statusText);
    }

    if (document.form1.EmployerID.value != "") {
      destobj.disabled = false;

      document.form1.GroupName.disabled = false;
      document.form1.FormerName.disabled = false;

      document.form1.StartYearID.disabled = false;
      document.form1.EndYearID.disabled = false;
      document.form1.JobStatusID.disabled = false;
      document.form1.IndustryID.disabled = false;
      document.form1.JobCategoryID.disabled = false;
    }
    else {
      //alert("yahoo");
      //document.form1.NewEmployerName.disabled = false;
      //document.getElementById("AddNewEmployerName").href = empcode;
    }

    document.getElementById("BranchIDimg").style.display = "none";

    addURL(document.form1, "Type=EmployerID");

    if (document.form1.EmployerID.value != "" && document.form1.CityID.value != "") {
      doStep1NextF()
    }
  }
}

function doSearchCityEmp() {
  document.form1.action = "getinfo/";
  document.form1.submit();
}

function GetXmlHttpObject() {
  var xmlHttp = null;

  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) {
        //do nothing here;
      }
    }
  }

  return xmlHttp;
}

function insertOption(insertObj, insertText, insertValue) {
  var y = document.createElement('option');
  y.text = insertText;
  y.value = insertValue;

  try {
    insertObj.add(y,null); // standards compliant
  }
  catch(ex) {
    insertObj.add(y); // IE only
  }
}

function insertOption2(insertObj, insertText, shorttext, insertValue) {
  var y = document.createElement('option');
  y.text = shorttext;
  y.value = insertValue;

  try {
    insertObj.add(y,null); // standards compliant
  }
  catch(ex) {
    insertObj.add(y); // IE only
  }

  insertObj.options[insertObj.length - 1].setAttribute("full", insertText);
  insertObj.options[insertObj.length - 1].setAttribute("short", shorttext);
}

