function changeOnload( newFunc ) {
    var tmpFunc = window.onload;
    if ( ! tmpFunc ) {
		window.onload = newFunc;    
		return;
	}
    bothFunc = function() {
        tmpFunc();
    	newFunc();
    }
    window.onload = bothFunc;
}

function timeOnload() {
	showTime();
	
	setTimeout(iframeReload, 60000);
};
			
function showTime() {
	var varFrame = window.frames["GlobalTimeFrame"];
	try {
		if ( varFrame ) {
			var varDoc = varFrame.document;
			if ( varDoc ) {
				var timeServer = varDoc.getElementById( "timeServer" );
				var timeClient = varDoc.getElementById( "timeClient" );
				if ( timeServer != null && timeClient != null ) {
					diff = (new Date(timeServer.value)).getTime() - timeClient.value;
				}
			}
		}
	} catch(e) { }
	var date = new Date( (new Date()).getTime() + diff );			
	document.getElementById("time").value = formatDate( date );
	setTimeout( showTime, 1000 );
}
			
function formatDate( localDate ) {
	var hours   = localDate.getHours();
	var minutes = localDate.getMinutes();
	var seconds = localDate.getSeconds();
	var result  = "" + ((hours > 12) ? hours - 12 : hours);
	result     += ((minutes < 10) ? ":0" : ":") + minutes;
	result     += ((seconds < 10) ? ":0" : ":") + seconds;
	result     += (hours >= 12) ? " PM" : " AM";
	return result;
}

function iframeReload() {
	var varFrame = window.frames["GlobalTimeFrame"];
	try {
		varFrame.location.reload();
	} catch(e) { }
	setTimeout(iframeReload, 60000);	
}

function globalWaitOnLoad() {
	var seatedForm = document.getElementById('seated');
	if ( seatedForm ) 
		seatedForm.submit();
	else
		setTimeout(waitRefresh, 15000);
}

function waitRefresh() {
	location.reload();
}

function openWait(tableName) {
        var winId = window.open(
        'WaitingPage.thtml', 
        'waitingWindow', 
        'location=0,menubar=0,resizable=1,toolbar=0,status=0,fullscreen=0,directories=0,width=340,height=130'
    );
}

function openAboutToBegin(id) {
        window.open(
                "TournamentAboutToBegin.thtml", 
                "TournamentAboutToBegin", 
                "width=385,height=180,menubar=0,directories=0,location=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0");
}

function disableLink(link) {
	location.href = link.href;
	link.href = "#";
}

