function showsubthis(thisid,direc) {
	if (direc == 1) {
	document.getElementById(thisid).className = ""; }
	else {
	document.getElementById(thisid).className = "hide"; }
}

function showsublist() {
	thiselem = document.getElementById('sublist');
	if (thiselem.className == "subhide") {
	thiselem.className = "subshow";
	document.getElementById('subdrop').className = "down";
	document.getElementById('subdrop').blur(); }
	else {
	thiselem.className = "subhide";
	document.getElementById('subdrop').className = "up";
	document.getElementById('subdrop').blur(); }
}

function submitform(thisid) {
	document.getElementsByName(thisid)[0].submit();
	return false;
}

function showpay() {
	if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) || (document.calc.months.value == null || document.calc.months.value.length == 0) || (document.calc.rate.value == null || document.calc.rate.value.length == 0)) {
		document.calc.pay.value = "Incomplete data";
	} else {
		var princ = document.calc.loan.value;
		var term  = document.calc.months.value;
		var intr   = document.calc.rate.value / 1200;
		var val = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
		var finalval = roundToTwoDecimals(val);
		if (isNaN(finalval)) {
			document.calc.pay.value = "Improper data";
		} else {
			document.calc.pay.value = finalval;
		}
	}
	// payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months))
}

function roundToTwoDecimals(input) {
    input = input * 100;
    input = Math.round(input);
    input = input / 100;
	input = decimalPadToMonetary(input);
    return input;
}

function decimalPadToMonetary(input) {
// Attention! This function returns a string value based off of the number passed to it.
// It is highly recommended that you do not store this value in the original variable,
// or the padding my be lost when the value is used again in a math function.

	stringThing = input.toString();
	var pointPos = stringThing.indexOf(".");
	var strLength = stringThing.length;
	if (pointPos == -1) {
      stringThing = stringThing + "" + ".00";
	} else {
		while (strLength < pointPos + 3) {
			stringThing = stringThing + "0";
			strLength = stringThing.length;
		}
	}
	return stringThing;
}

function togglepage(layerid) {
	togglehideall();
	var toelem = document.getElementById(layerid);
	toelem.className = "toggleshow";
	
	var layercontainer = layerid + "container";
	var layerlink = layerid + "link";
	
	document.getElementById('selectedtab').value = layerid;
	document.getElementById('tabcontainer').className = layercontainer;
	document.getElementById(layerlink).className = "fronttab";
}

function togglehideall() {
	document.getElementById('specific').className = "togglehide";
	document.getElementById('picture').className = "togglehide";
	document.getElementById('general').className = "togglehide";
	document.getElementById('specificlink').className = "backtab";
	document.getElementById('picturelink').className = "backtab";
	document.getElementById('generallink').className = "backtab";
}