var msg;
var strName;
var showScroll;

function showPPT(url,intNumPPT){
    msg.setTitle("Catequesis Hoy");
    urlPPT  = "loadhtmlppt.php?func=1&path="+url+"&numPPT="+intNumPPT+"&nameppt="+strName+"&showScroll="+showScroll;
    new Ajax.Request(urlPPT, {
            method: 'get',
            onFailure: function(transport) {
                    msg.showButtonOk(true);
                    msg.setText("<strong style='color:#FF0000'>Error de configuraci&oacute;n</strong>");
                    msg.setTitle("Catequesis Hoy");
            },
            onLoading: function(transport) {
                msg.setTitle("Catequesis Hoy - Cargando ppt...");
            },
            onSuccess: function(transport) {
                    msg.showButtonOk(true);                    
                    var arrText=transport.responseText.toArray();
                    var strText="";
                    for(i=0;i<arrText.length;i++)
                        strText+=arrText[i];
                    msg.setText(strText);
                    msg.setTitle("Catequesis Hoy");
            }
    });
}

function viewDocument(url,w,h,blShowScroll,name,docURL){
    if(w==null)w=650;
    if(h==null)h=500;    
    strName = ((name==null)?"img":name);
    showScroll = ((blShowScroll==null)?false:blShowScroll);    
    msg = new Message(false,blShowScroll);
    msg.setTitle("Catequesis Hoy - Cargando ppt...");        
    msg.setWidth(w);
    msg.setHeight(h);
    msg.setVisible(true);
    
    urlPPT  = "loadhtmlppt.php?func=1&path="+url+"&numPPT=0&nameppt="+strName+"&showScroll="+showScroll;
    new Ajax.Request(urlPPT, {
            method: 'get',
            onFailure: function(transport) {
                    msg.showButtonOk(true);
                    msg.setText("<strong style='color:#FF0000'>Error de configuraci&oacute;n</strong>");
                    //msg.setTitle("Catequesis Hoy - Cargando ppt...");
            },
            onSuccess: function(transport) {
                    msg.showButtonOk(true);
                    var arrText=transport.responseText.toArray();
                    var strText="";
                    for(i=0;i<arrText.length;i++)
                        strText+=arrText[i];
                    msg.setText(strText);
                    msg.setTitle("Catequesis Hoy");
            }
    });
}
/***********************************************************************************/

var navegador = navigator.appName
var ID = "gwin";
var ID_BACK = "gwin_back";

function resizesHeightComponents(id,idBack){

    var htmlheight = document.body.parentNode.scrollHeight;
    var windowheight = window.innerHeight;
    
    if ( htmlheight < windowheight ) {
        $(id).style.height = windowheight + "px";
        $(idBack).style.height = windowheight + "px";
    }
    else{
        $(id).style.height = htmlheight + "px";
        $(idBack).style.height = htmlheight + "px";
    }
}

function closeViewGDocument(id, idBack) {
    $(id).hide();
    $(idBack).hide();
    //Muestra las barras scroll
    document.body.style.overflow = "";    
    document.body.style.overflowX = "";
    document.body.scroll = "";
    if (navegador == "Microsoft Internet Explorer")
        document.documentElement.style.overflow = "auto";
}

function viewGDocument(docURL,title,isImageURL){

    //Oculta las barras scroll

    document.body.style.overflow = "hidden";
    document.body.style.overflowX = "hidden";
    document.body.scroll = "no";
    if (navegador == "Microsoft Internet Explorer")
        document.documentElement.style.overflow = "hidden";
    
    ////ver en ie lo de ocultar scroll
    //Ver de hacer rezise
    
    if($(ID) == null) {

        this.containerdivBack = document.createElement("div");
        this.containerdivBack.id = ID_BACK;
        this.containerdivBack.classReference = this;
        this.containerdivBack.style.zIndex = 20;
        this.containerdivBack.style.position = "absolute";
        this.containerdivBack.style.left = "0px";
        this.containerdivBack.style.top = "0px";
        this.containerdivBack.style.backgroundColor ="#86B30B";
        this.containerdivBack.style.width = (document.viewport.getWidth()-20)+"px";

        //Lo crea
        this.containerdiv = document.createElement("div");
        this.containerdiv.id = ID;
        this.containerdiv.classReference = this;
        this.containerdiv.style.zIndex = 21;
        this.containerdiv.style.position = "absolute";
        this.containerdiv.style.left = "0px";
        this.containerdiv.style.top = "0px";
        this.containerdiv.style.width = (document.viewport.getWidth()-20)+"px";
        
        objTemp = this.containerdiv;

        document.body.appendChild(this.containerdivBack);
        document.body.appendChild(this.containerdiv);

        resizesHeightComponents(ID, ID_BACK);
           
        $(ID_BACK).setOpacity(0.7);
    }else{
        //Lo hace visible
        objTemp = $(ID);
        $(ID_BACK).show();
        $(ID).show();
    }
    
    urlView = "";
    if(isImageURL!=null && isImageURL == true)
        urlView = docURL;
    else
        urlView = 'https://docs.google.com/viewer?url='+docURL+'&embedded=true';

    objTemp.innerHTML = '<div style="border:1px solid #B3EE0F;margin-top:10px;background-color:white;position:absolute;width:800px;height:590px;left:'+((document.viewport.getWidth()/2)-400 )+'px;top:'+document.viewport.getScrollOffsets().top+'px">'+
                              '<div style="height:25px;"><div style="margin-left:3px;margin-top:3px;overflow:hidden;width:65%;float:left;font-size:12px;font-family:Verdana;color:#86B30B"><b>'+title+'</b></div><div style="margin-top:3px;float:left;font-size:10px;font-family:Verdana;color:#86B30B;width:34%;text-align:right;"><a id="id_desc" href="'+docURL+'" target="_blank" style="color:#86B30B;">Descargar</a> | <a id="id_close" href="javascript:closeViewGDocument(\''+ID+'\',\''+ID_BACK+'\');" style="color:#86B30B;">Cerrar</a></div></div>'+
                              '<div style="background-color:white;height:560px;">'+
                                  '<iframe src="'+urlView+'" width="100%" height="100%" scrolling="auto" frameborder="0" transparency>'+
                                  '<p>Prueba con otro navegador. Lo sentimos!</p>'+
                                  '</iframe>'+
                               '</div>'+
                               '<div style="height:5px;"></div>'+
                          '</div>';

}

window.onresize = resizesHeightComponents(ID, ID_BACK);
