// applyRollover
function applyRollover(elements){
	if(typeof(elements)=='object'){
		for(var i=0; i<elements.length; i++){
			document.getElementById(elements[i]).onmouseover = function(){this.className += "_over"};
			document.getElementById(elements[i]).onmouseout = function(){this.className = this.className.replace('_over','')};
		}
	}
	else{
		document.getElementById(elements).onmouseover = function(){this.className += "_over"};
		document.getElementById(elements).onmouseout = function(){this.className = this.className.replace('_over','')};
	}
}

// applyChecker
function applyChecker(elements){
	if(typeof(elements)=='object'){
		for(var i=0; i<elements.length; i++){
			document.getElementById(elements[i]).onclick = function(){
				if(this.className.indexOf("_checked")>0)
					this.className = this.className.replace('_checked', '');
				else
					this.className = this.className.replace('_over','') + "_checked";
				displayCustomTotal();
			};
		}
	}
	else{
		document.getElementById(elements).onclick = function(){
				alert(this.className.indexOf("_checked"));
				if(this.className.indexOf("_checked")>0)
					this.className = this.className.replace('_checked', '');
				else
					this.className = this.className.replace('_over','') + "_checked";
				displayCustomTotal();
			};
	}
}

// Enable Click function in firefox
if($.browser.mozilla){
	HTMLElement.prototype.click = function(){
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}

// OpenPage
function openpage(name, value)
{
	for(var o in querystring)
	{
		if(o==name)
		{
			querystring[o] = value;
			break;
		}
	}

	var url = "";
	for(var o in querystring)
	{
		if(querystring[o]!="")
			url += "&" + o + "=" + querystring[o];
	}

	url = url.replace("&","?");
	window.location = url;
}

// Validate
function validate(obj, type, message, ref)
{
	if(ERROR && ERROR_OBJ != obj && ERROR_OBJ.id != "agree")
		return;
	switch(type)
	{
		case "blank":
		{
			if(jQuery.trim(obj.value)=="")
				ERROR = true;
			else
				ERROR = false;
		}
		break;
		case "numeric":
		{
			if(isNaN(obj.value))
				ERROR = true;
			else
				ERROR = false;
		}
		break;
		case "equal":
		{
			if(obj.value != ref.value)
				ERROR = true;
			else
				ERROR = false;
		}
		break;
		case "checked":
		{
			if(obj.checked != true)
				ERROR = true;
			else
				ERROR = false;
		}
		break;
	}
	if(ERROR)
	{
		$("#error").show();
		$("#error").html(message);
		setTimeout(function(){obj.focus();}, 10);
		ERROR_OBJ = obj;
		window.location="#error";
		return false;
	}
	else
	{
		$("#error").hide();
		return true;
	}
}
