﻿
var map;var gmarkers=[];var k;var geocoder;var gdir;var htmls=[];var to_htmls=[];var from_htmls=[];var LgMapControl;var ZipCodeSearch=false;function load(){if(GBrowserIsCompatible()){geocoder=new GClientGeocoder();map=new GMap2(document.getElementById("gmap"));CenterMap(44691,9);LgMapControl=new GLargeMapControl();map.addControl(LgMapControl);map.addControl(new GMapTypeControl());map.enableDoubleClickZoom();map.enableContinuousZoom();document.getElementById("gmap").style.visibility="hidden";gdir=new GDirections(map,document.getElementById("Directions"));}}
function showMap(CoKeys){map.clearOverlays();gmarkers.length=0;k=0;ClearDirections();GDownloadUrl("XmlData/WtbData.xml",function(data,responseCode){var xml=GXml.parse(data);var markers=xml.documentElement.getElementsByTagName("licensee");for(var i=0;i<markers.length;i++){if(CoKeys.indexOf(","+markers[i].getAttribute("co_key").toString()+",")>-1){var co_key=markers[i].getAttribute("co_key");var dba_name=markers[i].getAttribute("dba_name").toString();var web_site="";if(markers[i].getAttribute("website")!=""){if(markers[i].getAttribute("website").toString().indexOf('http://')>-1){web_site=markers[i].getAttribute("website").toString().replace(/^\s+|\s+$/g,'');}
else{web_site="http://"+markers[i].getAttribute("website").toString().replace(/^\s+|\s+$/g,'');}}
var email_address="";if(markers[i].getAttribute("email_address")!=""){email_address=markers[i].getAttribute("email_address").toString();}
var lic_option_code=markers[i].getAttribute("lic_option_code").toString();var product_purchased_code=markers[i].getAttribute("product_purchased_code").toString();var lat=markers[i].getAttribute("lat").toString();var lng=markers[i].getAttribute("lng").toString();AddOverlay(lat,lng,dba_name,co_key,web_site,email_address,lic_option_code,product_purchased_code);}}});if(ZipCodeSearch){switch(document.getElementById("ctl00_body_DdlMiles").options[document.getElementById("ctl00_body_DdlMiles").selectedIndex].value)
{case"5":CenterMap(document.getElementById("ctl00_body_TxtZipCode").value.replace(/^\s+|\s+$/g,''),11);break;case"15":CenterMap(document.getElementById("ctl00_body_TxtZipCode").value.replace(/^\s+|\s+$/g,''),10);break;case"25":CenterMap(document.getElementById("ctl00_body_TxtZipCode").value.replace(/^\s+|\s+$/g,''),9);break;case"50":CenterMap(document.getElementById("ctl00_body_TxtZipCode").value.replace(/^\s+|\s+$/g,''),8);break;}}
else{var ShipCity=document.getElementById("ctl00_body_TxtCity").value.replace(/^\s+|\s+$/g,'').toLowerCase();var ShipState="";var ShipCountry=document.getElementById("ctl00_body_DdlCountry").options[document.getElementById("ctl00_body_DdlCountry").selectedIndex].text.replace(/^\s+|\s+$/g,'');if(ShipCountry=="United States of America"||ShipCountry=="Canada"){ShipState=document.getElementById("ctl00_body_DdlState").options[document.getElementById("ctl00_body_DdlState").selectedIndex].value.replace(/^\s+|\s+$/g,'');CenterMap((ShipCity+", "+ShipState+", "+ShipCountry),9);}
else{if(ShipCity!=''){CenterMap((ShipCity+", "+ShipCountry),10);}
else{CenterMap(ShipCountry,8);}}}}
function CenterMap(Location,Zoom){geocoder.getLatLng(Location,function(point){map.setCenter(point,Zoom);});}
function AddOverlay(lat,lng,dba_name,co_key,web_site,email_address,lic_option_code,product_purchased_code){var ImageHtml="";switch(product_purchased_code){case"1":case"8":case"9":ImageHtml='<img src="../../Images/Wtb/Logos/Traditional.gif" width="115"></img>';break;case"2":ImageHtml='<img src="../../Images/Wtb/Logos/Natural.gif" width="115"></img>';break;case"3":ImageHtml='<img src="../../Images/Wtb/Logos/Prime.gif" width="115"></img>';break;case"4":ImageHtml='<img src="../../Images/Wtb/Logos/Traditional_Natural.gif" width="115"></img>';break;case"5":ImageHtml='<img src="../../Images/Wtb/Logos/Traditional_Prime.gif" width="115"></img>';break;case"6":ImageHtml='<img src="../../Images/Wtb/Logos/Prime_Natural.gif" width="115"></img>';break;case"7":ImageHtml='<img src="../../Images/Wtb/Logos/Traditional_Prime_Natural.gif" width="115"></img>';break;}
var WebSiteHtml="";if(web_site!=""){WebSiteHtml='<a target="_blank" href="'+web_site+'">Web Site</a>&nbsp;&nbsp;&nbsp;';}
var EmailHtml="";if(email_address!=""){EmailHtml='<a target="_blank" href="mailto:'+email_address+'">Email</a>';}
var DisclaimerHtml="<div style = 'width: 325px;font-weight:bold'>";switch(lic_option_code){case"1":DisclaimerHtml=DisclaimerHtml+"*This store carries CAB<sup>&reg;</sup> deli items only.";break;case"2":DisclaimerHtml=DisclaimerHtml+"*Be sure to ask for the CAB<sup>&reg;</sup> brand menu items!";break;case"3":DisclaimerHtml=DisclaimerHtml+"*Can be found in the fresh meat case";break;case"4":DisclaimerHtml=DisclaimerHtml+"*Can be found in the fresh meat case and the deli";break;case"6":case"7":DisclaimerHtml=DisclaimerHtml+"*Look for the CAB<sup>&reg;</sup> logo!";break;}
DisclaimerHtml=DisclaimerHtml+"</div>";var StandardHtml="<br /><table style = 'width: 325px'><tr><td style = 'width: 115px'>"+ImageHtml+"</td><td valign='top'><b>"+dba_name+"</b><br />"+WebSiteHtml+EmailHtml+"<br />";var LatLng=new GLatLng(lat,lng);var marker=new GMarker(LatLng,{title:dba_name+" - 9"+co_key+"9"});to_htmls[k]=StandardHtml+'<br />Directions:<br /><b>To Location</b> or <a href="javascript:fromhere('+"9"+co_key+"9"+')">From Location</a>'+'<br />Start address:<form action="javascript:getDirections()">'+'<input type="text" SIZE=27 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>'+'<INPUT value="Get Directions" TYPE="SUBMIT">'+'<input type="hidden" id="daddr" value="'+dba_name+"@"+lat+','+lng+'"/></form></td></tr></table>'+DisclaimerHtml;from_htmls[k]=StandardHtml+'<br />Directions:<br /><a href="javascript:tohere('+"9"+co_key+"9"+')">To Location</a> or <b>From Location</b>'+'<br />End address:<form action="javascript:getDirections()">'+'<input type="text" SIZE=27 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>'+'<INPUT value="Get Directions" TYPE="SUBMIT">'+'<input type="hidden" id="saddr" value="'+dba_name+"@"+lat+','+lng+'"/></form></td></tr></table>'+DisclaimerHtml;var InactiveHtml=StandardHtml+'<br />Directions:<br /><a href="javascript:tohere('+"9"+co_key+"9"+')">To Location</a> or <a href="javascript:fromhere('+"9"+co_key+"9"+')">From Location</a></td></tr></table>'+DisclaimerHtml;marker.bindInfoWindowHtml(InactiveHtml);map.addOverlay(marker);gmarkers[k]=marker;htmls[k]=InactiveHtml;k++;document.getElementById("gmap").style.visibility="visible";document.getElementById("reshead").style.visibility="visible";document.getElementById("Disclaimer").style.visibility="visible";}
function getDirections(){var saddr=document.getElementById("saddr").value
var daddr=document.getElementById("daddr").value
if(saddr!=""&&daddr!=""){GEvent.addListener(gdir,"load",handle);gdir.load("from: "+saddr+" to: "+daddr);}}
function handle(){var stat=gdir.getStatus().code;if(stat=="200"){document.getElementById("DirectionsHeader").style.visibility="visible";map.closeInfoWindow();}}
function tohere(j){for(var i=0;i<gmarkers.length;i++){if(gmarkers[i].getTitle().indexOf(j.toString().trim())>-1){gmarkers[i].openInfoWindowHtml(to_htmls[i]);}}}
function fromhere(j){for(var i=0;i<gmarkers.length;i++){if(gmarkers[i].getTitle().indexOf(j.toString().trim())>-1){gmarkers[i].openInfoWindowHtml(from_htmls[i]);}}}
function OpenInfoWindow(Lid,IsMapped){if(IsMapped=="True"){for(var i=0;i<gmarkers.length;i++){if(gmarkers[i].getTitle().indexOf(Lid.toString().trim())>-1){GEvent.trigger(gmarkers[i],"click");}}}
else{var WLoc=(screen.availWidth-350)/2;var HLoc=(screen.availHeight-170)/2;window.open("CoDetail.aspx?co="+Lid,"CoDetail","status=1,width=350,height=170,screenX="+WLoc+",screenY="+HLoc+",top="+HLoc+",left="+WLoc);}}
function OpenZipFind(){var Win=window.open("ZipFind.aspx","ZipFind","status=1,width=350,height=410");Win.moveTo(screen.availWidth/2-(350/2),screen.availHeight/2-(410/2));}
function ClearDirections(){gdir.clear();document.getElementById("DirectionsHeader").style.visibility="hidden";}
function PrintDirections(){map.closeInfoWindow();var a=window.open('','WhereToBuyCertifiedAngusBeef','');a.document.open("text/html");if(navigator.userAgent.toLowerCase().indexOf('msie')!=-1){a.document.write("<div id='map' style='width: 500px; height: 400px; overflow:hidden;'>");map.removeControl(LgMapControl);map.removeMapType(G_SATELLITE_MAP);map.removeMapType(G_HYBRID_MAP);a.document.write(document.getElementById('gmap').innerHTML);map.addControl(LgMapControl);map.addMapType(G_SATELLITE_MAP);map.addMapType(G_HYBRID_MAP);a.document.write("</div>");a.document.write("<br />");}
a.document.write("<div style='width: 500px; height: 400px;'>");a.document.write(document.getElementById('Directions').innerHTML);a.document.write("</div>");a.document.close();a.print();a.close();}
function PrintList(text){var p=window.open('','List','');p.document.open("text/html");p.document.write("<html><head><title>Print Locations</title><style type='text/css'>h3{color:#660000;}</style></head><body><div style='width: 500px;'>");p.document.write(text);p.document.write("</div></body></html>");p.document.close();p.print();p.close();}
function ValidateZipCity(oSrc,args){var Result=false;if(document.getElementById("ctl00_body_TxtZipCode").value.length>4){if(document.getElementById("ctl00_body_RblType_0").checked==true||document.getElementById("ctl00_body_RblType_1").checked==true){ZipCodeSearch=true;Result=true;DisableCityState();}
else{document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please choose the type of location you are searching for.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}}
else{if(document.getElementById("ctl00_body_DdlCountry").selectedIndex!=0){var Con=document.getElementById("ctl00_body_DdlCountry").options[document.getElementById("ctl00_body_DdlCountry").selectedIndex].text.replace(/^\s+|\s+$/g,'');if(Con=="United States of America"||Con=="Canada"){if((document.getElementById("ctl00_body_DdlState").selectedIndex!=0)&&document.getElementById("ctl00_body_TxtCity").value!=""){if(document.getElementById("ctl00_body_RblType_0").checked==true||document.getElementById("ctl00_body_RblType_1").checked==true){ZipCodeSearch=false;Result=true;DisableZipSearch();}
else{document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please choose the type of location you are searching for.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}}
else{Result=false;if(document.getElementById("ctl00_body_DdlState").selectedIndex!=0){document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please enter a zip code or a city.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}
else{document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please enter a zip code or select a state/territory.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}}}
else{if(document.getElementById("ctl00_body_RblType_0").checked==true||document.getElementById("ctl00_body_RblType_1").checked==true){ZipCodeSearch=false;Result=true;DisableZipSearch();}
else{document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please choose the type of location you are searching for.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}}}
else{Result=false;document.getElementById("ctl00_body_CusValZipCity").innerHTML="Please enter a zip code or select a country.";document.getElementById("ctl00_body_CusValZipCity").style.visibility="visible";}}
args.IsValid=Result;}
function ResetFields(){document.getElementById("ctl00_body_TxtCity").disabled=false;document.getElementById("ctl00_body_TxtCity").style.backgroundColor='white';document.getElementById("ctl00_body_TxtCity").value="";document.getElementById("ctl00_body_DdlState").disabled=false;document.getElementById("ctl00_body_DdlState").style.backgroundColor='white';document.getElementById("ctl00_body_DdlState").selectedIndex=0;document.getElementById("ctl00_body_DdlCountry").disabled=false;document.getElementById("ctl00_body_DdlCountry").style.backgroundColor='white';for(var i=0;i<=document.getElementById("ctl00_body_DdlCountry").length-1;i=i+1){var ddlText=document.getElementById("ctl00_body_DdlCountry").options[i].outerText;if(ddlText=="United States of America"){document.getElementById("ctl00_body_DdlCountry").selectedIndex=i;break;}}
document.getElementById("ctl00_body_TxtZipCode").disabled=false;document.getElementById("ctl00_body_TxtZipCode").style.backgroundColor='white';document.getElementById("ctl00_body_TxtZipCode").value="";document.getElementById("ctl00_body_DdlMiles").disabled=false;document.getElementById("ctl00_body_DdlMiles").style.backgroundColor='white';document.getElementById("ctl00_body_DdlMiles").selectedIndex=1;document.getElementById("ctl00_body_RblType_0").checked=false;document.getElementById("ctl00_body_RblType_1").checked=false;}
function DisableCityState(){document.getElementById("ctl00_body_TxtCity").disabled=true;document.getElementById("ctl00_body_TxtCity").style.backgroundColor='#d6d5d9';document.getElementById("ctl00_body_DdlState").disabled=true;document.getElementById("ctl00_body_DdlState").style.backgroundColor='#d6d5d9';document.getElementById("ctl00_body_DdlCountry").disabled=true;document.getElementById("ctl00_body_DdlCountry").style.backgroundColor='#d6d5d9';}
function ToggleState(){var Con=document.getElementById("ctl00_body_DdlCountry").options[document.getElementById("ctl00_body_DdlCountry").selectedIndex].text.replace(/^\s+|\s+$/g,'');if(Con!="United States of America"&&Con!="Canada"){document.getElementById("ctl00_body_DdlState").disabled=true;document.getElementById("ctl00_body_DdlState").style.backgroundColor='#d6d5d9';}
else{document.getElementById("ctl00_body_DdlState").disabled=false;document.getElementById("ctl00_body_DdlState").style.backgroundColor='white';}}
function DisableZipSearch(){document.getElementById("ctl00_body_TxtZipCode").disabled=true;document.getElementById("ctl00_body_TxtZipCode").style.backgroundColor='#d6d5d9';document.getElementById("ctl00_body_DdlMiles").disabled=true;document.getElementById("ctl00_body_DdlMiles").style.backgroundColor='#d6d5d9';}