var hasConfirmedBookingConditions = false;
var ele;
var ele1;
var i=50;

 		var stds = new Array();
		stds[0] = "std1GearList";
		stds[1] = "std2GearList";
		stds[2] = "std3GearList";
		stds[3] = "std4GearList";
		stds[4] = "std5GearList";
		stds[5] = "std6GearList";
		
		var selected;
		
		var slots = new Array();
		
		var cells = new Array("cell0","cell1","cell2","cell3","cell4","cell5","cell6","cell7","cell8","cell9","cell10","cell11");

function select(id){

	var ele = document.getElementById(id);	
	var col = ele.style.backgroundColor;
	
	if(col == 'green' || col ==''){
		ele.value = '--'
		ele.style.backgroundColor = 'blue'
	}

	else{
		ele.value = 'A'
		ele.style.backgroundColor = 'green'	
	}

}

function sortTab(id){
	
	switch(id){
		case "tab3": 	
				tab3.src="images/tab3.jpg"; 
				tab2.src="images/tab2b.jpg"; 
				tab1.src="images/tab1b.jpg"; 
				tab3.style.top= -22+'px'; 
				tab2.style.top= -23+'px';
				tab1.style.top= -23+'px';
				tabInfo.innerHTML = '<ul><li>'+"Contemporary in-house music tutors"+'</li><li>'+"Currently offering tuition for drums and guitar"+'</li><li>'+"One to one tution form beginner to advanced"+'<li>'+"Competetive rates call 01382 200725"+'</li></ul>';
		break;
		case 'tab2': 	tab2.src="images/tab2.jpg"; 
				tab3.src="images/tab3b.jpg"; 
				tab1.src="images/tab1b.jpg"; 
				tab3.style.top= -23+'px'; 
				tab2.style.top= -22+'px';
				tab1.style.top= -23+'px';
				tabInfo.innerHTML = '<ul><li>'+"High end digital recording studio"+'</li><li>'+"Professional sound engineer supplied"+'</li><li>'+"Steinberg Cubase environment"+'</li><li>'+"Competetive rates!"+'</li><li>'+"Register and book now!"+'</li></ul>';
		break;
		case 'tab1': 	tab1.src="images/tab1.jpg"; 
				tab2.src="images/tab2b.jpg"; 
				tab3.src="images/tab3b.jpg"; 
				tab3.style.top= -23+'px'; 
				tab2.style.top= -23+'px';
				tab1.style.top= -22+'px';
				tabInfo.innerHTML = '<ul><li>'+"Spacious 'Live room' rehearsal studio"+'</li><li>'+"All PA, drums, and back-line supplied"+'</li><li>'+"Competetive rates!"+'</li><li>'+"Register and book now!"+'</li></ul>';
		break;
	}
}

function sortLists(id){

	var ele = document.getElementById(id);			// make selected link visible
	ele.style.visibility = 'visible';
	ele.style.display = 'block';

	for(var i=0;i<stds.length-1;i++){				// hide all the rest

		if(stds[i]!=id){
			
			ele = document.getElementById(stds[i]);
			ele.style.display = 'none';
			ele.style.visibility = 'hidden';
		}
	}
	
	
}
	

function btnOver(id){
	var ele = document.getElementById(id);
	ele.style.backgroundColor = '#777777'
	ele.style.color = 'orange';
	
}
			
function btnOut(id){
	var ele = document.getElementById(id);
	ele.style.backgroundColor = '#5d5b5d'
	ele.style.color = 'white';
}

function btnOut2(id){
	var ele = document.getElementById(id);
	ele.style.backgroundColor = '#999999'
	ele.style.color = 'white';
}
function btnOver2(id){
	var ele = document.getElementById(id);
	ele.style.backgroundColor = '#777777'
	ele.style.color = 'orange';
}

function setFadeID(id){
	ele = document.getElementById(id);
}
			

function overlayOver(){

	if(navigator.appName == "Microsoft Internet Explorer"){

			
		if(ele.filters.alpha.opacity > 0){
			ele.filters.alpha.opacity -= 2;

			if(ele.filters.alpha.opacity == 0){
				clearTimeout(timer);
			}
			else{
				var timer = setTimeout("overlayOver()", 10);
			}
		}
	}
	if(navigator.appName == "Netscape")
	{
		ele.style.MozOpacity = 0.0;
	}

}
			
