﻿
function screenSize() {
      var w, h; // Объявляем переменные, w - длина, h - высота
      w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
      h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
       mw = (window.innerWidth ? window.innerWidth : document.body.offsetWidth);
      mh = (window.innerHeight ? window.innerHeight :  document.body.offsetHeight);
      return {w:w, h:h, mw:mw, mh:mh};
}
IsNullOrEmpty = function(str){
    return str == null || str == "";
}
AddQueryParameter = function(queryString, parameterName, parameterValue){
    if(parameterValue == null || parameterValue == "") return queryString;
    return queryString 
           + (queryString != "" ? "&" : "") 
           + parameterName + "=" + escape(parameterValue);
}
CreateNotEmptyValueString = function(name, value){
    if(IsNullOrEmpty(value)) return "";
    return name + value;
}

//Dictionary Manager Class
//=========================================================================
DictionaryManager = function() { this.m_dictionaries = new Object();}
DictionaryManager.prototype.GetDictionary = function(dictionaryID){ return this.m_dictionaries[dictionaryID]; }
DictionaryManager.prototype.AddDictionary = function(dictionaryID,dictionary) { this.m_dictionaries[dictionaryID] = dictionary; }
DictionaryManager.prototype.SelectNames = function(dictionaryID,items){
    var dictionary = this.m_dictionaries[dictionaryID];
    var names = new Array();
    var ids = items;
    for(var indexItem in ids){
        for(var indexDic in dictionary){
            if(dictionary[indexDic][0] == ids[indexItem]) names.push(" " + dictionary[indexDic][1]);
        }
    }
    return names.join();
}
DictionaryManager.Instance = new DictionaryManager();

//Url Choiser Class
//=========================================================================
UrlChoiserSingle = function(url) { this.m_url = url; }
UrlChoiserSingle.prototype.GetUrl = function() { return this.m_url; }

UrlChoiserList = function(url) { 
    this.m_urls = new Array(); 
    this.m_urls.push(url);
    this.m_position = 0;
    }
UrlChoiserList.prototype.GetUrl = function() {return this.m_urls[this.m_position];}
UrlChoiserList.prototype.AddUrl = function(url) {this.m_urls.push(url);}
UrlChoiserList.prototype.SetCurrentUrl = function(position) {
    if( this.m_urls.length > position && position >= 0 ) this.m_position = position;
}

