// Standard Dreamweaver functions
function MM_swapImgRestore() 
{
	var i, x, a = document.MM_sr; 
	for (i = 0; a&&i < a.length&&(x=a[i])&&x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) 
{
  	var p, i, x;  
	if (!d) d = document; 
	if ((p=n.indexOf("?")) > 0&&parent.frames.length) 
	{
    	d = parent.frames[n.substring(p+1)].document; 
		n = n.substring(0,p);
	}
  	if (!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0; !x&&i < d.forms.length; i++) x=d.forms[i][n];
  	for (i=0; !x&&d.layers&&i < d.layers.length; i++) x = MM_findObj(n,d.layers[i].document);
  	if (!x && d.getElementById) x = d.getElementById(n); 
	return x;
}

function MM_swapImage() 
{
	var i, j=0, x, a = MM_swapImage.arguments; 
	document.MM_sr = new Array; 
	for (i=0; i < (a.length-2); i+=3)
   	if ((x=MM_findObj(a[i]))!=null)
	{
		document.MM_sr[j++] = x; 
		if (!x.oSrc) x.oSrc = x.src; x.src = a[i+2];
	}
}

function MM_preloadImages() 
{
	var d=document; 
	if(d.images)
	{
		if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if(a[i].indexOf("#")!=0)
		{
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

function MM_jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) 
{
	var p,i,x;  
	if (!d) d=document; 
	if ((p=n.indexOf("?")) > 0&&parent.frames.length) 
	{
   		d = parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
  	if (!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0; !x&&i < d.forms.length; i++) x = d.forms[i][n];
  	for (i=0; !x&&d.layers&&i < d.layers.length; i++) x = MM_findObj(n,d.layers[i].document);
  	if (!x && document.getElementById) x=document.getElementById(n); 
	return x;
}

function MM_showHideLayers() 
{
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
	if ((obj=MM_findObj(args[i]))!=null) 
  	{ 
		v=args[i+2];
		if (obj.style) 
		{ 
			obj=obj.style; 
			v=(v=='show')?'visible':(v='hide')?'hidden':v; 
		}
		obj.visibility=v; 
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function openNewWindow(URLtoOpen, windowName, windowFeatures) 
{ 
	if (newWindow) newWindow.close(); 
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
} 

function openNewWindow(URLtoOpen, windowName, windowFeatures) 
{ 
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
	newWindow.focus(); 
}

function MM_openBrWindow(theURL,winName,features) 
{
	window.open(theURL,winName,features);
}

function MM_popupMsg(msg) 
{
	alert(msg);
}

//strBaseURL	= '87.224.103.206';
strBaseURL		= 'adventure.klio.co.uk';
var isNS4;
var isNS6;
var isIE4;
var isIE5;
var strPlatform;

isNS4 		= (document.layers) ? true : false;
isIE4 		= (document.all && !document.getElementById) ? true : false;
isIE5 		= (document.all && document.getElementById) ? true : false;
isNS6 		= (!document.all && document.getElementById) ? true : false;

Browser 	= navigator.appName
Net 		= Browser.indexOf("Netscape")
Micro 		= Browser.indexOf("Microsoft")
Netscape 	= false
IE 			= false

if(Net >= 0) 
{
	Netscape = true
}

if(Micro >= 0) 
{
	IE = true
}

var xPos;
var yPos;
document.onmousemove = XYpos;

var updateRequest = createMultiRequest();

function createRequest()
{
	try
	{
		request = new XMLHttpRequest();
	}
	catch (trymicrosoft)
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed)
			{
				request = null;
			}
		}
	}

	if(request == null)
	{
		alert("Error creating request object");
	}

	return request;
}

function createMultiRequest()
{
	try
	{
		request = new XMLHttpRequest();
	}
	catch (trymicrosoft)
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed)
			{
				request = null;
			}
		}
	}
 
	if(request == null)
	{
		alert("Error creating request object");
	}
 
	return request;
}

function XYpos(e) 
{
	if (IE == true) 
	{
		xPos = event.screenX
		yPos = event.screenY
	}
	else
	{
		xPos = e.clientX;
		yPos = e.clientY;
	}
	
	yPos = document.documentElement.scrollTop + yPos;
}

