/*!*
 *  storelocator.js
 *  22_Webshop
 *
 *  Created on 2007-07-12.
 *  Copyright SinnerSchrader. All rights reserved.
 *
 *  Version 3.0
 */
var map = null, loc = "", gQuery = "", xQuery = "", trafficInfo, storeArray = new Array(), brandshops = new Array(), apiUrl = "/storelocator/SearchForStoresVPAction.do";

/**
 * Initialize and render the map
 */
function load(){
	// console.log("load()");
	
	document.getElementById("noStoreResultListHeader").innerHTML = getMessagesByKey("formError");
	document.getElementById("resultError").style.display = "block";
	
	if (brandshops.length < 1) {
		document.getElementById("drivingDirectionsForm").style.display = "none";
	}
	else {
		document.getElementById("drivingDirectionsForm").style.display = "block";
	}
	
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("googleMap"));
		map.setUIToDefault();
		map.removeMapType(G_SATELLITE_MAP);
		map.removeMapType(G_PHYSICAL_MAP);
		map.addControl(new GMapTypeControl());
		//var ov = new GOverviewMapControl(new GSize(100,100));
		//map.addControl(ov);
		//ov.hide(true);
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		map.enableScrollWheelZoom();
		var trafficOptions = {
			incidents: true
		};
		trafficInfo = new GTrafficOverlay(trafficOptions);
		setMapToCountry();
		if (location.search.length > 0) {
			var params = location.search.split("&");
			for (var i = 0; i < params.length; i++) {
				var paramSplit = params[i].split("=");
				var key = paramSplit[0];
				var value = decodeURI(paramSplit[1].replace(/\+/g, " "));
				if (key == "countryId") 
					document.forms['storelocatorForm'].elements['countryId'].value = value;
				if (key == "location") 
					document.forms['storelocatorForm'].elements['location'].value = value;
			}
			window.setTimeout("waitUntilMapIsLoaded()", 100);
		}
		
		//addlisteners
		GEvent.addDomListener(document.getElementById('storelocatorForm'), "submit", showBrandShops);
		GEvent.addDomListener(document.getElementById('drivingDirectionsForm'), "submit", showDrivingDirectionsForStore);
		GEvent.addDomListener(document.getElementById('backtoresults'), "click", switchToResultView);
		GEvent.addDomListener(document.getElementById('find'), "click", function(){
			this.blur();
		});
		GEvent.addDomListener(document.getElementById('startrouting'), "click", function(){
			this.blur();
		});
	}
}

/**
 * @param form {node} form element
 * @param type {string} "error" or any other value to indicate which color to use
 * highlights the given form element with backgroundcolor fading animation
 * */
function highlightForm(form, type) {
	var dir = form;
	var color = (type == "error") ? "#fae6e6" : "#fbfaca";
	dir.style.backgroundColor = color;
	if(YUI) {
		YUI().use('node', 'anim', function(Y){
			var colorAnim = new Y.Anim({
				node: dir,
				from: {
					backgroundColor: color
				},
				to: {
					backgroundColor: '#fff'
				},
				duration:1.0
			});
			colorAnim.run();
		});
	}
}

/**
 * Checks if the map loaded to avoid JS error.
 * If the map is loaded calls showBrandMaps()
 */
function waitUntilMapIsLoaded(){
	//console.log("waitUntilMapIsLoaded()");
	if (map.isLoaded()) 
		showBrandShops();
	else 
		window.setTimeout("waitUntilMapIsLoaded()", 1000);
}

/**
 * @param {Integer} i The marker number
 * Creates a marker with number
 * @returns A GIcon object
 */
function getMapIcon(i){
	//console.log("getMapIcon()");
	var baseIcon = new GIcon(i);
	//baseIcon.image = "http://www.google.com/intl/de_ALL/mapfiles/marker.png";
	baseIcon.image = "/images/elements/el_gmapmarker_" + i + ".gif";
	baseIcon.shadow = "/images/elements/el_gmapmarker_shadow.png";
	baseIcon.iconSize = new GSize(20.0, 34.0);
	baseIcon.shadowSize = new GSize(34.0, 34.0);
	baseIcon.iconAnchor = new GPoint(10.0, 34.0);
	baseIcon.infoWindowAnchor = new GPoint(13.0, 34.0);
	return baseIcon;
}

