﻿// JScript File



function delOldDiv() {
    var livemaindiv = document.getElementById('livemaindiv');
    if (livemaindiv != null) {
        var live = document.getElementById('live');
        live.removeChild(livemaindiv);
    }        
}

function ShowLive(Games) {

    
    if (Games != "") {
        var Markets = Games.split("~");
        var bet = [];
        var prevdate = '';	
	    var header = 0    	
	    var j = 0;
    	
	    bet["Display"] = []
	    bet["Price"] = []
	    bet["MarketID"] = []
	    

        var live = document.getElementById('live');
         var LiveDiv = document.getElementById('livemaindiv');
         if (LiveDiv != null) {
            live.removeChild(LiveDiv);
         };
         addLiveName('მიმდინარე თამაშები');

        size = Markets.length;
        
        for(var i=0; i<size; i++)
	    {
	       Bets = Markets[i].split("#");
    	    
           var Game = Bets[0].split("|");
           
           GameID = Game[0];
           GameDate = Game[1];
           GameName = Game[2];
           GameState = Game[3];
           
          
           var std  =	GameDate.split("-");
           

           var Odds = Bets[1].split("*");
           
           for(var k=0; k<Odds.length-1 ; k++)
           {
                var s = Odds[k].split("|")
                bet["MarketID"][k] = s[0];
                bet["Display"][k] = s[1];
                bet["Price"][k] = s[2];
                
                
            var lineRC  =  document.getElementById("slip").rows;
                var cnt = countRows() - 1;
                for(var brow = 1; brow <= cnt; brow++)
		        {
		            var SlipPrice = document.getElementById("p_"+brow).innerHTML;
		            var SlipGameID = lineRC[brow].getElementsByTagName("td")[2].id.substr(7);
		            var SlipMarketType = lineRC[brow].getElementsByTagName("td")[2].axis;
		            if (GameID == SlipGameID && s[1]==SlipMarketType && SlipPrice!=s[2]) {
                        lineRC[brow].getElementsByTagName("td")[0].id = "Slip_" + s[0];
		                document.getElementById("p_"+brow).innerHTML = s[2];
		                getLines();
		                alert("თამაშში " + GameName + " " + s[1] + " შეიცვალა კუში, რომელიც არის ბილეთში");
		            }
		        }
           }
            if(std[0] != prevdate)
		    {
		    if (header == 0) {
			    addliveheader(bet);
                CreateLiveOddTable();
			    header = 1;
			}
			    addDateLive(std[0]);
			    prevdate = std[0];
			    
		    }
    		        j = j + 1;	
            addliveline(GameID,std[1],GameName,bet,GameState, j);
        }        
    } else {
        delOldDiv();
    }
    
}


	function addliveheader(bet)
	{
	    var div = document.createElement("div");
	    div.className = "betblock_tabletitle1";
	    div.innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='3' height='3'><img src='images/bettable1_title_left.gif' width='3' height='3' /></td><td><img src='images/blank.gif' width='1' height='1' /></td><td width='3' height='3'><img src='images/bettable1_title_right.gif' width='3' height='3' /></td></tr></table>"
		
		
		var tbl = document.createElement('table');
	    var tblBody = document.createElement('tbody');
		   
	    tbl.className = "bettableup1"
        tbl.setAttribute("cellpadding", "0");
        tbl.setAttribute("cellspacing", "1");
        tbl.width="100%";     

          var rh = document.createElement("tr");

		  column = document.createElement("td");
		  column.className="bettableup1_3";
		  column.innerHTML = "";
		  rh.appendChild(column);
		  
		  column = document.createElement("td");
		  column.innerHTML = "";
		  rh.appendChild(column);        

		for(i = 0; i<bet["Display"].length; i++)
		{
		  column = document.createElement("td");
		  column.className="bettableup1_3";
		  column.innerHTML = bet["Display"][i];
		  rh.appendChild(column);
		  
		}
		
		var LeagueBodyDiv = "LiveBodyDiv";		
		var OddsTable = document.getElementById(LeagueBodyDiv); 

        tblBody.appendChild(rh);
        tbl.appendChild(tblBody);
        div.appendChild(tbl);
        OddsTable.appendChild(div);

}

  	function addDateLive(dt)

	{
		var tbl 	= document.getElementById("LiveOdds");
		var tblBody = document.getElementById("LiveBody");

          var row = document.createElement("tr");
		  var c1	 = document.createElement("td");
			c1.setAttribute("colspan","5")
			c1.colSpan = 5;
			c1.setAttribute("class","green_10")
			c1.setAttribute("className", "green_10");
		  	c1.innerHTML =  dt;
            row.appendChild(c1);

        tblBody.appendChild(row);
        tbl.appendChild(tblBody);
	}

 	function CreateLiveOddTable()
	{
		
		var tbl = document.createElement('table');
		tbl.setAttribute("id","LiveOdds");
		tbl.setAttribute("width","100%");
		tbl.setAttribute("class","bettableup1");
		tbl.setAttribute("className","bettableup1");
		
		
		tbl.setAttribute("border","0");
		tbl.setAttribute("cellpadding","0");
		tbl.setAttribute("cellspacing","1");
		
		
		
		var tblBody = document.createElement('tbody');
		tblBody.setAttribute("id","LiveBody");
		
		tbl.appendChild(tblBody);		
		
		var LeagueBodyDiv = "LiveBodyDiv"; 		
		var OddsTable = document.getElementById(LeagueBodyDiv);
		
		OddsTable.appendChild(tbl);
		
       
	}
	
