
/**
 * BEKB|BCBE Mortgage Calculator
 * Copyright November 2007 by Unic Internet Solutions
 * 
 * Provides the core functionality for the calculator
 * 
 *
 * @class
 * This class represents a form instance on the
 * server side. It holds the current form or current step
 * respectively with all its attributes and properties.<br/>
 * Additionally it provides all necessary helper 
 * methods for the server side handling of forms.
 *
 * @author AlR
 * @version 1.0
 */
function MortgageCalculator() {}

/**
 * Returns an object containing all the calculation results.
 *
 * @param {Object} oInputValues all the input values needed for the calculations
 * <pre>
 *	{
 *		Price : &lt;Integer&gt;,
 *		Equity : &lt;Integer&gt;,
 *		Income : &lt;Integer&gt;,
 *		ObjectType : &lt;Integer&gt;
 *	}
 *	</pre>
 *
 * @return the result object
 * <pre>
 *	{
 *		monthlyChargeCalculatory : &lt;Integer&gt;,
 *		monthlyChargeMinimum : &lt;Integer&gt;,
 *		mortgageInterest : &lt;Integer&gt;,
 *		monthlyAmortisation : &lt;Integer&gt;,
 *		runningCosts : &lt;Integer&gt;,
 *		chargeBoundary : &lt;Integer&gt;,
 *		percentageOfIncome : &lt;Float&gt;,
 *		mortgageAmount : &lt;Integer&gt;
 *	}
 * </pre>
 * @type Object
 */
MortgageCalculator.getResult = function(oInputValues){
	var iMonthlyChargeCalculatory = 
		this.getMonthlyCharge(
			MortgageCalculator.Constants.fINTEREST_RATE_CALCULATORY,
			MortgageCalculator.Constants.fINTEREST_RATE_CALCULATORY,
			oInputValues.ObjectType,
			oInputValues.Price,
			oInputValues.Equity
		);
	return {
		monthlyChargeCalculatory : iMonthlyChargeCalculatory,
		monthlyChargeMinimum : 
			this.getMonthlyCharge(
				MortgageCalculator.Constants.fINTEREST_RATE_MINIMUM,
				MortgageCalculator.Constants.fINTEREST_RATE_SECOND,
				oInputValues.ObjectType,
				oInputValues.Price,
				oInputValues.Equity
			),
		mortgageInterest : this.getMortgageInterest(oInputValues.Price, oInputValues.Equity),
		monthlyAmortisation : this.getMonthlyAmortisation(oInputValues.Price, oInputValues.Equity),
		runningCosts : this.getRunningCosts(oInputValues.ObjectType, oInputValues.Price),
		chargeBoundary : this.getChargeBoundary(oInputValues.Income / 12.0),
		percentageOfIncome : this.getRoundedPercentage(oInputValues.Income / 12.0, iMonthlyChargeCalculatory),
		mortgageAmount : this.getMortgageAmount(oInputValues.Price, oInputValues.Equity)
	}
}


/* CALCULATIONS */

