function f_tog(that, blank, text) {
	if ($(that).val() == text)
		$(that).val(blank);
	else if ($(that).val() == blank)
		$(that).val(text);
}

var gRememberMe = 1;
function switchRememberMe(alt) {
	if (gRememberMe == 1) {
		gRememberMe = 0;
		if (alt > 0)
			document.getElementById("img_angemeldet_bleiben").src = '/art/css/cinema_selector/b_angemeldet_bleiben.gif';
		else
			document.getElementById("img_angemeldet_bleiben").src = '/art/css/b_angemeldet_bleiben.gif';
		document.getElementById("rememberMe").value = 'false';
	}
	else {
		gRememberMe = 1;
		if (alt > 0)
			document.getElementById("img_angemeldet_bleiben").src = '/art/css/cinema_selector/b_angemeldet_bleiben_hi.gif';
		else
			document.getElementById("img_angemeldet_bleiben").src = '/art/css/b_angemeldet_bleiben_hi.gif';
		document.getElementById("rememberMe").value = 'true';
	}
}

function collapseBill() {
	document.getElementById('home_plakat_teaser').style.width = "320px";
}

function expandBill() {
	document.getElementById('home_plakat_teaser').style.width = "808px";
}

function openExpand(tmpID) {
	document.getElementById(tmpID).style.display = 'block';
	initExpand(tmpID);
}

function closeExpand(tmpID) {
	document.getElementById(tmpID).innerHTML = '&nbsp;';
	document.getElementById(tmpID).style.display = 'none';
}

function openContentExpand(tmpID) {
	document.getElementById(tmpID).style.display = 'block';
	initContentExpand(tmpID);
}

function closeContentExpand(tmpID) {
	document.getElementById(tmpID).innerHTML = '&nbsp;';
	document.getElementById(tmpID).style.display = 'none';
}

function LoadAjaxLayer(layer, url) {
	$(layer).load(url);
}

function ImgMouseOver(item, on) {
	if (typeof item.src != 'undefined') {
		if (on == 1)
			item.src = item.src.replace(".gif", "_hi.gif");
		else
			item.src = item.src.replace("_hi.gif", ".gif");
	}
}

function ImgMouseOverPng(item, on) {
	if (typeof item.src != 'undefined') {
		if (on == 1)
			item.src = item.src.replace(".png", "_hi.png");
		else
			item.src = item.src.replace("_hi.png", ".png");
	}
}

function switchTab(tabLayer, imgItem) {
	var DivImages = document.getElementById(tabLayer).getElementsByTagName('img');
	for (var i = 0; i < DivImages.length; i++)
		DivImages[i].src = DivImages[i].src.replace("_hi.gif", ".gif"); // alles auf lo schnatzen
	document.getElementById("Img_" + imgItem).src = document.getElementById("Img_" + imgItem).src.replace(".gif", "_hi.gif");
}

function SubmitAjaxForm(FormUrl, FormId, ResultLayer) {
	var queryString = $('#' + FormId).formSerialize();
	jQuery.post(FormUrl, queryString, function(data) { jQuery('#' + ResultLayer).html(data) });
}

function createCombobox(p_layer) {
	$(p_layer).jcombox({ fx: 'slideFade', fxDelay: 150, theme: 'opera', set: true });
}

function SendBirthdayBox(p_tag, p_monat) {
	if (document.getElementById(p_tag).value > 0 && document.getElementById(p_monat).value > 0)
		self.location.href = '/FilmeundStars/Profisuche/Star?search_star_name=Starname&search_star_geburtstag=' + document.getElementById(p_tag).value + '&search_star_geburtsmonat=' + document.getElementById(p_monat).value;
	else
		Boxy.alert("Bitte geben Sie Geburtstag und -monat ein.", null, { title: 'Happy Birthday' });
	return false;
}

function ShowLoginWarning() {
	Boxy.alert("Sie m&uuml;ssen bei Mein CinemaxX angemeldet sein, um diese Funktion nutzen zu k&ouml;nnen.<br /><br />Falls Sie noch kein Mein CinemaxX Mitglied sind, k&ouml;nnen Sie sich <a href='/MeinCinemaxx/Register/' class='more bold' onfocus='blur();'>hier kostenlos registrieren</a>.", function(val) { document.getElementById("UserPanelMessages").innerHTML = "<img src=\"/art/css/mein_cinemaxx/login_hint.gif\" alt=\"\" title=\"\"/>"; }, { title: 'Anmeldung erforderlich' });
	return false;
}

function showPic(tmpZG, blnOpt) {
	if (blnOpt == 1)
		$('#' + tmpZG).attr('src', '/art/css/main/' + tmpZG + '.png')
	else
		$('#' + tmpZG).attr('src', '/art/dummy.gif');
}

