function CaixaBaixa(fsValor, foForm, foNome) { 
	if (window.event.keyCode >= 65 && window.event.keyCode <= 90){
		x = new String(document.forms[foForm].elements[foNome].value);
		document.forms[foForm].elements[foNome].value = x.toLowerCase();
	}
} 

function validaEmail(Email){
	var filter = /^(([a-zA-Z0-9_-])+(([\.\])+([a-zA-Z0-9_-]{0,1})))+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	var arrayEmail = Email.split(";"); //Separa os email 
	for (var i=0;i < arrayEmail.length; i++){ //varre a lista de emails 
		if ( !filter.test(arrayEmail[i]) ){ 
			return false; //se tiver erro sai com false 
		}
		else{ 
			return true; // se nao achou erro retorrna verdadeiro 
		}
	}
} 

function enviarEmail(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validaEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtAssunto.value==''){
		alert('Informe um assunto!');
		document.form.txtAssunto.focus();
	}
	else if(document.form.txtMsg.value==''){
		alert('Digite uma mensagem!');
		document.form.txtMsg.focus();
	}
	else{
		document.form.action='?ac=contato';
		document.form.submit();
	}
}

function salvarEmail(){
	if(document.formNews.txtEmailNewsLetter.value == ''){
		alert('Informe o email');
		document.formNews.txtEmailNewsLetter.focus();
	}
	else if(validaEmail(document.formNews.txtEmailNewsLetter.value)==false){
		alert('E-mail inválido');
		document.formNews.txtEmailNewsLetter.value = '';
	}
	else{
		document.formNews.action='?ac=cadastrar_email';
		document.formNews.submit();
	}
}
function busca(valor,teclapres){
   var tecla = 0;
   if(document.all){
        tecla = teclapres.keyCode;
    }
    else{
      tecla = teclapres.which;
      if(tecla==1){tecla=0}
    }
    if (tecla == 13 || tecla == 0){
       if(document.formBusca.txtCriterio.value==''||document.formBusca.txtCriterio.value=='Pesquisar...'){
			alert('Informe um critério de busca!');
			document.formBusca.txtCriterio.focus();
		}
		else{
			document.formBusca.action='?ac=busca';
			document.formBusca.submit();
		}
   } 
}
function buscaCID(valor,teclapres){
   var tecla = 0;
   if(document.all){
        tecla = teclapres.keyCode;
    }
    else{
      tecla = teclapres.which;
      if(tecla==1){tecla=0}
    }
    if (tecla == 13 || tecla == 0){
       if(document.form.txtCriterio.value==''||document.form.txtCriterio.value=='Localizar CID...'){
			alert('Informe um critério!');
			document.form.txtCriterio.focus();
		}
		else{
			document.form.action='?ac=buscaCID';
			document.form.submit();
		}
   } 
}
function MudaCor1(idrow) {
    document.getElementById(idrow).style.background = "#7BA7D8"; //valor quando clicado
}
function MudaCor2(idrow) {
    document.getElementById(idrow).style.background = "#EBEBEB"; //valor quando normal
}
function atualizarSubLink(valor){
	var frame=document.getElementById("iFrameSubLink");
	frame.src='?ac=carregar_sub_link&idlink='+valor;
}

function atualizarPesquisaLink(valor){
	var frame=document.getElementById("iFrameSubLink");
	frame.src='?ac=carregar_busca_link&idlink='+valor;
}
function ajaxInit(){
var xmlhttp ;

	try {
 		xmlhttp = new XMLHttpRequest ( ) ;
 	}catch (ee){
		try { 
		xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP") ;
 		}catch( e ) {
 			try {
 				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP" ) ;
 			}catch(E) {
 				xmlhttp= false ;
 			}
 		}
 	}
 return xmlhttp ;
}
function carregarFoto(id){
	ajax=ajaxInit();
	document.getElementById("divImg").innerHTML="<img src=\"imagens/carregando.gif\" \>";
	if(ajax){
		ajax.open('GET','?ac=carregar_foto&id='+id,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("divImg").innerHTML=ajax.responseText;
					fadeInit();
				}
			}
		}
	}
	ajax.send(null);
}

function pagina(id,limit,paginas){
	ajax=ajaxInit();
	document.getElementById("divImagensEsq").innerHTML="<img src=\"imagens/carregando.gif\" \>";
	if(ajax){
		ajax.open('GET','?ac=carregar_pagina&id='+id+'&limit='+limit+'&paginas='+paginas,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("divImagensEsq").innerHTML=ajax.responseText;
				}
			}
		}
	}
	ajax.send(null);
}
var	fadeTarget;
var preInitTimer;

/* functions */

function preInit() {
	/* an inspired kludge that - in most cases - manages to initially hide the image
	   before even onload is triggered (at which point it's normally too late, and a nasty flash
	   occurs with non-cached images) */
	if ((document.getElementById)&&(fadeTarget=document.getElementById('imgFade'))) {
		fadeTarget.style.visibility = "hidden";
		if (typeof preInitTimer != 'undefined') clearTimeout(preInitTimer); /* thanks to Steve Clay http://mrclay.org/ for this small Opera fix */
	} else {
		preInitTimer = setTimeout("preInit()",2);
	}
}

function fadeInit() {
	if (document.getElementById) {
		/* get a handle on the fadeable object, to make code later more manageable */
		preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		/* set the initial opacity in a (hopefully) cross browser way
		   notice that because of the way the image is in front, and not obfuscated
		   by another object we need to "fade out", i don't need a fallback mechanism
		   to show/hide the covering object...the image is just there, full stop */
		if (fadeTarget.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			fadeTarget.style.MozOpacity = 0;
		} else if (fadeTarget.style.opacity!=null) {
			/* CSS3 compatible */
			fadeTarget.style.opacity = 0;
		} else if (fadeTarget.style.filter!=null) {
			/* IE's proprietary filter */
			fadeTarget.style.filter = "alpha(opacity=0)";
		}
		/* make the object visible again */
		fadeTarget.style.visibility = 'visible';
		window.setTimeout("fadeIn(0)", 500);
	}
}

function fadeIn(opacity) {
	if (fadeTarget) {
		if (opacity <= 100) {
			if (fadeTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeTarget.style.MozOpacity = (opacity/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeTarget.style.opacity = (opacity/100)-.001;
			} else if (fadeTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}
			opacity += 10;
			window.setTimeout("fadeIn("+opacity+")", 30);
		}
	}
}
/* 3rd party helper functions */

/* addEvent handler for IE and other browsers */
function addEvent(elm, evType, fn, useCapture) 
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
}