//-------------------------------------------------------------------------------------------------
//-- CLASS SLIDER CONTROL - Coded by Lugital.com
//-------------------------------------------------------------------------------------------------
//-- HTML Requirement:
//-- <input id='sliderText' name='sliderText' value='' onchange='pSlider.TextOnChange();' onkeyup='pSlider.TextOnKeyUp();'><br>
//-- <div id='sliderScroll' style='width:300px;height:30px;overflow-x:scroll;overflow-y:hidden;' onscroll="pSlider.OnScroll();">
//-- <img id='sliderImage' src='admin/img/spacer.gif' style='width:1px;height:1px;border:0px'></div>
//-- Code: pSlider = new FormSlider('slider', 300, 1000, 100000, 1000, true);
//-------------------------------------------------------------------------------------------------
function FormSlider(inID, inScrollWidth, inMin, inMax, inStep, inIsLockRange) {
	this.ObjText = this.GetObject(inID + 'Text');
	this.ObjScroll = this.GetObject(inID + 'Scroll');
	this.ObjImage = this.GetObject(inID + 'Image');
	this.Min = inMin;
	this.Max = inMax;
	this.Step = inStep;
	if (inIsLockRange == false) { this.IsLockRange = false; }
	this.ObjScroll.style.width = inScrollWidth;
	if (inStep > 0) { this.Step = inStep; } else { this.Step = 1; }
	var pDec = new String(String(this.Step));
	var pDotLoc = pDec.indexOf('.');
	if (pDotLoc != -1) { this.Decimal = pDec.length - pDotLoc -1; } else { this.Decimal = 0; }
	this.Init(true);
}
	FormSlider.prototype.Init = function(inSetScroll) {	
		this.RealMax = (this.Max - this.Min) / this.Step;
		this.RealMax = this.RealMax * 10; // ADD Resolution
		this.ObjImage.style.width = (parseInt(this.ObjScroll.style.width) + this.RealMax);
		this.SetScroll(this.ObjText.value, inSetScroll);
	}
	// PROPERTY
	FormSlider.prototype.ObjText;
	FormSlider.prototype.ObjScroll;
	FormSlider.prototype.ObjImage;
	FormSlider.prototype.Min;
	FormSlider.prototype.Max;
	FormSlider.prototype.RealMax;
	FormSlider.prototype.Step;
	FormSlider.prototype.Decimal;
	FormSlider.prototype.IsLockRange = true;
	// METHOD
	FormSlider.prototype.GetObject = function(inID) { if (document.getElementById) { return top.document.getElementById(inID); } else if (document.all) {	return top.document.all[inID]; } else {	return null; } }
	FormSlider.prototype.GetValue = function() { return this.ObjText.value;	}	
	FormSlider.prototype.SetValue = function(inValue) { this.ObjText.value = inValue; this.SetScroll(inValue);	}	
	FormSlider.prototype.SetMax = function(inValue) { if (inValue != this.Max) { this.Max = new Number(inValue); this.Init(); } }
	FormSlider.prototype.OnScroll = function() {
		var pValue = new Number(((this.ObjScroll.scrollLeft * (this.Max - this.Min)) / this.RealMax) + this.Min);
		var pMulti = Math.round(pValue / this.Step);
		pValue = this.Step * pMulti;
		pValue = pValue.toFixed(this.Decimal);
		this.ObjText.value = pValue;
	}
	FormSlider.prototype.SetScroll = function(inValue, inSetScroll) {
		var pInValue = new Number(parseFloat(inValue))
		pInValue = pInValue.toFixed(this.Decimal);
		if (this.IsLockRange == true) {
			pCheckMultiple = pInValue / this.Step; pCheckMultiple = pCheckMultiple.toString()
			if (pCheckMultiple.indexOf('.') != -1) { // Not a Multiple of Slider Step
				pInValue = Math.round(pInValue); 
				pInValue = pInValue.toFixed(this.Decimal);
			}
			if (pInValue < this.Min || pInValue == 'NaN') { pInValue = this.Min.toFixed(this.Decimal); }
			if (pInValue > this.Max) { pInValue = this.Max.toFixed(this.Decimal); }
		}
		this.ObjText.value = pInValue;
		var pValue = (((pInValue - this.Min) * this.RealMax) / (this.Max - this.Min));
		if (this.IsLockRange == true || inSetScroll == true) { this.ObjScroll.scrollLeft = pValue; }
	}	
	FormSlider.prototype.TextOnChange = function () {
		this.SetScroll(this.ObjText.value, true);
	}
	FormSlider.prototype.TextOnKeyUp = function() { 
		if (event.keyCode == 13 ) { this.SetScroll(this.ObjText.value, true); } 
	}