function AddArticleToCart(lngShop, tmpArticle) {
	if (lngShop == 2)
		document.location.href = '/Shop/Warenkorb/KinoflatShop';
	else {
		Boxy.ask((lngShop == 3 ? "Die Pr&auml;mie " : "Der Artikel ") + "<b>" + tmpArticle + "</b> wurde in Ihren Warenkorb gelegt!<br/><br/>Klicken Sie auf <b>Zum Warenkorb</b>, um " + (lngShop == 3 ? "diese Pr&auml;mie " : "diesen Artikel ") + " zu erwerben oder schauen Sie sich nach anderen " + (lngShop == 3 ? "Pr&auml;mien" : "Artikeln") + " um.<br/><br/>", { "1": "Weiter schauen", "2": "Zum Warenkorb" },
      function(r) {
      	if (r == "2") {
      		if (lngShop == 1)
      			document.location.href = '/Shop/Warenkorb/CinemaxXShop';
      		if (lngShop == 3)
      			document.location.href = '/Shop/Warenkorb/Praemienshop';
      	}
      }
    );
	}
}

function createAccordion(p_headerclass, p_contentclass, p_defaultexpanded) {
	ddaccordion.init({
		headerclass: p_headerclass,
		contentclass: p_contentclass,
		revealtype: "click",
		collapseprev: true,
		defaultexpanded: [p_defaultexpanded],
		onemustopen: true,
		animatedefault: false,
		persiststate: false,
		toggleclass: ["", "AccordionHeadOpen"],
		togglehtml: ["none", "", ""],
		animatespeed: "fast",
		oninit: function(expandedindices) { },
		onopenclose: function(header, index, state, isclicked) { }
	});
}

$(document).ready(function () {
	//$('#user_email').click(function() { f_tog($(this), '', 'E-Mail') }).blur(function() { f_tog($(this), '', 'E-Mail') });
	//$('#user_pass').click(function() { f_tog($(this), '', 'Passwort') }).blur(function() { f_tog($(this), '', 'Passwort') });
	if ($("#user_search").val() != undefined) {
		$('#user_search').click(function () { f_tog($(this), '', 'Suche') }).blur(function () { f_tog($(this), '', 'Suche') });
		$("#user_search").autocomplete(
    "/Search/SuggestBoxResult", {
    	minChars: 3,
    	width: 260,
    	selectFirst: false,
    	resultsClass: "ac_results",
    	matchSubset: false
    });
		$("#user_search").result(function (event, data, formatted) {
			$(this).val(data[1]);
			document.global_search.submit();
		});
	}
	if ($("#userSearch").val() != undefined) {
		$('#userSearch').click(function () { f_tog($(this), '', 'Suche') }).blur(function () { f_tog($(this), '', 'Suche') });
		$("#userSearch").autocomplete(
    "/Search/SuggestBoxResult", {
    	minChars: 3,
    	width: 260,
    	selectFirst: false,
    	resultsClass: "ac_results3",
    	matchSubset: false
    });
		$("#userSearch").result(function (event, data, formatted) {
			$(this).val(data[1]);
			document.globalSearch.submit();
		});
	}



});

function initHighslide(tmpSpeed, tmpPosition, tmpGroup) {
	hs.graphicsDir = '/art/css/highslide/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'rounded-white';
	hs.fadeInOut = true;
	hs.numberPosition = tmpPosition;
	hs.dimmingOpacity = 0.75;
	hs.blockRightClick = true;
	if (tmpGroup != "") {
		for (i = 0; i < tmpGroup.length; i++) {
			if (hs.addSlideshow) hs.addSlideshow({
				slideshowGroup: tmpGroup[i],
				interval: tmpSpeed,
				repeat: false,
				useControls: true,
				fixedControls: false,
				overlayOptions: {
					opacity: 1,
					position: 'top right',
					hideOnMouseOut: false
				}
			});

		}
	} else {
		if (hs.addSlideshow) hs.addSlideshow({
			interval: tmpSpeed,
			repeat: false,
			useControls: true,
			fixedControls: false,
			overlayOptions: {
				opacity: 1,
				position: 'top right',
				hideOnMouseOut: false
			}
		});
	}
}

// childUrl (string)
// childName (string)
// childWidth (integer)
// childHeight (integer)
// childStatus (integer)
// childScrollbars (yes/no)
// childLocation (yes/no)
// childTollbar (yes/no)
// childMenubar (yes/no)

