


function Slider(root, title, minBarId, maxBarId, minTextBox, maxTextBox, outOfMin, outOfMax, 
				totalWidth, width1, width2, width3, width4, width5, vMin, vMax, validMin, validMax, spaceWidth, cover) {
  
  this.root = root;
  this.title = title;
  this.minBarId = minBarId;
  this.maxBarId = maxBarId;
  this.minTextBox = minTextBox;
  this.maxTextBox = maxTextBox;
  this.outOfMin = outOfMin;
  this.outOfMax = outOfMax;
  this.width1 = width1;
  this.width2 = width2;
  this.width3 = width3;
  this.width4 = width4;
  this.width5 = width5;
  //설정될 수 있는 최소값
  this.vMin = vMin;
  //설정될 수 있는 최대값
  this.vMax = vMax;
  //총길이
  this.totalWidth = totalWidth;
  //최소값의 현재 x 좌표
  this.minCurrPos = width1;
  //최대값의 현재 x 좌표
  this.maxCurrPos = width1 + width2 + width3;
  //이전에 설정된 최소값
  this.vPastMin = vMin;
  //이전에 설정된 최대값
  this.vPastMax = vMax;
  //유효 최소값
  this.validMin = validMin;
  //유효 최대값
  this.validMax = validMax;
  //바의 좌우 여백 길이
  this.spaceWidth = spaceWidth;
  //컨트롤 비활성화시 덮는 덮개
  this.cover = cover;
  
  this.getRoot = getRoot;
  this.getWidth1 = getWidth1;
  this.getWidth2 = getWidth2;
  this.getWidth3 = getWidth3;
  this.getWidth4 = getWidth4;
  this.getWidth5 = getWidth5;
  this.setWidth1 = setWidth1;
  this.setWidth3 = setWidth3;
  this.setWidth5 = setWidth5;
  this.getVMin = getVMin;
  this.getVMax = getVMax;
  this.getTotalWidth = getTotalWidth;
  this.getMaxPos1 = getMaxPos1;
  this.getMinPos1 = getMinPos1;
  this.getMaxPos2 = getMaxPos2;
  this.getMinPos2 = getMinPos2;
  this.adjustPosByMin = adjustPosByMin;
  this.adjustPosByMax = adjustPosByMax;
  //화면상에서 길이를 값으로 환산한다.
  this.convertValToLen = convertValToLen;
  //값을 화면상의 길이로 환산한다.
  this.convertLenToVal = convertLenToVal;
  //마우스 드래그에 bar의 색상 조절
  this.adjustBarColor  = adjustBarColor;
  //최소값을 직접입력했을 때 슬라이더 처리
  this.adjustMinPosByText = adjustMinPosByText;
  //최대값을 직접입력했을 때 슬라이더 처리
  this.adjustMaxPosByText = adjustMaxPosByText;
  //변경되기 전의 최소값을 설정
  this.setVPastMin = setVPastMin;
  //변경되기 전의 최대값을 설정
  this.setVPastMax = setVPastMax;
  //컨트롤을 화면에 뿌린다
  this.paintControl = paintControl;
  //바가 음의 무한대 영역에 있는지 체크
  this.checkMinusInfinity = checkMinusInfinity;
  //바가 양의 무한대 영역에 있는지 체크
  this.checkFlusInfinity = checkFlusInfinity;
  //값들의 가중치 적용. 기본은 모든 값이 균일함
  this.applyWeight = applyWeight;
  //값들의 가중치 역적용. 기본은 모든 값이 균일함
  this.reverseApplyWeight = reverseApplyWeight;
  //컨트롤을 비활성화 시킨다
  this.disableControl = disableControl;
  //컨트롤을 활성화 시킨다.
  this.enableControl = enableControl;
}

