﻿Type.registerNamespace("Ftn.Client");
/// common
Ftn.Client.Toolkit = {
getClientBounds : function() {
        //Gets the width and height of the browser client window (excluding scrollbars)
        var clientWidth;
        var clientHeight;
        switch(Sys.Browser.agent) {
            case Sys.Browser.InternetExplorer:
                clientWidth = document.documentElement.clientWidth;
                clientHeight = document.documentElement.clientHeight;                
                if (!document.documentElement.clientHeight)
                        clientHeight=document.getElementsByTagName('body')[0].clientHeight;
                if (!document.documentElement.clientWidth)                                          
                        clientWidth=document.getElementsByTagName('body')[0].clientWidth;                
                break;
            case Sys.Browser.Safari:
                clientWidth = window.innerWidth;
                clientHeight = window.innerHeight;
                break;
            case Sys.Browser.Opera:
                clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
                break;
            default:  // Sys.Browser.Firefox, etc.
                clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
                break;
        }
        return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
    },
	disableSelect : function()
    {
        //IE6 Bug with SELECT element always showing up on top
        var selects=new Array();
        if ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && (Sys.Browser.version < 7))
        {
            var i = 0;var tagelements;
            tagelements = document.getElementsByTagName('SELECT');
            for (var k = 0 ; k < tagelements.length; k++){
               var visibility; 
               if(tagelements[k].style.visibility.length>0) visibility = tagelements[k].style.visibility;
               else visibility = 'visible';
               selects[i] = {tag: tagelements[k], visib: visibility} ;
               tagelements[k].style.visibility = 'hidden';
               i++; }
        }       
        return selects;
    },
	enableSelect: function(selects)
    {
        //IE6 Bug with SELECT element always showing up on top
        if(selects)
        {
        if ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && (Sys.Browser.version < 7)) {
          for (var k = 0 ; k < selects.length; k++)
               selects[k].tag.style.visibility = selects[k].visib;
        }
        }
    }, 
    putElementBeforClosingFormTag : function(element, containerId)
    {
        var container= document.getElementById(containerId);
        var form = document.getElementById('aspnetForm');
        if(container!=null)
            form.removeChild(container);
        var el=document.createElement('div'); el.id=containerId; el.style.height='0px';
        form.insertBefore(el, document.getElementById('divMainContext'));
        if(element!=null)
            document.getElementById(containerId).appendChild(element);
    },
    insertAfter:function(parent, node, referenceNode)
    {
        parent.insertBefore(node, referenceNode.nextSibling);
    },
    isIE6:function()
    {
        return (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7);
    }
}
var $getClientBounds = Ftn.Client.Toolkit.getClientBounds;
var $disableSelect = Ftn.Client.Toolkit.disableSelect;
var $enableSelect  = Ftn.Client.Toolkit.enableSelect;
var $moveElementToFormEnd = Ftn.Client.Toolkit.putElementBeforClosingFormTag;
var $insertAfter = Ftn.Client.Toolkit.insertAfter;
var $isIE6 = Ftn.Client.Toolkit.isIE6;

//var $delegate = Function.createDelegate;
///////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.TextBoxWatermark = function(element) {
    Ftn.Client.TextBoxWatermark.initializeBase(this, [element]);
    this._watermarkText = "";
    this._watermarkCssClass = "";
    this._textBoxFocusDelegate = null;
    this._textBoxBlurDelegate = null;
    this._isWatermarket = true;
    this._oldCssClass = null;
    this._watermarkChangedHandler = null;
    this._wrapper = null;
    if ((typeof(WebForm_OnSubmit) == 'function') && !Ftn.Client.TextBoxWatermark._originalWebForm_OnSubmit) {
       Ftn.Client.TextBoxWatermark._originalWebForm_OnSubmit = WebForm_OnSubmit;
       WebForm_OnSubmit = Ftn.Client.TextBoxWatermark.WebForm_OnSubmit;
    }
}

Ftn.Client.TextBoxWatermark.prototype = {
    initialize: function() {
        Ftn.Client.TextBoxWatermark.callBaseMethod(this, 'initialize');
       
        this._textBoxFocusDelegate = Function.createDelegate(this,this._textBoxFocus);
        this._textBoxBlurDelegate = Function.createDelegate(this, this._textBoxBlur);
        this._textBoxKeyPressDelegate = Function.createDelegate(this,this._textBoxKeyPress);
        $addHandler(this.get_element(), "focus", this._textBoxFocusDelegate);
        $addHandler(this.get_element(), "blur", this._textBoxBlurDelegate);
        $addHandler(this.get_element(), "keypress", this._textBoxKeyPressDelegate);
        this._oldCssClass = this.get_element().className;
        this._wrapper = Ftn.Client.TextBoxWrapper.get_Wrapper(this.get_element());
        var currentValue =  this._wrapper.get_Current();
        if (("" == currentValue) || (this._watermarkText == currentValue)) {
            this._wrapper.set_Watermark(this._watermarkText)
            this._wrapper.set_IsWatermarked(true);
        }
        this._watermarkChangedHandler = Function.createDelegate(this, this._onWatermarkChanged);
        this._wrapper.add_WatermarkChanged(this._watermarkChangedHandler);
        this._regPartUpdateEvent();
    },
    dispose: function() {        
        $removeHandler(this.get_element(), "focus", this._textBoxFocusDelegate);
        $removeHandler(this.get_element(), "blur", this._textBoxBlurDelegate);
        $removeHandler(this.get_element(), "keypress", this._textBoxKeyPressDelegate);
        if (this._watermarkChangedHandler) {
            this._wrapper.remove_WatermarkChanged(this._watermarkChangedHandler);
            this._watermarkChangedHandler = null;
        }
        // Clear watermark text to avoid confusion during Refresh/Back/Forward
        if(this._wrapper.get_IsWatermarked()) {
            this._clearText(false);
        }            
         if (Sys && Sys.WebForms && Sys.WebForms.PageRequestManager){
                this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
                if (this._pageRequestManager) {
                    this._pageRequestManager.remove_endRequest(Function.createDelegate(this, this._partialUpdateEndRequest));
                }
            }
        Ftn.Client.TextBoxWatermark.callBaseMethod(this, 'dispose');
    },
    
    // events handlers
    _onWatermarkChanged : function(sender, eventArgs) {
        if (this._wrapper.get_IsWatermarked()) {
            this._textBoxBlur();
        } else {
            this._textBoxFocus();
        }
    },
    _textBoxFocus : function(e)
    {
        var el = this.get_element();
        if(this._wrapper.get_IsWatermarked()) {
            // Clear watermark
            this._clearText(e ? true : false);
        }
        if(this._oldCssClass)
            el.className = this._oldCssClass;
    },
    
    _textBoxKeyPress : function(e)
    {
       this._wrapper.set_IsWatermarked(false);
    },
    
    _textBoxBlur: function(e)
    {
        //var wrapper = Ftn.Client.TextBoxWrapper.get_Wrapper(this.get_element());
        if(("" == this._wrapper.get_Current()) || this._wrapper.get_IsWatermarked()) {
           this._applayWatermark();}
    },
    _onSubmit:function()
    {
        if(this._wrapper.get_IsWatermarked())
           this._clearText(false);
    },
    _partialUpdateEndRequest : function(sender, endRequestEventArgs) {
        if (this.get_element()) {
            // Restore the cleared watermark (useful when the submit was wrapped in an UpdatePanel)
            this.get_element().blur();
            this._textBoxBlur();
        }
    },
    _regPartUpdateEvent:function(){
         if (Sys && Sys.WebForms && Sys.WebForms.PageRequestManager){
                this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
                if (this._pageRequestManager) {
                    this._pageRequestManager.add_endRequest(Function.createDelegate(this, this._partialUpdateEndRequest));
                }
            }
     },
    _applayWatermark : function()
    {
        var wrapper = this._wrapper;
        wrapper.set_Watermark(this._watermarkText);
        wrapper.set_IsWatermarked(true);
        if(this._watermarkCssClass) {
            this.get_element().className = this._watermarkCssClass;
        }
    },
    _clearText : function (focusing)
    {
        //var element = this.get_element();
        var wrapper = this._wrapper;
        wrapper.set_Value("");
        wrapper.set_IsWatermarked(false);
        if(focusing) {
           this.get_element().setAttribute("autocomplete","off");  // Avoid NS_ERROR_XPC_JS_THREW_STRING error in Firefox
           this.get_element().select(); // This fix displays the blinking cursor in a focused, empty text box in IE
        }
        this.get_element().className = this._oldCssClass;  
    },
    // properties
    get_WatermarkText: function()
    {
        return this._watermarkText;
    }, 
    set_WatermarkText: function (value)
    {
         this._watermarkText = value;
         //this._textBoxBlur();
    },
    get_WatermarkCssClass: function()
    {
        return this._watermarkCssClass;
    }, 
    set_WatermarkCssClass: function (value)
    {
         this._watermarkCssClass = value;
    }
}
Ftn.Client.TextBoxWatermark.registerClass('Ftn.Client.TextBoxWatermark', Sys.UI.Behavior);
//////

