/* Maskierte E-Mail Adresse dekodieren */
function mask(n,d,txt) {
	if(txt == ''){ txt = n+"@"+d; }
	var string = "<a href='"+"ma"+"ilt"+"o:"+n+"@"+d+"'>"+txt+"<\/a>";
	document.write(string);
}

decodeMailLink = function (obj,name,domain,sub,text)
{
	var params = '';
	if(typeof(sub) 	!= 'undefined' && sub.length>0){params = '?subject='+sub;}
	if(typeof(text)	!= 'undefined' && text.length>0){params += ((params.length==0)?'?':'&')+'body='+text;}
	if(sub.search(/\?/)>-1){params= sub;}//Compatibility to older encodings
	obj.href = unescape('%6D%61%69%6C%74%6F%3A')+name+unescape('%40')+domain+params;
}

/* Kalender an der Richtigen Stelle anzeigen */
function ShowCalendar(e,id){
    var obj = document.getElementById(id);
    if(typeof(obj) == 'undefined'){ return false; }

    //Soll der Kalender ausgeblendet werden?
    if(obj.style.display == 'block'){
        obj.style.display = 'none';
        return false;
    }
    //Kalender positionieren und anzeigen
    obj.style.left 		= (Mouse.positionX+15)+'px';
    obj.style.top 		= (Mouse.positionY+5)+'px';
    obj.style.display 	= 'block';
    return true;
}

function displayNone (id) {
  document.getElementById(id).style.display = "none";
}

/* Funktionen fuer die Datumsuebergaben im Ticketshop*/
function setDateStart(y,m,d,id) {

	var jj = document.getElementById('jj');
	var mm = document.getElementById('mm');
	var tt = document.getElementById('tt');

	refreshDateAbreise(y,m,d);//AbreiseDatum aktualisieren

	var objDate = document.getElementById(id);
	if(typeof(objDate) == 'undefined'){ return false; }

	//Datum zurueckschreiben
	objDate.value = d+'.'+m+'.'+y;

	jj.value = y;
	mm.value = m;
	tt.value = d;
	document.getElementById('flashCalendarStartDate').style.display = 'none';
	document.forms['shop'].submit();
}


/* Funktionen fuer die Datumsuebergaben */
function setDateAnkunft(y,m,d,id) {

	var jj = document.getElementById('jj');
	var mm = document.getElementById('mm');
	var tt = document.getElementById('tt');

	refreshDateAbreise(y,m,d);//AbreiseDatum aktualisieren

	var objDate = document.getElementById(id);
	if(typeof(objDate) == 'undefined'){ return false; }

	//Datum zurueckschreiben
	objDate.value = d+'.'+m+'.'+y;

	jj.value = y;
	mm.value = m;
	tt.value = d;
	document.getElementById('flashCalendarAnkunft').style.display = 'none';
}

//Automatisches setzen des Abreisedatums, falls moeglich
function refreshDateAbreise(y,m,d){
	var jj1 = document.getElementById('jj1').value*1;
	var mm1 = document.getElementById('mm1').value*1;
	var tt1 = document.getElementById('tt1').value*1;
	var anknunftsDate = new Date((y*1),((m*1)-1),(d*1),10,00);
	var currAbreiseDate = new Date(jj1,mm1-1,tt1,10,00);
	var currentDate = new Date();
	currentDate.setDate((currAbreiseDate.getDate()*1)-7);
	currentDate.setMinutes(currAbreiseDate.getMinutes());
	currentDate.setHours(currAbreiseDate.getHours());
	currentDate.setSeconds(currAbreiseDate.getSeconds());
	if(currAbreiseDate == currentDate
		|| anknunftsDate>=currAbreiseDate
	){
		var newAbreise = new Date((y*1),(m*1)-1,(d*1)+7,10,00);
		aM = String((newAbreise.getMonth()+1));
		aM = aM.replace(/^(\d){1}$/,'0$1');
		aD = String(newAbreise.getDate());
		aD = aD.replace(/^(\d){1}$/,'0$1');
		setDateAbreise(newAbreise.getFullYear(),aM,aD,'ferienpl_abreise');
	}
}


