var hints = new Array('ext.','dd/mm/yy');

function defaultHints() {
	var toset = new Array(
			new Array('ext',0),
			new Array('date_of_birth',1),
			new Array('date_purchased',1),
			new Array('applicant1_dob',1),
			new Array('applicant2_dob',1),
			new Array('app1_dob',1),
			new Array('app2_dob',1)
		);

	for(var count=0; count < toset.length; count++) {
		var obj = document.getElementById(toset[count][0]);
		
		if(obj) {
			var hint = hints[toset[count][1]];
			setHint(obj,hint);
		}
	}
}

function getObjVal(id) {
	var input = document.getElementById(id).value;
	var output = "";
	var badchars = "£, %";
	
	for(var i = 0; i < input.length; i++) {
		if(badchars.indexOf(input.charAt(i)) == -1) {
			output += input.charAt(i);
		}
	}
	
	if(output == "") {
		output = "0";
	}
	
	return eval(Math.abs(output));
}

function switchCalc(formid) {
	var alldivs = document.getElementsByTagName('div');
	
	for(var i=0;i < alldivs.length;i++) {
		if(alldivs[i].className == "calc_result" || alldivs[i].className == "calc_form") {
			alldivs[i].style.display = "none";
		}
	}
	
	document.getElementById(formid).style.display = "block";
}

function calcSecured() {
	var term = getSelected('term') * 12;
	var ipp = getSelected('apr') / 1200;
	var payment = getObjVal('amount') * (ipp / (1 - Math.pow(1 + ipp,-term)));

	document.getElementById('monthly_payment').innerHTML = payment.toFixed(2);
	document.getElementById('message').style.display = "block";
}

function switchSection(curobj,newsection) {
	var sections = new Array('loan','app1','app2','employment','property','mortgage','credit','legal');
	var cursection = curobj.parentNode.parentNode.parentNode.parentNode;
	
	if(checkFields(cursection)) {
		for(var i=0;i<sections.length;i++) {
			if(document.getElementById("section_" + sections[i])) {
				document.getElementById("section_" + sections[i]).style.display = "none";
			}
		}
	
		//window.location = "#section_" + newsection;
		window.location = "#top";	
		document.getElementById("section_" + newsection).style.display = "block";
	} else {	
		alert("Please complete all the required fields.");
	}
}

function chooseAppType() {
	var appradios = document.forms['apptype_form'].apptype;
	var selectedtype = "";
	
	for (i=0;i<appradios.length;i++) {
		if(appradios[i].checked) {
			selectedtype = appradios[i].value;
			break;
		}
	}
	
	if(selectedtype != "") {
		window.location = "../" + selectedtype + "/quote.php";
	} else {
		alert("Please select the type of loan you would like to apply for.");
	}
}