function setCurrent(objid) {
	if(document.getElementById("sidenav_" + objid)) {
		document.getElementById("sidenav_" + objid).className += " current";
	}
}

function setHint(obj,hint) {
	if((obj.value == "") || (obj.value == hint)) {
		obj.style.color = "#666666";
		obj.value = hint;
	}
}

function clearHint(obj) {
	var hintflag = false;

	for(var count=0; count < hints.length; count++) {
		if(obj.value == hints[count]) {
			hintflag = true;	
		}
	}

	var ckval = obj.value;
	if(hintflag) {
		obj.value = "";
		obj.style.color = "#000000";
	}
}

function checkFields(obj,showoutput) {	
	var tock = obj.getElementsByTagName('input');
	var ckflag = true;

	for(var count=0; count < tock.length; count++) {
		if((tock[count].type == "text") && (tock[count].className == "req")) {
			if(tock[count].value == "") {
				ckflag = false;
			} else {
				for(var hintcount=0; hintcount < hints.length; hintcount++) {
					if(tock[count].value == hints[hintcount]) {
						ckflag = false;	
					}
				}
			}
		}
	}
	
	if((showoutput != null) && (!ckflag)) {
		alert("Please complete all the fields");
	}
	
	return ckflag;
}

function getSelected(id) {
	var obj = document.getElementById(id);
	return obj.options[obj.selectedIndex].value;
}

function showHide(showid,hideid) {
	document.getElementById(hideid).style.display = "none";
	document.getElementById(showid).style.display = "block";
}

function formatCurrency(obj) {
	num = obj.value.toString().replace(/\£|\,/g,'');
	
	if(isNaN(num)) {
		num = "0";
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pence = num%100;
	num = Math.floor(num/100).toString();
	
	if(pence<10) {
		pence = "0" + pence;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	}

	obj.value = (((sign)?'':'-') + '£' + num + '.' + pence);
}

function checkDate(field) {
	var allowBlank = true;
	var errorMsg = "";

	// regular expression to match required date format
	re = /^(\d{1,2})\/(\d{1,2})\/(\d{2})$/;
	
	if(field.value != '') {
		if(regs = field.value.match(re)) {
			if(regs[1] < 1 || regs[1] > 31) {
				errorMsg = "Invalid value for day: " + regs[1];
			} else if(regs[2] < 1 || regs[2] > 12) {
				errorMsg = "Invalid value for month: " + regs[2];
			} else if(regs[3] < 0 || regs[3] > 99) {
				errorMsg = "Invalid value for year: " + regs[3];
			}
		} else {
			errorMsg = "Invalid date format: " + field.value;
		}
	} else if(!allowBlank) {
		errorMsg = "Empty date not allowed!";
	}
	
	if(errorMsg != "") {
		alert(errorMsg);
		field.focus();
		
		return false;
	}
	
	return true;
}

function jumpmenu() {
	switch(getSelected('division_jumpmenu_choices')) {
		case "#":
			jumpurl = "#"
			break;
		case "group":
			jumpurl = "http://www.foundations-online.co.uk/";
			break;
		case "mortgages":
			jumpurl = "http://www.foundations-mortgages.co.uk/";
			break;
		case "loans":
			jumpurl = "http://www.foundations-loans.co.uk/";
			break;
		case "legal":
			jumpurl = "http://www.foundations-online.co.uk/solicitors/";
			break;
		case "accounting":
			jumpurl = "http://www.foundations-online.co.uk/accounting/";
			break;
		case "maintenance":
			jumpurl = "http://www.foundations-online.co.uk/property-maintenance/";
			break;
		case "inventories":
			jumpurl = "http://www.foundations-inventories.co.uk";
			break;
		case "cleaning":
			jumpurl = "http://www.foundations-online.co.uk/";
			break;
		case "removals":
			jumpurl = "http://www.foundations-online.co.uk/removals/";
			break;
	}
	
	window.location = jumpurl;
	return false;
}