﻿
function ShowModalDialog(title, url){
    return ActivarModalPopUp(title, url, 830, 480);
}

function ShowModalDialogConfirmarEmplazamiento(title, url){
    return ActivarModalPopUp(title, url, 316, 390); //ancho x alto
}

function ShowModalDialogWidthDimensions(title, url, p_ancho, p_alto){
    return ActivarModalPopUp(title, url, p_ancho, p_alto);
}

function ShowModalDialogWithNewWidthAndReturnToOriginalWidthOnClosePlease(title,url,width, idBoto){
    document.getElementById("BtConfirmar").style.display = "none";
    document.getElementById("BtVolverAtras").style.display = "none";
    document.getElementById("BtEnviar").style.display = "none";
    
    if(idBoto != null)document.getElementById(idBoto).style.display = "inline";
    document.getElementById("modalPopUpContainerBody").style.width= width + "px";            
    var r = ShowModalDialogWidthDimensions(title, url, width, 480);
   
    document.getElementById("btTancar").onclick = function(){
        if(idBoto != null)document.getElementById(idBoto).style.display = "none";
        DesactivarModalPopUp();
    }
    return r;
}

function ShowModalDialogWithNewWidthAndHeight(title,url,width,height,idBoto){
    document.getElementById("BtConfirmar").style.display = "none";
    document.getElementById("BtVolverAtras").style.display = "none";
    document.getElementById("BtEnviar").style.display = "none";
        
    if(idBoto != null)document.getElementById(idBoto).style.display = "inline";
    document.getElementById("modalPopUpContainerBody").style.width= width + "px";
    document.getElementById("modalPopUpContainerBody").style.height = height + "px";            
    var r = ShowModalDialogWidthDimensions(title, url, width, height);
    document.getElementById("btTancar").onclick = function(){
        if(idBoto != null)document.getElementById(idBoto).style.display = "none";
        DesactivarModalPopUp();
    }
    return r;
}

function DesactivarModalPopUp(){     
    AmagarSelects();
    //los pongo a cero por que una vez que se muestra la ventana aparece scroll en el navegador
    document.getElementById("modalPopUpContainerBody").style.width = "0px";
    document.getElementById("modalPopUpContainerBody").style.height = "0px";
    var ventana = window;
    ventana.document.getElementById("modalPopUpContainer").className = "modalPopUpCapaOFF";
    ventana.document.getElementById("modalPopUpContainerBody").className = "modalPopUpCapaInteriorOFF";
    document.getElementById("modalPopUpFrame").src = "about:blank";  
    if(document.getElementById("BtConfirmar"))document.getElementById("BtConfirmar").value = "Confirmar"; 
    if(document.getElementById("BtConfirmar"))document.getElementById("BtConfirmar").disabled = false;   
    
    // botones para solucion de usuario
    if(document.getElementById("ButtonNuevaSolConUsuarioParent"))
        document.getElementById("ButtonNuevaSolConUsuarioParent").style.display = "none";
        
    if(document.getElementById("ButtonDuplicarSolConUsuarioParent"))
        document.getElementById("ButtonDuplicarSolConUsuarioParent").style.display = "none";

    if(document.getElementById("ButtonAceptarSolConUsuarioParent"))
        document.getElementById("ButtonAceptarSolConUsuarioParent").style.display = "none";
    
    if(document.getElementById("ButtonGuardarSolConUsuarioParent"))
        document.getElementById("ButtonGuardarSolConUsuarioParent").style.display = "none";

    if(document.getElementById("ButtonVolverUsuarioParent"))
        document.getElementById("ButtonVolverUsuarioParent").style.display = "none";
        
    var botonAtras = document.getElementById("BtVolverAtras");
    if(botonAtras != null){
        botonAtras.style.display = "none";
    }  
    var botonEnviar = document.getElementById("BtEnviar");
    if(botonEnviar != null){
        botonEnviar.style.display = "none";
    }  
    
    return false;
}