/**
 * @param {GLat} lat Latitude of a point
 * @param {Gng} lng Langitude of a point
 * @param {String} bubble HTML code for the info window
 * @param {Integer} storeIter A Id for the marker object
 * @param {Integer} markerId Id for the marker image
 * Adds an marker with info window to map by given coords and saves it to the storeArray.
 */
function insertStoresIntoMap(lat, lng, bubble, storeIter, markerId){
	//console.log("insertStoresIntoMap()");
	var point = new GLatLng(lat, lng);
	var marker = new GMarker(point, getMapIcon(markerId));
	GEvent.addListener(marker, "click", function(){
		marker.openInfoWindowHtml(bubble);
	});
	map.addOverlay(marker);
	storeArray[storeIter] = marker;
}

var locationIcon = new GIcon();
locationIcon.image = "/images/elements/el_gmapmarker_loc.png";
//locationIcon.shadow = "/images/elements/el_gmapmarker_loc_shadow.png";
locationIcon.iconSize = new GSize(21, 20);
//locationIcon.shadowSize = new GSize(32, 33);
locationIcon.iconAnchor = new GPoint(10, 10);
locationIcon.infoWindowAnchor = new GPoint(10, 10);
/**
 * @param {String} address An address
 * Centers the map to the given address
 */
function centerResult(result){
	//console.log("centerRegion()");
	var bounds = new GLatLngBounds(new GLatLng(result.getAttribute('zoomMinLatitude'), result.getAttribute('zoomMinLongitude')), new GLatLng(result.getAttribute('zoomMaxLatitude'), result.getAttribute('zoomMaxLongitude')));
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}

function setMapToCountry(){
	var bounds = new GLatLngBounds(new GLatLng(startMinLatitude, startMinLongitude), new GLatLng(startMaxLatitude, startMaxLongitude));
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}

/**
 * @param {Glat} lat Latitude
 * @param {GLng} long Longitude
 * Add a marker to the map with coords
 */
function placeLocationMarker(lat, lng){
	var marker = new GMarker(new GLatLng(lat, lng), {
		icon: locationIcon,
		clickable: false
	});
	map.addOverlay(marker);
}

function clearMap(){
	map.clearOverlays();
}

/**
 * Clears the Map and result list
 */
function clearResults(){
	//console.log("clearResults()");
	storeArray = new Array();
	clearMap();
	document.getElementById("storeResultListHeader").innerHTML = "";
	document.getElementById("storelocatorResults").innerHTML = "";
	return true;
}

/**
 * @param {String} resultDirectionAddress String with coords of the start point
 * Iterates over the result xml and creates HTML LI nodes in result list
 */