SubmitModes = {RealTime : "RealTime", SubmitButton : "SubmitButton" }
//SearchForm Class
//=========================================================================
FilterForm = function(name, urlchoiser, subName, schemaSearch, schemaRender,schemaData,renderParameter,callBackResult,callBackLoading,callBackError,direct,autoRefresh){
    this.SubmitMode = SubmitModes.RealTime;
    this.m_name= name;
    this.m_urlChoiser = urlchoiser;
      
    this.m_pagingsort = null;
            
    this.m_schemaSearch = schemaSearch;
    this.m_schemaRender = schemaRender;
    this.m_schemaData = schemaData;
    this.m_subName = subName;
    
    this.m_renderParameter = renderParameter;
    this.m_inputs = new Array();
    this.m_isChange = false; 

    //IT'S AJAX
    var thisObject = this;
    this.ObjectsCallbacks = { 
        success : function(result){ thisObject.m_isLoading = false; callBackResult(result);}, 
        error : callBackError
    }
    this.SubscribeCallbacks = { 
        success : function(result){ alert("Запрос сохранен"); }, 
        error : callBackError
    }    
    this.Loading = callBackLoading;
    this.ajax = new Mian.Lib.HttpRequest();     

    if(autoRefresh == true){ 
        Mian.Lib.EventManager.Instance.AddEventHandler("DOM_PostLoad", document, function() { 
            Mian.Lib.EventManager.Instance.RaiseEvent("Pre_AutoRefresh",thisObject);
            thisObject.Refresh(); 
            Mian.Lib.EventManager.Instance.RaiseEvent("Post_AutoRefresh",thisObject);
        })
    } 
}
FilterForm.prototype.SetButtonSubmitMode = function(){
    this.SubmitMode = SubmitModes.SubmitButton;
}
FilterForm.prototype.AddInput = function(name,input){
    var z = new Object();
    var thisObject = this;
    input.Refresh = function(){ thisObject.Refresh(); }
    input.Change = function(){ thisObject.OnChange(); }
    input.IsChange = function() {thisObject.OnIsChange();}
    input.Event = function(e) { thisObject.IssueEvent(e);}
    z.name = name;
    z.input = input;
    var isNew = true;
    for(var index in this.m_inputs)
      if(this.m_inputs[index].name == name)
      {
        isNew = false;
        this.m_inputs[index] = z;
      }
    if(isNew == true) this.m_inputs.push(z);
}
FilterForm.prototype.GetInput = function(name){   
    var result = null;
    for(var index in this.m_inputs)
      if(this.m_inputs[index].name == name)
        result = this.m_inputs[index];

    return result.input;
}
FilterForm.prototype.ToQueryParameters = function(){
   var result = "";
   for(var index in this.m_inputs)
   {
        var item = this.m_inputs[index];
        var value = item.input.ToQueryParameters();
        if(value!='') result += item.name + ":" + value + ";"; 
   } 
    
   return result;
}
FilterForm.prototype.GetUrl = function(){
    var url = this.m_urlChoiser.GetUrl();
    var ret = '';
    if(url.indexOf('?')==-1) 
        ret = url + '?';
        else
        ret = url + '&';
    return ret;
}
FilterForm.prototype.GetQueryParameter  = function(param){
    var nameForm = (this.m_name!="") ? this.m_name + "=" : "=";
    var pading = "";
    if(this.m_pagingsort!=null) pading = "page:" + this.m_pagingsort.ToQueryParameters();
    var result = "";
    if(param!="")
        return nameForm + param + pading;
        else
        return nameForm +  pading;
}
FilterForm.prototype.GetShemaParameter  = function(){
    var result = "";
    result = AddQueryParameter(result, "search", this.m_schemaSearch);
    result = AddQueryParameter(result, "render", this.m_schemaRender);
    result = AddQueryParameter(result, "result", this.m_renderParameter);
    result = AddQueryParameter(result, "data", this.m_schemaData);
    result = AddQueryParameter(result, "name", this.m_subName);  
    return result;
}
FilterForm.prototype.GetSubmitUrl = function(){
    var qparam = this.GetQueryParameter(this.ToQueryParameters());  
    if(qparam != "") qparam = '&' + qparam;
    return this.GetUrl()+ this.GetShemaParameter() + qparam;
}
FilterForm.prototype.ClearFilters = function(){
    this.m_queryParameters.ClearParameters(); 
}
FilterForm.prototype.OnIsChange = function(){
    this.m_isChange = true;
}
FilterForm.prototype.Change = function(){
    if(this.ajax.IsLoading() == false){
        this.m_isChange = false;
        this.OnChange();
    }
}
FilterForm.prototype.OnChange = function(){
    if(this.SubmitMode == SubmitModes.RealTime) this.Refresh();
}
FilterForm.prototype.IssueEvent = function(e){
   for(var index in this.m_inputs)
   {
        var item = this.m_inputs[index];
        item.input.ProcessEvent(e);
   } 
}
FilterForm.prototype.Refresh = function(){
    if(this.ajax.IsLoading() == false){
        if(this.Loading) this.Loading();
        if(this.m_urlChoiser.m_position == 0)
            this.ajax.GetJSON(this.GetSubmitUrl(), this.ObjectsCallbacks);
        else
            this.ajax.GetJSON(this.GetSubmitUrl(), this.SubscribeCallbacks);
    }    
}
FilterForm.prototype.GetBackUrl = function(anchor){
    var cutStr = document.location.href;
    var cutIndex = cutStr.indexOf('?filter=');
    if(cutIndex == -1) cutIndex = cutStr.length;
    var resSrt = cutStr.substr(0, cutIndex);
    var page = this.GetInput('page');
    if(page!=null) page.m_Flag = true;
    return anchor.href + '&back=' + escape(resSrt + "?filter=" + this.ToQueryParameters());
}
//Input Class
//=========================================================================
Input = function(){}
Input.prototype.Clear = function(){}
Input.prototype.ToString = function(){ return ""; }
Input.prototype.IsEmpty = function(){ return this.ToString() == ""; }
Input.prototype.ToQueryParameters = function(){ return ""; }
Input.prototype.AttachEvents = function(){}
Input.prototype.OnChange = function(){ if(this.Change != null) this.Change(); }
Input.prototype.OnIsChange = function(){ if(this.IsChange != null) this.IsChange(); }
Input.prototype.IssueEvent = function(e){ if(this.Event!=null) this.Event(e); }
Input.prototype.ProcessEvent = function(e){}
Input.prototype.OnRefresh = function(){ if(this.Refresh != null) this.Refresh();}

