// $Revision: 1.43 $

window.status = "";

var flagId='';

/****************************************************
 *name : trim(strSource)
 *discription : Remove left and right spaces of string
 *param : strSource- Original string
 *return : String without left and right spaces
 ****************************************************/
function trim(strSource) {
    return strSource.replace(/(^\s*)|(\s*$)/g, "");
}

/****************************************************
 *name : enterToTab()
 *discription : Change the event of key "Enter" to "Tab"
 ****************************************************/
function enterToTab(){
  if(event.srcElement.type != 'button' && event.srcElement.type != 'textarea' && event.keyCode == 13){
    event.keyCode = 9;
  }
}

function displayList(list1,list2){
  if(list1 != null && list2 != null && list2.options){// Modify for slip 7153
    for (var i = 0;i < list2.options.length; i++){
      var selectedValue = list2.options[i].value;
      for (j=0; j < list1.options.length; j++){
        if (list1.options[j].value == selectedValue){
          list1.remove(j);
        }
      }
    }
  }
}
        
    function enableListItem(list) {

        for (var i = list.length - 1; i >= 0; i--) {

            list.options[i].selected = true;
        }

    }


     function moveList(LeftList,RightList) {
    for (var i = LeftList.length - 1; i >= 0; i--) {
    if ( LeftList.options[i].selected) {
        var option0 = new Option( LeftList.options[i].text,
                                  LeftList.options[i].
                                 value);
        option0.selected = true;
        for (var j =  RightList.length - 1; j >= 0;j--) {

        }
         RightList.options[
            RightList.length] = option0;
         LeftList.options[i] = null;
    }
}
for (var i =  RightList.length - 1; i >= 0; i--) {
     RightList.options
        [i].selected = true;
}
}
    function moveValue(LeftList,RightList) {
    for (var i =  RightList.length - 1; i >= 0; i--) {
    if ( RightList.options[i].selected) {
        var option0 = new Option( RightList.options[i].
                                 text,
                                  RightList.options[i].
                                 value);
         LeftList.options[ LeftList.
            length] = option0;
         RightList.options[i] = null;
    }
}
for (var i =  RightList.length - 1; i >= 0; i--) {
     RightList.options[i].selected = true;
}
}

function moveDegreeValue(LeftList,RightList,degreeList) {
    for (var i =  RightList.length - 1; i >= 0; i--) {
        if ( RightList.options[i].selected) {
          if(isExisted(degreeList,RightList.options[i].value)){
            var option0 = new Option( RightList.options[i].text,
                                  RightList.options[i].value);
            LeftList.options[ LeftList.length] = option0;
           }
         RightList.options[i] = null;
       }
    }
    for (var i =  RightList.length - 1; i >= 0; i--) {
         RightList.options[i].selected = true;
    }
}

