﻿defaultStatus = 'Welcome to RestaurantForms.net';

var oddStyle = GetCookie("ostyle");
var timeZone = GetCookie("tzone");
var refreshInterval = GetCookie("refresh");
if(oddStyle==null) { oddStyle=1; } else { oddStyle = parseInt(oddStyle);}
if(timeZone==null) { timeZone=0; } else { timeZone = parseInt(timeZone);}
if(refreshInterval==null) { refreshInterval=30; } else { refreshInterval = parseInt(refreshInterval);}
refreshInterval = refreshInterval * 1000;

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
		return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;
	}	
	return null;
}

function GetCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function AddFav(doctitle) {
	if(doctitle=='' || doctitle==undefined) { doctitle = document.title; }
	window.external.AddFavorite(location.href, doctitle);
}

function Recommend() {
	window.open("recommend.asp","recommend","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=530,height=410,resizable=no");
}

function QDemo() {
	window.open("help/demo2.asp","qdemo","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=530,height=430,resizable=no");
}

function link(url) { window.location.href = url; }

function hdr_sort(frm, fld, dr) {
	if(frm.elements("ofld").value == fld) {
		frm.elements("odir").value = 1-dr;
	} else {
		frm.elements("ofld").value = fld;
		frm.elements("odir").value = 0;
	}		
	frm.submit();
}

function MnuOn(id) {
	id.style.backgroundColor = "#FFE7B9";
}

function MnuOff(id) {
	id.style.backgroundColor = "#FFEFC8";
}

function event(id) {
	window.location.href = "event.asp?eid=" + id;
}


function bet(id) {
	window.location.href = 'bet.asp?bid=' + id;
}

function CancelBet(eventID, betID) {
	if(confirm('ARE YOU SURE YOU WANT TO CANCEL THE SELECTED BET?'))
		window.location.href='event.asp?cancel=1&eid=' + eventID + '&bid=' + betID;
}

function round(number,X) {
	X = (!X ? 0 : X);
	if(X==0)
		return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	else
		return Xtend(Math.round(number*Math.pow(10,X))/Math.pow(10,X), X);
}

function roundNoEx(number,X){
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function Xtend(Q,X) { 
	var P;
    Q = String(Q);
    while ((P=Q.indexOf('.'))<0) 
		Q+='.';
    while (Q.length <= P+X) 
		Q+='0';
    return Q; 
}

function PageInit() {
	UpdateClocks();
	window.setInterval("UpdateClocks()", 1000);
}

function UpdateClocks() {
	SetTime(clockMain, timeZone, 1);
	SetTime(clockLondon, 0, 0);
	SetTime(clockNY, -5, 0);
	SetTime(clockTokyo, 9, 0);
	SetTime(clockMoscow, 4, 0);
	SetTime(clockOZ, 10, 0);
	SetTime(clockNZ, 12, 0);
	SetTime(clockIstanbul, 2, 0);
}

function SetTime(id, adjst, wt) {
	var v = new Date();
	v.setHours(v.getUTCHours()+adjst);
	var h = v.getHours();
	var n = v.getMinutes();
	var s = v.getSeconds();
	var tmp = SRepeat('0', 2-h.toString().length) + h + ':' + SRepeat('0', 2-n.toString().length) + n
	if(wt==1) { tmp = tmp + ':' + SRepeat('0', 2-s.toString().length) + s; }
	id.innerHTML = tmp;
}

function sts(v) {
	window.status = v;
}

function MDate(dtm, wtime, nullval) {
	if(dtm==null || dtm=='') {
		return nullval;
	} else {
		var v = new Date(dtm);
		v.setHours(v.getHours()+timeZone);
		var m = v.getMonth()+1;
		var d = v.getDate();
		var h = v.getHours();
		var n = v.getMinutes();
		var s = SRepeat('0', 2-m.toString().length) + m + '.' + SRepeat('0', 2-d.toString().length) + d + '.' + v.getYear();
		if(wtime) { s+=' ' + SRepeat('0', 2-h.toString().length) + h + ':' + SRepeat('0', 2-n.toString().length) + n; }
		return s;
	}
}

function SRepeat(str, rcount) {
	var tmp = '';
	for(var i=0;i<rcount;i++) {
		tmp = tmp + str;
	}
	return tmp;
}

function AMNavig(v) {
	if(v!=0) {
		if(v=='logout.asp') {
			if(confirm('ARE YOU SURE YOU WANT TO LOG OUT OF YOUR ACCOUNT?')) { link(v); } else { return false; }
		} else {
			link(v);
		}
	}
}

function ShowReserved(eid) {
	window.open("reserved.asp?eid="+eid,"reserved","toolbar=no,location=no,status=yes,menubar=no,scrollbars=auto,width=500,height=330,resizable=no");	
}


