/* JavaScript-Datei fuer Ticket Compliments */

try {
document.execCommand('BackgroundImageCache', false, true);
} catch (e) {}

/* Formulareeingaben pruefen */
function checkForm(formname, werte) {
	var fields = new Array();
	var check = 0;
	var email_regex = /^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})$/;
	var check_email = -1;

	for (var i=0; i<werte.length; i++) {
		fields[i] = document[formname][werte[i]].value;
	}

	for (var i=0; i<fields.length; i++) {
		if (fields[i] == "") {
			alert('Sie müssen alle mit * gekennzeichneten Felder ausfüllen!');
			return false;
		} else {
			check++;
		}
		if (werte[i] == 're_email') {
			check_email = fields[i].search(email_regex);
			if (check_email == -1) {
				alert('Bitte tragen Sie eine korrekte E-Mail-Adresse ein.');
				return false;
			}
		}
	}
	if (check == werte.length) {
		return true;
	} else {
		return false;
	}
}

// Funktion zum Unterbinden von Mehrfachausfuehrungen
var only_once_list = new Array();
function only_once(obj) {
	if(only_once_list[obj.name] == 1) {
		return true;
	}
	if(obj.href) {
		obj.disabled;
		if(obj.style) {
			obj.style.color = "#999999";
			obj.style.textDecoration = "none";
			obj.style.cursor = 'wait';
		}
		return true;
	}
	for(var i = 0; ; i++) {
		if(!obj[i]) { break; }
		if(obj[i].type != 'button' && obj[i].type != 'submit') { continue; }
		if(obj[i].name == 'execonce') {
			obj[i].disabled;
			if(obj[i].style) {
				obj[i].style.backgroundColor = "#CCCCCC";
				obj[i].style.color = "#999999";
				obj[i].style.border = "solid #999999 1px";
			}
		}
	}
	only_once_list[obj.name] = 1;
	return true;
}

// Funktion fuer die Weiterempfehlung
function recommendation() {
	document.getElementById('link').style.display = "none";
	document.getElementById('form').style.display = "block";
	document.emailform.url.value = location.href;
	document.emailform.nachricht.innerHTML = "Hallo,\nich m?chte Ihnen gerne die folgende Webseite des Ticket Restaurant weiterempfehlen:\n\nhttp://www.ticketrestaurant.de\n\nDort finden Sie interessante Infos zu Fehlsichtigkeiten, Lasertechnologien und Behandlungsmethoden.\n\nViel Spass beim Surfen.";
	location.href += "#form";
	return false;
}

function recommendation_check(formname, werte) {
	for (var i=0; i<werte.length; i++) {
		var email = document[formname][werte[i]].value;
		var email_check = email.search(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/);
		if (email_check == -1) {
			alert('Bitte tragen Sie eine korrekte E-Mail-Adresse ein!\nFalsche E-Mail-Adresse: ' + email);
			return false;
		}
	}
	return true;
}

// Darstellen/Verstecken von News auf Contentseiten
var news_array = new Array();
function show_news(news_id) {
	for(i=0; i<news_array.length; i++) {
		document.getElementById('news'+news_array[i]).style.display = "none";
		//document.getElementById('news'+news_array[i]).style.visibility = "hidden";
		document.getElementById('header'+news_array[i]).className = "";
	}
	document.getElementById('news'+news_id).style.display = "block";
	//document.getElementById('news'+news_id).style.visibility = "visible";
	document.getElementById('header'+news_id).className = "active";
	//document.getElementById('firstinfo').style.display = 'none';
}

// Funktion, um E-Mail zu verbergen
function openmailurl(prefix, postfix) {
	location.href= 'mailto:' + prefix + '@' + postfix;
}


// Funktion für die Logo-Parade
var old_number1 = 0, old_number2 = 0;
var new_number1 = 0, new_number2 = 0;
function partnerlogo() {
	if($("#partner_widget").attr("id")) {
		$("#partner_widget").fadeOut("slow", function(){
			// neue Zahl fuer das 1. Bild ermitteln (darf nicht eines der beiden vergangenen Logos sein)
			while(new_number1 == old_number1 || new_number1 == old_number2) {
				new_number1 = Math.floor(Math.random()*37);
			}
			// neue Zahl fuer das 2. Bild ermitteln (darf nicht eines der beiden vergangenen Logos sein UND auch nicht das gerade erzeugte 1. Bild)
			while(new_number2 == old_number1 || new_number2 == old_number2 || new_number2 == new_number1) {
				new_number2 = Math.floor(Math.random()*37);
			}
			$("#" + this.id + " img:eq(0)").attr("src", "/images/partnerlogos/alle_partner/" + new_number1 + ".gif");
			$("#" + this.id + " img:eq(1)").attr("src", "/images/partnerlogos/alle_partner/" + new_number2 + ".gif");
			$("#" + this.id).fadeIn("slow");
			old_number1 = new_number1;
			old_number2 = new_number2;
	
		});
		window.setTimeout("partnerlogo()", 5000);
	}
}

