//updated on 2/18/2009

function AppController()
{
//    var ws_url = "/mslo/servlet/MSLO_WS";
	var ws_callback = new WebServiceCallback ();
//    var ws_handler = new WebServiceHandler();
    this.ws = new MSLO_WS (this);
    this.map_controller = new MapController();
    this.points = {};
    this.storeLocationDiv = "mapFoundStores";
    this.firstSearch = true;
    this.didInit = false;
    this.onGoingRequest = false;
    this.batchSize = 5;
    this.currPoint = 0;

}
AppController.prototype.initialize = function(map_div, latitude, longitude, zoom)
{
    if(this.didInit == false){
    	this.map_controller.initialize(map_div, latitude, longitude, zoom);
    	this.didInit = true;
    }
}

AppController.prototype.submitOnEnter = function(field,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	   {
	   this.submitLocator();
	   return false;
	   }
	else
	   return true;

}

function removeAlert(selectBox) {
    
    var prodType = selectBox[selectBox.selectedIndex].value;
    var alertProd = document.getElementById("alert-prod");
    
    if (prodType != 'SelectOne') {
       	alertProd.style.display = "none";
    }
   
}

function removeLocationAlert() {
    var locAlert = document.getElementById("alert-location");
    locAlert.style.display = "none";
}

function disableFields(field) {
	var postCode = document.getElementById("postCode");
    var city = document.getElementById("city");
    var state = document.getElementById("state");
    
    if (field == postCode) {
       	city.disabled = true;
       	state.disabled = true;
    } else if (field == city) {
    	postCode.disabled = true;
    }
}

function enableFields() {
	var postCode = document.getElementById("postCode");
    var city = document.getElementById("city");
    var state = document.getElementById("state");
    city.disabled = false;
    state.disabled = false;
    postCode.disabled = false;
}

function getStoreData(prod, lat, lon, radius, retailer){
		
	var url = "http://lamp.marthastewart.com/store_locator/locator.php?product_type="+prod+"&radius="+radius+"&latitude="+lat+"&longitude="+lon+"&retailer="+retailer+"&callback=?"
	
	$.getJSON(url, function(data) {
		if (data) {
			//$("#store_data").html("<pre>"+data.stores.replace(/\\/g,'\n')+"</pre>");
			store_data = data.stores.replace(/\\/g,'\n');
			MSLO_WS.prototype.ahcReply(store_data);
		} else {
			alert("no data");
		}
		
	});
				
}

