<!--
function Formata_Telefone(objeto,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = objeto.value;
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( " ", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8) {
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ) {
		tam = tam - 1 ;
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
		if ( tam <= 4 ) { 
	 		objeto.value = vr ;
		}
	 	if ( (tam > 4) && (tam <= 8) ) {
	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 10) ) {
			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
		}
	}		
}

function Validar_Email(email)
{
	if(email.length < 6) {
		return false;
	}
	var x = 0;
	for (var c=0;c<email.length;c++) {
		if (email.substring(c,c+1) == '@') {
			x = c;
		}
	}
	var y = 0;
	if (x > 0) {
		for (c=x;c<email.length;c++) {
			if (email.substring(c,c+1)=='.') {
				y = c;
				var valida = 1;
			}
		}
		if (y > 0) {
			var dominio = '';
			for (c=x;c<y;c++) {
				dominio = dominio + email.substring(1,c);
			}
		}
	}
	else {
		return false;
	}					
	if (y <= x+2){
		return false;
	}				
	if (valida == 1){
		return true;
	}
}

function Validar_Contato()
{
	if (document.form.nome.value=="") {
		document.form.nome.focus();
		alert("O nome é um campo obrigatório!");
		return;
	}
	if (document.form.email.value=="") {
		document.form.email.focus();
		alert("O e-mail é um campo obrigatório!");
		return;
	}
	else {
		if (!Validar_Email(document.form.email.value)) {
			document.form.email.focus();
			alert("E-mail inválido!");
			return;
		}
	}
	if (document.form.cidade.value=="") {
		document.form.cidade.focus();
		alert("A cidade é um campo obrigatório!");
		return;
	}
	if (document.form.estado.value=="") {
		document.form.estado.focus();
		alert("O estado é um campo obrigatório!");
		return;
	}
	if (document.form.telefone.value=="") {
		document.form.telefone.focus();
		alert("O telefone é um campo obrigatório!");
		return;
	}
	if (document.form.mensagem.value=="") {
		document.form.mensagem.focus();
		alert("A mensagem é um campo obrigatório!");
		return;
	}
	document.form.submit();
}
//-->

function Compara_Data()
{
	datai =  document.form.dt_chegada.value;
	datai = datai.replace("/","");
	datai = datai.replace("/","");
	dataf =  document.form.dt_saida.value;
	dataf = dataf.replace("/","");
	dataf = dataf.replace("/","");
	
	diai =  datai.substring(0,2);
	mesi =  datai.substring(4,2);
	anoi =  datai.substring(8,4);
	
	diaf =  dataf.substring(0,2);
	mesf =  dataf.substring(4,2);
	anof =  dataf.substring(8,4);
	
	
	datai = anoi + "" + mesi + "" + diai;
	dataf = anof + "" + mesf + "" + diaf;

	if (datai == dataf) {
		return 0;
	}
	else if (datai < dataf) {
		return 1;
	}
	else {
		return -1;
	}
}

function Limpa(S)
{
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0) {
			temp = temp + digito;
		}
	}
	return temp;
}

function Inverte(S)
{
	var temp = "";
	for (var i=0; i<S.length; i++) {
		temp = S.charAt(i) + temp;
	}
    return temp;
}

function Resto(S)
{
	var invertido = Inverte(Limpa(S));
	var soma = 0;
	for (var i=0; i<invertido.length; i++) {
		soma = soma + (i+2) * eval(invertido.charAt(i));
	}
	soma *= 10;
	return ((soma % 11) % 10);
}

function Validar_CPF()
{
	if ((document.form.cpf.value == "000.000.000-00") || (document.form.cpf.value == "111.111.111-11") || (document.form.cpf.value == "222.222.222-22") || (document.form.cpf.value == "444.444.444-44") || (document.form.cpf.value == "555.555.555-55") || (document.form.cpf.value == "666.666.666-66") || (document.form.cpf.value == "777.777.777-77") || (document.form.cpf.value == "888.888.888-88") || (document.form.cpf.value == "999.999.999-99")) {
		return (false);
	}
	var result = "";
	var OK = false;
	var temp = Limpa(document.form.cpf.value);
	if (temp.length>10) {
		var work = temp.substring(0,(temp.length)-2);
		var resto = Resto(work);
		OK = (resto == eval(temp.charAt((temp.length)-2)));
		if (OK){
			work = work + resto;
			resto = Resto(work);
			OK = (resto == eval(temp.charAt((temp.length)-1)));
		}
	}
	if (OK){
		return (true);
	}
	else 
	{
		return (false);
	}
}

function Validar_Email(email)
{
	if(email.length < 6) {
		return false;
	}
	var x = 0;
	for (var c=0;c<email.length;c++) {
		if (email.substring(c,c+1) == '@') {
			x = c;
		}
	}
	var y = 0;
	if (x > 0) {
		for (c=x;c<email.length;c++) {
			if (email.substring(c,c+1)=='.') {
				y = c;
				var valida = 1;
			}
		}
		if (y > 0) {
			var dominio = '';
			for (c=x;c<y;c++) {
				dominio = dominio + email.substring(1,c);
			}
		}
	}
	else {
		return false;
	}					
	if (y <= x+2){
		return false;
	}				
	if (valida == 1){
		return true;
	}
}

function Validar_Numero(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
}

function Mascarar_CEP(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '-';
		}
	}
}