function getMouseXY(e) 
{
	if (IE) 
	{ // grab the x-y pos.s if browser is IE
		xPos = event.clientX + document.body.scrollLeft
		yPos = event.clientY + document.body.scrollTop
	} 
	else
	{  // grab the x-y pos.s if browser is NS
		xPos = e.pageX
		yPos = e.pageY
	}  
	// catch possible negative values in NS4
	if (xPos < 0){xPos = 0}
	if (yPos < 0){yPos = 0}  
  
  	return true
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop 	= obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop 	+= obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function is_int(strValue)
{
	var i;

	if (isEmpty(strValue.value))
	{
		return 'empty';
	}

	for (iCount = 0; iCount < strValue.value.length; iCount++)
	{
		var strThisChar = strValue.value.charAt(iCount);

		if (!isDigit(strThisChar))
		{
			return false;
		}
	}
	
	return true;
}

function isEmpty(strValue)
{
	return ((strValue == null) || (strValue.length == 0))
}

function isDigit(iValue)
{
	return ((iValue >= "0") && (iValue <= "9"))
}



function changeActionDiv(strContent, strVisibleStatus, leftPos, topPos)
{
	hActionDiv 					= document.getElementById("actionDiv");
	hActionDiv.innerHTML		= strContent;
	hActionDiv.style.visibility	= strVisibleStatus;
	hActionDiv.style.top		= topPos + 'px';
	hActionDiv.style.left		= leftPos + 'px';
}

function showActionLayer(iLeft, iTop, iWidth, iHeight)
{
	hALayer						= document.getElementById("actionLayer");
	hALayer.style.background	= '#FFFFFF';
	hALayer.style.visibility	= 'visible';
	hALayer.style.left			= iLeft + 'px';
	hALayer.style.top			= iTop + 'px';
	hALayer.style.width			= iWidth + 'px';
	hALayer.style.height		= iHeight + 'px';
}

function hideActionLayer()
{
	hALayer 					= document.getElementById("actionLayer");
	hALayer.style.visibility	= 'hidden';
}

function hideActionDiv()
{
//	if(IE)
//	{
//		upload					= document.getElementById("actionLayer");
//		upload.style.visibility	= 'hidden';
//	}

	handle 						= document.getElementById("actionDiv");
	handle.style.visibility 	= "hidden";
}

function getCheckedValue(radioObj) 
{
	if(!radioObj)	return "";
	
	var radioLength = radioObj.length;
	
	if(radioLength == undefined)
	{
		if(radioObj.checked)
		{
			return radioObj.value;
		}
		else
		{
			return "";
		}
	}
	
	for(var i = 0; i < radioLength; i++) 
	{
		if(radioObj[i].checked) 
		{
			alert(radioObj[i].value);
			return radioObj[i].value;
		}
	}
	return "";
}



// Stock Check
function getWeeks()
{
	strType		= getCheckedValue('stock.recording');
	
	strType		= '';
	iLength		= document.stock.recording.length;

	for (i = 0; i < iLength; i++) 
	{
		if (document.stock.recording[i].checked) 
		{
			strType = document.stock.recording[i].value;
		}
	}
	
	if(strType.length > 0)
	{
		iVenueID	= document.getElementById('venueid').value;
		
		var strURL	= 'http://' + strBaseURL + '/admin/stocks/getweeks.php?venueid=' + iVenueID + '&type=' + strType + '&dummy=' + new Date().getTime();
	
		week = createRequest();
		week.open("GET", strURL, true);
		week.onreadystatechange = showWeekDrop;
		week.send(null);
	}
	else
	{
		alert('Please choose either Delivery or Stock Check');
	}
}

function showWeekDrop()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("weekDropSpan");
		handle.innerHTML = week.responseText;
	}
	else
	{
		handle = document.getElementById("weekDropSpan");
		handle.innerHTML = 'Please wait while the list is compiled';
	}
}

function getProducts()
{
	iWeekID		= document.getElementById('weekid').value;
	iVenueID	= document.getElementById('venueid').value;
	
	strType		= '';
	iLength		= document.stock.recording.length;

	for (i = 0; i < iLength; i++) 
	{
		if (document.stock.recording[i].checked) 
		{
			strType = document.stock.recording[i].value;
		}
	}
	
	var strURL	= 'http://' + strBaseURL + '/admin/stocks/getproducts.php?venueid=' + iVenueID + '&weekid=' + iWeekID + '&type=' + strType + '&dummy=' + new Date().getTime();
	
//	alert(strURL);

	products = createRequest();
	products.open("GET", strURL, true);
	products.onreadystatechange = showProductInputTable;
	products.send(null);
}

