﻿
function gId(str){ return document.getElementById(str); }

// Galeria
function Delete_Galeria(id)
{
    if(confirm("Va a eliminar la galería y todas sus fotos de forma permanente. Esta acción no se puede deshacer." +
               "\n\nPulse ACEPTAR para continuar o CANCELAR para abortar la operación:") == true)
    {
        document.forms[0].Param.value = id;
        __doPostBack('Delete','');
    }
    else
    {
	    return;
    }
}

function Delete_Foto(id)
{
    if(confirm("Va a eliminar la fotografía de forma permanente. Esta acción no se puede deshacer." +
               "\n\nPulse ACEPTAR para continuar o CANCELAR para abortar la operación:") == true)
    {
        document.forms[0].Param.value = id;
        __doPostBack('Delete','');
    }
    else
    {
	    return;
    }
}

function Update_Galeria(id)
{
    document.forms[0].Param.value = id;
     __doPostBack('Modificar','');
}

function Update_Foto(id)
{
    document.forms[0].Param.value = id;
     __doPostBack('Modificar','');
}

var Listen_New_Gal = false;
var Listen_New_Foto = false;
function Open_Listener()
{
    if(Listen_New_Gal)
    {
        Open_New_Gal('modificar');
    }
    if(Listen_New_Foto)
    {
        Open_New_Foto('modificar');
    }
    if(gId('Novedades'))
    {        
        gId('Novedades').onclick = function()
        {
            Enable_Nov();
        }
    }
}

function Open_New_Gal(mode)
{    
    Open_New_Win(); 
    if(mode == 'modificar')
    {
        gId('new_tit').innerHTML = 'Modificar galería';
    }
    else
    {
        gId('new_tit').innerHTML = 'Nueva galería';
    }
}

function Close_New_Gal()
{
    gId('TITULO').value = "";
    gId('DESCRIPCION').value = "";
    gId('fileIcono').value = "";
    gId("new_box").style.display = 'none';
    Hide_Velo();
}

function Open_New_Foto(mode)
{
    Open_New_Win(); 
    if(gId('Novedades').checked)
    {
        gId('fileNov').disabled = false;
    }
    else
    {
        gId('fileNov').disabled = true;
    }
    if(mode == 'modificar')
    {
        gId('new_tit').innerHTML = 'Editar fotografía';
    }
    else
    {
        gId('new_tit').innerHTML = 'Subir nueva fotografía';
    }
}

function Close_New_Foto()
{
    gId('TITULO').value = "";
    gId('DESCRIPCION').value = "";
    gId('filePhoto').value = "";
    gId('fileThumb').value = "";   
    gId('Novedades').checked = false;
    gId('fileNov').disabled = true;
    gId("new_box").style.display = 'none';
    Hide_Velo();
}

function Open_New_Win()
{
    var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();		
	var winTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 400) / 2);
	var winLeft = ((arrayPageSize[0] - 20 - 280) / 2); 	
	gId("new_box").style.top = (winTop < 0) ? "0px" : winTop + "px";
	gId("new_box").style.left = (winLeft < 0) ? "0px" : winLeft + "px";    
    gId("new_box").style.display = 'block'; 
    Set_Velo(arrayPageSize[1]);
}

function Enable_Nov()
{
    if(gId('Novedades').checked)
    {
        gId('fileNov').disabled = false;
    }
    else
    {  
        gId('fileNov').disabled = true;
    }
}

function Set_Velo(altura)
{   
    var velo = document.createElement('DIV');
        velo.id = 'velo';
        velo.style.width = '100%';
	    velo.style.height = altura + 'px';
    gId('ext').appendChild(velo);    
}

function Hide_Velo()
{
    if(gId("velo"))
    {
        gId('ext').removeChild(gId('velo'));
    } 
}

function getPageScroll()
{
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize()
{	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function Click_Right(e) 
{
    if (document.all) 
    {
        if (event.button == 2) 
        {
            alert(gId('pie_Copy').innerHTML);
            return false;
        }
    }
    else if (document.layers) 
    {
        if (e.which == 3) 
        {
            alert(gId('pie_Copy').innerHTML);
            return false;
        }
    }
}

//Logon
function Client_Logon()
{
    document.forms[0].Param.value = hex_sha1(gId('CLAVE').value);
    __doPostBack('Logon','');
}