////////////////////////////////////////////////////
// functions to clear and reset text field values //
////////////////////////////////////////////////////

function clearMe(fe,txt) {
	if (fe.value == txt) {
		fe.value = "";
	}	return;
}

function resetMe(fe,txt) {
	if (fe.value == "") {
		fe.value = txt;
	}	return;
}

//////////////////////////////////////////////////////////////
// function to limit the number of characters in a textarea //
//////////////////////////////////////////////////////////////

function textLimit(field, maxlen) {
	if (field.value.length > maxlen + 1) {
		alert('Oops! \n\nYour personal message must be 200 characters or less.');
	}
	if (field.value.length > maxlen) {
		field.value = field.value.substring(0, maxlen);
	}
}

//////////////////////////////////////////////////////
// function to allow easier access to url variables //
//////////////////////////////////////////////////////

var qs = location.search.substring(1);
var nv = qs.split('&');
var url = new Object();
for(i = 0; i < nv.length; i++) {
  eq = nv[i].indexOf('=');
  url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
}

////////////////////////////////////
// function for preloading images //
////////////////////////////////////

var preloaded = new Array();
function preloadImages() {
	for (var i = 0; i < arguments.length; i++) {
		preloaded[i] = document.createElement('img');
		preloaded[i].setAttribute('src',arguments[i]);
	}
}

////////////////////////////////////
// change page on dropdown select //
////////////////////////////////////

function selectPage(obj) {
	if (obj.options.selectedIndex > 1) {
    var page = obj.options[obj.selectedIndex].value;
    window.location.href = page;
	}
}

//////////////////////////////////////////
// function to show/hide/toggle any div //
//////////////////////////////////////////

function divToggle(action,div) {
	if (action == 'show') {
		document.getElementById(div).style.display = "block";
	} else if (action == 'hide') {
		document.getElementById(div).style.display = "none";
	} else if (action == 'toggle') {
		if (document.getElementById(div).style.display == "none") {
			document.getElementById(div).style.display = "block";
		} else {
			document.getElementById(div).style.display = "none";
		}
	}
}

/////////////////////////////////////////////
// function to fix the shoppe menu for ie6 //
/////////////////////////////////////////////

function menuFix() {
	var sfEls = document.getElementById("shoppenav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
		this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
	var sfEls = document.getElementById("shoppenav").getElementsByTagName("span");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
		this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}