/**
 * Returns the calculated monthly charge.
 * 
 * @param {Float} fInterestRateFirst the first hypo interest rate used for the calculation (either calculatory or minimal)
 * @param {Float} fInterestRateSecond the second hypo interest rate used for the calculation (either calculatory or minimal)
 * @param {String} sObjectType the type of the object type
 * @param {Integer} iPrice the price of the object
 * @param {Integer} iEquity the equity of the requesting person
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getMonthlyCharge = function(fInterestRateFirst, fInterestRateSecond, sObjectType, iPrice, iEquity) {
	var fCharge;
	var fAmortisation = MortgageCalculator.getAmortisationFull(iPrice, iEquity);
	if (fAmortisation > 0){
		fCharge = 
			(iPrice * MortgageCalculator.Constants.fINTEREST_RATE_AMORTISATION * fInterestRateFirst / 12.0)
			+ (
				(iPrice - iEquity - iPrice * MortgageCalculator.Constants.fINTEREST_RATE_AMORTISATION)
				* fInterestRateSecond
			) / 12
			+ MortgageCalculator.getMonthlyAmortisation(iPrice, iEquity) 
			+ MortgageCalculator.getRunningCosts(sObjectType, iPrice);
	}
	else{
		fCharge = 
			((iPrice - iEquity) * fInterestRateFirst / 12.0)
			+ MortgageCalculator.getMonthlyAmortisation(iPrice, iEquity) 
			+ MortgageCalculator.getRunningCosts(sObjectType, iPrice);
	}
	
	return Math.round(fCharge);
}

/**
 * Returns the calculated mortgage interest rate.
 * 
 * @param {Integer} iPrice the price of the object
 * @param {Integer} iEquity the equity of the requesting person
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getMortgageInterest = function(iPrice, iEquity){
	return Math.round( this.getMortgageAmount(iPrice, iEquity) * MortgageCalculator.Constants.fINTEREST_RATE_CALCULATORY / 12.0 );
}

/**
 * Returns the calculated monthly amortisation.
 * 
 * @param {Integer} iPrice the price of the object
 * @param {Integer} iEquity the equity of the requesting person
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getMonthlyAmortisation = function(iPrice, iEquity){
	var fAmortisation = MortgageCalculator.getAmortisationFull(iPrice, iEquity);
	if (fAmortisation > 0){
		fAmortisation = fAmortisation / 15.0 / 12.0;
	}
	else{
		fAmortisation = 0;
	}
	
	return Math.round(fAmortisation);
}

/**
 * Returns the calculated running costs.
 * 
 * @param {String} sObjectType the type of the object type
 * @param {Integer} iPrice the price of the object
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getRunningCosts = function(sObjectType, iPrice){
	var iInterestRate;
	// force to numeric type, otherwise switch won't work
	sObjectType *= 1;
	switch(sObjectType){
		case MortgageCalculator.Constants.ObjectType.Minergie:
			iInterestRate = MortgageCalculator.Constants.fINTEREST_RATE_MINERGIE;
		break;
		case MortgageCalculator.Constants.ObjectType.NewBuilding:
			iInterestRate = MortgageCalculator.Constants.fINTEREST_RATE_NEW_BUILDING;
		break;
		case MortgageCalculator.Constants.ObjectType.OldBuilding:
			iInterestRate = MortgageCalculator.Constants.fINTEREST_RATE_OLD_BUILDING;
		break;
	}
	//alert(iInterestRate);
	return Math.round(iPrice * iInterestRate / 12.0);
}

/**
 * Returns the calculated charge boundary.
 * 
 * @param {Integer} iIncome the income of the requesting person
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getChargeBoundary = function(iIncome){
	return Math.round(iIncome * MortgageCalculator.Constants.fINTEREST_RATE_CHARGE_BOUNDARY);
}

/**
 * Returns the calculated mortgage amount.
 * 
 * @param {Integer} iPrice the price of the object
 * @param {Integer} iEquity the equity of the requesting person
 *
 * @return the calculated value
 * @type Integer
 *
 * @private
 */
MortgageCalculator.getMortgageAmount = function(iPrice, iEquity){
	return iPrice - iEquity;
}


/* HELPERS */

/**
 * Returns the full amortisation amount without any deduction.
 * 
 * @param {Integer} iPrice the price of the object
 * @param {Integer} iEquity the equity of the requesting person
 *
 * @return the calculated value
 * @type Float
 *
 * @private
 */
MortgageCalculator.getAmortisationFull = function(iPrice, iEquity){
	var fPriceEquity = iPrice - iEquity;
	var fPricePart = iPrice * MortgageCalculator.Constants.fINTEREST_RATE_AMORTISATION;
	var fAmortisation = fPriceEquity - fPricePart;
	return fAmortisation;
}

