
var inloggad = "16309";

function validate(day, open, close, price, cur) {
	weekday = new Array ("Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag");
	weekday["0,1,2,3,4,5,6"] = "Mån-Sön";
	weekday["1,2,3,4,5"] = "Mån-Fre";
	if (confirm("Säker på att ni vill öppna banan under dessa tider:\r\n\r\nDag:	" + weekday[day] + "\r\nÖppnar:	" + open + "\r\nStänger:	" + close + "\r\nPris:	" + price + " " + cur))
		return true;
	else
		return false;
}

function timeInput(field) {
	if (field.value.length == 2 && event.keyCode != 8) {
		field.value = field.value + ":";
	}
}

function objEdit(objectId) {
	location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=objects&objEdit=" + objectId;
}

function objDel_confirm(objectId) {
	if (confirm("Vill Ni radera objektet?"))
		location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=tracks&delObjID=" + objectId;
	else return false;
}

function trkAdd(objectId) {
	location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=tracks&objectID=" + objectId;
}

function trkDel_confirm(trackId) {
	if (confirm("Vill Ni radera banan?"))
		location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=tracks&delTrkID=" + trackId;
	else return false;
}

function trkEdit(objectId, trackId) {
	location.href="open.php?menu=systemmodules&page=open&open=reservation&p=tracks&objectID=" + objectId + "&trkEdit=" + trackId;
}

function trkOpenTimes(objectId, trackId) {
	location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=tracks&objectID=" + objectId + "&trkTimes=" + trackId;
}

function lvlDel_confirm(lvlId) {
	if (confirm("Vill Ni radera spelarnivån?\r\n\r\nOBS! Alla spelare på denna nivå kommer att ändras."))
		location.href= "open.php?menu=systemmodules&page=open&open=reservation&p=settings&delLvlID=" + lvlId;
	else return false;
}

function lvlEdit(lvlId) {
	location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=settings&updLvlID=" + lvlId;
}

function newUser() {
	location.href = "open.php?menu=systemmodules&page=open&open=reservation&p=members&regNew=1";
}

var lastRow = null;
var lastRowImage = null;
var selectedRow = null;
var arrSelectedId = new Array();
var arrSelectedImage = new Array();
var lastTrackID = null;
var lastTimeID = null;
var lastTimeIDcolor = null;
var i = 0;

function listRowOn( rowEl, trackId, timeId )	{
	if (lastRow != null)
		lastRow.style.backgroundImage = lastRowImage;
	lastRowImage = rowEl.style.backgroundImage;
//	rowEl.style.backgroundImage ='url(/library/systemmodules/tbs/images/usr_booked2.gif)';
	lastRow = rowEl;

	var trackcol= eval ('document.all.track'+trackId+'.style');
	trackcol.backgroundColor="#bbbbbb";
	lastTrackID = trackcol;

	var timerow= eval ('document.all.time'+timeId+'.style');
	lastTimeIDcolor = timerow.backgroundColor;
	timerow.backgroundColor="#cccccc";
	lastTimeID = timerow;

}

function listRowSelect (rowEl, rowId ) {
	var book = true;
	for (n=0; n<arrSelectedId.length; n++) {
		if (arrSelectedId[n] == rowId) {
			arrSelectedId[n] = null;
			rowEl.style.backgroundImage = arrSelectedImage[n];
			lastRowImage = arrSelectedImage[n];
			book = false;
		}
	}
	if (book) {
		arrSelectedId[i] = rowId;
		arrSelectedImage[i++] = lastRowImage;
		rowEl.style.backgroundImage ='url(/library/systemmodules/tbs/images/usr_booked.gif)';
		lastRowImage = 'url(/library/systemmodules/tbs/images/usr_booked.gif)';
	}

	var btn = document.getElementById("acceptbutton");
	if(arrSelectedId.length > 0) {
		var empty = true;
		for (j=0; j<arrSelectedId.length; j++) {
			if(arrSelectedId[j] != null) {
				empty = false;
			}
		}
		if(empty) {
			btn.style.visibility = 'hidden';
		}
		else {
			btn.style.visibility = 'visible';
		}
	}
	else {
		btn.style.visibility = 'hidden';
	}
}

function listRowClear()	{
	if (lastRow != selectedRow) {
		lastRow.style.backgroundImage = lastRowImage;
		lastTrackID.backgroundColor="#FF6A1E";
		lastTimeID.backgroundColor = lastTimeIDcolor;
	}
}

	var lastRow_cal = null;
	var lastRowBGColor_cal = null;
	var selectedRow_cal = null;

function listRowOn_cal( rowEl )
{
	if (lastRow_cal != null)
		lastRow_cal.style.backgroundColor = lastRowBGColor_cal;
	lastRowBGColor_cal = rowEl.style.backgroundColor;
	rowEl.style.backgroundColor ='#8BA3BB';
	lastRow_cal = rowEl;
}

function listRowSelect_cal( rowEl ) {
	if (selectedRow_cal != null)
		selectedRow_cal.style.backgroundColor = lastRowBGColor_cal;
	selectedRow_cal = rowEl;
}

function listRowClear_cal() {
	if (lastRow_cal != selectedRow_cal)
		lastRow_cal.style.backgroundColor = lastRowBGColor_cal;
}

function Booking() {
	if (inloggad == false) {
		if (confirm("Ni är ej inloggade!\r\n\r\nVill ni gå till inloggningszonen?"))
			location.href = "login.php";
	} else {
		var id = 0;
		for (n=0; n < arrSelectedId.length; n++) {
			if (arrSelectedId[n] != null)
				id = id+":"+arrSelectedId[n];
		}
		location.href="bekrafta_bokning.php?tracktimes="+id+"&date_toplay=2007-01-25";
	}
}