// CheckListInput Class
//=========================================================================
CheckListInput = function(containerID,isChange,dictionaryID,checkeds,nameEvent,valueEvent){
    this.m_nameEvent = nameEvent;
    this.m_valueEvent = valueEvent;
    this.m_isActive = true;
    this.m_container = document.getElementById(containerID);
    this.m_checkeds = checkeds;
    this.m_dictionaryID = dictionaryID;
    var ChecklistCallBackChange = this;
    
    for(var index in this.m_checkeds)
    {
        checked = document.getElementById(this.m_checkeds[index][0]);
        var e = new Object();
        e.name = dictionaryID;
        e.value = this.m_checkeds[index][1];
        if(isChange == true) checked.onclick = function(){e.value = ChecklistCallBackChange.GetValue(this.id); e.IsActive = this.checked; ChecklistCallBackChange.IssueEvent(e);ChecklistCallBackChange.OnChange();};
     }
}
CheckListInput.prototype = new Input;
CheckListInput.prototype.ProcessEvent =function(e)
{
    if(e.name == this.m_nameEvent && e.value == this.m_valueEvent)
    {
        if(e.IsActive) 
        {
            this.m_isActive = true;    
            this.m_container.style.display='block'
        }
        else 
        {
            this.m_isActive = false;    
            this.m_container.style.display='none';
        }
    }
}
CheckListInput.prototype.ToString = function(){
    var checkeds = this.GetCheckedValue();
    return DictionaryManager.Instance.SelectNames(this.m_dictionaryID,checkeds);
}
CheckListInput.prototype.IsEmpty = function(){
   for(var index in this.m_checkeds)
        if(document.getElementById(this.m_checkeds[index][0]).checked) return false; 
   return true;
}
CheckListInput.prototype.GetValue = function(id){
   for(var index in this.m_checkeds)
        if(this.m_checkeds[index][0] == id) return this.m_checkeds[index][1]; 
   return '';
}
CheckListInput.prototype.ToQueryParameters = function(){
    if(this.m_isActive == false) return '';
    var checkeds = this.GetCheckedValue();
    if(checkeds.length > 0) return checkeds.join();
    return '';
}
CheckListInput.prototype.GetCheckedValue = function(){
    var checkeds = new Array();
    for(var index in this.m_checkeds)
        if(document.getElementById(this.m_checkeds[index][0]).checked)
        checkeds.push(this.m_checkeds[index][1]);
    return checkeds;
}
CheckListInput.prototype.Clear = function()
{
    for(var index in this.m_checkeds)
        document.getElementById(this.m_checkeds[index][0]).checked = false;
}
// HiddenInput Class
//=========================================================================        
ValueInput = function(data, isAddToQueryParameters) { 
    this.m_data = data; 
    this.m_isAddToQueryParameters = isAddToQueryParameters;
}
ValueInput.prototype = new Input;
ValueInput.prototype.ToQueryParameters = function(){
    if(this.m_isAddToQueryParameters == null || this.m_isAddToQueryParameters == false) return "";
    return this.m_data;
}
// TextInput Class
//=========================================================================        
TextInput = function(data) { 
    this.m_data = document.getElementById(data); 
    this.AttachEvents();
}
TextInput.prototype = new Input;
TextInput.prototype.ToQueryParameters = function(){
    return escape(this.m_data.value);
}
TextInput.prototype.AttachEvents = function(){
    var thisObject = this;
    
    var changeHandler = function() {thisObject.OnChange();}
    if(document.addEventListener){
        this.m_data.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_data.attachEvent("onchange", changeHandler);
    }                       
}