function showProductInputTable()
{
	if(products.readyState == 4)
	{
		handle = document.getElementById("productTableSpan");
		handle.innerHTML = products.responseText;
	}
}

function viewProducts(iWeekID, iVenueID)
{	
	var strURL	= 'http://' + strBaseURL + '/admin/stocks/getproductstoedit.php?venueid=' + iVenueID + '&weekid=' + iWeekID + '&dummy=' + new Date().getTime();
	
	products = createRequest();
	products.open("GET", strURL, true);
	products.onreadystatechange = showWeekData;
	products.send(null);
}

function showWeekData()
{
	if(products.readyState == 4)
	{
		handle = document.getElementById("productTableSpan");
		handle.innerHTML = products.responseText;
	}
}

function changeSCValues(iWeekID, iVenueID, iProductID, strDel, strEnd, strPrice)
{
	// Make the names of the spans and inputs
	strDelSpan			=	'delivered_' + iProductID + '_span';
	strEndSpan			=	'ending_' + iProductID + '_span';
	strPriceSpan		=	'price_' + iProductID + '_span';
	strEditSpan			=	'edit_' + iProductID + '_span';
	strDelInput			=	'delivered_' + iProductID;
	strEndInput			=	'ending_' + iProductID;
	strPriceInput		=	'price_' + iProductID;
	
	// Create handles to the right spans
	hDelivery			=	document.getElementById(strDelSpan);
	hEnding				=	document.getElementById(strEndSpan);
	hPrice				=	document.getElementById(strPriceSpan);
	hEdit				=	document.getElementById(strEditSpan);
	
	// Make the new html for the spans
	strDel				=	'<input type="text" name="delivered_' + iProductID + '" value="' + strDel + '" size="1" class="required" id="' + strDelInput + '">';
	strEnding			=	'<input type="text" name="ending_' + iProductID + '" value="' + strEnd + '" size="1" class="required" id="' + strEndInput + '">';
	strPrice			=	'<input type="text" name="price_' + iProductID + '" value="' + strPrice + '" size="4" class="required" id="' + strPriceInput + '">';
	strEdit				=	'<a href="javascript:changeWeekValues(\'' + iWeekID + '\', \'' + iVenueID + '\', \'' + iProductID + '\')" class="subheaderlink">update</a>';
	
	// Change the span contents
	hDelivery.innerHTML	=	strDel;
	hEnding.innerHTML	=	strEnding;
	hPrice.innerHTML	=	strPrice;
	hEdit.innerHTML		=	strEdit;
	
	return;
}

function changeWeekValues(iWeekID, iVenueID, iProductID)
{
	// Make the names of the spans and inputs
	strDelSpan			=	'delivered_' + iProductID + '_span';
	strEndSpan			=	'ending_' + iProductID + '_span';
	strPriceSpan		=	'price_' + iProductID + '_span';
	strEditSpan			=	'edit_' + iProductID + '_span';
	strDelInput			=	'delivered_' + iProductID;
	strEndInput			=	'ending_' + iProductID;
	strPriceInput		=	'price_' + iProductID;
	
	// Create handles to the right input and spans
	hDelivery			=	document.getElementById(strDelInput);
	hEnding				=	document.getElementById(strEndInput);
	hPrice				=	document.getElementById(strPriceInput);
	hDeliverySpan		=	document.getElementById(strDelSpan);
	hEndingSpan			=	document.getElementById(strEndSpan);
	hPriceSpan			=	document.getElementById(strPriceSpan);
	hEditSpan			=	document.getElementById(strEditSpan);
	
	// Get the data from the input boxes
	strDel				=	hDelivery.value;
	strEnding			=	hEnding.value;
	strPrice			=	hPrice.value;
	strEdit				=	'<a href="javascript:changeSCValues(\'' + iWeekID + '\', \'' + iVenueID + '\', \'' + iProductID + '\', \'' + strDel + '\', \'' + strEnding + '\', \'' + strPrice + '\')" class="subheaderlink">edit</a>';
	
	// Check we have values for everything
	if((strDel.length > 0) && (strEnding.length > 0) && (strPrice.length > 0))
	{
		var strURL	= 'http://' + strBaseURL + '/admin/stocks/getupdateprice.php?venueid=' + iVenueID + '&weekid=' + iWeekID + '&iProductID=' + iProductID + '&delivered=' + strDel + '&ending=' + strEnding + '&price=' + strPrice + '&dummy=' + new Date().getTime();
		
		// Change the span contents
		hDeliverySpan.innerHTML	=	'<strong>' + strDel + '</strong>';
		hEndingSpan.innerHTML	=	'<strong>' + strEnding + '</strong>';
		hPriceSpan.innerHTML	=	strPrice;
		hEditSpan.innerHTML		=	strEdit;
		
		products = createRequest();
		products.open("GET", strURL, true);
		products.onreadystatechange = doValueChange;
		products.send(null);
	}
	else
	{
		alert('Please make sure you have entered values for all fields');
	}
}