function insertStoresIntoResultListAndGoogleMap(resultDirectionAddress){
	//console.log("insertStoresIntoResultListAndGoogleMap()");
	document.getElementById("storeResultListHeader").innerHTML = getMessagesByKey("resultIntrotext") + getMessagesByKey("resultText");
	var storeIter = 0;
	/*
	 HTML example:
	 <li class="brandshop">
	 <h4>BRAND Store Europapassage</h4>
	 <address>
	 Ballindamm 40<br />20095 Hamburg<br />Tel: +49(0)40/40185994<br />
	 <a href="#" target="_blank">driving directions</a>
	 </address>
	 <p class="distance"><b>Distance<br />from center<br /></b>5,7 km</p>
	 </li>
	 */
	for (var i = 0; i < brandshops.length; i++) {
		//insert in resultlist
		var storeResultListItem = document.createElement("LI");
		storeResultListItem.id = "storelocatorResult" + i;
		if (i % 3 == 0) {
			storeResultListItem.className = "storelocatorResult clear";
		}
		else {
			storeResultListItem.className = "storelocatorResult";
		}
		storeResultListItem.onclick = new Function("openStoreInfo('" + i + "');");
		var storeResultListItemH4 = document.createElement("H4");
		storeResultListItemH4.appendChild(document.createTextNode(brandshops[i].getAttribute('title')));
		if (brandshops[i].getAttribute('brandShop') == "true") {
			// storeResultListItem.className = "brandshop";
			storeResultListItemH4.style.backgroundImage = "url(/images/icons/ic_brandshop_small.gif)";
			storeResultListItemH4.style.backgroundRepeat = "no-repeat";
		}
		else {
			storeResultListItemH4.style.backgroundImage = "url(/images/icons/ic_numbers_" + (++storeIter) + ".gif)";
			storeResultListItemH4.style.backgroundRepeat = "no-repeat";
		}

		var storeResultListItemP = document.createElement("P");
		storeResultListItemP.className = "distance";
		storeResultListItemP.innerHTML = getMessagesByKey("distance") + ' ';
		storeResultListItemP.innerHTML += getMessagesByKey("fromCenter") + ': ';
		storeResultListItemP.innerHTML += "<span>" + brandshops[i].getAttribute('distanceKm') + " " + getMessagesByKey("km") + "</span>";
		
		
		var storeResultListItemAddress = document.createElement("ADDRESS");
		if (brandshops[i].getAttribute('address1') != "") {
			storeResultListItemAddress.appendChild(document.createTextNode(brandshops[i].getAttribute('address1')));
			storeResultListItemAddress.appendChild(document.createElement("BR"));
		}
		if (brandshops[i].getAttribute('address2') != "") {
			storeResultListItemAddress.appendChild(document.createTextNode(brandshops[i].getAttribute('address2')));
			storeResultListItemAddress.appendChild(document.createElement("BR"));
		}
		if (brandshops[i].getAttribute('address3') != "") {
			storeResultListItemAddress.appendChild(document.createTextNode(brandshops[i].getAttribute('address3')));
			storeResultListItemAddress.appendChild(document.createElement("BR"));
		}
		if (brandshops[i].getAttribute('zip') != "" && brandshops[i].getAttribute('city') != "") {
			storeResultListItemAddress.appendChild(document.createTextNode(brandshops[i].getAttribute('zip') + " "));
			storeResultListItemAddress.appendChild(document.createTextNode(brandshops[i].getAttribute('city')));
			storeResultListItemAddress.appendChild(document.createElement("BR"));
		}
		if (brandshops[i].getAttribute('phone') != "") {
			storeResultListItemAddress.appendChild(document.createTextNode(getMessagesByKey("tel") + ": " + brandshops[i].getAttribute('phone')));
		}
		/*
		if(brandshops[i].getAttribute('fax') != "") {
			storeResultListItemAddress.appendChild(document.createElement("BR"));
			storeResultListItemAddress.appendChild(document.createTextNode(getMessagesByKey("fax") + ": " + brandshops[i].getAttribute('fax')));
		}
		 */
	   
		storeResultListItem.appendChild(storeResultListItemH4);
		storeResultListItem.appendChild(storeResultListItemP);
		storeResultListItem.appendChild(storeResultListItemAddress);
	   
		if (brandshops[i].getAttribute('catAccessories') == "true" ||
		brandshops[i].getAttribute('catKonfektion') == "true" ||
		brandshops[i].getAttribute('catOutdoor') == "true" ||
		brandshops[i].getAttribute('catStrickUndShirt') == "true") {
			var storeResultListItemUL = document.createElement("UL");
			storeResultListItemUL.className = "availcats";
			if (brandshops[i].getAttribute('catAccessories') == "true") {
				var storeResultListItemLiMens = document.createElement("LI");
				storeResultListItemLiMens.innerHTML = getMessagesByKey("accessoires");
				storeResultListItemUL.appendChild(storeResultListItemLiMens);
			}
			if (brandshops[i].getAttribute('catKonfektion') == "true") {
				var storeResultListItemLiWomens = document.createElement("LI");
				storeResultListItemLiWomens.innerHTML = getMessagesByKey("konfektion");
				storeResultListItemUL.appendChild(storeResultListItemLiWomens);
			}
			if (brandshops[i].getAttribute('catOutdoor') == "true") {
				var storeResultListItemLiKids = document.createElement("LI");
				storeResultListItemLiKids.innerHTML = getMessagesByKey("outdoor");
				storeResultListItemUL.appendChild(storeResultListItemLiKids);
			}
			if (brandshops[i].getAttribute('catStrickUndShirt') == "true") {
				var storeResultListItemLiGolf = document.createElement("LI");
				storeResultListItemLiGolf.innerHTML = getMessagesByKey("knitAndShirt");
				storeResultListItemUL.appendChild(storeResultListItemLiGolf);
			}
			storeResultListItem.appendChild(storeResultListItemUL);
		}

		if (brandshops[i].getAttribute('directionsAvailable') == "true") {
			var storeResultListItemAnchor = document.createElement("A");
			storeResultListItemAnchor.className = "icon actionLink actionLinkSmall iconFwd iconLeft";
			storeResultListItemAnchor.innerHTML = getMessagesByKey("directions");
			storeResultListItemAnchor.href = "javascript:showDrivingDirectionFields('" + brandshops[i].getAttribute('latitude') + "," + brandshops[i].getAttribute('longitude') + "','" + brandshops[i].getAttribute('title') + ", " + brandshops[i].getAttribute('address1') + "');";
			//http://maps.google.com/maps?f=d&saddr=" + resultDirectionAddress + "&daddr=" + brandshops[i].getAttribute('latitude') + "," + brandshops[i].getAttribute('longitude');
			storeResultListItem.appendChild(storeResultListItemAnchor);
		}
		
		
		document.getElementById("storelocatorResults").appendChild(storeResultListItem);
		//insert into map
		/*var balloonView = "<div class=\"gmBubble\">";
		 balloonView += "<h4>" + brandshops[i].getAttribute('title') + "<\/h4>";
		 if(brandshops[i].getAttribute('shoppingmall') != "")
		 balloonView += "<p>" + brandshops[i].getAttribute('address1') + "<br />";
		 if(brandshops[i].getAttribute('address2') != "")
		 balloonView += brandshops[i].getAttribute('address2') + "<br />";
		 if(brandshops[i].getAttribute('address3') != "")
		 balloonView += brandshops[i].getAttribute('address3') + "<br />";
		 if(brandshops[i].getAttribute('zip') != "" && brandshops[i].getAttribute('city') != "")
		 balloonView += brandshops[i].getAttribute('zip') + " " + brandshops[i].getAttribute('city') + "<\/p>";
		 balloonView += "<\/div>";*/
		var balloonView = '<iframe src="/storelocator/GMapPopupVPAction.do?' + brandshops[i].getAttribute('storeid') + '" style="width:180px;height:130px;" frameborder="0" scrolling="no" ></iframe>';
		var markertype = (brandshops[i].getAttribute('brandShop') == "true") ? 0 : storeIter;
		insertStoresIntoMap(brandshops[i].getAttribute('latitude'), brandshops[i].getAttribute('longitude'), balloonView, i, markertype);
	}
	hideStartIndicator();
	//openStoreInfo('0');
	return false;
}

