// JavaScript Document

function fnShow(obj) {
		 if(document.getElementById){
		 	 document.getElementById(obj).style.display = "block";
		 }
		 
}

function fnHide(obj) {
		 if(document.getElementById){
		 	 document.getElementById(obj).style.display = "none";
		 }
		 
}

function fnShowHide(obj, obj2){
	 if(document.getElementById){
		 var el = document.getElementById(obj);
		 var el2 = document.getElementById(obj2);
	
	
		 if(el.style.display == "none"){
			 el.style.display = "block";
			 el2.style.display = "none";
		
		
		 }else{
		 	el.style.display = "none";
		 }
	
	 }
}

function MM_preloadImages() { //v3.0
  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_swapImgRestore() { //v3.0
  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) { //v4.01
  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() { //v3.0
  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 doMouseClick(targetName) {
	var event = null;
	var target = null;

	if (document.getElementById) {
		target = document.getElementById(targetName);
	}
	
	if (document.createEvent)
	{
		// None-IE browser
		event.initMouseEvent('click',
			true, // Click events bubble
			true, // and they can be cancelled
			document.defaultView, // Use the default view
			1, // Just a single click
			0, 0, 0, 0, // Don't bother with co-ordinates
			false, // Don't apply any key modifiers
			false,
			false,
			false,
			0, // 0 - left, 1 - middle, 2 - right
			null); // Click events don't have any targets other than
					// the recipient of the click
		target.dispatchEvent(event);
	} else {
		// IE
		target.fireEvent('onClick');	
	}
	
/*	if (document.createEvent) {
		event = document.createEvent('MouseEvents');
	}
	
	if(target & & target.dispatchEvent & & event & & event.initMouseEvent) {
	} */

}

/*
* Show product info overlay.
* Requires hidden link named "prodzoomanchor" - see end of index.jsp
*/
var imageLoadTimeout;
function showProductLayer(gameType, gameID, roomID, productID, colourScheme) 
{
	// biggest image - if images haven't loaded yet, need to loop round
	// until they have
	var imageLink = document.getElementById(gameType + 'HugeImageLink' + gameID).innerHTML;
	if (imageLink != "")
	{
		var image = document.getElementById("prodzoomimage"); 
		image.innerHTML = imageLink;
	} else {
		if (imageLoadTimeout != null)
		{
			clearTimeout(imageLoadTimeout);
			imageLoadTimeout = null;
		}
		imageLoadTimeout = setTimeout("showProductInfo('" + gameType + "', '" + gameID + "', '" + roomID + "', '" + productID + "')", 400);
		return;
	}

	// Description for title bar
	var descriptionHTML = document.getElementById(gameType + 'Desc' + gameID).innerHTML;
	descriptionParts = descriptionHTML.split(/[<>]/);
	var descIndex = 2; 
	if (descriptionParts.length == 3)
	{
		// Between games, the description is not a link, just text
		descIndex = 1;
	}
	document.getElementById("prodzoomtitle").innerHTML = descriptionParts[descIndex];
	 
	// Current price
	var price = "This game is now closed";
	var priceHTML = document.getElementById(gameType + 'Price' + gameID).innerHTML;
	var closed = (priceHTML.search(/Now/) < 0); 
	if (!closed)
	{
		priceParts = priceHTML.split(/[<>]/);
		if (gameType == "Web")
		{
			price = priceParts[5];
		}
		else if (gameType == "TV")
		{
			price = priceParts[4];
		}	
	}
	document.getElementById("prodzoomprice").innerHTML = price;
	
	// Quantity left
	if (gameType == "TV" && !closed)
	{
		var qtyLeft = document.getElementById(gameType + 'Qty' + gameID).innerHTML;
		var qtyLeftParts = qtyLeft.split(/[<>]/);
		document.getElementById("prodzoomquantity").innerHTML = "<p class='remaining'>Only " + qtyLeftParts[1] + "</p>"; 
	}
	
	// video
	var videoLink = document.getElementById(gameType + 'VideoLink' + gameID).innerHTML;
	insertVideo(videoLink);
	
	// short description ....
	var deliveryMessage = "";
	var deliveryPrice = "";
	if (!closed)
	{
		deliveryDate = document.getElementById('activeDeliveryDate').innerHTML;
		deliveryMessage = "This item can be delivered to you on<br />" + deliveryDate;
		deliveryPrice = document.getElementById(gameType + 'Delivery' + gameID).innerHTML;
	}
	document.getElementById("prodzoomdelivery").innerHTML = deliveryMessage;
	document.getElementById("prodzoompandp").innerHTML = deliveryPrice;
	
	// Buy link
	if (!closed)
	{
		var buyAction = "";
		var buyText = document.getElementById(gameType + 'Buy' + gameID).innerHTML;
		if (buyText.search(/href/) >= 0)
		{
			// There's an action, so display "buy now"
			var buyParts = buyText.split(/[<>]/);
			var anchor = buyParts[0];
			var anchorParts = anchor.split(/\"/);
			buyAction = anchorParts[1];
		}
		
		if (buyAction != "")
		{
			document.getElementById("prodzoombuy").innerHTML = 
				"<a href='../gemopedia/js/" + buyAction + "' class='prodzoombuynow'>" + 
				"<img src='/img/prodzoom/color" + colourScheme + "/btn-buy.gif' " +
				"alt='buy now' width='84' height='12' id='BuyImage' " +
				"onmouseover=\"MM_swapImage('BuyImage','','/img/prodzoom/color" + colourScheme + "/btn-buy_Over.gif',1)\" " +
				"onmouseout='MM_swapImgRestore()' />" +   
				"</a>";
		}
	}
	
	// Details link
	document.getElementById("prodzoomdetails").innerHTML = 
		"<a href='/games-current.jsp?game=" + gameType + gameID + "' class='viewfull'>" +
		"<img src='/img/prodzoom/color" + colourScheme + "/btn-viewdetails.gif' " +
		"alt='view full details' width='152' height='12' id='ViewImage' " +
		"onmouseover=\"MM_swapImage('ViewImage','','/img/prodzoom/color" + colourScheme + "/btn-viewdetails_Over.gif',1)\" " +
		"onmouseout='MM_swapImgRestore()' /></a>";

	doMouseClick('prodzoomanchor');
}

function showShopProductInfo(productType, productIndex) 
{
	// Description for title bar
	var description = document.getElementById('desc' + productIndex).innerHTML;
	if (productType == "game")
	{
		var fullDescription = document.getElementById('fulldesc' + productIndex).innerHTML;
		if (fullDescription.search(/Ex-Demo/) >= 0)
		{
			description += " (EX-DEMO PRODUCT)";		
		}
	}
	document.getElementById("prodzoomtitle").innerHTML = description;

	// Current price
	var price = "";
	if (productType == "shop")
	{
		// Just one fixed price
		price = document.getElementById('price' + productIndex).innerHTML;
	} else {
		// Show buy now price and bid price
		price = "<span class='left'>Buy Now for </span><span class='right'>";
		price += document.getElementById('buyprice' + productIndex).innerHTML;
		price += "</span><br /><span class='left'> or place a Forward Bid for </span><span class='right'>";		
		price += document.getElementById('bidprice' + productIndex).innerHTML;
		price += "</span>";		
	}
	document.getElementById("prodzoomprice").innerHTML = price;
	
	// biggest image
	var imageHTML = document.getElementById("hugeimage" + productIndex).innerHTML; 
	var image = document.getElementById("prodzoomimage"); 
	if (imageHTML == "")
	{
		image.innerHTML = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>Sorry, there is no image available for this product.</p>";
	} else {
		var imageLink = "<img src='../gemopedia/js/" + imageHTML + "' alt='product image' width='300' height='300' class='left' />";
		image.innerHTML = imageLink;
	}

	// video
	var videoLink = document.getElementById('video' + productIndex).innerHTML;
	insertVideo(videoLink);

	// Buy link
 	var buyAction = "";
	var buyText = document.getElementById('buy' + productIndex).innerHTML;
	if (buyText.search(/href/) >= 0)
	{
		// There's an action, so display "buy now"
		var buyParts = buyText.split(/[<>]/);
		var anchor = buyParts[0];
		var anchorParts = anchor.split(/\"/);
		buyAction = anchorParts[1];
	}
	
	if (buyAction != "")
	{
		document.getElementById("prodzoombuy").innerHTML = 
			"<a href=\"" + buyAction + "\" class='prodzoombuynow'>" + 
			"<img src='/img/prodzoom/color4/btn-buy.gif' " +
			"alt='buy now' width='84' height='12' id='BuyImage' " +
			"onmouseover=\"MM_swapImage('BuyImage','','/img/prodzoom/color4/btn-buy_Over.gif',1)\" " +
			"onmouseout='MM_swapImgRestore()' />" +   
			"</a>";
	}

	if (productType == "game")
	{
		// Bid link
	 	var bidAction = "";
		var bidText = document.getElementById('bid' + productIndex).innerHTML;
		if (bidText.search(/href/) >= 0)
		{
			// There's an action, so display "Place Bid"
			var bidParts = bidText.split(/[<>]/);
			var anchor = bidParts[0];
			var anchorParts = anchor.split(/\"/);
			bidAction = anchorParts[1];
		}
		
		if (bidAction != "")
		{
			document.getElementById("prodzoombid").innerHTML = 
				"<br /><a href=\"" + bidAction + "\" class='prodzoombid'>" + 
				"<img src='/img/prodzoom/color4/btn-bid.gif' " +
				"alt='place forward bid' width='165' height='12' id='BidImage' " +
				"onmouseover=\"MM_swapImage('BidImage','','/img/prodzoom/color4/btn-bid_Over.gif',1)\" " +
				"onmouseout='MM_swapImgRestore()' />" +   
				"</a>";
		}

		// Forward bids
		var forwardBids = document.getElementById('forwardbid' + productIndex).innerHTML;
		document.getElementById("prodzoomfuturebid").innerHTML = 
			forwardBids;
		
		// Game start time
		var startTime = document.getElementById('start' + productIndex).innerHTML;
		document.getElementById("prodzoomgamestart").innerHTML = 
			"<p>Game starts at " + startTime + ".</p>";
	}
	
	// Details link
	var detailsLink = document.getElementById('details' + productIndex).innerHTML;
	document.getElementById("prodzoomdetails").innerHTML = 
		"<a href='../gemopedia/js/" + detailsLink + "' class='viewfull'>" +
		"<img src='/img/prodzoom/color4/btn-viewdetails.gif' " +
		"alt='view full details' width='152' height='12' id='ViewImage' " +
		"onmouseover=\"MM_swapImage('ViewImage','','/img/prodzoom/color4/btn-viewdetails_Over.gif',1)\" " +
		"onmouseout='MM_swapImgRestore()' /></a>";

	doMouseClick('prodzoomanchor'); 
}

function insertVideo(videoLink)
{
	var embedParam = "<embed src='" + videoLink + "' quality='high' " + 
						"pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' " + 
						"width='240' height='180'></embed>";
	
	var video = 
		"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " +
		"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' " + 
		"width='240' height='180'>" +
		"<param name='movie' value='" + videoLink + "'>" +
		"<param name='quality' value='high'>" +
		"<PARAM NAME='menu' VALUE='false'>" + embedParam + 
		"Flash Video</object>";

	document.getElementById("prodzoomvideo").innerHTML = video;
}

function DisplayDeliveryPricing(bandid)
{
	//open pop-up
	var url = "/deliverypricing.jsp?id=" + bandid;
	loginWindow = window.open(url,"DeliveryWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1,height=400,width=650,screenX=20,screenY=20,top=20,left=20");
    loginWindow.opener = self;
    loginWindow.focus();
} 

function forwardTo(forwardURL)
{
	if (document.images)
        window.location.replace(forwardURL);		//stops going into the history
    else
        window.location.href = forwardURL;
}        

