﻿
Type.registerNamespace('Interhome.Web.BL.WebFramework.Ajax');Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs=function(oldValue,newValue){Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs.initializeBase(this);this._oldValue=oldValue;this._newValue=newValue;};Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs.prototype={get_oldValue:function(){return this._oldValue;},get_newValue:function(){return this._newValue;}};Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs.registerClass('Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs',Sys.EventArgs);Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior=function(e){Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.initializeBase(this,[e]);this._parentControlID=null;this._secondaryParentControlID=null;this._category=null;this._promptText=null;this._promptSeperatorText=null;this._selectIfOnlyOneItem=null;this._loadingText=null;this._servicePath=null;this._serviceMethod=null;this._contextKey=null;this._additionalData=null;this._useContextKey=false;this._parentElement=null;this._changeHandler=null;this._parentChangeHandler=null;this._parentKeyupHandler=null;this._lastParentValues=null;this._selectedValue=null;this._redirects=null;};Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.prototype={initialize:function(){Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.callBaseMethod(this,'initialize');$common.prepareHiddenElementForATDeviceUpdate();var e=this.get_element();this._clearItems();e.CascadingDropDownCategory=this._category;this._changeHandler=Function.createDelegate(this,this._onChange);$addHandler(e,"change",this._changeHandler);if(this._parentControlID){this._parentElement=$get(this._parentControlID);Sys.Debug.assert(this._parentElement!==null,String.format(AjaxControlToolkit.Resources.CascadingDropDown_NoParentElement,this._parentControlID));if(this._parentElement){e.CascadingDropDownParentControlID=this._parentControlID;this._parentChangeHandler=Function.createDelegate(this,this._onParentChange);$addHandler(this._parentElement,"change",this._parentChangeHandler);if(!this._parentElement.childDropDown){this._parentElement.childDropDown=[];}
this._parentKeyupHandler=Function.createDelegate(this,this._onParentKeyUp);$addHandler(this._parentElement,"keyup",this._parentKeyupHandler);this._parentElement.childDropDown.push(this);}}
this._onParentChange(null,true);},removeHandler:function(element,eventName,handler){try{$removeHandler(element,eventName,handler);}catch(e){}},dispose:function(){var e=this.get_element();if(this._changeHandler){this.removeHandler(e,"change",this._changeHandler);this._changeHandler=null;}
if(this._parentChangeHandler){if(this._parentElement){this.removeHandler(this._parentElement,"change",this._parentChangeHandler);}
if(this._parentKeyupHandler){this.removeHandler(this._parentElement,"keyup",this._parentKeyupHandler);}
this._parentChangeHandler=null;this._parentKeyupHandler=null;}
Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.callBaseMethod(this,'dispose');},_clearItems:function(){var e=this.get_element();while(0<e.options.length){e.remove(0);}},_isPopulated:function(){var items=this.get_element().options.length;if(this._promptText&&this._promptSeperatorText){return items>2;}else if(this._promptText){return items>1;}else{return items>0;}},_setOptions:function(list,inInit,gettingList){var optionElement;if(!this.get_isInitialized()){return;}
var e=this.get_element();this._clearItems();var headerText;if(gettingList&&this._loadingText){headerText=this._loadingText;}else if(this._promptText){headerText=this._promptText;}
if(headerText){optionElement=new Option(headerText,"");e.options[e.options.length]=optionElement;if(this._promptSeperatorText){var optionElement2=new Option(this._promptSeperatorText,"");e.options[e.options.length]=optionElement2;}}
var selectedValueOption=null;var firstValueOption=null;var defaultIndex=-1;var selectedValueHasBeenSet=false;if(list){this._redirects=[];for(var i=0;i<list.length;i++){var listItemName=list[i].n;var listItemValue=list[i].v;this._redirects[i]=list[i].r;if(list[i].d){defaultIndex=i;if(this._promptText){defaultIndex++;}
if(this._promptText&&this._promptSeperatorText){defaultIndex++;}}
optionElement=new Option(listItemName,listItemValue);if(listItemValue==this._selectedValue&&this._selectedValue!==''){selectedValueOption=optionElement;}
if(!firstValueOption){firstValueOption=optionElement;}
e.options[e.options.length]=optionElement;}
if(selectedValueOption){selectedValueOption.selected=true;}else if(list.length==1&&this._selectIfOnlyOneItem&&firstValueOption){firstValueOption.selected=true;this.set_SelectedValue(firstValueOption.value,firstValueOption.text);selectedValueHasBeenSet=true;}}
if(selectedValueOption){this.set_SelectedValue(e.options[e.selectedIndex].value,e.options[e.selectedIndex].text);}else if(!selectedValueOption&&defaultIndex!=-1){e.options[defaultIndex].selected=true;this.set_SelectedValue(e.options[defaultIndex].value,e.options[defaultIndex].text);}else if(!inInit&&!selectedValueOption&&!gettingList&&!selectedValueHasBeenSet){this.set_SelectedValue('','');}
if(e.childDropDown&&!gettingList){for(var childIndex=0;childIndex<e.childDropDown.length;childIndex++){e.childDropDown[childIndex]._onParentChange();}}
else{if(list&&(Sys.Browser.agent!==Sys.Browser.Safari)&&(Sys.Browser.agent!==Sys.Browser.Opera)){if(e.lastSelectedValue&&this.get_SelectedValue()!=e.lastSelectedValue){if(e.onchange){try{e.onchange();}catch(err){}}}else if(document.createEvent){var onchangeEvent=document.createEvent('HTMLEvents');onchangeEvent.initEvent('change',true,false);this.get_element().dispatchEvent(onchangeEvent);}else if(document.createEventObject){this.get_element().fireEvent('onchange');}}}
if(headerText){e.disabled=!list||(0===list.length);}
e.lastSelectedValue=this.get_SelectedValue();this.raisePopulated(Sys.EventArgs.Empty);},_onChange:function(){if(!this._isPopulated()){return;}
var e=this.get_element();var selectedIndex=e.selectedIndex;if(this._promptText){selectedIndex--;}
if(this._promptText&&this._promptSeperatorText){selectedIndex--;}
if(-1!=selectedIndex){if(this._redirects!==null&&selectedIndex<this._redirects.length&&this._redirects[selectedIndex]&&this._redirects[selectedIndex]!==''){document.location.href=this._redirects[selectedIndex];}
this.set_SelectedValue(e.options[e.selectedIndex].value,e.options[e.selectedIndex].text);}else{this.set_SelectedValue('','');}},_onParentKeyUp:function(ev){this._onParentChange(null,false);},_onParentChange:function(evt,inInit){var e=this.get_element();var knownCategoryValues=this._createKnownCategoryValues(this._parentControlID);if(knownCategoryValues===''){knownCategoryValues=this._createKnownCategoryValues(this._secondaryParentControlID);}
if(knownCategoryValues!==''&&this._lastParentValues==knownCategoryValues){return;}
this._lastParentValues=knownCategoryValues;if(knownCategoryValues===''&&(this._parentControlID||this._secondaryParentControlID)){this._setOptions(null,inInit);return;}
this._setOptions(null,inInit,true);if(this._servicePath&&this._serviceMethod){var eventArgs=new Sys.CancelEventArgs();this.raisePopulating(eventArgs);if(eventArgs.get_cancel()){return;}
var params={knownCategoryValues:knownCategoryValues,category:this._category,additionalData:(this._additionalData===null?'':this._additionalData)};if(this._useContextKey){params.contextKey=this._contextKey;}else{params.contextKey='';}
Sys.Net.WebServiceProxy.invoke(this._servicePath,this._serviceMethod,false,params,Function.createDelegate(this,this._onMethodComplete),Function.createDelegate(this,this._onMethodError));$common.updateFormToRefreshATDeviceBuffer();}},_onMethodComplete:function(result,userContext,methodName){this._setOptions(result);},_onMethodError:function(webServiceError,userContext,methodName){if(webServiceError.get_timedOut()){this._setOptions([this._makeNameValueObject(AjaxControlToolkit.Resources.CascadingDropDown_MethodTimeout)]);}else{this._setOptions([this._makeNameValueObject(String.format(AjaxControlToolkit.Resources.CascadingDropDown_MethodError,webServiceError.get_statusCode()+" "+webServiceError.get_message()))]);}},_createKnownCategoryValues:function(parentControlID){var knownCategoryValues='';while(parentControlID){var parentElement=$get(parentControlID);if(parentElement&&(-1!=parentElement.selectedIndex)){var selectedValue=parentElement.options[parentElement.selectedIndex].value;if(selectedValue&&selectedValue!==''){knownCategoryValues=parentElement.CascadingDropDownCategory+':'+selectedValue+';'+knownCategoryValues;parentControlID=parentElement.CascadingDropDownParentControlID;continue;}}
break;}
return knownCategoryValues;},_makeNameValueObject:function(message){return{'name':message,'value':message};},get_ParentControlID:function(){return this._parentControlID;},set_ParentControlID:function(value){if(this._parentControlID!=value){this._parentControlID=value;this.raisePropertyChanged('ParentControlID');}},get_SecondaryParentControlID:function(){return this._secondaryParentControlID;},set_SecondaryParentControlID:function(value){if(this._secondaryParentControlID!=value){this._secondaryParentControlID=value;this.raisePropertyChanged('SecondaryParentControlID');}},get_Category:function(){return this._category;},set_Category:function(value){if(this._category!=value){this._category=value;this.raisePropertyChanged('Category');}},get_PromptText:function(){return this._promptText;},set_PromptText:function(value){var newValue=(value===''?null:value);if(this._promptText!=newValue){this._promptText=newValue;this.raisePropertyChanged('PromptText');}},get_SelectIfOnlyOneItem:function(){return this._selectIfOnlyOneItem;},set_SelectIfOnlyOneItem:function(value){if(this._selectIfOnlyOneItem!=value){this._selectIfOnlyOneItem=value;this.raisePropertyChanged('SelectIfOnlyOneItem');}},get_PromptSeperatorText:function(){return this._promptSeperatorText;},set_PromptSeperatorText:function(value){if(this._promptSeperatorText!=value){this._promptSeperatorText=value;this.raisePropertyChanged('PromptSeperatorText');}},get_LoadingText:function(){return this._loadingText;},set_LoadingText:function(value){if(this._loadingText!=value){this._loadingText=value;this.raisePropertyChanged('LoadingText');}},get_SelectedValue:function(){return this._selectedValue;},set_SelectedValue:function(value,text){if(this._selectedValue!=value){if(!text){var i=value.indexOf(':::');if(-1!=i){text=value.slice(i+3);value=value.slice(0,i);}
if(value=='clearSelection'){value='';text='';}}
var oldValue=this._selectedValue;this._selectedValue=value;this.raisePropertyChanged('SelectedValue');this.raiseSelectionChanged(new Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownSelectionChangedEventArgs(oldValue,value));}
Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.callBaseMethod(this,'set_ClientState',[this._selectedValue+':::'+text]);},get_ServicePath:function(){return this._servicePath;},set_ServicePath:function(value){if(this._servicePath!=value){this._servicePath=value;this.raisePropertyChanged('ServicePath');}},get_ServiceMethod:function(){return this._serviceMethod;},set_ServiceMethod:function(value){if(this._serviceMethod!=value){this._serviceMethod=value;this.raisePropertyChanged('ServiceMethod');}},get_contextKey:function(){return this._contextKey;},set_contextKey:function(value){if(this._contextKey!=value){this._contextKey=value;this.set_useContextKey(true);this.raisePropertyChanged('contextKey');}},get_additionalData:function(){return this._additionalData;},set_additionalData:function(value){if(this._additionalData!=value){this._additionalData=value;this.raisePropertyChanged('additionalData');}},get_useContextKey:function(){return this._useContextKey;},set_useContextKey:function(value){if(this._useContextKey!=value){this._useContextKey=value;this.raisePropertyChanged('useContextKey');}},add_selectionChanged:function(handler){this.get_events().addHandler('selectionChanged',handler);},remove_selectionChanged:function(handler){this.get_events().removeHandler('selectionChanged',handler);},raiseSelectionChanged:function(eventArgs){var handler=this.get_events().getHandler('selectionChanged');if(handler){handler(this,eventArgs);}},add_populating:function(handler){this.get_events().addHandler('populating',handler);},remove_populating:function(handler){this.get_events().removeHandler('populating',handler);},raisePopulating:function(eventArgs){var handler=this.get_events().getHandler('populating');if(handler){handler(this,eventArgs);}},add_populated:function(handler){this.get_events().addHandler('populated',handler);},remove_populated:function(handler){this.get_events().removeHandler('populated',handler);},raisePopulated:function(eventArgs){var handler=this.get_events().getHandler('populated');if(handler){handler(this,eventArgs);}}};Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior.registerClass('Interhome.Web.BL.WebFramework.Ajax.CascadingDropDownBehavior',AjaxControlToolkit.BehaviorBase);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();