// Gaia Ajax Widgets Copyright (C) 2007  Frost Innovation AS. details at http://ajaxwidgets.com/
if(!window.Gaia)
Gaia=Class.create();Gaia.Control=Class.create();Gaia.Control._itsRegisteredInvisibleControls=new Array();Gaia.Control._itsRegisteredControls=new Array();Gaia.Control._itsRegisteredControlsArray=new Array();Gaia.Control._updateControl=null;Gaia.Control.setUpdateControl=function(el,isCallback){Gaia.Control._updateControl=el;if(el){Element.hide(el);}}
Gaia.Control.registerControl=function(control){if(Gaia.Control._itsRegisteredControls[control.element.id]){Gaia.Control._itsRegisteredControls[control.element.id].destroy();}
Gaia.Control._itsRegisteredControls[control.element.id]=control;Gaia.Control._itsRegisteredControlsArray.push(control);return control;}
Gaia.Control.destroyAllContaining=function(inId,except){var arr=new Array();Gaia.Control._itsRegisteredControlsArray.each(function(idx){if(idx.element.id!=except&&idx.element.id.indexOf(inId)!=-1)
arr.push(idx);});arr.each(function(idx){idx.destroy();});}
$G=function(control){return Gaia.Control._itsRegisteredControls[control];}
$FC=function(field){if($(field))
return $(field);var input=document.createElement('input');input.type='hidden';input.name=field;input.id=field;document.getElementsByTagName('form')[0].appendChild(input);return input;}
$FChange=function(field,unchangedTo,value){var el=$FC(field);el.value=el.value.substr(0,unchangedTo)+value;}
Gaia.Control._defaultUrl=null;Gaia.Control._version='1.0';Gaia.Control._activeRequest=false;Gaia.Control._activeRequests=new Array();Gaia.Control._createNewRequestImplementation=function(controlToCallFor,methodAfter,evt,extraParams,url,evalScripts){Gaia.Control._activeRequest=true;if(Gaia.Control._updateControl)
Element.show(Gaia.Control._updateControl);var evalScriptsPar=true;if(evalScripts!=null)
evalScriptsPar=evalScripts;var opt={method:'post',postBody:'GaiaCallback=true',onSuccess:function(t){if(methodAfter){if(Gaia.Control._updateControl)
Element.hide(Gaia.Control._updateControl);methodAfter(t);}
Gaia.Control._activeRequests.splice(0,1);Gaia.Control._activeRequest=false;},onFailure:function(err){if(confirm('Error from server: '+err.status+', \''+err.statusText+'\', Ajax Engine shutdown for security reasons, refresh page to enable application again...\nDo you wish to see the debug results?')){var dbg=document.createElement('iframe');dbg.width='100%';dbg.height='100%';dbg.style.position='absolute';dbg.style.left='0px';dbg.style.top='0px';dbg.style.zIndex=10000;document.body.appendChild(dbg);dbg.contentWindow.document.open();dbg.contentWindow.document.write(err.responseText);dbg.contentWindow.document.close();}},evalScripts:false};if($('__GAIA_FILES')){opt.postBody+='&__GAIA_FILES='+encodeURIComponent($F('__GAIA_FILES'));}
if($('__EVENTVALIDATION')){opt.postBody+='&__EVENTVALIDATION='+encodeURIComponent($F('__EVENTVALIDATION'));}
if($('__VIEWSTATE')){opt.postBody+='&__VIEWSTATE='+encodeURIComponent($F('__VIEWSTATE'));}
if($('__VIEWSTATEENCRYPTED')){opt.postBody+='&__VIEWSTATEENCRYPTED='+encodeURIComponent($F('__VIEWSTATEENCRYPTED'));}
if(extraParams){opt.postBody+='&gaiaParams='+encodeURIComponent(extraParams);}
Gaia.Control._itsRegisteredControlsArray.each(function(ctrl){if(ctrl==this)
opt.postBody+=ctrl._getElementPostValueEvent(evt);else
opt.postBody+=ctrl._getElementPostValue();}.bind(controlToCallFor));new Ajax.Request((url||(controlToCallFor?controlToCallFor.options.url:null)||Gaia.Control._defaultUrl),opt);}
Gaia.Control._dispatchNextRequest=function(request){if(Gaia.Control._activeRequest){setTimeout(function(){Gaia.Control._dispatchNextRequest(request)},50);}else{Gaia.Control._createNewRequestImplementation(request.control,request.method,request.evtIn,request.xtraParams,request.urlToCall,request.evaluate);}}
Gaia.Control._createNewRequest=function(controlToCallFor,methodAfter,evt,extraParams,url,evalScripts){var retVal={control:controlToCallFor,method:methodAfter,evtIn:evt,xtraParams:extraParams,urlToCall:url,evaluate:evalScripts};Gaia.Control._activeRequests.push(retVal);Gaia.Control._dispatchNextRequest(retVal);return retVal;}
Gaia.Control.returnValue=null;Gaia.Control.callPageMethod=function(method,params,onFinished){var parsedParams=method+',PageMethod';if(params){params.each(function(param){var idxParam=param;if(typeof param=='string'){while(idxParam.indexOf(',')!=-1){idxParam=idxParam.replace(',','|$|');}}
parsedParams+=','+idxParam;});}
Gaia.Control._createNewRequest(null,function(t){Gaia.Control.evalServerCallback('Gaia.Control.returnValue = '+t.responseText);if(onFinished)
onFinished(Gaia.Control.returnValue);},null,parsedParams,null,false);}
Gaia.Control.callControlMethod=function(method,params,onFinished,passId){var parsedParams=method+',ControlMethod,'+(passId||this.element.id);if(params){params.each(function(param){var idxParam=param;if(typeof param=='string'){while(idxParam.indexOf(',')!=-1){idxParam=idxParam.replace(',','|$|');}}
parsedParams+=','+idxParam;});}
Gaia.Control._createNewRequest(null,function(t){Gaia.Control.evalServerCallback('Gaia.Control.returnValue = '+t.responseText);if(onFinished)
onFinished(Gaia.Control.returnValue);},null,parsedParams,null,false);}
Gaia.Control.currentIdx=0;Gaia.Control.lastLoadedScript=null;Gaia.Control.evalServerCallback=function(script){Gaia.javaScriptFilesToWaitFor=0;Gaia.Control.lastLoadedScript=script.split(';;;;;');Gaia.Control.currentIdx=0;return Gaia.Control._executeScript(true);}
Gaia.Control._executeScript=function(shouldExecute){var retVal=null;if(Gaia.Control.currentIdx<Gaia.Control.lastLoadedScript.length){if(shouldExecute){retVal=eval(Gaia.Control.lastLoadedScript[Gaia.Control.currentIdx]);setTimeout('Gaia.Control._executeScript(false);',100);}else{if(Gaia.javaScriptFilesToWaitFor==0){Gaia.Control.currentIdx+=1;Gaia.Control._executeScript(true);}else{setTimeout('Gaia.Control._executeScript(false);',100);}}}
return retVal;}
Gaia.Control.prototype={initialize:Prototype.emptyFunction,baseInitializeControl:function(element){this.element=$(element);if(!this.element)
this.element=element;this.options=Object.extend({url:Gaia.Control._defaultUrl},arguments[1]||{});},setVisible:function(value){value?Element.show(this.element):Element.hide(this.element);return this;},setFocus:function(){this.element.focus();return this;},destroy:function(){this._destroyImpl();},_destroyImpl:function(){if(this._subscribedEvents){this._subscribedEvents.each(function(evt){Element.stopObserving(this.element,evt.name,evt.evt);}.bind(this));}
var toDestroy;var idx=0;Gaia.Control._itsRegisteredControlsArray.each(function(ctrl){if(ctrl.element.id==this.element.id){toDestroy=ctrl;throw $break;}
idx+=1;}.bind(this));if(toDestroy){Gaia.Control._itsRegisteredControlsArray.splice(idx,1);delete Gaia.Control._itsRegisteredControls[this.element.id];}},_observeImpl:function(evtName,bubbleUp){if(this._subscribedEvents==null){this._subscribedEvents=new Array();}
if(!this._subscribedEvents[evtName]){var _onEventEvent=this._onEvent.bindAsEventListener(this,evtName,bubbleUp);Element.observe(this.element,evtName,_onEventEvent);this._subscribedEvents.push({name:evtName,evt:_onEventEvent});}},observe:function(evtName,bubbleUp){this._observeImpl(evtName,(bubbleUp?true:false));return this;},_getElementPostValue:function(){throw"Abstract _getElementPostValue not overridet";},getCallbackName:function(){if(this.element.name&&this.element.name.length>0)
return this.element.name;var retVal=this.element.id;while(retVal.indexOf('_')!=-1){retVal=retVal.replace('_','$');}
return retVal;},_getElementPostValueEvent:function(){throw"Abstract _getElementPostValueEvent not overridet";},_onEventImpl:function(evt,evtName){if(typeof(WebForm_OnSubmit)=='function'){if(WebForm_OnSubmit()!=true)
return;}
if(window['_spFormOnSubmitCalled']!=null&&window['_spFormOnSubmitCalled']!='undefined'){_spFormOnSubmitCalled=false;}
if(Gaia.Control._updateControl==null)
this.setEnabled(false);this._updaterControl=Gaia.Control._updateControl;Gaia.Control._createNewRequest(this,this._afterEvent.bind(this),evt);},_shouldRunAjaxRequest:function(){return true;},_onEvent:function(evt,evtName,bubbleUp){try{this._onEventImpl(evt,evtName);}catch(err){alert("Gaia Error: _onEvent/Gaia - Control.js fire\n\nError Message:\n\n"+err);}
if(!bubbleUp)
Event.stop(evt);},_destroyAllChildren:function(el){var g=$G(el.id);for(var idx=0;idx<el.childNodes.length;idx++){this._destroyAllChildren(el.childNodes[idx]);}
if(g)
g.destroy();},_afterEvent:function(t){if($(this.element.id)){if(this._updaterControl==null)
this.setEnabled(true);}
Gaia.Control.evalServerCallback(t.responseText);}};Gaia.Control.browserFinishedLoading=true;