//Definições de ambiente
document.onkeydown = function() {
    if ((window.event.srcElement.tagName.toUpperCase() != 'INPUT') && (window.event.srcElement.tagName.toUpperCase() != 'TEXTAREA') && (window.event.keyCode == 8)) return false;
}

//Funções da aplicação
function $(obj){
    if(typeof obj=='string') return document.getElementById(obj);
};

function fnLink(pagina,target,op)	{
	var frm = document.frm;

	frm.op.value = op;
	frm.pagina.value = pagina;
	frm.cod_postagem.value = "";
	frm.cod_postagemcategoria.value = "";
	frm.campo_busca.value = "";
	frm.action = "";
	frm.target = (target=="")?"_self":target;
	frm.submit();
}

function fnBuscar()	{
	var frm = document.frm;

	frm.op.value = "busca";
	frm.pagina.value = "p_principal.php";
	frm.cod_postagem.value = "";
	frm.cod_postagemcategoria.value = "";
	frm.action = "";
	frm.target = "_self";
	frm.submit();
}

function fnColuna(cod_postagemcoluna,cod_postagemcategoria)	{
	var frm = document.frm;

	frm.op.value = "coluna";
	frm.pagina.value = "p_coluna.php";
	frm.cod_postagemcoluna.value = cod_postagemcoluna;
	frm.cod_postagemcategoria.value = cod_postagemcategoria;
	frm.campo_busca.value = "";
	frm.action = "";
	frm.target = "_self";
	frm.submit();
}

function fnPostagem(cod_postagem,cod_postagemcoluna)	{
	var frm = document.frm;

	frm.op.value = "coluna";
	frm.pagina.value = "p_postagem.php";
	frm.cod_postagem.value = cod_postagem;
	frm.cod_postagemcoluna.value = cod_postagemcoluna;
	frm.cod_postagemcategoria.value = "";
	frm.campo_busca.value = "";
	frm.action = "";
	frm.target = "_self";
	frm.submit();
}

function fnBlog(cod_postagem,cod_postagemcategoria)	{
	var frm = document.frm;

	frm.op.value = "";
	frm.pagina.value = "";
	frm.cod_postagemcategoria.value = cod_postagemcategoria;
	frm.cod_postagem.value = cod_postagem;
	frm.action = "blog";
	frm.target = "_self";
	frm.submit();
}

function fnEvento(cod_evento,cad_eventocategoria)	{
	var frm = document.frm;

	frm.op.value = "evento";
	frm.pagina.value = "p_evento.php";
	frm.cod_evento.value = cod_evento;
	frm.cad_eventocategoria.value = cad_eventocategoria;
	frm.submit();
}

function fnColunista(cod_colunista)	{
	var frm = document.frm;

	frm.op.value = "colunista";
	frm.pagina.value = "p_colunista.php";
	frm.cod_colunista.value = cod_colunista;
	frm.submit();
}

function fnDepoimento()	{
	var frm = document.frm;

	frm.op.value = "depoimento";
	frm.pagina.value = "p_depoimento.php";
	frm.action = "";
	frm.submit();
}


function fnClipping(cod_clipping)	{
	var frm = document.frm;

	frm.op.value = "clipping";
	frm.pagina.value = "p_clipping.php";
	frm.cod_clipping.value = cod_clipping;
	frm.sql_p_.value = "0";
	frm.mes.value = "";
	frm.ano.value = "";
	frm.submit();
}

function fnClippingPeriodo(mes,ano) {
	var frm = document.frm;

	frm.op.value = "clipping";
	frm.pagina.value = "p_clipping.php";
	frm.cod_clipping.value = "";
	frm.mes.value = mes;
	frm.ano.value = ano;
	frm.submit();	
}


function fnNews() {
	var frm = document.frm;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.news_nome.value==""){
		alert("Informe o Nome")
		frm.news_nome.focus();
		return false;
	}

	if (frm.news_email.value==""){
		alert("Informe o E-mail")
		frm.news_email.focus();
		return false;
	}

	if (!reEmail.test(frm.news_email.value)) {
		alert("E-mail inválido : " + frm.news_email.value)
		frm.news_email.focus();
		return false;
	}

	alert('Seu email será adicionado a nossa lista.')
	frm.op.value = "news";
	frm.pagina.value = "p_principal.php";
	frm.target = "";
	frm.submit();
}