function openChild(childUrl, childName, childWidth, childHeight, childStatus, childScrollbars, childLocation, childTollbar, childMenubar, childReziable) {
	var newChild = null;
	if (childWidth > 0) {
		childPosLeft = Math.floor((screen.width - childWidth) / 2);
		childPosTop = Math.floor((screen.height - childHeight) / 2);
		newChild = window.open(childUrl, childName, 'width=' + childWidth + ',height=' + childHeight + ',innerwidth=' + childWidth + ',innerheight=' + childHeight + ',top=' + childPosTop + ',left=' + childPosLeft + ',status=' + childStatus + ',scrollbars=' + childScrollbars + ',location=' + childLocation + ',toolbar=' + childTollbar + ',menubar=' + childMenubar + ',resizable=' + childReziable);
	} else {
		newChild = window.open(childUrl, childName);
	}
	if (newChild != null)
		newChild.window.focus();
}

function AddCxXBookmark(txtURL, txtText) {
	if (window.sidebar)
		window.sidebar.addPanel(txtText, txtURL, "");
	else if (document.all)
		window.external.AddFavorite(txtURL, txtText);
	else {
		Boxy.alert("Bitte dr&uuml;cken Sie CTRL+D bzw. Apfel+D, um diese Seite zu bookmarken.", null, { title: 'Seite bookmarken' });
		return false;
	}
}

/* LoadLivePaper */
var epWindow = false;
function loadfilmlivepaper() {
	var epURL = "http://www.kinolive.de/flash_cmxx.php";
	//?"+Math.random();
	var w, h;
	w = screen.width;
	h = screen.height;
	epWindow = window.open(epURL, "test", "fullscreen=no,resizable=yes,status=yes,toolbar=no,menubar=no,location=no,width=" + w + ",height=" + h + ",top=0,left=0");
	epWindow.focus();
	setTimeout("Check()", 2000);
}

function Check() {
	if (!epWindow) alert('HINWEIS! ' + "\n\n" + 'Ihr popUp-Blocker verhindert das Öffnen des livepapers. Bitte deaktivieren Sie ihren popUp-Blocker.');
}

function showState(tmpState) {
	$('div[id^="city_' + tmpState + '_"]').addClass('cs_city');
	$('div[id^="city_' + tmpState + '_"]').removeClass('cs_city_disabled');
	$('div[id^="cinema_' + tmpState + '_"]').addClass('cs_cinema');
	$('div[id^="cinema_' + tmpState + '_"]').removeClass('cs_cinema_disabled');
	$('div[id^="city_"]:not([id^="city_' + tmpState + '_"])').removeClass('cs_city');
	$('div[id^="city_"]:not([id^="city_' + tmpState + '_"])').addClass('cs_city_disabled');
	$('div[id^="cinema_"]:not([id^="cinema_' + tmpState + '_"])').removeClass('cs_cinema');
	$('div[id^="cinema_"]:not([id^="cinema_' + tmpState + '_"])').addClass('cs_cinema_disabled');
}

