
//Start for buying tvgame product by Toux

//End for buying tvgame product by Toux

//Start for get tvgame (ajax)
var intervalTVGameObject = setInterval("getTVGame()",4000);
var reqTVGame;
var pgName = "TV";
//var gameCount = 0;
function getTVGame(){	
	var url = "tvgame.htm?dummy="+Math.random();
	if (window.XMLHttpRequest){
		reqTVGame = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqTVGame = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//window.status = "Refreshing...<%=request.getServerName()%> ";
	reqTVGame.open("GET", url, true);
	reqTVGame.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	reqTVGame.onreadystatechange = callBackTVGame;
	reqTVGame.send(null);
}
function callBackTVGame(){

	try{
		if (reqTVGame.readyState == 4){
	
			if (reqTVGame.status == 200){
				//window.status = window.status + "callbackTVGame()...";
				var l = reqTVGame.responseText;	
				
												
				if(l != null && l.length > 0){
					var result = eval(l);					
					var index = -1;
					//if (navigator.appName == 'Netscape') index = -1;
					for (i=1;i<=result.length;i++) {
						var obj = result[i+index];
						if(obj != null){																																																																																															
							//window.status = window.status + " from[" + obj.from + "]";
							var gameStatusEL = document.getElementById("gameStatus"+i);						
							if((gameStatusEL != null) && (obj.gameStatus != gameStatusEL.innerHTML)){
								if(obj.gameStatus != null){
									gameStatusEL.innerHTML = obj.gameStatus;																	
								}else{								
									gameStatusEL.innerHTML = "";								
								}
							}	
							var gameStatusEL = document.getElementById("gameStatus2"+i);
													
							if((gameStatusEL != null) && (obj.gameStatus != gameStatusEL.innerHTML)){
								if(obj.gameStatus != null && obj.BottomText ==null){
									gameStatusEL.innerHTML = obj.gameStatus;																	
								}else{								
									gameStatusEL.innerHTML = "";								
								}
							}
							var productNameEL = document.getElementById("productName"+i);
							if((productNameEL !=null) && (productNameEL.innerHTML != '<a href="javascript:showLayer(\''+obj.productId+'\',\''+pgName+'\');" alt="Click Here For Full Details" style={cursor:hand}>'+obj.productName+'</a>')){
								if(obj.productNameEL != null){
									productNameEL.innerHTML = '<a href="javascript:showLayer(\''+obj.productId+'\',\''+pgName+'\');" alt="Click Here For Full Details" style={cursor:hand}></a>';
									document.tvgameform.productId.value = obj.productId;
									if(obj.gameStatus!=null && obj.gameStatus!=""){
									productNameEL.innerHTML = "";
									}	
								}else{	
									productNameEL.innerHTML ='<a href="javascript:showLayer(\''+obj.productId+'\',\''+pgName+'\');" alt="Click Here For Full Details" style={cursor:hand}>'+obj.productName+'</a>';
									document.tvgameform.productId.value = obj.productId;
								}																	
							}
							//Anupama(Product description link click should open the product layer)							
							//if((productNameEL != null) && (productNameEL.innerHTML != obj.productName)){
								//if(obj.productName != null){								
								//	productNameEL.innerHTML = obj.productName;
									//window.status = window.status + " product[" + obj.productName + "]";
									//if(obj.gameStatus!=null && obj.gameStatus!=""){
									//	productNameEL.innerHTML = "";
									//}								
								//}else{								
									//productNameEL.innerHTML = "";								
								//}
							//}							
							var amountEL = document.getElementById("amount"+i);						
							if((amountEL != null) && (amountEL.innerHTML != obj.amount)){
								if(obj.amount != null){
									amountEL.innerHTML = obj.amount;
									document.tvgameform.purchaseAmount.value = obj.amount;
									//window.status = window.status + " amount[" + obj.amount + "]";
								}else{
									amountEL.innerHTML = "";
								}
							}																				
							var productImgEL = document.getElementById("productImg"+i);
							
							 if((productImgEL != null) && (productImgEL.innerHTML != '<img border="0" src="http://www.gemstv.com/' + obj.productImg + '" height="170"   onClick="showLayer(\''+obj.productId+'\',\''+pgName+'\')" alt="Click Here For Full Details" style={cursor:hand}">')){
								if(obj.productImg != null && obj.fullDetailLink != null){
									//productImgEL.innerHTML = '<img border="0" src="http://www.gemstv.com/' + obj.productImg + '"   height="170"  onClick="showLayer(\''+obj.productId+'\',\''+pgName+'\')" alt="Click Here For Full Details" style={cursor:hand}">';
									productImgEL.innerHTML = '<img border="0" src="http://www.gemstv.com/' + obj.productImg + '"   height="170"   onmouseout="closeQuickLookLauncherTVH();"  onmouseover="openQuickLookLauncherTVH(\''+pgName+'\')" >\n<div style="visibility: hidden;" id="submitLookLauncherTVH" class="cssHide2">\n<img src="/images/home/button_quicklook_launcher_over.gif" id="quickLookLauncherImg"  onmouseover="launchQuickLookTVH();" onmouseout="removeQuickLookTVH();" onclick="javascript:showLayer(\''+obj.productId+'\',\'TV\');\"  style="cursor: pointer;">\n</div>';
								}else{
									productImgEL.innerHTML = "";
								}	
							}														
							var fullDetailLinkEL = document.getElementById("fullDetailLink"+i);
							if((fullDetailLinkEL !=null) && (fullDetailLinkEL.innerHTML != '<a href="javascript:showLayer(\''+obj.productId+'\',\''+pgName+'\');" alt="Click Here For Full Details" style={cursor:hand}><img src=\"../images/magglass.gif\" alt=\"view details\" border=\"0\"/></a>')){
								if(obj.fullDetailLink != null){
									fullDetailLinkEL.innerHTML = '<a href="javascript:showLayer(\''+obj.productId+'\',\''+pgName+'\');" alt="Click Here For Full Details" style={cursor:hand}><img src="../images/magglass.gif" alt="view details" border="0"/></a>';
								}else{
									fullDetailLinkEL.innerHTML = "<a href=\"javascript:showLayer('+obj.productId+');\" alt=\"Click Here For Full Details\" style=\"{cursor:hand}\"><img src=\"../images/magglass.gif\" alt=\"view details\" border=\"0\"/></a>";
								}																	
							}								
							var priceEL = document.getElementById("currentp"+i);
							if((priceEL != null) && (priceEL.innerHTML != obj.price + "")){										
								if(obj.price != null){																		
									priceEL.innerHTML = obj.price + "";
									document.tvgameform.purchasePrice.value = obj.price;
									//window.status = window.status + " price[" + obj.price + "]";
								}else{										
									priceEL.innerHTML = "";										
								}
							}																								
							var startPriceEL = document.getElementById("startp"+i);
							if((startPriceEL != null) && (startPriceEL.innerHTML != obj.startPrice + "")){
								if(obj.startPrice != null){								
									startPriceEL.innerHTML = obj.startPrice + "";
								}else{
									startPriceEL.innerHTML = "";
								}	
							}																			
							var buyProductLinkEL = document.getElementById("buyProductLink"+i);
							
							if(buyProductLinkEL !=null){							
								if(obj.productId!=null && obj.ouCode!=null && obj.price!=null && obj.channelId!=null && obj.gameId!=null){
								
									buyProductLinkEL.innerHTML = "<a onClick=javascript:buyNowTVGameProd('"+obj.productId+"','"+obj.ouCode+"','"+1+"','"+obj.price+"','"+obj.channelId+"','"+obj.gameId +"') style={cursor:hand}><img border=0 src=images/btn-buyl.gif id=\"Image12\" onmouseover=\"MM_swapImage('Image12','','images/games/btn-buylrg-over.gif',1)\" onmouseout=\"MM_swapImgRestore()\"></a>";
									document.tvgameform.channelId.value = obj.channelId;
									document.tvgameform.gameId.value = obj.gameId;
									if(obj.gameStatus!=null && obj.gameStatus!=""){
										buyProductLinkEL.innerHTML = "<img border=0 src=images/games_48.gif>";
									}																		
								}else{
										buyProductLinkEL.innerHTML = "<img border=0 src=images/btn-buyl.gif>";									
								}
							}							
																																																											
						}							
					}
				}
			}
		}
	}catch(e){
		//window.status = "callBackTVGame()..." + e.description;
	}														
}
//End for get game (ajax)


