//----------------------------------------------------------------------------------------------
// VARIABLES GLOBALES
//----------------------------------------------------------------------------------------------
var timerID = null;
var timerID_2 = null;
var rollID = null;
var timerOn = false;
var timecount = 600;
var GNSubMenus = 7;			//10-03-2009 Antes 8, eliminado domótica
var TopMenu = 182;
var GSubMenus = new Array(GNSubMenus); // Contiene las coordenadas x de los subMenus; 
var bMenuCalculados = false;

//----------------------------------------------------------------------------------------------
// FUNCIONES GLOBALES
//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------
function AvisarPaginaNoDisponible()
//----------------------------------------------------------------------------------------------
{
		alert("Esta secci&oacute;n no está disponible en este momento. Perdone las molestias.");
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=260,height=160,scrollbars=no,titlebar=no,left=300,top=300');
return false;
}


//----------------------------------------------------------------------------------------------
function PedirLogin()
//----------------------------------------------------------------------------------------------
{
	popup("../Recursos/VentanaLogin.swf", "Ventana de Login");
}
	
//----------------------------------------------------------------------------------------------
function PonTimer() 
//----------------------------------------------------------------------------------------------
{
	if (timerOn == false) 
	{
		timerID = setTimeout( "OcultarSubMenus()" , timecount);
		timerOn = true;
    }
}
//----------------------------------------------------------------------------------------------
function QuitaTimer() 
//----------------------------------------------------------------------------------------------
{
	if(top.document.readyState=="complete")
	{
        if (timerOn) 
		{
			clearTimeout(timerID);
        	timerID = null;
			rollID = null;
            timerOn = false;
	    }
	}
}	



//----------------------------------------------------------------------------------------------
function AbreFichaProducto(theURL) 
//----------------------------------------------------------------------------------------------
{ 

	var x = 0;
	var y = 0;
	var	winWidth = 640+20;
	var winHeight = 480;
	x = (screen.availWidth - 12 - winWidth) / 2;
	y = (screen.availHeight - 48 - winHeight) / 2;
	if (x<0) x = 0;
	if (y<0) y=0;
	var features = "screenX=" + x + ",screenY=" + y + ",width=" + winWidth + ",height=" + winHeight + ",top=" + y + ",left=" + x + ",scrollbars=yes" 
	+ ",Menubar=no"+ ",Titlebar=no";
	//var NewWindow = open(theURL,winName,"screenX=" + x + ",screenY=" + y);//,features);
	var NewWindow = open(theURL, "FichaDeProducto", features);//"width=475,height=670,status=no,toolbar=no,scrollbars=yes,menubar=no,screenX=0,screenY=0,"); 
	NewWindow.focus();
} 

//----------------------------------------------------------------------------------------------
function OpenWindow(theURL,winName,winWidth,winHeight,otherFeatures) 
//----------------------------------------------------------------------------------------------
{ 
	var x = 0;
	var y = 0;
	x = (screen.availWidth - 12 - winWidth) / 2;
	y = (screen.availHeight - 48 - winHeight) / 2;
	if (otherFeatures != "") {otherFeatures = "," + otherFeatures}

	var features = "screenX=" + x + ",screenY=" + y + ",width=" + winWidth + ",height=" + winHeight+",top="+y+",left="+x+"'" + ",scrollbars=yes" + otherFeatures
	
	//var NewWindow = open(theURL,winName,"screenX=" + x + ",screenY=" + y);//,features);
	var NewWindow = open(theURL, winName, features);//"width=475,height=670,status=no,toolbar=no,scrollbars=yes,menubar=no,screenX=0,screenY=0,"); 
	//lert("1");
	NewWindow.focus();
	//alert("2");
}