function loadProg(tmpField, tmpChange, intReset, tmpPage) {
	var tmpParam = "";
	var Center = $('#Center').val();
	var CenterOld = $('#CenterOld').val();
	var WeekStart = $('#WeekStart').val();
	var Genre = $('#Genre').val();
	var Time = $('#Time').val();
	var Display = $('#Display').val();
	var Special = $('#Special').val();
	var EDI = $('#EDI').val();
	var EDIType = $('#EDIType').val();

	if (Center == undefined)
		Center = '';
	if (CenterOld == undefined)
		CenterOld = '';
	if (WeekStart == undefined)
		WeekStart = '';
	if (Genre == undefined)
		Genre = '';
	if (Time == undefined)
		Time = '';
	if (Display == undefined)
		Display = '';
	if (Special == undefined)
		Special = '';
	if (EDI == undefined)
		EDI = '';
	if (EDIType == undefined)
		EDIType = '';

	if (tmpField == 'jQ' || tmpField == 'Genre' || tmpField == 'EDIType' || tmpField == 'Time') {
		if (intReset == 1) {
			Genre = '';
			Time = '';
			Special = '';
			EDI = '';
			EDIType = '';
			$('#Genre').val('');
			$('#Time').val('');
			$('#Special').val('');
			$('#EDI').val('');
			$('#EDIType').val('');
			$('#btnReset').hide();
		} else {
			//alert('Genre ' + Genre + '\nTime ' + Time + '\nSpecial ' + Special + '\nEDI ' + EDI + '\nEDIType ' + EDIType)
			if (Genre == '' && Time == '' && Special == '' && EDI == '' && EDIType == '')
				$('#btnReset').hide();
			else
				$('#btnReset').show();
		}
		var tmpSearch = '';
		var tmpSearch1 = '';
		if (Special != '')
			tmpSearch += '.kc1';

		if (EDIType != '') {
			if (EDIType == '2,4,6,8') //OV
				tmpSearch += '.ov1';
			if (EDIType == '1,2') //2D
				tmpSearch += '.d21';
			if (EDIType == '3,4') //3D
				tmpSearch += '.d31';
			if (EDIType == '5,6,7,8') //IMAX
				tmpSearch += '.im1';
			if (EDIType == '7,8') //IMAX 3D
				tmpSearch += '.i31';
		}
		if (Genre != '') {
			var tmpGenre = Genre.toLowerCase();
			if (tmpGenre == 'artmaxx') {
				tmpSearch += '.am1';
			} else if (tmpGenre == 'familienprogramm') {
				tmpSearch += '.fp1';
			} else if (tmpGenre == 'original') {
				tmpSearch += '.ov1';
			} else if (tmpGenre == 'science fiction') {
				tmpSearch += '.science.fiction';
			} else {
				if (tmpGenre.indexOf('die') != -1) {
					tmpSearch += '.komoedie';
				} else {
					tmpSearch += '.' + tmpGenre;
				}
			}
		}
		if (EDI != '') {
			if (EDI.indexOf(',') != -1) {
				arrEDI = EDI.split(',');
				var newSearch = '';
				//tmpSearch += '(';
				for (var e = 0; e < arrEDI.length; e++) {
					if (e > 0)
						newSearch += ',';
					newSearch += tmpSearch + '.edi' + arrEDI[e];
				}
				tmpSearch = newSearch;
				//tmpSearch += ')';
			} else {
				tmpSearch += '.edi' + EDI;
			}
		}
		//console.log(tmpSearch);
		if (Time != '')
			tmpSearch1 += '.tm' + Time;
		if (tmpSearch == '') {
			$('div.filmbox').show();
		} else {
			$('div.filmbox').hide();
			$('div' + tmpSearch).show();
		}
		$('.cinebox').show();
		if (tmpSearch1 == '') {
			$('.timebox').show();
		} else {
			$('.timebox').hide();
			$('' + tmpSearch1).show();
		}

		arrFilmBox = $(".filmbox:visible");
		if (arrFilmBox.length == 0)
			$('#nofound').show();
		else {
			var cntVisible = 0;
			arrFilmBox.each(function(index, element) {
				if ($(this).find(".timebox:visible").length == 0)
					$(this).hide();
				else {
					arrTimeBox = $(this).find(".cinebox:visible");
					arrTimeBox.each(function(index, element) {
						if ($(this).find(".timebox:visible").length == 0)
							$(this).hide();
						else {
							$(this).show();
							cntVisible++;
						}
					});
				}
			});
			if (cntVisible == 0)
				$('#nofound').show();
			else
				$('#nofound').hide();
		}
	} else {
		if (Special != '') {
			if (Special == 'KlexXi' && tmpChange.indexOf('KlexXi') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += 'KlexXi';
			}
		}
		if (EDIType != '') {
			if (EDIType == '1,2' && tmpChange.indexOf('2D') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += '2D';
			}
			if (EDIType == '3,4' && tmpChange.indexOf('3D') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += '3D';
			}
			if (EDIType == '5,6,7,8' && tmpChange.indexOf('IMAX') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += 'IMAX';
			}
			if (EDIType == '7,8' && tmpChange.indexOf('IMAX3D') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += 'IMAX3D';
			}
			if (EDIType == '2,4,6,8' && tmpChange.indexOf('Original') == -1 && intReset == 0) {
				if (tmpParam != '') tmpParam += ';';
				tmpParam += 'Original';
			}
		}
		if (tmpChange != '') {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += tmpChange;
		}
		if (Center != '' && tmpChange.indexOf('Cinema') == -1) {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'Center=' + Center;
		}
		if (WeekStart != '' && tmpChange.indexOf('WeekStart') == -1) {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'WeekStart=' + WeekStart;
		}
		if (Genre != '' && tmpChange.indexOf('Genre') == -1 && intReset == 0) {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'Genre=' + Genre;
		}
		if (Time != '' && tmpChange.indexOf('Time') == -1 && intReset == 0) {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'Time=' + Time;
		}
		if (Display != '1') {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'Display=' + Display;
		}
		if (EDI != '' && tmpChange.indexOf('EDI') == -1 && intReset == 0) {
			if (tmpParam != '') tmpParam += ';';
			tmpParam += 'EDI=' + EDI;
		}
		if (tmpPage.indexOf('inderfilmprogramm') != -1) {
			if (Center != CenterOld)
				tmpParam += "?switchCinemaId=" + Center;
		}

		this.location.href = tmpPage + tmpParam;
	}
}



