﻿


var BGupdateTimer = 1000;
var today = new Date();	
var SQLdateString =  (today.getMonth()+1) +"-"+ today.getDate() +"-"+ today.getFullYear();



function UpdateBetGraph_callback(response){

    var data = response.value;
    var content = document.getElementById("content"); 
    if (content == null)
    {
      content = parent.document.getElementById("content");
    }

        
    if (document.getElementById('Game_'+data.LeagueID+"_"+data.EventID) !=null ){
        data.Total = CustomBetgraphOdds(data.LeagueID,data.EventID,"total");
        data.Spread = CustomBetgraphOdds(data.LeagueID,data.EventID,"spread");
    }
 
    oDiv=document.createElement("DIV");
    oDiv.id = "Graph_"+data.LeagueID+"_"+data.EventID+"_Buffer";
	oDiv.style.position = "absolute";
	oDiv.style.zIndex = 5000;
	oDiv.style.left = '-3000px';
	oDiv.style.top = 0;  
	oDiv.style.width = 310;
	oDiv.style.height = 410;	
	oDiv.innerHTML = data.GraphHTML; 
	content.appendChild(oDiv);
    window.setTimeout("bufferGraph("+data.LeagueID+", "+data.EventID+", "+data.Total+", "+data.Spread+");",500);
   
   
}

function bufferGraph(LeagueID, EventID, Total, Spread){

    var content = document.getElementById("content"); 
if (content == null)
{
      content = parent.document.getElementById("content");
}

  var graph = document.getElementById("Graph_"+LeagueID+"_"+EventID);
  if (graph == null)
  {
    graph = parent.document.getElementById("Graph_"+LeagueID+"_"+EventID);
  }
  var buffer_graph = document.getElementById("Graph_"+LeagueID+"_"+EventID+"_Buffer");
  
  if (buffer_graph == null)
  {
    buffer_graph = parent.document.getElementById("Graph_"+LeagueID+"_"+EventID+"_Buffer");
  }
  
    if ( buffer_graph != null && graph != null){
       graph.innerHTML = buffer_graph.innerHTML;
       content.removeChild(buffer_graph);
    }
}

function BetGraphOn(LeagueID, GameDateTime, EventID,  Total, Spread,ScoreStatus, page_type,e) {//turnOnGraph(1, 22104, -3, 35.4);
    if (!e) e = window.event;

    var content = document.getElementById("content"); 
    if (content == null)
    {
      content = parent.document.getElementById("content");
    }

    if (page_type == "Custom"){
    
        Total = CustomBetgraphOdds(LeagueID,EventID,"total");
        Spread = CustomBetgraphOdds(LeagueID,EventID,"spread");
    }

	var graph = document.getElementById("Graph_"+LeagueID+"_"+EventID);

	if (graph == null){

	        var coord = getMouseCoord(e).split(",");
	
			oDiv=document.createElement("DIV");
			oDiv.id = "Graph_"+LeagueID+"_"+EventID;
			oDiv.style.position = "absolute";
			oDiv.style.zIndex = 5000;
			oDiv.style.left = ((parseInt(coord[0]) + 200) > 500 ? 50 : 400)  + 'px';
			oDiv.style.top = (parseInt(coord[1])) + 'px';
			oDiv.style.width = 310;
			oDiv.style.height = 410;	
			oDiv.innerHTML = "";

			if (page_type =="Team" || page_type =="Preview")
			{
			    window.setTimeout("parent.document.getElementById('content').appendChild(oDiv);", 100);
			}
			else{
			    window.setTimeout("document.getElementById('content').appendChild(oDiv);", 100);
			}
			window.setTimeout("BetGraph.UpdateBetGraph( "+LeagueID+","+EventID+", "+Total+", "+Spread+", '"+ScoreStatus+"', '"+GameDateTime+"', "+UpdateBetGraph_callback+")", BGupdateTimer );

		}
		return;
}

function turnOffGraph( LeagueID, EventID ) {
	var ss = document.getElementById("Graph_"+LeagueID+"_"+EventID);
	if ( ss != null ) {
		ss.parentNode.removeChild(ss); 
	}
}

function showHelp( e, LeagueID, EventID, type ) {
    if (!e) e = window.event;
    
    var content = document.getElementById("content");   
    if (content == null)
    {
        content = parent.document.getElementById("content");
    }

	var helpDiv = document.getElementById("HelpBalloon");
	if ( helpDiv == null){
    
		
	    var oDiv = document.createElement("DIV");
	    var divId;
	    oDiv.style.position = "absolute";
    		
	    var graphDiv = document.getElementById("Graph_"+LeagueID+"_"+EventID);
	    var buf_graphDiv = document.getElementById("Graph_"+LeagueID+"_"+EventID+"_Buffer");

        var coord = getMouseCoord(e).split(",");
    	 
	    oDiv.style.left =  coord[0].toString(10) + 'px';
        oDiv.style.top =  (coord[1]-50).toString(10) + 'px';
    	
    	
	    if ( LeagueID == 1  ||  LeagueID == 2  ) {
		    oDiv.innerHTML = "<img src='"+ImagesURL+"/scores/football/football_bubble.gif' />";
	    } else {
		    oDiv.innerHTML = "<img src='"+ImagesURL+"/scores/basketball/basketball_bubble.gif' />";
	    }
    		
	    oDiv.id = "HelpBalloon";
	    oDiv.style.zIndex = 6000;
	    balloonHelpFadeCounter = 50;
	    balloonHelpFadeDirection = 20;

	   if ( graphDiv != null){
	      content.appendChild(oDiv);	
	   }
	}	
}
	
	
	function hideHelp(  ) {
		var content = document.getElementById("content");   
        if (content == null)
        {
            content = parent.document.getElementById("content");
        }
        
		var helpDiv = document.getElementById("HelpBalloon");
		if ( helpDiv != null) {
			content.removeChild(helpDiv);
		}
	}


function fadeBalloon( divId, LeagueID, EventID ) {
	var graphDiv = document.getElementById("Graph_"+LeagueID+"_"+EventID);
		if ( balloonHelpFadeDirection != 0 ) {
			var oDiv = document.getElementById( divId );
			if ( oDiv != null ) {
			
				balloonHelpFadeCounter += balloonHelpFadeDirection;
				if ( balloonHelpFadeCounter >= 100 ) {
					balloonHelpFadeDirection = 0;
					oDiv.style.filter="alpha(opacity=100)";
				} else {
					window.setTimeout("fadeBalloon(\""+divId+"\");", 1 );
					oDiv.style.filter="alpha(opacity="+balloonHelpFadeCounter+")";
				}
				
			}
		}
	} 	
	