Ftn.Client.TextBoxWatermark.WebForm_OnSubmit = function() {
    var result = Ftn.Client.TextBoxWatermark._originalWebForm_OnSubmit();
    if (result) {
        var components = Sys.Application.getComponents();
        for(var i = 0 ; i < components.length ; i++) {
            var component = components[i];
            if (Ftn.Client.TextBoxWatermark.isInstanceOfType(component)) {
                component._onSubmit();
            }
        }
    }
    return result;
}

//////

Ftn.Client.TextBoxWrapper = function(element) {
    Ftn.Client.TextBoxWrapper.initializeBase(this, [element]);
    this._current = element.value;
    this._watermark = null;
    this._isWatermarked = false;
}

Ftn.Client.TextBoxWrapper.prototype = {

    dispose : function() {
        this.get_element().FtnClientTextBoxWrapper = null;
        Ftn.Client.TextBoxWrapper.callBaseMethod(this, 'dispose');
    },

    get_Current : function() {
        this._current = this.get_element().value;
        return this._current;
    },
    set_Current : function(value) {
        this._current = value;
        this._updateElement();
    },

    get_Value : function() {
        if (this.get_IsWatermarked()) {
            return "";
        } else {
            return this.get_Current();
        }
    },
    set_Value : function(text) {
        this.set_Current(text);
        if (!text || (0 == text.length)) {
            if (null != this._watermark) {
                this.set_IsWatermarked(true);
            }
        } else {
            this.set_IsWatermarked(false);
        }
    },

    get_Watermark : function() {
        return this._watermark;
    },
    set_Watermark : function(value) {
        this._watermark = value;
        this._updateElement();
    },
    get_IsWatermarked : function() {
        return this._isWatermarked;
    },
    set_IsWatermarked : function(isWatermarked) {
        if (this._isWatermarked != isWatermarked) {
            this._isWatermarked = isWatermarked;
            this._updateElement();
            this._raiseWatermarkChanged();
        }
    },

    _updateElement : function() {
        var element = this.get_element();
        if (this._isWatermarked) {
            if (element.value != this._watermark) {
                element.value = this._watermark;
            }
        } else {
            if (element.value != this._current) {
                element.value = this._current;
            }
        }
    },

    add_WatermarkChanged : function(handler) {
        this.get_events().addHandler("WatermarkChanged", handler);
    },
    remove_WatermarkChanged : function(handler) {
        this.get_events().removeHandler("WatermarkChanged", handler);
    },
    _raiseWatermarkChanged : function() {
        var onWatermarkChangedHandler = this.get_events().getHandler("WatermarkChanged");
        if (onWatermarkChangedHandler) {
            onWatermarkChangedHandler(this, Sys.EventArgs.Empty);
        }
    }
}
Ftn.Client.TextBoxWrapper.get_Wrapper = function(element) {
    if (null == element.FtnClientTextBoxWrapper) {
        element.FtnClientTextBoxWrapper = new Ftn.Client.TextBoxWrapper(element);
    }
    return element.FtnClientTextBoxWrapper;
}
Ftn.Client.TextBoxWrapper.registerClass('Ftn.Client.TextBoxWrapper', Sys.UI.Behavior);

Ftn.Client.TextBoxWrapper.validatorGetValue = function(id) {
    var control = $get(id);
    if (control && control.FtnClientTextBoxWrapper) {
        return control.FtnClientTextBoxWrapper.get_Value();
    }
    return Ftn.Client.TextBoxWrapper._originalValidatorGetValue(id);
}

if (typeof(ValidatorGetValue) == 'function') {
   Ftn.Client.TextBoxWrapper._originalValidatorGetValue = ValidatorGetValue;
    ValidatorGetValue = Ftn.Client.TextBoxWrapper.validatorGetValue;
}

//if (Sys.CultureInfo.prototype._getAbbrMonthIndex) {
//    try {
//        Sys.CultureInfo.prototype._getAbbrMonthIndex('');
//    } catch(ex) {
//        Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) {
//            if (!this._upperAbbrMonths) {
//                this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames);
//            }
//            return Array.indexOf(this._upperAbbrMonths, this._toUpper(value));
//        }
//        Sys.CultureInfo.CurrentCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex;
//        Sys.CultureInfo.InvariantCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex;
//    }
//}