function Testar_Cnpj(cnpj,g)
{
	var vercnpj = 0;
	var ind = 2;
	var tam;
	for(f=g;f>0;f--) {
		vercnpj += parseInt(cnpj.charAt(f-1))*ind;
		if(ind>8) {
			ind = 2;
		}
		else {
			ind++;
		}
	}
	vercnpj %= 11;
	if(vercnpj == 0 || vercnpj == 1) {
		vercnpj = 0;
	}
	else {
		vercnpj = 11 - vercnpj;
	}
	if(vercnpj != parseInt(cnpj.charAt(g))) {
		return(0);
	}
	else {
		return(1);
	}
}

function Validar_CNPJ()
{
	cnpj = Limpa(document.form.cnpj.value);
	if(cnpj == 0) {
		return (false);
	}
	else {
		g = cnpj.length-2;
		if(Testar_Cnpj(cnpj,g) == 1) {
			g = cnpj.length-1;
			if(Testar_Cnpj(cnpj,g) == 1) {	
				return (true);
			}
			else {
				return (false);
			}
		}
		else {
			return (false);
		}
	}
}

function Mascarar_CNPJ(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 6 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 10 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
		if (campo.value.length == 15 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function Mascarar_CPF(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 3 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 7 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 11 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function Mascarar_Data(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
	}
}

function Mascarar_Telefone(objeto,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = objeto.value;
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( " ", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8) {
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ) {
		tam = tam - 1 ;
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
		if ( tam <= 4 ) { 
	 		objeto.value = vr ;
		}
	 	if ( (tam > 4) && (tam <= 8) ) {
	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 10) ) {
			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
		}
	}		
}

function Getbox(parent)
{
	if (typeof(parent) == "undefined") {
		parent = 0;
	}
	this.top = 0;
	this.left = 0;
	this.width = screen.width;
	this.height = screen.height;
	if (parent == 2) {
		this.top = window.screenTop;
		this.left = window.screenLeft;
		this.width = document.body.offsetWidth;
		this.height = document.body.offsetHeight;
	}
	else if (parent == 1) {
		this.width = screen.availWidth;
		this.height = screen.availHeight;
	}
	else if(parent == 0) {
		this.width = screen.width;
		this.height = screen.height;
	}
	else {
		this.top = parent.screenTop;
		this.left = parent.screenLeft;
		this.width = parent.document.body.offsetWidth;
		this.height = parent.document.body.offsetHeight;
	}
}

POP_win = 2;
POP_client = 1;
POP_tot = 0;

function PopUp(url,width,height,halign,valign,parent)
{
	var top = 0;
	var left = 0;
	box = new Getbox(parent);
	switch(halign) {
		case "":
		case "left":
		left = 0;
		break;
		case "right":
		left = box.width - width;
		break;
		case "center":
		left = (box.width - width) / 2;
		break;
		default:
		if (typeof(halign) == "string") {
			if (halign.search(/%/g) != "-1") {
				left = (box.width - width) * parseInt(halign) / 100;
			}
			else {
				left = parseInt(halign);
			}
		}
		else if (typeof(halign) == "number") {
			left = halign;
		}
	}
	switch(valign){
		case "":
		case "top":
		top = 0;
		break;
		case "bottom":
		top = box.height - height;
		break;
		case "center":
		top = (box.height - height) / 2;
		break;
		default:
		if (typeof(valign) == "string") {
			if (valign.search(/%/g) != "-1") {
				top = (box.height - height) * parseInt(valign) / 100;
			}
			else {
				top = parseInt(valign);
			}
		}
		else if (typeof(valign) == "number"){
			top = valign;
		}
	}
	top += box.top;
	left += box.left;
	window.open(url,"","width="+width+",height="+height+",top="+top+",left="+left);
	return;
}

function PopUp_Barra(url,width,height,halign,valign,parent,scrollbars,resizable)
{
	var top = 0;
	var left = 0;
	box = new Getbox(parent);
	switch(halign) {
		case "":
		case "left":
		left = 0;
		break;
		case "right":
		left = box.width - width;
		break;
		case "center":
		left = (box.width - width) / 2;
		break;
		default:
		if (typeof(halign) == "string") {
			if (halign.search(/%/g) != "-1") {
				left = (box.width - width) * parseInt(halign) / 100;
			}
			else {
				left = parseInt(halign);
			}
		}
		else if (typeof(halign) == "number") {
			left = halign;
		}
	}
	switch(valign){
		case "":
		case "top":
		top = 0;
		break;
		case "bottom":
		top = box.height - height;
		break;
		case "center":
		top = (box.height - height) / 2;
		break;
		default:
		if (typeof(valign) == "string") {
			if (valign.search(/%/g) != "-1") {
				top = (box.height - height) * parseInt(valign) / 100;
			}
			else {
				top = parseInt(valign);
			}
		}
		else if (typeof(valign) == "number"){
			top = valign;
		}
	}
	top += box.top;
	left += box.left;
	
	var menubar = 0;
	var locationbar = 0;
	var directories = 0;
	var statusbar = 0;
	var toolbar = 0;
	
	windowprops = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;

	windowprops += (menubar ? ",menubars" : "") +
	(scrollbars ? ",scrollbars" : "") +
	(locationbar ? ",location" : "") +
	(directories ? ",directories" : "") +
	(resizable ? ",resizable" : "") +
	(statusbar ? ",status" : "") +
	(toolbar ? ",toolbar" : "");
	
	window.open(url,"",windowprops);
	return;
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
        found = true;
    else
        index++;
        return found;
    }

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;
}
//Fim da Função AutoTab

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true; //Esse está certo
    }
}

sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
} else {
    sCod += sValue.charAt(nCount);
    nCount++;
}
i++;
}

objForm[strField].value = sCod;
if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
    return true;
}
} else {
    return true;
}
}