function doValueChange()
{
	if(products.readyState == 4)
	{
		if(products.responseText.length > 4)
		{
//			alert(products.responseText);
			alert('Update Failed. Please call support');
		}
		else
		{
			alert('Update Successful');
		}
	}
}



// Rota
function getRotaWeeks()
{
	iVenueID	= document.getElementById('venueid').value;
		
	var strURL	= 'http://' + strBaseURL + '/admin/rotas/getweeks.php?venueid=' + iVenueID + '&dummy=' + new Date().getTime();

	week = createRequest();
	week.open("GET", strURL, true);
	week.onreadystatechange = showWeekDrop;
	week.send(null);
}

function showRotaWeekDrop()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("weekDropSpan");
		handle.innerHTML = week.responseText;
	}
}

function getRotaDetails()
{
	iWeekID		= document.getElementById('weekid').value;
		
	var strURL	= 'http://' + strBaseURL + '/admin/rotas/getdetails.php?weekid=' + iWeekID + '&dummy=' + new Date().getTime();

	week = createRequest();
	week.open("GET", strURL, true);
	week.onreadystatechange = showRotaDetails;
	week.send(null);
}

function showRotaDetails()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("rotaTableSpan");
		handle.innerHTML = week.responseText;
	}
}

function getWeeksHotButtons()
{
	iVenueID	= document.getElementById('iVenueID').value;
	
	if(iVenueID > 0)
	{
		var strURL	= 'http://' + strBaseURL + '/admin/rotas/getweeks.php?iVenueID=' + iVenueID + '&dummy=' + new Date().getTime();
	
		week = createRequest();
		week.open("GET", strURL, true);
		week.onreadystatechange = showWeekHotButtonDrop;
		week.send(null);
	}
	else
	{
		alert('Please choose a venue');
	}
}

function showWeekHotButtonDrop()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("weekdropspan");
		handle.innerHTML = week.responseText;
	}
	else
	{
		handle = document.getElementById("weekdropspan");
		handle.innerHTML = 'Please wait while the list is compiled';
	}
}

function getDayHotButtons()
{
	iVenueID	= document.getElementById('iVenueID').value;
	iWeekID	= document.getElementById('iWeekID').value;
	
	if(iVenueID > 0)
	{
		var strURL	= 'http://' + strBaseURL + '/admin/rotas/getdays.php?iVenueID=' + iVenueID + '&iWeekID=' + iWeekID + '&dummy=' + new Date().getTime();
	
		week = createRequest();
		week.open("GET", strURL, true);
		week.onreadystatechange = showDayHotButtonDrop;
		week.send(null);
	}
	else
	{
		alert('Please choose a week');
	}
}

function showDayHotButtonDrop()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("daydropspan");
		handle.innerHTML = week.responseText;
	}
	else
	{
		handle = document.getElementById("daydropspan");
		handle.innerHTML = 'Please wait while the list is compiled';
	}
}

function getHotButtons()
{
	var strURL	= 'http://' + strBaseURL + '/admin/rotas/gethotbuttons.php?dummy=' + new Date().getTime();
	
	week = createRequest();
	week.open("GET", strURL, true);
	week.onreadystatechange = showHotButtons;
	week.send(null);
}

function showHotButtons()
{
	if(week.readyState == 4)
	{
		handle = document.getElementById("hotbuttonsspan");
		handle.innerHTML = week.responseText;
	}
	else
	{
		handle = document.getElementById("hotbuttonsspan");
		handle.innerHTML = 'Please wait while the hot buttons are compiled';
	}
}



// Daily Functions
function getSafeInput()
{
	iVenueID	= document.getElementById('venueid').value;
	iDay		= document.getElementById('safe_day').value;
	iMonth		= document.getElementById('safe_month').value;
	iYear		= document.getElementById('safe_year').value;
	
	document.getElementById('checked').value = 0;
		
	var strURL	= 'http://' + strBaseURL + '/admin/daily/getsafeinputs.php?v=' + iVenueID + '&d=' + iDay + '&m=' + iMonth + '&y=' + iYear + '&dummy=' + new Date().getTime();

	safe = createRequest();
	safe.open("GET", strURL, true);
	safe.onreadystatechange = showSafeInputs;
	safe.send(null);
}