function AddLiveDiv(leagueID)
	{
    	var LiveMainDiv = document.createElement("div");
       
       
		LiveMainDiv.setAttribute("id","livemaindiv");
        var OddsTable = document.getElementById('live');
		
		//OddsTable.insertBefore(SpaceDiv,OddsTable.firstChild);
		//OddsTable.insertBefore(LeagueMainDiv,OddsTable.firstChild);
		
		OddsTable.appendChild(LiveMainDiv);
		//OddsTable.appendChild(SpaceDiv);
		

	}	
	
function AddLiveNameDiv(leagueName)
	{
	        var LiveMainDiv = document.getElementById("livemaindiv");
	        LiveMainDiv.className = "betblock";
			
			var LiveNameDiv = document.createElement("div");
			LiveNameDiv.setAttribute("id","livenamediv");
			
			LiveNameDiv.setAttribute("class","lng")
			LiveNameDiv.setAttribute("className", "lng");
			
			LiveMainDiv.appendChild(LiveNameDiv);
			
			AddLiveNameTable(leagueName);
	}	
	
	function AddLiveNameTable(leagueName)
	{
	    
	    var LiveNameDiv = document.getElementById("livenamediv");
	    
	    var LiveNamatable = document.createElement("table");
	    LiveNamatable.setAttribute("width","100%");
		var LiveNameTableBody = document.createElement("tbody");
		
		
		var colTr = document.createElement("tr");
			
			var col1 = document.createElement("td");
/*			col1.setAttribute("colspan","3");			
			col1.setAttribute("width","1");
			col1.setAttribute("height","1");
			col1.calssName = "ccline";
			var img1 = document.createElement("img");
			img1.src = "images/blank.gif";
			img1.setAttribute("id","arrow_live");
			col1.appendChild(img1);*/
			col1.innerHTML = '<div class="title"><img width="360" height="25" src="images/online_title.gif"/></div><div class="ccline"><img width="1" height="1" src="images/blank.gif"/></div>';
			
			colTr.appendChild(col1);
						
		
			LiveNameTableBody.appendChild(colTr);
			LiveNamatable.appendChild(LiveNameTableBody);
		
		LiveNameDiv.appendChild(LiveNamatable);	
	}	

	function AddLiveBodyDiv() 
	{
	    var LiveMainDiv = document.getElementById("livemaindiv");
	    
	    var LiveBodyDiv = document.createElement("div");
			LiveBodyDiv.setAttribute("id","LiveBodyDiv");
			LiveBodyDiv.setAttribute("class","leagueBody");
			LiveBodyDiv.setAttribute("className","leagueBody");
			
			LiveMainDiv.appendChild(LiveBodyDiv);
	}
		
 function addLiveName(leagueName)
 {
        AddLiveDiv()
        AddLiveNameDiv(leagueName)
        AddLiveBodyDiv()
 }


