
function evalJSON(resp){var json;try{json=JSON.parse(resp);}
catch(e){eval('json = '+resp+';');}
return json;}
function XMLHttp(callback,params,timeout){var that=this;this.status=false;this.xmlhttp=false;this.URL=null;this.scripts=new Array();this.timeout=(timeout)?timeout:30000;this.callback=callback;this.params=params;this.timerid=null;this.resp=null;this.retry=false;this.content=null;this.verbose=true;HideTooltip();if(window.XMLHttpRequest){this.xmlhttp=new XMLHttpRequest()}
else if(window.ActiveXObject){this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
this.Abort=function(){that.xmlhttp.abort();}
this.Response=function(){var tmp=that.xmlhttp.responseText.replace(/<\?xml(.*)\/?>\n?/gim,"");tmp=tmp.replace(/<!DOCTYPE(.*)?>\n?/gim,"");var reg=/<script[^>]*>([\S\s]*?)<\/script>/gim;var scr=tmp.match(reg);if(scr){for(var i=0;i<scr.length;i++){that.scripts[that.scripts.length]=scr[i].replace(reg,'$1');}}
return tmp.replace(reg,'');}
this.EvalScripts=function(){for(var i=0;i<that.scripts.length;i++){eval(that.scripts[i]);}}
this.setVerbose=function(verbose){this.verbose=verbose;}
this.ProcessStatus=function(){if(that.xmlhttp.readyState==4){switch(that.xmlhttp.status){case 0:break;case 200:case 304:that.resp=that.Response();break;case 403:case 404:that.resp='<div class="PageTitle">Error</div><div class="Error">HTTP: 404 File not found</div><div>'+that.URL+'</div>';break;default:if(that.retry){alert('ProcessStatus Status: '+that.xmlhttp.status+' is not supported at this time.');}
else{that.retry=true;if(that.content){that.xmlhttp.send(that.content);}
else{that.xmlhttp.send(null);}}
break;}
if(that.timerid){window.clearTimeout(that.timerid);that.timerid=null;}
if(that.callback){that.callback(that.resp,that);}}}
this.ProcessJSONStatus=function(){if(that.xmlhttp.readyState==4){switch(that.xmlhttp.status){case 0:break;case 200:case 304:that.resp=evalJSON(that.xmlhttp.responseText);break;}
if(that.timerid){window.clearTimeout(that.timerid);that.timerid=null;}
if(that.callback){that.callback(that.resp,that);}}}
this.GetContent=function(URL){that.URL=URL.replace(/&amp;/img,"&");if(that.xmlhttp){if(that.callback){that.timerid=window.setTimeout(function(){that.xmlhttp.abort();if(that.verbose){alert("AJAX Request timed out: "+that.URL);}
if(that.params["working"]){HideWorking(that.params["working"]);}},that.timeout);that.xmlhttp.onreadystatechange=that.ProcessStatus;that.xmlhttp.open("GET",that.URL,true);}
else{that.xmlhttp.open("GET",that.URL,false);}
that.xmlhttp.setRequestHeader('X_Requested_With','XMLHttpRequest');that.xmlhttp.send();if(!that.callback){that.ProcessStatus();return that.resp;}
else{return true;}}
else{return false;}}
this.PostContent=function(URL,form_id,ignore_defaults){that.URL=URL.replace(/&amp;/img,"&");if(that.xmlhttp){var form_obj=document.getElementById(form_id+"_form");if(form_obj){var r=[];for(var i=0;i<form_obj.length;i++){if(!form_obj.elements[i].disabled){switch(form_obj.elements[i].type){case'undefined':break;case'radio':if(form_obj.elements[i].checked){r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].value);}
break;case'select-one':var index=form_obj.elements[i].selectedIndex;r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].options[index].value);break;case'select-multiple':if(form_obj.elements[i].name.match(/\[\]$/)){for(var o=0;o<form_obj.elements[i].length;o++){if(form_obj.elements[i].options[o].selected){r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].options[o].value);}}}
else{var val=0;for(var o=0;o<form_obj.elements[i].length;o++){if(form_obj.elements[i].options[o].selected){val+=parseInt(form_obj.elements[i].options[o].value);}}
r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(val);}
break;case'checkbox':if(form_obj.elements[i].checked){r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].value);}
else{r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(0);}
break;case'hidden':r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].value);break;case'password':if(form_obj.elements[i].defaultValue!=form_obj.elements[i].value||!ignore_defaults){if(form_obj.elements[i].value){r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(calcMD5(form_obj.elements[i].value));}
else{r[r.length]=null;}}
break;default:if(form_obj.elements[i].defaultValue!=form_obj.elements[i].value||!ignore_defaults){r[r.length]=encodeURIComponent(form_obj.elements[i].name)+"="+encodeURIComponent(form_obj.elements[i].value);}
break;}}}
that.content=r.join('&');if(that.callback){that.timerid=window.setTimeout(function(){that.xmlhttp.abort();if(that.verbose){alert("AJAX Request timed out: "+that.URL);}
if(that.params["working"]){HideWorking(that.params["working"]);}},that.timeout);that.xmlhttp.onreadystatechange=that.ProcessStatus;that.xmlhttp.open("POST",that.URL,true);}
else{that.xmlhttp.open("POST",that.URL,false);}
that.xmlhttp.setRequestHeader('X_Requested_With','XMLHttpRequest');that.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');that.xmlhttp.setRequestHeader('Charset','UTF-8');that.xmlhttp.setRequestHeader('Content-Length',that.content.length);that.xmlhttp.send(that.content);}
else if(XDB_DEBUG){alert('Object: '+form_id+' not found!');}}
if(!that.callback){that.ProcessStatus();return that.resp;}
else{return true;}}
this.GetJSON=function(URL){that.URL=URL;if(that.xmlhttp){if(that.callback){that.timerid=window.setTimeout(function(){that.xmlhttp.abort();if(that.verbose){alert("AJAX Request timed out: "+that.URL);}},that.timeout);that.xmlhttp.onreadystatechange=that.ProcessJSONStatus;that.xmlhttp.open("GET",URL,true);}
else{that.xmlhttp.open("GET",URL,false);}
that.xmlhttp.setRequestHeader('X_Requested_With','XMLHttpRequest');that.xmlhttp.send("");if(!that.callback){that.ProcessJSONStatus();return that.resp;}
else{return true;}}
else{return that.status;}}}
function SetFocus(form_id,field_id){if(form_id&&field_id){$('#'+form_id+' #'+field_id).focus().select();}}
var focus_form=null;var focus_field=null;function UpdateContent_callback(resp,xmlhttp,no_animation){var retval=true;if(resp&&resp!=''){if(resp.substring(0,33)=="<body id=\"body\"><div class=\"Error"){ShowPopup('CallbackError','Error',resp);xmlhttp.EvalScripts();retval=false;}
else if(resp.substring(0,35)=="<body id=\"body\"><div class=\"Warning"){ShowPopup('CallbackWarning','Warning',resp);xmlhttp.EvalScripts();}
else if(resp.substring(0,40)=="<body id=\"body\"><div class=\"Notification"){ShowPopup('CallbackNotification','Notification',resp);xmlhttp.EvalScripts();}
else{var id='#'+xmlhttp.params["id"];if(no_animation||($.browser.msie&&$.browser.version<8)||$(id).css("display")=='none'){$(id).html(resp);}
else{$(id).hide().html(resp).fadeIn("normal");}
xmlhttp.EvalScripts()
if(xmlhttp.params["callback"]){xmlhttp.params["callback"](xmlhttp.params["params"]);}}}
if(typeof(FB)!="undefined"){FB.XFBML.parse(document.getElementById(xmlhttp.params["id"]));}
HideWorking(xmlhttp.params["working"]);SetFocus(focus_form,focus_field);return retval;}
function UpdateContent(id,URL,callback,callback_params,timeout){focus_form=null;focus_field=null;if(URL&&URL.length>0){var obj=document.getElementById(id);if(obj){var working=ShowWorking(obj);var params={"working":working,"id":id};if(callback){if(callback_params){for(var key in callback_params){params[key]=callback_params[key];}}}
else{callback=UpdateContent_callback;}
var HTTPobj=new XMLHttp(callback,params,timeout);HTTPobj.GetContent(URL);}
else if(XDB_DEBUG){alert('Object: '+id+' not found!');}}}
function AddContent_callback(resp,xmlhttp){if(resp&&resp!=''){$('#'+xmlhttp.params["id"].innerHTML).append(resp);xmlhttp.EvalScripts();}
if(typeof(FB)!="undefined"){FB.XFBML.parse(document.getElementById(xmlhttp.params["id"]));}
HideWorking(xmlhttp.params["working"]);SetFocus(focus_form,focus_field);}
function AddContent(id,URL){focus_form=null;focus_field=null;if(URL&&URL.length>0){var obj=document.getElementById(id);if(obj){var working=ShowWorking(obj);var params={"working":working,"id":id};var HTTPobj=new XMLHttp(AddContent_callback,params);HTTPobj.GetContent(URL);}
else if(XDB_DEBUG){alert('Object: '+id+' not found!');}}}
function RemoveContent(parent,child){var p=document.getElementById(parent);var c=document.getElementById(child);if(p&&c){p.removeChild(c);}}
function AddStylesheet(URL,media,title){var cssNode=document.createElement('link');cssNode.type='text/css';cssNode.rel='stylesheet';cssNode.href=URL;if(media){cssNode.media=media;}
else{cssNode.media='screen';}
if(title){cssNode.title=title;}
document.getElementsByTagName("head")[0].appendChild(cssNode);}
function ReloadStylesheet(URL,title){var nodes=document.getElementsByTagName("link");for(var i=0;i<nodes.length;i++){var s=nodes[i];if(s.rel=='stylesheet'&&s.href&&s.title==title){s.href=URL+(URL.indexOf('?')>=0?'&':'?')+'Reload='+(new Date().getTime());}}}
function ResetForm(form_id){var form_obj=document.getElementById(form_id+"_form");if(form_obj){form_obj.reset();}}
function PostContent(id,URL,form_id,callback,callback_params,timeout,ignore_defaults){focus_form=null;focus_field=null;var obj=document.getElementById(id);if(obj){var working=ShowWorking(obj);var params={"working":working,"id":id};if(callback){if(callback_params){for(var key in callback_params){params[key]=callback_params[key];}}}
else{callback=UpdateContent_callback;}
var HTTPobj=new XMLHttp(callback,params,timeout);HTTPobj.PostContent(URL,form_id,ignore_defaults);}
else if(XDB_DEBUG){alert('Object: '+id+' not found!');}}
function UpdateStaticContent(id,content){if(typeof(content)!='undefined'){if($('#'+id)){if($.browser.msie&&$.browser.version<8){$('#'+id).html(content);}
else{$('#'+id).hide().html(content).fadeIn();}}
else if(XDB_DEBUG){alert('Object: '+id+' not found!');}}}
function ShowNotification_callback(resp,xmlhttp){if(UpdateContent_callback(resp,xmlhttp,true)){$('#NotificationPopUp').center().fadeIn();}}
function ShowNotification(page_xid,title){if(page_xid){var notification=CreatePopUp("NotificationPopUp","StandardPopUp","body",title);UpdateContent('NotificationPopUp_Body','/page.php?PageId='+page_xid,ShowNotification_callback);}}
function GetJSON(URL,callback,params,timeout){var HTTPobj=new XMLHttp(callback,params,timeout);return HTTPobj.GetJSON(URL);}