function showSafeInputs()
{
	if(safe.readyState == 4)
	{
		if(safe.responseText == 'Both the opening and closing logs have been completed for this date/venue. Moving to cash logs')
		{
			alert(safe.responseText);
			window.location	=	'cashlogs.php?m=new';
		}
		else
		{
			handle = document.getElementById("safeTableSpan");
			handle.innerHTML = safe.responseText;
		}
	}
}

function editSafeLog(iSafeID, strID, iStart, iFinish)
{
	hStart				=	document.getElementById(strID + "_S");
	hFinish				=	document.getElementById(strID + "_F");
	hEdit				=	document.getElementById(strID + "_E");
	
	strStartInput		=	'<input type="text" name="start" value="' + iStart + '" size="5" id="start">';
	strFinishInput		=	'<input type="text" name="finish" value="' + iFinish + '" size="5" id="finish">';
	strEditInput		=	'<a href="javascript:updateSafeLog(\'' + iSafeID + '\', \'' + strID + '\')" class="subheaderlink">update</a>';
	
	hStart.innerHTML	= 	strStartInput;
	hFinish.innerHTML	= 	strFinishInput;
	hEdit.innerHTML		= 	strEditInput;
}

function updateSafeLog(iSafeID, strID)
{
	hStart				=	document.getElementById("start");
	hFinish				=	document.getElementById("finish");
	
	iStart				=	hStart.value;
	iFinish				=	hFinish.value;
	
	// Check we have values for everything
	if((iStart.length > 0) && (iFinish.length > 0))
	{
		var strURL	= 'http://' + strBaseURL + '/admin/daily/getupdatesafelog.php?i=' + iSafeID + '&d=' + strID + '&s=' + iStart + '&f=' + iFinish + '&dummy=' + new Date().getTime();
		
		// Change the span contents
		hStart				=	document.getElementById(strID + "_S");
		hFinish				=	document.getElementById(strID + "_F");
		hEdit				=	document.getElementById(strID + "_E");
		
		hStart.innerHTML	=	iStart;
		hFinish.innerHTML	=	iFinish;
		hEdit.innerHTML 	=	'<a href="javascript:editSafeLog(\'' + iSafeID + '\', \'' + strID + '\', \'' + iStart + '\', \'' + iFinish + '\');" class="subheaderlink">Edit</a>';
		
		safe = createRequest();
		safe.open("GET", strURL, true);
		safe.onreadystatechange = doSafeLogChange;
		safe.send(null);
	}
	else
	{
		alert('Please make sure you have entered values for all fields');
	}
}

function doSafeLogChange()
{
	if(safe.readyState == 4)
	{
		if(safe.responseText.length > 4)
		{
			alert('Update Failed. Please call support');
		}
		else
		{
			alert('Update Successful');
		}
	}
}

function editCashLog(iCashID, strID, iTotal)
{
	hTotal				=	document.getElementById(strID + "_SPAN");
	hEdit				=	document.getElementById(strID + "_E");
	
	strTotalInput		=	'<input type="text" name="total" value="' + iTotal + '" size="5" id="total">';
	strEditInput		=	'<a href="javascript:updateCashLog(\'' + iCashID + '\', \'' + strID + '\')" class="subheaderlink">update</a>';
	
	hTotal.innerHTML	= 	strTotalInput;
	hEdit.innerHTML		= 	strEditInput;
}

function updateCashLog(iCashID, strID)
{
	hTotal				=	document.getElementById("total");	
	iTotal				=	hTotal.value;
	
	// Check we have values for everything
	if(iTotal.length > 0)
	{
		var strURL	= 'http://' + strBaseURL + '/admin/daily/getupdatecashlog.php?i=' + iCashID + '&f=' + strID + '&t=' + iTotal + '&dummy=' + new Date().getTime();
		
		// Change the span contents
		hTotal				=	document.getElementById(strID + "_SPAN");
		hEdit				=	document.getElementById(strID + "_E");
		
		hTotal.innerHTML	=	iTotal;
		hEdit.innerHTML 	=	'<a href="javascript:editSafeLog(\'' + iCashID + '\', \'' + strID + '\', \'' + iTotal + '\');" class="subheaderlink">Edit</a>';
		
		cash = createRequest();
		cash.open("GET", strURL, true);
		cash.onreadystatechange = doCashLogChange;
		cash.send(null);
	}
	else
	{
		alert('Please make sure you have entered values for all fields');
	}
}

