/**
 * @author RWelbers
 * <rwelbers@brainpool.de>
 */



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;
	}
}



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 changeVideo(id)
{
	ajax('', 'ajax.php', 'getVideo&id='+id+'&ajax=true', 'videoWrapper', '', 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;
}
