﻿function ps_InitPage(){if(document._ps_MapInitialized)return;document._ps_MapInitialized=true;if((document._ps_SellerMapFullScreen)&&(document._ps_SellerMapFullScreen=="true")){var mapCell=document.getElementById(document._ps_MapCellID);mapCell.style.width="100%";mapCell.style.height="500px";var vendorScrollingDiv=document.getElementById(document._ps_VendorScrollingDivID);vendorScrollingDiv.style.height="530px";vendorScrollingDiv.style.width="224px";var vendorsHeadingDiv=document.getElementById(document._ps_VendorsHeadingDivID);vendorsHeadingDiv.style.width="232px";var mapDiv=document.getElementById(document._ps_SellerMapDivID);mapDiv.style.width=mapCell.offsetWidth+'px';mapDiv.style.height="530px";if(Sys.Browser.agent==Sys.Browser.Safari)mapDiv.style.minWidth=mapDiv.style.width;var mapCellAbsolutePosition=_FindAbsolutePosition(mapCell);mapDiv.style.top=(mapCellAbsolutePosition.offsetTop)-(Sys.Browser.agent!=Sys.Browser.InternetExplorer?(Sys.Browser.agent==Sys.Browser.Firefox?50:Sys.Browser.agent==Sys.Browser.Safari&&navigator.userAgent.indexOf('Chrome')>-1?275:-20):0)+'px';mapDiv.style.left=mapCellAbsolutePosition.offsetLeft+'px';};var map=new VEMap(document._ps_SellerMapDivID);document._ps_SellerMap=map;map.LoadMap();ps_LookupLocation();};function _ps_ScheduleNextLocalStoreUpdate(){document._ps_LocalStoreUpdateAttemptsLeft--;document._ps_getLocalSellerStoresTimerId=window.setTimeout(function(){_ps_GetLocalStores();},document._ps_UpdatesCheckInterval);};function _ps_StartLocalStoreUpdate(immidiate){document._ps_isFirstRequest=true;document._ps_LocalStoreUpdateAttemptsLeft=document._ps_LocalStoreUpdateAttempts;if(immidiate)_ps_GetLocalStores();else if(!document._ps_getLocalSellerStoresTimerId)_ps_ScheduleNextLocalStoreUpdate();};function ps_StopRefreshTimer(){if(document._ps_getLocalSellerStoresTimerId){window.clearTimeout(document._ps_getLocalSellerStoresTimerId);document._ps_getLocalSellerStoresTimerId=null;}};function _ps_GetLocalStores(){document._ps_getLocalSellerStoresTimerId=null;PriceLister.Avalon.Web.ScriptService.SellerLocalStoreService.GetLocalStores2(document._ps_ProductId,document._ps_location,document._ps_latLong.Latitude,document._ps_latLong.Longitude,document._ps_isFirstRequest,_ps_GetLocalStoresCallback,_ps_GetError);document._ps_isFirstRequest=false;};function _ps_GetSellerIdIndex(sellerId){var sellerBodyPanelIdIndex;var l=document._ps_SellerIDs.length;for(var i=0;i<l;i++)if(document._ps_SellerIDs[i]==sellerId)return i;return -1;};function _ps_GetStoreRowIndex(table,localStoreInfo){var rows=table.rows;var l=rows.length;for(var i=0;i<l;i++)if(rows[i].getAttribute('storeId')==localStoreInfo.StoreId)return i;return -1;};function _ps_GetPushpinCellElement(localStoreInfo){var cell=document.createElement('td');cell.className='SellerStorePinCell';cell.align='left';cell.vAlign='top';cell.innerHTML='<img src="'+document._ps_MapPinImageLocation+localStoreInfo.SellerMapPinImage+'">';return cell;};function _ps_GetStoreDescriptionHTML(localStoreInfo){var storeStockStyle;if(localStoreInfo.StoreStockDescription.toLowerCase()=="in stock")storeStockStyle="InStock";else if(localStoreInfo.StoreStockDescription.toLowerCase()=="out of stock")storeStockStyle="OutOfStock";else storeStockStyle="";var innerHTML=localStoreInfo.Address+'<br/>'+localStoreInfo.City+', '+localStoreInfo.State+'&nbsp;'+localStoreInfo.ZipCode+'<br/>'+'<b>Price : </b>'+localStoreInfo.Price+'<br/>'+'<b>Stock Status : </b><span class="'+storeStockStyle+'">'+localStoreInfo.StoreStockDescription+'</span><br/>'+'<b>Updated : </b><span class="'+localStoreInfo.UpdatedTextStyle+'">'+localStoreInfo.UpdatedText+'</span><br/>'+'<b>Distance : </b>'+localStoreInfo.Distance+'<br/>'+'<b>Phone : </b>'+localStoreInfo.Phone+'<br/>'+'<b>Weekday : </b>'+localStoreInfo.WeekdayStoreHours+'<br/>'+'<b>Saturday : </b>'+localStoreInfo.SaturdayStoreHours+'<br/>'+'<b>Sunday : </b>'+localStoreInfo.SundayStoreHours+'<br/>';return innerHTML;};function _ps_GetStoreInfoCellElement(localStoreInfo){var cell=document.createElement('td');cell.className='SellerStoreInfoCell';cell.align='left';cell.vAlign='top';cell.innerHTML=_ps_GetStoreDescriptionHTML(localStoreInfo);return cell;};function _ps_SetRow(row,localStoreInfo){row.onclick=function(){ps_CenterPin(localStoreInfo.StoreId)};row.title='Click here to center the map on this store.';row.appendChild(_ps_GetPushpinCellElement(localStoreInfo));row.appendChild(_ps_GetStoreInfoCellElement(localStoreInfo));};function AnimateUpdatedRows(row,index){var divOverlay=document.createElement('div');divOverlay.className="SellerRowFlashOverlay";divOverlay.id="overlay"+index;var rowPosition=_FindAbsolutePosition(row);divOverlay.style.left=rowPosition.offsetLeft+"px";divOverlay.style.top=rowPosition.offsetTop+"px";divOverlay.style.width=row.offsetWidth+"px";divOverlay.style.height=row.offsetHeight+"px";var initialOpacity=10;divOverlay.style.filter="alpha(style=0,opacity:"+initialOpacity+")";divOverlay.style.KHTMLOpacity=initialOpacity/100;divOverlay.style.MozOpacity=initialOpacity/100;divOverlay.style.opacity=initialOpacity/100;document.getElementById(document._ps_VendorScrollingDiv).appendChild(divOverlay);window.setTimeout("FlashRow('"+divOverlay.id+"', 17)",50);};function FlashRow(divOverlayId,stepsLeft){var divOverlay=document.getElementById(divOverlayId);var opacity;if(stepsLeft>13)opacity=70+((13-stepsLeft)*15);else opacity=70-((13-stepsLeft)*5);divOverlay.style.filter="alpha(style=0,opacity:"+opacity+")";divOverlay.style.KHTMLOpacity=opacity/100;divOverlay.style.MozOpacity=opacity/100;divOverlay.style.opacity=opacity/100;if(stepsLeft>0)window.setTimeout("FlashRow('"+divOverlayId+"', "+(stepsLeft-1)+");",stepsLeft>13?50:100);else document.body.removeChild(divOverlay);};function _ps_UpdateStoreRow(table,rowIndex,localStoreInfo){var row=table.rows[rowIndex];var oldRowUpdated=row.getAttribute('updated');while(row.cells.length)row.removeChild(row.cells[0]);_ps_SetRow(row,localStoreInfo);_ps_SetRowAttributes(row,localStoreInfo);if((localStoreInfo.Updated=='JUST UPDATED')&&(oldRowUpdated!='JUST UPDATED'))AnimateUpdatedRows(row,rowIndex);};function _ps_InsertStoreRow(table,localStoreInfo){var rows=table.rows;var l=rows.length;var insertIndex;for(insertIndex=0;insertIndex<l;insertIndex++)if(rows[insertIndex].getAttribute('storeId')==localStoreInfo.StoreId)break;var newRow=table.insertRow(insertIndex);newRow.className='PCursor';_ps_SetRow(newRow,localStoreInfo);_ps_SetRowAttributes(newRow,localStoreInfo);};function _ps_SetRowAttributes(row,localStoreInfo){row.setAttribute('storeId',localStoreInfo.StoreId);row.setAttribute('distance',1.0*localStoreInfo.Distance.substr(0,localStoreInfo.Distance.indexOf(' ')));row.setAttribute('updated',localStoreInfo.UpdatedText);};function _ps_SetSellerInfo(localStoreInfo){var sellerIdIndex=_ps_GetSellerIdIndex(localStoreInfo.SellerId);if(sellerIdIndex>-1){document.getElementById(document._ps_SellerProcessingStorePanels[sellerIdIndex]).style.display='none';document.getElementById(document._ps_SellerEnterLocationFirstPanels[sellerIdIndex]).style.display='none';if(localStoreInfo.NoStore){document.getElementById(document._ps_SellerNoStorePanels[sellerIdIndex]).style.display='block';return;}else document.getElementById(document._ps_SellerNoStorePanels[sellerIdIndex]).style.display='none';var table=document.getElementById(document._ps_SellerStoresTables[sellerIdIndex]);var rowIndex=_ps_GetStoreRowIndex(table,localStoreInfo);if(rowIndex>-1)_ps_UpdateStoreRow(table,rowIndex,localStoreInfo);else{_ps_InsertStoreRow(table,localStoreInfo);document.getElementById(document._ps_SellerStoresTables[sellerIdIndex]).style.display='block';}}};function _ps_GetPushpin(storeID){var l=document._ps_pushpinIDs.length;for(var i=0;i<l;i++){if(document._ps_pushpinIDs[i][0]==storeID)return document._ps_SellerMap.GetShapeByID(document._ps_pushpinIDs[i][1]);};return null;};function _ps_SetPushpin(pushpin,localStoreInfo){pushpin.SetCustomIcon(document._ps_MapPinImageLocation+localStoreInfo.SellerMapPinImage);pushpin.SetTitle('<img src="'+localStoreInfo.SellerLogoImageUrl+'" title="'+localStoreInfo.SellerName+'" alt="'+localStoreInfo.SellerName+'" />');pushpin.SetDescription('<div class="PopupDetails">'+_ps_GetStoreDescriptionHTML(localStoreInfo)+'</div>');};function _ps_SetPushpins(localStoreInfo){var pushpin=_ps_GetPushpin(localStoreInfo.StoreId);if(!pushpin){pushpin=document._ps_SellerMap.AddPushpin(new VELatLong(localStoreInfo.Latitude,localStoreInfo.Longitude));document._ps_pushpinIDs.push(new Array(localStoreInfo.StoreId,pushpin.GetID()));};_ps_SetPushpin(pushpin,localStoreInfo);};function _ps_GetLocalStoresCallback(result){var l=result!=null?result.length:0;if(l>0){var selectedSellerId=(document._ps_SellerId*1);var allSellerInfoUpdated=true;var map=document._ps_SellerMap;var furthestPointCoord;if(document._ps_panMap&&selectedSellerId>0){furthestPointCoord=new Object();furthestPointCoord.Distance=0;furthestPointCoord.Longitude=0;furthestPointCoord.Latitude=0;};for(var i=0;i<l;i++){var storeInfo=result[i];allSellerInfoUpdated=allSellerInfoUpdated&&(storeInfo.UpdatedText=='JUST UPDATED');_ps_SetSellerInfo(storeInfo);_ps_SetPushpins(storeInfo);if(document._ps_panMap&&(storeInfo.SellerId==selectedSellerId)){var distance=Math.sqrt(Math.pow(storeInfo.Latitude-document._ps_latLong.Latitude,2)+Math.pow(storeInfo.Longitude-document._ps_latLong.Longitude,2));if(distance>furthestPointCoord.Distance){furthestPointCoord.Longitude=storeInfo.Longitude;furthestPointCoord.Latitude=storeInfo.Latitude;furthestPointCoord.Distance=distance;}}};if(furthestPointCoord&&furthestPointCoord.Distance>0)map.IncludePointInView(new VELatLong(furthestPointCoord.Latitude,furthestPointCoord.Longitude));document._ps_panMap=false;if(document._ps_SelectedSellerHeaderPanelId){var storeHeaderDiv=document.getElementById(document._ps_SelectedSellerHeaderPanelId);storeHeaderDiv.click();document._ps_SelectedSellerHeaderPanelId=null;}};l=document._ps_SellerIDs.length;if(document._ps_LocalStoreUpdateAttemptsLeft>0){if(allSellerInfoUpdated){for(var i=0;i<l;i++){if(document.getElementById(document._ps_SellerProcessingStorePanels[i]).style.display=='none'){allSellerInfoUpdated=false;break;}}};if(!allSellerInfoUpdated)_ps_ScheduleNextLocalStoreUpdate();}else{for(var i=0;i<l;i++){var processingStorePanel=document.getElementById(document._ps_SellerProcessingStorePanels[i]);if(processingStorePanel.style.display!='none'){processingStorePanel.style.display='none';document.getElementById(document._ps_SellerNoStorePanels[i]).style.display='block';}}}};function _ps_GetError(result){};function _ps_LookupLocationCallback(a,b,results,c){if((results!=null)&&(results.length>0)){document._ps_latLong=results[0].LatLong;var addressParts=results[0].Name.split(',');var found=false;var i;for(i=0;i<addressParts.length;i++){var index=addressParts[i].indexOf(' (postal code)');if(index>-1){document._ps_location=addressParts[i].substr(0,index);found=true;break;}};if(!found){var addressZipCode=addressParts[addressParts.length-2].substr(3,5);if(!isNaN(addressZipCode))document._ps_location=addressParts[addressParts.length-2].substr(3,5);};if(!found){document._ps_location=addressParts[0]+', '+addressParts[1];};PriceLister.Avalon.Web.ScriptService.SellerLocalStoreService.IssueLocalStoresUpdateRequest(document._ps_ProductId,document._ps_location,document._ps_latLong.Latitude,document._ps_latLong.Longitude,_ps_IssueLocalStoresUpdateRequestCallback,_ps_GetError);document.getElementById(document._ps_InvalidLocationLabelID).innerHTML='&nbsp;';document._ps_panMap=true;_ps_StartLocalStoreUpdate(true);}else{document.getElementById(document._ps_InvalidLocationLabelID).innerHTML='Location could not be found.';scheduleNextRefresh=false;}};function _ps_IssueLocalStoresUpdateRequestCallback(result){};function ps_LookupLocation(){var value=document.getElementById(document._ps_edtLocationId).value;if((value)&&(value!='')){var map=document._ps_SellerMap;map.Find(null,value,null,null,0,1,false,false,false,true,_ps_LookupLocationCallback);map.Clear();document._ps_pushpinIDs=new Array();var l=document._ps_SellerIDs.length;for(var i=0;i<l;i++){document.getElementById(document._ps_SellerProcessingStorePanels[i]).style.display='block';document.getElementById(document._ps_SellerEnterLocationFirstPanels[i]).style.display='none';var table=document.getElementById(document._ps_SellerStoresTables[i]);table.style.display='none';while(table.rows.length>0)table.deleteRow(table.rows[0]);}}};function ps_CenterPin(storeId){var pushpin=_ps_GetPushpin(storeId);if(pushpin)document._ps_SellerMap.PanToLatLong(pushpin.GetPoints()[0]);};function ps_LocationKeypress(currentEvent){switch(currentEvent.keyCode){case Sys.UI.Key.enter:ps_LookupLocation();return true;}};