function fnContato() {
	var frm = document.frm;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.contato_nome.value==""){
		alert("Informe o Nome")
		frm.contato_nome.focus();
		return false;
	}

	if (frm.contato_telefone.value==""){
		alert("Informe o Telefone")
		frm.contato_telefone.focus();
		return false;
	}

	if (frm.contato_email.value==""){
		alert("Informe o E-mail")
		frm.contato_email.focus();
		return false;
	}

	if (!reEmail.test(frm.contato_email.value)) {
		alert("E-mail inválido : " + frm.contato_email.value)
		frm.contato_email.focus();
		return false;
	}

	frm.op.value = "contato";
	frm.pagina.value = "p_contato.php";
	frm.target = "";
	frm.submit();
}

function fnAssinar() {
	var frm = document.frm;
	var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	if (frm.contato_nome.value==""){
		alert("Informe o Nome")
		frm.contato_nome.focus();
		return false;
	}

	if (frm.contato_documento.value==""){
		alert("Informe o Documento")
		frm.contato_documento.focus();
		return false;
	}

	if (frm.contato_senha.value==""){
		alert("Informe uma Senha de acesso")
		frm.contato_senha.focus();
		return false;
	}

	if (frm.contato_endereco.value==""){
		alert("Informe o Endereço")
		frm.contato_endereco.focus();
		return false;
	}

	if (frm.contato_cidade.value==""){
		alert("Informe a Cidade")
		frm.contato_cidade.focus();
		return false;
	}

	if (frm.contato_uf.value==""){
		alert("Informe o Estado")
		frm.contato_uf.focus();
		return false;
	}

	if (frm.contato_cep.value==""){
		alert("Informe o CEP")
		frm.contato_cep.focus();
		return false;
	}

	if (frm.contato_telefone.value==""){
		alert("Informe o Telefone")
		frm.contato_telefone.focus();
		return false;
	}

	if (frm.contato_email.value==""){
		alert("Informe o E-mail")
		frm.contato_email.focus();
		return false;
	}

	if (!reEmail.test(frm.contato_email.value)) {
		alert("E-mail inválido : " + frm.contato_email.value)
		frm.contato_email.focus();
		return false;
	}

	frm.op.value = "assinar";
	frm.pagina.value = "p_assine.php";
	frm.target = "";
	frm.submit();
}

function fnManagerMenu(categoria){
	var i;
	var objs = document.getElementsByName('menu_coluna');
	for(i=0;i<=objs.length-1;i++) objs[i].style.display = (objs[i].id==categoria)?"block":"none";
}

function fnSearch(sql_p_){
	var frm = document.frm;
	
	frm.op.value = "search";
	frm.sql_p_.value = (sql_p_)?sql_p_:1;
	frm.submit();
}

function fnImagePreview(src) {
	var html = (fnImagePreview.arguments[1])?fnImagePreview.arguments[1]:"";
	var div = document.createElement("div");
	
	div.id = "image-preview";
	div.style.width = fnSize('')[0];
	div.style.height = fnSize('')[1];
	div.innerHTML = "<div id='image-previewcenter'><img src='"+src+"'>"+html+"</div>"
	div.onclick = function() { fnRemove() };
	function fnRemove() { $("image-preview").parentNode.removeChild($("image-preview")); }
	document.body.appendChild(div);
	if (document.all) {div.style.filter = "alpha(opacity=80)";}else{div.style.opacity = "1";$('image-previewcenter').style.opacity = "1"}
	$('image-previewcenter').style.left = ((fnSize('')[0] - fnSize('image-previewcenter')[0]) / 2)+"px";
	$('image-previewcenter').style.top = ((fnSize('')[1] - fnSize('image-previewcenter')[1]) / 2)+"px";
}