function overlayOut(){
	if(navigator.appName == "Microsoft Internet Explorer"){
		ele.filters.alpha.opacity = 70;
	}
	if(navigator.appName == "Netscape"){
		ele.style.MozOpacity = 0.7;
	}
}

var str = ""
var chars = new Array();
var temp = "";
var i=0;

function setStrwithtime(s){
	
	var t;
	var currentTime = new Date()
	var hours = currentTime.getHours()
	var minutes = currentTime.getMinutes()

	if (minutes < 10){
		minutes = "0" + minutes
	}
	if(hours > 11){
		dorn = "PM"
	} else {
		dorn = "AM"
	}
	
	t = hours+":"+minutes+" "+dorn

	str = "    "+s+" "+t;
	mylist();
}

function setStr(s){

	str = "    "+s;
	mylist();
}

function mylist(){
	
		chars[i] = str.charAt(i);		// get each char of string
		temp = temp + chars[i];

	if(i == str.length){

		clearTimeout(timer);
		
	}
	else{
		if((i % 2) == 0){
			scrollingList.innerHTML = temp+"_";

		}else{
			scrollingList.innerHTML = temp;
		}
	
		i++;

		var timer = setTimeout('mylist()', 20);
	}			
}

function selectDate(day){

	var ele = document.getElementById(day);

	ele.backgroundColor='#000000';
}

function overCal(id){

	var ele = document.getElementById(id);
	
	if(ele.innerHTML!=0){
		ele.style.borderColor="white";
	}else{
		// do nothing
	}
	
}

function outCal(id){

	var ele = document.getElementById(id);
	ele.style.borderColor="black";

}

function selectDate(id, col){
	
	
	var day;
	var ele = document.getElementById(id);
	var val = ele.innerHTML;
	
	for(var i=0;i<42;i++){
		if(document.getElementById("calCell"+i).innerHTML == ""){
			document.getElementById("calCell"+i).style.backgroundColor='#222222';
		}else{
			document.getElementById("calCell"+i).style.backgroundColor='#444444';
		}
	}
	
	ele.style.backgroundColor='red';
	
	var mmyyyy = document.head.dateText.value;
	
	var month = mmyyyy.substring(0,3);
	var year = mmyyyy.substring(3);
	
	switch(month){
		case "Jan": month = "01"; break;
		case "Feb": month = "02"; break;
		case "Mar": month = "03"; break;
		case "Apr": month = "04"; break;
		case "May": month = "05"; break;
		case "Jun": month = "06"; break;
		case "Jul": month = "07"; break;
		case "Aug": month = "08"; break;
		case "Sep": month = "09"; break;
		case "Oct": month = "10"; break;
		case "Nov": month = "11"; break;
		case "Dec": month = "12"; break;
	}
	
	if(val!=0){
		
		if(val <= 9){
			day = "0"+val;
			selected = day+"/"+month+""+year;
		
		}
		else{
			selected = val+"/"+month+""+year;
		}
		
		var dOfwk;
		
		switch(col){
			case 1: dOfwk = "Monday"; break;
			case 2: dOfwk = "Tuesday"; break;
			case 3: dOfwk = "Wednesday"; break;
			case 4: dOfwk = "Thursday"; break;
			case 5: dOfwk = "Friday"; break;
			case 6: dOfwk = "Saturday"; break;
			case 0: dOfwk = "Sunday"; break;
		}
		
		showTimetable(selected,dOfwk);
			
		//window.location="booking.php?date="+selected+"&dOfwk="+dOfwk;
	}
	else{
		ele.style.backgroundColor='#222222';
	}
}


function setSelID(id){

	var ele = document.getElementById(id);
	ele.style.backgroundColor="red";
}


function hideMsg(){
	
	var msg = document.getElementById("msg");
	
	if(msg.style.display == 'block'){
		msg.style.display = 'none';
	}
}

function selTimeSlot(val,id,date,day){

	hideMsg();
	
	//var ele = document.getElementById(id);
	var state;
	if(val == "--"){
	
		state = "rem";
	}
	else{

		state = "ins";
	}
	//alert(id+" "+date+" "+state+" "+day);
//updateTimetable(ele.name,date,state,day);
	updateTimetable(id,date,state,day);
	//window.location.href="booking.php?timeslot="+ele.name+"&date="+date+"&state="+state+"&dOfwk="+day;
}

