// JavaScript Document
function CreateBookmarkLink(Title, URL) {
	if (window.sidebar) {
		window.sidebar.addPanel(Title, URL, "");
	} else if( window.external ) {
		window.external.AddFavorite(URL, Title);
	}
	return true;
}

function ID(id){
	return document.getElementById(id);
}

function visibility(id){
	id = ID(id);
	if (id.style.display == 'block' || !id.style.display){
		id.style.display = 'none';
		return;		
	}
	id.style.display = 'block';
	return;		
}

function changeImage(imgId, imgSrc, titleId, titleInnerHtml, mLink) {
	$(imgId).src = imgSrc;
	$(titleId).innerHTML = titleInnerHtml;	
	
	mParent = $(mLink).parentNode;
	
	for (i=0;i<mParent.childNodes.length;i++) {
		Try.these (
			function() {
				mParent.childNodes[i].className = '';	
			}	
		)
	}
	$(mLink).className = 'act';
	
}

function checkStep(id){
	id = ID(id);
	fields = new Array();
	if (!id.hasChildNodes()) return false;
	for (i=0; i<id.childNodes.length; ++i){
		if (!id.childNodes[i]) continue;
		if (id.childNodes[i].tagName == 'INPUT') {
			fields.push(id.childNodes[i].id);
		}
		if (!id.childNodes[i].hasChildNodes()) continue;
	
		for (ii=0; ii<id.childNodes[i].childNodes.length; ++ii){
			if (!id.childNodes[i].childNodes[ii]) continue;
			if (id.childNodes[i].childNodes[ii].tagName == 'INPUT') {
				fields.push(id.childNodes[i].childNodes[ii].id);
			}
			if (!id.childNodes[i].childNodes[ii].hasChildNodes()) continue;
			
			for (iii=0; iii<id.childNodes[i].childNodes[ii].childNodes.length; ++iii){
				if (!id.childNodes[i].childNodes[ii].childNodes[iii]) continue;
				if (id.childNodes[i].childNodes[ii].childNodes[iii].tagName == 'INPUT') {
					fields.push(id.childNodes[i].childNodes[ii].childNodes[iii].id);
				}
			}	
		}
	}
	for (i=0; i < fields.length; ++i) {
		if (fields[i].indexOf('_r') != -1 && ID(fields[i]).value.length <1) {
			ID(fields[i]).focus();
			return false;			
		}
	}
	
	if (document.getElementById('children').value.length > 0 && 
		document.getElementById('childAge').value.length < 1 ) {
		document.getElementById('childAge').focus();
		return false;
	}
	return true;
}


function bookNext(previous, id) {
	id = ID(id);
	
	 
	
	for (var step = id.parentNode; step.id.indexOf('step') == -1; step = step.parentNode );
	step = step.id;
	if (!checkStep(step) && previous != 1) {
		alert (errorString);
		return false;
	}
	
	if (step == 'step3') {
		if (!checkStep('step2')) {
			alert (errorString);
			
			return false;
		} else {
			visibility('step2');	
		}
	}
	
	visibility(step);
	step = step.substr(4);	
	(previous == 1) ? --step : ++step;
	if (ID('step'+step)) {
		visibility('step'+step);
	}
	return true;
}

function getRadioValue(formName, radioName) {
	radio = document.forms[formName][radioName];
	
	for (i=0; i<radio.length; ++i) {
		if (radio[i].checked) {
			return radio[i].value;
		}
	}
	return false;	
}

function setWindowTitle(title) {
	document.title = title;	
}

function toggleOpen(node) {
    node = document.getElementById(node);
    if (node.style.display === 'none') {
        node.style.display = 'block';
    } else {
        node.style.display = 'none';
    }
    return false;
}
function open_popup(w,h,url)
{
	x = screen.availWidth/2-w/2;
	y = screen.availHeight/2-h/2;
	var popupWindow = window.open(
		url,'','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=no');
}

function checkEmail(email){
	emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	if(emailRegExp.test(email)){
		return true;
	}else{
		return false;
	}
}

function newsletterSubmit() {	
	if (document.getElementById('newsletterName').value.length == 0 || document.getElementById('newsletterEmail').value.length == 0)
	{
		alert('Bitte füllen Sie alle Felder aus!');
	}
	else if (checkEmail(document.getElementById('newsletterEmail').value) == false)
	{
		alert('Bitte geben Sie eine gültige E-Mail Adresse an!');
	}
	else
	{
		ID('newsletterForm').submit();
	}
}