function fnSize(obj) {
	if (obj=='') {
		width = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
		height = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
	} else {
		width = $(obj).clientWidth;
		height = $(obj).clientHeight;
	}
	fnSize[0] = width;
	fnSize[1] = height;
	return fnSize;
}

// FUNÇÕES GERAIS

if(Browser == undefined) {
    var Browser = {
        isIE: function(){ return (window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? true : false; }
    };
}


var Flash = function(movie, id, width, height, initParams){
    this.html = "";
    this.variables = new Array();
    this.flashversion = (typeof initParams != "undefined" && typeof initParams.flashversion != "undefined") ? initParams.flashversion : "7,0,0,0";
    this.attributes = {
        "classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
        "codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=" + this.flashversion,
        "type": "application/x-shockwave-flash"
    };
    this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer" };
    
    if(movie) {
        this.addAttribute("data", movie);
        this.addParameter("movie", movie);
    }
    
    if(id && id != null && (this.id = id)) {
        this.addAttribute("id", this.id);
        this.addAttribute("name", this.id);
    } else {
        this.id = null;
    }
    
    if(width) this.addAttribute("width", width);
    if(height) this.addAttribute("height", height);

    this.addAttribute("wmode", "transparent");
    this.addParameter("wmode", "transparent");

    if(initParams != undefined) for(var i in initParams) this.addParameter(i.toString(), initParams[i]);
};

Flash.version = "v1.8";

Flash.prototype.getObject = function()
{
    if(this.id == null) return null;
    try
    {
        if(window.document[this.id])
        {
            return window.document[this.id];
        }
        else
        {
            return document.getElementById(window.document[this.id]);
        }
    }
    catch(e) { return null; }
};

Flash.getObjectByExceptions = function(obj, excep)
{
    var tempObj = {};
    for(var i in obj)
    {
        var EOF = false;
        for(var j=0; j<excep.length; j++) if(excep[j] == i.toString()) { EOF = true; break; };
        if(!EOF) tempObj[i] = obj[i];
    }
    return tempObj;
};

Flash.prototype.addAttribute = function(prop, val){ this.attributes[prop] = val; };
Flash.prototype.addParameter = function(prop, val){ this.params[prop] = val; };
Flash.prototype.addVariable = function(prop, val){ this.variables.push([prop, val]); };

Flash.prototype.getFlashVars = function()
{
    for(var i=0, tempString = new Array(); i<this.variables.length; i++) tempString.push(this.variables[i].join("="));
    return tempString.join("&");
};
Flash.prototype.toString = function()
{
    this.params.flashVars = this.getFlashVars();
    if(Browser.isIE())
    {
        //IE
        this.html = "<ob" + "ject";
        var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
        for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
        this.html += "> ";
        var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
        for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
        this.html += " </obj" + "ect>";
    }
    else
    {
        //non-IE
        this.html = "<!--[if !IE]> <--> <obj" + "ect";
        var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
        for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
        this.html += "> ";
        var params = Flash.getObjectByExceptions(this.params, ["extend"]);
        for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
        this.html += " </obj" + "ect> <!--> <![endif]-->";
    }
    return this.html;
};
Flash.prototype.write = Flash.prototype.writeIn = function(w)
{
    if(typeof w == "string" && (w = document.getElementById(w)));
    if( w != null ) { w.innerHTML = this.toString(); }
    else if( w == undefined ) { document.write( this.toString() ); }
        else { return false; }
};

//automatization functions...
Flash.correctAll = function()
{
    if(!/msie/.test(navigator.userAgent.toLowerCase()) || !document.getElementsByTagName) return false;
    for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length;
        (objects[i].outerHTML ? (objects[i].outerHTML = objects[i].outerHTML, objects[i].style.visibility = "visible") : null), i++);
};
Flash.automatic = function(r)
{
    if(r && window.attachEvent)
    {    
        for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length; (objects[i].style.visibility = "hidden"), i++);
        window.attachEvent("onload", Flash.correctAll);
        window.attachEvent("onunload", function(){ window.detachEvent("onload", Flash.correctAll); });
    }
    else
    {
        Flash.correctAll();
    }
};