// END CLASS SLIDER CONTROL
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//-- CLASS ARROW BOX CONTROL - Coded by Lugital.com
//-------------------------------------------------------------------------------------------------
//-- HTML Requirement:
//-- <input id='aboxText' name='aboxText' value='' onchange='pSlider.TextOnChange();' onkeyup='pSlider.TextOnKeyUp();'><br>
//-- Code: pABox = new FormArrowBox('abox', 1000, 100000, 1000, true);
//-------------------------------------------------------------------------------------------------
var gFormArrowBoxTimer = null;
var gFormArrowBoxObj = null;
function FormArrowBox(inID, inMin, inMax, inStep, inIsLockRange) {
	this.ObjText = this.GetObject(inID + 'Text');
	this.Min = inMin;
	this.Max = inMax;
	this.Step = inStep;
	if (inIsLockRange == false) { this.IsLockRange = false; }
	if (inStep > 0) { this.Step = inStep; } else { this.Step = 1; }
	var pDec = new String(String(this.Step));
	var pDotLoc = pDec.indexOf('.');
	if (pDotLoc != -1) { this.Decimal = pDec.length - pDotLoc -1; } else { this.Decimal = 0; }
	this.Init();
}
	FormArrowBox.prototype.Init = function() {	

	}
	// PROPERTY
	FormArrowBox.prototype.ObjText;
	FormArrowBox.prototype.Min;
	FormArrowBox.prototype.Max;
	FormArrowBox.prototype.Step;
	FormArrowBox.prototype.Decimal;
	FormArrowBox.prototype.IsLockRange = true;
	FormArrowBox.prototype.State = 0; // 0 = Normal, 1 = Count Up, 2 = Count Down
	// METHOD
	FormArrowBox.prototype.GetObject = function(inID) { if (document.getElementById) { return top.document.getElementById(inID); } else if (document.all) {	return top.document.all[inID]; } else {	return null; } }
	FormArrowBox.prototype.GetValue = function() { return new Number(this.ObjText.value);	}	
	FormArrowBox.prototype.SetMax = function(inValue) { if (inValue != this.Max) { this.Max = new Number(inValue); this.Init(); } }
	FormArrowBox.prototype.SetValue = function(inValue) {
		var pInValue = new Number(parseFloat(inValue))
		pInValue = pInValue.toFixed(this.Decimal);
		if (this.IsLockRange == true) {
			/*pCheckMultiple = pInValue / this.Step; pCheckMultiple = pCheckMultiple.toString()
			if (pCheckMultiple.indexOf('.') != -1) { // Not a Multiple of Slider Step
				pInValue = Math.round(pInValue); 
				pInValue = pInValue.toFixed(this.Decimal);
			}*/
			if (pInValue > this.Max) { pInValue = this.Max.toFixed(this.Decimal); }
		}
		if (pInValue < this.Min || pInValue == 'NaN') { pInValue = this.Min.toFixed(this.Decimal); }
		this.ObjText.value = pInValue;
	}
	FormArrowBox.prototype.UpOnMouseDown = function () { 
		this.State = 1;
		gFormArrowBoxObj = this;
		clearTimeout(gFormArrowBoxTimer);
		gFormArrowBoxTimer = setTimeout(gFormArrowBoxObj.TimerTick, 500);
	}	
	FormArrowBox.prototype.TimerTick = function () { 
		if (gFormArrowBoxObj.State == 1) {
			gFormArrowBoxObj.SetValue(gFormArrowBoxObj.GetValue() + gFormArrowBoxObj.Step);
			gFormArrowBoxTimer = setTimeout(gFormArrowBoxObj.TimerTick, 50);
		} else if (gFormArrowBoxObj.State == 2) {
			gFormArrowBoxObj.SetValue(gFormArrowBoxObj.GetValue() - gFormArrowBoxObj.Step);
			gFormArrowBoxTimer = setTimeout(gFormArrowBoxObj.TimerTick, 50);			
		} else {
			clearTimeout(gFormArrowBoxTimer);
		}
	}	
	FormArrowBox.prototype.UpOnMouseUp = function () { this.State = 0;this.SetValue(this.GetValue() + this.Step);this.ObjText.onchange(); }	
		FormArrowBox.prototype.UpOnMouseOut = function () { this.State = 0;this.ObjText.onchange();	}		
	FormArrowBox.prototype.DownOnMouseDown = function () { 
		this.State = 2;
		gFormArrowBoxObj = this;
		clearTimeout(gFormArrowBoxTimer);
		gFormArrowBoxTimer = setTimeout(gFormArrowBoxObj.TimerTick, 500);
	}		
	FormArrowBox.prototype.DownOnMouseUp = function () { this.State = 0;this.SetValue(this.GetValue() - this.Step);this.ObjText.onchange(); }	
		FormArrowBox.prototype.DownOnMouseOut = function () { this.State = 0;this.ObjText.onchange(); }			
	FormArrowBox.prototype.TextOnChange = function () {	this.SetValue(this.ObjText.value); }
	FormArrowBox.prototype.TextOnKeyUp = function() { if (event.keyCode == 13 ) { this.SetValue(this.ObjText.value); } }