/**
 * Returns a rounded percentage value rounded to 2 decimal parts (xx.xx).
 * 
 * @param {Float} fFirst the first original value
 * @param {Float} fSecond the second value to be taken into percentage
 *
 * @return the calculated value
 * @type Float
 *
 * @private
 */
MortgageCalculator.getRoundedPercentage = function(fFirst, fSecond){
	iDecimalPointsFactor = Math.pow(10, MortgageCalculator.Constants.iPERCENT_DECIMAL_POINTS) * 1.0;	

	if (fFirst == 0 || fSecond == 0){
		return 0;
	}
	var fPercentage = 100.0 / fFirst * fSecond;
	return Math.round(fPercentage * iDecimalPointsFactor) / iDecimalPointsFactor;
}


/* GUI */


/**
 * Returns the position of the charge boundary line in percent (xx.xx). Minimum value is
 * the offset of the bar from top and maximum value is the height of the bar
 * 
 * @param {Float} fPercentage (in % form, i.e. xx.xx)
 *
 * @return the calculated value
 * @type Float
 */
MortgageCalculator.getChargeLinePosition = function(fPercentage){
	var iPosition = Math.round(MortgageCalculator.Constants.iBOUNDARY_LINE_POSITION / 
				(100 - 100.00 * MortgageCalculator.Constants.fINTEREST_RATE_CHARGE_BOUNDARY) * Math.max(100 - fPercentage, 1));
	
	// lower part needs to be scaled (below charge bounday)
	var fPercentageDecimal = fPercentage / 100.0;
	if (fPercentageDecimal < MortgageCalculator.Constants.fINTEREST_RATE_CHARGE_BOUNDARY){
		var iRestHeight = MortgageCalculator.Constants.iBAR_HEIGHT - MortgageCalculator.Constants.iBOUNDARY_LINE_POSITION;
		
		iPosition = iPosition + 
			(iRestHeight / MortgageCalculator.Constants.fINTEREST_RATE_CHARGE_BOUNDARY *
				(MortgageCalculator.Constants.fINTEREST_RATE_CHARGE_BOUNDARY - fPercentageDecimal));
	}
	
	return Math.min(
		MortgageCalculator.Constants.iBAR_HEIGHT + MortgageCalculator.Constants.iCHARGE_LINE_OFFSET - 40, 
		Math.max(
			MortgageCalculator.Constants.iCHARGE_LINE_OFFSET, 
			iPosition
		)
	);
}

/**
 * Returns the position of the background image for the output fields in percent (xx.xx). 
 * Minimum value is 1% and maximum value is 99%, as borders of scaled image are not clean.
 * 
 * @param {Float} fPercentage (in % form, i.e. xx.xx)
 *
 * @return the calculated value
 * @type Float
 */
MortgageCalculator.getColorBackgroundPosition = function(fPercentage){
	var iPositionBar = this.getChargeLinePosition(fPercentage) - MortgageCalculator.Constants.iCHARGE_LINE_OFFSET;
	return ( 
		Math.min(
			99,
			Math.max(
				1,
				100.0 /MortgageCalculator.Constants.iBAR_HEIGHT * iPositionBar
			)
		)
	);
}

/* GUI HELPERS */


/**
 * Returns the sanitized string as number, i.e. removes all non-numeric parts.
 * 
 * @param {String} sNumber any input string
 *
 * @return the sanitized number
 * @type Float
 *
 * @private
 */
MortgageCalculator.getSanitizedNumber = function(sNumber){
	sNumber = (sNumber || "").toString();
	// remove leading 0's
	sNumber = sNumber.replace(/^0*/, '').replace(/([\.,].+)/, '');
	// remove all non-digits
	return sNumber? sNumber.replace(/\D/g, '') : "0";
}


/**
 * Returns the formatted number as a string, i.e. x'xxx.xx 
 * 
 * @param {String} sNumber a number, with allowed parts '-', '.'
 *
 * @return the formatted number
 * @type Float
 *
 * @private
 */
