/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   mygosuMenu
 * VERSION:   1.3.3
 * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
 * LINK:      http://gosu.pl/dhtml/mygosumenu.html
 * LICENSE:   BSD (revised)
 */

function ClickShowHideMenu(id) {
    this.box1Hover = true;
    this.box2Hover = true;
    this.highlightActive = false;

    this.init = function() {
        if (!document.getElementById(this.id)) {
            alert("Element '"+this.id+"' does not exist in this document. ClickShowHideMenu cannot be initialized");
            return;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
        this.load();
        if (window.attachEvent) {
            window.attachEvent("onunload", function(e) { self.save(); });
        } else if (window.addEventListener) {
            window.addEventListener("unload", function(e) { self.save(); }, false);
        }
    }
    this.closeAll = function() {
        var id_openbox = this.cookie.get(this.id);
        if (id_openbox) {
            this.hide(id_openbox);
            document.getElementById(id_openbox).className = "box1";
        }
    }
    this.parse = function(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].className) {
                if ("box1" == nodes[i].className.substr(0, 4)) {
                    nodes[i].id = id + "-" + tree.length;
                    tree[tree.length] = new Array();
                    eval('nodes[i].onmouseover = function() { self.box1over("'+nodes[i].id+'"); }');
                    eval('nodes[i].onmouseout = function() { self.box1out("'+nodes[i].id+'"); }');
                    eval('nodes[i].onclick = function() { self.box1click("'+nodes[i].id+'"); }');
                }
                if ("section" == nodes[i].className) {
                    id = id + "-" + (tree.length - 1);
                    nodes[i].id = id + "-section";
                    tree = tree[tree.length - 1];
                }
                if ("box2" == nodes[i].className.substr(0, 4)) {
                    nodes[i].id = id + "-" + tree.length;
                    tree[tree.length] = new Array();
                    eval('nodes[i].onmouseover = function() { self.box2over("'+nodes[i].id+'", "'+nodes[i].className+'"); }');
                    eval('nodes[i].onmouseout = function() { self.box2out("'+nodes[i].id+'", "'+nodes[i].className+'"); }');
                }
            }
            if (this.highlightActive && nodes[i].tagName && nodes[i].tagName == "A") {
                if (document.location.href == nodes[i].href) {
                    nodes[i].className = (nodes[i].className ? ' active' : 'active')
                }
            }
            if (nodes[i].childNodes) {
                this.parse(nodes[i].childNodes, tree, id);
            }
        }
    }

    this.box1over = function(id) {
        if (!this.box1Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = (this.id_openbox == id ? "box1-open-hover" : "box1-hover");
    }

    this.box1out = function(id) {
        if (!this.box1Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = (this.id_openbox == id ? "box1-open" : "box1");
    }

    this.box1click = function(id) {
        if (!document.getElementById(id)) {
            return;
        }
        var id_openbox = this.id_openbox;
        if (this.id_openbox) {
            if (!document.getElementById(id + "-section")) {
                return;
            }
            this.hide();
            if (id_openbox == id) {
                if (this.box1hover) {
                    document.getElementById(id_openbox).className = "box1-hover";
                } else {
                    document.getElementById(id_openbox).className = "box1";
                }
            } else {
                document.getElementById(id_openbox).className = "box1";
            }
        }
        if (id_openbox != id) {
            this.show(id);
            var className = document.getElementById(id).className;
            if ("box1-hover" == className) {
                document.getElementById(id).className = "box1-open-hover";
            }
            if ("box1" == className) {
                document.getElementById(id).className = "box1-open";
            }
        }
    }

    this.box2over = function(id, className) {
        if (!this.box2Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = className + "-hover";
    }

    this.box2out = function(id, className) {
        if (!this.box2Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = className;
    }

    this.show = function(id) {
        if (document.getElementById(id + "-section")) {
            document.getElementById(id + "-section").style.display = "block";
            this.id_openbox = id;
        }
    }

    this.hide = function() {
        document.getElementById(this.id_openbox + "-section").style.display = "none";
        this.id_openbox = "";
    }

    this.save = function() {
        if (this.id_openbox) {
            this.cookie.set(this.id, this.id_openbox);
        } else {
            this.cookie.del(this.id);
        }
    }

    this.load = function() {
        var id_openbox = this.cookie.get(this.id);
        if (id_openbox) {
            this.show(id_openbox);
            document.getElementById(id_openbox).className = "box1-open";
        }
    }

    function Cookie() {
        this.get = function(name) {
            var cookies = document.cookie.split(";");
            for (var i = 0; i < cookies.length; i++) {
                var a = cookies[i].split("=");
                if (a.length == 2) {
                    a[0] = a[0].trim();
                    a[1] = a[1].trim();
                    if (a[0] == name) {
                        return unescape(a[1]);
                    }
                }
            }
            return "";
        }
        this.set = function(name, value) {
            document.cookie = name + "=" + escape(value);
        }
        this.del = function(name) {
            document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Array();
    this.cookie = new Cookie();
    this.id_openbox = "";
}

if (typeof String.prototype.trim == "undefined") {
    String.prototype.trim = function() {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}

/*
function validate2() 
{
	
notValid = false;

var errorAlert = document.getElementById('communicate');

alert(document.reserve.elements[0]);

var i=1;

for( i=1; i< document.reserve.elements.length;i++)
{
	alert(document.reserve.elements[i].value);
	
	if(document.reserve.elements[i].value == '')
	{
		alert('ss');

		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		red = document.getElementById(document.reserve.options[i].value);
		red.style.color = 'red';
		
		notValid = true;
	
		
	}
	else
	{
		red = document.getElementById(document.reserve.options[i].value);
		red.style.color = 'black';	
	}
	
}


}
*/

function validate() {


notValid = false;

var errorAlert = document.getElementById('communicate');

selIndex = document.reserve.persons.selectedIndex;
howMany = document.reserve.persons.options[selIndex];

//alert(howMany.value);

if(howMany.value == 'single')
{

	mNv=document.reserve.name.value;
	
	if (mNv=='') {
		
		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		red = document.getElementById('name_span');
		red.style.color = 'red';
		
		notValid = true;
	
			
	}
	else
	{
		red = document.getElementById('name_span');
		red.style.color = 'black';	
	}
	
	address = document.reserve.address.value;
	
	if (address=='') {
		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		red = document.getElementById('address_span');
		red.style.color = 'red';
		
		notValid = true;
		
	}
	else
	{
		red = document.getElementById('address_span');
		red.style.color = 'black';	
	}
	
	tel = document.reserve.tel.value;
	
	if (tel=='') {
		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		red = document.getElementById('tel_span');
		red.style.color = 'red';
		
		notValid = true;
		
	}
	else
	{
		red = document.getElementById('tel_span');
		red.style.color = 'black';	
	}

}
else if(howMany.value == 'extended')
{
	person_amount = 4;

	personNotComplete = false;

	for(var i=1; i <= person_amount; i++)
	{
		

		var nameValue = document.reserve['name'+i].value;
		var addressValue = document.reserve['address'+i].value;
		var languageValue = document.reserve['language'+i].value;
		var telephoneValue = document.reserve['tel'+i].value;

		var name = document.reserve['name'+i];
		var address = document.reserve['address'+i];
		var language = document.reserve['language'+i];
		var telephone = document.reserve['tel'+i];

		var name_span = document.getElementById('name'+i+'_span');
		var address_span = document.getElementById('address'+i+'_span');
		var language_span = document.getElementById('language'+i+'_span');
		var telephone_span = document.getElementById('tel'+i+'_span');

		if(nameValue != '' && addressValue != '' && languageValue != '' && telephoneValue != '' )
		{
			
			name.style.border = '';
			
			address.style.border = '';
			
			language.style.border = '';
			
			telephone.style.border = '';
			
			name_span.style.color = 'black';
			address_span.style.color = 'black';
			language_span.style.color = 'black';
			telephone_span.style.color = 'black';
			
			person = true;	
		}
		else if(nameValue == '' && addressValue == '' && languageValue == '' && telephoneValue == '' )
		{
			person = false;
		}
		else
		{
			name.style.border = '2px solid red';
			
			address.style.border = '2px solid red';
			
			language.style.border = '2px solid red';
			
			telephone.style.border = '2px solid red';
			
			name_span.style.color = 'black';
			address_span.style.color = 'black';
			language_span.style.color = 'black';
			telephone_span.style.color = 'black';
			
			personNotComplete = true;
		}
	
	
	}

	
	if (personNotComplete)
	{
		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		notValid = true;
	}
}
//alert(document.reserve.select1.options);

weeks = document.reserve.weeks.value;
	
if (weeks=='') {
	errorAlert.style.display = "block";
	errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
	
	red = document.getElementById('weeks_span');
	red.style.color = 'red';
	
	notValid = true;
	
}
else
{
	red = document.getElementById('weeks_span');
	red.style.color = 'black';	
}

departure= document.reserve.departure.value;
	
if (departure=='') {
	errorAlert.style.display = "block";
	errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
	
	red = document.getElementById('departure_span');
	red.style.color = 'red';
	
	notValid = true;
	
}
else
{
	red = document.getElementById('departure_span');
	red.style.color = 'black';	
}

email= document.reserve.email.value;
	
if (email=='') {
	errorAlert.style.display = "block";
	errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
	
	red = document.getElementById('email_span');
	red.style.color = 'red';
	
	notValid = true;
	
}
else
{
	red = document.getElementById('email_span');
	red.style.color = 'black';	
}

var select_amount = 2;


for(var i=1; i <= select_amount; i++)
{
	var selectIndex = document.reserve['select'+i].selectedIndex;
	var opcja1 = document.reserve['select'+i].options[selectIndex];
	
	if (opcja1.innerHTML=='' || opcja1.innerHTML=='Wybierz opcje') {
		errorAlert.style.display = "block";
		errorAlert.innerHTML = 'Uzupełnij wszystkie wymagane pola';
		
		red = document.getElementById('select'+i+'_span');
		red.style.color = 'red';
		
		notValid = true;
		
	
	}
	else
	{
		red = document.getElementById('select'+i+'_span');
		red.style.color = 'black';	
	}
}


if(!notValid)
	document.reserve.submit();

}

function showForm(selectTag)
{
	
	var whichForm = selectTag.options[selectTag.selectedIndex];
	
	//alert(whichForm.value);
	
	if(whichForm.value == 'single')
	{
		document.getElementById('one').style.display = "block";
		document.getElementById('more').style.display = "none";
	
	}
	else if(whichForm.value == 'extended')
	{			
		document.getElementById('more').style.display = "block";
		document.getElementById('one').style.display = "none";
		
	}
}	