function getRoot() { return this.root; }
function getWidth1() { return this.width1; }
function getWidth2() { return this.width2; }
function getWidth3() { return this.width3; }
function getWidth4() { return this.width4; }
function getWidth5() { return this.width5; }
function setWidth1(v) { this.width1 = v; }
function setWidth3(v) { this.width3 = v; }
function setWidth5(v) { this.width5 = v; }
function getVMin() { return this.vMin; }
function getVMax() { return this.vMax; }
function getValidMin() { return this.validMin; }
function getValidMax() { return this.validMax; }
function getTotalWidth() { return this.totalWidth; }
//최소값을 정하는 눈금자가 움직일 수 있는 최저값
function getMinPos1() { return 0; }
//최소값을 정하는 눈금자가 움직일 수 있는 최고값
function getMaxPos1() { return this.totalWidth - this.width2 - this.width4 - this.width5; }
//최대값을 정하는 눈금자가 움직일 수 있는 최저값
function getMinPos2() { return this.width1; }
//최대값을 정하는 눈금자가 움직일 수 있는 최고값
function getMaxPos2() { return this.totalWidth - this.width2 - this.width4; }
function adjustPosByMin(v) { 
  this.width1 = v;
  this.width3 = this.totalWidth - this.width1 - this.width2 - this.width4 - this.width5;
}
function adjustPosByMax(v) { 
  this.width5 = -v;
  this.width3 = this.totalWidth - this.width1 - this.width2 - this.width4 - this.width5;
}
function convertValToLen(v) {
  v = (parseInt(v) - parseInt(this.vMin)) * (this.totalWidth - this.width2 - this.width4) / (this.vMax - this.vMin);
  return Math.round(v);
}
function convertLenToVal(l) {
  l = l * (this.vMax - this.vMin) / (this.totalWidth - this.width2 - this.width4) + this.vMin;
  return Math.round(l);
}
function adjustBarColor() {
  document.getElementById(this.outOfMin).style.width = this.width1;
  document.getElementById(this.outOfMax).style.width = this.width5;
}
function adjustMinPosByText(v, secondCondition) {

	v = this.reverseApplyWeight(v);

	if (secondCondition == null) {
	  if (v >= this.validMin && v <= this.validMax) {
	    tmp = this.convertValToLen(v);
	    document.getElementById(this.minBarId).style.left = tmp;
		document.getElementById(this.minTextBox).style.backgroundImage = ""
	    this.adjustPosByMin(tmp);
	    if (v > this.convertLenToVal(this.getMaxPos1())) {
	      document.getElementById(this.maxBarId).style.left = tmp - this.totalWidth + this.width2 + this.width4;
	      this.adjustPosByMax(tmp - this.totalWidth + this.width2 + this.width4);
	      document.getElementById(this.maxTextBox).value = document.getElementById(this.minTextBox).value;
	    }
	    this.adjustBarColor();
	    setVPastMin(v);
	  } else if (v < this.validMin) {
	    /*
		var msg = this.title + "(이)가 " + this.validMin + "보다 크거나 같고 " + this.validMax + "보다 작거나 같아야 합니다.";
	    alert(msg);
	    if (this.vPastMin != this.vMin)
	    	document.getElementById(this.minTextBox).value = this.vPastMin;
		*/
		document.getElementById(this.minBarId).style.left = 0;
		this.adjustPosByMin(0);
	    this.adjustBarColor();
	    setVPastMin(v);
	  } else if (v > this.validMax) {
		document.getElementById(this.maxBarId).style.left = 0;
		document.getElementById(this.maxTextBox).value = "+∞";
		this.adjustPosByMax(0);
		document.getElementById(this.minBarId).style.left = this.totalWidth - this.width2 - this.width4;
		this.adjustPosByMin(this.totalWidth - this.width2 - this.width4);
	    this.adjustBarColor();
	    setVPastMin(v);
	  } 
	} else {
		tmp = this.convertValToLen(v);
		document.getElementById(this.minBarId).style.left = tmp;
		this.adjustPosByMin(tmp);
		this.adjustBarColor();
		if (v == this.vMin) {
			document.getElementById(this.minTextBox).value = "-∞";
		} else {
			document.getElementById(this.minTextBox).style.backgroundImage = "";
		}
		setVPastMin(v);
	}
}
function adjustMaxPosByText(v, secondCondition) {

	v = this.reverseApplyWeight(v);

	if (secondCondition == null) {
	  if (v >= this.validMin && v <= this.validMax) {
	    tmp = this.convertValToLen(v);
	    document.getElementById(this.maxBarId).style.left = tmp - this.totalWidth + this.width2 + this.width4;
		document.getElementById(this.maxTextBox).style.backgroundImage = ""
	    this.adjustPosByMax(tmp - this.totalWidth + this.width2 + this.width4);
	    if (v < this.convertLenToVal(this.getMinPos2())) {
	      document.getElementById(this.minBarId).style.left = tmp;
	      this.adjustPosByMin(tmp);
	      document.getElementById(this.minTextBox).value = document.getElementById(this.maxTextBox).value;
	    }
	    this.adjustBarColor();
	    setVPastMax(v);
	  } else if (v > this.validMax) {

	    /*
		var msg = this.title + "(이)가 " + this.validMin + "보다 크거나 같고 " + this.validMax + "보다 작거나 같아야 합니다.";
	    alert(msg);
	    if (this.vPastMax != this.vMax)
	    	document.getElementById(this.maxTextBox).value = this.vPastMax;
		*/
		document.getElementById(this.maxBarId).style.left = 0;
		this.adjustPosByMax(0);
	    this.adjustBarColor();
	    setVPastMax(v);
	  } else if (v < this.validMin) {
		document.getElementById(this.minBarId).style.left = 0;
		document.getElementById(this.minTextBox).value = "-∞";
		this.adjustPosByMin(0);
		document.getElementById(this.maxBarId).style.left = -(this.totalWidth - this.width2 - this.width4);
		this.adjustPosByMax(-(this.totalWidth - this.width2 - this.width4));
	    this.adjustBarColor();
	    setVPastMax(v);
	  }
	} else {
		tmp = this.convertValToLen(v);
		document.getElementById(this.maxBarId).style.left = tmp - this.totalWidth + this.width2 + this.width4;
		this.adjustPosByMax(tmp - this.totalWidth + this.width2 + this.width4);
		this.adjustBarColor();
		if (v == this.vMax) {
			document.getElementById(this.maxTextBox).value = "+∞";
		} else {
			document.getElementById(this.maxTextBox).style.backgroundImage = "";
		}
		setVPastMax(v);
	}
}
function setVPastMin(v) {
  this.vPastMin = v;
}
function setVPastMax(v) {
  this.vPastMax = v;
}
function paintControl() {
  var control = "";

  control += "<table id=tbl2 width=" + this.totalWidth + " height=36 border=0 cellpadding=0 cellspacing=0>";
  control += "<tr><td width=22>&nbsp;</td>";
  control += "<td align=center>";
  control += "<input type=text name=" + this.minTextBox + " style=\"border:1 solid #babcb0;width:40px;height:17px;font-size:12px; text-align:center;\" onclick=\"this.style.backgroundImage='';\" onBlur=\"adjustSliderByText('" + this.minBarId + "', this);\">";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_char.gif\" hspace=\"5\" border=0>";
  control += "<font color=\"#993300\" style=\"font-size:14px;font-weight:bold\">" + this.title + "</font>";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_char.gif\" hspace=\"5\" border=0>";
  control += "<input type=text name=" + this.maxTextBox + " style=\"border:1 solid #babcb0;width:40px;height:17px;font-size:12px; text-align:center;\" onclick=\"this.style.backgroundImage='';\" onBlur=\"adjustSliderByText('" + this.maxBarId + "', this);\">";
  control += "</td>";
  control += "<td width=\"22\" valign=\"top\">";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_swh01.gif\" style=\"width:22; height:22; cursor:hand;\" vspace=\"8\" onclick=\"disableControl('" + this.cover + "');\" />";
  control += "</td>";
  control += "</tr>";
  control += "</table>";

  control += "<table border=0 width=290 height=20 bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\"><tr><td></td></tr></table>";

  control += "<table id=div1 width=" + this.totalWidth + " height=6 border=0 cellpadding=0 cellspacing=0  bgcolor-\"ffffff\" style=\"position:absolute; z-index:3; \">";
  control += "<tr height=6><td align=left>";
  control += "<img src=\"" + this.root + "/js/controls/images/space.gif\" border=0 style=\"height:6; width:10;\">";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_gauge_cover01.gif\" border=0 id=" + this.outOfMin + " style=\"height:6; width:0;\">";
  control += "</td></tr></table>";
  
  control += "<table id=div2 width=" + this.totalWidth + " height=6 border=0 cellpadding=0 cellspacing=0  bgcolor-\"ffffff\" style=\"position:absolute; z-index:2; \">";
  control += "<tr height=6><td align=right>";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_gauge_cover01.gif\" border=0 id=" + this.outOfMax + " style=\"height:6; width:0;\">";
  control += "<img src=\"" + this.root + "/js/controls/images/space.gif\" border=0 style=\"height:6; width:10; \">";
  control += "</td></tr></table>";	
  
  control += "<table id=tbl1 width=" + this.totalWidth + " border=0 cellpadding=0 cellspacing=0 bgcolor-\"ffffff\" style=\"position:absolute; z-index:4;\">";
  control += "<tr height=\"19\">";
  control += "<td bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\" width=0></td>";
  control += "<td bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\" width=" + this.width2 + ">";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_trg_left01.gif\" onclick=\"checkInfinity('" + this.minBarId + "');\" border=0 class=" + this.minBarId + " name=" + this.minBarId + " style=\"position:relative; cursor:hand;\"></td>";
  control += "<td bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\" width=250></td>";
  control += "<td bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\" width=" + this.width4 + ">";
  control += "<img src=\"" + this.root + "/js/controls/images/t_sch_trg_right01.gif\" onclick=\"checkInfinity('" + this.maxBarId + "');\" border=0 class=" + this.maxBarId + " name=" + this.maxBarId + " style=\"position:relative; cursor:hand;\"></td>";
  control += "<td bgcolor-\"ffffff\" style=\"filter:alpha(opacity=50)\" width=0></td>";
  control += "</tr></table>";
        

  document.write(control);
}
function checkMinusInfinity(temp, x) {
  var nos_pos = temp + event.clientX - x;
  var v = this.convertLenToVal(nos_pos);
  if (v < this.validMin) {
    document.getElementById(this.minBarId).style.left = 0;
    this.adjustPosByMin(0);
	document.getElementById(this.minTextBox).value = "-∞";
	this.adjustBarColor();
	setVPastMin(this.vMin);
  } 
}
function checkFlusInfinity(temp, x) {
  var nos_pos = temp + event.clientX - x  + this.totalWidth - this.width2 - this.width4;
  var v = this.convertLenToVal(nos_pos);
  if (v > this.validMax) {
    document.getElementById(this.maxBarId).style.left = 0;
    this.adjustPosByMax(0);
    document.getElementById(this.maxTextBox).value = "+∞";
    this.adjustBarColor();
    setVPastMax(v);
  }
}
function applyWeight(v) {
	if (v > this.validMax) {
		return "+∞";
	} else if (v < this.validMin) {
		return "-∞";
	} else {
		return v;
	}
}
function reverseApplyWeight(v) {
	return v;
}
function disableControl(objname) {
	document.getElementById(objname).style.display = "";
}
function enableControl(objname) {
	//nothing
}