MortgageCalculator.getFormattedNumber = function(sInputNumber){
	sInputNumber = (sInputNumber || "").toString();
	if (sInputNumber){
		// split by decimal point
		var bHasSign = sInputNumber.indexOf('-') == 0;
		var asNumberSplit = sInputNumber.split('.');
		sInputNumber = asNumberSplit[0].replace(/^-/, ''); // remove sign
		for (var i = 0; i < Math.floor((sInputNumber.length - (1 + i)) / 3); ++i){
			sInputNumber = sInputNumber.substring(0, sInputNumber.length - (4 * i + 3)) 
				+ "'" + sInputNumber.substring(sInputNumber.length - (4 * i + 3));
		}
		
		// add decimal part
		if (asNumberSplit[1]){
			sInputNumber += '.' + asNumberSplit[1];
		}
		// add sign
		if (bHasSign){
			sInputNumber = '-' + sInputNumber;
		}
	}
	else{
		sInputNumber = "0";
	}
	return sInputNumber;
}


MortgageCalculator.getUrlParameter = function(){
	var sQuery = "";
	
	for (var item in request) {
		if (item != "aktion" && item != "action" && item != "mode" &&  item != "session") {
			sQuery += "&" + escape(item) + "=" + escape(request[item]);
		}
	}
	
	return sQuery;
}



/* CLIENTSIDE GUI FUNCTIONS */

/**
 * Initializes the calculator gui, i.e. sets default values
 * and sets the right part to "start" state.
 */
