//===============================================================================
//= FUNÇÕES DE FORMULÁRIO =======================================================
//===============================================================================
var tipo = 0;
var urlbusca = "busca/index";

function FaleConosco() {
	tipo = 1;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function Newsletter() {
	tipo = 2;
	document.form1.action = "newsletter-act.asp";
	document.form1.method = "post";
}

function Busca01() {
	tipo = 3;
	var buscarEm = document.form1.buscarEm.value;
	switch(buscarEm) {
		case "0": urlbusca = "busca/index"; break;
		case "1": urlbusca = "noticias/busca"; break;
		case "2": urlbusca = "artigos/busca"; break;
		case "3": urlbusca = "frase-do-dia/busca"; break;
		case "4": urlbusca = "audios/busca"; break;
		case "5": urlbusca = "videos/busca"; break;
	}
	document.form1.action = "busca/index.asp";
	document.form1.method = "get";
}

function Busca02() {
	tipo = 4;
	var buscarEm = document.form1.buscarEm.value;
	switch(buscarEm) {
		case "0": urlbusca = "busca/index"; break;
		case "1": urlbusca = "noticias/busca"; break;
		case "2": urlbusca = "artigos/busca"; break;
		case "3": urlbusca = "frase-do-dia/busca"; break;
		case "4": urlbusca = "audios/busca"; break;
		case "5": urlbusca = "videos/busca"; break;
	}
	document.form1.action = "../busca/index.asp";
	document.form1.method = "get";
}

function Busca03() {
	tipo = 5;
	var buscarEm = document.form1.buscarEm.value;
	switch(buscarEm) {
		case "0": urlbusca = "busca/index"; break;
		case "1": urlbusca = "noticias/busca"; break;
		case "2": urlbusca = "artigos/busca"; break;
		case "3": urlbusca = "frase-do-dia/busca"; break;
		case "4": urlbusca = "audios/busca"; break;
		case "5": urlbusca = "videos/busca"; break;
	}
	document.form1.action = "../../busca/index.asp";
	document.form1.method = "get";
}

function Comentario() {
	tipo = 6;
	document.form1.action = "comentar-act.asp";
	document.form1.method = "post";
}

function EnvieParaAmigo() {
	tipo = 7;
	document.form1.action = "enviar-para-um-amigo-act.asp";
	document.form1.method = "post";
}

function NewsletterBoxPP() {
	tipo = 8;
	document.form1.action = "newsletter/index.asp";
	document.form1.method = "get";
}

function NewsletterBox() {
	tipo = 8;
	document.form1.action = "../newsletter/index.asp";
	document.form1.method = "get";
}

function EuReporter() {
	tipo = 9;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function AnexarArquivo() {
	tipo = 10;
	document.form1.action = "anexar-act.asp";
	document.form1.method = "post";
}

function ExposicaoComprar() {
	tipo = 11;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}


function EnviaFormulario() {
	switch(tipo) {
		case 1: return VFaleConosco(); break;
		case 2: return VNewsletter(); break;
		case 3: if (VBusca()) { document.location.href=urlbusca+".asp?secao="+document.form1.buscarEm.value+"&busca=" + document.form1.busca.value; } break;
		case 4: if (VBusca()) { document.location.href="../"+urlbusca+".asp?secao="+document.form1.buscarEm.value+"&busca=" + document.form1.busca.value; } break;
		case 5: if (VBusca()) { document.location.href="../../"+urlbusca+".asp?secao="+document.form1.buscarEm.value+"&busca=" + document.form1.busca.value; } break;
		case 6: return VComentario(); break;
		case 7: return VEnviaParaAmigo(); break;
		case 8: return VNewsletterBox(); break;
		case 9: return VEuReporter(); break;
		case 10: return VAnexarArquivo(); break;
		case 11: return VExposicaoComprar(); break;
	}
	return false;
}

//===============================================================================
//= BUSCA =======================================================================
//===============================================================================
function VBusca() {
	if (!(document.form1.busca.value.length > 1)) { alert("Informe o texto a ser procurado no site."); document.form1.busca.focus(); return false; };
	return true;
}


//===============================================================================
//= FUNÇÃO DE EXIBIÇÃO DOS MENUS ================================================
//===============================================================================
function SHMenu(menu, linkMenu) {
	element = document.getElementById("menu" + menu);
	element.style.display = element.style.display != 'none' ? 'none' : '';
}


//===============================================================================
//= IMPRESSÃO ===================================================================
//===============================================================================
function PrintNews(noticia) {
	if (!isNaN(noticia)) {
		NewWindow('imprimir.php?id='+noticia,'newsprint',650,550,'yes');
	};
}


//===============================================================================
//= CONTROLA TAMANHO DAS FONTES =================================================
//===============================================================================
var fontSize = 12;
var fMax = 25;
var fMin = 9;
var inc = 1;

function setFontSize() {
	var tempSize = getCookie("fontSize");
	
	if ((tempSize != null) && (tempSize >= fMin) && (tempSize <= fMax)) 
		fontSize = tempSize;
	else
		setCookie("fontSize", fontSize);

	var ptexto = document.getElementById('pTexto');
	if (ptexto) 
		ptexto.style.fontSize = fontSize + 'px';
}

function changeFontSize(increment) {
	if(increment) 
		fontSize=parseInt(fontSize) + parseInt(inc);
	else 
		fontSize=parseInt(fontSize) - parseInt(inc);

	if (fontSize > fMax)
		fontSize = fMax;
	if(fontSize < fMin)
		fontSize = fMin;

	var ptexto = document.getElementById('pTexto');
	if (ptexto) 
		ptexto.style.fontSize = fontSize + 'px';

	setCookie('fontSize', fontSize);
}

function incrementFontSize() {
	changeFontSize(true);
}

function decrementFontSize() {
	changeFontSize(false);
}


//===============================================================================
//= OUTRAS FUNÇÕES DO SITE ======================================================
//===============================================================================
function display(ID) {
	document.getElementById(ID).style.display = document.getElementById(ID).style.display == 'none' ? '' : 'none';
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


//===============================================================================
//= ABRE POP-UP CENTRALIZADO ====================================================
//===============================================================================
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition = parseInt((screen.height) ? (screen.height-h)/2 : 0);
	settings = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable,status=yes'
	win = window.open(mypage,myname,settings)
}


//===============================================================================
//= REDIMENSIONA POP-UP =========================================================
//===============================================================================
function Redimensiona(w, h) {
	//Corrige o tamanho da janela
	if (navigator.appName == "Microsoft Internet Explorer") {
		w = parseInt(w) + 10;
		h = parseInt(h) + 48;
	} else {
		w = parseInt(w) + 6;
		h = parseInt(h) + 49;
	};
	// IE 7
	var nversao = navigator.userAgent;
	var nresult = nversao.search(/\bMSIE 7.0\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 30;
	};
	//
	// FIREFOX 3
	var nversao = navigator.userAgent;
	var nresult = nversao.search(/\bFirefox\/3.0\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 30;
	};
	//
	// SAFARI / CHROME
	var nversao = navigator.userAgent;
	var nresult = nversao.search(/\bSafari\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 10;
	};
	//
	LeftPosition =  parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition =  parseInt((screen.height) ? (screen.height-h)/2 : 0);
	window.moveTo(LeftPosition,TopPosition);
	window.resizeTo(w, h);
	window.focus();
}


//===============================================================================
//= EXIBE FLASHS ================================================================
//===============================================================================
function ExibeFlash(movie,w,h,wmode,bg) {
	if(wmode == "transparent") { ftransp = true; wmode = "wmode='transparent'"; } else { ftransp = false; wmode = ""; };

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	if(ftransp) { document.write('<param name="wmode" value="transparent"/>'); };
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" '+wmode+' width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}

//===============================================================================
//= EXIBE / ESCONDE ELEMENTOS ===================================================
//===============================================================================
function ExibeEsconde(id) {
	document.getElementById(id).style.display = document.getElementById(id).style.display == 'none' ? '' : 'none';
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//===============================================================================
//= MANIPULAR COOKIES ===========================================================
//===============================================================================
function getCookieVal(inicio) {
	var fim = document.cookie.indexOf(";", inicio);
	if (fim == -1) fim = document.cookie.length;
	return unescape(document.cookie.substring(inicio, fim));
}

function getCookie(label) {
	var arg = label + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(label, valor, expires) {
	document.cookie = label + "=" + escape(valor) + 
		((expires) ? "; expires=" + expires.toGMTString() : "");
}

function delCookie(label) {
	if (getCookie(label)) {
		document.cookie = label + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


//===============================================================================
//= VERIFICA NAVEGADORES ========================================================
//===============================================================================
var ua = navigator.userAgent;
var ver = parseInt( navigator.appVersion );
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /MSIE/.test(ua);
var ie6 = ie && /MSIE [0123456]/.test(ua);
var ie7 = ie && /MSIE [789]/.test(ua);
var ieBox = ie && (document.compatMode == null || document.compatMode != "CSS1Compat");
var moz = !opera && /gecko/i.test(ua);
var nn6 = !opera && /netscape.*6\./i.test(ua);