var bg_pos = 0;
function init_content_bg() {
	bg_pos = $("#content").width();
	//window.setInterval("move_content_bg()", 5000);
}

function move_content_bg() {
	// neuen Wert der x-Position berechnen
	var temp_pos = $("#content").css( "backgroundPosition" );
	temp_pos = temp_pos.split(" ");
	temp_pos[0] = parseInt(temp_pos[0].replace(/px/, ""));
	temp_pos[0] -= bg_pos;
	temp_pos = temp_pos[0] + "px " + temp_pos[1];
	// Animation durchführen
	$("#content").animate({ backgroundPosition: temp_pos }, 800);
}

$(document).ready(
	function() {
		// Karussell nur auf der Startseite starten
		if(document.getElementById("carussell")) {
			initCaroussell();
		}

		partnerlogo();
		/*init_content_bg();

		$('.kwicks').kwicks({  
			min : 185,
			spacing : 2,
			isVertical : false,
			sticky : true
		});
		$("#kwick2").trigger("mouseover");
		$("#kwick1").trigger("mouseover");*/
	
	/* Suchformular leeren und wieder 'Suchen' einsetzen, wenn es leer bleibt */
	$('#words').focus(function(){
		if ($(this).val() == 'Suchen') {
			$(this).val('');
		}
	});
	
	$('#words').blur(function(){
		if ($(this).val() == '') {
			$(this).val('Suchen');
		}
	});
	
	
	//Kontaktformular 'Business'	
	$('#toggle_kontakt_business').click(
		function() {
			if ($("#contactform_endkunden").css('display') == 'block') {
				$('#contactform_endkunden').slideToggle(1000);
				$('#toggle_kontakt_endkunden a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_endkunden a img').attr('width', '11');
				$('#toggle_kontakt_endkunden a img').attr('height', '13');
			}
			if ($("#contactform_partner").css('display') == 'block') {
				$('#contactform_partner').slideToggle(1000);
				$('#toggle_kontakt_partner a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_partner a img').attr('width', '11');
				$('#toggle_kontakt_partner a img').attr('height', '13');
			}
   			$('#contactform_business').slideToggle(1000);               
			if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_kontakt.gif'){
					$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_gedreht_kontakt.gif');
					$(this).children('a').children('img').attr('width', '13');
					$(this).children('a').children('img').attr('height', '11');
			} else {
				$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$(this).children('a').children('img').attr('width', '11');
				$(this).children('a').children('img').attr('height', '13');
			}
			
			this.blur();
			return false;
		}
	);	
	
	//Kontaktformular 'Endkunden'
	$('#toggle_kontakt_endkunden').click(
		function() {
   			if ($("#contactform_business").css('display') == 'block') {
				$('#contactform_business').slideToggle(1000);
				$('#toggle_kontakt_business a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_business a img').attr('width', '11');
				$('#toggle_kontakt_business a img').attr('height', '13');
			}
			if ($("#contactform_partner").css('display') == 'block') {
				$('#contactform_partner').slideToggle(1000);
				$('#toggle_kontakt_partner a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_partner a img').attr('width', '11');
				$('#toggle_kontakt_partner a img').attr('height', '13');
			}
   			$('#contactform_endkunden').slideToggle(1000);               
			if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_kontakt.gif'){
					$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_gedreht_kontakt.gif');
					$(this).children('a').children('img').attr('width', '13');
					$(this).children('a').children('img').attr('height', '11');
			} else {
				$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$(this).children('a').children('img').attr('width', '11');
				$(this).children('a').children('img').attr('height', '13');
			}
			
			this.blur();
			return false;
		}
	);	
	
	//Kontaktformular 'Partner'
	$('#toggle_kontakt_partner').click(
		function() {	
   			if ($("#contactform_business").css('display') == 'block') {
				$('#contactform_business').slideToggle(1000);
				$('#toggle_kontakt_business a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_business a img').attr('width', '11');
				$('#toggle_kontakt_business a img').attr('height', '13');
			}
			if ($("#contactform_endkunden").css('display') == 'block') {
				$('#contactform_endkunden').slideToggle(1000);
				$('#toggle_kontakt_endkunden a img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$('#toggle_kontakt_endkunden a img').attr('width', '11');
				$('#toggle_kontakt_endkunden a img').attr('height', '13');
			}
   			$('#contactform_partner').slideToggle(1000);               
			if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_kontakt.gif'){
					$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_gedreht_kontakt.gif');
					$(this).children('a').children('img').attr('width', '13');
					$(this).children('a').children('img').attr('height', '11');
			} else {
				$(this).children('a').children('img').attr('src', '/images/buttons/doppelpfeil_gr_kontakt.gif')
				$(this).children('a').children('img').attr('width', '11');
				$(this).children('a').children('img').attr('height', '13');
			}
			
			this.blur();
			return false;
		}
	);	
	
		
	$('[id^=toggle_logos_universal_]').click(
		function() {
			$(this).next("[id^=logos_universal_]").slideToggle(1000);
			if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_kontakt.gif'){
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_gedreht_kontakt.gif',
					width : '13',
					height : '11'
				});
			} else {
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_kontakt.gif',
					width : '11',
					height : '13'
				});
			}

			this.blur();
			return false;
		}
	);	
	
	
	$('[id^=toggle_mailing_]').click(
		function() {
			$(this).next("[id^=text_mailing_]").slideToggle('fast');
			if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_violett.gif'){
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_gedreht_violett.gif',
					width : '13',
					height : '11'
				});
			} else if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_gedreht_violett.gif'){
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_violett.gif',
					width : '11',
					height : '13'
				});
			}else if ($(this).children('a').children('img').attr('src') == '/images/buttons/doppelpfeil_gr_blau.gif'){
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_gedreht_blau.gif',
					width : '13',
					height : '11'
				});
			} else {
				$(this).children('a').children('img').attr({
					src : '/images/buttons/doppelpfeil_gr_blau.gif',
					width : '11',
					height : '13'
				});
			}

			this.blur();
			return false;
		}
	);	
	
	
	$('#toggle_kontakt_endkunden, #toggle_kontakt_partner, #toggle_kontakt_business , [id^=toggle_logos_universal_], .mailing_toggle_areas' ).hover(
		function () {
			$(this).css({'cursor' : 'pointer', 'background-image' : 'url(/images/verlauf_kontakt_hover.gif)'});
		}, 
		function () {
			$(this).css({'cursor' : 'default', 'background-image' : 'url(/images/verlauf_kontakt.gif)'});
		}
	);
	
	//hover-Effekte für versch. Elemente
	$('.contactform .form_image').hover(
		function () {
			$(this).css({'background-position' : '0px -13px'});
		}, 
		function () {
			$(this).css({'background-position' : '0px 0px'});
		}
	);
	
	$('#search .form_image').hover(
		function () {
			$(this).css({'background-position' : '0px -13px'});
		}, 
		function () {
			$(this).css({'background-position' : '0px 0px'});
		}
	);
	
	$('#carussell').hover(
		function () {
			$(this).css({'background-position' : '0px -91px', 'cursor' : 'pointer'});
			$(this).children('.karusselllink').css({'text-decoration' : 'underline'});
		}, 
		function () {
			$(this).css({'background-position' : '0px 0px' , 'cursor' : 'default'});
			$(this).children('.karusselllink').css({'text-decoration' : 'none'});
		}
	);
	
	$('#carussell_praemien #carussell').hover(
		function () {
			$(this).css({'background-position' : '0px 0px', 'cursor' : 'default'});
		}, 
		function () {
			$(this).css({'background-position' : '0px 0px' , 'cursor' : 'default'});
		}
	);
	
	$('#carussell_alle_partner #carussell').hover(
		function () {
			$(this).css({'background-position' : '0px 0px', 'cursor' : 'default'});
		}, 
		function () {
			$(this).css({'background-position' : '0px 0px' , 'cursor' : 'default'});
		}
	);
	
	$('#content_portal_right div').each(function() {
		$(this).hover(
			function () {
				$(this).css({'background' : 'url(/images/verlauf_unten.gif) repeat-x 0px bottom', 'cursor' : 'pointer'});
			}, 
			function () {
				$(this).css({'background' : 'none' , 'cursor' : 'default'});
			}
		);
	});
	
	//<br> fuer Listenelemente werden ausgebelndet, damit 'komfortabel' in arketect-Textblöcke Listenelemente eingesetzt werden können.
	$('#content ul > br').css('display', 'none');
	
	$('body.mailing #content_right div img.teaser_header_shadow').css('width','255px');
		
});