function DesactivarModalPopUpAdndRefreshPage(){
    DesactivarModalPopUp(); 
    window.location.href = window.location.href;
}


function ActivarModalPopUp(title, url, p_ancho, p_alto){
   
    var ventana = window;
	try{
	    AmagarSelects();
	    document.getElementById("modalPopUpFrame").src = "about:blank";
	}catch(fallo){
	}		   

	//se activa la manta que cubre toda la página actual
    var capa = null;
    capa = ventana.document.getElementById("modalPopUpContainer");
    if(capa == null){
        alert("No se ha encontrado el div modalPopUpContainer");
        return;
    }
    
    capa.style.height = document.documentElement.clientHeight;
    capa.className = "modalPopUpCapaON";
   
    //se activa una ventana sobre la manta
    var capa2 = null;
    capa2 = ventana.document.getElementById("modalPopUpContainerBody");
    var tablaContenidos = ventana.document.getElementById("modalPopUpContainerBodyTable"); 
    if(capa2 == null){
        alert("No se ha encontrado el div modalPopUpContainerBody");
        return;
    }
    capa2.className = "modalPopUpCapaInteriorON";

    var anchoventana = (document.all) ? document.documentElement.offsetWidth : innerWidth;
    var altoventana = (document.all) ? document.documentElement.offsetHeight : innerHeight;
	
    var anchopopup = capa2.style.width;
    var altopopup= capa2.style.height;
    
    if(anchopopup == undefined || anchopopup == ""){
        anchopopup = 760;
    };    
    if(p_ancho != undefined && p_ancho != null){
        anchopopup = p_ancho;
        capa2.style.width = anchopopup + "px";
        tablaContenidos.style.width = anchopopup + "px";
    }else{
        tablaContenidos.style.width = anchopopup;
    }        
    
    if(altopopup == undefined || altopopup == ""){
        altopopup = 480;
    };
    if(p_alto != undefined && p_alto != null){
        altopopup = p_alto;
        capa2.style.height = altopopup + "px";
        tablaContenidos.style.height = altopopup + "px";
    }else{
        tablaContenidos.style.height = altopopup;
    }
    
        
    capa.style.display = 'block';
    capa2.style.display = 'block';
    document.getElementById("modalPopUpTitle").style.width = (p_ancho-2) + "px";
    tablaContenidos.style.width = p_ancho + "px";
    tablaContenidos.style.display = 'block';
    
    var esquinaizquierda = (anchoventana / 2) - (parseInt(anchopopup) / 2);
    var esquinasuperior = (altoventana / 2) - (parseInt(altopopup) / 2)
    capa2.style.marginLeft = "-" + (anchopopup/2) + "px";
    capa2.style.marginTop = "-" + ((altopopup/2)) + "px";

    document.getElementById("modalPopUpTitle").innerHTML =  "&nbsp;" + title ;
    document.getElementById("modalPopUpFrame").style.height = altopopup - 50 + "px";
    document.getElementById("modalPopUpFrame").src = url;
    return document.getElementById("modalPopUpFrame");
}

function AmagarSelects(){
    if(document.frames){
        var f = document.frames;
        for(y=0;y<f.length;y++){
            var s = f[y].document.getElementsByTagName("select");
            for(x=0;x<s.length;x++){
                var v = s[x].style.visibility;
                s[x].style.visibility = (v=="hidden")?"visible":"hidden";
            }

            var s1 = f[y].document.getElementsByTagName("embed");
            for(x1=0;x1<s1.length;x1++){
                var v1 = s1[x1].style.visibility;
                s1[x1].style.visibility = (v1=="hidden")?"visible":"hidden";
            }
        }
    } 
} 

function enviaFormularioSugerencia() {
    var form = document.getElementById("modalPopUpFrame").contentWindow.document.forms[0];
    if (form.actividad.value != '0' && form.comentario.value != '' && form.mail.value != '') {
        form.submit();
        //parent.DesactivarModalPopUp();
    }
}