// END CLASS ARROW BOX CONTROL
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
//-- CLASS LOAN CALCULATOR - Coded by Lugital.com
//-- Code:
//-- pLoan = new LoanCalculator(110000, 10000, 5.0, 25);
//-- pLoan.SetBiWeekly();
//-- pPayment = pLoan.GetPayment();
//-------------------------------------------------------------------------------------------------
function LoanCalculator(inValue, inCashDown, inRate, inYear) {
	this.Value = inValue;
	this.CashDown = inCashDown;
	this.Rate = inRate;
	this.Year = inYear;
}
	// PROPERTY
	LoanCalculator.prototype.Value = 0; // Loan Amount
	LoanCalculator.prototype.CashDown = 0; // Cash Down 
	LoanCalculator.prototype.Loan = 0; // Loan Value 
	LoanCalculator.prototype.Rate = 0.00; // Interest rate (ie 5.45)
	LoanCalculator.prototype.Year = 0; // Num of Year
	LoanCalculator.prototype.PayType = 1; // 1:Monthly 2:Semi-Monthly 3:Bi-Weekly 4:Weekly
	// METHOD	
	LoanCalculator.prototype.SetMonthly = function() { this.PayType = 1; }
	LoanCalculator.prototype.SetSemiMonthly = function() { this.PayType = 2; }
	LoanCalculator.prototype.SetBiWeekly = function() { this.PayType = 3; }
	LoanCalculator.prototype.SetWeekly = function() { this.PayType = 4; }
	LoanCalculator.prototype.GetPayment = function() {
		this.Loan = this.GetLoan();
		pNumOfPayment = 0;
		pPayByYear = 0;
		switch (this.PayType){	
			case 1: pPayByYear = 12; pNumOfPayment = this.Year * pPayByYear; break; // Monthly
			case 2: pPayByYear = 24; pNumOfPayment = this.Year * pPayByYear; break; // Semi-Monthly
			case 3: pPayByYear = 26; pNumOfPayment = this.Year * pPayByYear; break; // Bi-Weekly
			case 4: pPayByYear = 52; pNumOfPayment = this.Year * pPayByYear; break; // Weekly
		}
		pRate = this.Rate / 100.0;
		pRate = Math.pow( Math.pow( (1.00 + pRate / 2), 2), (1.00 / pPayByYear) ) - 1;
	  pPaymentFloat = this.Loan * pRate / (1.00 - Math.pow((1 + pRate), 0.00 - pNumOfPayment));
	  if (pPaymentFloat < 0) { pPaymentFloat = 0.00; }
	  pPayment = new Number(pPaymentFloat).toFixed(2);
		return pPayment;
	}
	LoanCalculator.prototype.GetLoan = function() { 
		pLoan = this.Value - this.CashDown;
		if (pLoan == 'NaN') { pLoan = 0; }
		if (pLoan < 0) { pLoan = 0; }
		return pLoan
	}
	LoanCalculator.prototype.GetCashPercent = function() { 
		pPercent = pPercent = (this.CashDown * 100) / this.Value;
		if (pPercent > 100) { pPercent = 100; }
		return pPercent.toFixed(2);
	}
// END CLASS LOAN CALCULATOR
//-------------------------------------------------------------------------------------------------