/**
 * Gets the search results via AJAX and shows suggestion selector if no location a country was found.
 */
function getStoresFromDB(){
	//console.log("getStoresFromDB()");
	var request = GXmlHttp.create();
	request.open("GET", encodeURI(apiUrl + "?" + xQuery), true);
	request.onreadystatechange = function(){
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;
			result = xmlDoc.documentElement;
			if (xmlDoc.documentElement.getAttribute("error") == "close") {
				window.close();
			}
			else 
				if (xmlDoc.documentElement.getAttribute("error") == "true") {
					setMapToCountry();
					document.getElementById("noStoreResultListHeader").innerHTML = "Olsen always wants to provide the best service.<br />Therefore we're currently updating our Olsen Store database.<br /><br />Please try again later.";
					document.getElementById("storelocatorResults").style.display = "none";
					document.getElementById("resultError").style.display = "block";
					hideStartIndicator();
				}
				else {
					brandshops = xmlDoc.documentElement.getElementsByTagName("store");
					if (brandshops.length == 0) {
						setMapToCountry();
						document.getElementById("noStoreResultListHeader").innerHTML = getMessagesByKey("noResultsForAddress");
						document.getElementById("storelocatorResults").style.display = "none";
						document.getElementById("resultError").style.display = "block";
						hideStartIndicator();
					}
					else {
						placeLocationMarker(result.getAttribute('latitude'), result.getAttribute('longitude'));
						document.getElementById("resultError").style.display = "none";
						document.getElementById("storelocatorResults").style.display = "block";
						centerResult(result);
						insertStoresIntoResultListAndGoogleMap(result.getAttribute('latitude') + "," + result.getAttribute('longitude'));
					}
					trackingCountry = xmlDoc.documentElement.getElementsByTagName("stores")[0].getAttribute("countryName");
					trackingQuery = xmlDoc.documentElement.getElementsByTagName("stores")[0].getAttribute("location");
					trackResults();
				}
		}
	}
	request.send(null);
}

