var auctionTimerID = null;
var auctionTimerRunning = false;


function isNumeric(x) {			
	// return true or false						
	// regular expression that validates a value is numeric
	var RegExp = /^(-)?(\d*)$/; 
	// compare the argument to the RegEx
	// the 'match' function returns 0 if the value didn't match
	var result = x.match(RegExp);
		
	if (result == null)
		return false;
	return true;
	// return result;
}

function redirectTo(url, target, isPortlet) {
	if (isPortlet) {
		target.openUrl(url);
	} else {
		window.open(url, "_self");
	}
}

function authLogin(form) {
	initLogin(form.un.value, form.pass.value);
}

function initLogin(un, pw) {
	document.getElementById("username").value = un;
	document.getElementById("password").value = pw;
	document.getElementById("login-form").submit();
}

function doSearch(){
		document.searchForm.submit();
}

function entsub(event,un, pw) {
	if (event && (event.which == 13 || event.keyCode == 13)) {
		initLogin(un, pw);
	} else {
		return true;
	}
}

function submitLogin(form, path, redir, message) {
	url = path + "/auth?username=" + form.un.value + "&password=" + form.pass.value + "&redir=" + redir;
	parameters = ""
	document.body.style.cursor = "wait";
	new Ajax.Request(
		url, Object.extend({
			parameters:   parameters,
			method:       "post",
			onFailure: alert("Failed"),
			onException: function(transport,exception) {
				alert(exception);
				document.body.style.cursor = "default";
			},
			onComplete:   function(transport) { completeLogin(transport.responseText, message); },
			asynchronous: true 
		}));
}

function completeLogin(transport, msg) {
	if (transport.indexOf("LoginFailed") == -1) {
		//window.open(window.location.href, "_self");
		window.location.reload();
	} else {
		document.getElementById("login-warning").innerHTML = msg;
	}
	document.body.style.cursor = "default";
}