///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.ModalPopup = function(element) {
     Ftn.Client.ModalPopup.initializeBase(this, [element]);
     
     this._onShowDelegate = null;
     this._onHideDelegate = null;
     this._onScrollDelegate = null;
     this._onResizeDelegate = null;
     this._windowHandlersAttach = false;
          
     this._popupControlID = null;
     this._popupControl = null;
     
     this._backgroundCssClass = null;
     this._backgroundControl = null;
     
     this._okControlID = null;
     this._okControl = null;
     
     this._iframe = null;     
     
     this._withScriptControlID=null;
     this._withScriptControl=null;
     
     this._scriptOnClose=null;  
     this._onCloseScriptDelegate = null; 
}
Ftn.Client.ModalPopup.prototype ={
     initialize: function() {
     
        Ftn.Client.ModalPopup.callBaseMethod(this, 'initialize');
        this._onShowDelegate =Function.createDelegate(this, this._onShow);
        this._onHideDelegate  = Function.createDelegate(this, this._onHide);
        this._onScrollDelegate = Function.createDelegate(this,this._setPosition);
        this._onResizeDelegate = Function.createDelegate(this,this._setPosition);
                
        this._onCloseScriptDelegate = Function.createDelegate(this,this._onCloseScriptRun);
        
        this._popupControl = $get(this._popupControlID);
        this._popupControl.style.display ="none";
	    this._popupControl.style.zIndex= 10001;	
	    
	    $addHandler(this.get_element(), "click", this._onShowDelegate);
        
        if(this._okControlID){
            this._okControl = $get(this._okControlID);
            $addHandler(this._okControl,"click", this._onHideDelegate);
        }
            
        if(this._withScriptControlID){
            this._withScriptControl = $get(this._withScriptControlID);
            $addHandler(this._withScriptControl,"click", this._onCloseScriptDelegate);
        }
        
        $moveElementToFormEnd(this._popupControl, "div_form_bottom_"+this.get_id());
        this._createBackground();
        this._regPartUpdateEvent();
     },
     _onCloseScriptRun:function(e)
     { 
      if (this._scriptOnClose)    
      {
        var text = this._scriptOnClose.toString();
        eval(text);     
      }
      this.hide();
      e.preventDefault();
      return false;
     },     
    dispose: function() {   
         
        $removeHandler(this.get_element(), "click", this._onShowDelegate);
        if(this._okControlID)
            $removeHandler(this._okControl,"click", this._onHideDelegate);
        if (this._withScriptControlID && this._onScriptDoDelegate)    
            $removeHandler(this._withScriptControl,"click",this._onScriptDoDelegate);
            
        if (Sys && Sys.WebForms && Sys.WebForms.PageRequestManager){
            this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
            if (this._pageRequestManager) {
               this._pageRequestManager.remove_endRequest(Function.createDelegate(this, this._partialUpdateEndRequest));
            }
        }    
        Ftn.Client.ModalPopup.callBaseMethod(this, 'dispose');
    },    
    _onShow : function(e)
    {
        this.show();
        e.preventDefault();
        return false;
    },
    show: function(e)
    {
        $addHandler(window, "scroll",this._onScrollDelegate);
        $addHandler(window, "resize",this._onResizeDelegate);
        this._windowHandlersAttach  = true;
        this._setPosition();
        this._setDisplayProperty("block");
        this._setPosition();
        this._showed(new Sys.EventArgs());
    },
    _onHide:function(e)
    {
        this.hide();
        e.preventDefault();
        return false;
    },
    hide: function()
    {   
        if(this._windowHandlersAttach){
        $removeHandler(window, "scroll",this._onScrollDelegate);
        $removeHandler(window, "resize",this._onResizeDelegate);
        this._windowHandlersAttach = false;}
        this._setDisplayProperty("none");
    },
    _partialUpdateEndRequest : function(sender, endRequestEventArgs) {
        if (this.get_element()) {
        var action = endRequestEventArgs.get_dataItems()[this.get_element().id];
        if ("show" == action) {
           this.show();
        } else if ("hide" == action) {
          this.hide();
        }
        }
    },
    _regPartUpdateEvent:function(){
         if (Sys && Sys.WebForms && Sys.WebForms.PageRequestManager){
                this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
                if (this._pageRequestManager) {
                    this._pageRequestManager.add_endRequest(Function.createDelegate(this, this._partialUpdateEndRequest));
                }
            }
     },
    _setPosition: function()
    {
        var clientBounds = $getClientBounds();
        var bounds = Sys.UI.DomElement.getBounds(this._popupControl);
        var clientWidth  = clientBounds.width;
        var clientHeight = clientBounds.height;
        var height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight)+'px';
        this._backgroundControl.style.height = height;
        if(this._iframe) this._iframe.height = height;
        var isIE6 = $isIE6();
        if(isIE6){
            var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
            var w = Math.max(Math.max(document.documentElement.scrollWidth,  document.body.scrollWidth)/2,  clientWidth) +'px';    
            this._backgroundControl.style.width  = w;
            if(this._iframe) this._iframe.width  = w;
            this._popupControl.style.position = 'absolute';
            this._popupControl.style.left =scrollLeft+(clientWidth/2)-bounds.width/2 +'px'
            this._popupControl.style.top =scrollTop+(clientHeight/2)- bounds.height/2 +'px';
        }  else { this._popupControl.style.position = 'fixed';   
               this._popupControl.style.left = (clientWidth/2)-bounds.width/2 +'px';
               this._popupControl.style.top = (clientHeight/2)- bounds.height/2 +'px';
               this._backgroundControl.style.width  = Math.max(Math.max(document.documentElement.scrollWidth,  document.body.scrollWidth),  clientWidth) +'px';
               }
    },
    _createBackground:function()
    {
        this._backgroundControl = document.createElement('DIV');
        this._backgroundControl.style.position ='absolute';
        this._backgroundControl.style.top ='0px';
        this._backgroundControl.style.left ='0px';
        this._backgroundControl.style.display = 'none';
        this._backgroundControl.style.zIndex = 10000;
        if(this._backgroundCssClass && this._backgroundCssClass.length>0)  this._backgroundControl.className = this._backgroundCssClass;
        $get("div_form_bottom_"+this.get_id()).appendChild(this._backgroundControl);
        if($isIE6())
        {
           this._iframe = document.createElement('IFRAME');
           this._iframe.style.position ='absolute';
           this._iframe.style.top ='0px';
           this._iframe.style.left ='0px';
           this._iframe.style.display = 'none';
           this._iframe.style.zIndex = 9000;
           this._iframe.frameBorder = 0;
           this._iframe.style.filter = "alpha(opacity=0)";
           $insertAfter(this._backgroundControl.parentNode, this._iframe, this._backgroundControl);
        }
    },
    _setDisplayProperty: function(display)
    {
        this._popupControl.style.display=display;
        this._backgroundControl.style.display=display;
        if(this._iframe) this._iframe.style.display=display;
    },
    get_PopupControlID : function()
    {
        return this._popupControlID;
    },
    set_PopupControlID : function(value)
    {
        this._popupControlID = value;
    },
    get_BackgroundCssClass : function()
    {
        return this._backgroundCssClass;
    },
    set_BackgroundCssClass : function(value)
    {
        this._backgroundCssClass = value;
    },
    get_OkControlID : function()
    {
        return  this._okControlID;
    },
    set_OkControlID :function(value)
    {
        this._okControlID = value;
    },
    
    get_WithScriptControlID : function()
    {
        return  this._withScriptControlID;
    },
    set_WithScriptControlID :function(value)
    {
        this._withScriptControlID = value;
    },
    get_ScriptOnClose:function()
    {
       return this._scriptOnClose;
    },
    set_ScriptOnClose:function(value)
    {                 
       this._scriptOnClose = Sys.Serialization.JavaScriptSerializer.deserialize(value);
     },
        
    add_showed: function(handler) {
		 this.get_events().addHandler("showed", handler);
	},
	
	remove_showed: function (handler) {
		 this.get_events().removeHandler("showed", handler);
	},
	_showed: function(eventArgs) {
		 var handler = this.get_events().getHandler("showed");
		 if (handler) handler(this,eventArgs);
	}

}
Ftn.Client.ModalPopup.registerClass('Ftn.Client.ModalPopup', Sys.UI.Behavior);
///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.HoverMenu = function(element) {
    Ftn.Client.HoverMenu.initializeBase(this, [element]);
    this._popupControlID = null;
    this._popupControl = null;
    this._onHideDelegate = null;
    this._onShowDelegate = null;
    this._stopPropDlg = null;
    this._targetBounds = null;
    this._popupPosition = "Bottom";
    this._x=0;
    this._y=0;
    this._moveToBottom = false;
    this._mode ="Popup";
    this._ifr = null;
    this._tacss = null;
    this._tnacss = null;
    }
