//v.2.6 build 100722

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/

var lang_option="";
lang_option = lang;
function dhtmlxSlider(base,size,skin,vertical,step,min,max,value)
{
	if (_isIE)
    try 
    {
    document.execCommand("BackgroundImageCache", false, true);
    }
    catch (e){};
    var parentNod;
    if (base && typeof(base)=="object" && !base.nodeName)
    {
    parentNod=base.parent;
    skin=base.skin;
    min=base.min;
    max=base.max
    step=base.step;
    vertical=base.vertical;
    value=base.value;
    size=base.size;
    
    };

    if (!base)
    {
    var z="slider_div_"+(new Date()).valueOf()+Math.random(1000);
    parentNod = document.createElement ("div");
    parentNod.setAttribute ("id", z);
    var child = document.body.lastChild;
    while (child.lastChild && child.lastChild.nodeType == 1)
    child=child.lastChild;child.parentNode.insertBefore(parentNod,child);
    }
    else if (typeof(base)!="object")
    parentNod=document.getElementById(base);
    else
    parentNod = base;
    if (typeof(size)=="object")
    {
    skin=size.skin;
    min=size.min;
    max=size.max;
    step=size.step;
    vertical=size.vertical;
    value=size.value;size=size.size;
    };
    
    this.size = size;
    this.vMode=vertical||false;
    this.skin = dhtmlx.skin || skin || "default";
    this.parent = parentNod;
    this.isInit = false;
    this.disabled = false;
    this.value = value || min || 0;
    this.inputPriority = true;
    this.stepping = false;
    this.imgURL = window.dhx_globalImgPath||dhtmlx.image_path||"";
    this._skinsImgs = 
 {"default": {ls:1,lz:1,rz:1,rs:1},
 ball: {ls:1,lz:1,rz:1,rs:1},
 zipper: {bg:1,lz:1,rz:1},
 arrow: {bg:1,ls:1,rs:1},
 arrowgreen: {bg:1,ls:1,rs:1},
 simplesilver:{lz:1,ls:1,rs:1,rz:1},
 simplegray: {lz:1,ls:1,rs:1,rz:1},
 bar: {bg:1,ls:1,rs:1},
 dhx_skyblue: {bg:1,ls:1,rs:1,lz:1}};
 //this._def = [min-0||0,max-0||100,step-0||1,value-0||0,size-0]; changed
 this._def = [min-0||0,max-0||0,step-0||1,value-0||0,size-0];
 dhtmlxEventable(this);
 return this;
 };
 dhtmlxSlider.prototype.createStructure = function(){
 if (this.con)
 {this.con.parentNode.removeChild(this.con);this.con = null;};
 
 if (this.vMode)
 {this._sW="height";this._sH="width";this._sL="top";this._sT="left";var skinImgPath = this.imgURL+"skins/"+this.skin+"/vertical/";}
 else
 {this._sW="width";this._sH="height";this._sL="left";this._sT="top";var skinImgPath = this.imgURL+"skins/"+this.skin+"/";};
 
 this.con=document.createElement("DIV");
 this.con.onselectstart=function()
 {return false;};
 
 this.con._etype="slider";
 this.con.className = "dhtmlxSlider" + (this.skin!='default'?"_"+this.skin:"");
 if (this._skinsImgs[this.skin]['bg'])
 //this.con.style.backgroundImage = "url("+skinImgPath+"bg.gif)";
 
 this.drag=document.createElement("DIV");
 this.drag._etype="drag";
 this.drag.className = "selector";
 //this.drag.style.backgroundImage = "url("+skinImgPath+"selector.gif)";
 
 var leftSide = document.createElement("DIV");
 leftSide.className = "leftSide";
 //if (lang_option){
	if (lang_option=="1" || lang_option=="14" || lang_option== "15"){
		leftSide.className = "leftSide_ar";		
	}
 //}
 if (this._skinsImgs[this.skin]['ls'])
 //leftSide.style.background = "url("+skinImgPath+"leftside_bg.gif)";
 
 this.leftZone = document.createElement("DIV");
 this.leftZone.className = "leftZone";
 
 //if (lang_option){
	if (lang_option=="1" || lang_option=="14" || lang_option== "15"){
		this.leftZone.className = "rightZone";		
	}
// }
 if (this._skinsImgs[this.skin]['lz'])
 //this.leftZone.style.background = "url("+skinImgPath+"leftzone_bg.jpg)  repeat-x scroll 0% 50% transparent";//chaged to JPEG extension
 this.leftZone.style.width = this.value + 'px';
 
 var rightSide = document.createElement("DIV");
 rightSide.className = "rightSide";
// if (lang_option){
if (lang_option=="1" || lang_option=="14" || lang_option== "15"){
		rightSide.className = "rightSide_ar";
	}
 //}
 if (this._skinsImgs[this.skin]['rs'])
// rightSide.style.background = "url("+skinImgPath+"rightside_bg.gif)";
 
 this.rightZone = document.createElement("DIV");
 this.rightZone.className = "rightZone";
 //if (lang_option){
	if (lang_option=="1" || lang_option=="14" || lang_option== "15"){
		this.rightZone.className = "leftZone";
	}
// }
 if (this._skinsImgs[this.skin]['rz'])
 this.rightZone.style.background = "url("+skinImgPath+"rightzone_bg.gif)";
 
// this.tab = document.createElement("table");

// this.row=document.createElement("tr");

//if(this._def[0]>this._def[1])
//{
//    var tdwidth=(this._def[4]-40)/this._def[0];
//     for(i=this._def[0];i>=this._def[1];i--)
//     {
//     this.col=document.createElement("td");
//     var text=document.createTextNode(i);
//     this.col.appendChild(text);
//     this.col.setAttribute("style","width:"+tdwidth+"px");
//     this.row.appendChild(this.col);
//     
//     }
//    //window.status=this._def[0] +"  "+this._def[1] +"   "+this._def[3]+"    "+this._def[4];
//}
//else
//{
//    var tdwidth=(this._def[4]-40)/this._def[1];
//     for(i=this._def[0];i<=this._def[1];i++)
//    {
//     this.col=document.createElement("td");
//     var text=document.createTextNode(i);
//     this.col.appendChild(text);
//     this.col.setAttribute("style","width:"+tdwidth+"px");
//     this.row.appendChild(this.col);
//    }
//    //window.status=this._def[0] +"  "+this._def[1] +"   "+this._def[3]+"    "+this._def[4];
//}


//this.tab.appendChild(this.row);


 this.con.appendChild(leftSide);
 this.con.appendChild(this.leftZone);
 this.con.appendChild(this.rightZone);
 this.con.appendChild(rightSide);
 this.con.appendChild(this.drag);
 this.parent.appendChild(this.con);
 
 //this.parent.appendChild(this.tab);
 
 if (!this.parent.parentNode || !this.parent.parentNode.tagName)
 document.body.appendChild(this.parent);
 
 if (this.vMode)
 {
     this._sW="height";
     this._sH="width";
     this._sL="top";
     this._sT="left";
     this.con.style.width = this.con.offsetHeight + 'px';
     for (var i=0;i<this.con.childNodes.length;i++)
     {
     this.con.childNodes[i].style.fontSize = "0";
     var tmp = this.con.childNodes[i].offsetWidth;
     this.con.childNodes[i].style.width = this.con.childNodes[i].offsetHeight + 'px';
     this.con.childNodes[i].style.height = tmp + 'px';tmp = this.con.childNodes[i].offsetLeft;
     this.con.childNodes[i].style.left = this.con.childNodes[i].offsetTop + 'px';
     this.con.childNodes[i].style.top = tmp + 'px';
     };
     rightSide.style.top = this.size - rightSide.offsetHeight + 'px';
     this.zoneSize = this.size - rightSide.offsetHeight;
     this.dragLeft = this.drag.offsetTop;
     this.dragWidth = this.drag.offsetHeight;
     this.rightZone.style.height = this.zoneSize + 'px';
 }
 else 
 {
 var arrayRS = new Array();
arrayRS =   RSQid.split(',') ;
   for (i=0;i<=arrayRS.length-1;i++ )
    {
    if(document.getElementById('dv_'+arrayRS[i]))
    {
       if(document.getElementById('dv_'+arrayRS[i]).style.display=='none'){
            document.getElementById('dv_'+arrayRS[i]).style.display='block';     
        }
        
    }
 }
 this.zoneSize = this.size - rightSide.offsetWidth;

      
 this.dragLeft = this.drag.offsetLeft;
 this.dragWidth = this.drag.offsetWidth;
 this.rightZone.style.width = this.zoneSize + 'px';
  
     for (i=0;i<=arrayRS.length-1;i++ )
    {
    
    if(document.getElementById('dv_'+arrayRS[i]))
    {
    if (document.getElementById('dv_'+arrayRS[i]).style.display=='block')
    
    {
        document.getElementById('dv_'+arrayRS[i]).style.display='none';  
    }
    }
    
     }
 };
 this.con.style[this._sW] = this.size+"px";
 this.con.onmousedown=this._onMouseDown;
 this.con.onmouseup = this.con.onmouseout = function () {clearInterval (this.that._int)};
 this.con.that = this;
 this._aCalc(this._def);};
 
 dhtmlxSlider.prototype._aCalc=function(def)
 {if (!this.isInit)return;
 
 this.shift=def[0];
 this.limit=def[1]-this.shift;
 this._mod=(def[4]-this.dragLeft*2-this.dragWidth)/this.limit;
 this._step=def[2];
 this.step=this._step*this._mod;
 this._xlimit=def[4]-this.dragLeft*2-this.dragWidth;

 if (!this.posX)
 {this.posX=this._xlimit*(def[3]-this.shift)/this.limit;};
 this._applyPos(true);
 return this;};
 
 dhtmlxSlider.prototype.setMin=function(val)
 {this._def[0] = val-0;
 this._aCalc(this._def);};
 
 dhtmlxSlider.prototype.setMax=function(val)
 {this._def[1] = val-0;
 this._aCalc(this._def);};
 
 dhtmlxSlider.prototype.setStep=function(val)
 {this._def[2] = val-0;this._aCalc(this._def);};
 
 dhtmlxSlider.prototype._applyPos=function(skip)
 {if (!this.isInit)return;
 if (this.step!=1)
 this.posX=Math.round(this.posX/this.step)*this.step;
 if (this.posX<0)this.posX=0;
 if (this.value < (this._def[0] || 0))
 this.value = this._def[0] || 0;
 
 if (this.value > this._def[1])
 this.value = this._def[1];
 
 if (this.posX>this._xlimit)
 this.posX=this._xlimit;
 
 var a_old=this.drag.style[this._sL];
 this.drag.style[this._sL]=this.posX+this.dragLeft*1+"px";

 this.leftZone.style[this._sW]=this.posX+this.dragLeft*1+"px";
 this.rightZone.style[this._sL]=this.posX+this.dragLeft*1+1+"px";
 this.rightZone.style[this._sW]=this.zoneSize-(this.posX+this.dragLeft*1)+"px";
 var nw=this.getValue();


 if (this._link)
 {if (this._linkBoth)this._link.value=nw;
 else
 this._link.innerHTML=nw;};
 
 if (!skip&&a_old!=this.drag.style[this._sL])
 this.callEvent("onChange",[nw,this]);
 this.value = this.getValue ();
 if(!this._dttp)this._setTooltip(nw);};
 
 dhtmlxSlider.prototype._setTooltip=function(nw)
 {
 //this.con.title=nw;
 };
 
 dhtmlxSlider.prototype.setSkin=function(skin)
 {this.skin = skin||"default";
 if (this.isInit)
 this.createStructure();};
 
 dhtmlxSlider.prototype.startDrag = function(e) 
 {if (this._busy)return;
 if ((e.button === 0)|| (e.button === 1))
  {this.drag_mx = e.clientX;
  this.drag_my = e.clientY;
  this.drag_cx = this.posX;
  this.d_b_move = document.body.onmousemove;
  this.d_b_up = document.body.onmouseup;
  var _c=this;document.body.onmouseup = function(e){_c.stopDrag(e||event);_c=null;};
  document.body.onmousemove = function (e) {_c.onDrag(e||event);};this._busy=true;}};
  
  dhtmlxSlider.prototype.onDrag = function(e) 
  {if (this._busy)
    {if (!this.vMode)this.posX = this.drag_cx + e.clientX - this.drag_mx;
    else
    this.posX = this.drag_cx + e.clientY - this.drag_my;
    
    this._applyPos();}
 };
 
 dhtmlxSlider.prototype.stopDrag = function(e) 
 {
 document.body.onmousemove = this.d_b_move?this.d_b_move:null;document.body.onmouseup = this.d_b_up?this.d_b_up:null;this.d_b_move=this.d_b_up=null;this._busy=false;this.callEvent("onSlideEnd",[this.getValue()])
 };

