//===============================================================================
//= FUNÇÕES DE JQUERY =======================================================
//===============================================================================
$(document).ready(function(){
	 $("div#menu-institucional dl dd").hide();
	 $("div#menu-institucional dl dt a").click(function(){
		  $("div#menu-institucional dl dd:visible").slideUp("normal");
		  $(this).parent().next().slideDown("slow");
		  return false;
	 });
});


//===============================================================================
//= FUNÇÕES DE FORMULÁRIO =======================================================
//===============================================================================
var tipo = 0;

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 Busca() {
	tipo = 3;
	document.form1.action = "busca.asp";
	document.form1.method = "get";
}

function Busca02() {
	tipo = 4;
	document.form1.action = "../busca/index.asp";
	document.form1.method = "get";
}

function Busca03() {
	tipo = 5;
	document.form1.action = "../../busca/index.asp";
	document.form1.method = "get";
}


function EnviaFormulario() {
	switch(tipo) {
		case 1: return VFaleConosco(); break;
		case 2: return VNewsletter(); break;
		case 3: if (VBusca()) { document.location.href="busca.asp?busca=" + document.form1.busca.value; } break;
		case 4: if (VBusca()) { document.location.href="../busca/index.asp?busca=" + document.form1.busca.value; } break;
		case 5: if (VBusca()) { document.location.href="../../busca/index.asp?busca=" + document.form1.busca.value; } 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' : '';
}


//===============================================================================
//= FUNÇÃO DE EXIBIÇÃO DOS MENUS DE CATEGORIA ===================================
//===============================================================================
function EscondeCat(id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == 'none') ? '' : 'none';
}


//===============================================================================
//= 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\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>');
}


//===============================================================================
//= 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);


//===============================================================================
//= AJAX ========================================================================
//===============================================================================
function ajaxInit() {
	var req;
	
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				req = new XMLHttpRequest();
			} catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}
	return req;
};

function LoadAjax(metodo, url, send, destino, loadshow, loadcontent, loaddestino) {
	var ajax = ajaxInit();	
	if(ajax) {  
		if(metodo == "post") {  
				ajax.open("POST", url, true);  
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
		} else {
				ajax.open("GET", url + "?rnd="+ Math.random() +"&"+ send, true);  
		}
		ajax.onreadystatechange = function() { 
																if (ajax.readyState == 1) {
																	if (loadshow == 2) {
																		document.getElementById(loaddestino).innerHTML = loadcontent;
																	};
																}
																if (ajax.readyState == 4) {
																	if (ajax.status == 200) {
																		var resultado = ajax.responseText; // Coloca o retornado pelo Ajax nessa variável 
																		resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4) 
																		resultado = unescape(resultado); // Resolve o problema dos acentos 
																		if (loadshow == 2) {
																			document.getElementById(loaddestino).innerHTML = '';
																		};
																		document.getElementById(destino).innerHTML = resultado;
																	};
																}
															}  
			
		if(metodo == "post") {  
			ajax.send(send);  
		} else {  
			ajax.send(null);  
		}  
	}  
}