function booking_confirm() {
	location.href='?tracktimes=&action=confirmed&date_toplay=';
}

function reg_member_validate() {
	var success = true;
	if (document.getElementById("surname").value == ""){
		document.getElementById("surname").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("lastname").value == ""){
		document.getElementById("lastname").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("epost").value == "") {
		document.getElementById("epost").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("cellular").value == "") {
		document.getElementById("cellular").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("phone_day").value == "") {
		document.getElementById("phone_day").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("phone_evening").value == "") {
		document.getElementById("phone_evening").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("address").value == "") {
		document.getElementById("address").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("zipcode").value == "") {
		document.getElementById("zipcode").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("city").value == "") {
		document.getElementById("city").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("personnr").value.length != 11 ) {
		document.getElementById("personnr").style.backgroundColor = "#ffaaaa"; success = false; }
	return success;
}

function member_validate() {
	var success = true;
	if (document.getElementById("name").value == ""){
		document.getElementById("name").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("epost").value == "") {
		document.getElementById("epost").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("cellular").value == "") {
		document.getElementById("cellular").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("phone_day").value == "") {
		document.getElementById("phone_day").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("phone_evening").value == "") {
		document.getElementById("phone_evening").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("address").value == "") {
		document.getElementById("address").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("zipcode").value == "") {
		document.getElementById("zipcode").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("city").value == "") {
		document.getElementById("city").style.backgroundColor = "#ffaaaa"; success = false; }
	if (document.getElementById("password").value != document.getElementById("password_confirm").value) {
		alert("Lösenord stämmer inte med det bekräftade!\r\n\r\nFörsök igen");
		document.getElementById("password").style.backgroundColor = "#ffaaaa";
		document.getElementById("password_confirm").style.backgroundColor = "#ffaaaa";
		success = false;
	}
	return success;
}

function reclaimBooktime(cando, id) {
	if (cando) {
		if (confirm("Säker på att ni vill avboka tid?")) {
			location.href='?canceltime='+id;
			return true;
		} else return false;
	} else {
		if (confirm("Det är försent att avboka tiden, ni kan lämna tiden öppen för andra. Om inte tiden blir bokad kommer ni debiteras för tiden.")) {
			location.href='?cancelflyttime='+id;
			return true;
		} else return false;
	}
}

function doPayment(type, id) {
	if (confirm("Genomför betalningen?"))
		location.href = "admin_betala.php?payment="+type+"&id="+id;
}

function test(t) {
	alert(t);
}

function waitCursor() {
	document.body.style.cursor = "wait";
	return true;
}

function dialogOpenAdminBook(date_toplay, tracktimeID) {
	viewtime = window.open('/bokning/admin_viewtime.php?date_toplay=' + date_toplay + '&tracktime=' + tracktimeID, 'viewtime', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=740, height=380, left=0');
}

function openNoteBook(date_toplay, tracktimeID) {
	window.open('/bokning/notebook.php?date_toplay=' + date_toplay + '&tracktime=' + tracktimeID, 'notebook', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=400, height=200');
}

function clubNight(calendarday, user) {
	viewtime = window.open('/bokning/clubnight.php?calendarday=' + calendarday + '&user=' + user, 'nightclub', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=400, height=750');
}

function clubNightMemSelect(calendarday) {
	viewtime = window.open('/bokning/clubnight.php?calendarday=' + calendarday + '&action=memberform', 'nightclub_select', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=740, height=220', left=0);
}

function clubNightMemView(calendarday, uId) {
	viewtime = window.open('/bokning/clubnight.php?calendarday=' + calendarday + '&action=memberview&uId=' + uId, 'nightclub_select', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=740, height=220', left=0);
}

function tjejNight(calendarday, user) {
	viewtime = window.open('/bokning/tjejnight.php?calendarday=' + calendarday + '&user=' + user, 'nightclub', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=450, height=750');
}

function tjejNightMemSelect(calendarday) {
	viewtime = window.open('/bokning/tjejnight.php?calendarday=' + calendarday + '&action=memberform', 'tjejclub_select', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=740, height=220, left=0');
}

function tjejNightMemView(calendarday, uId) {
	viewtime = window.open('/bokning/tjejnight.php?calendarday=' + calendarday + '&action=memberview&uId=' + uId, 'tjejclub_select', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=740, height=220', left=0);
}

function cal_reserv(calendarday, ctime) {
	viewtime = window.open('/bokning/cal_reserv.php?calendarday=' + calendarday + '&ctime=' + ctime, 'cal_reserv', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=700, height=290');
}

function cal_reservMemSelect(calendarday, ctime) {
	viewtime = window.open('/bokning/cal_reserv.php?calendarday=' + calendarday + '&ctime=' + ctime + '&action=memberform', 'cal_reserv_select', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=700, height=200');
}
function updateTime() {
	parent.window.opener.location.reload();
	window.close();
}

function updPrice(getData) {
	if (document.book.becomemember.checked)
		location.href='admin_viewtime.php' + getData + '&memberchecked=1';
	else
		location.href='admin_viewtime.php' + getData + '&memberchecked=0';
}


function gotourl() {
  var i, args=gotourl.arguments; document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function addChr(input, name, chr, length) {
	if (input[name].value.length == length)
		input[name].value = input[name].value + chr;
}

