/******************************************************************************
* f_tog ( whatever that means ;-)
/*****************************************************************************/
function f_tog(that, blank, text)
{
  if ($(that).val() == text)
    $(that).val(blank);
  else if ($(that).val() == blank)
    $(that).val(text);
}

/******************************************************************************
* RememberMe Switch
/*****************************************************************************/
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';
  }
}

/******************************************************************************
* PlakatTeaser: collapseBill()
/*****************************************************************************/
function collapseBill()
{
  document.getElementById('home_plakat_teaser').style.width = "320px";
}

/******************************************************************************
* PlakatTeaser: expandBill()
/*****************************************************************************/
function expandBill()
{
  document.getElementById('home_plakat_teaser').style.width = "808px";
}

/******************************************************************************
* Expand: openExpand(id_des_expands)
/*****************************************************************************/
function openExpand(tmpID) 
{
  document.getElementById(tmpID).style.display = 'block';
  initExpand(tmpID);
}

/******************************************************************************
* Expand: closeExpand(id_des_expands)
/*****************************************************************************/
function closeExpand(tmpID) 
{
  document.getElementById(tmpID).innerHTML = '&nbsp;';
  document.getElementById(tmpID).style.display = 'none';
}

/******************************************************************************
* ContentExpand: openExpand(id_des_expands)
/*****************************************************************************/
function openContentExpand(tmpID) 
{
  document.getElementById(tmpID).style.display = 'block';
  initContentExpand(tmpID);
}

/******************************************************************************
* ContentExpand: closeExpand(id_des_expands)
/*****************************************************************************/
function closeContentExpand(tmpID) 
{
  document.getElementById(tmpID).innerHTML = '&nbsp;';
  document.getElementById(tmpID).style.display = 'none';
}

/******************************************************************************
* Global / LoadAjaxLayer
/*****************************************************************************/
function LoadAjaxLayer(layer, url)
{
  $(layer).load(url);
}

/******************************************************************************
* Global / ImgMouseOver
/*****************************************************************************/
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");
  }
}

/******************************************************************************
* Global / switchTab
/*****************************************************************************/
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
  
  // set my Tab to "_hi"
  document.getElementById("Img_"+imgItem).src = document.getElementById("Img_"+imgItem).src.replace(".gif", "_hi.gif");
}

/******************************************************************************
* Global / SubmitAjaxForm
/*****************************************************************************/
function SubmitAjaxForm( FormUrl, FormId, ResultLayer )
{
  var queryString = $('#'+FormId).formSerialize();
  jQuery.post( FormUrl, queryString, function(data){ jQuery('#'+ResultLayer).html(data) } );
}

/******************************************************************************
* createCombobox
/*****************************************************************************/
function createCombobox(p_layer) 
{
  $(p_layer).jcombox({ fx: 'slideFade', fxDelay: 150 , theme: 'opera', set: true });
}

/******************************************************************************
* SendBirthdayBox
/*****************************************************************************/
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;
}

/******************************************************************************
* ShowLoginWarning
/*****************************************************************************/
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;
}

/******************************************************************************
* AddArticleToCart
/*****************************************************************************/
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';
		        }
		    }
        );
    }
}

/******************************************************************************
* createAccordion
/*****************************************************************************/
function createAccordion( p_headerclass, p_contentclass, p_defaultexpanded )
{
	ddaccordion.init({
	headerclass: p_headerclass,   // Shared CSS class name of headers group
	contentclass: p_contentclass, // Shared CSS class name of contents group
	revealtype: "click",        // Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover"
	collapseprev: true,         // Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [p_defaultexpanded],       // index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: true,          // Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false,      // Should contents open by default be animated into view?
	persiststate: false,        // persist state of opened contents within browser session?
	toggleclass: ["", "AccordionHeadOpen"], // Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], // Additional HTML added to the header when it's collapsed and expanded
	animatespeed: "fast",       // speed of animation: "fast", "normal", or "slow"
	oninit:function(expandedindices){}, // custom code to run when headers have initalized
	onopenclose:function(header, index, state, isclicked){} //custom code to run whenever a header is opened or closed
	});
}

/*****************************************************************************
* CinemaxX Implementation
/*****************************************************************************/
$(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') });
    $('#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();
    });
});

/*****************************************************************************
* initHighslide
/*****************************************************************************/
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++) {
	        //alert(tmpGroup[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
	        }
	    });
	}
}

// Die Funktion openChild wird zum Oeffnen von Childwindows per JavaScript eingesetzt.
// Uebegabe Parameter sind:
//
// childUrl (string) - die URL des zu Oeffnenden Fensters
// childName (string) - der Name des Fensters
// childWidth (integer) - die Breite
// childHeight (integer) - die Hoehe
// childStatus (integer) - die Statuszeile wird angezeigt 
// childScrollbars (yes/no) -  es kann Scrollbars geben
// childLocation (yes/no) - die Adresszeile wird angezeigt
// childTollbar (yes/no) - die Toolbar wird angezeigt
// childMenubar (yes/no) - die Menubar wird angezeigt

// das Fenster wird in der Mitte des Bildschirms geoeffnet

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();
}

/* AddBookmark */
function AddCxXBookmark(txtURL, txtText)
{
  if (window.sidebar)
  {
    // firefox
    window.sidebar.addPanel(txtText,txtURL, "");
  }
  else if(document.all)
  {
    // ie
    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.');
}