function isExisted(degreeList,value){
    for(var i=0;i<degreeList.length;i++){
        if(degreeList[i].value == value){
            return true;
        }
    }
    deleteOtherDegree(value);
    return false;
}

    /** Shift list up. Add for slip 8331
      * @author Lww
      * @version 1.0
      * @param list
      */
    function shiftUpList(list){
        var len = list.length;
        var special = null;
        for(var i = 0;i < len;i ++){
           if(list[i].selected){
                var properIndex;
                //Get proper index
                var preIndex = i - 1;
                if(preIndex < 0){
                    return;
                }else{
                    properIndex = preIndex;
                }
                
                var tmp = list[i];
                list[i] = new Option(list[properIndex].text,
                                     list[properIndex].value);
                list[properIndex] = new Option(tmp.text,tmp.value);
                list[properIndex].selected = true;
            }
        }
        
    }
    
    /** Shift list down. Add for slip 8331
      * @author Lww
      * @version 1.0
      * @param list
      */
    function shiftDownList(list){
        var len = list.length;
        for(var i = len - 1;i > -1; i --){
           if(list[i].selected){
                var properIndex;
                //Get proper index
                var afterIndex = i + 1;
                if(afterIndex > len - 1){
                    return;
                }else{
                    properIndex = afterIndex;
                }
                var tmp = list[i];
                list[i] = new Option(list[properIndex].text,
                                     list[properIndex].value);
                list[properIndex] = new Option(tmp.text,tmp.value);
                list[properIndex].selected = true;
            }
        }
        
    }

    /** Move the whole list. Add for slip 8331
      * @author Lww
      * @version 1.0
      * @param leftList, rightList
      */
    function moveWholeList(leftList,rightList){
          var rightLength = rightList.length;
          for(var i = leftList.length - 1;i > -1;-- i){
           var option0 = new Option(leftList[i].text,
                                                    leftList[i].value);
            leftList[i] = null;
            option0.selected = true;
            var temp = 0;
            for (var j = rightList.length - 1; j >= 0; j--) {
                if(option0.value == rightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                rightList.options[rightList.length] = option0;
            }

        }
        for (var i =  rightList.length - 1; i >= 0; i--) {
         rightList.options[i].selected = true;
       }
    }
    
   /** Pop up a window with given url. 
      * E.g. popWindow('anyAction.do?id=33226',0.85,0.8,50,20);
      * @author Lww
      * @version 1.0
      * @param url:  the url we want to navigate to.
      * @param hScale: window height scale(not pixel) (0 < hScale <=1)
      * @param wScale: window width  scale(not pixel) (0 < hScale <=1)
      * @param left:   pixels away from the screen left edge.
      * @param top :   pixels away from the screen top edge.
      */
    function popWindow(url,hScale,wScale,left,top, winName){
        if(winName == null){
            winName = 'config';
        }
        var newWindow = window.open(url,winName,"height=" + (screen.height*hScale) + ",width=" + (screen.width*wScale) +
        ",left=" + left + ",top=" + top + ",toolbar=no, menubar=no, status=no, scrollbars=yes,resizable=no");  
        newWindow.focus();
    }  
     
function winOpen()        {
    window.open("http://brainhunter.careerperfect.com","Resume", "toolbar=no, menubar=no, status=no, scrollbars=yes,resizable=yes");
}

function clearSelected(obj){
 if(obj != null && obj.options){// Modify for slip 7153
   for(var i=0;i<obj.options.length;i++){
     if(obj.options[i].selected == true)
       obj.options[i].selected=false;
   }
 }
}

function filterOptions(tbl,typeCode) {
    var browserName=navigator.appName;
    var isIE=browserName.indexOf("Microsoft")!=-1?true:false;
    var tbl = document.getElementById(tbl);
    if(isIE) {
        var tblChild = tbl.firstChild;
    for(var i = 0;i < tblChild.childNodes.length;i++){
      var child = tblChild.childNodes[i];
      var id = child.getAttribute("id");
      if(id.indexOf("AT")!=-1 && id.indexOf(typeCode)==-1){
        child.style.display="none";
      }else{
        child.style.display="";
      }
    }
    }
    else {
    }
}

function addRowToTable(tbl) {
    var browserName=navigator.appName;
    var isIE=browserName.indexOf("Microsoft")!=-1?true:false;
    var tbl = document.getElementById(tbl);
    if(isIE) {
        var tblChild = tbl.firstChild;
        var nodeAdd = tblChild.firstChild.cloneNode(true);
        nodeAdd.style.display = "";
        tblChild.appendChild(nodeAdd);
    }
    else {
        var tblChild = tbl.childNodes[1];
        var nodeAdd = tblChild.firstChild.cloneNode(true);
        nodeAdd.style.display = "";
        tbl.appendChild(nodeAdd);
    }
}

function gotoPage(pageNo){
    document.pageForm.pageNo.value=pageNo;
    document.pageForm.submit();
}

function submitForm(frm,obj,value){
    obj.value = value;
    frm.submit();
}

function delQuestion(frm,obj,value){
    if(confirm('It will remove the question permanently,do you really want to continue?')){
      frm.remove.value="remove";
        submitForm(frm,obj,value);
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


/****************************************************
 *  Add js for Ajax using DWR framework by wanghd
 ****************************************************/

// Add for slip 9028
var RETRY_TIMES = 5;
var RETRY_INTERVAL = 1000;

function populateData(result, dropDownName, defaultOption, callCounter){

  // remove all existing drop down options.
  DWRUtil.removeAllOptions(dropDownName);
  if (callCounter) {
      window.status = "Retrieve " + dropDownName + " for the " + callCounter + " time .. ...";
  }
  // add "Select" option into the drop down 
  DWRUtil.addOptions(dropDownName,[{ name:defaultOption, id:'' }],'id','name');
  // add options into the drop down 
  DWRUtil.addOptions(dropDownName,result,"value","label");

}

/**
 * When drop down list "country" is changed, retrieve and populate corresponding
 * province list to drop down list "state/province". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5 
 * Page : Seeker contact location,  
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the province should be selected by default
 * @param otherCityRow Id of other city part
 * @param otherCity Value of option in city drop down list of which text is "other"
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeCountry(countryCode, provinceCode, cityCode, defaultOption, 
                       otherCityRow, otherCity, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var country=$(countryCode).value;
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the province.
  $(provinceCode).selectedIndex = 0;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(provinceCode);
  }
  
  if (!($(provinceCode) && $(provinceCode).length && $(provinceCode).length > 0)) {

      var retryFunction = "changeCountry('" + countryCode + "','" + provinceCode + "','" + 
                           cityCode + "','" + defaultOption + "','" + 
                           otherCityRow + "','" + otherCity + 
                           "',true," + (callCounter+1) + ")";
                           
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  
  // populate the province drop down list according to country code.
  displayDropDown.getProvinces(country, 
                  function(result){populateData(result, provinceCode, defaultOption, callCounter);});
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the empty city drop down list 
  populateData(null,cityCode,defaultOption);
  // set the country state status.
  setCountryStateStatus(countryCode,provinceCode,cityCode,otherCityRow,otherCity);
}

/**
 * When drop down list "state/province" is changed, retrieve and populate corresponding
 * city list to drop down list "city". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5 
 * Page : Seeker contact location 
 *   
 * @param provinceCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the city should be selected by default
 * @param otherCityRow Id of other city part
 * @param otherCity Value of option in city drop down list of which text is "other"
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */ 
function changeProvince(provinceCode, cityCode, defaultOption, otherCityRow, 
                        otherCity, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  
  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvince('" + provinceCode + "','" + cityCode + "','" + 
                           defaultOption + "','" + otherCityRow + "','" + otherCity + 
                           "',true," + (callCounter+1) + ")";
                           
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  // populate the city drop down list according to province code.
  displayDropDown.getCities(province, 
                  function(result){populateData(result, cityCode, defaultOption, callCounter);});
  // set the state city status.
  setStateStatus(provinceCode,cityCode,otherCityRow,otherCity);
}

function initializeCountryStateCity(countryCode,provinceCode,cityCode,otherCityRow,otherCity){
  // initalize the status. set the drop down list to disable or not.
  setCountryStateStatus(countryCode,provinceCode,cityCode,otherCityRow,otherCity);
}

function setCityStatus(cityCode,otherCityRow,otherCity){
  // if user choosed other in city drop down list, we need display the otherc city input text to allow user input.
  var city=DWRUtil.getText(cityCode);
  if (city == otherCity){
    $(otherCityRow).style.display="";
  }
  else{
    $(otherCityRow).style.display="none";
  }
}

function setStateStatus(provinceCode,cityCode,otherCityRow,otherCity){
  var province=$(provinceCode).value;
  // if the province is "Select", we need disable the city drop down list.
  if (province == null || province == ""){
    $(cityCode).disabled=true;
  }
  else{
    $(cityCode).disabled=false;
  }
  setCityStatus(cityCode,otherCityRow,otherCity);
}

function setCountryStateStatus(countryCode,provinceCode,cityCode,otherCityRow,otherCity){
  var country=$(countryCode).value;
  // if country is "Select", we need disable the province and city drop down list.
  if (country == null || country == ""){
    $(provinceCode).disabled=true;
    $(cityCode).disabled=true;
  }
  else{
    $(provinceCode).disabled=false;
    $(cityCode).disabled=false;
  }
  setStateStatus(provinceCode,cityCode,otherCityRow,otherCity);
}


function setCeckOtherCityFlagValue(cityCode,otherCity,checkOtherCityFlag){
  // if user choosed other in city drop down list, we need validate the otherc city.
  var city=DWRUtil.getText(cityCode);
  var hidCheckOtherCityFlag = $(checkOtherCityFlag);
  if (!hidCheckOtherCityFlag) {
      hidCheckOtherCityFlag = document.getElementsByName(checkOtherCityFlag);
  }
  
  if (city == otherCity){
    hidCheckOtherCityFlag.value="Y";
  }
  else{
    hidCheckOtherCityFlag.value="N";
  }
}

/****************************************************
 *  Add function for candidate search
 ****************************************************/
function initializeCountryStateCitySearch(countryCode,provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type){
  // initalize the status. set the drop down list to disable or not.       
  setCountryStateStatusSearch(countryCode,provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type);
}
         
function setCountryStateStatusSearch(countryCode,provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type){
  var country=$(countryCode).value;
  var num=$(locationNum).value;
  // if country is "Select", we need disable the province and city drop down list.
  if (country == null || country == ""){
    DWRUtil.setValue(locationNum,1);
    $(provinceCode).disabled=true;
    $(cityCode).disabled=true;
    $(tdProvince2).style.display="none";
    $(tdProvince3).style.display="none";
    $(tdCity2).style.display="none";
    $(tdCity3).style.display="none";
  }
  else{
    $(provinceCode).disabled=false;
    $(cityCode).disabled=false;
    if(num==2){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    }
    else if(num==3){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    $(tdProvince3).style.display="";
    $(tdCity3).style.display="";    
    }
  }
  setStateStatusSearch2(provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type);
}

function setStateStatusSearch(provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type){
  var province=$(provinceCode).value;
  var num=$(locationNum).value;
  var province2;
  if(provinceCode2!=null){
      province2=$(provinceCode2).value;
  }
  var province3;
  if(provinceCode3!=null){
     province3=$(provinceCode3).value;
  }
  // if the province is "All", we need disable the city drop down list.
  if (province == null || province == ""){
    DWRUtil.setValue(locationNum,1);
    $(cityCode).disabled=true;
    $(tdProvince2).style.display="none";
    $(tdProvince3).style.display="none";
    $(tdCity2).style.display="none";
    $(tdCity3).style.display="none";
  }
  else{
    var provinceText=DWRUtil.getText(provinceCode);
    DWRUtil.setValue(citySpan1,provinceText);
    $(cityCode).disabled=false;
    
    if(num==2){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    if (province2 != null && province2 != ""){
    var provinceText2=DWRUtil.getText(provinceCode2);
      DWRUtil.setValue(citySpan2,provinceText2);
    }
    }
    else if(num==3){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    $(tdProvince3).style.display="";
    $(tdCity3).style.display="";
    if (province2 != null && province2 != ""){
      var provinceText2=DWRUtil.getText(provinceCode2);
      DWRUtil.setValue(citySpan2,provinceText2);
    }
    if (province3 != null && province3 != ""){
      var provinceText3=DWRUtil.getText(provinceCode3);
      DWRUtil.setValue(citySpan3,provinceText3);
    }    
    }   
     setTimeout("selectedList('cityJobCode')", 1000);
  }
}

function setStateStatusSearch2(provinceCode,provinceCode2,provinceCode3,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type){
  var province=$(provinceCode).value;
  var num=$(locationNum).value;
  var province2;
  if(provinceCode2!=null){
      province2=$(provinceCode2).value;
  }
  var province3;
  if(provinceCode3!=null){
     province3=$(provinceCode3).value;
  }
  // if the province is "All", we need disable the city drop down list.
  if (province == null || province == ""){
    DWRUtil.setValue(locationNum,1);
    $(cityCode).disabled=true;
    $(tdProvince2).style.display="none";
    $(tdProvince3).style.display="none";
    $(tdCity2).style.display="none";
    $(tdCity3).style.display="none";
  }
  else{
    var provinceText=DWRUtil.getText(provinceCode);
    DWRUtil.setValue(citySpan1,provinceText);
    $(cityCode).disabled=false;
    
    if(num==2){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    if (province2 != null && province2 != ""){
    var provinceText2=DWRUtil.getText(provinceCode2);
      DWRUtil.setValue(citySpan2,provinceText2);
    }
    }
    else if(num==3){
    $(tdProvince2).style.display="";
    $(tdCity2).style.display="";
    $(tdProvince3).style.display="";
    $(tdCity3).style.display="";
    if (province2 != null && province2 != ""){
      var provinceText2=DWRUtil.getText(provinceCode2);
      DWRUtil.setValue(citySpan2,provinceText2);
    }
    if (province3 != null && province3 != ""){
      var provinceText3=DWRUtil.getText(provinceCode3);
      DWRUtil.setValue(citySpan3,provinceText3);
    }    
    }   
  }
}

/**
 * When drop down list "country" is changed, retrieve and populate corresponding
 * province list to drop down list "state/province". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5
 * Page : Simple Search and Advance Search for candidates (Candidate location and
 *        Job location ) 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode(2/3) Name of drop down lists "state/province"
 * @param cityCode Name of the first drop down list "city"
 * @param defaultOption Value of the province should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeCountrySearch(countryCode, provinceCode, provinceCode2, provinceCode3, 
                             cityCode, defaultOption, tdProvince2, tdProvince3, tdCity2, 
                             tdCity3, locationNum, citySpan1, citySpan2, citySpan3, type, 
                             isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var country=$(countryCode).value;
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the province.
  $(provinceCode).selectedIndex = 0;
  DWRUtil.removeAllOptions(provinceCode2);
  DWRUtil.removeAllOptions(provinceCode3);
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(provinceCode);
  }
  
  if (!($(provinceCode) && $(provinceCode).length && $(provinceCode).length > 0)) {

      var retryFunction = "changeCountrySearch('" + countryCode + "','" + provinceCode + "','" + 
                           provinceCode2 + "','" + provinceCode3 + "','" +  
                           cityCode + "','" + defaultOption + "','" + 
                           tdProvince2 + "','" + tdProvince3 + "','" + tdCity2 + "','" + 
                           tdCity3 + "','" + locationNum + "','" + citySpan1 + "','" + 
                           citySpan2 + "','" + citySpan3 + "','" + type + 
                           "',true," +  (callCounter+1) + ")";

      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  if(type=='job'){
      displayDropDown.getSiteStates4JsSearch(country, 
                      function(result){populateData(result, provinceCode, defaultOption, callCounter);});
  } else{
      displayDropDown.getProvinces(country, 
                      function(result){populateData(result, provinceCode, defaultOption, callCounter);});
  }
  
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the city.
  clearSelected($(cityCode));
  // populate the empty city drop down list 
  populateData(null,cityCode,defaultOption);
  // set the country state status.
  setCountryStateStatusSearch(countryCode, provinceCode, null, null, cityCode, tdProvince2, 
                              tdProvince3, tdCity2, tdCity3, locationNum, citySpan1, 
                              citySpan2, citySpan3, type);
}

/**
 * This function is called in pages Simple and Advance "Search Candidates"
 * When drop down list "state/province" is changed, retrieve and populate corresponding
 * city list to drop down list "city". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5
 * Page : Simple Search and Advance Search for candidates (Candidate location and
 *        Job location ) 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode(2/3)) Name of drop down lists "state/province"
 * @param cityCode Name of the first drop down list "city"
 * @param defaultOption Value of the city should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeProvinceSearch(countryCode, provinceCode, cityCode, defaultOption,
                              tdProvince2, tdProvince3, tdCity2, tdCity3, locationNum,
                              provinceCode2, provinceCode3, citySpan1, citySpan2,
                              citySpan3, type, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  var country=$(countryCode).value;
  var province2;
  if(provinceCode2!=null){
      province2=$(provinceCode2).value;
  }
  var province3;
  if(provinceCode3!=null){
      province3=$(provinceCode3).value;
  }
  
  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  clearSelected($(cityCode));
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  
  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvinceSearch('" + countryCode + "','" + provinceCode + "','" + 
                           cityCode + "','" + defaultOption + "','" + 
                           tdProvince2 + "','" + tdProvince3 + "','" + 
                           tdCity2 + "','" + tdCity3 + "','" + locationNum + "','" +
                           provinceCode2 + "','" + provinceCode3 + "','" + citySpan1 + "','" + 
                           citySpan2 + "','" + citySpan3 + "','" + type +
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  DWRUtil.setValue(citySpan1,'');
  // populate the city drop down list according to province code.
  if('job'==type){
    displayDropDown.getSiteCities4JsSearch(country,province, 
                    function(result){populateData(result, cityCode, defaultOption, callCounter);});
    if(province2==null||province2==""){
      displayDropDown.getSiteStates4JsSearch(country, function(result){populateData(result,provinceCode2,null);});
    }
    if(province3==null||province3==""){
      displayDropDown.getSiteStates4JsSearch(country, function(result){populateData(result,provinceCode3,null);});
    }
       
  }
  else{
    displayDropDown.getCities(province, 
                    function(result){populateData(result, cityCode, defaultOption, callCounter);});
    if(province2==null||province2==""){
      displayDropDown.getProvinces(country, function(result){populateData(result,provinceCode2,null);});
    }
    if(province3==null||province3==""){
      displayDropDown.getProvinces(country, function(result){populateData(result,provinceCode3,null);});  
    }
  }
  // set the state city status.
  setStateStatusSearch(provinceCode,null,null,cityCode,tdProvince2,tdProvince3,tdCity2,tdCity3,locationNum,citySpan1,citySpan2,citySpan3,type);
}

/**
 * When drop down list "state/province" is changed, retrieve and populate corresponding
 * city list to drop down list "city". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5 
 * Page : Simple Search and Advance Search for candidates (Candidate location and
 *        Job location )  
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the province should be selected by default
 * @param type <b>job</b> : Handle drop down lists in "Job" section
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeProvinceSearchOther(countryCode, provinceCode, cityCode, defaultOption,
                                   citySpan, type, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  var provinceText=DWRUtil.getText(provinceCode);
  var country=$(countryCode).value;
  DWRUtil.setValue(citySpan,provinceText);
  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  clearSelected($(cityCode));
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  
  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvinceSearchOther('" + countryCode + "','" + provinceCode + "','" + 
                           cityCode + "','" + defaultOption + "','" + 
                           citySpan + "','" + type + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  
  // populate the city drop down list according to province code.
  if('job'==type){
      displayDropDown.getSiteCities4JsSearch(country,province, 
                      function(result){populateData(result, cityCode, defaultOption, callCounter);});
       setTimeout("selectedList('"+cityCode+"')", 1000);
  }
  else{
      displayDropDown.getCities(province, 
                      function(result){populateData(result, cityCode, defaultOption, callCounter);});
  }
}


 function initializeCountry(countryCode,provinceCode,hpCode,cityCode,hcCode){
  // initalize the status. set the drop down list to disable or not.
  setProvinceCityStatus(countryCode,provinceCode,hpCode,cityCode,hcCode);
}

function addLocation(countryCode,tdProvince,tdCity,tdProvinceCode,tdCityCode,citySpan,type,defaultValue){
  var country=$(countryCode).value;
  $(tdProvince).style.display="";
  $(tdCity).style.display="";    
  clearSelected($(tdCityCode));
  var provinceText=DWRUtil.getText(tdProvinceCode);
  DWRUtil.setValue(citySpan,provinceText);  
  var province = $(tdProvinceCode).options[0].value;
  
  if('job'==type){
   displayDropDown.getSiteCities4JsSearch(country,province, function(result){populateData(result,tdCityCode,defaultValue);});
    setTimeout("selectedList('"+tdCityCode+"')", 1000);
  }
  else{
   displayDropDown.getCities(province, function(result){populateData(result,tdCityCode,defaultValue);});
  }
}

function addLocation2(countryCode,tdProvince,tdCity,tdProvinceCode,tdCityCode,citySpan,type,defaultValue){
  var country=$(countryCode).value;
  $(tdProvince).style.display="";
  $(tdCity).style.display="";    
  clearSelected($(tdCityCode));
  var provinceText=DWRUtil.getText(tdProvinceCode);
  DWRUtil.setValue(citySpan,provinceText);  
  var province = $(tdProvinceCode).options[0].value;
  
  if('job'==type){
   displayDropDown.getSiteCities4JsSearch(country,province, function(result){populateData(result,tdCityCode,defaultValue);});
  }
  else{
   displayDropDown.getCities(province, function(result){populateData(result,tdCityCode,defaultValue);});
  }
}



function setProvinceStatus(provinceCode,hpCode,cityCode,hcCode){
  var province=$(provinceCode).value;
  // if the province is "Select", we need disable the city drop down list.
  if (province == null || province == ""){
    $(cityCode).disabled=true;
    $(hcCode).disabled=false;
  }
  else{
    $(cityCode).disabled=false;
    $(hcCode).disabled=true;
  }
}

/**
 * When drop down list "country" is changed, retrieve and populate corresponding
 * province list to drop down list "state/province". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5 
 * Page : seeker job location/salary information 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param hpCode 
 * @param cityCode Name of drop down list "city"
 * @param hcCode 
 * @param defaultOption Value of the province should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeCountryLocation(countryCode, provinceCode, hpCode, cityCode, hcCode,
                               defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var country=$(countryCode).value;
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the province.
  $(provinceCode).selectedIndex = 0;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(provinceCode);
  }
  
  if (!($(provinceCode) && $(provinceCode).length && $(provinceCode).length > 0)) {

      var retryFunction = "changeCountryLocation('" + countryCode + "','" + provinceCode + "','" + 
                           hpCode + "','" + cityCode + "','" + 
                           hcCode + "','" + defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  
  // populate the province drop down list according to country code.
  displayDropDown.getSiteStates4Js(country, 
                  function(result){populateData(result, provinceCode, defaultOption, callCounter);});
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the empty city drop down list 
  populateData(null,cityCode,defaultOption);
  // set the country state status.
  setProvinceCityStatus(countryCode,provinceCode,hpCode,cityCode,hcCode);
}

function setProvinceCityStatus(countryCode,provinceCode,hpCode,cityCode,hcCode){
  var country=$(countryCode).value;

  // if country is "Select", we need disable the province and city drop down list.
  if (country == null || country == ""){
    $(provinceCode).disabled=true;
    $(cityCode).disabled=true;
    $(hpCode).disabled=false;
    $(hcCode).disabled=false;
  }
  else if($(provinceCode) == null || $(provinceCode).value == ""){
    $(provinceCode).disabled=false;
    $(cityCode).disabled=true;
    $(hpCode).disabled=true;
    $(hcCode).disabled=false;
  }
  else {
    $(provinceCode).disabled=false;
    $(cityCode).disabled=false;
    $(hpCode).disabled=true;
    $(hcCode).disabled=true;
  }
  //setProvinceStatus(provinceCode,hpCode,cityCode,hcCode);
}

/**
 * When drop down list "state/province" is changed, retrieve and populate corresponding
 * city list to drop down list "city". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. Now the max times of recursive call is 4, which means 
 * the max times of call on this function is 5
 * Page : seeker job location/salary information 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param hpCode 
 * @param cityCode Name of drop down list "city"
 * @param hcCode 
 * @param defaultOption Value of the city should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeProvinceLocation(countryCode, provinceCode, hpCode, cityCode, hcCode,
                                defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  
  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvinceLocation('" + countryCode + "','" + provinceCode + "','" + 
                           hpCode + "','" + cityCode + "','" + 
                           hcCode + "','" + defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the city drop down list according to province code.
  displayDropDown.getSiteCities4Js($(countryCode).value,province, 
                  function(result){populateData(result, cityCode, defaultOption, callCounter);});
  // set the state city status.
  setProvinceStatus(provinceCode,hpCode,cityCode,hcCode);
}
function debug(){
    alert("It's me! --brainhunter.js");
}

function enterPLConfiguration(){
   var id = document.forms[0].clientId.value;
   document.location = 'enterPLConfiguration.do?clientId='+id;
}

function enterTLVMSOPtions(){
   var query = document.forms[0].query.value;
   document.location = 'enterTalentFlowVMSOptionsAction.do?'+query;
}


  function moveToList(LeftList,RightList) {
    for (var i = LeftList.length - 1; i >= 0; i--) {
        if ( LeftList.options[i].selected) {
            var option0 = new Option( LeftList.options[i].text,
                                      LeftList.options[i].value);
            option0.selected = true;
            var temp = 0;
            for (var j = RightList.length - 1; j >= 0; j--) {
                if(option0.value == RightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                RightList.options[RightList.length] = option0;
            }
            
         //   LeftList.options[i] = null;
        }
     }

     for (var i =  RightList.length - 1; i >= 0; i--) {
         RightList.options[i].selected = true;
     }
  }

  function moveToListDel(LeftList,RightList) {
    for (var i = LeftList.length - 1; i >= 0; i--) {
        if ( LeftList.options[i].selected) {
            var option0 = new Option( LeftList.options[i].text,
                                      LeftList.options[i].value);
            option0.selected = true;
            var temp = 0;
            for (var j = RightList.length - 1; j >= 0; j--) {
                if(option0.value == RightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                RightList.options[RightList.length] = option0;
            }
            
            LeftList.options[i] = null;
        }
     }

     for (var i =  RightList.length - 1; i >= 0; i--) {
         RightList.options[i].selected = true;
     }
  }

  function moveToListDelCross(LeftList,RightList,crossList) {

    for (var i = LeftList.length - 1; i >= 0; i--) {
        if ( LeftList.options[i].selected) {
           for (var j = crossList.length - 1; j >= 0; j--) {
                if(LeftList.options[i].value == crossList[j].value ){
                    crossList.options[j] = null;
                }
            }
        }
    }
    for (var i = LeftList.length - 1; i >= 0; i--) {
        if ( LeftList.options[i].selected) {
            var option0 = new Option( LeftList.options[i].text,
                                      LeftList.options[i].value);
            option0.selected = true;
            var temp = 0;
            for (var j = RightList.length - 1; j >= 0; j--) {
                if(option0.value == RightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                RightList.options[RightList.length] = option0;
            }
            
            LeftList.options[i] = null;
        }
     }

     for (var i =  RightList.length - 1; i >= 0; i--) {
         RightList.options[i].selected = true;
     }
  }

  function moveToWholeList(leftList,rightList){
       var rightLength = rightList.length;
       for(var i = leftList.length - 1;i > -1;-- i){
            var option0 = new Option(leftList[i].text,
                                                    leftList[i].value);
           option0.selected = true;
            var temp = 0;
            for (var j = rightList.length - 1; j >= 0; j--) {
                if(option0.value == rightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                rightList.options[rightList.length] = option0;
            }

        }
        for (var i =  rightList.length - 1; i >= 0; i--) {
         rightList.options[i].selected = true;
       }
    }

    function moveWholeListDelCross(leftList,rightList,crossList){
          var rightLength = rightList.length;
           for (var i = leftList.length - 1; i >= 0; i--) {
           for (var j = crossList.length - 1; j >= 0; j--) {
                if(leftList.options[i].value == crossList[j].value ){
                    crossList.options[j] = null;
                }
            }
      }
          for(var i = leftList.length - 1;i > -1;-- i){
           var option0 = new Option(leftList[i].text,
                                                    leftList[i].value);
            leftList[i] = null;
            option0.selected = true;
            var temp = 0;
            for (var j = rightList.length - 1; j >= 0; j--) {
                if(option0.value == rightList[j].value ){
                    temp = 1;
                    break;
                }
            }
            if(temp == 0){
                rightList.options[rightList.length] = option0;
            }

        }
        for (var i =  rightList.length - 1; i >= 0; i--) {
         rightList.options[i].selected = true;
       }
    }

//for slip 9388
function deleteOtherDegree(degreeCode){
        displayDropDown.deleteOtherDegree(degreeCode);
}

function ltrim(s){
    return s.replace( /^\s*/, ""); 

}

function rtrim(s){
    return s.replace( /\s*$/, "");
}

function trim(s){
    return rtrim(ltrim(s));
}


 function initializeCountryForSeeker(countryCode,provinceCode,cityCode){
  // initalize the status. set the drop down list to disable or not.
  setProvinceCityStatusForSeeker(countryCode,provinceCode,cityCode);
}

function setProvinceCityStatusForSeeker(countryCode,provinceCode,cityCode){
   var country=$(countryCode).value;

  // if country is "Select", we need disable the province and city drop down list.
  if (country == null || country == ""){
    $(provinceCode).disabled=true;
    $(cityCode).disabled=true;
  }
  else if($(provinceCode) == null || $(provinceCode).value == ""){
    $(provinceCode).disabled=false;
    $(cityCode).disabled=true;
  }
  else {
    $(provinceCode).disabled=false;
    $(cityCode).disabled=false;
  }
}




function changeCountryLocationForSeeker(countryCode, provinceCode, cityCode,
                               defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var country=$(countryCode).value;
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the province.
  $(provinceCode).selectedIndex = 0;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(provinceCode);
  }



  if (!($(provinceCode) && $(provinceCode).length && $(provinceCode).length > 0)) {

      var retryFunction = "changeCountryLocationForSeeker('" + countryCode + "','" + provinceCode + "','"+ cityCode + "','" + defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  
  // populate the province drop down list according to country code.
  displayDropDown.getSiteStates4Js(country, 
                  function(result){populateDataForSeeker('C',result, provinceCode, defaultOption, callCounter);});
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the empty city drop down list 
  populateDataForSeeker('',null,cityCode,defaultOption);
//         changeProvinceLocationForSeeker('countryCode','provinceCode','cityCode','ALL');

  // set the country state status.
  setProvinceCityStatusForSeeker(countryCode,provinceCode,cityCode);
}

function changeProvinceLocationForSeeker(countryCode, provinceCode, cityCode,
                                defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  

  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvinceLocationForSeeker('" + countryCode + "','" + provinceCode + "','"  + cityCode + "','"  + defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  

  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the city drop down list according to province code.
   displayDropDown.getSiteCities4Js($(countryCode).value,province, 
                  function(result){populateDataForSeeker('P',result, cityCode, defaultOption, callCounter);});
  setTimeout("selectedList('cityCode')", 500);

  // set the state city status.
  setProvinceCityStatusForSeeker(countryCode,provinceCode,cityCode);
}


function populateDataForSeeker(flag,result, dropDownName, defaultOption, callCounter){

  // remove all existing drop down options.
  DWRUtil.removeAllOptions(dropDownName);
  if (callCounter) {
      window.status = "Retrieve " + dropDownName + " for the " + callCounter + " time .. ...";
  }
//alert(result)
  // add "Select" option into the drop down 
  if((result == null || result == '' ) ){
          DWRUtil.addOptions(dropDownName,[{ name:defaultOption, id:'' }],'id','name');
  }else{
      
     if(result.length > 1 && result[0].value != '0'){
        
       DWRUtil.addOptions(dropDownName,[{ name:defaultOption, id:'' }],'id','name');
     }else if(flag=='C' ){
         
         setTimeout("changeProvinceLocationForSeeker('countryCode','provinceCode','cityCode','ALL')",500);
     }
  }
  
  // add options into the drop down 
  DWRUtil.addOptions(dropDownName,result,"value","label");

}

function selectedList(name){
   var cityCode = document.getElementById(name);
   if(cityCode != null){
       cityCode.options[0].selected=true;
   }
}

 function initializeCountryForJob(countryCode,provinceCode,hpCode,cityCode,hcCode){
  // initalize the status. set the drop down list to disable or not.
  setProvinceCityStatusForJob(countryCode,provinceCode,hpCode,cityCode,hcCode);
}



function setProvinceStatusForJob(provinceCode,cityCode){
  var province=$(provinceCode).value;
  // if the province is "Select", we need disable the city drop down list.
  if (province == null || province == ""){
    $(cityCode).disabled=true;
  }
  else{
    $(cityCode).disabled=false;
  }
}

/**
 * When drop down list "country" is changed, retrieve and populate corresponding
 * province list to drop down list "state/province". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked.  
 * Page : Job Requisition Builder / Add Template 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the province should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeCountryLocationForJob(countryCode, provinceCode, cityCode,
                               defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var country=$(countryCode).value;
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the province.
  $(provinceCode).selectedIndex = 0;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(provinceCode);
  }
  
  if (!($(provinceCode) && $(provinceCode).length && $(provinceCode).length > 0)) {

      var retryFunction = "changeCountryLocationForJob('" + countryCode + "','" + provinceCode + "','" + 
                          cityCode + "','" + 
                           defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
  
  // populate the province drop down list according to country code.
  displayDropDown.getSiteStates4Js(country, 
                  function(result){populateData(result, provinceCode, defaultOption, callCounter);});
  // when we change country, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the empty city drop down list 
  populateData(null,cityCode,defaultOption);
  // set the country state status.
  setProvinceCityStatusForJob(countryCode,provinceCode,cityCode);
}

function setProvinceCityStatusForJob(countryCode,provinceCode,cityCode){
  var country=$(countryCode).value;

  // if country is "Select", we need disable the province and city drop down list.
  if (country == null || country == ""){
    $(provinceCode).disabled=true;
    $(cityCode).disabled=true;
  }
  else if($(provinceCode) == null || $(provinceCode).value == ""){
    $(provinceCode).disabled=false;
    $(cityCode).disabled=true;
  }
  else {
    $(provinceCode).disabled=false;
    $(cityCode).disabled=false;
  }
  //setProvinceStatus(provinceCode,hpCode,cityCode,hcCode);
}

/**
 * When drop down list "state/province" is changed, retrieve and populate corresponding
 * city list to drop down list "city". At the same time, process
 * city section accordingly. If the current call of this function fails, a recursive
 * call will be invoked. 
 * Page : Job Requisition Builder / Add Template 
 *   
 * @param countryCode Name of drop down list "country"
 * @param provinceCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the city should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeProvinceLocationForJob(countryCode, provinceCode, cityCode,
                                defaultOption, isRetry, callCounter){
  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var province=$(provinceCode).value;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(cityCode);
  }
  
  if (!($(cityCode) && $(cityCode).length && $(cityCode).length > 0)) {

      var retryFunction = "changeProvinceLocationForJob('" + countryCode + "','" + provinceCode + "','" + 
                          cityCode + "','" + 
                          defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  $(cityCode).selectedIndex = 0;
  // populate the city drop down list according to province code.
  displayDropDown.getSiteCities4Js($(countryCode).value,province, 
                  function(result){populateData(result, cityCode, defaultOption, callCounter);});
  // set the state city status.
  setProvinceStatusForJob(provinceCode,cityCode);
}

/**
 * Check or Uncheck all checkboxes belongs to the passed in checkbox group
 * @param ctrlCheckBox The checkbox that controls the status of the checkbox group "ctrledCheckBoxes"
 * @param ctrledCheckBoxes The checkbox group to be controlled
 * @param theForm The HTML form that the checkboxes blong to 
 */ 
function checkUncheckAll(ctrlCheckBox, ctrledCheckBoxes, theForm) {

    if (!ctrledCheckBoxes) return;
    
    if (!ctrledCheckBoxes.length) {
        ctrledCheckBoxes.checked = ctrlCheckBox.checked;
        return;
    }
    
    if (ctrledCheckBoxes.length > 1) {
        for (var i=0; i<ctrledCheckBoxes.length; i++) {
            ctrledCheckBoxes[i].checked = ctrlCheckBox.checked;
        }
    }
    
    return;
}


/**
 
 *   
 
 * @param planCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the city should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeDurationForPricingPlan( planCode, duration,
                                defaultOption, isRetry, callCounter){

  // Add for slip 9028
  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
  
  var planCodeValue=planCode.value;
  
  // Add for slip 9028
  if (!isRetry) {
      // remove all existing drop down options.
      DWRUtil.removeAllOptions(duration);
  }
  
  if (!(duration && duration.length && duration.length > 0)) {

      var retryFunction = "changeDurationForPricingPlan('" + planCodeValue + "','" + 
                          duration + "','" + 
                          defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }

  //when we change province, we need set the selected Index of city code to zero. it means user need rechoose the city.
  duration.selectedIndex = 0;
  // populate the city drop down list according to province code.
  displayDropDown.getPricingPlanDurations(planCodeValue, 
                  function(result){populateData(result, duration, defaultOption, callCounter);});
  
}


/**
 
 *   
 
 * @param planCode Name of drop down list "state/province"
 * @param cityCode Name of drop down list "city"
 * @param defaultOption Value of the city should be selected by default
 * @param isRetry Flag of whether the current call comes from a recursive call
 * @param callCounter The counter of times of call on this function
 */
function changeJobClassification( parentContent, 
                                defaultOption, isRetry, callCounter){

  if (!callCounter) {
      callCounter = 1;
  } else if (callCounter > RETRY_TIMES) {
      return;
  }
 
  var contentId = parentContent.value ;
  
  var flag =  document.getElementById("content_retrieved");

  if (!isRetry) {   
     flag.value='';
  } 

  if (!(flag && flag.value == 'Y' )) {

      var retryFunction = "changeJobClassification('" + parentContent + "','" +  
                          defaultOption + 
                           "',true," + (callCounter+1) + ")";
      
      setTimeout(retryFunction, RETRY_INTERVAL);
  } else if (isRetry) {
      return;
  }
 
  // populate the city drop down list according to province code.
  displayDropDown.retrieveContentsByParent(contentId, 
                  function(result){populateTrackingFields(result,  defaultOption, callCounter);});
  
}

function populateTrackingFields(result, defaultOption, callCounter){

  var flag = document.getElementById("content_retrieved").value = "Y";

  if (callCounter) {
      window.status = "Retrieve " +  " for the " + callCounter + " time .. ...";
  }
    
  ar = result.split('@%@&');  

  for( i=0; i<ar.length; i++)   {
    ar2 = ar[i].split('=');
    obj = document.getElementById('tagName' + ar2[0]);
    if(obj)    
        obj.value = ar2[1];
  }

 

}

function openDateWindow(id) {
        flagId=id;
        window.open('jsp/Calendar.jsp?locale='+document.getElementById('currentLocale').value,'DateWindow','width=350,height=250,resizable=yes,scrollbars=yes');
}

function setDate(v){
        var obj = document.getElementById(flagId);
        obj.value=v;
}


 
