function updateCity() {
	$.getJSON("/ajax/city.php", {action: 'getCityFromPostalCode', postalCode: $('#postalCode').val()},
	function(data){
		$('#cityId').val(data.id);
		$('#city').val(data.name);
	});
}
function ge(elmId) {
	return document.getElementById(elmId);
}

function getIFrameDocument(id){
	var rv = null;
	var frame=ge(id);

	if (frame.contentDocument) {
		rv = frame.contentDocument;
	} else {
		rv = document.frames[id].document;
	}
	return rv;
}

function adjustIFrameHeight(iframeId) {
	var frame = ge(iframeId);
	var frameDoc = getIFrameDocument(iframeId);
	frame.height = frameDoc.body.offsetHeight;
}
function renewSession() {
	$.get("/ajax/session.php");
}
function validateMail(mail) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(mail))
	return true;
	else{
		return false;
	}
}
function toggleFavorites(recipeId, callback) {
	$.getJSON("/ajax/favorite.php", {action: 'updateFavorites', recipeId: recipeId},
	function(data){
		return callback(data);
	});
}
function resetFormField(field) {
	var type = field.type;
	var tag = field.tagName.toLowerCase(); // normalize case

	// it's ok to reset the value attr of text inputs,
	// password inputs, and textareas
	if (type == 'text' || type == 'password' || tag == 'textarea')
	field.value = "";

	// checkboxes and radios need to have their checked state cleared
	// but should *not* have their 'value' changed
	else if (type == 'checkbox' || type == 'radio')
	field.checked = false;

	// select elements need to have their 'selectedIndex' property set to -1
	// (field works for both single and multiple select elements)
	else if (tag == 'select')
	field.selectedIndex = -1;
}
function popupPage(url) {
	popupWidth = 780; // set the popup width
	popupHeight = parseInt(780 / 1.618); // set the popup height

	leftVal = (screen.width / 2) - (popupWidth / 2);
	topVal = 100;
	var page = window.open(url, '', 'width=' + popupWidth  + ', height=' + popupHeight + ',scrollbars=yes, resizable=no, left=' + leftVal + ', top=' + topVal);
	page.focus();
}
function roundNumber(num, decimals) {
	return Math.round(parseFloat(num) * Math.pow(10, decimals)) / Math.pow(10, decimals);
}