//Navigation Bar
var OFFSET = 3;
function ddMenu(id, dir)
{
	var h = document.getElementById('ddheader-' + id);
	var c = document.getElementById('ddcontent-' + id);

	function hide_menu()
	{
		c.style.display = 'none';
		h.style.border = '1px dotted #9A0000';
	}
	
	if(dir==1)
	{
		clearTimeout(c.timer);
		c.style.display = 'block';
		h.style.border = '1px solid #9A0000';
		c.style.left = h.offsetWidth + OFFSET + 'px';
	}

	if (dir==-1)
	{
		c.timer = setTimeout(hide_menu, 100);
	}
}

function fade(i, pre, prefix) 
{
	if(pre==-1)
	{
		n=document.getElementById(prefix + i);
		n.style.display = 'block';
		n.style.opacity = '1';
		n.style.filter = '100';
	}
	else
	{
		p=document.getElementById(prefix + pre);
		n=document.getElementById(prefix + i);
		p.style.display = 'none';
		n.style.display = 'block';
		n.style.opacity = '1';
		n.style.filter = '100';
	}
}

function hide(id)
{	
	var div = document.getElementById(id);
	div.style.display = 'none';
}


//The following is for the main_form

var ajaxUrl = 'form_processor.php';

function watchForm(){
	Event.observe($('main_form'), 'submit', function(event) {
		Event.stop(event);
		checkForm();
	});
}

function checkForm(){
	errors = 0;
	
	if($('FirstName').value == ""){
		new Effect.Highlight($('FirstName'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('LastName').value == ""){
		new Effect.Highlight($('LastName'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('StreetAddress').value == ""){
		new Effect.Highlight($('StreetAddress'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('City').value == ""){
		new Effect.Highlight($('City'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('State').value == ""){
		new Effect.Highlight($('State'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('Zip').value == ""){
		new Effect.Highlight($('Zip'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
	if($('PhoneNumber').value == ""){
		new Effect.Highlight($('PhoneNumber'),{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		errors++;
	}
		
	email = $('email');
	if(email.value.indexOf("@") <= 1 || email.value.indexOf(" ") >= 1 || email.value.indexOf(".") <= 1 || email.value == ""){
		new Effect.Highlight(email,{startcolor:'#F0BBC4', endcolor:'#f0f0f0', duration: '8.0'});
		email.focus();
		errors++;
	}

	if(errors == 0){
		runAjax('main_form');
	}
	else {
		alert("Please fill in the form completely and try again.");
	}

	return false;
}

function runAjax(formID){	
	//query = "";
	$(formID).request({ onComplete: function() {
		alert("Thank You for reserving your ticket(s).  You will receive a confirmation email shortly.")
		new Effect.DropOut("Form");
	} });

	//var myAjax = new Ajax.Updater(ajaxUrl, {method: 'POST', postBody: query, onComplete: function(){
	//	alert("Thank you");
	//}});
	return false;
}
