// SITE FUNCTIONS 
// CREATED 6/29/2004
// BY James Gibson

// Updated May 17, 2005
// By Jordan Roher

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}

// if (window.attachEvent) window.attachEvent("onload", sfHover);

function inputFocus(element, message) {
	if(!document.getElementById(element).value) {
		document.getElementById(element).value = message;
		tempElement = document.getElementById(element);
		tempElement.className = 'light';
	}
	else {
		if(document.getElementById(element).value == message) {
			document.getElementById(element).value = '';
			tempElement = document.getElementById(element);
			tempElement.className = 'dark';
		}
		else {
			tempElement = document.getElementById(element);
			tempElement.className = 'dark';
		}
	}
}

function inputFocusList(element, message) {
	if(!document.getElementById(element).value) {
		document.getElementById(element).value = '';
		tempElement = document.getElementById(element);
		tempElement.className = 'dark';
	}
	else {
		if(message.indexOf(document.getElementById(element).value) != -1) {
			document.getElementById(element).value = '';
			tempElement = document.getElementById(element);
			tempElement.className = 'dark';
		}
		else {
			tempElement = document.getElementById(element);
			tempElement.className = 'dark';
		}
	}
}

// submits a form to itself
function submitForm(form, action) {
	form.action = action;
	form.submit();
}

function fieldFocus(element) {
	document.getElementById(element).focus();
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
		theForm[z].checked = theElement.checked;
		z++;
	}
}

function cancelForm(action) {
	window.location.href = action;
}

function toggleDiv(id) {
	element = document.getElementById(id);
	element.className = (element.className.toLowerCase() == 'show'?'hide':'show');
}

function toggleButton(buttonID,inputFocusID) {
	// Lots of things to do here (some assumed).
	// We're assuming that there's a div called "site-form" and "site-noform", for one thing.
	
	// First, toggle site-form and site-noform
	toggleDiv('site-form');
	toggleDiv('site-notform');
	
	// Then, change the status of the button the user just clicked.
	element = document.getElementById(buttonID);
	element.className = (element.className.toLowerCase() == 'up'?'down':'up');
	
	// Finally, have the page focus on the first element in the form
	if(document.getElementById('site-form').className.toLowerCase() == 'show')
		document.getElementById(inputFocusID).focus();
}

function toggleGroupRow(groupRowID, groupRowDivID) {
	// Lots of things to do here.
	
	// First, toggle the groupRowDiv.
	toggleDiv(groupRowDivID);
	
	// Then, toggle the groupRow in a special way.
	element = document.getElementById(groupRowID);
	element.className = (element.className.toLowerCase() == 'arrow-up'?'arrow-down':'arrow-up');
}

function showDiv(id) {
	element = document.getElementById(id);
	element.className = 'show';
}

function hideDiv(id) {
	element = document.getElementById(id);
	element.className = 'hide';
}

function dealerBidOptionsAlternate(theElement, inputElement) {
	if(theElement.checked == true) {
		document.getElementById(inputElement).className = 'light';
		document.getElementById(inputElement).value = theElement.title;
	}
}

function dealerBidOptionsPrice(theElement, radioButtons) {
	var theForm = theElement.form;
	for(i = 0; i < theForm.length; i++) {
		if(theForm[i].type == 'radio' && theForm[i].name == radioButtons) {
			theForm[i].checked = false;
		}
	}
}
