<!--

// Functions

// 2004-09-10	checkCookie		:	Looks for presence of 'chat' cookie and offers user the option to return to last logged page
// 2004-09-10	getTime			:	Compares system time against defined opening and closing times
// 2004-09-10	showOpen		:	Called from getTime - details to be displayed when store open
// 2004-09-10	showClosed		:	Called from getTime - details to be displayed when store closed

function checkCookie()
{
	if (getCookie("chat"))
	{
		var cookieData = getCookie("chat");
		var cookieDataArray = cookieData.split("~");
		var end_count=cookieDataArray.length;

		// This is supposed to be the URL where the customer left the troubleshooting process
		var refURL = cookieDataArray[5];

		// A special case is where they've been to chat, and we've added a ?chat=1 to the URL
		//try {var paramPos = refURL.indexOf('?chat'); } catch(err){}
		try {var paramPos = refURL.indexOf('?chat');} catch(err){}

		// If there's a refURL, ask if we want to go back, otherwise, clear it out
		if (refURL && (paramPos == -1))
		{

			// Special case needed for when the saved URL is the iMac index page
			var supportDirLoc = refURL.indexOf('/support/imac/');
			var baseURL = refURL.substring(supportDirLoc,refURL.length);
			if ((baseURL != '/support/imac/' && baseURL != '/support/imac/index.html') && refURL.indexOf('assistant/') != -1) {
				alert("It appears that you've been using the troubleshooting assistant, we\'ll provide an option to return where you left off.");
				htmlText = '<span class="G10"><a href="javascript:displayHelpWindow(\'/support/imac/assistant/reenter.html?'+refURL+'\',450,440)" class="html">Resume where you left off...</a>';

				writeDiv('reenter', null, htmlText);

				// Remove the refURL so we don't ask again
				var cookieValue = cookieDataArray[0] + "~" + cookieDataArray[1] + "~" + cookieDataArray[2] + "~" + cookieDataArray[3] + "~" + cookieDataArray[4] + "~";
				setCookie("chat",cookieValue, "","/",".apple.com",""); 
			}
		}
	}
}


function getTime()
{
	var d = new Date()
	
	var h = (d.getUTCHours())
	var m = (d.getUTCMinutes())
	var s = (d.getUTCSeconds())
	
	if (h<10)
	{
		var h = '0' + h;
	}
	if (m<10)
	{
		var m = '0' + m;
	}
	if (s<10)
	{
		var s = '0' + s;
	}
	
	var newTime = h + m + s;
	
	document.write("Current Time (UTC): " + newTime);
	
	// Must convert open and close time to UTC for a point of reference
	// open 07:00 (15:00 UTC), closed 19:00 (03:00 UTC+1)
	// UTC is 7hrs ahead of PDT
	
	var openTime = "140000";
	var closedTime = "020000";
	
	if ((newTime>openTime)||(newTime<closedTime))
	{
		showOpen();
	}
	else
	{
		showClosed();
	}
}

function showOpen()
{
	// Details to be displayed if store is open
	document.write("<BR>Store Open");
}

function showClosed()
{
	// Details to be displayed if store is closed
	document.write("<BR>Store Closed");
}

//-->

