var post = {
	sjaelland : {
		url 		  : "/sjaelland",
		intervals : [
			[1000, 4999]
		]
	},
	
	fyn : {
		url 		  : "/fyn",
		intervals : [
			[5000, 5999]
		]
	},
	haderslev : {
		url 		  : "/soenderjylland",
		intervals : [
            [6000, 6040],
 			[6070, 6090],
 			[6100, 6579],
 			[6630, 6639],
 			[6660, 6681],
 			[6683, 6899],
 			[6600, 6600],
 			[6640, 6640],
 			[6650, 6650],
 			[6041, 6064],
 			[6621, 6623],
 			[6682, 6682],
 			[6880, 6880],
 			[6960, 6960],
 			[7000, 7079],
 			[7200, 7200],
 			[7250, 7250]
		]
	},
	
	fms : {
		url 		  : "/nord-midtjylland",
		intervals : [
			[6900, 6999],
			[7080, 7199],
			[7260, 9999],
			[7182, 7184],
			[7190, 7190]
		]
	}
}


function findPostal(x, hideobj) {
	getValue = document.getElementById(x).value;
	hobj = document.getElementById(hideobj);
	
	if (checkSyntax(getValue)) {
		if (lookupPostal(getValue) != null) {
			window.location.href = lookupPostal(getValue);
		} else {
			hobj.style.display = 'block';
		}
	} else {
		alert("Det indtastede er ikke et postnummer.");
	}
}

function checkSyntax(x) {
	var patt = /^\d{4}$/;
	return patt.test(x);
}
	
function lookupPostal(x) {
	var url = null;

	for (place in post) {
		for (inter in post[place].intervals) {
			from = post[place].intervals[inter][0];
			to = post[place].intervals[inter][1];
			
			if ((x >= from) && (x <= to)) {
				url = post[place].url;
				break;
			}
		}
	}
	
	return url;
}

function closediv(hideobj) {
	hobj = document.getElementById(hideobj);
	
	if (hobj.style.display != 'none') {
		hobj.style.display = 'none';
	}
}
