var mainHash = "";
var tempUrl = location.href.split("#");
var targetDiv = "";
var menuOpened = false;

function newHash(value)
{
	window.hash(value);
	return false;
}

function updateFlash(flashHash)
{
	alert (flashHash);
	var flash = window.document.bluecastle;
	flash.SetVariable("hash", flashHash);
}

function openDiv(source)
{
	if (source != "false")
	{
		document.getElementById("hoverDiv").style.display = "block";

		if (document.getElementById("hoverDivContent"))
		{
			ajax(source, "hoverDivContent");
		}
	}
}

function closeDiv()
{
	if (document.getElementById("hoverDivContent"))
	{
		document.getElementById("hoverDivContent").innerHTML = "";
	}

	if (document.getElementById("hoverDiv"))
	{
		document.getElementById("hoverDiv").style.display = "none";
	}
}

function ajax(page, resultDiv, opened)
{
	if (page != "false")
	{
		targetDiv = resultDiv;
		
		xmlHttpCustom = GetXmlHttpObjectCustom();

		if (xmlHttpCustom == null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}

		if (page.indexOf("?") > -1)
		{
			url = page + "&menuOpened=" + opened;
		}
		else
		{
			url = page + "?menuOpened=" + opened;
		}

		xmlHttpCustom.onreadystatechange = stateChanged;
		xmlHttpCustom.open("GET",url,true);
		xmlHttpCustom.send(null);

		return false;
	}
}

function stateChanged() 
{
	if (xmlHttpCustom.readyState == 4 || xmlHttpCustom.readyState == "complete")
	{
		document.getElementById(targetDiv).innerHTML = xmlHttpCustom.responseText;
	}
}

function GetXmlHttpObjectCustom()
{
	var xmlHttp = null;

	try
	{
		xmlHttp = new XMLHttpRequest();
	}
		catch (e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}

function swapImage(imageId)
{
	if (document.getElementById(imageId))
	{
		if (document.getElementById(imageId).src.indexOf("/images/basic/bullet_media.gif") > -1)
		{
			document.getElementById(imageId).src = "/images/basic/bullet_media_opened.gif";
			document.getElementById("subMenu").style.display = "block";
			menuOpened = true;
		}
		else
		{
			document.getElementById(imageId).src = "/images/basic/bullet_media.gif";
			document.getElementById("subMenu").style.display = "none";
			menuOpened = false;
		}

		document.getElementById(imageId).blur();

		return false;
	}
}

function sendEmail(itemId)
{
	window.location = "mailto:\?subject\=Blue Castle Games&body=Blue Castle Games: " + window.location + "|itemId," + itemId;

	return false;
}

function printableVersion(releaseId)
{
	window.open("/php/mediacentre/printrelease.php?releaseId="+releaseId+"&print=true", "printableVersion", "width=900, height=580, menubar=no, toolbars=no, resizable=no");

	return false;
}







function printURL() {
	var header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Printable version</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
	header += '<link rel="stylesheet" href="/css/default.css" type="text/css"><style>body {background-color: #ffffff; margin: 0px; padding: 0px;}</style></head>';
	header += '<body onLoad="window.print();">';
	header += '<table align="center"><tr><td width="100%" bgcolor="#ffffff">';
	var footer = '</td></tr></table></body></html>';

	var strInner = document.body.innerHTML;
	var startPos = strInner.lastIndexOf("<!-- print_start -->");	
	var endPos = strInner.lastIndexOf("<!-- print_end -->");
	strInner = strInner.substring(startPos+20, endPos);
		
	if (strInner.lastIndexOf("<!-- print_pause_on -->") > -1){
		var str1 = "<!-- print_pause_on -->";
		var str2 = "<!-- print_pause_off -->";
		startPos = strInner.lastIndexOf(str1);	
		endPos = strInner.lastIndexOf(str2);
		if (endPos > startPos){
			leftStr = strInner.substring(0, startPos);
			rightStr = strInner.substring(endPos + str2.length, strInner.length);
			strInner =	 leftStr + rightStr;
		}
	}
	var xwin = window.open("/code/printable.php", "PrintVersion", "menubar=yes, scrollbars=yes, resizable=yes, width=625, toolbar=yes, statubar=no");
	xwin.document.write(header+strInner+footer);
}

function isPPC() {
	if (navigator.appVersion.indexOf("PPC") != -1) return true;
	else return false;
}

function sendPage(mailHeadline){
	if(!isPPC()) {
		window.location="mailto:\?subject\=" + mailHeadline + "&body=" + mailHeadline + ": " + window.location;
	}else { 
		window.location="mailto:\?body=" + mailHeadline + ": " + window.location;
	}
}
