/**
 * Old javascript crap used on old version of itzone website,
 * some of this stuff is still required (just while new version is in
 * development stage, slowly - slowly is unnecessary crap gonna be bounced
 * and neccessary stuff is gonna be rewrited as some nice part of Page object)
 *
 */
var PreloadFlag = false;
var expDays = 90;
var exp = new Date();
var tmp = '';
var tmp_counter = 0;
var tmp_open = 0;
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

/**
 * Simply sets a cookie
 *
 */
function SetCookie(name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

/**
 * Used internaly by GetCookie to get cookie value from cookie data
 *
 */
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1)
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

/**
 * Simply returns value of cookie
 *
 */
function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

/**
 * Switches visibility of one or two elements, and it could set cookie to save
 * whether has element been hidden or shown
 *
 */
function ShowHide(id1, id2, id3)
{
	var res = expMenu(id1);
	if (id2 != '') expMenu(id2);
	if (id3 != '') SetCookie(id3, res, exp);
}

/**
 * Switches visibility of item with specified id
 *
 */
function expMenu(id)
{
	var itm = null;
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm)
	{
		// do nothing
	}
	else if (itm.style)
	{
		if (itm.style.display == "none")
		{
			itm.style.display = "";
			return 1;
		}
		else
		{
			itm.style.display = "none";
			return 2;
		}
	}
	else
	{
		itm.visibility = "show";
		return 1;
	}
}

/**
 * Shows element with specified ID
 *
 */
function Show(id)
{
	var itm = null;
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm)
	{
		// do nothing
	}
	else if (itm.style)
	{
			itm.style.display = "";
	}
	else
	{
		itm.visibility = "show";
	}

	return false;
}

/**
 * Hides element with specified ID
 *
 */
function Hide(id)
{
	var itm = null;
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm)
	{
		// do nothing
	}
	else (itm.style)
	{
			itm.style.display = "none";
	}

	return false;
}

/**
 * Server-time driven clock by XShady
 *
 */
var ServerClockTime = new Date();

function startServerClock(elementId)
{
	Page.setInterval('doServerClock("' + elementId + '")', 500);
}

function doServerClock(elementId)
{
	var serverDate = new Date();
	serverDate.setTime(Page.getServerTime());

    writeTimeToElement(serverDate, document.getElementById(elementId));
}

function writeTimeToElement(objDate, elementObj){
	var hours = objDate.getHours();
	var minutes = objDate.getMinutes();
	var seconds = objDate.getSeconds();

	if (hours == 0)
		hours = "0" + hours;
	if (minutes <= 9)
		minutes = "0" + minutes;
	if (seconds <= 9)
		seconds = "0" + seconds;

	elementObj.innerHTML = hours + ":" + minutes + ":" + seconds;
}