// hover-functionality for images
function mouseOver(image_object) {
	image_object.src = image_object.src.replace(/\.(jpg|gif|png)/, "_hover.$1");
}
function mouseOut(image_object) {
	image_object.src = image_object.src.replace(/_hover/, "");
}
// anti-spam mail-address-function
function mailMe(address) {
	var address = address.replace(/123/, "");
	var address = address.replace(/456/, "");
	var address = address.replace(/bei/, "@");
	location.href = "mailto:"+address;
}

// ajax functions
function jsoneval(s) {
	if(typeof(s)=="string") {
		if(s.charAt(0)=="{" && s.charAt(s.length-1)=="}") {
			return eval('('+s+')');
		}
		else {
			return "{}";
		}
	}
}
function handleAjaxResponse(page, dom, callback, json) {
	if(typeof(json) == 'string') {
		var response = jsoneval(json);
	} else {
		var response = json;
	}
	if(typeof(response)=="object") {
		if(response.dom) {
			$('#'+response.dom).html(response.html).fadeIn(200);
		}
		// set inner html of dom element
		if(dom && typeof(response.html) == "string") {
			$('#'+dom).html(response.html).fadeIn(200);
		}
		// replace dom element
		if(response.dom_replace && typeof(response.html) == "string") {
			$("#"+response.dom_replace).replaceWith(response.html);
		}
		if(typeof(response.js) == "string") {
			eval(response.js);
		}
		if(callback) {
			callback(response);
		}
		// handle remote error information
		if(response.error_dom && response.error_html) {
			$('#'+response.error_dom).html(response.error_html).fadeIn(200);
		}
	}
}
function handleIFrameResult (json) {
	handleAjaxResponse(null, null, null, json);
}
function loadAjax(page, dom, callback) {
	$.get('/ajax/'+page,
				 function(json) {
					 handleAjaxResponse(page, dom, callback, json);
				 }
	);
}
function loadAjaxPost(page, params, dom, callback) {
	$.post('/ajax/'+page, params,
		   function(json) {
				handleAjaxResponse(page, dom, callback, json);
			}
	);
}