function doCashLogChange()
{
	if(cash.readyState == 4)
	{
		if(cash.responseText.length > 4)
		{
			alert('Update Failed. Please call support');
		}
		else
		{
			alert('Update Successful');
		}
	}
}

function getCashInput()
{
	iVenueID	= document.getElementById('venueid').value;
	iDay		= document.getElementById('cash_day').value;
	iMonth		= document.getElementById('cash_month').value;
	iYear		= document.getElementById('cash_year').value;
	
	document.getElementById('checked').value = 0;
		
	var strURL	= 'http://' + strBaseURL + '/admin/daily/getcashinputs.php?v=' + iVenueID + '&d=' + iDay + '&m=' + iMonth + '&y=' + iYear + '&dummy=' + new Date().getTime();

	cash = createRequest();
	cash.open("GET", strURL, true);
	cash.onreadystatechange = showCashInputs;
	cash.send(null);
}

function showCashInputs()
{
	if(cash.readyState == 4)
	{
		if(cash.responseText == 'A cash log for this date/venue already exists. Moving to hours log')
		{
			alert(cash.responseText);
			window.location	=	'hour.php?m=new';
		}
		else
		{
			handle = document.getElementById("cashTableSpan");
			handle.innerHTML = cash.responseText;
		}
	}
}

function getHoursInput()
{
	iVenueID	= document.getElementById('venueid').value;
	iDay		= document.getElementById('hours_day').value;
	iMonth		= document.getElementById('hours_month').value;
	iYear		= document.getElementById('hours_year').value;
	
	document.getElementById('checked').value = 0;
		
	var strURL	= 'http://' + strBaseURL + '/admin/daily/gethoursinputs.php?v=' + iVenueID + '&d=' + iDay + '&m=' + iMonth + '&y=' + iYear + '&dummy=' + new Date().getTime();

	hours = createRequest();
	hours.open("GET", strURL, true);
	hours.onreadystatechange = showHoursInputs;
	hours.send(null);
}

function showHoursInputs()
{
	if(hours.readyState == 4)
	{
		handle = document.getElementById("hoursTableSpan");
		handle.innerHTML = hours.responseText;
	}
}

function editHoursWorks(strDay, iRowID, strIn, strOut)
{
	strContent = '<table width="250" border="0" cellpadding="2" cellspacing="0"><tr><td align="center"><span class="subheader">Change Hours</span></td></tr><tr><td align="center">Enter times as 00:00 in 24 hour format<br><br>In: <input type="text" name="in" value="' + strIn +'" size="6" id="in">&nbsp;&nbsp;&nbsp;Out: <input type="text" name="out" value="' + strOut +'" size="6" id="out"><br><br><a href="javascript:updateHoursWorked(\'' + strDay + '\', \'' + iRowID + '\')" class="subheaderlink">Submit</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onClick="hideActionDiv(); return false;" class="subheaderlink">Cancel</a></td></tr></table>';
		
	changeActionDiv(strContent, 'visible', xPos - 150, yPos - 75);
}

function updateHoursWorked(strDay, iRowID)
{
	strIn		= document.getElementById('in').value;
	strOut		= document.getElementById('out').value;
			
	var strURL	= 'http://' + strBaseURL + '/admin/daily/getupdatehourslog.php?i=' + iRowID + '&d=' + strDay + '&in=' + strIn + '&out=' + strOut + '&dummy=' + new Date().getTime();
	
	hours = createRequest();
	hours.open("GET", strURL, true);
	hours.onreadystatechange = doHoursUpdate;
	hours.send(null);
}

function doHoursUpdate()
{
	if(hours.readyState == 4)
	{
		alert('Times updated, please refresh the page to see the changes');
		hideActionDiv();
	}
}

function validateLog(iHomeVenueID)
{
	iVenueID	= document.getElementById('venueid').value;
	
	if(iVenueID != iHomeVenueID)
	{
		iChecked	= document.getElementById('checked').value;
		if(iChecked == 0)
		{
			alert('You are about to save data for a store that is not your default. If this is incorrect, please change you selection now, or click \'Save Safe Log\' again to continue');
			document.getElementById('checked').value = 1;
		}
		else
		{
			document.daily.submit();
		}
	}
	else
	{
		document.daily.submit();
	}
}

