/**
 * Adds and removes classes to a list of links to allow keyboard accessibility
 *
 * @param string dropDownId
 * @param string hoverClass
 * @param int mouseOffDelay
 */
function dropdown(dropdownId, hoverClass, mouseOffDelay) {
	if(dropdown = document.getElementById(dropdownId)) {
		var listItems = dropdown.getElementsByTagName('li');
		for(var i = 0; i < listItems.length; i++) {
			listItems[i].onmouseover = function() { this.className = addClass(this); }
			listItems[i].onmouseout = function() {
				var that = this;
				setTimeout(function() { that.className = removeClass(that); }, mouseOffDelay);
				this.className = that.className;
			}
			
			var anchor = listItems[i].getElementsByTagName('a');
			anchor = anchor[0];
			anchor.onfocus = function() { tabOn(this.parentNode); }
			anchor.onblur = function() { tabOff(this.parentNode); }
		}
	}
	
	function tabOn(li) {
		if(li.nodeName == 'LI') {
			li.className = addClass(li);
			tabOn(li.parentNode.parentNode);
		}
	}
	
	function tabOff(li) {
		if(li.nodeName == 'LI') {
			li.className = removeClass(li);
			tabOff(li.parentNode.parentNode);
		}
	}
	
	function addClass(li) { return li.className + ' ' + hoverClass; }
	function removeClass(li) { return li.className.replace(hoverClass, ""); }
}

var theImages = new Array()
theImages[0] = 'banner_image_1.jpg'
theImages[1] = 'banner_image_2.jpg'
theImages[2] = 'banner_image_3.jpg'
theImages[3] = 'banner_image_4.jpg'
theImages[4] = 'banner_image_5.jpg'
theImages[5] = 'banner_image_6.jpg'

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++) {
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));

function showImage() {
   document.write('<img src="images/'+theImages[whichImage]+'" width="790" height="204" alt="Just Cruisin 4WD Tours" border="0">');
}

function validate_required(field, alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

function validate_options(field1, field2, alerttxt) {
	flag = false;
	
	with (field1) {
		if (value==null||value=="") {
			flag = false;
		} else {
			flag = true;
		}
	}
	
	if (flag == false) {
		with (field2) {
			if (value==null||value=="") {
				flag = false;
			} else {
				flag = true;
			}
		}
	}
	
	if (flag == false) {
		alert(alerttxt);
		return false;
	} else {
		return true;
	}
}

function validate_form(thisform) {
	with (thisform) {
		if (validate_required(full_name, "Name must be filled out")==false) {
			full_name.focus();
			return false;
		}
		if (validate_options(phone, email, "Phone or Email must be filled out")==false) {
			phone.focus();
			return false;
		}
	}
}
