// JavaScript Document

function $(id) { return document.getElementById(id) }
function $$$(id) { return document.getElementsByTagName(id) }

/* ************************* */
/*      Eventos del CMS      */
/* ************************* */

addListener(window,"load",initCMS);
addListener(window,"load",fs_contenido);
addListener(window,"load",fs_fixSubmit);


function initCMS()
{   
    //addListener(window,"load",fs_contenido);
    //addListener(window,"load",fs_fixSubmit);
    MostrarPanel('pan1','tab1');
}


/* ************************* */
/*        Funcion Login      */
/* ************************* */

function centrarLogin()
{
	var myWidth = 0, myHeight = 0;
  	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	 } 
	 else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	 {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	 } 
	 else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	 {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	 }
	 $('login').style.display = "block";
	 $('login').style.left = ((myWidth-322)/2) + "px";
	 $('login').style.top = ((myHeight-103)/2) + "px";
}

/* ************************* */
/*          Paneles          */
/* ************************* */

//Oculta todos los paneles
function OcultarPaneles()
{
    try
    {
		for(i=1;i<=8;i++)
		{
			if($('tab'+i).className== "solapa_activa") $('tab'+i).className= "solapa";
			if($('tab'+i).className== "solapa_chica_activa") $('tab'+i).className= "solapa_chica";
			$('pan'+i).style.display = "none";
		}
    }
    catch(e)
    {	    
    }    
}

//Muestra un determinado panel previamente ocultando todos los paneles
function MostrarPanel(obj)
{   
    //alert(typeof(obj));
    // 
    var id;
    var boton;
    if(typeof(obj)=="string")
    {
        panel = "pan1";
        boton = "tab1";
     }
     else
     {
        //obj = el objeto
        //id = nombre del panel
        //boton = nombre del button tab
       boton = obj.id.toString();
       panel = "pan" + boton.replace("tab","");
     }
     
   try
   {
       OcultarPaneles();
       //document.getElementById(boton).style.backgroundColor ='#ffcc99';
		$(panel).style.display = 'block';
		if($(boton).className == "solapa") 
	   		$(boton).className = "solapa_activa";
		else
			$(boton).className = "solapa_chica_activa";
   }
   catch(e)
   {	    
   } 

}

/* ************************* */
/*      Eventos del menu     */
/* ************************* */

function showMenu(obj, cond)
{
	if (!posicionSubmenu) posicionSubmenus();
	var itemMenu=obj.id.replace("menu","").replace("sub","");
	$("submenu" + itemMenu).style.display = (cond) ? "block" : "none";
	$("menu"+itemMenu).className = (cond) ? "item_menu_activo" : "item_menu";
}

var posicionSubmenu = false;
function posicionSubmenus()
{
	posicionSubmenu = true;
	try
    {
		for(i=1;i<=20;i++)
		{
			$("submenu"+i).style.left = $("menu"+i).offsetLeft + "px";
		}
    }
    catch(e)
    {	    
    }
}

/* ************************* */
/*      Script del submit    */
/* ************************* */

var fs_imagenLoading = new Image();
fs_imagenLoading = 'http://www.nuevabalear.com/images/cms/loading8.gif';



var forms=document.getElementsByTagName('form');
var iSubmit=0;


var nodoDiv = document.createElement("div");
var nodoImagen = document.createElement("img");

function fs_contenido()
{
	
	var oBody = $$$("body").item(0);
	nodoDiv.appendChild(document.createTextNode(" "));
	//nodoDiv.setAttribute("style", "position: absolute; width: 140px; height: 100px; background-color: rgb(51, 51, 51); top: 0px; left: 0px; display: none;");
	nodoDiv.style.position = "absolute";
	nodoDiv.style.width = "140px";
	nodoDiv.style.height = "100px";
	nodoDiv.style.backgroundColor = "#333";
	nodoDiv.style.top = document.documentElement.scrollTop + "px";
	nodoDiv.style.left = "0px";
	nodoDiv.style.display = "none";
	nodoDiv.setAttribute("id","fs_img_fondo_oscuro");
	
	nodoImagen.setAttribute("width","140");
	nodoImagen.setAttribute("height","100");
	//nodoImagen.setAttribute("style", "position: absolute; z-index: 10000; top: 0px; left: 0px; display: none;");
	nodoImagen.style.position = "absolute";
	nodoImagen.style.zIndex = "1000";
	nodoImagen.style.top = document.documentElement.scrollTop + "px";
	nodoImagen.style.left = "0px";
	nodoImagen.style.display = "none";
	nodoImagen.setAttribute("src", fs_imagenLoading);
	nodoImagen.setAttribute("id", "fs_img_loading");
	
	oBody.appendChild(nodoDiv);
	oBody.appendChild(nodoImagen);
}

