function initStndOtherParams(obj){
                var stndArray = new Array("stndCounty","stndZip","stndName");
                for (i = 0; i < stndArray.length; i++){
                    if (obj.name != stndArray[i]){
                        if (stndArray[i] == "stndCounty"){
                           document.stndForm.stndCounty.selectedIndex = 0;
                        }
                        else {
                             document.stndForm.elements[stndArray[i]].value = "";
                        }
                    }
                }
                clearMultiAddrDivs();
        }

        function initLocOtherParams(obj){
                 if (obj.name == "locZip5"){
                     with (document.locForm){
                          locAddress.value = "";
                          locCity.value = "";
                          locZip.value = "";
                     }
                 }
                 else {
                      if (document.locForm.locZip5.value != ""){
                         document.locForm.locZip5.value = "";
                      }
                 }
                 clearMultiAddrDivs();

        }

        function clearMultiAddrDivs(){
                 if (document.getElementById && document.getElementById('multiAddrDiv1')!= null){
                    document.getElementById('multiAddrDiv1').innerHTML = '';
                 }
                 if (document.getElementById && document.getElementById('multiAddrDiv2')!= null){
                    document.getElementById('multiAddrDiv2').innerHTML = '';
                 }
                 if (document.getElementById && document.getElementById('multiAddrDiv3')!= null){
                    document.getElementById('multiAddrDiv3').innerHTML = '';
                 }
        }

        function showMultiAddrDivs(){
                 show('multiAddrDiv1');
                 show('multiAddrDiv2');
                 show('multiAddrDiv3');
        }

        function selectAddr(addr,geox,geoy,matchscore,matchtype){
                 with (document.locForm){
                      RAF_Address.value = addr;
                      RAF_GeoX.value = geox;
                      RAF_GeoY.value = geoy;
                      RAF_MatchScore.value = matchscore;
                      RAF_MatchType.value = matchtype;
                      action = "facListings.jsp";
                      submit();
                 }
        }

        function onLoadTrigger(){
                 try {
                     var addrListLength = getCookie("addrListLen");
                     if (addrListLength == "null" || addrListLength == "0"){
                        clearMultiAddrDivs();
                     }
                     else {
                          if (parseInt(addrListLength) > 1){
                             showMultiAddrDivs();
                          }
                      }
                 }
                 catch (err){}

                 if (document.getElementById && document.getElementById('focusDiverter')!= null){
                    document.getElementById('focusDiverter').focus();
                 }
        }

        function validateLocFormParams(){
                 with (document.locForm){
                      var ZipRegEx = new RegExp(/^\d{5}$/);

                      if (locAddress.value == "" && locZip5.value == ""){
                         alert("Please choose either the Zip code or Address options");
                         locZip5.focus();
                         return false;
                      }

                      //Validate Zip5
                      if (locZip5.value != ""){
                         if (!locZip5.value.match(ZipRegEx)){
                            alert("Zip must be a 5 digit number");
                            locZip5.focus();
                            return false;
                         }
                      }

                      //Validate Address, City, Zip
                      if (locAddress.value != ""){
                         if (locAddress.value.charAt(0) == " "){
                            alert("Enter the Address from the starting position");
                            locAddress.focus();
                            return false;
                         }
                         else {
                              if (locAddress.value.indexOf(".") != -1){
                                 locAddress.value = locAddress.value.replace(/[\.]/g,"");
                              }
                              if (locAddress.value.indexOf(",") != -1){
                                 locAddress.value = locAddress.value.replace(/[\,]/g,"");
                              }
                              if (locAddress.value.indexOf("&") != -1){
                                 locAddress.value = locAddress.value.replace(/[\&]/g,"and");
                              }
                              var AddrRegEx = new RegExp(/[\@\$\#\%\*\(\)\+\=\!\~\`\?\/\^\{\[\}\]\:\;\\"\<\>\|\\]/);
                              if (locAddress.value.match(AddrRegEx)){
                                 alert("Special characters are not allowed in the Address");
                                 locAddress.focus();
                                 return false;
                              }
                              AddrRegEx = null;
                         }
                         if (locZip.value == "" && locCity.value == ""){
                            alert("Either Street, City or Street, Zip are required");
                            locCity.focus();
                            return false;
                         }
                         if (locCity.value != ""){
                            if (locCity.value.charAt(0) == " "){
                                alert("Enter the City from the starting position");
                                locCity.focus();
                            }
                            else {
                                  if (locCity.value.indexOf(".") != -1){
                                     locCity.value = locCity.value.replace(/[\.]/g,"");
                                  }
                                  if (locCity.value.indexOf(",") != -1){
                                     locCity.value = locCity.value.replace(/[\,]/g,"");
                                  }
                                  var CityRegEx = new RegExp(/[\&\@\$\#\%\*\(\)\+\=\!\~\`\?\'\/\^\{\[\}\]\:\;\\"\<\>\|\\]/);
                                  if (locCity.value.match(CityRegEx)){
                                     alert("Special characters are not allowed in the City");
                                     locCity.focus();
                                     return false;
                                  }
                                  CityRegEx = null;
                            }
                         }
                         if (locZip.value != ""){
                            if (!locZip.value.match(ZipRegEx)){
                               alert("Zip must be a 5 digit number");
                               locZip.focus();
                               return false;
                            }
                         }

                      }
                 }
                 return true;
        }

        function validateStndFormParams(){
                with (document.stndForm){
                      var ZipRegEx = new RegExp(/^\d{5}$/);
                      if (stndCounty.selectedIndex == 0 && stndZip.value == "" && stndName.value == ""){
                         alert("Either County or Zip or Name is required");
                         return false;
                      }
                      if (stndZip.value != ""){
                          if (!stndZip.value.match(ZipRegEx)){
                             alert("Zip must be a 5 digit number");
                             stndZip.focus();
                             return false;
                          }
                      }
                      if (stndName.value != ""){
                         if (stndName.value.charAt(0) == " "){
                            alert("Enter the Name from starting position");
                            stndName.focus();
                            return false;
                         }
                         else {
                              var NameRegEx = new RegExp(/[\@\$\#\%\*\(\)\+\=\!\~\`\?\/\^\{\[\}\]\:\;\\"\<\>\|\\]/);
                              if (stndName.value.match(NameRegEx)){
                                 alert("Special characters are not allowed in the Name");
                                 stndName.focus();
                                 return false;
                              }
                              NameRegEx = null;
                         }
                      }
                }
                return true;
        }

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function show(c) {
    if (document.getElementById && document.getElementById(c)!= null)
    node = document.getElementById(c).style.display='';
    else if (document.layers && document.layers[c]!= null)
    document.layers[c].display = '';
    else if (document.all)
    document.all[c].style.display = '';
}
function hide(c) {
    if (document.getElementById && document.getElementById(c)!= null)
    node = document.getElementById(c).style.display='none';
    else if (document.layers && document.layers[c]!= null)
    document.layers[c].display = 'none';
    else if (document.all)
    document.all[c].style.display = 'none';
}
