function showImage(imgId, imgSrc) {
	document.images[imgId].src = eval(imgSrc + ".src");
}

function markSelectedImage(element_id) {
	$('#maxityImageLinks > span').attr('class', 'idaba_image_unselected');
	$('#maxityImageLinks > #' + element_id).attr('class', 'idaba_image_selected');
}

function markSelectedVideo(element_id) {
	unmarkSelectedVideo();
	$('#maxityVideoLinks > #' + element_id).attr('class', 'idaba_image_selected');
}

function unmarkSelectedVideo() {
	$('#maxityVideoLinks > span').attr('class', 'idaba_image_unselected');
}

function popup_image(url) {
    imgwindow=window.open(url, "", "width=" + screen.availWidth + ", height=" + screen.availHeight + ",top=1,left=1,location=no,resizable=yes,toolbar=no,menubar=no,personalbar=no,scrollbars=no,status=no");
    imgwindow.focus();
}

function popup_url(url) {
    urlwindow=window.open(url, "", "width=" + screen.availWidth + ", height=" + screen.availHeight + ",top=1,left=1,resizable=yes,toolbar=yes,menubar=yes,personalbar=yes,scrollbars=yes,status=yes");
    urlwindow.moveto(1,1);
    urlwindow.focus();
}

function popup_image_sized(url, p_width, p_height, p_top, p_left) {
    if (p_width == 0 || p_width > screen.availWidth) p_width = screen.availWidth;
	else p_width = p_width + 20;
    if (p_height == 0 || p_height > screen.availHeight) p_height = screen.availHeight;
	else p_height = p_height + 20;
    if (p_top == 0) {
		if (p_height < screen.availHeight) p_top = (screen.availHeight- p_height) / 2;
		else p_top = 1;
    }
    if (p_left == 0) {
		if (p_width < screen.availWidth) p_left = (screen.availWidth - p_width) / 2;
		else p_left = 1;
    }

    urlwindow=window.open(url, "", "width=" + p_width + ",height=" + p_height +",top=" + p_top + ",left=" + p_left + ",location=no,resizable=yes,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,status=no");
    urlwindow.focus();
}

function popup_url_sized(url, p_width, p_height, p_top, p_left) {
    if (p_width == 0 || p_width > screen.availWidth) p_width = screen.availWidth;
    if (p_height == 0 || p_height > screen.availHeight) p_height = screen.availHeight;
    if (p_top == 0) {
	if (p_height < screen.availHeight) p_top = (screen.availHeight- p_height) / 2;
	else p_top = 1;
    }
    if (p_left == 0) {
	if (p_width < screen.availWidth) p_left = (screen.availWidth - p_width) / 2;
	else p_left = 1;
    }

    urlwindow=window.open(url, "", "width=" + p_width + ",height=" + p_height +",top=" + p_top + ",left=" + p_left + ",location=no,resizable=yes,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,status=no");
    urlwindow.focus();
}

function popup_url_sized_formpost(form, target, p_width, p_height, p_top, p_left) {
    if (p_width == 0 || p_width > screen.availWidth) p_width = screen.availWidth;
    if (p_height == 0 || p_height > screen.availHeight) p_height = screen.availHeight;
    if (p_top == 0) {
	if (p_height < screen.availHeight) p_top = (screen.availHeight- p_height) / 2;
	else p_top = 1;
    }
    if (p_left == 0) {
	if (p_width < screen.availWidth) p_left = (screen.availWidth - p_width) / 2;
	else p_left = 1;
    }

    window.open("", target, "width=" + p_width + ",height=" + p_height +",top=" + p_top + ",left=" + p_left + ",location=no,resizable=yes,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,status=no");
    var a = window.setTimeout("document." + form + ".submit();", 500);
}

function openPrintVersion() {
		var params = "print=true";
		if (document.location.search != "") {
			params = document.location.search + "&" + params;		
		} else {
			params = "?" + params;
		}
		window.open(document.location.pathname + params, "print", "top=1,left=1,width=700,height=600,dependent=yes,status=no,resizable=yes,toolbar=no,location=no,scrollbars=yes");
}

function submitMailForm(form_name, check_recipient_mail) {
	s_error = "";

	if (document.forms[form_name].elements["p_mailtitle"] != null && document.forms[form_name].elements["p_mailtitle"].value == "") {
		s_error += "Betreff\n";
	}
	if (check_recipient_mail) {
		if (document.forms[form_name].elements["p_mailrecipientmail"] != null && document.forms[form_name].elements["p_mailrecipientmail"].value == "") {
			s_error += "E-Mail-Adresse des Empfaengers\n";
		} else if ( document.forms[form_name].elements["p_mailrecipientmail"].value != "(none)" &&
			   (document.forms[form_name].elements["p_mailrecipientmail"].value.indexOf("@") == -1 || document.forms[form_name].elements["p_mailrecipientmail"].value.indexOf(".") == -1)
			  ) {
			s_error += "E-Mail des Empfaengers ist ungueltig\n";
		}
	}
	if (document.forms[form_name].elements["p_mailsendermail"] != null && document.forms[form_name].elements["p_mailsendermail"].value == "") {
		s_error += "E-Mail-Adresse des Absenders\n";
	} else if ( document.forms[form_name].elements["p_mailsendermail"].value != "(none)" &&
		   (document.forms[form_name].elements["p_mailsendermail"].value.indexOf("@") == -1 || document.forms[form_name].elements["p_mailsendermail"].value.indexOf(".") == -1)
		  ) {
		s_error += "E-Mail des Absenders ist ungueltig\n";
	}
	if (document.forms[form_name].elements["p_mailtext"] != null && document.forms[form_name].elements["p_mailtext"].value == "") {
		s_error += "Text der E-Mail\n";
	}

	if (s_error != "") {
		s_error = "Das Formular ist unvollstaendig ausgefuellt, bitte ergaenzen Sie folgende Angaben:\n\n" + s_error;
		alert(s_error);
		return false;
	}
}