function editParLevels(strID)
{
	// Make the names of the spans and inputs
	strBalSpan			=	strID + '_BAL';
	strBatSpan			=	strID + '_BAT';
	strDulSpan			=	strID + '_DUL';
	strEditSpan			=	strID + '_EDIT';
	strBalHidden		=	strID + '_BALH';
	hBatHidden			=	strID + '_BATH';
	hDulHidden			=	strID + '_DULH';
	
	// Create handles to the right spans
	hBalHidden			=	document.getElementById(strBalHidden);
	hBatHidden			=	document.getElementById(hBatHidden);
	hDulHidden			=	document.getElementById(hDulHidden);
	hBalSpan			=	document.getElementById(strBalSpan);
	hBatSpan			=	document.getElementById(strBatSpan);
	hDulSpan			=	document.getElementById(strDulSpan);
	hEditSpan			=	document.getElementById(strEditSpan);
	
	// Get the old data
	strBalVal			=	hBalHidden.value;
	strBatVal			=	hBatHidden.value;
	strDulVal			=	hDulHidden.value;
	
	// Make the new html for the spans
	strBal				=	'<input type="text" name="' + strID + '_BALI" value="' + strBalVal + '" size="7" class="required" id="' + strID + '_BALI">';
	strBat				=	'<input type="text" name="' + strID + '_BATI" value="' + strBatVal + '" size="7" class="required" id="' + strID + '_BATI">';
	strDul				=	'<input type="text" name="' + strID + '_DULI" value="' + strDulVal + '" size="7" class="required" id="' + strID + '_DULI">';
	strEdit				=	'<a href="javascript:changeParValues(\'' + strID + '\')" class="subheaderlink">update</a>';
	
	// Change the span contents
	hBalSpan.innerHTML		=	strBal;
	hBatSpan.innerHTML		=	strBat;
	hDulSpan.innerHTML		=	strDul;
	hEditSpan.innerHTML		=	strEdit;
	
	return;
}

function changeParValues(strID)
{
	// Make the names of the spans and inputs
	strBalSpan			=	strID + '_BAL';
	strBatSpan			=	strID + '_BAT';
	strDulSpan			=	strID + '_DUL';
	strEditSpan			=	strID + '_EDIT';
	strBalInput			=	strID + '_BALI';
	strBatInput			=	strID + '_BATI';
	strDulInput			=	strID + '_DULI';
	strBalHidden		=	strID + '_BALH';
	strBatHidden		=	strID + '_BATH';
	strDulHidden		=	strID + '_DULH';
	
	// Create handles to the right spans
	hBalInput			=	document.getElementById(strBalInput);
	hBatInput			=	document.getElementById(strBatInput);
	hDulInput			=	document.getElementById(strDulInput);
	hBalSpan			=	document.getElementById(strBalSpan);
	hBatSpan			=	document.getElementById(strBatSpan);
	hDulSpan			=	document.getElementById(strDulSpan);
	hEditSpan			=	document.getElementById(strEditSpan);
	hBalHidden			=	document.getElementById(strBalHidden);
	hBatHidden			=	document.getElementById(strBatHidden);
	hDulHidden			=	document.getElementById(strDulHidden);
	
	// Get the data from the input boxes
	strBal				=	hBalInput.value;
	strBat				=	hBatInput.value;
	strDul				=	hDulInput.value;
	strEdit				=	'<a href="javascript:editParLevels(\'' + strID + '\')" class="subheaderlink">edit</a>';
	
	// Check we have values for everything
	if((strBal.length > 0) && (strBat.length > 0) && (strDul.length > 0))
	{
		var strURL	= 'http://' + strBaseURL + '/admin/daily/getupdateparlevels.php?field=par' + strID + '&bal=' + strBal + '&bat=' + strBat + '&dul=' + strDul + '&dummy=' + new Date().getTime();
		
		// Change the span contents
		hBalSpan.innerHTML	=	strBal + '<input type="hidden" name="' + strID + '_BALH" value="0" id="' + strID + '_BALH">';
		hBatSpan.innerHTML	=	strBat + '<input type="hidden" name="' + strID + '_BATH" value="0" id="' + strID + '_BATH">';
		hDulSpan.innerHTML	=	strDul + '<input type="hidden" name="' + strID + '_DULH" value="0" id="' + strID + '_DULH">';
		hEditSpan.innerHTML	=	strEdit;
		
		par = createRequest();
		par.open("GET", strURL, true);
		par.onreadystatechange = doParChange;
		par.send(null);
	}
	else
	{
		alert('Please make sure you have entered values for all fields');
	}
}

