/*	MTCS - Seacove Javascript
**
**	© Copyright MTCS, all rights reserved
**
*/

/*	set global variables */

/*	display random graphic loop in browser */
function displayRandomGraphic()
{
	document.write("<img src=");
	document.write('"');
	document.write("images/");
	document.write(CurrentGraphic);
	document.write(".jpg");
	document.write('"');
	document.write(" width=");
	document.write('"');
	document.write("502");
	document.write('"');
	document.write(" height=");
	document.write('"');
	document.write("264");
	document.write('"');
	document.write(">");
}

/*	set cookie function stores the cookie by assigning the values to the document.cookie-object */
function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date();
	
	/*	converts the number of days to a valid date */
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays*24*3600*1000));

	/*	Note the date is converted to Greenwich Meantime using the 'toGMTstring()'-function */
	document.cookie = NameOfCookie + "=" + escape(value) + 
			((expiredays == null) ? "" : ";expires=" + ExpireDate.toGMTString());
}


/*	get cookie function loads the documents cookie to a string */
function getCookie(NameOfCookie)
{
	var begin, end, data = "";

	if(document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie + "=");
		if(begin != -1)
		{
			/* Cookie was set so the value stored in the cookie is returned from the function */
			begin += NameOfCookie.length + 1;
			end = document.cookie.indexOf(";", begin);
			if(end == -1)
				end = document.cookie.length;
			data = unescape(document.cookie.substring(begin, end));
		}
	}
	/* Cookie was not set so the value "" is returned from the function */
	return(data);
}


/*	general purpose delete cookie function */
function deleteCookie(NameOfCookie)
{
	/* checks if the cookie is set and if so expiry date is set to Jan. 1st 1970 */
	if(getCookie(NameOfCookie))
		document.cookie = NameOfCookie + "=" + ";expires= Thu, 01-Jan-70 00:00:01 GMT";
}


/*	Converts the string returned by a cookie into an array */
function cookieCutter(dough)
{
	var i = -1, currentItem = 0, offset = 0;
	var biteMe = new Array();
	dough = dough + ';';
	do
	{
		i++;
		if(dough.charAt(i) == ',' || (dough.charAt(i) == ';' && i != 0))
		{
			biteMe[currentItem] = dough.substring(offset,i);
			currentItem++;
			offset = i + 1;
		}
	}while(dough.charAt(i) != ';')
	return(biteMe);
}


/* formats a number for printing on the screen */
function screenNumber(number, currency)
{
	var buffer;

	buffer = String(Math.round(number * 100));
	buffer = buffer.substring(0, buffer.length - 2) + "." + buffer.substring(buffer.length - 2, buffer.length);
	if (currency)
		buffer = "$ " + buffer;
	return(buffer);
}