AppController.prototype.submitLocator =  function()
{
  
    if(this.onGoingRequest != false)
    {
        return;
    }
    this.onGoingRequest = true;
    var fm = document.getElementById("locator");
    
    var prodAlert = document.getElementById("alert-prod");
    var locAlert = document.getElementById("alert-location");
    var alertMessage = document.getElementById("alert-message");
    
    var postCode = fm.postCode.value;
    var city = fm.city.value;
    var sel = fm.state.selectedIndex;
    var stateprov = fm.state.options[sel].value;
    
    sel = fm.radius.selectedIndex; 
    var radius = fm.radius.options[sel].value;
    
    sel = fm.retailer.selectedIndex;
    var r = fm.retailer.options[sel].value;
    var retailer;
    if(r == "*ALL*")
    {
        retailer = this.ws.ALL_RETAILERS; 
    }
    else
    {
        retailer = r;
    }
    
    sel = fm.product_type.selectedIndex;
    var pt = fm.product_type.options[sel].value;
    var product_type;
    
    if(pt == "SelectOne" && city == "Enter City" && postCode == "Enter ZIP/Postal Code")
    {
    	//mandatory product type check
    	prodAlert.style.display = "block";
    	prodAlert.innerHTML = "Oops, you forgot to select a product type"
    	
    	locAlert.style.display = "block";
    	locAlert.innerHTML = "Oops, you forgot to enter your location"
    	
    	

    	
    	//turn the request off so we don't get stuck
    	this.onGoingRequest = false;
    	
    	return;
    }
    if(pt == "SelectOne") {
    	prodAlert.style.display = "block";
    	prodAlert.innerHTML = "Oops, you forgot to select a product type"
    	this.onGoingRequest = false;
    	var re = /^[a-zA-Z0-9 ]*$/;
    	if(re.test(postCode)!=true){
	    	//if((postCode.toString().search(/^[0-9]+$/) == 0)){
	  			locAlert.style.display = "block";
	    		locAlert.innerHTML = "Please check your ZIP or postal code"
	    		
	    		//turn the request off so we don't get stuck
	    		this.onGoingRequest = false;
	    		
	    	//}
	    }
    	return;
    }
    if(pt == "*ALL*")
    {
        product_type = this.ws.ALL_PRODUCTS; 
    }
    else
    {
        product_type = pt;
    }
    
    var search_key;
    if(postCode != "" && postCode != "Enter ZIP/Postal Code")
    {
    	var re = /^[a-zA-Z0-9 ]*$/;
    	if(re.test(postCode)!=true){
	    	//if((postCode.toString().search(/^[0-9]+$/) == 0)){
	  			locAlert.style.display = "block";
	    		locAlert.innerHTML = "Please check your ZIP or postal code"
	    		
	    		//turn the request off so we don't get stuck
	    		this.onGoingRequest = false;
	    		return;
	    	//}
	    }
    	search_key = postCode;
    }
    else if(city != "" && city != "Enter City")
    {
        search_key = city+", "+stateprov;
    }
    else if(city == "" || city == "Enter City")
  
    {
        locAlert.style.display = "block";
    	locAlert.innerHTML = "Oops, you forgot to enter your location"
        
        //turn the request off so we don't get stuck
    	this.onGoingRequest = false;
    	
        return;
    }


	
    
    
    locAlert.style.display = "none";
    prodAlert.style.display = "none";
    alertMessage.style.display = "none"
    
	// save the values we need to go back to original view
	this.city = city;
	this.postCode = postCode;
	this.radius = radius;
    this.retailer = retailer;
    this.product_type = product_type;

    // reset the divs
    this.setUpFoundStores();
    this.clearNumStoresFound();
    
    if(!MSLO_Lookups.isEtailerOnlyProduct(this.product_type))
    	this.showLoadingMessage();


    //clear the map
    this.map_controller.clearMap();

    this.map_controller.geocoder.getLatLng(
        search_key,
        function(point) {
            if(point){
                app_controller.map_controller.centerOnAddress(point, radius);
                var latitude = point.lat();
                var longitude = point.lng();
                app_controller.saveLatLon(latitude, longitude);
                app_controller.ws.searchStores(latitude, longitude, radius, retailer, product_type);
                getStoreData(product_type, latitude, longitude, radius, retailer);
            }
        }
    );
}

AppController.prototype.saveLatLon = function(latitude, longitude)
{
    this.latitude = latitude;
    this.longitude = longitude;
}

