
	var changeMade = 0;
	
	window.onbeforeunload = checkChanged;
	
	function checkChanged ()
	{
		if (changeMade)
			return "Changes made to this record will be lost.";
	}
	
	
	function tickBox (boxname)
	{
		document.getElementById(boxname).checked = 1;
		changeMade = 1;		
	}
	
	function toggleBox (boxname)
	{
		if (document.getElementById(boxname).checked)
			document.getElementById(boxname).checked = false;
		else
			document.getElementById(boxname).checked = true;
	}
	
	function setRadioChoice (radioname, choice)
	{
		document.getElementById(radioname).value = choice;
	}
	
	function copyField (from, to)
	{
		document.getElementById(to).value = document.getElementById(from).value;
		changeMade = 1;		
	}
	
	function setField (target, val)
	{
		document.getElementById(target).value = val;
		changeMade = 1;
	}
	
	function setHTML (target, html)
	{
		document.getElementById(target).innerHTML = html;
	}	
	
	function hideBox (box)
	{
		document.getElementById(box).style.display = 'none';
	}
	
	function showBox (box)
	{
		document.getElementById(box).style.display = '';
	}
	
	function toggleHiddenWithValue (thingy, value)
	{
		if (value)
			document.getElementById(thingy).style.display = '';
		else
			document.getElementById(thingy).style.display = 'none';
	}
	
	function toggleHidden (thingy, img)
	{
		if (document.getElementById(thingy).style.display)
		{
			document.getElementById(thingy).style.display = '';
			if (img)
				document.getElementById(thingy+'img').src = minus.src;
		}
		else
		{
			document.getElementById(thingy).style.display = 'none';
			if (img)
				document.getElementById(thingy+'img').src = plus.src;
		}			
	}
	
	var deleteGenericSuccess = function(o)
	{
		if (o.responseText == '0')
		{
			alert('Delete failed, please try again.');
			return;
		}
		
		if (o.responseText == '1')
			return;
		else
		{
			hide = o.responseText.split(",");
			for (x in hide)
				if (document.getElementById(hide[x]))
					document.getElementById(hide[x]).style.display = 'none';
		}
	}
	
	var deleteGenericFailure = function(o)
	{
		alert('Delete failed, please try again.');
	}
	
	var deleteGenericCallback =
	{
		success: deleteGenericSuccess,
		failure: deleteGenericFailure
	}
	
	function deleteGeneric (table, idfield, id, hide)
	{
		if (!confirm('Are you sure you want to delete this item?'))
			return false;
			
		var cObj = YAHOO.util.Connect.asyncRequest('GET','/admin/deleteGeneric.php?table='+table+'&idfield='+idfield+'&id='+id+'&hide='+hide,deleteGenericCallback,null);
	}
	
		
	function URLEncode(plaintext)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					alert( "Unicode Character '" 
							+ ch 
							+ "' cannot be encoded using standard URL encoding.\n" +
							  "(URL encoding only supports 8-bit characters.)\n" +
							  "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		return encoded;
	};	

	
	var updateCartCostSuccess = function(o)
	{
		if (o.responseText == '0')
			return;

		bits = o.responseText.split('|||');
		document.getElementById('totalCost').innerHTML = bits[0];
		document.getElementById('cost_'+bits[1]).innerHTML = bits[2];
	}
	
	var updateCartCostFailure = function(o)
	{
		return;
	}
	
	var updateCartCostCallback =
	{
		success: updateCartCostSuccess,
		failure: updateCartCostFailure
	}
	
	function updateCartCost (item_id, quantity)
	{
		if (quantity == 0)
		{
			if (!confirm('Are you sure you want to remove this item from your cart?'))
				return;
				
			document.getElementById('item_'+item_id).style.display = 'none';
		}
		
		var cObj = YAHOO.util.Connect.asyncRequest('GET','/cartUpdate.php?item_id='+item_id+'&quantity='+quantity,updateCartCostCallback,null);
	}
	