/* Event Functions */

//String prototype.trim = function() {
//    a = this.replace(/^\s+/, '');
//    return a.replace(/\s+$/, '');
//}


function goToLocation(loc){
   var expandedLoc = getExpanded(loc);
//alert(expandedLoc);
   elements = expandedLoc.split(", ");
   var suburb = elements[0].replace(" ", "-");
   var state = elements[1];
	 if(expandedLoc == "Not Found") {
	    alert("Please enter a valid suburb in the location field"); }
	 else {
      window.location.href ="/suburb/" + state + "/" + suburb + "/restaurants.html";
	 }
}


function getExpanded(loc){
   loc = loc.replace(/\s\s*$/, '');  // trim off trailing spaces
   var i = 0;
	 var inputLength = loc.length;			 
	 var locationFound = false;
	 var expandedLoc = "Not Found";
	 while(locationFound == false && i < customarray.length) {
      if (loc.toLowerCase() ==  customarray[i].substr(0,inputLength).toLowerCase()){
			   locationFound = true;
				 expandedLoc = customarray[i];
			}
	    i++;   
   }
	 if (inputLength < 1) expandedLoc = "Not Found";
   return expandedLoc;
}