Ftn.Client.HoverMenu.prototype = {
    initialize: function() {
        Ftn.Client.HoverMenu.callBaseMethod(this, 'initialize');
        this._targetBounds = Sys.UI.DomElement.getBounds(this.get_element());
        this._initPopup();
        if(this._moveToBottom) $moveElementToFormEnd(this._popupControl, "div_hover_bottom_"+this.get_id());
        this._initIframe();
        this._onHideDelegate = Function.createDelegate(this,this._onHide);
        this._onShowDelegate = Function.createDelegate(this,this._onShow);
        this._tnacss = this.get_element().className;
        switch(this._mode){
            case "Hover" : 
                    $addHandler(this.get_element(), "mouseover",this._onShowDelegate);
                    $addHandler(this.get_element(), "mouseout", this._onHideDelegate );
                    $addHandler(this._popupControl, "mouseover",this._onShowDelegate);
                    $addHandler(this._popupControl, "mouseout", this._onHideDelegate );
                    break;
            case "Popup": 
                    this._stopPropDlg = Function.createDelegate(this,this._stopProp);
                    $addHandler(this.get_element(), "click",this._onShowDelegate);
                    $addHandler(this._popupControl, "click",this._stopPropDlg);
                    $addHandler(document.body, "click", this._onHideDelegate);
                    break;    
        }
    },
    dispose: function() {        
         switch(this._mode){
            case "Hover" : 
                    $removeHandler(this.get_element(), "mouseover",this._onShowDelegate);
                    $removeHandler(this.get_element(), "mouseout", this._onHideDelegate );
                    $removeHandler(this._popupControl, "mouseover",this._onShowDelegate);
                    $removeHandler(this._popupControl, "mouseout", this._onHideDelegate );
                    break;
            case "Popup": 
                    $removeHandler(this.get_element(), "click",this._onShowDelegate);
                    $removeHandler(this._popupControl, "click",this._stopPropDlg);
                    $removeHandler(document.body, "click", this._onHideDelegate);
                    break;    
        }
        Ftn.Client.HoverMenu.callBaseMethod(this, 'dispose');
    },
    _onShow:function(e)
    {
        this.show();
        this._stopProp(e);
        e.preventDefault();
    },
    _onHide:function(e)
    {
       this.hide();
       this._stopProp(e);
    },
    show: function(e)
    {
        this._showpPopup(this.get_element());
    },
    hide:function(e)
    {
       this._hidden();
       this._popupControl.style.display="none";
       if (this._tacss) this.get_element().className= this._tnacss;
       this._hideIframe();
    },
    showFixPosition:function(targetElement)
    {
        this._showpPopup(targetElement);
    },
    _showpPopup : function(targetElement)
    {
        var eventArgs = {cancel:false};
        this._showed(eventArgs);
        if(eventArgs.cancel) return;
        this._popupControl.style.display="";
        if (this._tacss) this.get_element().className= this._tacss;
        var bounds= this._getBounds(targetElement);
        Sys.UI.DomElement.setLocation(this._popupControl,bounds.x,bounds.y);
        this._showIframe(bounds.x,bounds.y);
    },
    _getBounds : function(targetElement) {
          var parent = this._popupControl.offsetParent;
          if(this._popupControl.offsetParent==null||this._popupControl.offsetParent.tagName==="HTML")
             parent = document.body;
          var popupOffsetLoc = Sys.UI.DomElement.getLocation(parent);  
          var bounds= Sys.UI.DomElement.getBounds(targetElement);
          var popupBounds =  Sys.UI.DomElement.getBounds(this._popupControl)
          var x,y; 
          switch (this._popupPosition){
            case "Bottom":x =  bounds.x -popupOffsetLoc.x;  
                          y = bounds.y -popupOffsetLoc.y + bounds.height;
                          break;
            case "Left" : x =  bounds.x -popupOffsetLoc.x -popupBounds.width;  
                          y = bounds.y -popupOffsetLoc.y;
                          break;
            case "Right": x =  bounds.x -popupOffsetLoc.x + bounds.width;  
                          y = bounds.y -popupOffsetLoc.y;
                          break;
            case "BottomRight" : x =   bounds.x -popupOffsetLoc.x + bounds.width - popupBounds.width;   
                                 y = bounds.y -popupOffsetLoc.y + bounds.height;                          
          }
          x= x+this._x; y= y+this._y;
          return  {'x':x, 'y':y};
	},
	_initPopup:function()
	{
	    if(this._popupControl==null)
	        this._popupControl = $get(this._popupControlID);
        this._popupControl.style.display="none";
        this._popupControl.style.position="absolute";
        this._popupControl.style.zIndex=1000;
        this._popupControl.style.top="0px";
        this._popupControl.style.left="0px";
        this._popupControl.style.visibility="visible";
	},
	_initIframe: function()
	{
	    if($isIE6()){
	    var ifr = document.createElement("IFRAME");
	    ifr.style.display="none";
        ifr.style.position="absolute";
        ifr.style.zIndex=900;
        ifr.style.top="0px";
        ifr.style.left="0px";
        ifr.frameBorder = 0;
        this._popupControl.style.display="block";
        ifr.width = this._popupControl.offsetWidth;
        ifr.height = this._popupControl.offsetHeight;
        this._popupControl.style.display="none";
        $insertAfter(this._popupControl.parentNode, ifr,this._popupControl);
	    this._ifr =ifr;
	    }
	},
	_showIframe:function(x,y)
	{
	    if(this._ifr)
	    {
	       this._ifr.style.display="block";
	       Sys.UI.DomElement.setLocation(this._ifr,x,y); 
	    }
	},
	_hideIframe:function()
	{
	    if(this._ifr)
	        this._ifr.style.display="none";
	},
	_stopProp: function(e)
	{
	    e.stopPropagation();
	},
    get_PopupControlID: function()
    {
        return this._popupControlID;
    },
    set_PopupControlID: function(value)
    {
        this._popupControlID = value;
    },
    get_PopupPosition :function()
    {
        return this._popupPosition;
    },
    set_PopupPosition:function(value)
    {
        this._popupPosition = value; 
    },
    get_X:function()
    {
        return this._x;
    },
    set_X:function(value)
    {
        this._x= value;
    },
    get_Y:function()
    {
        return this._y;
    },
    set_Y:function(value)
    {
        this._y = value;
    },
    get_MoveToBottom:function()
    {
       return this._moveToBottom;
    },
    set_MoveToBottom:function(value)
    {
        this._moveToBottom = value;
    },
    get_Mode:function()
    {
        return this._mode;
    },
    set_Mode:function(value)
    {
        this._mode = value;
    },
    get_TargetActiveCss:function()
    {
        return this._tacss;
    },
    set_TargetActiveCss:function(value)
    {
        this._tacss = value;
    },
    add_showed: function(handler) {
		 this.get_events().addHandler("showed", handler);
	},
	remove_showed: function (handler) {
		 this.get_events().removeHandler("showed", handler);
	},
	_showed: function(eventArgs) {
		 var handler = this.get_events().getHandler("showed");
		 if (handler) handler(this,eventArgs);
	},
	add_hidden: function(handler) {
		 this.get_events().addHandler("hidden", handler);
	},
	remove_hidden: function (handler) {
		 this.get_events().removeHandler("hidden", handler);
	},
	_hidden: function() {
		 var handler = this.get_events().getHandler("hidden");
		 if (handler) handler(this);
	}
}
Ftn.Client.HoverMenu.registerClass('Ftn.Client.HoverMenu', Sys.UI.Behavior);
///////////////////////////////////////////////////////////////////////////////////
Ftn.Client.CascadingDropDown = function(element) {
    Ftn.Client.CascadingDropDown.initializeBase(this, [element]);
    this._ParentControlID=null;
    this._ParentControl=null;
    this._StateFieldID = null;
    this._StateField = null;
    this._PromtText= null;
    this._EmptyText = null;
    this._LoadingText= null;
    this._ServiceMethod = null;
    this._ServicePath = null;
    this._SelectedValue = "";
    this._Category =null;
    this._onParentChangeDelegate = null;
    this._onChangeDelegate = null;
    this._first = true;
    }
