function redirect (url) {

	location.href = url;

	return false;

}

function confirm_redirect (url, message) {

	if (confirm (message))
		redirect (url);

	return false;

}

function confirm_delete (url, message)
{
	if (confirm (message))
		redirect (url);
}

function highlight (element) {

	Element.addClassName (element, 'highlight');

}

function unhighlight (element) {

	Element.removeClassName (element, 'highlight');

}

function show (id) {

	document.getElementById(id).style.display = '';

}

function hide (id) {

	document.getElementById(id).style.display = 'none';

}

function switch_display (hide, show) {

	if (hide)
	document.getElementById(hide).style.display = 'none';

	if (show)
	document.getElementById(show).style.display = '';

}

function urlencode(str) {
	var result = "";

	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}

	return escape(result);
}

function urldecode(str) {
	return unescape(str.replace(/\+/g, " "));
}

function format_cc (element) {

	element.value = element.value.replace(/([^0-9]*)/g, '');

}

$(document).ready(function(){
	//popup windows
	$('a.popup').bind('click',function(){
		window.open(this.href);
		return false;
	});
	
	$(".close-widget").each(function(i){
		$(this).bind("click",function(){
		//div_parent = this.parentNode.parentNode;
		//$(div_parent).hide();
			$('#error-list').hide();
		});
	});
	
	$('a.popup-window-small').bind('click',function(){
		window.open(this.href,this.title,'width=600px,height=500px,scrollbars=0');
		return false;
	});
});



/*
Description:

	Allows only valid characters to be entered into input boxes.
	Note: does not validate that the final text is a valid number
	  (that could be done by another script, or server-side)

Usage:

	$(window).load(
		function()
		{
			$(".numeric").numeric(); // or $(".numeric").numeric(",");
		}
	);

Parameters:

	decimal     : Decimal separator (e.g. '.' or ',' - default is '.')
	allowPaste  : let paste operations through (does nothing with IE - paste is always allowed)
*/
$.fn.numeric = function(decimal, allowPaste)
{
	this.keypress(
		function(e)
		{
			decimal = decimal || ".";
			allowPaste = allowPaste || true;
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
			var allow = false;
			// allow Ctrl+A
			if((e.ctrlKey && key == 97 /* firefox */) || key == 65 /* opera */) allow = true;
			// allow Ctrl+X (cut)
			if((e.ctrlKey && key == 120 /* firefox */) || key == 88 /* opera */) allow = true;
			// allow Ctrl+C (copy)
			if((e.ctrlKey && key == 99 /* firefox */) || key == 67 /* opera */) allow = true;
			// allow Ctrl+Z (undo)
			if((e.ctrlKey && key == 122 /* firefox */) || key == 90 /* opera */) allow = true;
			// allow or deny Ctrl+V (paste)
			if((e.ctrlKey && key == 118 /* firefox */) || key == 86 /* opera */)
			{
				allow = allowPaste;
			}
			// if a number was not pressed
			if(key < 48 || key > 57)
			{
				/* '-' only allowed at start */
				if(key == 45 && this.value.length == 0) return true;
				/* only one decimal separator allowed */
				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1)
				{
					allow = false;
				}
				// check for other keys that have special purposes
				if(
					key != 8 /* backspace */ &&
					key != 9 /* tab */ &&
					key != 13 /* enter */ &&
					key != 35 /* end */ &&
					key != 36 /* home */ &&
					key != 37 /* left */ &&
					key != 39 /* right */ &&
					key != 46 /* del */
				)
				{
					
					allow = false;
				}
				else
				{
					// for detecting special keys (listed above)
					// IE does not support 'charCode' and ignores them in keypress anyway
					if(typeof e.charCode != "undefined")
					{
						// special keys have 'keyCode' and 'which' the same (e.g. backspace)
						if(e.keyCode == e.which && e.which != 0)
						{
							allow = true;
						}
						// or keyCode != 0 and 'charCode'/'which' = 0
						else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0)
						{
							allow = true;
						}
					}
				}
				// if key pressed is the decimal and it is not already in the field
				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) == -1)
				{
					allow = true;
				}
			}
			else
			{
				allow = true;
			}
			return allow;
		}
	);
	return this;
}
