
﻿function AjaxEventInfo(uniqueId,rawEventInfoString){this.uniqueId=uniqueId;var infoSplit=rawEventInfoString.split("_");var maybeActivatedElementId=infoSplit[0];if(maybeActivatedElementId.charAt(0)!="#"){this.activatedElementId=maybeActivatedElementId;this.activatedElement=document.getElementById(this.activatedElementId);this.eventType=GoHazel.EventTypes[infoSplit[1]];}
else{this.activatedElementId=null;this.activatedElement=null;this.eventType=null;}
this.elapsedServerTime=0;this.clientStartTime=new Date();this.elapsedTime=function(){return(new Date().getTime()-this.clientStartTime.getTime());};this.keepGoing=true;this.end=function(){this.keepGoing=false;};}
function GetXmlHttpRequest(){var xmlHttp;try{xmlHttp=new XMLHttpRequest();}
catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(evt){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(err){alert("Your browser does not support AJAX!");}}}
return xmlHttp;}
function GetAjaxPage(secure){if(!secure){return"__RenderAJAX.aspx";}
if(window.location.protocol=="https://"){return"__RenderAJAX.aspx";}
var result="https://"+window.location.host+window.location.pathname;var lastSlash=result.lastIndexOf("/");return result.substring(0,lastSlash+1)+"__RenderAJAX.aspx";}
function RunInstructions(infoPackage,eventModel){var instructions;var serverState;var literalValues=[];eventModel.elapsedServerTime=infoPackage.getAttribute("ElapsedTime");var clientVars=infoPackage.getElementsByTagName('ClientVariable');var clientSources=infoPackage.getElementsByTagName('ClientSource');__ClientStateFields=[];__ClientStateValues=[];for(var cIndex=0;cIndex<clientVars.length;cIndex++){__ClientStateFields.push(clientVars[cIndex].childNodes[0].nodeValue);__ClientStateValues.push(clientSources[cIndex].childNodes[0].nodeValue);}
var firstElement=infoPackage.getElementsByTagName('Instructions')[0];var firstChild=firstElement.childNodes[0];if(!firstChild){return;}
instructions=firstChild.nodeValue;var literalValueNodes=infoPackage.getElementsByTagName('LiteralValue');for(var index=0;index<literalValueNodes.length;index++){var firstLiteralChild=literalValueNodes[index].childNodes[0];literalValues[index]=firstLiteralChild?firstLiteralChild.nodeValue:"";}
eval(instructions);}
function DoAjax(eventInfo,eventData,secure){eventData=eventData||"";secure=secure||false;var clientState=CollectClientState(eventInfo,escape(eventData));var eventModel=new AjaxEventInfo(GoHazel.ajaxCounter++,eventInfo);GoHazel.pendingAjaxEvents.push(eventModel);if(typeof GoHazel.ajaxBefore=='function'){GoHazel.ajaxBefore(eventModel);}
if(!eventModel.keepGoing){GoHazel.removePendingAjaxEvent(eventModel.uniqueId);return;}
var xmlHttp=GetXmlHttpRequest();xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){RunInstructions(xmlHttp.responseXML.documentElement,eventModel);if(typeof GoHazel.ajaxAfter=='function'){GoHazel.ajaxAfter(eventModel);}
GoHazel.removePendingAjaxEvent(eventModel.uniqueId);}};var ajaxPage=GetAjaxPage(secure);xmlHttp.open("POST",ajaxPage,true);xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlHttp.send(clientState);}
function __UpdateBodyHtml(newHtml){document.body.innerHTML=newHtml;var d=document.body.getElementsByTagName("script");var t=d.length;for(var x=0;x<t;x++){var newScript=document.createElement("script");newScript.type="text/javascript";if(d[x].getAttribute("src")){newScript.setAttribute("src",d[x].getAttribute("src"));}else{newScript.text=d[x].text;}
document.body.appendChild(newScript);}
var dL=document.body.getElementsByTagName("link");var tL=dL.length;for(var xL=0;xL<tL;xL++){var newLink=document.createElement("link");newLink.setAttribute("rel","stylesheet");newLink.setAttribute("type","text/css");newLink.setAttribute("href",dL[xL].getAttribute("href"));document.body.appendChild(newScript);}}
function __RefreshPage(){window.location.reload();}
function __runErrorDialog(msg){var count=$("#__ghDiv").length;if(count<=0){var div=jQuery("<div id='__ghDiv' title='Runtime Error'></div>");div.appendTo(document.body);}
$("#__ghDiv").html(msg);$("#__ghDiv label").css({"display":"block","width":"4px","float":"left"});$("#__ghDiv").dialog({resizable:true,buttons:{"OK":function(){$(this).dialog("destroy");}}});}
var GoHazel={ajaxBefore:null,ajaxAfter:null,EventTypes:["","Click","KeyUp","Change"],ajaxCounter:0,pendingAjaxEvents:[],removePendingAjaxEvent:function(uniqueId){for(var i=0;i<this.pendingAjaxEvents.length;i++){var evt=this.pendingAjaxEvents[i];if(evt.uniqueId==uniqueId){this.pendingAjaxEvents.splice(i,1);return;}}},ajaxSubmitIfEnter:function(jsEvt,ghEvtInfo){var action="DoAjax(\""+ghEvtInfo+"\", \"\");";return GoHazel.submitIfEnter(jsEvt,action);},submitIfEnter:function(evt,action){var keycode;if(window.event){keycode=window.event.keyCode;}
else if(evt){keycode=evt.which;}
else{return true;}
var result=true;if(keycode==13){eval(action);result=false;}
if(!result){if(window.event){window.event.returnValue=false;window.event.cancelBubble=true;}else{evt.preventDefault();evt.stopPropagation();evt.cancelBubble=true;}}
return result;},ajaxCall:function(eventInfo,eventData,eventContainer){eventContainer=eventContainer||"";DoAjax("#"+eventContainer+"#"+eventInfo,eventData);},secureAjaxCall:function(eventInfo,eventData,eventContainer){eventContainer=eventContainer||"";DoAjax("#"+eventContainer+"#"+eventInfo,eventData,true);}};