/* Funktionen fuer die Datumsuebergaben */
function setDateAbreise(y,m,d,id) {

	//BIS
	var jj1 = document.getElementById('jj1');
	var mm1 = document.getElementById('mm1');
	var tt1 = document.getElementById('tt1');

	var objDate = document.getElementById(id);
	if(typeof(objDate) == 'undefined'){ return false; }

	//Datum zur?ckschreiben
	objDate.value = d+'.'+m+'.'+y;

	jj1.value = y;
	mm1.value = m;
	tt1.value = d;

	document.getElementById('flashCalendarAbreise').style.display = 'none';
}


/* Funktion fuer den Popup-Aufruf vom Quick-Ferienplaner */
function QuickHoliday(formObj){
	if(!checkQuickHoliday()){
		return false;
	}

	if(formObj.target == '_blank'){
		return true;
	}
	//var QuickHoliday = window.open(formObj.action,'QuickHoliday','width=800,height=600,scrollbars=yes,resizable=no');
	if(openPopUp("about:blank",'QuickHoliday','95%','85%','scrollbars=yes,resizable=yes,location=no',true) !== false){
		formObj.target = 'QuickHoliday';
		return true;
	}
	formObj.target = '_blank';
	window.setTimeout('PopUpBlockerQuickHoliday()',5);
	return false;
}

function PopUpBlockerQuickHoliday(){
	document.getElementById('formFerien').submit();
}

function checkQuickHoliday(){
	var formObj = document.getElementById('ppr');
	if (formObj.value > 6 || isNaN(formObj.value)) {
		formObj.value = 6;
		alert("Es kann nur fuer max. 6 Personen ein Zimmer gebucht werden!");
		return false;
	}
	return true;
}

var PopUpSessions = new Object();
function openPopUp(href,wName,width,height,params,center,noReturn){
	if(params == 'undefined'){
		var params = '';
	}

	if(isNaN(width) && width.search(/%$/)!=-1){
		width = parseInt(width.replace(/%$/,''));
		width = Math.round(((width/100)*screen.availWidth));
	}
	if(isNaN(height) && height.search(/%$/)!=-1){
		height = parseInt(height.replace(/%$/,''));
		height = Math.round(((height/100)*screen.availHeight));
	}

	//Automatisch zentrieren
	if(center == true){
		var cLeft = (screen.availWidth - width) / 2;
		var cTop = (screen.availHeight - height) / 2;
		params = params.replace(/top=(\d{0,})/,'top='+cTop);
		if(isNaN(RegExp.$1) || RegExp.$1 == ''){
			params += ',top='+cTop;
		}
		params = params.replace(/left=(\d{0,})/,'left='+cLeft);
		if(isNaN(RegExp.$1) || RegExp.$1 == ''){
			params += ',left='+cLeft;
		}
	}
	if(!isNaN(width)){
		params += ',width='+width;
	}
	if(!isNaN(height)){
		params += ',height='+height;
	}
	params = params.replace(/\,\,/,',');
	params = params.replace(/((^\,)|(\,$))/,'');
	PopUpSessions[wName] = window.open(href,wName,params);
	if(typeof(PopUpSessions[wName]) == 'object' && PopUpSessions[wName] != null){
		PopUpSessions[wName].focus();
		if(noReturn != 'undefined'){
			return;
		}
		return PopUpSessions[wName];
	}
	alert(LANG['POPUP_BLOCKER']);
	if(noReturn != 'undefined'){
		return;
	}
	return false;
}


