var storeSelectionLayerCommand = new Array(8); storeSelectionLayerCommand[0] = '/includes/store_selector_layer.jsp'; storeSelectionLayerCommand[1] = '/custserv/locate_store_layer.cmd'; storeSelectionLayerCommand[2] = '/custserv/save_user_store.cmd'; storeSelectionLayerCommand[3] = '/custserv/store_detail.jsp?viewStoreId='; storeSelectionLayerCommand[4] = '/custserv/save_user_store.cmd?storeId='; storeSelectionLayerCommand[5] = '/includes/store_selector_only_layer.jsp'; storeSelectionLayerCommand[6] = '/custserv/locate_store_only_layer.cmd'; var storeSelectionLayerFixedContainerId = "#widget-fixed-store-selection-layer"; var storeSelectionLayerContainerId = "#widget-storeSelection"; var storeSelectionLayerCloseButClass = ".widget-close-but"; var hideTimeOuts= new Array(); var ssLoadingHTML = '
' + '
' + '
' + '
'+ '
Loading...
' + '
' + '
' + '
' + '
'; var ssSimpleHTML = '
'; //var htmls = new Hash(); //var markers = new Hash(); //var toHtmls = new Hash(); //var fromHtmls = new Hash(); //var geocoder; //if (typeof(GClientGeocoder) != 'undefined') { // geocoder = new GClientGeocoder(); //} function saveUserStoreFixed(storeId) { saveUserStoreWithParams(storeId, true); } function saveUserStore(storeId) { saveUserStoreWithParams(storeId, false); } function saveUserStoreNoClose(storeId) { saveUserStoreWithParams(storeId, false, true) } function saveUserStoreWithParams(storeId, fixed, noClose) { if (fixed === undefined) { fixed = false; } if (noClose == undefined) { noClose = false; } var params = "storeId=" + storeId; var postURL = storeSelectionLayerCommand[2] + "?" + params; if (!fixed){ hideStoreLayer(); showStoreSelectionLayerLoading(ssLoadingHTML); positionStoreSelectionLayer(); } $.ajax({ type: "POST", url: postURL, dataType: "html", timeout: 15000, complete: function() { }, success: function(data) { location.reload(true); // Reload once we've set the store on the server. }, error: function() { } }); } function searchStoreLayer() { searchStoreLayerWithParams(''); } function searchStoreLayerFixed() { searchStoreLayerWithParams('fixed=true'); } function searchStoreLayerNoClose() { searchStoreLayerWithParams('noclose=true'); } function searchStoreLayerWithParams(params) { var cityStateZip = ($("input[name=cityStateZipLayer]").val()); var clientLat = ''; var clientLong = ''; var isStore = isStoreSelected(); var isSignedIn = document.getElementById('userSignedInData').value; // from header.jsp var requestURL = storeSelectionLayerCommand[1]; if ((isSignedIn === "false") && (isStore === false)) { requestURL = storeSelectionLayerCommand[1]; } else if ((isSignedIn === "true") && (isStore === false)) { requestURL = storeSelectionLayerCommand[6]; // return to store_selector_only_layer.jsp } // build the query with a radius of 50. params = "cityStateZip=" + encodeURIComponent(cityStateZip) + "&radius=50&" + params; // clientLat = geocode.lat(); // clientLong = geocode.lng(); params = params + "&latitude=" + clientLat + "&longitude=" + clientLong; //alert( "Lat-" + clientLat + " Long-" + clientLong ); // var postURL = storeSelectionLayerCommand[1] + "?" + params ; var postURL = requestURL + "?" + params ; $.ajax({ type: "POST", url: postURL, dataType: "html", timeout: 15000, complete: function() { }, success: function(data) { hideStoreLayerLoading(); $(storeSelectionLayerContainerId).append(data); $(storeSelectionLayerContainerId).show(); return true; }, error: function() { //hideRegLoading(); //return false; //alert('error'); } }); } // Just a throttle that will stop a client geo code loop from happening. var attemptedClientGeoCodeInLayer = false; // this provides similar functionality to searchStoreLayerWithParams but it will // attempt to geocode the stuff. function searchStoreLayerGeocodedWithParams(params, cityStateZip) { var clientLat = ''; var clientLong = ''; if (attemptedClientGeoCodeInLayer) { return; } attemptedClientGeoCodeInLayer = true; // build the query with a radius of 50. params = "cityStateZip=" + encodeURIComponent(cityStateZip) + "&radius=50&" + params; var clientGeoCoder = new GClientGeocoder(); clientGeoCoder.getLatLng( cityStateZip, function(geocode) { // sfarrugia 12/29/2009 - commenting here call back function for the getLatLng function. if (!geocode) { // sfarrugia 12/29/2009 - just let the ajax call deal with displaying hte message - no need // for the alert. //alert('yo'); return false; } else { // // submit the populated form // //alert( geocode.lat() + " " + geocode.lng() ); // clientLat = geocode.lat(); clientLong = geocode.lng(); params = params + "&latitude=" + clientLat + "&longitude=" + clientLong; //alert( "Lat-" + clientLat + " Long-" + clientLong ); var postURL = storeSelectionLayerCommand[1] + "?" + params ; $.ajax({ type: "POST", url: postURL, dataType: "html", timeout: 15000, complete: function() { }, success: function(data) { hideStoreLayerLoading(); $(storeSelectionLayerContainerId).append(data); $(storeSelectionLayerContainerId).show(); return true; }, error: function() { //hideRegLoading(); //return false; //alert('error'); } }); } } ); } function displayStoreSelectionLayer() { showStoreSelectionLayer('show','', false, 0); } function displayStoreSelectionLayerFixed() { showStoreSelectionLayer('fixedshow','fixed=true', false, 0); } function displayStoreSelectionLayerNoClose() { showStoreSelectionLayer('nocloseshow', 'noclose=true', false, 0); } function displayStoreSelectionLayer(dest) { // set the destination param params = "dest=" + dest; showStoreSelectionLayer('show',params, false, 0); } /* Function(s) to Show the storeSelection Layer */ function showStoreSelectionLayer(action,params,refreshPage,refreshDelayTime) { var isStore = isStoreSelected(); // var isSignedIn = isSignedIn(); var isSignedIn = document.getElementById('userSignedInData').value; // from header.jsp if( (action == "show") || (action == "fixedshow") || (action == "nocloseshow") ) { showStoreSelectionLayerLoading(ssLoadingHTML); requestURL = storeSelectionLayerCommand[0]; if ((isSignedIn === "false") && (isStore === false)) { requestURL = storeSelectionLayerCommand[0]; } else if ((isSignedIn === "true") && (isStore === false)) { requestURL = storeSelectionLayerCommand[5]; } } else { alert("missing action"); } requestURL = requestURL; params = "ts=" + timestamp() + "&action=" + action + "&" + params; $.ajax({ type: "POST", url: requestURL, data: params, dataType: "html", timeout: 15000, success: function(data) { if (action == 'fixedshow') { positionStoreSelectionLayerFixed(); } else if (action == 'nocloseshow') { disableUserInputForStoreSelection(); positionStoreSelectionLayer(); } else { positionStoreSelectionLayer(); } hideStoreLayerLoading(); $(storeSelectionLayerContainerId).append(data); $(storeSelectionLayerContainerId).show(); if (refreshPage != undefined && refreshPage) { setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0); } return true; }, complete: function() { $(storeSelectionLayerCloseButClass).click(function() { hideStoreLayer(); }); if (action == 'show') { if(!$('#cboxOverlay').length){ $('body').append('
'); } else { $('#cboxOverlay').show(); } setTimeout(function(){ $('#cboxOverlay').click(function() { hideStoreLayer(); $('#cboxOverlay').hide(); }); },10); } var labelTimer; if (labelTimer != null){ clearTimeout(labelTimer); labelTimer = null; } labelTimer = setTimeout(function(){ setFormLabels(); },500); }, error: function() { hideStoreLayerLoading(); return false; } }); }; function showStoreSelectionLayerLoading(htmlToShow) { $(storeSelectionLayerContainerId).remove(); //load, position, show new cart $("body").append(htmlToShow); $(storeSelectionLayerContainerId).show(); }; function hideStoreLayerLoading() { $(storeSelectionLayerContainerId + " *").remove(); $(storeSelectionLayerContainerId).html(""); }; //Center the positionstoreSelectionLayer function positionStoreSelectionLayer() { $(storeSelectionLayerContainerId).center(); //Bring the positionstoreSelectionLayer down a bit since the center function is better suited to larger layers $(storeSelectionLayerContainerId).css('top', '160px'); }; //Display the layer in a fixed area. function positionStoreSelectionLayerFixed() { //alert('position fixed'); $(storeSelectionLayerFixedContainerId).html($(storeSelectionLayerContainerId)); }; //Edit this function if need to do something special on basket close. function hideStoreLayer() { $(storeSelectionLayerContainerId).hide(); $(storeSelectionLayerContainerId).remove(); if ($('#cboxOverlay').length){ $('#cboxOverlay').hide(); } }; // sfarrugia 8/27/2009 // Check to see if the store is not selected function noStoreSelected() { return (!isStoreSelected()); } // sfarrugia 8/27/2009 // Check to see if the store is selected by checking local divs function isStoreSelected() { if ( $('.selectedStoreIdData').length ) { return true; } else { return false; } } // sfarrugia 12/31/2009 - Submits the form and allows for some special behavior here if needed. function submitSearchForm(formId) { if (formId === undefined) { formId = "locateStoreForm"; } var form = document.getElementById(formId); // grab the form object. var searchValue = form.cityStateZip.value; // clear lat and long in case it came through already from a previous successful display. form.latitude.value = ''; form.longitude.value = ''; // stran: to validate city, state, zip code string // alpha, numeric, hyphens, commas and apostrophes accepted var objRegExp = /^([a-zA-Z0-9-,\s'])*$/; if (!objRegExp.test(searchValue)) { alert("Please enter a valid City & State, or ZIP Code."); return false; } return true; } // sfarrugia 12/31/2009 - Submit the form after geo coding the lat and long. //function submitGeoCodedSearchForm(formId) { // if (formId === undefined || formId == '') { // formId = "locateStoreForm"; // } // // var form = document.getElementById(formId); // grab the form object. // var searchValue = form.cityStateZip.value; // // // // we dont know what the coords are so go to google to grab // // them. // // // // // stran: to validate city, state, zip code string // // alpha, numeric, hyphens, commas and apostrophes accepted // var objRegExp = /^([a-zA-Z0-9-,\s'])*$/; // if (!objRegExp.test(searchValue)) { // alert("Please enter a valid City & State, or ZIP Code."); // return false; // } // geocoder = new GClientGeocoder(); // geocoder.getLatLng( // searchValue, // function(geocode) { // sfarrugia 12/29/2009 - commenting here // // call back function for the getLatLng function. // if (!geocode) { // // // // what we have here... is.. a failure to communicate // // // // Updated by stran, to change the error message according to UIS // alert("Please enter a valid City & State, or ZIP Code."); // // return false; // // } else { // // // // submit the populated form // // // // alert( geocode.lat() + " " + geocode.lng() ); // // // submitGeoCodeResultsForm(form, geocode.lat(), geocode.lng()); // } // } // ); // return false; //} //function submitGeoCodeResultsForm(form, lat, lng) { // // // // // // copy the passed latitude and longitude results to the form // // and submit it // // // form.latitude.value = lat; // form.longitude.value = lng; // form.submit(); //} //function initializeMap(lat, lng, radius) { // MyMapInitialize("map", lat, lng, 12 - Math.ceil(radius/15), MYMODE_MAP); // MyMapAddMarker(lat, lng, MYMARKER_TYPE2); //} // //function initializeMapAllStores(lat, lng) { // MyMapInitialize("map", lat, lng, 3, MYMODE_MAP); //} // This function picks up the click and opens the corresponding info window //function myClick(i) { // showme(i); //MyMapOpenWindow(markers.getItem(i), htmls.getItem(i)); //} //function toHere(id) { // $('div#marker' + id + ' .toHere').show(); // $('div#marker' + id + ' .fromHere').hide(); // $('div#marker' + id).parent().find('.streetView').hide(); // $('div#marker' + id + ' .infoWindowDirections.default').hide(); //} // //function fromHere(id) { // $('div#marker' + id + ' .fromHere').show(); // $('div#marker' + id + ' .toHere').hide(); // $('div#marker' + id).parent().find('.streetView').hide(); // $('div#marker' + id + ' .infoWindowDirections.default').hide(); //} //// functions that open the directions forms //function toHere(i) { // MyMapOpenWindow(markers.getItem(i),toHtmls.getItem(i)); //} // //function fromHere(i) { // MyMapOpenWindow(markers.getItem(i),fromHtmls.getItem(i)); //} // move this to include so other people can use it? //function Hash() //{ // this.length = 0; // this.items = new Array(); // for (var i = 0; i < arguments.length; i += 2) { // if (typeof(arguments[i + 1]) != 'undefined') { // this.items[arguments[i]] = arguments[i + 1]; // this.length++; // } // } // // this.removeItem = function(in_key) // { // var tmp_value; // if (typeof(this.items[in_key]) != 'undefined') { // this.length--; // var tmp_value = this.items[in_key]; // delete this.items[in_key]; // } // // return tmp_value; // } // // this.getItem = function(in_key) { // return this.items[in_key]; // } // // this.setItem = function(in_key, in_value) // { // if (typeof(in_value) != 'undefined') { // if (typeof(this.items[in_key]) == 'undefined') { // this.length++; // } // // this.items[in_key] = in_value; // } // // return in_value; // } // // this.hasItem = function(in_key) // { // return typeof(this.items[in_key]) != 'undefined'; // } //} $(function(){ $(".checkStoreSelected").click(function(){ displayStoreSelectionLayer(); }); });