// LinkedSelectsInput Class
//=========================================================================
//Class used Array Of DictionaryItemWithChildsResult
//DictionaryItemResult = function(){
//    var Key = "childKey1";
//    var Value = "childValue1";
//}
//DictionaryItemWithChildsResult = function(){
//    var Key = "parentKey1";
//    var Value = "parentValue1";
//    var Childs = Array Of DictionaryItemResult
//}
LinkedSelectsInput = function(parentSelectID, childSelectID, data){
    this.m_parentSelect = document.getElementById(parentSelectID);
    this.m_childSelect = document.getElementById(childSelectID);
    this.m_data = data;
    this.AttachEvents();
} 
LinkedSelectsInput.prototype = new Input;
LinkedSelectsInput.prototype.ToQueryParameters = function(){
    return this.m_parentSelect.options[this.m_parentSelect.selectedIndex].value + "," + this.m_childSelect.options[this.m_childSelect.selectedIndex].value; 
}
LinkedSelectsInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeParentHandler = function() { thisObject.OnParentChange(); }
    var changeChildHandler = function() { thisObject.OnChange(); }
    if(document.addEventListener){
        this.m_parentSelect.addEventListener("change", changeParentHandler, true);
        this.m_childSelect.addEventListener("change", changeChildHandler, true);
    }else if(document.attachEvent){
        this.m_parentSelect.attachEvent("onchange", changeParentHandler);
        this.m_childSelect.attachEvent("onchange", changeChildHandler);
    }                       
}
LinkedSelectsInput.prototype.OnParentChange = function(){
    var selectedParentKey = this.m_parentSelect.options[this.m_parentSelect.selectedIndex].value;
    for(var index in this.m_data){
        if(this.m_data[index].Key == selectedParentKey){
            this.m_childSelect.options.length = 0;
            var childs = this.m_data[index].Childs;
            for(var childIndex in childs){
                this.m_childSelect.options[this.m_childSelect.options.length] = new Option(childs[childIndex].Value, childs[childIndex].Key);    
            }
        }
    }
    if(this.Change != null) this.Change();
}          
//SelectInput Class
//=========================================================================
SelectInput = function(selectID,isChange){
    this.m_select = document.getElementById(selectID);
    if(isChange == true) this.AttachEvents();
} 
SelectInput.prototype = new Input;
SelectInput.prototype.ToQueryParameters = function(){
    return this.m_select.options[this.m_select.selectedIndex].value; 
}
SelectInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeHandler = function() { thisObject.OnChange(); }
    if(document.addEventListener){
        this.m_select.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_select.attachEvent("onchange", changeHandler);
    }                       
}
SelectInput.prototype.OnChange = function(){ 
    if(this.Change != null && this.m_select.options[this.m_select.selectedIndex].value != "") this.Change(); 
}
//SelectInput Class
//=========================================================================
SelectInputAdmin = function(selectID){
    this.m_select = document.getElementById(selectID);
    this.AttachEvents();
} 
SelectInput.prototype = new Input;
SelectInput.prototype.ToQueryParameters = function(){
    return this.m_select.options[this.m_select.selectedIndex].value; 
}
SelectInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeHandler = function() { thisObject.OnChange(); }
    if(document.addEventListener){
        this.m_select.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_select.attachEvent("onchange", changeHandler);
    }                       
}
SelectInput.prototype.OnChange = function(){ if(this.Change != null && this.m_select.options[this.m_select.selectedIndex].value != "") this.Change(); }
// PopupDialog Class
//=========================================================================
PopupDialog = function(dialogID,cssLayer,cssShadow){
    this.m_dialog = document.getElementById(dialogID);
    this.m_parent = this.m_dialog.parentNode;
    this.m_shadow = document.createElement("DIV");
    this.m_shadow.className = cssShadow;
    this.m_layer = document.createElement("DIV");
    this.m_layer.className = cssLayer;
    this.m_parent.appendChild(this.m_layer);
    this.m_parent.appendChild(this.m_shadow);
}
PopupDialog.prototype.ShowDialog = function(){
    this.m_dialog.style.Zindex = 2000;
    this.m_dialog.style.position='absolute';
    this.m_dialog.style.display='block';
    var size = screenSize();
    
    var height = this.m_dialog.clientHeight;
    var width = this.m_dialog.clientWidth;
    var top = size.h/2 - height/2;
    var left = size.w/2 - width/2;
    
    this.m_layer.style.position='absolute';
    this.m_layer.style.display='block';
    this.m_layer.style.top = 0;//coord.top+'px';
    this.m_layer.style.left = 0;//coord.left+'px';
    this.m_layer.style.width = size.mw + 'px';
    this.m_layer.style.height = size.mh + 'px';
    this.m_layer.style.filter = "alpha(opacity=80)";
    this.m_layer.style.opacity = 0.8;
        
    this.m_dialog.style.position='absolute';
    this.m_dialog.style.top  = top + 'px';
    this.m_dialog.style.left = left + 'px';
       
    this.m_shadow.style.position='absolute';
    this.m_shadow.style.top  = top + 5 + 'px';//coord.top+'px';
    this.m_shadow.style.left = left + 5 + 'px';//coord.left+'px';
    this.m_shadow.style.width = width;
    this.m_shadow.style.height = height;
    this.m_shadow.style.display='block';
}
PopupDialog.prototype.CloseDialog = function(){
    this.m_dialog.style.display='none';
    this.m_layer.style.display='none';
    this.m_shadow.style.display='none';
}
// MoneyInput Class
//=========================================================================
MoneyInput = function(dictionaryID, beginID, endID, currencyID, unitID){
    //this.m_container = document.getElementById(containerID);
    this.m_dictionaryID = dictionaryID;
    this.m_unit = document.getElementById(unitID);
    this.m_beginControl = document.getElementById(beginID);
    this.m_endControl = document.getElementById(endID);
    this.m_currency = document.getElementById(currencyID);
    this.AttachEvents();
}
MoneyInput.prototype = new Input;
MoneyInput.prototype.ToString = function(){
    if(this.IsEmpty()) return "";
    var strRet= "";
    strRet += CreateNotEmptyValueString(" от ", this.m_begin);
    strRet += CreateNotEmptyValueString(" до ", this.m_end);
    var selectedItemNames = DictionaryManager.Instance.SelectNames(this.m_dictionaryID,this.m_currency.options[this.m_currency.selectedIndex].value.split(','));
    strRet += CreateNotEmptyValueString(" ", selectedItemNames);
    return strRet;
}
MoneyInput.prototype.IsEmpty = function(){
    if(this.m_beginControl.value != "" || this.m_endControl.value != "" ) return false;
    return true;
}
MoneyInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()) return "";
    return  this.m_currency.options[this.m_currency.selectedIndex].value 
            + "," + this.m_unit.value  
            + "," + Mian.Lib.ParseToInt(this.m_beginControl.value)
            + "," + Mian.Lib.ParseToInt(this.m_endControl.value);
}
MoneyInput.prototype.AttachEvents = function(){
    var thisObject = this;   
    var changeHandler = function() {thisObject.OnIsChange();}
    if(document.addEventListener){
        this.m_beginControl.addEventListener("change", changeHandler, true);
        this.m_endControl.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_beginControl.attachEvent("onchange", changeHandler);
        this.m_endControl.attachEvent("onchange", changeHandler);
    }                       
}
MoneyInput.prototype.GetScaleName = function(){
    var result = this.m_currency.options[this.m_currency.selectedIndex].value 
            + "_" + this.m_unit.value;
    return result;
}
//PageInput Class
//=========================================================================
PageSortInput = function(pageNo,pageCount,pageSize,sort,direct){
    this.m_pageNo = pageNo;
    this.m_pageSize = pageSize; 
    this.m_pageCount = pageCount;
    this.m_sort = sort;
    this.m_direct = direct;
    this.m_Flag = false;
}
PageSortInput.prototype = new Input;
PageSortInput.prototype.ToString = function(){
    if(this.IsEmpty()) return "";    
    var strRet = "";
    if(this.m_current!="") strRet += " страница:" +  this.m_pageNo;
    if(this.m_pageSize!="") strRet += " размер страницы:" +  this.m_pageSize;    
    if(this.m_Sort!="") strRet += " сортировка:" +  this.m_sort;    
    return strRet;
}
PageSortInput.prototype.IsEmpty = function(){
    if(this.m_current != "" || this.m_pageSize != "" || this.m_sort != "") return false;
    return false;
}
PageSortInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()) return "";
    if(this.m_Flag == false) this.m_pageNo = 1;
    return this.m_pageNo 
           + ',' + this.m_pageSize 
           + ',' + this.m_sort + '_' + this.m_direct;
}
PageSortInput.prototype.NextPage = function(){
    this.m_pageNo -= 0;
    if(this.m_pageNo < this.m_pageCount){
        this.m_pageNo += 1;
        this.m_Flag = true;
        this.OnRefresh();
    }
}
PageSortInput.prototype.PrevPage = function(){
    this.m_pageNo -= 0;
    if(this.m_pageNo > 1){ 
        this.m_pageNo -= 1;
        this.m_Flag = true;
        this.OnRefresh();
        //this.OnChange();
    }
}
PageSortInput.prototype.SizePage = function(pageSize){
      this.m_pageSize = pageSize;
      this.m_Flag = true;
      this.OnRefresh();
}
PageSortInput.prototype.GotoPage = function(page){
    if(page <= this.m_pageCount){
        this.m_pageNo = page;
        this.m_Flag = true;
        this.OnRefresh();
    }
}
PageSortInput.prototype.Sorting = function(sort){
    this.m_pageNo = 1;
    this.m_direct = this.m_direct == "asc" ? "desc" : "asc";
    this.m_sort = sort;
    this.m_Flag = true;
    this.OnRefresh();
}
// RangeInput Class
//=========================================================================
RangeInput = function(beginID,endID,meas){
    this.m_meas = meas;
    this.m_beginID = beginID;
    this.m_endID = endID;
    this.m_beginControl = document.getElementById(beginID);
    this.m_endControl = document.getElementById(endID);
    this.AttachEvents();
 }
 RangeInput.prototype = new Input;
 RangeInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeHandler = function() {thisObject.OnIsChange();}
        if(document.addEventListener){
        this.m_beginControl.addEventListener("change", changeHandler, true);
        this.m_endControl.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_beginControl.attachEvent("onchange", changeHandler);
        this.m_endControl.attachEvent("onchange", changeHandler);
    }                       
}
RangeInput.prototype.ToString = function(){
    if(this.IsEmpty()) return "";
    var strRet = "";
    strRet += CreateNotEmptyValueString(" от:", this.m_beginControl.value);
    strRet += CreateNotEmptyValueString(" до:", this.m_endControl.value);
    return strRet;
}
RangeInput.prototype.IsEmpty = function(){
    if(this.m_beginControl.value != "" || this.m_endControl.value != "") return false;
    return true;
}
RangeInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()) return "";
    var result = "";
    result = this.m_beginControl.value 
             + "," + 
             this.m_endControl.value;
    result += CreateNotEmptyValueString(",", this.m_meas);
    return  result;
}
RangeInput.prototype.OnChange = function(){
    if(this.Change != null) this.Change();
}
// RangeInput Class
//=========================================================================
RangeIntInput = function(beginID,endID,meas){
    this.m_meas = meas;
    this.m_beginID = beginID;
    this.m_endID = endID;
    this.m_beginControl = document.getElementById(beginID);
    this.m_endControl = document.getElementById(endID);
    var ChecklistCallBackChange = this;
    this.AttachEvents();
 }
 RangeIntInput.prototype = new Input;
 RangeIntInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeHandler = function() {thisObject.OnChange();}
        if(document.addEventListener){
        this.m_beginControl.addEventListener("change", changeHandler, true);
        this.m_endControl.addEventListener("change", changeHandler, true);
    }else if(document.attachEvent){
        this.m_beginControl.attachEvent("onchange", changeHandler);
        this.m_endControl.attachEvent("onchange", changeHandler);
    }                       
}
RangeIntInput.prototype.ToString = function(){
    if(this.IsEmpty()) return "";
    var strRet = "";
    strRet += CreateNotEmptyValueString(" от:", this.m_beginControl.value);
    strRet += CreateNotEmptyValueString(" до:", this.m_endControl.value);
    return strRet;
}
RangeIntInput.prototype.IsEmpty = function(){
    if(this.m_beginControl.value != "" || this.m_endControl.value != "") return false;
    return true;
}
RangeIntInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()) return "";
    var result = "";
    result = Mian.Lib.ParseToInt(this.m_beginControl.value) 
             + "," + 
             Mian.Lib.ParseToInt(this.m_endControl.value);
    result += CreateNotEmptyValueString(",", this.m_meas);
    return  result;
}
RangeIntInput.prototype.OnChange = function(){
    if(this.Change != null) this.Change();
}
// MetroInput Class
//=========================================================================
MetroInput = function(containerID,hiddenID, dictionaryID,nameEvent,valueEvent){
    this.m_nameEvent = nameEvent;
    this.m_valueEvent = valueEvent;
    this.m_isActive = true;
    this.m_container = document.getElementById(containerID);
    
    this.m_hidden = document.getElementById(hiddenID);
    this.m_dictionaryID = dictionaryID;
    var ChecklistCallBackChange = this;
    //if(this.m_hidden != null)this.m_hidden.onchange = function(){ChecklistCallBackChange.OnChange();};
 }
