/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (dave@gazingus.org)
 *
 * Originally from http://gazingus.org/dhtml/?id=109
 *
 * mfischer, 2003.05.07: reworked for own purposes
 * - Open menus with onmouseover event
 * - use timeout to closemenu when mouse not over
 * - renamed all identifier names so we've no namespace clashes
 *   (lwm - light weight menu)
 *
 * mfischer, 2003.05.08:
 * - use getPosition function to get left/top offset if menu is contained in other elements
 *
 * Last time tested: 2003.05.08:
 * Works in: MSIE55+, MacMSIE51, Win/Gecko, Win/Opera 7.1
 * 
 */

var lwmCurrentMenu = null;
var lwmMenuTimer = null;
var lwm_MENU_TIMER_TIMEOUT = 500;

function lwmInitMenu(menuId, triggerId) {
	var menu = document.getElementById(menuId);
	var trigger = document.getElementById(triggerId);

	if (menu == null || trigger == null) {
		return;
	}

	menu.onmouseover = function() {
		if (lwmMenuTimer == null) {
			return;
		}
		clearTimeout(lwmMenuTimer);
	}

	menu.onmouseout = function() {
		lwmMenuTimer = setTimeout('lwmTimerHideMenu()', lwm_MENU_TIMER_TIMEOUT);
	}

	trigger.onmouseover = function() {
		if (lwmCurrentMenu) {
			lwmCurrentMenu.style.visibility = 'hidden';
		}
		this.showMenu();

		if (lwmMenuTimer == null) {
			return;
		}
		clearTimeout(lwmMenuTimer);
	}

	trigger.onmouseout = function() {
		lwmMenuTimer = setTimeout('lwmTimerHideMenu()', lwm_MENU_TIMER_TIMEOUT);
	}

	trigger.showMenu = function() {
		var pos = lwmGetPosition(this);
		// Wierd MacMSIE5
		if (pos.top == 0) {
			pos.top = 10;
		}
		menu.style.left = pos.left + 'px';
		menu.style.top = pos.top + this.offsetHeight + 'px';
		menu.style.visibility = 'visible';
		lwmCurrentMenu = menu;
	}
}

function lwmTimerHideMenu() {
	if (lwmCurrentMenu) {
		lwmCurrentMenu.style.visibility = 'hidden';
	}
}

/* Originally from
 * http://www.faqts.com/knowledge_base/view.phtml/aid/9095/fid/128 , rewritten
 * for better readability */
			 
function lwmGetPosition(element) {
	var left = 0;
	var top = 0;
	while (element != null) {
		left += element.offsetLeft;
		top  += element.offsetTop;
		element = element.offsetParent;
	}
	return {left:left, top:top}
}


/* --- other stuff --- */
function checkFieldsContact(theForm) {
	var hasError = 0;
	theForm.realname.style.backgroundColor='#fff';
	theForm.email.style.backgroundColor='#fff';
	theForm.humancheck.style.backgroundColor='#fff';

	if (theForm.realname.value == '') {
    alert('Please enter your name.');
    theForm.realname.focus();
    theForm.realname.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.email.value == '') {
    alert('Please enter your e-mail address.');
    theForm.email.focus();
    theForm.email.style.backgroundColor='#f33';
		hasError = 1;
	}
  if (theForm.humancheck.value != 'corvette') {
    alert('You did not type the word corvette into the proper field.');
    theForm.humancheck.focus();
    theForm.humancheck.style.backgroundColor='#f33';
		hasError = 1;
  }
	if (hasError == 1) {
    return false;
	}
  return true;
}

function checkFields(theForm) {
	var hasError = 0;
	var errorFields = '';
	theForm.realname.style.backgroundColor='#fff';
	theForm.Address.style.backgroundColor='#fff';
	theForm.City.style.backgroundColor='#fff';
	theForm.State.style.backgroundColor='#fff';
	theForm.zipCode.style.backgroundColor='#fff';
	theForm.phoneNumber.style.backgroundColor='#fff';
	theForm.email.style.backgroundColor='#fff';
	theForm.humancheck.style.backgroundColor='#fff';

	if (theForm.realname.value == '') {
    alert('Please enter your name.');
    theForm.realname.focus();
    theForm.realname.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.Address.value == '') {
    alert('Please enter your mailing address.');
    theForm.Address.focus();
    theForm.Address.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.City.value == '') {
    alert('Please enter the city of your mailing address.');
    theForm.City.focus();
    theForm.City.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.State.value == '') {
    alert('Please enter the state of your mailing address.');
    theForm.State.focus();
    theForm.State.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.zipCode.value == '') {
    alert('Please enter the zip code of your mailing address.');
    theForm.zipCode.focus();
    theForm.zipCode.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.phoneNumber.value == '') {
    alert('Please enter your phone number.');
    theForm.phoneNumber.focus();
    theForm.phoneNumber.style.backgroundColor='#f33';
		hasError = 1;
	}
	if (theForm.email.value == '') {
    alert('Please enter your e-mail address.');
    theForm.email.focus();
    theForm.email.style.backgroundColor='#f33';
		hasError = 1;
	}
  if (theForm.humancheck.value != 'corvette') {
    alert('You did not type the word corvette into the proper field.');
    theForm.humancheck.focus();
    theForm.humancheck.style.backgroundColor='#f33';
		hasError = 1;
  }
	if (hasError == 1) {
    return false;
	}
  return true;
}
