	function InicializarIndices() {
		if (document.CargaInicial==null) {
			document.CargaInicial=false; // Seta para só fazer uma vez por documento
			var ctrlAnterior=null;
			var IndAnt=0;
			for ( var i=0; i<document.forms[0].elements.length;i++)	{
				var e=document.forms[0].elements[i];
				if ( e.type!="hidden" && e.type!="image" ) {
					if (ctrlAnterior != null) ctrlAnterior.IndicePosterior=i;
					ctrlAnterior=e;
					e.Indice=i;
					e.IndiceAnterior=IndAnt;
				}
			}
		}
	}
	// Limpar o conteúdo do(s) campo(s)
	function LimparCampo(ind) {	// Para -1, limpa todos os elementos
		if (isNaN(ind)) // Limpa pelo nome
			document.forms[0].elements[ind].value="";
		else if (ind != -1) // Limpa o elemento "ind" ( só considera "text" e "password" )
			for (var i=ind; i < document.forms[0].elements.length;i++ )
				if(document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password") { // Só limpa campo "text"
					document.forms[0].elements[i].value="";
					break;
				}
		else // Limpa todos os elementos "text" e "password"
			for ( var i=0; i < document.forms[0].elements.length; i++)
				if ( document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password")
					document.forms[0].elements[i].value="";
	}
	
	// Verificar qual navegador
	function QualNavegador() {
		var s = navigator.appName
		if(s == "Microsoft Internet Explorer") return "IE";
		else if ( s == "Netscape" ) return "NE";
		else return "";
	}
	
	// Verificar qual a versão do navegador
	function QualVersao() {
		var s = navigator.appVersion;
		if ( QualNavegador() == "IE" ) {
			var i = s.search("MSIE");
			s=s.substring(i+5);
			i=s.search(".");
			return parseInt(s.substring(0,i+1));
		}
		else if ( QualNavegador() == "NE" )	return parseInt(s.substring(0,1));
		else return 0;
	}
	
	// Colocar o foco em determinado campo
	function SetarFoco(ind) {
		InicializarIndices();
		if ( isNaN(ind) && document.forms[0].elements[ind].type!="hidden" )
			document.forms[0].elements[ind].focus();
		else
			for (;ind<document.forms[0].elements.length;ind++)
				if (document.forms[0].elements[ind].type!="hidden")
					break;
			if (ind<=document.forms[0].elements.length)
				document.forms[0].elements[ind].focus();
		}
	// Setar o evento
	function SetarEvento(ctrl, Tam, Tipo, AutoSkip) { // Filtra navegadores conhecidos
		var s = QualNavegador();
		if (s.length==0) return;
		if (s=="IE" && QualVersao()>6) return;
		if (s=="NE" && QualVersao()>4) return;
		if (ctrl.onkeypress==null) {
			if (AutoSkip==null) AutoSkip=true;
			if (Tipo!=null)	Tipo.toUpperCase();
			ctrl.Tam=Tam;
			ctrl.Tipo=Tipo;
			ctrl.AutoSkip=true;
			ctrl.Saltar=false;
			InicializarIndices();
			ctrl.onkeypress=ValidarTecla;
			if (QualNavegador()=="IE" && QualVersao()>=5) ctrl.onkeyup=SaltarCampo;
		}
	}
	
	function SaltarCampo(ctrl) {
		if (ctrl==null)	ctrl=this;
		if ( ctrl.AutoSkip && ctrl.Saltar)
			if (ctrl.Saltar) {
				ctrl.Saltar=false;
				if ( ctrl.IndicePosterior != null ) SetarFoco(ctrl.IndicePosterior);
			}
	}
	
	// Fazer o salto de campo
	function ValidarTecla(evnt) {
		var tk;
	    var c;
		// Recebe a tela pressionada
		tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
	    c=String.fromCharCode(tk);
		c=c.toUpperCase();
		// Só aceita teclas alfanuméricas. Não aceita teclas de controle
	    if(tk<32) return true;
		if (tk>127)	return false;
	
		switch (this.Tipo) {
		case "D":
			if (c<"0" || c>"9") {
	       		return false;
	       	}
			break;
		case "N":
			if ((c<"0" || c>"9") && (c!="." && c!=","))
				return false;
			if ((c==",") && ((this.value.search(",")>-1) || (this.value.length==0)))
				return false;
			if ((c==".") && (this.value.length==0))
				return false;
			break;
		case "C":
			if ( c<"A" || c>"Z" ) return false;
			break;
		default:
			break;
		}
		this.Saltar=(this.value.length==this.Tam-1);
		if(((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE")) SaltarCampo(this);
		return true;
	}
	window.defaultStatus="SOS CANADÁ"

function abre_pag(url) {
	window.open(url,'show_process','scrollbars=yes,status=no,width=730,height=403,left=20,top=10,resizable=no');
}

function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus()
}
function se(campo){
	var digits="0123456789"
	var campo_temp 
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)	
	  if (digits.indexOf(campo_temp)==-1){
		    campo.value = campo.value.substring(0,i);
		    break;
	   }
	}
}

function Fotos(nome,total,st,atual,id) {
	xmlHttp=GetXmlHttpObjectFT()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="fotos.php"
	url=url+"?nome="+nome
	url=url+"&total="+total
	url=url+"&st="+st
	url=url+"&atual="+atual
	url=url+"&id="+id
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET",url,true)
	xmlHttp.onreadystatechange=stateChange = function () {
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			document.getElementById(id).innerHTML = xmlHttp.responseText
		}
	}
	xmlHttp.send(null)
}

function GetXmlHttpObjectFT() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function Mascara(e,mask,id) {
        if(window.event) { _TXT = e.keyCode; }
        else if(e.which) { _TXT = e.which; }
        if (_TXT == 13) document.form.submit();
        if(_TXT > 47 && _TXT < 58) {
                var i = document.getElementById(id).value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
                if (texto.substring(0,1) != saida) {
                        document.getElementById(id).value += texto.substring(0,1);
                }
                return true;
        } else {
                if (_TXT != 8) { return false; }
                else { return true; }
        }
}
function validate(){
        var sos_erro="";
        var fc="";
        if (document.form.nome.value=="") {
                var sos_erro=sos_erro+"- Seu Nome;\n";
                if (!fc) {
                        var fc="1";
                        document.form.nome.focus();
                }
        }
        if (document.form.email.value=="" && document.form.fone.value=="") {
                var sos_erro=sos_erro+"- Email ou telefone para contato;\n";
                if (!fc) {
                        var fc="1";
                        document.form.email.focus();
                }
        }
        if (document.form.assunto.value=="") {
                var sos_erro=sos_erro+"- Entre com o assunto;\n";
                if (!fc) {
                        var fc="1";
                        document.form.assunto.focus();
                }
        }
        if (document.form.txt.value=="") {
                var sos_erro=sos_erro+"- Entre com sua mensagem;\n";
                if (!fc) {
                        var fc="1";
                        document.form.txt.focus();
                }
        }
        if (sos_erro=="") return true;
        else {
                alert ("Preencha corretamente o(s) campo(s):\n\n"+sos_erro);
                return false;
        }
}