MetroInput.prototype =  new Input;
MetroInput.prototype.Clear = function(){
     this.m_hidden.value = "";
}
MetroInput.prototype.ToString = function(){
    var result = "";
    result = DictionaryManager.Instance.SelectNames(this.m_dictionaryID,this.m_hidden.value.split(','));
    return result;
}
MetroInput.prototype.IsEmpty = function(){
    return this.m_hidden.value=="";
}
MetroInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()|| this.m_isActive == false) return '';
    return this.m_hidden.value;
}
MetroInput.prototype.ProcessEvent = function(e){
    if(e.name == this.m_nameEvent && e.value == this.m_valueEvent){
        if(e.IsActive) {
            this.m_isActive = true;    
            this.m_container.style.display='block'
        } else {
            this.m_isActive = false;    
            this.m_container.style.display='none';
        }
    }
}
// FloorInput Class
//=========================================================================
FloorInput = function(beginID,endID,firstID,lastID){
    this.m_beginControl = document.getElementById(beginID);
    this.m_endControl = document.getElementById(endID);
    this.m_first = document.getElementById(firstID);
    this.m_last = document.getElementById(lastID);
    this.AttachEvents();
}
FloorInput.prototype = new Input;
FloorInput.prototype.ClearInputs = function(){
    his.m_beginControl.value = "";
    this.m_endControl.value = "";
    this.m_first.checked = false;
    this.m_first.checked = false;
}
FloorInput.prototype.ToString = function(){
    if(this.IsEmpty()) return "";
    var strRet = "";
    strRet += CreateNotEmptyValueString(" от:", this.m_beginControl.value);
    strRet += CreateNotEmptyValueString(" до:", this.m_endControl.value);
    if(this.m_first.checked) strRet += " кроме первого";
    if(this.m_last.checked) strRet += " кроме последнего";
    
    return strRet;
}
FloorInput.prototype.IsEmpty = function(){
    if(this.m_beginControl.value != "" || this.m_endControl.value != "" || this.m_first.checked || this.m_last.checked) return false;
    return true;
}
FloorInput.prototype.ToQueryParameters = function(){
    if(this.IsEmpty()) return "";
    return this.m_beginControl.value + "," + this.m_endControl.value + "," + this.m_first.checked + "," + this.m_last.checked;
}
FloorInput.prototype.AttachEvents = function(){
    var thisObject = this;
    var changeHandler = function() { thisObject.OnChange(); }
    if(document.addEventListener){
        this.m_beginControl.addEventListener("change", changeHandlerr, true);
        this.m_endControl.addEventListener("change", changeHandler, true);
        this.m_first.addEventListener("click",changeHandler,true);
        this.m_last.addEventListener("click",changeHandler,true);       
    } else if(document.attachEvent){
        this.m_beginControl.attachEvent("onchange", changeHandler);
        this.m_endControl.attachEvent("onchange", changeHandler);
        this.m_first.attachEvent("onclick",changeHandler,true);
        this.m_last.attachEvent("onclick",changeHandler,true)
    }                       
}
FloorInput.prototype.OnChange = function(){
    if(this.Change != null) this.Change();
}
