﻿function onEnterKeyPress(e, ctrlID)
      {
        var city = "";
        var state = "";
                     
        if(window.event) // IE
           {
             if (e.keyCode==13)
             {                     
                 if(ctrlID=="btnLocator")
                   {
                     city = document.getElementById("txtCity").value;
                     state = document.getElementById("txtState").value;
//                     alert(state);
                   }
                 else 
                   {
                     city = document.getElementById("txtCity2").value;
                     state = document.getElementById("txtState2").value;
                   }
                  
                 if(city.length>0 && state.length>0)
                     {
                       document.getElementById(ctrlID).focus();
                     }
                 else
                     {
                         alert("Please enter a city or zip and select a state.");
                     }
              }
           }
        else if(e.which) // Netscape/Firefox/Opera
          {
             if (e.which==13)
              {
                 if(ctrlID=="btnLocator")
                   {
                     city = document.getElementById("txtCity").value;
                     state = document.getElementById("txtState").value;
                   }
                 else 
                   {
                     city = document.getElementById("txtCity2").value;
                     state = document.getElementById("txtState2").value;
                   }
                  
                     if(city.length>0 && state.length>0)
                     {
                       document.getElementById(ctrlID).focus();
                     }
                     else
                     {
                         alert("Please enter a city or zip and select a state.");
                     }
              }
          }
      }   
      
function fncLocatorSearch()
    {
            var locatorSearch = document.getElementById("txtCity").value + "|" + document.getElementById("txtState").value;

            ws_Meineke.setLocatorSearch(locatorSearch, test);
        }

        function test(arg) { if ((arg == true) || (arg == 'true')) { window.location = "locator/centerLocator.aspx"; } else { alert("You must select a valid city or zip and state!"); } }  //{ window.location = "http://localhost:49369/meineke/locator/centerLocator.aspx"; } }

        function fncLocatorSearch_loc() {
            var locatorSearch = document.getElementById("txtCity").value + "|" + document.getElementById("txtState").value;

            ws_Meineke.setLocatorSearch(locatorSearch, test2);
        }

        function test2(arg) { if ((arg == true) || (arg == 'true')) { window.location = "centerlocator.aspx"; } else { alert("You must select a valid city or zip and state!"); } }

    function fncLocatorSearch_() {
        var locatorSearch = document.getElementById("txtCity").value + "|" + document.getElementById("txtState").value;
        ws_Meineke.setLocatorSearch(locatorSearch, test_);
    }

    function test_(arg) { if ((arg == true) || (arg == 'true')) { window.location = "../locator/centerlocator.aspx"; } else { alert("You must select a valid city or zip and state!"); } }
       
    
    function fncLocatorTextClick(strSearchValue)
    {
        if (strSearchValue == "City")
        {
            document.getElementById("txtLocatorSearch").value = "";
        }
    }
    
    function fncLocatorTextBlur(strSearchValue)
    {
        if (strSearchValue == "")
        {
            document.getElementById("txtLocatorSearch").value = "City";
        }
    }
    
function validateSearchAddress(strCriteria)
    {
            var usZip =  /(^\d{5}$)|(^\d{5}-\d{4}$)/;
            var caZip = /[a-zA-Z]{1}\d{1}[a-zA-Z](\-| |)\d{1}[a-zA-Z]\d{1}$/;
    
      if (usZip.test(strCriteria) || caZip.test(strCriteria))
      {
//        alert('Please enter City and State.');
        return true;
      }
      else {return false;}
    }

    
function onEnter(inField, e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13)
    {
        if (inField.id == "txtLocatorSearch")
        {
            //fncLocatorSearch(inField.value);
            event.returnValue = false;
        }
        
    }
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}

	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

function queryString(key)
{
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