/**
 * @param {String} targetgeo The geo address of the store
 * @param {String} targettext The address of the store
 * Doing the routing
 */
function showDrivingDirectionsForStore(){
	if (document.getElementById("startAddress").value == "") {
		// country is not selected
		//document.getElementById('mapFormErrors').style.display = "block";
		document.getElementById("startAddress").focus();
		//document.getElementById("startAddress").className = "input error";
		document.getElementById("startWrap").className = "error inner";
		highlightForm(document.forms['drivingDirectionsForm'], "error");
		document.getElementById('storeResultListHeader').style.display = "none";
		document.getElementById('resultError').style.display = "block";
		return false;
	}
	else {
		//document.getElementById("startAddress").className = "input";
		document.getElementById("startWrap").className = "inner";
	}
	var from = "from: " + document.getElementById("startAddress").value + ", " + document.getElementById("countryId2").value;
	var to = " to: " + document.getElementById('targetGeo').value;
	var route = from + to;
	showStartIndicator();
	switchToDrivingDirectionView();
	directionsPanel = document.getElementById("drivingDirections");
	/*while (directionsPanel.hasChildNodes()) {
		directionsPanel.removeChild(directionsPanel.firstChild);
	}*/
	directionsPanel.innerHTML = "";
	directions = new GDirections(map, directionsPanel);
	directions.load(route);
	GEvent.addListener(directions, "error", handleErrors);
	hideStartIndicator();
	return false;
}

function handleErrors(){
	if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
		//alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		document.getElementById("startAddress").focus();
		//document.getElementById("startAddress").className = "input error";
		document.getElementById("startWrap").className = "error inner";
		//document.getElementById("resultError").style.display = "block";
		highlightForm(document.forms['drivingDirectionsForm'], "error");
		document.getElementById('resultError').style.display = "block";
		document.getElementById('storeResultListHeader').innerHTML = "&nbsp;";
		document.getElementById('storeResultListHeader').style.display = "none";
	}
	else {
		document.getElementById("startWrap").className = "inner";
		document.getElementById("resultError").style.display = "none";
	}
	/*else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	 else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	 else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	 alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	 else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	 else
	 alert("An unknown error occurred.");
	 */
}

/**
 * @param {String} marker The id of a marker
 * Opens the bubble of the marker, when the user clicks a match in the result list
 */
function openStoreInfo(marker){
	//console.log("openStoreInfo()");
	if (storeArray[marker]) {
		GEvent.trigger(storeArray[marker], 'click');
	}
	return false;
}

/**
 * Shows the progress indikator
 */
function showStartIndicator(){
	//console.log("showStartIndicator()");
	document.getElementById('resultError').style.display = "none";
	document.getElementById('storeResultListHeader').style.display = "none";
	document.getElementById('searchstatus').style.display = "block";
	
}

/**
 * Hides the result list of stores
 */
function switchToDrivingDirectionView(){
	clearMap();
	map.addOverlay(trafficInfo);
	document.getElementById('storelocatorResults').style.display = "none";
	document.getElementById('drivingDirections').style.display = "block";
}

/**
 * Shows the driving direction fieldset
 */
function showDrivingDirectionFields(geo, label){
	document.getElementById('targetGeo').value = geo;
	document.getElementById('targetName').firstChild.data = label;
	document.getElementById('storelocatorForm').style.display = "none";
	var dir = document.getElementById('drivingDirectionsForm');
	if (dir.style.display != "block"){
		dir.style.display = "block";
		document.getElementById('startAddress').focus();
	}
	document.getElementById('startWrap').className = "inner";
	highlightForm(dir,"notice");
}

/**
 * Hides the drivingdirections list of stores
 */
function switchToResultView(){
	showBrandShops();
	map.removeOverlay(trafficInfo);
	document.getElementById('drivingDirections').style.display = "none";
	document.getElementById('storelocatorResults').style.display = "block";
	document.getElementById('drivingDirectionsForm').style.display = "none";
	document.getElementById('storelocatorForm').style.display = "block";
	highlightForm(document.getElementById('storelocatorForm'),"notice");
}

