function SetSearch() { 

}
function select_value(Selector) {
   var Field = Selector.name;
   var pos = Selector.name.indexOf("_");

   var Field = Field.substr(0,pos);
   var ValueField = Field + "_hidden";
//document.getElementById('Debug').value = ValueField;
   var Field = document.getElementById(Field);
   Field.value = Selector.options[Selector.selectedIndex].text;
   var ValueField = document.getElementById(ValueField);
   ValueField.value = Selector.options[Selector.selectedIndex].value;
//   document.getElementById(ValueField).value= Selector.options[Selector.selectedIndex].value;
   Selector.style.visibility = "hidden";
}

function open_selector(Obj) {
  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;
        }
      }
    }


    xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState == 4) {
          if(xmlHttp.responseText != 0) {
             var DropDown = Obj.name + "_Selector";
             var Result = Obj.name + "_hidden";
             var Selector = document.getElementById(DropDown);
             Selector.options.length = 0; // Clear the list of options
             var Text = xmlHttp.responseText;
             var OptionText = xmlHttp.responseText.split("|");
             for(var i=0; i < OptionText.length-1; i++) {
                window.status = OptionText[i];
                var pos = OptionText[i].indexOf("###");
                var AreaID = OptionText[i].substr(0,pos);
                var anOption = document.createElement('option') 
                try  {
                     Selector.add(anOption,null); // standards compliant
                } catch(ex) {
                     Selector.add(anOption); // IE only
                }
                  Selector.options[i].text  = OptionText[i].substr(pos+3);
                  Selector.options[i].value = OptionText[i].substr(0,pos);
             }
//             for (var idx=0; idx < document.getElementById('Codes_CountryCode').options.length; idx++) {
//                if (CountryCode == document.getElementById('Codes_CountryCode').options[idx].value) {
//                   document.getElementById('Codes_CountryCode').options[idx].selected=true;
//                }
//             }
           Selector.style.visibility = "visible";
           SearchBox = document.getElementById('Search');
           SearchBoxLeft = findPosX(Obj) - findPosX(SearchBox);
           SearchBoxTop  = findPosY(Obj) - findPosY(SearchBox) + 19;

           Selector.style.left = SearchBoxLeft + "px";
           Selector.style.top  = SearchBoxTop + "px";

//      document.getElementById('Debug').value = Selector.style.left + "|" + Selector.style.top;
          }
       }
      }

      var CountryCode = document.getElementById("Codes_CountryCode").value;
      var AreaCode    = document.getElementById("Codes").value;
      var ACMSLGadget = Obj.name + '_ACMSL';
      var minLen = document.getElementById(ACMSLGadget).value;

      if(AreaCode.length >= minLen) {
// Set the Search Type
             var Mode = "AreaCode";
// Check for Place
             if(isNaN(Obj.value.substr(0,1))) Mode = "Place";

// Test for PostCode
             var pattern = new RegExp("^[A-Z]{1,2}[0-9]{1,2}([A-Z]|\s)?","i");
             if(pattern.test(Obj.value))  {
                 Mode = "PostCode";
             } 
// Set the Mode
                document.getElementById('SearchType').value = Mode;

//    var PostCode    = document.getElementById("PostCode").value;
//    var pos = PostCode.indexOf(" ");
//    if(pos > 0) PostCode = PostCode.substr(0,pos);
      var url = "ajaxGetCode.php?CountryCode=" + CountryCode + "&letters=" + AreaCode + "&Mode=" + Mode;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);

      var DropDown = Obj.name + "_Selector";
      var Selector = document.getElementById(DropDown);

//window.status = DropDown;
      Selector.size = 9;
      }
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
        curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