function selTimeSlotAdmin(fn,ln,ph,em,val,id,date,day){

	hideMsg(); 
	
	//var ele = document.getElementById(id);
	
	var state;
	
	if(fn != "" && ph != ""){
		if(val == "--"){
			state = "rem";
		}
		else{
			state = "ins";
		}
		
		updateAdminTimetable(id,date,state,fn,ln,ph,em,day);
		
		//window.location.href="booking.php?timeslot="+ele.name+"&date="+date+"&state="+state+"&fn="+fn+"&ln="+ln+"&p="+ph+"&e="+em+"&dOfwk="+day;
	}
	else{
		alert("Please enter at least the customers first name and phone number before booking");
	}
	
}

function getSelectedRad(page){
	
	if (document.confirmForm.radbtn[0]) {

		for (var i=0;i<document.confirmForm.radbtn.length;i++) 
		{ 
			if (document.confirmForm.radbtn[i].checked) 
			{ 
             var rbvalue = document.confirmForm.radbtn[i].value; 
         
             window.location.href= page+'.php?confirm=0&sel='+rbvalue;
			} 
		} 
	}
	else{
		if (document.confirmForm.radbtn.checked) { 
		
			var rbvalue = document.confirmForm.radbtn.value;
			window.location.href= page+'.php?confirm=0&sel='+rbvalue;
		}
	}
}

function confirmBooking(page){
	//alert(document.getElementById('notes').value)
	
	var mess = document.getElementById('notes').value;
	window.location.href= page+'.php?confirm=1&val='+mess;
}

function finish(){

	window.location.href= 'index.php';
}

function checkSelection(id,state){
	
	var ele = document.getElementById(id);

	if(state == 'ins'){
		ele.disabled = 'false';
	}
	else{
		ele.disabled = 'true';
	}
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

  return true
}





function showbooking(text){

	document.getElementById("sessionInfo").style.visibility = 'visible';
	document.getElementById("sessionInfo").style.display = 'block';
	document.getElementById("info").innerHTML = text;


	document.getElementById("sessionInfo").style.left = (tempX + 5)+'px';
	document.getElementById("sessionInfo").style.top = (tempY + 5)+'px';
	
	
}

function hidebooking(){
	document.getElementById("sessionInfo").style.visibility = 'hidden';
	document.getElementById("sessionInfo").style.display = 'none';
}

function tableRow(row,id){

	var ele = document.getElementById(id);
	
	if((row % 2) == 0){
		ele.style.backgroundColor = '#555555';
	}
	else{
		ele.style.backgroundColor = '#888888';
	}
}

function openEditWeekly(){
		
	window.open( "popWeekly.php", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" );
	
}

function openEditAccess(){
		
	window.open( "popAccessLv.php", "myWindow", "status = 1, height = 300, width = 380, resizable = 1" );
	
}

function openUploadShowcase(){
		
	window.open( "uploadShowcase.php", "myWindow", "status = 1, height = 300, width = 380, resizable = 1" );
	
}

function openUpdatePrices(){

	window.open( "updatePrices.php", "myWindow", "status = 1, height = 300, width = 380, resizable = 1" );
	
}

function clear(a){
	a = document.getElementById('notes');
	a.value = "";
	
}

function over(id){
			var ele = document.getElementById(id);
			ele.style.color = 'orange';
		}
function out(id){
			var ele = document.getElementById(id);
			ele.style.color = 'white';
		}
/////////////////////////////////////////////////////////////////////////////////////////

function validatePrice(f){

	if(IsNumeric(f.studio.value) && IsNumeric(f.rehearsal.value)){
		
		return true;
	}
	else{
		alert("Please enter a numeric value")
		return false;
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


 function currencyFormat(num,row) {	//rounding to two decimal places	
	
	num = Math.round(num * 100)/100;	
	
	//Adds a trailing '0' to a single decimal place result OR	
	//Adds a trailing '.00' to an integer result 	
	
	if((num * 100 % 10 == 0) && (num * 10 % 10 != 0)) 	{		
		num += "0";	
	}	
	else if ((num * 100 % 10 == 0) && (num * 10 % 10 == 0)) 	{		
		num += ".00";	
	}	
	
	document.getElementById(row).innerHTML = num; 
}