//----------------------------------------------------------------------------------------------
function Iniciar()
//----------------------------------------------------------------------------------------------
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		/*
		FILTER: 
		progid:DXImageTransform.Microsoft.Gradient
		(StartColorStr=#EEEEEE, EndColorStr=#555555, Startcolor=#00FF00,Endcolor=#FFFF00,GradientType=0)
		*/
		document.body.style.filter = "progid:DXImageTransform.Microsoft.Gradient(StartColorStr=#EEEEEE, EndColorStr=#555555, Startcolor=#00FF00,Endcolor=#FFFF00,GradientType=0)";
		document.body.style.backgroundColor = "#555555";
		
	}
	else
	{
		document.body.style.backgroundColor = "#888888";
	}
	/*
	if(location.href.search("SABIA/Inicio")>0 || location.href.search("Inicio.html")>0)
	{
		var features = "screenX=" + 200 + ",screenY=" + 200 + ",width=" + 230 + ",height=" + 150+",top="+200+",left="+200+"'" + ",scrollbars=false, menubar=false, toolbar=false";
		var NewWindow = open("../Noticias/Nominacion_Principe_Felipe.html", "Principe_Felipe", features);//"width=475,height=670,status=no,toolbar=no,scrollbars=yes,menubar=no,screenX=0,screenY=0,"); 
		NewWindow.focus();
	}
	*/

	CalcularSubMenus();
	
}
//----------------------------------------------------------------------------------------------
function CalcularSubMenus()
//----------------------------------------------------------------------------------------------
{
	offset_x = document.body.clientWidth - document.getElementById('ID_TABLA_PRINCIPAL').width;
	offset_x /= 2;
	if (offset_x <= 0)
	{
		offset_x = 0;
	}
	else
	{
		//offset_x -= 2;
	}
	//alert(offset_x);
	GSubMenus[0] = offset_x+5;
	//alert("_0_" + GSubMenus[0]);
	//GSubMenus[1] = parseInt(GSubMenus[0]) + parseInt(document.getElementById("TDMenu"+0+"").width);
	//alert("_1_" + GSubMenus[1]);
	//alert("GSubMenus = " + GNSubMenus);
	for (i=1; i<GNSubMenus; i++)
	{
		i_1 = i-1;
		GSubMenus[i] = 4 + parseInt(GSubMenus[i-1]) + parseInt(document.getElementById("TDMenu"+i_1+"").width);
		//alert("!" + i + "!" + GSubMenus[i]);
	}
	//GSubMenus[1] = parseInt(GSubMenus[1]) +3;
	
	// Obtenemos la altura que será igual para todos
	//offset_y = TopMenu;
	offset_y = 10-2
	+ parseInt(document.getElementById("ID_CELDA_FLASH").style.height)
	+ parseInt(document.getElementById("ID_CELDA_MENU").style.height);
	GSubMenus[0] -= 5;
	for (i=0; i<GNSubMenus; i++)
	{
		document.getElementById("SubMenu"+i+"").style.left= GSubMenus[i] +"px";
		document.getElementById("SubMenu"+i+"").style.top = offset_y + "px"; //189
	}
	
	
	
	if (GSubMenus[4] < GSubMenus[5])
		bMenuCalculados = true;
}
//----------------------------------------------------------------------------------------------
function OcultarSubMenus()
//----------------------------------------------------------------------------------------------
{
	fondoMenuNormal = "url(../Recursos/Fondo_Degradado_Ambar.gif)";
	flechaNormal = "../Recursos/Flecha_Menu_Derecha.gif";
	
	for (i=0; i<GNSubMenus; i++)
	{
		if (i >= 0)
		{
			objeto = document.getElementById("SubMenu"+i+"");
			objeto.style.visibility = "hidden";
			
			
			//objeto = document.getElementById("FLECHAMENU"+i+"");
			//objeto.src = flechaNormal;
		}
		objeto = document.getElementById("TDMenu"+i+"");
		objeto.style.backgroundImage = fondoMenuNormal;
	}
	
}

//----------------------------------------------------------------------------------------------
function Menu_OnMouseOut(indice)
//----------------------------------------------------------------------------------------------
{
	PonTimer();
}

//----------------------------------------------------------------------------------------------
function Sleep(gap)
//----------------------------------------------------------------------------------------------
{ 
	/* gap is in millisecs */
	var then,now; then=new Date().getTime();
	now=then;
	while((now-then)<gap)
	{
		now=new Date().getTime();
	}
}

//----------------------------------------------------------------------------------------------
function Menu_OnMouseOver(indice)
//----------------------------------------------------------------------------------------------
{
	if (!bMenuCalculados)	CalcularSubMenus();
	
	if (!bMenuCalculados) return;
	
	fondoMenuActivo = "url(../Recursos/Fondo_Degradado_Ambar_Oscuro.gif)";
	flechaAbajo = "../Recursos/Flecha_Menu_Abajo.gif";
	
	QuitaTimer();
	OcultarSubMenus();

	if (indice >= 0)
	{
		objeto = document.getElementById("SubMenu"+indice+"");
		objeto.style.visibility = "visible";
		//objeto = document.getElementById("FLECHAMENU"+indice+"");
		//objeto.src = flechaAbajo;
	}
	
	objeto = document.getElementById("TDMenu"+indice+"");
  objeto.style.backgroundImage = fondoMenuActivo;
	  objeto.style.backgroundRepeat = "repeat-x";

}
//----------------------------------------------------------------------------------------------
function SubMenu_OnMouseOver(objeto)
//----------------------------------------------------------------------------------------------
{
	fondo = "url(../Recursos/Fondo_Degradado_Menu.gif)";
	objeto.style.backgroundImage = fondo;
}

//----------------------------------------------------------------------------------------------
function SubMenu_OnMouseOut(objeto)
//----------------------------------------------------------------------------------------------
{
	fondo = "";
	objeto.style.backgroundImage = fondo;
}