var calendarCtrl = new function(){
	this.flashID 				= 'xmlFormCalendar';
	this.currentCalendarField 	= false;
	this.currentFormat 			= false;
	this.standardFormat 		= 'D.M.Y';

	this.open = function(e,objID,format)
	{
		if(typeof(format)== 'undefined'){ var format = this.standardFormat; }
		this.currentCalendarField 	= objID;
		this.currentFormat 			= format;

		//Gibts das Feld?
	    if(this.getField() == false){ return false; }

	    //Soll der Kalender ausgeblendet werden?
	    if(this.getFlashLayer().style.display == 'block'){
	        this.hideFlash();
	        return false;
	    }
	    this.showFlash();
	}

	this.getField = function()
	{
		if((field = document.getElementById(this.currentCalendarField))){
			return  field;
		}
		return false;
	}

	this.getFlashLayer = function()
	{
		if((field = document.getElementById(this.flashID))){
			return field;
		}
		return false;
	}

	this.writeData = function(Y,M,D)
	{
		this.getField().value = this.parseFormat(Y,M,D);
		this.hideFlash();
	}

	this.parseFormat = function(Y,M,D)
	{
		//Aktuelles Format als Vorlage
		var value 	= this.currentFormat;
		//Alle Werte generieren
		var formats = new Object();
		formats.Y 	= Y;
		formats.y 	= Y.substr(Y.length-2,2);
		formats.m 	= Number(M);
		formats.M 	= (formats.m<10)?'0'+formats.m:formats.m;
		formats.d 	= Number(D);
		formats.D 	= (formats.d<10)?'0'+formats.d:formats.d;
		for(var format in formats){
			value = value.replace(format,formats[format]);
		}
		return value;
	}

	this.hideFlash = function()
	{
		this.getFlashLayer().style.display = 'none';
	}

	this.showFlash = function()
	{
//		Mouse.positionX = null;
//		Mouse.positionY = null;
//		//Kalender positionieren und anzeigen
//		
//		if(document.all){
//			if(!window.event || !document.body){
//				return;
//			}
//			Mouse.positionX = window.event.x + document.body.scrollLeft;
//			Mouse.positionY = window.event.y + document.body.scrollTop;
//		}else{
//			//Falls der schizo IE meint er sei ein FF
//			if(window.event){
//				return;
//			}
//			Mouse.positionX = e.pageX;
//			Mouse.positionY = e.pageY;
//		}	
		//alert (Mouse.positionX);
	    
	    //this.getFlashLayer().style.left 	= (Mouse.positionX+15)+'px';
	    //this.getFlashLayer().style.top 	= (Mouse.positionY+5)+'px';
	    this.getFlashLayer().style.display 	= 'block';
	}
}


/**************************************
Mouse Controller
****************************************/
Mouse = new Object();
Mouse.positionX = null;
Mouse.positionY = null;
Mouse.moinitoring = function (e)
{
	if(document.all){
		if(!window.event || !document.body){
			return;
		}
		Mouse.positionX = window.event.x + document.body.scrollLeft;
		Mouse.positionY = window.event.y + document.body.scrollTop;
	}else{
		//Falls der schizo IE meint er sei ein FF
		if(window.event){
			return;
		}
		Mouse.positionX = e.pageX;
		Mouse.positionY = e.pageY;
	}
}
document.onmousemove = Mouse.moinitoring;


/* Checkbox abfragen */
function checkCheckBox(obj,cvalue) {
	var id = obj.id.replace(/_\d{1,}$/,'');
    if (obj.checked) {
        document.getElementById(id).value=cvalue;
    } else{
        document.getElementById(id).value=0;
    } //IF
}

var timerInterval = false;
function timer(){
	if(timerInterval===false){
		timerInterval = window.setInterval('timer()',500);
	}
	var now = new Date();
	var seconds = now.getSeconds();
	var minutes = now.getMinutes();
	var hours 	= now.getHours();
	seconds	= (seconds<10)?'0'+seconds:seconds;
	minutes	= (minutes<10)?'0'+minutes:minutes;
	hours 	= (hours<10)?'0'+hours:hours;
	document.getElementById('currentTime').innerHTML = hours+':'+minutes+':'+seconds;
}
