//*************************************************
// Funções javascript de todo o site
// 16/09/2009
//*************************************************
//
// Funções para a popup principal
$.setupJMPopups({
    screenLockerBackground: "#003366",
    screenLockerOpacity: "0.7"

});

$(document).ready(function() {

    
    // Popup modal para uso em todas as paginas, vide uso abaixo:
    // Usage: http://jekk:5252/Default.aspx?popup=1&page=form.html&width=500
    if ($.getURLParam("popup") != null) 
    {
        $.openPopupLayer({
                name: "popup321",
                width: $.getURLParam("width"),
                url: $.getURLParam("page")
            }); 
    }

    // Carrega o flash de "carregando" do ajax
    $('#swfload').flash(
    {
        src: '/flash/carregando.swf',        
        expressInstall: true,
        width: 292,
        height: 132,
        wmode: 'transparent'
    },
		{
		    version: 10
	});
	
		// Carrega o flash de news na principal
	$('#swfsliderEnt').flash(
    {
        //src: '/flash/pcNews.swf',        
        src: '/flash/pcNewsNAT.swf',        
        expressInstall: true,
        width: 580,  //era 368
        height: 291,  // era 268
        wmode: 'transparent',
        flashvars: { main_dl_src: '/flash/pcNewsNAT.swf', dlXML: '/interfaceflash/Default.aspx?opt=pcnewsNATEnt'}
    },
		{
		    version: 10
	});
	

	
// ==UserScript==
    // @namespace     http://javascript.about.com
    // @author        Stephen Chapman
    // @name          iframe killer
    // @description   deletes all iframes from a web page
    // @include       http://example.com/
    // ==/UserScript==
    //while((el=document.getElementsByTagName('iframe')).length){el[0].parentNode.removeChild(el[0]);}


    // Funções para ptoteção da página
	var message="Todo o material contido neste site se encontra protegido pelas leis de direitos autorais.";
    function click(e) 
    {
        if (document.all) 
        {
            if (event.button==2||event.button==3) {
                //alert(message);
                return false;
            }
        }
        if (document.layers) 
        {
            if (e.which == 3) {
                // alert(message);
                return false;
            }
          }
        }
        if (document.layers) {
        document.captureEvents(Event.MOUSEDOWN);
    }
    document.onmousedown=click;
		
});


// Função que coloca um relógio em tempo real no topo da página, juntamente com a data
function ExibeRelogio(date)
 {
     var today  = new Date();
     var second = today.getSeconds();
     var minute = today.getMinutes();
     var hour   = today.getHours();
     var hour24 = today.getHours();
     var ampm   = "";
     
    if(second<10)
        {
            second = "0"+second;
        }
        
    if(minute<10)
        {
            minute = "0"+minute;
        }
        
   /* if(hour24<=12)
        {
            ampm = "AM";
        }
        
    else
        {
            ampm = "PM"
        } 
        
    if(hour24>=12)
        {
            hour= hour-12;
        }
        
    if(hour24==0)
        {
            hour=12;
        }*/
    
    document.getElementById('divRelogioEnt').innerHTML=(hour+":"+minute+":"+second + " ");
}





// Funções que tratam o timeout do ajax e caso ocorrer o mesmo redireciona para a pagina /Timeout.aspx
function EndRequestHandler(sender, args) {
    if (args.get_error() != undefined) {
        var errorMessage = args.get_error().message;
        var statusCode = args.get_response().get_statusCode();
        if (statusCode == '0' || statusCode == '12030' || statusCode == '12031')
            window.location.pathname = '/Timeout.aspx';
    }

    args.set_errorHandled(true);
}

function RequestErrorAjax() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}



      function MaxLenght(text,long){ 

       var maxlength = new Number(long); // Change number to your max length. 

       if (text.value.length > maxlength){ 
       text.value = text.value.substring(0,maxlength); 
}
}




// Querystring para JS

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}


// Função que abre a popup modal
function abrePopup(page) {
    $.openPopupLayer({
        name: "abrePopup",
        width: 640,
        url: page
    });

}