Ftn.Client.CascadingDropDown.prototype = {
    initialize: function() {
        Ftn.Client.CascadingDropDown.callBaseMethod(this, 'initialize');
        this._ParentControl = $get(this._ParentControlID);
        this._StateField = $get(this._StateFieldID);
        this._SelectedValue =this._StateField.value;
        this._onParentChangeDelegate = Function.createDelegate(this,this._onParentChange);
        this._onChangeDelegate = Function.createDelegate(this,this._onChange);
        $addHandler(this.get_element(), "change", this._onChangeDelegate);
        $addHandler(this._ParentControl,"change",this._onParentChangeDelegate);
        if(this._EmptyText===null) this._EmptyText = this._PromtText;
        this._onParentChange();
    },
    dispose: function() {        
        $removeHandler(this.get_element(), "change", this._onChangeDelegate);
        $removeHandler(this._ParentControl,"change",this._onParentChangeDelegate);
        Ftn.Client.CascadingDropDown.callBaseMethod(this, 'dispose');
    },
    _onChange:function(e)
    {
        var selectedItem = this.get_element().options[this.get_element().selectedIndex];
        this._SelectedValue = selectedItem.value;
        if(selectedItem.value.length>0)
            this._StateField.value = this._SelectedValue+":::"+selectedItem.innerHTML; 
        else this._StateField.value =":::";
        this._childChange(e);
    },
    _onParentChange: function()
    {
      this.get_element().disabled=true;  
      if(this._LoadingText){this._setOptions(new Array(),this._LoadingText);}
      if(this._ParentControl.selectedIndex>=0) {
      var selectedValue = this._ParentControl.options[this._ParentControl.selectedIndex].value;
      if(selectedValue.length===0)
      {
         if(this._PromtText)   
            this._setOptions(new Array(),this._PromtText);
         return;
      } 
      if(!this._first){this._SelectedValue="";this._StateField.value = ":::";} else {this._first = false;} 
      Sys.Net.WebServiceProxy.invoke(this._ServicePath,this._ServiceMethod,true,{ knownCategoryValues:this._getSelectedValues(), category:this._Category},
                                     Function.createDelegate(this,this._onComplete));
      }
    },
    _setOptions:function(options, firstItemText)
    {
        var e = this.get_element();
        this._clearOptions();
        if (firstItemText!==null && firstItemText.length>0)  
            this._createOption(null,firstItemText, e)
        for(var i=0; i<options.length; i++)
            this._createOption(options[i].value, options[i].name,e);
    },
    _clearOptions:function()
    {
      var e = this.get_element();
      while(e.options.length>0) {e.remove(0);}
    },
    _onComplete:function(results)
    {
        this._dataLoaded(results);
        if(results===null) return;
        if (results.length==0)
        {  if(this._EmptyText)
              this._setOptions(new Array(), this._EmptyText);
           else  this._setOptions(new Array(), null);  
           return;
        } else {
            if(this._PromtText)
              this._setOptions(results,this._PromtText);
            else this._setOptions(results,null);
            this.get_element().disabled=false;
        }
        if(this._SelectedValue.length>0)
            this._setSelectedValue();
        else {
        if(this._PromtText==null)
        {
           this._SelectedValue = this.get_element().options[0].value; 
           this._StateField.value = this.get_element().options[0].value+":::"+this.get_element().options[0].innerHTML;
        } 
        } 
           
    },
    _getSelectedValues:function()
    {
        var arrayToReturn="";
        for (var i=0; i<this._ParentControl.options.length; i++) {
            if(this._ParentControl.options[i].selected) {
             arrayToReturn = arrayToReturn + this._ParentControl.options[i].value + ",";
             }
        }
        var retval = arrayToReturn.substr(0,arrayToReturn.length-1);
        return retval; 
    },
   _setSelectedValue : function()
    {
       var index = this._StateField.value.indexOf(":::");
       if(index<=0)
         this._SelectedValue = this._StateField.value;
       else this._SelectedValue = this._StateField.value.substring(0,index);
      
       for(var i=0; i<this.get_element().options.length;i++) 
       {
          if(this.get_element().options[i].value===this._SelectedValue)
          {
             this.get_element().selectedIndex = i;
             this._StateField.value = this._SelectedValue+":::"+this.get_element().options[i].innerHTML; 
             break;
          }
       }
    },
    _createOption:function(value, name, select)
    {
       var option = document.createElement("OPTION");
       select.options.add(option);
       if(value) option.value = value; else option.value="";
       var text = document.createTextNode(name);
       option.appendChild(text);
       option.innerHTML=name;
       return option;
    },
    add_dataLoaded: function(handler) {
		 this.get_events().addHandler("dataLoaded", handler);
	},
	remove_dataLoaded: function (handler) {
		 this.get_events().removeHandler("dataLoaded", handler);
	},
	_dataLoaded: function(eventArgs) {
		 var handler = this.get_events().getHandler("dataLoaded");
		 if (handler) handler(this,eventArgs);
	},
	add_childChange:function()
	{
	    this.get_events().addHandler("childChange", handler);
	},
	remove_childChange:function()
	{
	     this.get_events().removeHandler("childChange", handler);
	},
	_childChange:function(eventArgs)
	{
	    var handler = this.get_events().getHandler("childChange");
		if (handler) handler(eventArgs);
	},
	set_ParentControlID:function(value)
    {
        this._ParentControlID = value;
    },
    set_PromtText:function(value)
    {
        this._PromtText = value;
    },
    set_EmptyText:function(value)
    {
        this._EmptyText= value;
    },
    set_LoadingText:function(value)
    {
        this._LoadingText = value;
    },
    set_ServiceMethod:function(value)
    {
        this._ServiceMethod = value;
    },
    set_ServicePath:function(value)
    {
        this._ServicePath = value;
    },
    set_StateFieldID:function(value)
    {
        this._StateFieldID = value;
    },
    get_ParentControlID:function()
    {
        return this._ParentControlID;
    },
    get_PromtText:function()
    {
        return this._PromtText;
    },
    get_EmptyText:function()
    {
        return this._EmptyText;
    },
    get_LoadingText:function()
    {
       return this._LoadingText;
    },
    get_ServiceMethod:function()
    {
       return this._ServiceMethod;
    },
    get_ServicePath:function()
    {
       return this._ServicePath;
    },
    get_StateFieldID:function()
    {
       return this._StateFieldID;
    },
    get_Category:function()
    {
       return this._Category;
    },
    set_Category:function(value)
    {
      this._Category = value;
    },
    get_SelectedItemText:function()
    {
       var index = this._StateField.value.indexOf(":::");
       if(index<0)
        return "";
       return this._StateField.value.substring(index+3,this._StateField.value.length);
    },
    get_SelectedItemValue:function()
    {
       var index = this._StateField.value.indexOf(":::");
       if(index<=0)
        return "";
       return this._StateField.value.substring(0,index);
    }
    
}
Ftn.Client.CascadingDropDown.registerClass('Ftn.Client.CascadingDropDown', Sys.UI.Behavior);
///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.AutoComplete = function (element){
    Ftn.Client.AutoComplete.initializeBase(this, [element]);
    this._serviceMethod = null;
    this._servicePath = null;
    this._listCss = null;
    this._itemCss= null;
    this._itemHlClass = null;
    this._inputKeydownDlg = null;
    this._listItemKeydownDlg = null;
    this._listItemMouseOverDlg = null;
    this._listItemClickDlg = null;
    this._listItemEnterDlg = null;
    this._inputBlurDlg = null;
    this._inputClickDlg = null;
    this._tickDlg = null;
    this._resultCount = 0;
    this._selectedIndex = -1;
    this._listNode=null;
    this._delimeters = new Array();
    this._delimeterIndex =0;
    this._prefix = 1;
    this._complCount =5;
    this._interval =0;
    this._timer = null;
    this._key = null;
 }
