// JavaScript Document

var fcn = {
    basePath: window.basePath,
    forwardPath: '',
    
    signupNewsletter: function(){
        var parameters = {
            method: 'post',
            postBody: 'email=' + $F('newsletterEmail')
        };
        new Ajax.Updater('newsletterStatus', fcn.basePath + 'backend/action.php?action=newsletter', parameters);
    },
    
    forwardPage: function(){
        window.open(fcn.forwardPath, '', 'width=400, height=260');
    },
    
	printPage: function(){
		window.print();
	},
	
    addToBookmarks: function(){
        if (document.all) {
            window.external.AddFavorite(location.href, document.title);
        } else if (window.sidebar) {
            window.sidebar.addPanel(document.title, location.href, '');
        }
    },
    
    bookingRequest: function(){
        $('bookingForm').submit();
    },
    
    openBigImage: function(e){
        parameters = {
			method: 'post',
			postBody: 'imageId='+e.element().id
		};
        new Ajax.Updater('image', fcn.basePath+'backend/action.php?action=getImage', parameters)
    },
    
    checkForm: function(e){
        e.stop();
        var form = e.element();
        var fields = ['name', 'email', 'subject', 'message'];
        var check = true;
        var fieldId = '';
        for (var i = 0; i < fields.length; ++i) {
            fieldId =['form',form.id,fields[i]] .join('_');
            if (!document.getElementById(fieldId)) {
                continue;
            }
            if (document.getElementById(fieldId).value.length < 1) {
                document.getElementById([fieldId, 'error'].join('_')).style.display = 'block';
                check = false;
            } else {
                document.getElementById([fieldId, 'error'].join('_')).style.display = 'none';
            }
        }
        
        if (check === true) {
            form.submit();
        }
        return false;
    }
};
function checkForm(formID){
    myForm = document.getElementById(formID);
    if (typeof(myForm) != "object") 
        return false;
    myElements = myForm.elements;
    myError = new Array();
    for (f = 0; f < myElements.length; f++) {
        myElement = myElements[f];
        if (myElement.id.indexOf('_req') != -1) {
            // REQUIRED FIELD
            if (myElement.value == "" || (myElement.type == "checkbox" && myElement.checked != true)) {
                myError.push(myElement);
            }
        }
    }
    if (myError.length > 0) {
        alert("Bitte füllen Sie alle Pflichtfelder aus!");
        myError[0].focus();
        return false;
    } else {
        return true;
    }
    return false;
}
function breakfast(value)
{
	var ap = value.charAt(0);
	if(ap == 0)
	{
		document.getElementById('fooddiv').innerHTML = "<select name=\"food\" id=\"food\" style=\"width: 165px;\"><option name=\"breakfast\" value=\"Zimmer mit Frühstück\">Zimmer mit Fr&uuml;hst&uuml;ck</option></select>";
	}
	if(ap == 1)
	{
		document.getElementById('fooddiv').innerHTML = "<select name=\"food\" id=\"food\" style=\"width: 165px;\"><option name=\"none\" value=\"none\"></option><option name=\"breakfast\" value=\"Appartement mit Frühstück\">Appartement mit Fr&uuml;hst&uuml;ck</option></select>";
	}
}