﻿var d=document;function fnGetBaseUrl()
{var strUrl=location.href;return strUrl.substring(0,strUrl.indexOf("/",strUrl.indexOf("/",strUrl.indexOf("/",8)+1))+1);}
function fnClearTextBoxValue(txt,strDefaultValue)
{var strCurrentValue=txt.value;if(strCurrentValue==strDefaultValue)
{txt.value="";}}
function fnRestoreTextBoxValue(txt,strDefaultValue)
{var strCurrentValue=txt.value;set
if(strCurrentValue=="")
{txt.value=strDefaultValue;}}
function fnClickButton(e,strButtonID)
{var evt=e?e:window.event;var btn=document.getElementById(strButtonID);if(btn)
{if(evt.keyCode==13)
{btn.click();return false;}}}
function fnClickButtonOnEnter(e,strButtonID)
{var evt=e?e:window.event;var btn=d.getElementById(strButtonID);if(btn)
{if(evt.keyCode==13)
{btn.click();return false;}}}
function fnOnclickOnEnter(lnk)
{if(((document.all)?window.event.keyCode:event.which)==13)
{}
else
{return true;}}
function fnToggleElement(strElementId)
{ele=d.getElementById(strElementId);if(ele.style.visibility=="hidden"||ele.style.display=="none"||ele.style.visibility==""||ele.style.display=="")
{ele.style.display="block";ele.style.visibility="visible";}
else
{ele.style.display="none";ele.style.visibility="hidden";}}
function AjaxManager()
{}
AjaxManager.prototype.Execute=function(url,onReadyStateHandler)
{var httpRequest=this.GetHttpRequest();httpRequest.onreadystatechange=onReadyStateHandler;httpRequest.open("GET",url,true);httpRequest.send(null);return httpRequest;}
AjaxManager.prototype.IsComplete=function(httpRequest)
{if(httpRequest==undefined)
{return false;}
if(httpRequest.readyState==4||httpRequest.readyState=="complete")
{return true;}
return false;}
AjaxManager.prototype.GetHttpRequest=function()
{req=null;if(window.XMLHttpRequest)
{try
{req=new XMLHttpRequest();}
catch(e)
{req=null;}}
else if(window.ActiveXObject)
{try
{req=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{try
{req=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e)
{req=null;}}}
return req;}
function fnResultMouseOver(div)
{div.style.backgroundColor="#eeeeee";}
function fnResultMouseOut(div)
{div.style.backgroundColor="transparent";}
function fnOpenNewWindow(strUrl,strPopupName,intPopupWidth,intPopupHeight,strProperties)
{var intPopupX=(screen.width-intPopupWidth)/2;var intPopupY=(screen.height-intPopupHeight)/2;var arrProperties=["width=",intPopupWidth,",height=",intPopupHeight,",left=",intPopupX,",top=",intPopupY,",",strProperties];var objWindow=window.open(strUrl,strPopupName,arrProperties.toString(""));if(objWindow)
objWindow.focus();return objWindow;}
function fnOpenGISWindow(strUrl)
{fnOpenNewWindow(strUrl,"GISWindow",900,700,"address=0,addressbar=0,menu=0,menubar=0,resizable=0,status=0,statusbar=0")}
function fnOpenCSCVirtualTourWindow(strUrl)
{fnOpenNewWindow(strUrl,"CSCVirtualTourWindow",903,500,"address=0,addressbar=0,menu=0,menubar=0,resizable=0,status=0,statusbar=0")}
function fnOpenMuseumVirtualTourWindow(strUrl)
{fnOpenNewWindow(strUrl,"MuseumVirtualTourWindow",512,520,"address=0,addressbar=0,menu=0,menubar=0,resizable=0,status=0,statusbar=0")}
function clearText(textBoxID,defaultVal)
{if(document.getElementById(textBoxID).value==defaultVal)
{document.getElementById(textBoxID).value='';}}
function clickOnEnter(buttonID)
{if(((document.all)?window.event.keyCode:event.which)==13)
{document.getElementById(buttonID).click();return false;}
else
{return true;}}
function OpenWindow(URL,name,width,height)
{window.open(URL,name,"scrollbars=yes,width="+width+",height="+height);}
function fnFocusOnSelect(intFocusOn)
{var d=document;var divText=d.getElementById('divFocusOnText');divText.innerHTML=arrFocusOnText[intFocusOn];liSelected=d.getElementById("liFocusOn"+intSelectedFocusOn);if(liSelected.className.indexOf("selected")>-1)
{liSelected.className=liSelected.className.substring(0,liSelected.className.indexOf(" selected"))}
var liToSelect=d.getElementById("liFocusOn"+intFocusOn);liToSelect.className=liToSelect.className+" selected";intSelectedFocusOn=intFocusOn;}
function whubEventsCalendar(strCalendarContainerId,strSelectedDate,strPartnerAcronym,strEventsCalendarPageUrl,strBaseUrl,strEventsDetailsContainerID,blnShowFullEventDetails,intResultCount)
{strContainerID=strCalendarContainerId;strEventsDetailsContainerID=strEventsDetailsContainerID;this.SelectedDate=strSelectedDate;this.Partner=strPartnerAcronym;this.EventsCalendarPageUrl=strEventsCalendarPageUrl;this.PageBaseUrl=strBaseUrl;this.CalendarHTMLURL="Plugins/EventsCalendar/AJAX/GetCalendarHTML.aspx";this.EventDetailsHTMLURL="Plugins/EventsCalendar/AJAX/GetEventDetailsHTML.aspx";var calendarUpdateManager=new AjaxManager();var eventsUpdateManager=new AjaxManager();var calendarHttpRequest=null;var eventsHttpRequest=null;this.Update=function(strNewDate)
{calendarHttpRequest=null;var strQS="?ID="+strContainerID+"&SelectedDate="+strNewDate+"&Partner="+this.Partner+"&EventsCalendarUrl="+this.EventsCalendarPageUrl;var strUrl=this.PageBaseUrl+this.CalendarHTMLURL+strQS;calendarHttpRequest=calendarUpdateManager.Execute(strUrl,UpdateCalendar_Callback);this.NewDate=strNewDate;strQS="?SelectedDate="+strNewDate+"&Partner="+this.Partner+"&EventsCalendarUrl="+this.EventsCalendarPageUrl+"&ShowFullDetails="+blnShowFullEventDetails+"&ResultCount="+intResultCount
var strUrl=this.PageBaseUrl+this.EventDetailsHTMLURL+strQS;eventsHttpRequest=eventsUpdateManager.Execute(strUrl,UpdateEventDetails_Callback);return false;}
function UpdateCalendar_Callback()
{if(calendarUpdateManager.IsComplete(calendarHttpRequest))
{var strHtml=calendarHttpRequest.responseText;calendarHttpRequest=null;if(strHtml)
{d.getElementById(strContainerID).innerHTML=strHtml;this.SelectedDate=this.NewDate;this.NewDate=null;}}}
function UpdateEventDetails_Callback()
{if(eventsUpdateManager.IsComplete(eventsHttpRequest))
{var strHtml=eventsHttpRequest.responseText;eventsHttpRequest=null;if(strHtml)
{d.getElementById(strEventsDetailsContainerID).innerHTML=strHtml;}}}}
function whubGoogleMapControl(strMapContainerID,strLongitude,strLatitude,intZoomLevel,strBorderUrl,strAPIKey)
{var strScriptId="scrptWhubGoogleMapPlugin";var blnMapReady=false;var btnUpdate=null;var btnReset=null;this.googleMap=null;this.layers=new Array();this.border=null;this.dynamicLoad=function()
{if(!d.getElementById(strScriptId))
{btnUpdate=d.getElementById("btnUpdate-"+strMapContainerID);btnReset=d.getElementById("btnReset-"+strMapContainerID);btnUpdate.disabled="disabled";btnReset.disabled="disabled";fnShowStatus();if(location.href.indexOf("www.worcestershire.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBTKwbA4yruutuWwHhQ1gXgIX0dzLhQ3FVC0XA0lvoHQpceItu-43FLzkA";}
else if(location.href.indexOf("whub.org.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBTsOvB2e4PnjUXlvrFCXwkJBva4LhQJvn3Ovv6c_aAMcgWDB1VidNdg3A";}
else if(location.href.indexOf("www.bromsgrove.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBTkGsWDCrjRhscFh2C5nVrsC27b4hQ_z8KNK0d3XYw9aZV8kUAySXZixA";}
else if(location.href.indexOf("www.malvernhills.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBQr23v877zmtoykJ6lAcqmc8TEVcRRpV3oTlM5SG67n405lsY-9QUbqEA";}
else if(location.href.indexOf("www.redditch.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBTBWPzBNaAZoiYmuofZkgJvzxKU3xSNIdTrL8Qq1Jzn8kxODJua8zaceQ";}
else if(location.href.indexOf("www.wychavon.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBQuHVglvzZb8bD1pf3BGUjzV8Z8tRQ_lI13ztEgm1NUU8ku-8Drvbg9Fw";}
else if(location.href.indexOf("www.wyreforestdc.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBS66SVdzD_5JKucXyPoeKl3mouyrxQxOjkUr4mqDcS1_hvxJ7WzG-3lUw";}
else if(location.href.indexOf("www.worcester.gov.uk")>-1)
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBRu3ZqoDxYxvo3KdDw15E8mEI0rrxQ4Gq3hhHY7kM5qKvoLVC1msSoFbw";}
else
{strAPIKey="ABQIAAAAjNYYnob9oMOm1M6LvSY5KBSY_MYKlWxDbMF9_Vr1ack__N9LWRQBBUTSwY992DfN_gDRVMaaIAZnyQ";}
var script=d.createElement("script");script.id=strScriptId;script.type="text/javascript";script.src="http://maps.google.com/maps?file=api&v=2.x&key="+strAPIKey+"&async=2&callback=map_"+strMapContainerID+".initialise";d.body.appendChild(script);}}
this.initialise=function()
{if(GBrowserIsCompatible())
{fnShowStatus();this.googleMap=new GMap2(document.getElementById(strMapContainerID));this.goToDefaultLocation();this.googleMap.setUIToDefault();this.loadBorder();GEvent.addListener(this.googleMap,"tilesloaded",function(){fnHideStaticMap();fnHideStatus();blnMapReady=true;d.getElementById("btnUpdate-divGoogleMap").disabled="";d.getElementById("btnReset-divGoogleMap").disabled="";});}
else
{alert("The page you are viewing is trying to display a Google Map but your web browser does not support this.");}}
function fnShowStatus()
{var div=d.getElementById("divLoading_"+strMapContainerID);div.innerHTML="Loading...";div.style.zIndex="2";}
function fnHideStatus()
{var div=d.getElementById("divLoading_"+strMapContainerID);div.style.zIndex="-1";}
function fnHideStaticMap()
{d.getElementById("imgStaticMap_"+strMapContainerID).style.zIndex="-1";}
this.loadBorder=function()
{if(strBorderUrl!="")
{this.border=new GGeoXml(strBorderUrl)
var str
for(x in this.border)
{str+=x+"\n"}
alert(str)
this.googleMap.addOverlay(this.border);}}
this.goToDefaultLocation=function()
{this.googleMap.setCenter(new GLatLng(strLongitude,strLatitude),intZoomLevel)}
this.reset=function()
{for(var i=0;i<this.layers.length;i++)
{this.layers[i].remove();}
var ddl=d.getElementById("ddlLayers_"+strMapContainerID);if(ddl)
{for(var i=0;i<ddl.options.length;i++)
{ddl.options[i].innerHTML=ddl.options[i].innerHTML.replace(" (On)","");}}
this.goToDefaultLocation();}
this.unload=function()
{if(d.getElementById(strScriptId)&&blnMapReady)
{GUnload();}}
this.addLayer=function(strLayerDataUrl)
{this.layers.push(new whubGoogleMapLayer(strLayerDataUrl));}
this.toggleByDropdown=function()
{var ddl=d.getElementById("ddlLayers_"+strMapContainerID);if(ddl)
{var intLayerID=ddl.options[ddl.selectedIndex].value;if(intLayerID!="")
{this.toggleLayer(intLayerID);var strLayerText=ddl.options[ddl.selectedIndex].innerHTML;var strLayerOffText="";var strLayerOnText=" (On)";if(strLayerText.indexOf(strLayerOnText)>-1)
{ddl.options[ddl.selectedIndex].innerHTML=strLayerText.substring(0,strLayerText.indexOf(strLayerOnText))}
else
{ddl.options[ddl.selectedIndex].innerHTML=strLayerText+strLayerOnText;}}
else
{alert("Please select an option from the drop down menu in order to make a change to the map.")}}}
this.toggleLayer=function(intLayerID)
{if(blnMapReady)
{if(this.layers[intLayerID].isVisible)
{this.layers[intLayerID].remove()}
else
{for(var i=0;i<this.layers.length;i++)
{if(i!=intLayerID)
{if(this.layers[i].isVisible)
{this.layers[i].remove();var ddl=d.getElementById("ddlLayers_"+strMapContainerID);if(ddl)
{ddl.options[i+1].innerHTML=ddl.options[i+1].innerHTML.replace(" (On)","");}}}}
this.layers[intLayerID].display(this.googleMap)}}
else
{alert("In order to make this page load quicker for you, we delayed loading the map until it looked like you wanted to use it.\n\nYou were a bit quick and the map hasn't quite finished loading yet, please click OK and try again and everything should be ready.");}}}
function whubGoogleMapLayer(strUrl)
{var strUrl=strUrl;var overlay=null;this.hasLoaded=false;this.isVisible=false;this.display=function(whubGglMp)
{if(!this.isVisible)
{if(!this.hasLoaded)
{this.load(whubGglMp);}
else
{this.show(whubGglMp);}}}
this.remove=function()
{if(this.isVisible)
{overlay.hide();this.isVisible=false;}}
this.show=function(whubGglMp)
{if(!this.isVisible)
{if(this.hasLoaded)
{overlay.show()
this.isVisible=true;}
else
{alert("We were unable to update the map because the data has not loaded.  Please try again later.")}}}
this.load=function(whubGglMp)
{if(!this.hasLoaded)
{overlay=new GGeoXml(strUrl)
this.hasLoaded=true;whubGglMp.addOverlay(overlay);this.isVisible=true;}}}
function fnTidyPoll()
{arrTbls=d.body.getElementsByTagName("table")
for(var i=0;i<arrTbls.length;i++)
{if(arrTbls[i].id.indexOf("ctl00_userpoll")>-1&&arrTbls[i].id.indexOf("_tbl")>-1)
{arrTbls[i].style.width="246px";arrTbls[i].style.padding="5px";arrTbls[i].style.border="0px solid #cccccc";var arrSubTbls=arrTbls[i].getElementsByTagName("table");for(var j=0;j<arrSubTbls.length;j++)
{arrSubTbls[j].style.width="150px";}}}}
function fnTidyForm()
{var arrTables=document.getElementsByTagName("table");for(i=0;i<arrTables.length;i++)
{if(arrTables[i].className=="tbform")
{var arrInputs=arrTables[i].getElementsByTagName("input");for(j=0;j<arrInputs.length;j++)
{if(arrInputs[j].type=="text")
{arrInputs[j].onfocus=function(){this.select();}}}
var arrTextareas=arrTables[i].getElementsByTagName("textarea");for(k=0;k<arrTextareas.length;k++)
{arrTextareas[k].onfocus=function(){this.select();}}}}}
