
// function storeLocator which will populate the values in the dropdown
function storeLocator(pStoreLocationArray){

	var mStoreLocations = new Array();
	mStoreLocations = mStatesArrayWithCodesUSA; // assigning all US states

	var selectedStateAgainstKey = null;	// state variable to store value against the key in the array passed						
	var storeLocationElem = getElement("stores");

	storeLocationElem.options[0] = new Option("Select a State", "");

	for(i = 0; i < pStoreLocationArray.length; i++){
		if(contains(mStoreLocations.getKeys(), pStoreLocationArray[i])){

			var index = inArray(mStoreLocations.getKeys(), pStoreLocationArray[i]); //index which matches the key
			selectedStateAgainstKey = mStoreLocations.getValues()[index];
			//alert("selected state : " + selectedStateAgainstKey + "   n key : " + pStoreLocationArray[i]);
			
			storeLocationElem.options[i+1] = new Option(selectedStateAgainstKey.replace("-",":"), "\""+pStoreLocationArray[i]+"\"");
		}				
	}	
}

//function written to display State Name in the jsp page
function displayStateName(pState){

	var storeLocationElem = getElement("stores");
	if(pState != null && pState != ""){
		if(contains(mStatesArrayWithCodesUSA.getKeys(), pState)){
			var index = inArray(mStatesArrayWithCodesUSA.getKeys(), pState);
			var selectedStateAgainstKey = mStatesArrayWithCodesUSA.getValues()[index];			
			
			var indexOfState = inArray(mStoreLocationArray, pState); //index of states from the array we fetch from droplet
			storeLocationElem.options.selectedIndex = indexOfState + 1; // unit addition because of "Select a State" string.
			disableImg(); //calling disableImg function
		}
		document.write("" + selectedStateAgainstKey.substr(5) + "");
	}
	else
		document.write("There are no stores in this region.");
}

// function to disable/enable the "See Stores" submit Button
function disableImg(){
	var storeLocationElem = getElement("stores");
	var img = getElement("storeImg");	
	
	if(storeLocationElem.options.selectedIndex == 0){
		img.src = "/anthro/images/043009help-liststores-bgda.jpg";
		img.alt = "Please Select a State";
		img.title = "Please Select a State";
		img.onmouseover=null;
		img.onmouseout = null;
		
	}
	else{
		img.src = "/anthro/images/043009help-liststores-bg.jpg";
		img.alt = "List Stores";
		img.title = "List Stores";
		img.onmouseover = function() { this.src="/anthro/images/043009help-liststores-bg.jpg"; }
		img.onmouseout = function() { this.src="/anthro/images/043009help-liststores-bg.jpg"; }
	}

}
