function openInNewWindow(href)
{
	var newWindow = window.open(href, '_blank');
	newWindow.focus();
	return false;
}

function redirectInCurrentWindow(href)
{
	window.location=href;
	return false;
}

function enableDisable()
{
	if (arguments.length % 2 != 0)
	{
		alert('Invalid argument count.');
		return false;
	}
	
	for(var i = 0; i < arguments.length; i+=2)
	{
		$("#"+arguments[i]).attr("disabled",arguments[i+1]);
	}
}

function validateForm()
{
	var returnVal = true;
	$("#errorMessage").css('visibility','hidden');
	$("#errorMessage").html("");
	
	$("input:text").add("input:password").add("select").each(
		function(i)
		{
			if (this.value.length==0){
				var label = $("label[for="+this.name+"]").text().replace(":","");
				$("#errorMessage").html($("#errorMessage").html()+"&quot;"+label+"&quot; is a required field.<br />");
				$("#errorMessage").css('visibility','visible');
				returnVal = false;
			}
		}
	);
	
	return ($("#errorMessage").html().length == 0);
}

function confirmDelete(){
	if (validateForm()){
		enableDisable('submitButton',true,'confirmButton',false);
	}
}

function checkPasswords()
{
	if ($("#password").attr("value") != $("#confirm").attr("value")){
		$("#errorMessage").html($("#errorMessage").html()+"Passwords do not match.<br />");
		$("#errorMessage").css('visibility','visible');
		return false;
	}
	return true;
}

function populateSelect()
{
	if (arguments.length % 2 != 1)
	{
		alert('Invalid argument count.');
		return false;
	}
	
	var optionReplace = "";
	
	for(var i = 1; i < arguments.length; i+=2)
	{
		optionReplace = optionReplace + "<option value=\""+arguments[i+1]+"\">"+arguments[i]+"</option>";
	}

	$("#"+arguments[0]).html(optionReplace);	
}

function populateSelectDriver(id)
{
	$("#"+id+" :selected").click();
}