function addliveline(gameID,GameDate,GameName,bet,GameState, j)

  {
		if (j%2)
	    {
	        cls = "bettable2";
	    }
	    else
	    {
	        cls = "bettable1";
	    }
		var tbl 	= document.getElementById('LiveOdds');
		var tblBody = document.getElementById('LiveBody');
		
		
        var rw  = document.createElement("tr");
		rw.setAttribute("id","game_"+gameID);
		
		// Time   		
		var tim	 = document.createElement("td");
		tim.setAttribute("class",cls +"_1")
		tim.setAttribute("className", cls +"_1");
	 	tim.innerHTML =  GameDate;
        rw.appendChild(tim);
		
		// teams 
		var tms = document.createElement("td");
		tms.setAttribute("class",cls +"_2")
		tms.setAttribute("className", cls +"_2");
		var teamDiv = document.createElement("div");
		teamDiv.setAttribute("id","t"+gameID);
		teamDiv.setAttribute("isGameInSlip","0");
		teamDiv.innerHTML = GameName;
		tms.appendChild(teamDiv);
        rw.appendChild(tms);
		
		
		for(var r=0;r<bet["Price"].length;r++)
		{
		
			
			column = document.createElement("td");
			column.setAttribute("class",cls +"_3");
			column.setAttribute("className", cls +"_3");
			column.setAttribute("abbr",j);
            column.setAttribute("id","vcol_"+bet["MarketID"][r]);
	
			div = document.createElement("div");
			
			div.setAttribute("class","prd");
			div.setAttribute("className","prd");
			
			div.setAttribute("id","v_"+bet["MarketID"][r]);
			div.setAttribute("isp",0);
			if (bet["Price"][r]!='1.00') {
			    if (GameState == 'S') {
			        div.onclick  = new Function("ts('"+ bet["MarketID"][r] +"','"+gameID+"','"+bet["Display"][r]+"','-1');");
			        div.onmouseover = new Function("th('" + bet["MarketID"][r] +"');");
			        div.onmouseout = new Function("th1('" + bet["MarketID"][r] +"');");
			        div.setAttribute("PriceType", 1);
			    }
			} else
			{
		        bet["Price"][r]='---'
			}
			div.innerHTML = bet["Price"][r];
			column.appendChild(div);
			rw.appendChild(column);
			

		}
		

        tblBody.appendChild(rw);
        tbl.appendChild(tblBody);
     	tbl.setAttribute("border", "0");
     	
     	//oddsdiv.appendChild(tbl);

}


	function showHideLive()
	{
		//toggle("LeagueBodyDiv"+leagueID);
		var obj = "LiveBodyDiv";
		var arrow = document.getElementById("arrow_live");
		
		   var el = document.getElementById(obj);
				
		        if ( el.style.display != 'none') {
					
		                el.style.display = 'none';
						arrow.src = "images/dot.gif";
		        }
		        else {
		                el.style.display = 'Block';
						arrow.src = "images/dot_1.gif";
		        }
	}
	
		/*function lth(odID)
	{
		var ob = document.getElementById("l_"+odID);
		var ob1 = document.getElementById("lcol_"+odID);
		var IsInSlip = ob.getAttribute("isp");
		if (IsInSlip != 1) {
		    ob1.className = "betover";
		}	}
	
		function lth1(odID)
	{
		
		var ob = document.getElementById("l_"+odID);
		var ob1 = document.getElementById("lcol_"+odID);
        j = ob1.getAttribute("abbr");
		if (j%2)
	    {
	        cls = "bettable2";
	    }
	    else
	    {
	        cls = "bettable1";
	    }
		var IsInSlip = ob.getAttribute("isp");
		if (IsInSlip != 1) {
		    ob1.className =  cls + "_3";
		}	}*/