dhtmlxSlider.prototype.getValue=function()
{
    if ((!this._busy)&& (this.inputPriority))
    return (Math.round (this.value / this._step) * this._step).toFixed(6)-0;
    return Math.round((Math.round((this.posX/this._mod)/this._step)*this._step+this.shift*1)*10000)/10000;
};
 
 dhtmlxSlider.prototype.setValue=function(val, skip)
 {
    
     if (isNaN(val)) 
     return;
     this._def[3] = this.value = val-0;
     this.posX=(Math.round(((val||0)-this.shift)*this._mod))
     this._applyPos(skip==null?true:skip);
 };
 
 dhtmlxSlider.prototype._getActionElement=function(nod)
 {
     if (nod._etype)return nod;
     if (nod.parentNode)
     return this._getActionElement(nod.parentNode);
     return null;
 };
 
dhtmlxSlider.prototype._onMouseDown=function(e)
 {

     if(this.that.disabled)return;
     e=e||event;
     var that=this.that;
	 var nod=that._getActionElement(_isIE?e.srcElement:e.target);
    switch (nod._etype){
		case "slider":
 if (that.vMode){var z=e.clientY-(getAbsoluteTop(that.con)-document.body.scrollTop);
  }
 else{
 
 var body = document.body;
 var docElem = document.documentElement;
 var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
 var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
 var clientTop = docElem.clientTop || body.clientTop || 0;
 var clientLeft = docElem.clientLeft || body.clientLeft || 0;
 
 var ccc = scrollLeft;
 var z=e.clientX-(getAbsoluteLeft(that.con)-ccc);
//     if((navigator.userAgent.indexOf('iPhone')!=-1) || (navigator.userAgent.indexOf('iPad')!=-1))
  if((navigator.userAgent.indexOf('iPhone')!=-1) )
        {
		 var z=e.clientX-(getAbsoluteLeft(that.con)); 
	    }
 }
  var posX = that.posX;that.posX = z-that.dragLeft-that.dragWidth/2;
 that.direction = that.posX > posX ? 1 : -1;
 if (that.stepping){
	 clearInterval (that._int);
 that.setValue (that.value + that._step * that.direction, false);
 that._int = setInterval (function () {that.setValue (that.value + that._step * that.direction, false)}, 600);
 }else {that._busy=true;that._applyPos();that._busy = false;};
 break;case "drag":
 that.startDrag(e||event);break;
 };return false;
 };
 
 dhtmlxSlider.prototype._linkFrom=function()
 {if(this.disabled)return;
 this.setValue (parseFloat (this._link.value), false);
 };
 
 dhtmlxSlider.prototype.linkTo=function(obj)
 {
 obj = (typeof(obj) != "object") ? document.getElementById(obj) : obj;
 this._link = obj;
 var name=obj.tagName.toString().toLowerCase();
 this._linkBoth=(((name=="input")||(name=="select")||(name=="textarea"))?1:0);
 if (this._linkBoth)
 {
    var self=this;var f=function()
    {
        if (this._nextSlider)window.clearTimeout(this._nextSlider);
        this._nextSlider=window.setTimeout(function(){self._linkFrom()},500);};
        obj.onblur=obj.onkeypress=obj.onchange=f;};
        this._applyPos();
  };
  
  dhtmlxSlider.prototype.enableTooltip=function(mode)
  {
  this._dttp=(!convertStringToBoolean(mode));
  this._setTooltip(this._dttp?"":this.getValue());
  };
  
  dhtmlxSlider.prototype.setImagePath = function(path)
  {this.imgURL = path;};
  
  dhtmlxSlider.prototype.init = function() 
  {
  this.isInit = true;
  this.createStructure();
  };
  
  dhtmlxSlider.prototype.setInputPriority = function (mode) 
  {this.inputPriority = mode;};
  
  dhtmlxSlider.prototype.setSteppingMode = function (mode) 
  {this.stepping = mode;};
  
  dhtmlxSlider.prototype.disable = function (mode) 
  {this.disabled = mode;};(function(){dhtmlx.extend_api("dhtmlxSlider",{_init:function(obj){return [ obj.parent, obj.size, obj.skin, obj.vertical, obj.min, obj.max, obj.value, obj.step ];},
 link:"linkTo"
 },{});})();
//v.2.6 build 100722

/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