/**
 * Hides the progress indikator
 */
function hideStartIndicator(){
	//console.log("hideStartIndicator()");
	document.getElementById('searchstatus').style.display = "none";
	document.getElementById('storeResultListHeader').style.display = "block";
	// document.forms['storelocatorForm'].elements['find'].disabled = false;
}

/**
 * Tracks the user's search
 */
var trackingCountry;
var trackingQuery;
function trackResults(){
	s.prop5 = (trackingCountry + ":" + trackingQuery).toLowerCase();
	s.prop6 = (brandshops && brandshops.length > 0) ? "successful" : "failed";
	void (s.t());
}

/**
 * This function is called by the form.
 * Validates the form, assembles the AJAX request and calls further functions.
 */
function showBrandShops(){
	//console.log("showBrandShops()");
	if (document.getElementById('suggestions')) 
		document.getElementById('location').parentNode.removeChild(document.getElementById('suggestions'));
	var formError = false;
	loc = document.forms['storelocatorForm'].elements['location'].value;
	if (loc == "") {
		// location is empty
		// or not 5 digit number ( /^([0-9])$/.test(loc.charAt(0)) && !/^([0-9]{3,5})$/.test(loc) )
		//document.getElementById("mapFormErrors").firstChild.data = getMessagesByKey("formError");
		//document.getElementById('mapFormErrors').style.display = "block";
		document.forms['storelocatorForm'].elements['location'].focus();
		//document.forms['storelocatorForm'].elements['location'].className = "input error";
		document.getElementById("locationWrap").className = "inner error";
		highlightForm(document.forms['storelocatorForm'], "error");
		formError = true;
	}
	if (document.forms['storelocatorForm'].elements['countryId'].value == "") {
		// country is not selected
		//document.getElementById('mapFormErrors').style.display = "block";
		document.forms['storelocatorForm'].elements['countryId'].focus();
		//document.forms['storelocatorForm'].elements['countryId'].className = "select error";
		document.getElementById("countryWrap").className = "inner error";
		highlightForm(document.forms['storelocatorForm'], "error");
		formError = true;
	}
	if (formError) {
		// document.forms['storelocatorForm'].elements['find'].disabled = false;
		return false;
	}
	if(!formError || formError == "undefined") {
		//document.getElementById('mapFormErrors').style.display = "none";
		document.getElementById("locationWrap").className = "inner";
		document.getElementById("countryWrap").className = "inner";
	}
	else {
		//document.getElementById("mapFormErrors").firstChild.data = '';
		//document.getElementById('mapFormErrors').style.display = "none";
		//document.forms['storelocatorForm'].elements['location'].className = "input";
		//document.forms['storelocatorForm'].elements['countryId'].className = "select";
		document.getElementById("locationWrap").className = "inner";
		document.getElementById("countryWrap").className = "inner";
	}
	gQuery = document.forms['storelocatorForm'].elements['location'].value + ", " + document.forms['storelocatorForm'].elements['countryId'].value;
	xQuery = "countryName=" + document.forms['storelocatorForm'].elements['countryId'].value;
	xQuery += "&location=" + document.forms['storelocatorForm'].elements['location'].value;
	//check for optione
	/*if(document.forms['storelocatorForm'].elements['womens'].checked)  xQuery += "&womens=true";
	 if(document.forms['storelocatorForm'].elements['mens'].checked)	xQuery += "&mens=true";
	 if(document.forms['storelocatorForm'].elements['kids'].checked)	xQuery += "&kids=true";
	 if(document.forms['storelocatorForm'].elements['infants'].checked) xQuery += "&infants=true";*/
	xQuery += "&countryId=" + document.forms['storelocatorForm'].elements['countryId'].value;
	xQuery += "&language=" + document.forms['storelocatorForm'].elements['language'].value;
	//console.log(xQuery);
	//tracking: edit 081114 veileh: values come via ajax from xml now
	//trackingCountry = document.forms['storelocatorForm'].elements['countryId'].value;
	//trackingQuery = document.forms['storelocatorForm'].elements['location'].value;
	showStartIndicator();
	clearResults();
	getStoresFromDB();
	return false;
}

window.onload = load;
window.onunload = GUnload;