MortgageCalculator.init = function() {	
	// hide no javascript warning
	$('no-js-layer').style.display = 'none';
	
	$('income').value = this.getFormattedNumber(
		MortgageCalculator.Constants.iDEFAULT_INCOME);
	$('equity').value = this.getFormattedNumber(
		MortgageCalculator.Constants.iDEFAULT_EQUITY);
	$('price').value = this.getFormattedNumber(
		MortgageCalculator.Constants.iDEFAULT_PRICE);
	
	// set object type radiobutton
	$('objectType' + MortgageCalculator.Constants.iDEFAULT_OBJECT_TYPE).checked = true;
	
	// set focus
	//$('price').focus();
	//$('price').select();
	
	// set init class to output region
	$('calculator').addClassName('start');
	
	// hide warning
	$('equityWarning').style.display = "none";
	
	this.calculate();
	
	// if print medium
	if (document.URL.match(/\/print\//)){
		window.print();
	}
}

/**
 * Performs an update of the calculation from a
 * specific single changed element value.
 * 
 * @param {Object} the dom element
 */
MortgageCalculator.updateResultFromElement = function(element){
	this.sanitizeNumber(element);
	this.formatNumber(element);
	
	this.calculate();
	
	// cleanup vars in timeout variables in Rules
	delete Rules.timeoutElement;
	delete Rules.timeoutTime;
}

/**
 * Performs an update of the calculation in respect to all
 * the input values.
 */
MortgageCalculator.calculate = function() {
	try{
		// only make the actual calculation if no value is zero
		if (!$('calculator').hasClassName('start') ||
			($('income').value != '0' && 
			 $('equity').value != '0' && 
			 $('price').value != '0')){

			// remove init class
			$('calculator').removeClassName('start');
						
			this.setResult();
		}
	}
	catch (e){
		//TODO
		alert("exception in calculate //" + e.name + "//" + e.code 
			+ "//" + e.message + "//" + e.lineNumber + "//" + e.stack);
	}
}

/**
 * Performs an update of the values of a specific elments value. This function
 * does not perform an updated calculation, it only sets the values to the gui.
 * 
 * @param {String} sElementName the elements name
 * @param {String} sMode the mode of the adjustment, either one of the
 * following values:
 * <ul>
 * <li>m: single decrease</li>
 * <li>mm: factorised decrease</li>
 * <li>p: single increase</li>
 * <li>pp: factorised decrease</li>
 * </ul>
 */
MortgageCalculator.adjustValue = function(sElementName, sMode){
	var oElement = $(sElementName);
	this.sanitizeNumber(oElement);
	var iStep = MortgageCalculator.Constants['iSTEP_' + sElementName.toUpperCase()];
	
	switch(sMode){
		case 'm': 
			oElement.value = oElement.value * 1 - iStep;
		break;
		case 'mm': 
			oElement.value = oElement.value * 1 - iStep * MortgageCalculator.Constants.iSTEP_FACTOR_BIG_STEP;
		break;
		case 'p': 
			oElement.value = oElement.value * 1 + iStep;
		break;
		case 'pp': 
			oElement.value = oElement.value * 1 + iStep * MortgageCalculator.Constants.iSTEP_FACTOR_BIG_STEP;
		break;
	}
}

/**
 * Performs the calculation and sets all result values.
 * 
 * @private
 */
MortgageCalculator.setResult = function() {
	try{

		// prepare calculation values
		var oInputValues = {
			Price : this.getSanitizedNumber($('price').value),
			Equity : this.getSanitizedNumber($('equity').value),
			Income : this.getSanitizedNumber($('income').value),
			// get checked radiobutton value
			ObjectType : this.getObjectTypeValue()
		};
		
		// set results to gui
		var oResult = this.getResult(oInputValues);
		for (var oResultKey in oResult){
			var oElement = $(oResultKey);
			if (oElement){
				var sValue = this.getFormattedNumber(oResult[oResultKey]);
				
				// duplicate value fields
				if (oResultKey == 'monthlyChargeCalculatory'){	
					$(oResultKey + '2').innerHTML = sValue + ',-';
				}
				else if(oResultKey == 'percentageOfIncome'){
					$(oResultKey + '2').innerHTML = sValue + '%';
				}
				
				// append unit identifier
				switch(oResultKey){
					case 'mortgageAmount':
					case 'chargeBoundary':
						sValue += ',-';
					break;
					case 'percentageOfIncome':
						sValue += '%';
					break;
					default:
						sValue += ' CHF';
				}
				
				$(oResultKey).innerHTML = sValue;
				
			}
			//else ERROR todo
		}
		
		// adjust the bar
		var iLinePosition = this.getChargeLinePosition(oResult.percentageOfIncome);
		
		var iLineDistance = iLinePosition - MortgageCalculator.Constants.iBOUNDARY_LINE_POSITION;
		
		if (Math.abs(iLineDistance) < MortgageCalculator.Constants.iMINIMUM_LINE_DISTANCE){			
			var iLineSpacing = MortgageCalculator.Constants.iMINIMUM_LINE_DISTANCE - Math.abs(iLineDistance);
			
			if (iLineDistance > 0){
				$$('#slider_tragbarkeit .slider .slider_r')[0].style.height = iLineSpacing + 'px';
				var oChargeLineElement = $('slider_tragbarkeit');
				
				oChargeLineElement.style.top = 
					(MortgageCalculator.Constants.iBOUNDARY_LINE_POSITION - iLineSpacing) + 'px';
				
				// set charge to default
				this.resetSliderCharge();
			}
			else {
				$$('#slider_belastung .slider .slider_r')[0].style.height = iLineSpacing + 'px';
				iLinePosition = iLinePosition - iLineSpacing;
				
				// set boundary to default
				this.resetSliderBoundary();
			}
		}
		else {
			this.resetSliderBoundary();
			this.resetSliderCharge();
		}
		
		$('slider_belastung').style.top = iLinePosition + 'px';
		
		
		// set the output field background
		var iBackgroundPosition = this.getColorBackgroundPosition(oResult.percentageOfIncome);
		$$('.resultBackground').each(function(el){
			el.style.backgroundPosition = "0% " + iBackgroundPosition + "%";
		});
			
			
		//show warning if equity below 20% of price
		if (oInputValues.Equity / oInputValues.Price < 0.2){
			$('equityWarning').style.display = "block";
		}
		else {
			$('equityWarning').style.display = "none";
		}
				
		// set output field style to positive / negative
		var oPositiveNegativeElements = $$('ul.negative', 'ul.positive');
		if (oResult.percentageOfIncome < 
				MortgageCalculator.Constants.iNEGATIVE_POSITIVE_BOUNDARY &&
			oResult.percentageOfIncome > 15
				){
			oPositiveNegativeElements[0].className = 'positive';
		}
		else{
			oPositiveNegativeElements[0].className = 'negative';
		}
	
	}
	catch (e){
		/*alert("exception in setResult //" + e.name + "//" + e.code 
			+ "//" + e.message + "//" + e.lineNumber + "//" + e.stack);*/
	}
}


/* CLIENTSIDE GUI HELPERS */


/**
 * Gets the domain of the current page.
 * 
 * @return the domain
 * @type String
 */
MortgageCalculator.getCurrentDomain = function(){
	return this.getDomainFromUrl(document.URL);
}

/**
 * Gets the domain of the referrer page.
 * 
 * @return the domain
 * @type String
 */
MortgageCalculator.getReferrerDomain = function(){
	return this.getDomainFromUrl(document.referrer);
}

/**
 * Return true if the current version is the internal version of either
 * one of "bekb.ch" or "money-net.ch", as opposed to the embedded version
 * from a third party website.
 * 
 * @return true if internal version
 * @type Boolean
 */
MortgageCalculator.isInternalVersion = function(){
	// external version has a referrer (the embedding page) and it does not match
	// one of bekb or money-net
	var sReferrerDomain = this.getReferrerDomain();
	var bIsExternalVersion = 
		!!sReferrerDomain
			&&
		!sReferrerDomain.match(/(bekb\.ch)|(money-net\.ch)|(money-net\.int\.unic\.com)/);
	
	return !bIsExternalVersion;
}

/**
 * Gets all the calculated values as a request parameter string for the form.
 * 
 * @return the request parameter string
 * @type String
 */
MortgageCalculator.getValuesAsParameterString = function(){
	var sQueryString = "";
		
	// direct calculation values
	[
		['objektangaben-liegenschaftswert-total', 'price'],
		['finanzierung-eigenmittel', 'equity'],
		['finanzierung-bruttoeinkommen', 'income'],
		['finanzierung_hypothekardarlehen', 'mortgageAmount']
		
	].each(function(value){
		var oElement = $(value[1]);
		var sValue = oElement.value === undefined ? oElement.innerHTML : oElement.value;
		sQueryString += value[0] + '=' + MortgageCalculator.getSanitizedNumber(sValue) + '&';
	});
	
	// differently calculated values
	[
		['objektangaben-liegenschaftswert-kaufpreis', 
			'objektangaben-liegenschaftswert-kaufpreis'],
		['absenden_ausgangspunkt', this.getReferrerDomain() || this.getCurrentDomain()],
		['objektangaben', 
			this.Constants.ObjectTypeParameter[this.getObjectTypeValue()]]
	].each(function(value){
		sQueryString += value[0] + '=' + value[1] + '&';
	});
	
	// strip last '&'
	return !!sQueryString ? sQueryString.substr(0, sQueryString.length - 1) : '';
}

/**
 * Gets all the calculated values as a request parameter string for printing.
 * 
 * @return the request parameter string
 * @type String
 */
MortgageCalculator.getValuesAsPrintParameterString = function(){
	var sQueryString = "";
		
	// direct calculation values
	[
		['price', 'price'],
		['equity', 'equity'],
		['income', 'income']
		
	].each(function(value){
		var oElement = $(value[1]);
		var sValue = oElement.value === undefined ? oElement.innerHTML : oElement.value;
		sQueryString += value[0] + '=' + MortgageCalculator.getSanitizedNumber(sValue) + '&';
	});
	
	// differently calculated values
	[
		['objectType', 
			this.getObjectTypeValue()]
	].each(function(value){
		sQueryString += value[0] + '=' + value[1] + '&';
	});
	
	// strip last '&'
	return !!sQueryString ? sQueryString.substr(0, sQueryString.length - 1) : '';
}


/**
 * Gets the content/text to be displayed of the tooltips.
 * 
 * @param {Object} oElement the dom element
 *
 * @return the text of the tooltip
 * @type String
 * 
 * @private
 */
MortgageCalculator.getTooltipContent = function(oElement){
	// get rid of html comment
	var sContent = oElement.innerHTML.match(/<!--(.+)-->/);
	sContent = !!sContent && sContent.length > 1 ? sContent[1] : oElement.innerHTML;
	return sContent;
}

/**
 * Sanitizes the value of the specified number.
 *
 * @param {Object} the dom element
 *
 * @see MortgageCalculator#getSanitizedNumber
 * 
 * @private
 */
MortgageCalculator.sanitizeNumber = function(oElement){
	var oElement = $(oElement);
	if (oElement){
		//alert('iMIN_VALUE_' + oElement.id.toUpperCase());
		oElement.value = this.getSanitizedNumber(
			//Math.max(
				oElement.value//,
			//	MortgageCalculator.Constants['iMIN_VALUE_' + oElement.id.toUpperCase()]
			//)
		);
	}
	// todo else error
}

/**
 * Formats the value of the specified number.
 *
 * @param {Object} the dom element
 *
 * @see MortgageCalculator#getFormattedNumber
 * 
 * @private
 */
MortgageCalculator.formatNumber = function(oElement){
	var oElement = $(oElement);
	if (oElement){
		oElement.value = this.getFormattedNumber(
			Math.max(
				oElement.value,
				MortgageCalculator.Constants['iMIN_VALUE_' + oElement.id.toUpperCase()]
			)
		);
	}
	// todo else error
}

/**
 * Resets the boundary slider
 * 
 * @private
 */
MortgageCalculator.resetSliderBoundary = function(){
	$('slider_tragbarkeit').style.top = 
		MortgageCalculator.Constants.iBOUNDARY_LINE_POSITION + 'px';
	$$('#slider_tragbarkeit .slider .slider_r')[0].style.height = '0px';
}


/**
 * Resets the charge slider
 * 
 * @private
 */
MortgageCalculator.resetSliderCharge = function(){
	$$('#slider_belastung .slider .slider_r')[0].style.height = '0px';
}


/**
 * Gets the currently selected value of the object type radiobuttons.
 * 
 * @return the value of the object type radiobuttons.
 * @type String
 * 
 * @private
 */
MortgageCalculator.getObjectTypeValue = function(){
	var oForm = $('mortgageCalculatorForm');
	for (var i = 0; i < oForm.objectType.length; ++i){
		if (oForm.objectType[i].checked == true){
			return oForm.objectType[i].value;
		}
	}
	return MortgageCalculator.Constants.iDEFAULT_OBJECT_TYPE;
}


/**
 * Gets the domain of supplied url
 * 
 * @param {String} sUrl the supplied url
 *
 * @return the domain
 * @type String
 * 
 * @private
 */
MortgageCalculator.getDomainFromUrl = function(sUrl){
	//var aResult = sUrl.match(/http:\/\/(.+\.[a-zA-Z]{2,4})(\/.*)?$/);
	var aResult = sUrl.match(/https?:\/\/([^\/$]+)[\/$]/);
	// /http:\/\/[^\.]*\.?([^.]+\.[a-zA-Z]{2,4})/ *** only "domain.top"
	return !!aResult ? aResult[1] : sUrl;
}


/** 
 * DEBUG Class
 * Provides debugging functionality.
 */
function Debug(){}
Debug.write = function(sMessage){
	$('debugConsole').innerHTML += sMessage + "<br />";
}