function fs_fixSubmit()
{
	var oLinks = $$$('a');
	for(i=0;i<oLinks.length;i++)
	{
		
		if(oLinks[i].className == "boton_grande_verde" || oLinks[i].className == "boton_chico_verde")
		{
			oLinks[i].onclick = fs_newsubmit;
		}	
		
		if(oLinks[i].className == "boton_grande_rojo")
		{
			oLinks[i].onclick = fs_cancelarSubmit;
		}
		
	}
}

function fs_newsubmit()
{
	
	try
	{
	    if (formularioValido())
	       { 
			fs_posicionarImg();
	        return true;
	        }
	    else
	    {
	        return false;
	    }
	}
	catch (e)
	{
	    fs_posicionarImg();
	    return true;  
	}
}

function fs_cancelarSubmit()
{
	fs_posicionarImg();
	return true;
}

function formularioValido()
{
	var oSpan = $$$('span');
	condicion = true;
	for(i=0;i<oSpan.length;i++)
	{
		if(oSpan[i].className == "errorMsg" && oSpan[i].style.display == "inline")
		{
			condicion = false;
		}	
	}
	return condicion;	
}

function fs_posicionarImg()
{
	var capaImg = "fs_img_loading";
	var myWidth = 0, myHeight = 0;
	
  	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	 } 
	 else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	 {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	 } 
	 else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	 {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	 }
	$('fs_img_fondo_oscuro').style.display="block";
	$('fs_img_fondo_oscuro').style.width = myWidth+ "px";
	$('fs_img_fondo_oscuro').style.height = myHeight + "px";
	$('fs_img_fondo_oscuro').style.opacity = "0.5";
	$('fs_img_fondo_oscuro').style.filter = "alpha(opacity=50)";
	nodoDiv.style.top = document.documentElement.scrollTop + "px";
	
	$(capaImg).style.display = "block";
	$(capaImg).style.left = ((myWidth-140)/2) + "px";
	$(capaImg).style.top = ((myHeight-100)/2 + document.documentElement.scrollTop) + "px";
	
}

/* ************************* */
/*      Funcion Listener     */
/* ************************* */

function addListener(obj,evt,func) 
{
    if (obj.attachEvent)
        obj.attachEvent('on' + evt, func);

    else 
    {
        if (obj.addEventListener) 
        {
            obj.addEventListener(evt,func,false);
        }
        else 
        {
            if (obj.eval) 
            {
                obj["on"+evt] = func;
            } 
            else 
            {
                alert("Error adding listener\nObject:"+obj+"ID:"+obj.id+" Name:"+obj.name+" TagName:"+obj.tagName+"\nEvent:"+evt);
            }
        }
    }
}


/* Fin del script de submit */


/* ************************* */
/*  Funcion Activar Partner  */
/* ************************* */

function activarPartner(fichero, partner, accion)
{
    if (fichero=="")
        return false;
    else
    {
        ajaxManager('exec_page','partner-ajax.aspx?partner='+partner+'&fichero='+fichero+'&accion='+accion+'&');
        return true;
    }
    
}

/* ********************************* */
/*  Funcion Borrar Foto Development  */
/* ********************************* */

function BorrarFoto(obj,id,foto,imgCont)
    {
        ajaxManager('exec_page','developments-img-borrar.aspx?id='+id+'&foto='+foto+'&');
        $(imgCont).src = "";   
        obj.style.display = "none";     
    }

function BorrarFichero(obj,id,fichero,lnk)
    {
        ajaxManager('exec_page','agent-files-borrar.aspx?id='+id+'&fichero='+fichero+'&');
        $(lnk).style.display = "none";
        obj.style.display = "none";               
    }

function BorrarFicheroPartner(obj,id,fichero,lnk)
    {
        ajaxManager('exec_page','partner-files-borrar.aspx?id='+id+'&fichero='+fichero+'&');
        $(lnk).style.display = "none";
        obj.style.display = "none";               
    }