// acciones para botones para solucion de usuario
function NuevaSolConUsuario_OnClick(q){
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;    
    var boton = d.getElementById("ButtonNuevaSolConUsuario");
    if(boton != undefined){
        boton.click();       
    }
} 

function DuplicarSolConUsuario_OnClick(q){
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;    
    var boton = d.getElementById("ButtonDuplicarSolConUsuario");
    if(boton != undefined){
        boton.click();       
    }
} 

function AceptarSolConUsuario_OnClick(q){    
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;    
    var boton = d.getElementById("ButtonAceptarSolConUsuario");
    if(boton != undefined){
        boton.click();       
    }
}

function GuardarSolConUsuario_OnClick(q){
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;    
    var boton = d.getElementById("Edit_ImageButtonGuardar");
    
    if(boton != undefined){
        boton.click();       
    }
}
/* fin acciones*/

function btConfirmarSC_onclick(q){
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;    
    var boton = d.getElementById("btnConfirmar");
    if(boton != undefined){
        boton.click();       
    }    
} 

function btConfirmarSC_onclick_AssignarNova(que){
    var d = document.getElementById("modalPopUpFrame").contentWindow.document;
    
    //"http://localhost/cte.c/Pages/SolConst/SCViewer.aspx?datasource=solucionesconstructivas&idSC=75"
    //"http://localhost/cte.c/Pages/Asignacion/IframeSCViewer.aspx?CambiarSCRequest=%7b%22Alto%22%3anull%2c%22Ancho%22%3anull%2c%22IdElementoDimensional%22%3anull%2c%22IdSolucionConstructiva%22%3a%22SC4c265aa5-597b-424b-8b27-f85a6a7af246%22%2c%22Orientacion%22%3anull%2c%22Planta%22%3a%22i871edbd3-b7b8-4554-ba57-807df32d85ad%22%2c%22Propiedades%22%3anull%2c%22SubTipoSolucionConstructiva%22%3a1%2c%22TipoOperacion%22%3a0%2c%22TipoSolucionConstructiva%22%3a1%7d"
    var boton = d.getElementById("btnConfirmar");
}

function amagaBoto(q){
    document.getElementById(q.id).style.display = "none";
}

function OpenUploadFIDE(){
    
    var ventana = window;
    if (window.parent.location.href.indexOf("Error.aspx") == -1) {
        ventana = window.parent;
        if (ventana.DesactivarModalPopUp != undefined) {
            ventana.DesactivarModalPopUp();
        }
    }
    ventana.ShowModalDialogWidthDimensions("Seleccionar fichero FIDE", "UploadFide.aspx", 500, 440);
    var boton = ventana.document.getElementById("btTancar");            
    if(boton != null){
        ventana.document.getElementById("btTancar").onclick = function(){        
            if(confirm("¿Esta seguro que desea abandonar la aplicación CTE.C?")){
              ventana.close();  
            }
        }
    }else{
        alert("Error : No se ha podido encontrar el botón 'btTancar' en la página");
    }                            
}

function OpenUploadSolConFIDE(){
    ShowModalDialogWidthDimensions("Importación de Soluciones Constructivas", "UploadImportarSCFide.aspx", 500, 440);
    var boton = document.getElementById("btTancar");            
    if(boton != null){
        document.getElementById("btTancar").onclick = function(){                    
            parent.DesactivarModalPopUp();            
        }
    }else{
        alert("Error : No se ha podido encontrar el botón 'btTancar' en la página");
    }                            
}

function openSugerencia(){
    var v = ShowModalDialogWidthDimensions("Sugerencias", "../Pages/Sugerencias.aspx", 700, 200);
    var boton = document.getElementById("BtEnviar");            
    if(boton != null){
        boton.style.display = "inline";
    }else{
        alert("Error : No se ha podido encontrar el botón 'BtEnviar' en la página");
    }        
}


