/**
 * Quick Form Validation: Less Than or Equals
 * Returns true if validating value is less than or equal to the the supplied
 * value.
 * @param element
 * @param value
 * @param arg
 * @return bool
 */
function qfv_lte (element, value, arg) {
	if (value <= arg) {
		return true;
	}
	return false;
}

/**
 * Quick Form Validation: Greater Than or Equals
 * Returns true if validating value is greater than or equal to the the supplied
 * value.
 * @param element
 * @param value
 * @param arg
 * @return bool
 */
function qfv_gte (element, value, arg) {
	if (value >= arg) {
		return true;
	}
	return false;
}

var message_row_state = 0;
var message_row_timeout;
function rollout (mode, msg) {
	switch (mode) {
		case 'message':
			document.getElementById('message_icon').src = root + "/resources/icons/comment.png";
			if (message_row_state > 0) {
				if (message_row_timeout) {
					window.clearTimeout(message_row_timeout);
				}
				document.getElementById('message_text').innerHTML = document.getElementById('message_text').innerHTML + '<br />' + msg;
			} else {
				document.getElementById('message_text').innerHTML = msg;
				Element.show('message_row');
			}
			message_row_timeout = window.setTimeout("Element.hide('message_row');", 10000);
			break;
		case 'error':
			document.getElementById('message_icon').src = root + "/resources/icons/exclamation.png";
			if (message_row_state > 0) {
				if (message_row_timeout) {
					window.clearTimeout(message_row_timeout);
				}
				document.getElementById('message_text').innerHTML = document.getElementById('message_text').innerHTML + '<br />' + msg;
			} else {
				document.getElementById('message_text').innerHTML = msg;
				Element.show('message_row');
			}
			message_row_timeout = window.setTimeout("Element.hide('message_row');", 10000);
			break;
		case 'login':
		default:
			Element.show('login_row');
			break;
	}
}

function menu_activate(menu, activator, color) {
	if (!color) { color = '#222'; }
	Element.show(menu);
	document.getElementById(activator).style.backgroundColor = color;
}

function menu_deactivate(menu, activator, color) {
	if (!color) { color = '#444'; }
	Element.hide(menu);
	document.getElementById(activator).style.backgroundColor = color;
}


function setValue (fid, val) {
	var f = document.getElementById(fid);
	if (!f) { return; }
	
	if ((typeof f.value == 'undefined') && (typeof f.innerHTML != 'undefined')) {
		f.innerHTML = val;
	} else if (typeof f.value != 'undefined') {
		f.value = val;
	}
}

function popup(w, h, url) {
	if (!w) { w = 100; }
	if (!h) { h = 100; }
	w = parseInt(w) + 20;
	h = parseInt(h) + 20;
	var d = new Date;
	var wname = 'popup' + d.valueOf();
	var nw = window.open(url, wname, 'width='+w+', height='+h);
}

function launchMovie(w, h, url) {
	popup(w, h, root+'/quicktime.php?width='+w+'&height='+h+'&url='+escape(url));
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function xml_scanForChild(xml, nodeName) {
	if (!xml.childNodes) { return false; }
	for (var i=0; i < xml.childNodes.length; i++) {
		if (xml.childNodes[i].nodeName == nodeName) { return xml.childNodes[i]; }
	}
	return false;
}

function fp_addToCart() {
	document.getElementById('cart_menu_button').style.display = 'inline';
}

function addToCart() {
	Element.hide('addToCart');
	Element.show('inCart');
	document.getElementById('cart_menu_button').style.display = 'inline';
}

function removeFromCart() {
	Element.show('addToCart');
	Element.hide('inCart');
}