Ftn.Client.AutoComplete.prototype = {
    
    initialize: function(){
         Ftn.Client.AutoComplete.callBaseMethod(this, 'initialize');
         this._initList();
         this._listItemKeydownDlg = Function.createDelegate(this, this._listItemKeyDown);
         this._listItemMouseOverDlg = Function.createDelegate(this,this._itemMouseOver);
         this._listItemClickDlg = Function.createDelegate(this,this._itemClick);
         this._inputBlurDlg = Function.createDelegate(this,this._hide);
         this._listItemEnterDlg = Function.createDelegate(this,this._listItemEnter);
         this._inputClickDlg = Function.createDelegate(this, this._cancelEvent);
         this._tickDlg = Function.createDelegate(this, this._inputKeydown);
         $addHandler(this.get_element(),"keyup",this._listItemKeydownDlg);
         $addHandler(this.get_element(),"click",this._inputClickDlg);
         $addHandler(this.get_element(),"keydown",this._listItemEnterDlg);
         $addHandler(this.get_element(),"blur",this._inputBlurDlg);
         $addHandler(document.getElementsByTagName("BODY")[0],"click",this._inputBlurDlg);
         
    },
    dispose : function (){
        $removeHandler(this.get_element(),"keyup",this._listItemKeydownDlg);
        $removeHandler(this.get_element(),"keydown",this._listItemEnterDlg);
        $removeHandler(this.get_element(),"click",this._inputClickDlg);
        $removeHandler(this.get_element(),"blur",this._inputBlurDlg);
        $removeHandler(document.getElementsByTagName("BODY")[0],"click",this._inputBlurDlg);
        Ftn.Client.AutoComplete.callBaseMethod(this, 'dispose');
    },
    _cancelEvent:function(e)
    {
        e.stopPropagation(); e.preventDefault();
    },
    _listItemEnter:function(e)
    {
        var k = e.keyCode ? e.keyCode : e.rawEvent.keyCode;
        if(k===Sys.UI.Key.enter)
        {
            this._hide();
            this._cancelEvent(e);
        }
    },
    _listItemKeyDown :function(e)
    {       
           this._stopTimer(); 
           var k = e.keyCode ? e.keyCode : e.rawEvent.keyCode;
           switch (k) { 
                case Sys.UI.Key.up: 
                        if(this._selectedIndex > 0){
                        this._selectedIndex--;
                        this._hightligthItem(this._listNode.childNodes[this._selectedIndex]);  
                        this.get_element().value = this._getNewInputText(this._listNode.childNodes[this._selectedIndex].innerHTML);
                        this._cancelEvent(e);}
                        break;
                case Sys.UI.Key.down:
                        if(this._selectedIndex < this._resultCount-1) {
                        this._selectedIndex++;
                        this._hightligthItem(this._listNode.childNodes[this._selectedIndex]);  
                        this.get_element().value = this._getNewInputText(this._listNode.childNodes[this._selectedIndex].innerHTML);
                        this._cancelEvent(e);}
                        break;     
                case Sys.UI.Key.pageUp: break;
                case Sys.UI.Key.pageDown: break; 
                case Sys.UI.Key.end: break;
                case Sys.UI.Key.home: break;                        
                case Sys.UI.Key.right: break;                        
                case Sys.UI.Key.left: break;
                case Sys.UI.Key.space: this._delimeterIndex = this._getLastDelimeterIndex(); break;   
                case Sys.UI.Key.esc:this._hide();break;
                default: this._delimeterIndex = this._getLastDelimeterIndex();
                         var prefix = this._getPrefixText();
                         if(prefix.length==0){this._hide();return;}  
                         if(prefix.length>this._prefix-1)
                            this._startTimer(); 
                         break;
                        }
    },
    _inputKeydown:function(e)
    {
        var prefix = this._getPrefixText();
        this._stopTimer();
        var params;
        if(this._key && this._key.length>0)
             params = {contextKey:this._key, prefixText:prefix,count:this._complCount};
         else params = { prefixText: prefix, count: this._complCount };
        if (this._listNode.style.width=="")
            this._listNode.style.width = this.get_element().offsetWidth + "px";
        Sys.Net.WebServiceProxy.invoke(this._servicePath,this._serviceMethod,true,
                            params, Function.createDelegate(this, this._buildList));   
    },
    _itemMouseOver:function(e)
    {
        this._hightligthItem(e.target);
    },
    _itemClick:function(e)
    {   
        this.get_element().value = this._getNewInputText(e.target.innerHTML);
        this.get_element().focus();
        this._hide();
        this._cancelEvent(e);
    },
    _buildList:function(list)
    {
        this._resultCount = 0;
        this._selectedIndex =-1;
        this._clearList();
        this._resultCount = list.length;
        for(var i=0; i<list.length; i++)
        {
            var li = document.createElement("LI");  
            li.className=this._itemCss; 
            var text = document.createTextNode(list[i]);                            
            this._listNode.appendChild(li);
            li.appendChild(text);
            $addHandler(li,"mouseover",this._listItemMouseOverDlg);
            $addHandler(li,"mousedown",this._listItemClickDlg);
        }
        if(this._resultCount>0) this._show();
    },
    _clearList:function()
    {
        var liArr = this._listNode.getElementsByTagName("LI");
        var count  = liArr.length-1;
        for(var i=count; i>=0;i--)
        {
            $removeHandler(liArr[i],"mouseover",this._listItemMouseOverDlg);
            $removeHandler(liArr[i],"mousedown",this._listItemClickDlg);
            this._listNode.removeChild(liArr[i]);
        } 
        
    },
    _hightligthItem:function(item)
    {
        var children = this._listNode.childNodes;
        for(var i =0; i<children.length; i++)
        {
            if(children[i]._hightlight){
                children[i].className = this._itemCss;
                item._hightlight =false;            
                }
        }
        item.className = this._itemHlClass;
        item._hightlight = true;
    },
    _getPrefixText:function()
    {
        var inputText= this.get_element().value;
        return inputText.substr(this._delimeterIndex+1).trim();
    },
    _getLastDelimeterIndex:function()
    {
        var index=-1;
        var inputText = this.get_element().value.trim();
        for(var i=0; i< this._delimeters.length; i++)
        {
            var currentIndex = inputText.lastIndexOf(this._delimeters[i]);
            if(currentIndex>=index) index=currentIndex;
        }
        return index;
    },
    _getNewInputText:function(addText)
    {
        var currentText = this.get_element().value;
        return currentText.substring(0,this._delimeterIndex+1) + addText;
    },
    _initList:function()
    {
        var ul = document.createElement("UL");
        ul.className= this._listCss;
        ul.style.display = "none";
        ul.style.position = "absolute";
        ul.style.visibility= "visible";
        this._listNode = ul;
        $insertAfter(this.get_element().parentNode,ul,this.get_element());
    },
    _show:function()
    {
        this._listNode.style.display="";
        var bounds = this._getBounds();
        Sys.UI.DomElement.setLocation(this._listNode,bounds.x,bounds.y);
    },
    _hide:function()
    {
        this._listNode.style.display="none";
        this._clearList();
        this._selectedIndex=-1;
        this._resultCount=0
    },
    _getBounds:function()
    {
         var parent = this._listNode.offsetParent;
         if(this._listNode.offsetParent.tagName==="HTML")
             parent = document.getElementsByTagName("BODY")[0];
         var popupOffsetLoc = Sys.UI.DomElement.getLocation(parent);  
         var bounds= Sys.UI.DomElement.getBounds(this.get_element());
         var popupBounds =  Sys.UI.DomElement.getBounds(this._listNode)
         var x,y; 
         x =  bounds.x -popupOffsetLoc.x;  
         y = bounds.y -popupOffsetLoc.y + bounds.height;
         return  {'x':x, 'y':y};
    },
    _startTimer:function()
    {
        this._timer = window.setTimeout(this._tickDlg, this._interval);
    },
    _stopTimer:function()
    {
        if(this._timer!=null){
            window.clearTimeout(this._timer);
            this._timer = null;}
    },
    get_ServiceMethod:function(){ return this._serviceMethod;},
    set_ServiceMethod:function(value){this._serviceMethod = value; },
    get_ServicePath:function() {return this._servicePath;},
    set_ServicePath:function(value){this._servicePath = value;},
    get_ListCss:function(){return this._listCss;},
    set_ListCss:function(value){this._listCss = value;},
    get_ListItemCss:function(){return this._itemCss ;},
    set_ListItemCss:function(value) {this._itemCss = value;},
    get_ListHLItem:function(){return this._itemHlClass;},
    set_ListHLItem:function(value) {this._itemHlClass = value;},
    get_Delimeters:function (){return this._delimeters;},
    set_Delimeters:function(value){this._delimeters = Sys.Serialization.JavaScriptSerializer.deserialize(value);},
    get_Prefix:function() {return this._prefix;},
    set_Prefix:function(value) { this._prefix = value;},
    get_ComplCount:function() {return this._complCount;},
    set_ComplCount:function(value) {this._complCount = value;},
    get_Interval:function () {return this._interval;},
    set_Interval:function (value) {this._interval = value;},
    get_ContextKey:function(){return this._key;},
    set_ContextKey:function(value){this._key = value;}
    
}
Ftn.Client.AutoComplete.registerClass('Ftn.Client.AutoComplete', Sys.UI.Behavior);
///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.Rating = function (element)
{
    Ftn.Client.Rating.initializeBase(this, [element]);
    this._filledCss="";
    this._emptyCss="";
    this._tag="";
    this._rating=0;
    this._hiddenId =null;
    this._stars = new Array();
    this._clickDlg=null;
    this._mouseOverDlg=null; 
    this._mouseOutDlg=null   
    this._max = 5;
}
Ftn.Client.Rating.prototype = {
    initialize: function()
    {
        Ftn.Client.Rating.callBaseMethod(this, 'initialize');
        this._clickDlg=Function.createDelegate(this,this._starClick);
        this._mouseOverDlg=Function.createDelegate(this,this._starOver);    
        this._mouseOutDlg =Function.createDelegate(this, this._lostFocus);
        this._initStarsArr();
        $addHandler(this.get_element(),"mouseout",this._mouseOutDlg);
    },
    dispose:function()
    {
        $removeHandler(this.get_element(),"mouseout",this._mouseOutDlg);
        for(var i=0; i<this._max; i++){
            $removeHandler(this._stars[i],"click",this._clickDlg);
            $removeHandler(this._stars[i],"mouseover",this._mouseOverDlg);
            }
        Ftn.Client.Rating.callBaseMethod(this, 'dispose');
    },
    _initStarsArr:function()
    {
        this._stars = this.get_element().getElementsByTagName(this._tag);
        for(var i=0; i<this._max; i++){
            $addHandler(this._stars[i],"click",this._clickDlg);
            $addHandler(this._stars[i],"mouseover",this._mouseOverDlg);
            }
    },
    _starClick:function(e)
    {  
        var r =  e.target.getAttribute("num");
        this._hidden.value = r;
        this._rating = parseInt(r);
        this._fillStars();
    },
    _fillStars:function()
    { 
        for(var i=0; i<this._max; i++)
           this._stars[i].className = i>this._rating-1 ? this._emptyCss : this._filledCss;
    },
    _starOver:function(e)
    {
        this._rating = parseInt(e.target.getAttribute("num"));
        this._fillStars();
    },
    _lostFocus:function(e)
    {
        this._rating = parseInt(this._hidden.value);
        this._fillStars();
    },
    get_FilledCss : function (){ return this._filledCss; },
    set_FilledCss :function(value) {this._filledCss = value; },
    get_EmptyCss : function (){ return this._emptyCss; },
    set_EmptyCss :function(value) {this._emptyCss = value; },
    get_Tag : function() {return this._tag;},
    set_Tag: function(value) {this._tag = value;},
    get_StateField:function() { return this._hidden;},
    set_StateField:function(value) { this._hidden = eval(value);},
    get_MaxRating:function () {return this._max;},
    set_MaxRating:function (value) {this._max = value;}
}
Ftn.Client.Rating.registerClass('Ftn.Client.Rating', Sys.UI.Control);
///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.HoverMenuLazyLoad = function(element) {
    Ftn.Client.HoverMenuLazyLoad.initializeBase(this, [element]);

    this._template = null;
	this._isLoadData = false;
}