AppController.prototype.buildStoreHTML = function(point, index)
{
	var br = "<br />";
	var src = this.map_controller.getSmallIconFile(point.retailer);
	var storeName = MSLO_Lookups.getRetailerName(point.retailer);

	//replace "Other" with the actual store name
	if(storeName == "Other")
		storeName = point.storeName;
	
	var url = point.webURL;
    //trim the protocol
    url = url.replace(/http:\/\/|https:\/\//, "");
    //find a / or ? to find the end of the url
    var end = url.search(/\/|\?/);
    var shortUrl;
    if(end != -1) {
        //trim everything after .com, .net etc..
        shortUrl = url.slice(0, end);
    } else {
        //there is nothing after .com, .net etc...
        shortUrl = url;
    }
    //add on http for the href 
    url = "http://" + url;

    //performance optimisation
    var htmlbuf = []; 
    htmlbuf.push("<div id='");
    htmlbuf.push(point.div_id);
    htmlbuf.push("' class='mapFoundStoreResult' onclick='app_controller.selectStore("); 
  
 	htmlbuf.push(index);
    /*htmlbuf.push(")' onmouseover='app_controller.highlightStore(");
    htmlbuf.push(index);
    htmlbuf.push(")' onmouseout='app_controller.unHighlightStore(");
    htmlbuf.push(index);
*/
    htmlbuf.push(")'>");
	//htmlbuf.push("<img src='");
   // htmlbuf.push(AppController.imagesURL);
    //htmlbuf.push(src);
    htmlbuf.push("<div class='store-info'><span class='mapFoundStoreRetailer'>");
    
    if(url != "http://"){
    
    htmlbuf.push("<a href='" + url + "' target='_blank'>" + storeName + "</a>");
    
    } else {
    
	htmlbuf.push(storeName + "</span>");
	
	}
	/*htmlbuf.push("</span><br /><span class='mapFoundStoreWeb'><a href='");
	htmlbuf.push(url)
    htmlbuf.push("' target='_blank'>");
	htmlbuf.push(shortUrl);
	htmlbuf.push("</a></span><br /><span class='mapFoundStoreAddress'>");*/
	htmlbuf.push("<br /><span class='mapFoundStoreAddress'>");
    htmlbuf.push(point.address);
	htmlbuf.push("</span><br /><span class='mapFoundStoreAddress2'>");
    htmlbuf.push(point.city);
    htmlbuf.push(", ");
    htmlbuf.push(point.state)
    htmlbuf.push(", ");
    htmlbuf.push(point.postCode)
    htmlbuf.push("<br/></span><span class='mapFoundStorePhone'>");
    htmlbuf.push(point.tel);
    htmlbuf.push("&nbsp&nbsp&nbsp");
    htmlbuf.push(point.hrsOperation); 
    htmlbuf.push("</span><br/>");
    htmlbuf.push("<a href='#' onclick='app_controller.selectStore(");
    htmlbuf.push(index);
    htmlbuf.push(");return false;' class='get-directions'>Get Directions</a></div></div>");

    var html = htmlbuf.join("");
    return html;
}

AppController.prototype.showNumStoresFound = function(count)
{
    var numStores = document.getElementById("numStoreLocations");
    numStores.innerHTML = "Store locations (" + count + ")";
}

var onlineAmount = "";

AppController.prototype.showOnlineStoresFound = function(count) {
    var header = document.getElementById("numOnlineStores");
	var html = "Online retailer (" + count + ")";
	header.innerHTML = html;
	onlineAmount = count;
}

AppController.prototype.showSearchDetails = function(count)
{
	var fm = document.getElementById("locator");
	var header = document.getElementById("mapHeaderP");
	var prodValue = fm.product_type.value;
	//alert(fm.postCode.value);	
	if (fm.postCode.value != "Enter ZIP/Postal Code" && fm.postCode.value != "") {
		var location = fm.postCode.value;
	} else {
		var location = fm.city.value + ", " + fm.state.value;
	}
		
	if(prodValue == "B") { prodType = "Bedding / Bath"; }
	else if(prodValue == "C") { prodType = "Crafts / Party Supplies"; }
	else if(prodValue == "I") { prodType = "Fine China"; }
	else if(prodValue == "F") { prodType = "Flowers"; }
	else if(prodValue == "O") { prodType = "Food"; }
	else if(prodValue == "U") { prodType = "Furniture"; }
	else if(prodValue == "G") { prodType = "Garden/Outdoor"; }
	else if(prodValue == "S") { prodType = "Holiday/Special Occasion"; }
	else if(prodValue == "H") { prodType = "Homes"; }
	else if(prodValue == "D") { prodType = "Home Decor"; }
	else if(prodValue == "K") { prodType = "Kitchen/dinnerware"; }
	else if(prodValue == "L") { prodType = "Lighting"; }
	else if(prodValue == "P") { prodType = "Paint"; }
	else if(prodValue == "T") { prodType = "Photo Cards"; }
	else if(prodValue == "R") { prodType = "Rugs/Floor Tiles"; }
	else if(prodValue == "A") { prodType = "Cleaning Supplies"; }
	else if(prodValue == "E") { prodType = "Pet Products"; }
	
	var allRetailers = onlineAmount + count;
	
	header.innerHTML = allRetailers + " retailers with " + prodType + " within " + fm.radius.value + " miles of " + location;
	
	var alertMessage = document.getElementById("alert-message");

	if (onlineAmount == 0 && count == 0){
		alertMessage.style.display = "block"
		alertMessage.innerHTML = "Sorry, we couldn't find any retailers that matched your search, please try again"
	}
}

AppController.prototype.showLoadingMessage = function()
{
    var numStores = document.getElementById("mapFoundStores");
    numStores.innerHTML = "<img src='"+AppController.imagesURL+"/sl_loading_bt.gif' class='loading_message' />";
}

AppController.prototype.clearLoadingMessage = function()
{
    var numStores = document.getElementById("mapFoundStores");
    numStores.innerHTML = "";
}

AppController.prototype.clearNumStoresFound = function()
{
    var numStores = document.getElementById("numStoreLocations");
    numStores.innerHTML = "";
}

AppController.prototype.showBackToResults = function() {
    var header = document.getElementById("mapHeaderP");
	header.innerHTML = "<a href='#' onclick='app_controller.backToResults();return false;' style='color:#5EC6D5;'>\< Back to Results</a>";
}

AppController.prototype.searchStores = function(message, points)
{
    this.clearLoadingMessage();
    this.onGoingRequest = false;
    this.points = this.sortPointsByProximity(points);
	this.showNumStoresFound(points.length);
	this.showSearchDetails(points.length);
	
    var html = "";
	
    for(var i = 0; i < points.length;i++)
    {
        var marker = this.map_controller.addMarker(points[i], i);
        marker.pointsIndex = i;
        points[i].marker = marker;
        points[i].div_id = "mapstore_"+i;
        html += this.buildStoreHTML(points[i], i);
    }
    var storeList = document.getElementById("mapFoundStores");
    storeList.innerHTML = html;
}
AppController.prototype.sortPointsByProximity =function(points)
{   
    var lat = this.latitude;
    var lon = this.longitude;
    function proximity(p1, p2)
    {
        var latDiff1 = lat - p1.latitude; 
        var lonDiff1 = lon - p1.longitude;
        var latDiff2 = lat - p2.latitude; 
        var lonDiff2 = lon - p2.longitude;
        var diff1 = latDiff1*latDiff1 + lonDiff1*lonDiff1;
        var diff2 = latDiff2*latDiff2 + lonDiff2*lonDiff2;
        if(diff1 > diff2){
            return 1;
        } else if(diff1 < diff2){
            return -1;
        }
        return 0;
    }
    var sorted = points.sort(proximity); 
    return sorted;
}

//may still be used
/*
AppController.prototype.plotNextBatchOnMap = function()
{
    var cp = this.currPoint;
    var bs = this.batchSize;
    var points = this.points;
    for(var i = 0; (i < cp + bs) && (i < points.length);i++)
    {
        var marker = this.map_controller.addMarker(points[i], i);
        marker.pointsIndex = i;
        points[i].marker = marker;
        points[i].div_id = "mapstore_"+i;
        this.addStoreToFoundList(points[i], i);
    }
    if(i < points.length)
    {
        this.currPoint = i;
        //do timeout
        window.setTimeout("app_controller.plotNextBatchOnMap()", 10);
    }
    else
    {
        this.currPoint = 0;
    }
}
*/

AppController.prototype.getStoreAddress = function (index){
	var store = this.points[index];
	var address = store.address + ", " + store.city + " " + store.postCode;
	return address;
}

AppController.prototype.getMarker = function(index){
    return this.points[index].marker;
}

AppController.prototype.selectStore = function(index) {

	//if there was a store already selected, then deselect it
	if(this.selectedStoreIndex != null && this.selectedStoreIndex != index)
		this.deSelectStore(this.selectedStoreIndex);
		
	if (!this.points[index]) return;

	this.highlightStore(index);
	this.map_controller.selectMarker(this.points[index].marker);
	this.selectedStoreIndex = index;
	scrollTo(0,230);
}

AppController.prototype.deSelectStore = function(index) {
	if (!this.points[index]) return;
	this.unHighlightStore(index);
	this.map_controller.deSelectMarker(this.points[index].marker);
}

AppController.prototype.highlightStore = function(index) {
	if (!this.points[index]) return;
	// highlight backgound of store 
	var item = document.getElementById(this.points[index].div_id);
	if (item)
		item.style.backgroundColor="#ebebeb";
}

AppController.prototype.unHighlightStore = function(index) {
	if (!this.points[index]) return;
	var item = document.getElementById(this.points[index].div_id);
	if (item)
		item.style.backgroundColor="#FFFFFF";
}

AppController.prototype.scrollIntoView = function(index) {
	// scroll list to make item visible
	/*var itemHeight = 91;
	var visibleHeight = 0;
	var storeList = document.getElementById("results");
	var max = storeList.scrollHeight;
	var itemBottom = (index + 1) * itemHeight;
	if (itemBottom > storeList.scrollTop + visibleHeight)
		storeList.scrollTop = itemBottom - visibleHeight;
	else {
		var itemTop = index * itemHeight;
		if (itemTop < storeList.scrollTop)
			storeList.scrollTop = itemTop;
	}*/
}

AppController.prototype.backToResults = function() {
    this.map_controller.centerOnAddress(new GLatLng(this.latitude,this.longitude), this.radius); 
	this.setUpFoundStores();
	this.searchStores("return to search", this.points);
	document.getElementById("mapFoundStores2").className = '';
    document.getElementById("mapFoundStores").className = '';
    document.getElementById("results").className = '';
    document.getElementById("numStoreLocations").className = '';
    var onlineStores = document.getElementById("numOnlineStores");
 	onlineStores.style.display = 'block';
 	 var alertMessage = document.getElementById("alert-message");
    alertMessage.style.display = "none";
	this.showSearchDetails(this.points.length);
}

AppController.prototype.getStoreDetails = function(index)
{
	this.setUpDetails(index);

    // show the store details
    this.showDetailsHtml(index);
    // tell the map to show close-up of store
    this.map_controller.detailsZoom(this.points[index].latitude, this.points[index].longitude);
}

AppController.prototype.showDetailsHtml = function(index)
{
    var point = this.points[index];
    var html =  "<div><strong>Directions to:</strong><br /><br />"; 
    if(point.storeName!="")
    {
        html += "<b>" + point.storeName + "</b>";
    }
    if(point.address!="")
    {
        html += "<br />" + point.address;
    }
    if(point.locName!="")
    {
        html += "<br />" + point.locName;
    }
    if(point.city!="" || point.state!="" || point.postCode!="")
    {
        html += "<br />" + point.city + 
                (point.state != ""?", " + point.state:"") + " " + 
                point.postCode; 
    }
    if(point.tel!="")
    {
        html += "<br />" + point.tel;
    }
    
    //verify the url format
    	urlStr ="";
    	urlStrProper="";
    	urlObj = null;
    	if(point.webURL == ""){//no website
    		urlStr ="";
    		urlStrProper = "";
    		urlObj = {protocol:"", host:""};
    	}
    	else{
    		urlStr = ""+point.webURL;
    		urlStrProper = urlStr;
    		urlObj = MSLO_Lookups.parseURL(urlStr);
    	}
    	if(urlObj.protocol != "http://" && urlObj.protocol != "https://"){
			urlStrProper = "http://"+urlStr;
	}
    	
    	//shorten the url to the top level domain name for display only
    	if(urlObj.host !="")
		urlStr = urlObj.host;
	
    if(point.webURL!="")
    {
        html += "<br /><a href='" + urlStrProper + "' target='_blank'>" + 
                urlStr + "</a>";
    }
    if(point.hrsOperation!="")
    {
        html += "<br />" + point.hrsOperation;
    }
	html += "</div>";

    var store = document.getElementById("mapFoundStores");
    store.innerHTML = html;
}

AppController.prototype.print = function() 
{
	// if its a directions view
	if (this.map_controller.showingDirections())
		this.map_controller.printDirections();
	else
		window.print();
}
AppController.prototype.setUpFoundStores = function() 
{
    if(this.firstSearch == true)
    {	
    
    	this.firstSearch = false;
    	var mlc = document.getElementById("mapLeftColumn"); 
    	mlc.style.width="546px";
       
        /*var mfsh = document.getElementById("mapFindStoreHeader"); 
       	mfsh.style.background = "url(" + AppController.imagesURL + "find_store.gif) no-repeat";
    	mfsh.style.height = "39px";
    	
    	var mlcb = document.getElementById("mapLeftColumnBorder"); 
    	mlcb.style.width =  "238px";
		mlcb.style.height = "530px";

    	var mlcc = document.getElementById("mapLeftColumnContent"); 
    	mlcc.style.padding="0px 0px 0px 5px";
    	mlcc.style.width = "238px";*/
    	
    	var mrc = document.getElementById("mapRightColumn"); 
       	mrc.style.visibility="visible";
       
       	var vc = document.getElementById("vignetteContainer");
       	vc.style.visibility="hidden";
    	vc.style.display = "none";
    }
    
    var found = document.getElementById("mapFoundStores");
    found.innerHTML = "";
    //found.style.width = "325px";

    var found2 = document.getElementById("mapFoundStores2");
    
    sel = document.getElementById("product_type");
    var prodType = sel.options[sel.selectedIndex].value;
    
    numEtailers = 0;
    
    //fetch the total number of etailers per product type, or if all was selected then fetch them all
    if(prodType != -1)
    	numEtailers = MSLO_Lookups.getNumberOfEtailersForProductOrRetailer(prodType);
    else if(prodType == -1)
    	numEtailers = MSLO_Lookups.getNumberOfEtailers();
    	
    
    sel = document.getElementById("retailer");
    var retailerType = sel.options[sel.selectedIndex].value;
    //fetch the total number of etailers per retailer type or if all select then do nothing
    numRetailerEtailers = 0;
    if(retailerType != -1)
    	numRetailerEtailers = MSLO_Lookups.getNumberOfEtailersForProductOrRetailer(retailerType);
    else
    	numRetailerEtailers = 0;
      	
    
    //show the number of stores or show 0 if something went wrong with the lookup
    if(numEtailers >= 0 && numRetailerEtailers == 0)
    	this.showOnlineStoresFound(numEtailers);
    else if(numRetailerEtailers > 0)
    	this.showOnlineStoresFound(numRetailerEtailers);
    else
    	this.showOnlineStoresFound(0);
    	
    found2.innerHTML = "";
    if(retailerType != 2 && retailerType != 7 && retailerType != -1){
    	//if they select a brick and mortar retailer then dont show any etailer results
    	found2.innerHTML = "";
    	this.showOnlineStoresFound(0);
    }
    else if(!MSLO_Lookups.isValidCombination(retailerType, prodType)){
    	//if this is not a valid combination of retailer-product then show nothing too
    	found2.innerHTML = "";
    	this.showOnlineStoresFound(0);
    }
    else if(prodType != -1 && numRetailerEtailers ==0){ //fetch etailer for specific product
    	for(i=0;i<numEtailers;i++){
    		etailer = MSLO_Lookups.getNextEtailer(i,prodType);
    		
    		if(etailer == null)
    			continue;	//something went wrong fetching the next etailer, continue onto next one. 
    			
    		found2.innerHTML = found2.innerHTML + "<div style='height: 20px; padding:0px 1px 0px 6px; margin: 3px 0px 1px 0px;'><span class='mapFoundStoreWeb'>" + 
							"<a href='"+etailer.url+"' target='_blank'> "+etailer.pretty+" </a>" + 
						"</span></div>";
    	}
    }
    else if(numRetailerEtailers > 0){
    	for(i=0;i<numRetailerEtailers;i++){
        		etailer = MSLO_Lookups.getNextEtailer(i,retailerType);
        		
        		if(etailer == null)
        			continue;	//something went wrong fetching the next etailer, continue onto next one. 
        			
        		found2.innerHTML = found2.innerHTML + "<div style='padding:3px 1px 1px 6px;'><span class='mapFoundStoreWeb'>" + 
    							"<a href='"+etailer.url+"' target='_blank'> "+etailer.pretty+" </a>" + 
    						"</span></div>";
    	}
    }
    else{ //loop through all the etailers
    	etailers = MSLO_Lookups.getAllEtailers();
    	for(i=0;i<numEtailers;i++){
	    		etailer = etailers[i];
	    		
	    			if(etailer == null)
	    				continue;	//something went wrong fetching the next etailer, continue onto next one. 
	    			
	    			found2.innerHTML = found2.innerHTML + "<div style='padding:3px 1px 1px 6px;'><span class='mapFoundStoreWeb'>" + 
								"<a href='"+etailer.url+"' target='_blank'> "+etailer.pretty+" </a>" + 
							"</span></div>";
			
    	}
    
    }
    //found2.style.width = "218px";
    //found2.style.height = "196px";
    found2.style.padding = "0px 0px 0px 0px";

    //clear the map
    this.map_controller.clearMap();
}
AppController.prototype.setUpDirections = function() 
{
	// set up headers
	this.clearNumStoresFound();
	this.showBackToResults();

    var found = document.getElementById("mapFoundStores");
    found.innerHTML = "";
    //found.style.width = "218px";

    var found2 = document.getElementById("mapFoundStores2");
    //found2.style.width = "325px";
    //found2.style.height = "196px";
    found2.innerHTML = "";	
}
AppController.prototype.setUpDetails = function(index) 
{
	// set up headers
	this.clearNumStoresFound();
	this.showBackToResults();

    var found = document.getElementById("mapFoundStores");
    found.innerHTML = "";
    //found.style.width = "218px";

    var found2 = document.getElementById("mapFoundStores2");
    //found2.style.width = "325px";
    //found2.style.height = "196px";
    found2.innerHTML =  "<div style='margin-top:10px;margin-left:10px;'>" +	
                        "<b>GET DRIVING DIRECTIONS</b>" +
						"<br /><br />" +
						"To get directions, please enter your starting address:" + 
						"<br /><br />" +
						"<input type='text' name='mapDirFmAddress' id='mapDirFmAddress'>" +
						"<input type='image' style='padding-left:5px;vertical-align:bottom;' src='" + AppController.imagesURL + "button_go.gif' onclick='app_controller.map_controller.getDirections("+index+",\"mapDirFmAddress\")'>" +
                        "</div>";

	
}
AppController.imagesURL = "http://images.marthastewart.com/images/channel/corporate/shop/store_locator/";

