function isMSIE()
{
	return (navigator.appName == "Microsoft Internet Explorer");
}

function isSafari()
{
	var agt=navigator.userAgent.toLowerCase();
	return ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;;
}

function addEventObject(o, evento, callbackFunction, bubble)
{
	if(isMSIE())
	{
		o.attachEvent(evento, callbackFunction);
	}
	else
	{
		if(evento.indexOf('on')==0)
		{
			evento = evento.substr(2);
		}
		o.addEventListener(evento, callbackFunction, bubble);
	}
}

function consultarGalleta(nombre){
	var buscamos = nombre + "=";
	if (document.cookie.length > 0) {
	  i = document.cookie.indexOf(buscamos);
	  if (i != -1) {
	    i += buscamos.length;
      j = document.cookie.indexOf(";", i);
			if (j == -1) j = document.cookie.length;
      return unescape(document.cookie.substring(i,j));
    }
  }
}


function Marcadores()
{
	this.getObject = function(id)
	{
		var o = null;
		if(isMSIE() || isSafari())
		{
			o = document.getElementById(id);
		}
		else
		{
			var ieo = document.getElementById(id);
			if(ieo)
			{
				var embo = ieo.getElementsByTagName('embed');
				if(embo.length) o=embo[0];
			}
		}
		return o;
	}

	this.callFunction = function(idMarcador, functionName, arrParams)
	{
		var strArguments = functionName;
		if(typeof(arrParams)!='undefined')
		{
			for(var i=0; i< arrParams.length; ++i)
			{
				strArguments += '<param>' + arrParams[i];
			}
		}
		var marcador = this.getObject(idMarcador);
		if(marcador){
		  if(idMarcador == "rugby2"){
		    //alert(strArguments);
		  }
		  //alert(strArguments);
		  marcador.SetVariable('objSocket.call', strArguments);
		}
	}

	this.setData = function(idMarcador, data)	{
		this.callFunction(idMarcador, 'setData', new Array(data));
		Marcadores_AutoProcess();
	}
	
	Array.prototype.in_array=function(){ 
    for(var j in this){ 
        if(this[j]==arguments[0]){ 
            return true; 
        } 
    } 
    return false;     
	}

	
	this.enable = function(idMarcador, idPartido) {
		this.callFunction(idMarcador, 'enableGame', new Array(idPartido,""));
	}

	this.setServerTime = function(idMarcador, hora) {
		this.callFunction(idMarcador, 'setServerTime', new Array(hora));
	}

	this.refresh = function(idMarcador) {
		galleta = consultarGalleta('objMarcador');
		remote_marcadorSetData(idMarcador);
	}

	this.init = function(){
		if(m_pos==0){
			Marcadores_AutoProcess();
		}
	}

	this.initServerTime = function(idMarcador){
		remote_marcadorSetServerTime(idMarcador);
	}

	this.getObject = function(id)
	{
		var o = null;
		if(isMSIE() || isSafari())
		{
			o = document.getElementById(id);
		}
		else
		{
			var ieo = document.getElementById(id);
			if(ieo)
			{
				var embo = ieo.getElementsByTagName('embed');
				if(embo.length) o=embo[0];
			}
		}
		return o;
	}

	this.autoProcess = function()
	{
		if(m_pos < m_arrMarcadores.length)
		{
			var id = m_arrMarcadores[m_pos];
			m_pos++;
			if(this.getObject(id)!=null)
			{
				this.initServerTime(id);
				this.refresh(id);
				setTimeout('Marcadores_AutoProcess("'+id+'");', 2500);
			}
			else { Marcadores_AutoProcess(); }
		}
	}
	
	this.initMarcador = function(idMarcador){
		this.callFunction(idMarcador, 'init', "");
	}
	
	this.showAll = function()
	{
		var o = null;
		for(var i=0; i<m_arrMarcadores.length; i++)
		{
			o = document.getElementById(m_arrMarcadores[i]);
			if(o!=null && o.style.display!='block') {
			  o.style.display = 'block';
			  if(m_arrMarcadores[i] == "futbol2"){
			    setTimeout("initFutbol2()",1000);
			  }else if(m_arrMarcadores[i] == "rugby2"){
			    setTimeout("initRugby2()",1000);
			  }
			}
		}
	}

	var m_pos = 0;
	var m_arrMarcadores = new Array('rugby','rugby2','futbol','futbol2','tenis','basquet','voley','hockey');
}

var marcadores = new Marcadores();
function Marcadores_AutoProcess(id)
{
	setTimeout('marcadores.autoProcess();', 750);
	
	if(typeof(id)!='undefined'){
		try			{	eval("Init"+id+"();");}
		catch(e){	}
	}
}

function call_remote_7minutosSetData(){
  selectedTitular = ( parseInt(selectedTitular)+1 < arrayTitulares.length ) ? parseInt(selectedTitular)+1 : 0 ;
  remote_7minutosSetData(arrayTitulares[selectedTitular]);
}

function Marcadores_OnLoad()
{
  /*
  if( document.getElementById("obj_7minutos") ){
	  setInterval('call_remote_7minutosSetData()',10000);
	}
	*/
	setTimeout('Marcadores_OnLoad2()', 5000);
}

function Marcadores_OnLoad2(){
  marcadores.showAll();
}

function initFutbol2(){
  marcadores.initServerTime('futbol2');
  marcadores.refresh('futbol2');
}

function initRugby2(){
  marcadores.initServerTime('rugby2');
  marcadores.refresh('rugby2');
}

addEventObject(window, 'onload', Marcadores_OnLoad, true);
setTimeout('Marcadores_OnLoad()', 120000);