/**
 * @author Jens-Frederik Allermann
 * 
 */


var project = '/lml';
var isLive = isLive();

if(isLive)
var project = '';


var RecaptchaOptions = {
   theme : 'clean',
   tabindex : 2
};

function isLive(){
	var url = document.URL;
	var localDomain = "/cms06.+/";
	var result = url.search(localDomain);
	if (result != -1){
		return false;
	}
	else{
		return true;
	}
}


/*
 * GET DATA
 */

HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!=''){
	gArr=strGET.split('&');
	for(i=0;i<gArr.length;++i){
		v='';vArr=gArr[i].split('=');
		if(vArr.length>1){v=vArr[1];}
		HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
	}
}
function GET(v){
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}


function checkTextareaLength(target, errormsg, length){
      var x = document.getElementById(target).value;
      
      var currentTextLength = length - x.length;
      if(currentTextLength < 0)
      currentTextLength = 0;
      
      document.getElementById(errormsg).innerHTML = currentTextLength;
      
      if (x.length > length) {
            x = x.substring(0, length);
            //alert("Du kannst maximal " + length + " Zeichen angeben.");
      };
      document.getElementById(target).value = x;
}

function domElem(id){
	return document.getElementById(id);
}

function showElem(id){
	document.getElementById(id).style.display = 'block';
}
function hideElem(id){
	document.getElementById(id).style.display = 'none';
}

function switchNewsTermine(activeTab)
{
	tab = domElem('news_termine_navi');
	tab.style.backgroundImage = 'url("'+project+'/media/images/buttons/'+activeTab+'_tab.png")';
	
	var action = 'get'+activeTab+'&ajax=true';
	
	ajax('', 'ajax.php', action, 'news_termine_container', '', false);
	
	return true;
}

function showLoadingGif(id)
{
	var obj = domElem(id);
	var newDiv = document.createElement("div");
	var img = '<img src="'+project+'/media/images/loading.gif" alt="Bitte warten..." style="padding-top: 150px;" />';
	newDiv.id = 'loadingDiv';
	obj.appendChild(newDiv);
	newDiv.innerHTML = img;
	newDiv.style.position = 'absolute';
	newDiv.style.top = '0px';
	newDiv.style.left = '0px';
	newDiv.style.width = '100%';
	newDiv.style.height = '100%';
	newDiv.style.backgroundColor = '#ffffff';
	newDiv.style.textAlign = 'center';
	newDiv.style.opacity = '0.9';
}

function delLoadingGif()
{
	var loader = domElem('loadingDiv');
	var parent = loader.parentNode;
	parent.removeChild(loader);
}

function changeMetaTags(title, img)
{
	domElem('metaTITLE').content = title;
	domElem('metaIMG').content = 'http://www.lena-meyer-landrut.de'+img;
}

function changeVideo(id, isFirstLoad)
{
	ajax('', 'ajax.php', 'getVideo&id='+id+'&ajax=true', 'videoWrapper', '', false);
	if(typeof isFirstLoad =="undefined")
	{
		ajax('', 'ajax.php', 'getVideoList&template=comments&ajax=true&videoID='+id, 'videoTabListContent', '', false);
	}
}

function changeVideoAutoplay(id, isFirstLoad)
{
	ajax('', 'ajax.php', 'getAutoplayVideo&id='+id+'&ajax=true', 'videoWrapper', '', false);
	if(typeof isFirstLoad =="undefined")
	{
		ajax('', 'ajax.php', 'getVideoList&template=comments&ajax=true&videoID='+id, 'videoTabListContent', '', false);
	}
}

function getHomeVideo()
{
	ajax('', 'ajax.php', 'getHomeVideo&ajax=true', 'playerInner', '', false);
}

function showNews(news)
{
	ajax('', 'ajax.php', 'getNews&news='+news+'&ajax=true', 'showNews', '', false);
}

function changeGBButton()
{
	domElem('writeButton').style.display = 'none';
	domElem('sendMsg').innerHTML = 'Dein Eintrag wurde erfolgreich gespeichert.';
	//domElem('sendMsg').innerHTML = 'Dein Eintrag wurde erfolgreich gespeichert und <br />wird schnellstmöglich freigeschaltet.';
}

function showGBForm(){
	domElem('writeGbEntry').style.display = 'block';
	domElem('gbContent').style.display = 'none';
}
function hideGBForm(){
	domElem('writeGbEntry').style.display = 'none';
	domElem('gbContent').style.display = 'block';
}

function checkNaviPos()
{
	// all except Explorer
	if (self.innerHeight)  {
	    screenX = self.innerWidth;
	    screenY = self.innerHeight;
	}
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight) {
	    screenX = document.documentElement.clientWidth;
	    screenY = document.documentElement.clientHeight;
	}
	// other Explorers
	else if (document.body) {
	    screenX = document.body.clientWidth;
	    screenY = document.body.clientHeight;
	}  
	
	if(screenY <= 590)
	{
		posNavi = domElem('posNavi');
		navi = domElem('navi');
		
		posNavi.style.top = '0';
		posNavi.style.left = '0';
		
		navi.style.top = '0';
		navi.style.left = '0';
		
	}
}

function initGallery(){
	var fo = new SWFObject(project + "/media/swf/gallery.swf", "Lena Meyer-Landrut", "100%", "100%", "8");
	
	// SIMPLEVIEWER CONFIGURATION OPTIONS
	// To use an option, uncomment it by removing the "//" at the start of the line
	// For a description of config options, go to: 
	// http://www.airtightinteractive.com/simpleviewer/options.html
	
	fo.addVariable("xmlDataPath", project + "/includes/xml/gallery.xml");
	
	fo.addParam("menu","false");
	fo.addParam("wmode","transparent");
	fo.addParam("quality","high");
	//fo.addVariable("firstImageIndex", "5");	
	//fo.addVariable("langOpenImage", "Bild in neuem Fenster öffnen");
	//fo.addVariable("langAbout", "Die Galerie von Lena Meyer-Landrut");	
	//fo.addVariable("preloaderColor", "0xFFFFFF");
	
	fo.write("gallery");
}


function openPopup(width, height, url) {
	if(!width || (typeof width == 'undefined')){width = 450;}
	if(!height || (typeof height == 'undefined')){height = 300;}

    var newPop = window.open(url, '', 'width=' + width + ',height=' + height + ',screenX=50,screenY=50');
    newPop.focus();
	return false;
}


function openPopupNewsletter() {
	var targetTextfield = "newsletter_input";
	var url = project + '/includes/snippets/newsletter.html?email='+document.getElementById(targetTextfield).value;
	openPopup(500,500, url);
	document.getElementById(targetTextfield).value = '';
	return false;
}