Ftn.Client.HoverMenuLazyLoad.prototype =
{
    initialize: function() {
		this._createAndInitPopupDiv();
	
        Ftn.Client.HoverMenuLazyLoad.callBaseMethod(this, 'initialize');

		this._isLoadData = false;
		this._isStartLoadData = false;
        this._template = $get(this.get_TemplateID());
		//this._contentTemplate = $get(this._template, 'content');
    },

    dispose: function() {
		document.body.removeChild(this._popupControl);
		this._template = null;
        Ftn.Client.HoverMenuLazyLoad.callBaseMethod(this, 'dispose');
    },

	_createAndInitPopupDiv : function() {
		var div = document.createElement('div');
		div.id = this.get_id() + '_hoverLazy';
        div.style.display = "none";
		document.body.appendChild(div);
		this._popupControl = div;
	},

    _execServiceMethod: function() {
        Sys.Net.WebServiceProxy.invoke($url(this.ServicePath), this.get_MethodName(), false, { 'id': this.ParameterId }, Function.createDelegate(this, this._serviceComplite));
    },
	
	_serviceComplite: function(resObject){
		var newNode = this._template.cloneNode(true);
		newNode.id = this._template.id + this.get_id();
		var stringNewNode = newNode.innerHTML;
		
		for (var key in resObject)   {
			stringNewNode = this._strReplace(stringNewNode, '_' + key + '_', resObject[key]);
		}
		
		this._popupControl.innerHTML = stringNewNode;
		this._isLoadData = true;
	},
	
	_strReplace : function (haystack, needle, replacement) {
		var temp = haystack.split(needle);
		return temp.join(replacement);
	},

	_showed : function(eventArgs) {
		Ftn.Client.HoverMenuLazyLoad.callBaseMethod(this, '_showed');
		if(eventArgs.cancel) return;
		if (this._isStartLoadData) return;
		
		this._isStartLoadData = true;
		//this._popupControl.innerHTML = this._getLoadTemplate();
		this._execServiceMethod();
	},
	
	_getLoadTemplate : function() {
		return
		'<div class="text-loading">' +
			'<h2>' +
				'<img width="16" height="16" src="images/loader.gif" alt="Loading…"/>' +
				'Loading…' +
			'</h2>'+
		'</div>';
	},

    get_TemplateID: function() {
        return this.TemplateID;
    },
    set_TemplateID: function(value) {
        if (this.TemplateID != value)
            this.TemplateID = value;
    },
    get_ParameterId: function() {
        return this.ParameterId;
    },
    set_ParameterId: function(value) {
        if (this.ParameterId != value)
            this.ParameterId = value;
    },
    get_ServicePath: function() {
        return this.ServicePath;
    },
    set_ServicePath: function(value) {
        if (this.ServicePath != value)
            this.ServicePath = value;
    },
    get_MethodName: function() {
        return this.MethodName;
    },
    set_MethodName: function(value) {
        if (this.MethodName != value)
            this.MethodName = value;
    }
}				
Ftn.Client.HoverMenuLazyLoad.inheritsFrom(Ftn.Client.HoverMenu);
Ftn.Client.HoverMenuLazyLoad.registerClass('Ftn.Client.HoverMenuLazyLoad', Ftn.Client.HoverMenu);
///////////////////////////////////////////////////////////////////////////////////////////////
Ftn.Client.WatermarkedTextBox = function()
{
    Ftn.Client.WatermarkedTextBox.initializeBase(this);
    this._input = null;
    this._watermark = null;
    this._onFocusDlg = null;
    this._onBlurDlg = null;
    this._onFocusInputDlg = null;
}
Ftn.Client.WatermarkedTextBox.prototype = 
{
     initialize: function()
     {
        Ftn.Client.WatermarkedTextBox.callBaseMethod(this, 'initialize');
        this._onFocusDlg = Function.createDelegate(this, this._onFocus);
        this._onFocusInputDlg = Function.createDelegate(this, this._onFocusInput);
        this._onBlurDlg = Function.createDelegate(this, this._onBlur);
        $addHandler(this._watermark,"focus",this._onFocusDlg);
        $addHandler(this._input,"focus",this._onFocusInputDlg);
        $addHandler(this._input,"blur", this._onBlurDlg);
        
     },
     dispose: function() {
        Ftn.Client.WatermarkedTextBox.callBaseMethod(this, 'dispose');
        $removeHandler(this._watermark,"focus",this._onFocusDlg);
        $removeHandler(this._input,"focus",this._onFocusInputDlg);
        $removeHandler(this._input,"blur", this._onBlurDlg);
     },
     _onFocus:function(e)
     {
        this._input.focus();
     },
     _onFocusInput:function()
     {
        if(this._input.value.length==0)
            this._watermark.style.display = "none";
     },
     _onBlur:function(e)
     {
        if(this._input.value.length==0)
            this._watermark.style.display = "block";
     },
     get_Input:function(){return this._input;},
     set_Input:function(value){this._input=value;},
     get_Watermark:function(){return this._watermark;},
     set_Watermark:function(value){this._watermark = value;}
} 
Ftn.Client.WatermarkedTextBox.registerClass('Ftn.Client.WatermarkedTextBox', Sys.Component);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
