var xmlhttp
function loadXMLDoc(url, idWrite, tRequest)
{
	if(tRequest!="GET" || tRequest!="POST")
		tRequest = "GET";
	element	=  document.getElementById(idWrite);
	element.innerHTML  = "<div style=\"width:100%; padding-top:100px; text-align:center;\"><div style=\"width:150px;\"><div style=\"float:left; padding-top:5px;\">Carregando Aguarde...</div><div style=\"float:left;\"><img src=\"img/clocks.gif\" style=\"margin-left:10px;\" align=\"center\"></div></div</div>";   

// code for Mozilla, etc.

if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4)
	{
			// if OK
			if (xmlhttp.status==200)
			{
			  element.innerHTML=xmlhttp.responseText
			}
			else
			{
				alert("Problem Ao Tentar Abrir Arquivo: " + url )
			}
	  }
  }
  xmlhttp.open(tRequest,url,true)
  xmlhttp.send(null)
  }

// code for IE

else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	if (xmlhttp)
	{
	xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4)
	{
			// if OK
			if (xmlhttp.status==200)
			{
			  element.innerHTML=xmlhttp.responseText
			}
			else
			{
				alert("Problem Ao Tentar Abrir Arquivo:" + xmlhttp.statusText)

			}
	  }
  }

	xmlhttp.open(tRequest,url,true)
	if(tRequest=="POST")
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send()
	}
  }
}

var pagAtual =  "";
var pagAnt =  "";

function mudaConteudo(endpagina) {
	if (!endpagina || endpagina==""){
		myCoo = getCookie('pagina');
		myPrimVez = getCookie('primVez');
		if (myPrimVez == 'true'){
			mypagina = "Home";
			setCookie('pagina', mypagina);
			setCookie('primVez', 'false');
		}

		else{
			mypagina = myCoo;
			setCookie('pagina', mypagina);
		}
	}

	else{

		mypagina = endpagina

	}

	if (mypagina != pagAtual){
		pagAnt = pagAtual;
		pagAtual = mypagina;
		//verifica se eh a pagina de fotos
		if(mypagina=="fotos"){
			//se for abre com jquery
			$foo("#contGeral").load("inc/fotos.php");
		}else{
			//se nao for abre normal com loadXMLDoc
			loadXMLDoc('inc/'+mypagina+'.php', 'contGeral', 'GET');
		}
		setCookie('pagina', mypagina);
		if (pagAnt != "Home" && pagAnt != ""){
			mudaImg('bot'+pagAnt, 'off', '');
		}
		if (mypagina != "Home"){
			mudaImg('bot'+mypagina, 'on', '');
		}
	}
}



function mudaImg(imagem, estado, narq){
	if (narq != pagAtual){
		myImg = document.getElementById(imagem)
		if (myImg != undefined){
			myImg.src = "img/"+imagem+"_"+estado+".gif";
		}
	}
}


function volta(){
	loadXMLDoc('inc/'+pagAnt+'.php', 'contGeral', 'GET');
	holdPagAnt = pagAnt;
	pagAnt = pagAtual;
	pagAtual = holdPagAnt;
	holdPagAnt = "";
}



function simplePreload() { 
	var args = simplePreload.arguments; 
	document.imageArray = new Array(args.length); 
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
		}
}


function Abre(url, width, height, rola)
	{						
	if (rola==""){rola="yes"}
	window.open(url,"_blank","resizable=no,toolbar=no,status=no,top=" + (window.screen.height - height)/2 + ",left=" + (window.screen.width - width)/2 + ",menubar=no,scrollbars=" + rola + ",width=" + width + ",height=" + height);
	}


function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}



function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0){ 
		offset = document.cookie.indexOf(search)
		if (offset != -1){ 
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length
				return unescape(document.cookie.substring(offset, end))
			} 
		} 
	}



function expira(){
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	return expires;
}



function checaCookie(name,nomim) {
	if (getCookie(name)=='on'){
		Elemento = document.getElementById(nomim);
		Elemento.style.display="block";
	}
}
function  onlyNumbers(){
			if (event.keyCode < 48 || event.keyCode > 57) 
				event.returnValue = false;
}

function validaMail(objMail){
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objMail))) 
    { 
		email = false;
	} 
	else{
		email = true;
	}
	return email;
}

function validaEmail(email){
	ER = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$");
    if (ER.test(email)){
    	return true;
    }
    else{
    	return false;
    }
}

// SOLUÇÃO PARA O SCRIPT DO JQUERY QUE ENTRA EM CONFLITO COM O SCRIPT DO PROTOTYPE.
// FOI SUBSTTITUIDO O $ PARA $foo PARA SOLUCIONAR O PROBLEMA DO CONFLITO ENTRE OS SCRIPTS.
var $foo = jQuery.noConflict();

// 1 VARIÁVEL (VETOR) E 2 METODOS PARA CONTROLAR AS LISTAS DE CATEGORIAS NA GALERIA DE FOTOS DO SITE
var categorias = new Array();

function fechaCategorias(qtdCateg){
	for(i=0; i<=qtdCateg; i++){
		categorias[i]="fechado";
	}
}

//abre a categoria de fotos se ela estiver fechada
function abreFecha(id) {
	if(categorias[id] == "fechado"){
		//busca as categorias e as galerias que tem relacionamento com a categoria passada como parametro
		$foo('#cate_'+id).load("sistemas/geral/sis/galeria/new_view3/index.php?acao=filhoByCate&id="+id);
		$foo("#cate_"+id).slideDown("normal");
		categorias[id] = "aberto";
	}else{
		//$foo("#cate_"+id).css({margin:'0 0 0 10px', padding:'0 0 0 15px'});
		//$foo("#cate_"+id+" li").css({padding:'0 0 0 0px'});
		$foo("#cate_"+id).fadeOut("normal");
		categorias[id] = "fechado";
	}
}

//escreve o flash na div desejada para que nao precise clicar nele antes de usa-lo
function montaFlash(destino, flavez, width, height, trans, scale){

	var myFlash =
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+flavez+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="swf/'+flavez+'.swf" />'
	;
	if (trans == "yes"){
		myFlash += '<param name="wmode" value="transparent" />';
	}
	if (scale == "yes"){
		myFlash += '<param name="scale" value="noscale" />';
	}
	myFlash +=
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="swf/'+flavez+'.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="empresas" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}

function mudaPaginaGaleria(url){
	$foo('#contGeral').load(url);
}