function submitGastroReservationForm(form_name) {
	s_error = "";

	if (document.forms[form_name].elements["name1"] != null && document.forms[form_name].elements["name1"].value == "") {
		s_error += "Name\n";
	}
	if (document.forms[form_name].elements["text1"] != null && document.forms[form_name].elements["text1"].value == "") {
		s_error += "Anfrage-Text\n";
	}
	if (
		(document.forms[form_name].elements["email1"] != null && document.forms[form_name].elements["email1"].value == "") &&
		(document.forms[form_name].elements["phone1"] != null && document.forms[form_name].elements["phone1"].value == "") &&
		(document.forms[form_name].elements["fax1"] != null && document.forms[form_name].elements["fax1"].value == "")) {
		s_error += "Email, Telefon oder Telefax\n";
	}

	if (s_error != "") {
		s_error = "Das Formular ist unvollstaendig ausgefuellt, bitte ergaenzen Sie folgende Angaben:\n\n" + s_error;
		alert(s_error);
		return false;
	}

	return true;
}

var g_interval;
var g_target_height;
var g_scroll_value;
var g_element_id;

function smoothResizeHeightPlus() {
	s_height = document.getElementById(g_element_id).style.height;
	i_height = parseInt(s_height.substr(0, s_height.length-2));

	i_height = i_height + g_scroll_value;
	if (i_height > g_target_height) i_height = g_target_height;

	document.getElementById(g_element_id).style.height = i_height + "px";

	if (i_height >= g_target_height) {
		window.clearInterval(g_interval);
	}
}

function smoothResizeHeightMinus() {
	s_height = document.getElementById(g_element_id).style.height;
	i_height = parseInt(s_height.substr(0, s_height.length-2));

	i_height = i_height - g_scroll_value;
	if (i_height < g_target_height) i_height = g_target_height;

	document.getElementById(g_element_id).style.height = i_height + "px";

	if (i_height <= g_target_height) {
		window.clearInterval(g_interval);
	}
}

function smoothResizeHeight(target_height, element_id, scroll_value, scroll_interval) {
	g_target_height = target_height;
	g_scroll_value = scroll_value;
	g_element_id = element_id;

	s_height = document.getElementById(g_element_id).style.height;
	i_height = parseInt(s_height.substr(0, s_height.length-2));

	if (i_height > g_target_height) {
		g_interval = window.setInterval("smoothResizeHeightMinus()", scroll_interval);
	} else if (i_height < g_target_height) {
		g_interval = window.setInterval("smoothResizeHeightPlus()", scroll_interval);
	}
}


function infobox_show(elem_id) {
	document.getElementById(elem_id).style.visibility='visible';
}

function infobox_hide(elem_id) {
	document.getElementById(elem_id).style.visibility='hidden';
}

function idabaAjaxLoader(selector_loading, selector_target, url, params, type, text, callback) {
	if (type == null || type.length == 0) {
		type = 'big';
	}
	if (text == null || text.length == 0) {
		text = 'Loading...';
	}
			
	$(selector_loading).html('<div class="idaba-loading-' + type + '">' + text + '</div>');
	$(selector_target).load(url, params, function() {
		if (jQuery.isFunction(callback)) {
			callback.call();
		}
		if (selector_loading != selector_target) {
			$(selector_loading).html('');
		}
		bodyInit();
	});
}

function showLoading(elem_id, type, callback) {
	if (type == 'small') {
		page = '<div style="width:100%;text-align:center;"><img src="/opencms/export/system/modules/com.maxity/resources/login/images/ajax-loader_small.gif" width="16" height="16" border="0" alt=""></div>';
	} else {
		page = '<div style="width:100%;text-align:center;"><img src="/opencms/export/system/modules/com.maxity/resources/login/images/ajax-loader.gif" width="32" height="32" border="0" alt=""></div>';		
	}

	$('#' + elem_id).html(page);
	
	if (jQuery.isFunction(type)) {
		type.call();
	} else if (jQuery.isFunction(callback)) {
		callback.call();
	}
}

function showMaxityVideo(elemid, num, file, title, width, height, lang, module_video) {
	selector = '#' + elemid;
	
	if ($(selector).is(':visible')) {
		closeMaxityVideo(elemid);
	} else {
		$(selector).height(70 + (1.0 * height));
	
		showLoading(
			elemid, 
			function() {
				$(selector).slideToggle(
					'fast',
					function(){
						$(selector).load(
							module_video,
							{p_stream_num:num,p_stream_filename:file,p_stream_title:title,p_stream_width:width,p_stream_height:height,p_elemid:elemid,p_lang:lang}
						);
					}
				);
			}
		);
	}
	
	markSelectedVideo('idaba_select_video_'+num);
}

function closeMaxityVideo(elemid){
	selector = '#' + elemid;
	
	$(selector).html('');
	$(selector).slideToggle('fast', function() {
		unmarkSelectedVideo();
	});
}