function doParChange()
{
	if(par.readyState == 4)
	{
		if(par.responseText.length > 4)
		{
			alert('Update Failed. Please call support');
		}
		else
		{
			alert('Update Successful');
		}
	}
}

function updateCashTotal(iTotal)
{
	hTotal	=	document.getElementById("runningtotal");
	hCBT	=	document.getElementById("cashbagtotal");
	
	iRunVal	=	0;
	
	for(iCount = 1; iCount < iTotal; iCount++)
	{
		handle	=	document.getElementById("field" + iCount);
		if(handle.value.length > 0)
		{
			iRunVal	=	eval(iRunVal) + eval(handle.value);
		}
	}
	
	iNewVal	=	'&pound;' + iRunVal.toFixed(2);
	hTotal.innerHTML =	iNewVal;
	hCBT.value =	iRunVal;
}


// Holiday Functions
function changeHolidayMonthView()
{
	iMonth		= document.getElementById('month').value;
	iYear		= document.getElementById('year').value;
		
	var strURL	= 'http://' + strBaseURL + '/admin/rotas/getcalview.php?m=' + iMonth + '&y=' + iYear + '&dummy=' + new Date().getTime();

	hols = createRequest();
	hols.open("GET", strURL, true);
	hols.onreadystatechange = showHolidayCalendar;
	hols.send(null);
}

function showHolidayCalendar()
{
	if(hols.readyState == 4)
	{
		handle = document.getElementById("calSpan");
		handle.innerHTML = hols.responseText;
	}
}


// Training Functions
function addTestResult(iTestID, iStaffID, iTry)
{
	strContent = '<form action="./training.php?m=add" method="post"><table width="250" border="0" cellpadding="2" cellspacing="0"><tr><td align="center" class="mainheader">Test ' + iTestID + ' attempt ' + iTry + ' Result</td></tr><tr><td align="center">Score: <input type="text" name="total" value="" size="6">%</td></tr><tr><td align="center"><input type="submit" name="save" value=" Save Test Result " class="button" />&nbsp;&nbsp;&nbsp;<input type="button" value=" Cancel " onClick="hideActionDiv(); return false;"></td></tr></table><input type="hidden" name="iTestID" value="' + iTestID + '" /><input type="hidden" name="iStaffID" value="' + iStaffID + '" /><input type="hidden" name="iTry" value="' + iTry + '" /></form>';
		
	changeActionDiv(strContent, 'visible', xPos - 150, yPos - 75);
}

function addScheduledTest(iTestID, iStaffID)
{
	strContent = '<form action="./training.php?m=schedule" method="post"><table width="250" border="0" cellpadding="2" cellspacing="0"><tr><td align="center" class="mainheader">Test ' + iTestID + ' Scheduled For</td></tr><tr><td align="center">Date: <select name="iDay" size="1"><option value="" selected></option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select> - <select name="iMonth" size="1"><option value="" selected></option><option value="01">Jan</option><option value="02">Feb</option><option value="03">Mar</option><option value="04">Apr</option><option value="05">May</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Aug</option><option value="09">Sep</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option></select> - <select name="iYear" size="1"><option value="" selected></option><option value="2009">2009</option><option value="2010">2010</option><option value="2011">2011</option></select></td></tr><tr><td align="center"><input type="submit" name="save" value=" Save Test Date " class="button" />&nbsp;&nbsp;&nbsp;<input type="button" value=" Cancel " onClick="hideActionDiv(); return false;"></td></tr></table><input type="hidden" name="iTestID" value="' + iTestID + '" /><input type="hidden" name="iStaffID" value="' + iStaffID + '" /></form>';
		
	changeActionDiv(strContent, 'visible', xPos - 150, yPos - 75);
}


// Forum functions
function showReplyEntry(iThreadID)
{
	hReplySpan	=	document.getElementById('replySpan');
	
	strOutput	=	'<form action="./index.php" method="POST" name="reply"><textarea name="content" cols="120" rows="5"></textarea><br><input type="submit" name="save" value=" Save Reply " class="button"><input type="hidden" name="m" value="savereply" ><input type="hidden" name="iThreadID" value="' + iThreadID + '" ></form>';
	
	hReplySpan.innerHTML	=	strOutput;
}















