function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,d,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) {
  	if ((obj=MM_findObj(args[i]))!=null) {
		v=args[i+2];
		d='';
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		// altera o display do obj
		if (obj) { d=(v=='visible')?'':(v=='hidden')?'none':d; }
		obj.visibility=v;
		obj.display=d;
	}
  }
}

// Faz um fading na imagem
function fade(it, inicio, fim, time) {
	obj = document.getElementById(it);
	//obj.style.width='100%';
	
	//document.getElementById(it).style.filter = 'Alpha(Opacity=50)';
	//document.getElementById(it).style["opacity"] = 0.5;
	if (inicio < fim) {
		inicio += 10;
	} else if (fim < inicio) {
		inicio -= 10;
	} else {
		return;
	}
	
	obj.style["filter"] = "Alpha(opacity="+inicio+")";
	obj.style["opacity"] = inicio/100;
	setTimeout(function() { fade(it, inicio, fim,time); }, time);
}

// Retorna um objeto atraves do id
function $id(id) {
	return document.getElementById(id);
}


/**
 * cria uma string contendo as informacoes de um objeto
 */
function investigarObjeto(objeto, espaco) {
	if (typeof(espaco) == "undefined") {
		espaco = "";
	}
	var texto = "";
	for (prop in objeto) {
		texto += espaco;
		texto += prop + ": ";
		if (typeof(objeto[prop]) == "object") {
			texto += investigarObjeto(objeto[prop], espaco + "  ");
		}
		else {
			texto += objeto[prop];
		}
		texto += "\n";
	}
	return texto;
}

// Substitui uma string por outra
function replaceAll(str, de, para) {
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}

function mostra_dica(poObjeto) {
	var dica = document.getElementById("calendario_legenda");
	var f = getXY(poObjeto);
	dica.style.display = "";
	dica.style.visibility = "visible";
	dica.style.top = f.top + "px"; //(f.top - dica.offsetHeight + poObjeto.offsetWidth) + "px";
	dica.style.left = (f.left + poObjeto.offsetWidth + 4) + "px";
}

function getXY(Obj) {
	for (var sumTop=0,sumLeft=0;Obj!=document.body;sumTop+=Obj.offsetTop,sumLeft+=Obj.offsetLeft, Obj=Obj.offsetParent);
	return {left:sumLeft,top:sumTop}
}

function esconde_dica(poObjeto) {
	var dica = document.getElementById("calendario_legenda");
	dica.style.display = "";
	dica.style.visibility = "hidden";
}

// Valida a busca do site
function valida_busca(poForm) {
	if (poForm.txtFiltro.value.length < 3) {
		alert("O texto deve ter pelo 3 letras para buscar.");
		return false;
	} else {
		poForm.submit();
	}
}


// Grava o texto do editor Html num campo do formulario
function editor(poCampo, pcEditor) {
	var loEditor = document.getElementById(pcEditor);
	if (loEditor.html_mode == false) {
		wp_send_to_html(loEditor)
	}
	poCampo.value = loEditor.html_edit_area.value;
}

// Muda a cor de fundo de um objeto
function MudaCor(poObj, pcCor) {
	poObj.style.background = pcCor;
}

// Insere ou atualiza os itens do carrinho
function carrinho(pnAcao, poFormulario) {
	var lnRetira = 0;
	var f = poFormulario;
	// Verifica se é pra limpar o carrinho
	if (pnAcao == 4) {
		if (!(window.confirm("Deseja limpar os itens deste orçamento?"))) {
			return false;
		}
	}
	
	// Verifica se é pra finalizar a compra
	if (pnAcao == 5) {
		if (!(window.confirm("Deseja finalizar este orçamento?"))) {
			return false;
		}
	}
	
	// Verifica se é pra remover algum produto
	for (var i = 0; i < f.length; i++) {
		if (f[i].name.substring(0, 6) == "txtQtd") {
			if (f[i].value == "") { f[i].value = 0; }
			if (f[i].value == "0") { lnRetira++; }
		}
	}
	if ((lnRetira > 0) && (pnAcao != 4)) {
		if (!(window.confirm("Os itens com quantidade 0 (Zero) serão retirados do orçamento. Deseja continuar?"))) {
			return false;
		}
	}
	
	f.txtOperacao.value = pnAcao;
	f.submit();
}

// Carrega um conteudo dentro de uma camada via Ajax
function CarregaCamada(pcPagina, pcCamada) {
	var req = null;
	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", pcPagina, true);
		req.send(null);
	// Procura por uma versao ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", pcPagina, true);
			req.send();
		}
	}
	
	function processReqChange() {
		if (req.readyState == 4) {
			if ((req.status == 200) && ((req.responseText) != "UNKNOWN")) {
				if (document.getElementById(pcCamada)) {
					document.getElementById(pcCamada).innerHTML = req.responseText;
				}
			} else {
				//alert("Houve um problema ao obter os dados:\n" + req.statusText);
			}
		}
	}
}


// Retorna um objeto padrao JSON via Ajax e executa uma função passada
function ExecutaFuncaoAjax(pcPagina, pcFuncao) {
	var req = null;
	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", pcPagina, true);
		req.send(null);
	// Procura por uma versao ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", pcPagina, true);
			req.send();
		}
	}
	
	mostraCarregando();
	
	function processReqChange() {
		if (req.readyState == 4) {
			if ((req.status == 200) && ((req.responseText) != "UNKNOWN")) {
				//alert(req.responseText);
				//eval('var objJson='+req.responseText+'');
				eval('var objJson = ' + req.responseText + '');
				ocultaCarregando();
				return pcFuncao(objJson);
			} else {
				ocultaCarregando();
				//alert("Houve um problema ao obter os dados:\n" + req.statusText);
			}
		}
	}
}


/**
 * adiciona um item na combo
 * @param object combo
 * @param string texto
 * @param string|int valor
 * @param int posicao
 */
function adicionarOpcaoCombo(combo, texto, valor, posicao) {
	var opcao = new Option(texto, valor);
	
	var outrasOpcoes = [];
	for (var i = posicao; i < combo.length; i++) {
		outrasOpcoes.push(combo[i]);
	}
	
	combo.length = posicao + 1;
	combo[posicao] = opcao;
	
	for (var j = 0, k = posicao + 1; j < outrasOpcoes.length; j++, k++) {
		combo[k] = outrasOpcoes[j];
	}
}



// Mostra uma mensagem de carregando
function mostraCarregando(pcMensagem) {
	if ((pcMensagem == undefined) || (pcMensagem == 'undefined') || (pcMensagem == "")) {
		pcMensagem = "Carregando...";
	}
	if (($id("div_carregando") == 'null') || ($id("div_carregando") == null)) {
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','div_carregando');
		objOverlay.className = 'mensagem_carregando';
		objOverlay.style.display = 'block';
		objOverlay.innerHTML = pcMensagem;
		//objOverlay.onclick = function() { myLightbox.end(); return false; }
		objBody.appendChild(objOverlay);
	} else {
		$id("div_carregando").style.display = 'block';
	}
	mudaAlinhamentoMensagem();
}

// Ocultar uma mensagem de carregando
function ocultaCarregando() {
	if (($id("div_carregando") != 'null') && ($id("div_carregando") != null)) {
		$id("div_carregando").style.display = 'none';
	}
}

// Alinha a mensagem no rodape
function mudaAlinhamentoMensagem() {
	// Browser detection
	var dom = document.getElementById ? true:false;
	var nn4 = document.layers ? true:false;
	var ie4 = document.all ? true:false;
	
	if ($id("div_carregando").style.display == 'block') {
		if (nn4) {
			$id("div_carregando").left = "0px";
			$id("div_carregando").top = (window.innerHeight + window.pageYOffset - 20) + "px";
		} else {
			if (!document.documentElement) {
				scrollY = document.body.scrollTop;
				tamanhoY = document.body.clientHeight;
	        } else {
				scrollY = document.documentElement.scrollTop;
				tamanhoY = document.documentElement.clientHeight;
			}
			$id("div_carregando").style.left = "0px";
			$id("div_carregando").style.top = (tamanhoY + scrollY - 20) + "px";
		}
		setTimeout("mudaAlinhamentoMensagem()", 100);
	}
}

// Pega a altura da tela
function altura_tela() {
	var altura = 0;
	if ((document.documentElement) && (document.documentElement.clientWidth)) {
		altura = document.documentElement.clientHeight;
	} else {
		if ((document.body) && (document.body.clientWidth)) {
			altura = document.body.clientHeight;
		}
	}
	return altura;
}



// Valida o login do colunista
function valida_login_colunista(poForm) {
	var f = poForm;
	if (f.txtEmail.value == "") {
		alert("Informe seu email.");
		f.txtEmail.focus();
		return false;
	} else {
		if (ValidaEmail(f.txtEmail) == false) {
			return false;
		}
	}
	if (f.txtSenha.value == "") {
		if (!(window.confirm("A senha está em branco. Deseja continuar?"))) {
			f.txtSenha.focus();
			return false;
		}
	}
	
	f.txtOperacao.value = 2;
	f.submit();
	return true;
}


// Valida o login do internauta sem o campo CEP
function valida_login(poForm) {
	var f = poForm;
	if (f.txtNome) {
		if ((f.txtOperacao.value == 1) && ((f.txtNome.value == "") || (f.txtNome.value == "Seu Nome"))) {
			alert("Informe seu nome.");
			f.txtNome.focus();
			return false;
		}
	}
	if ((f.txtEmail.value == "") || (f.txtEmail.value == "Seu E-mail")) {
		alert("Digite seu email.");
		f.txtEmail.focus();
		return false;
	} else {
		if (ValidaEmail(f.txtEmail) == false) {
			return false;
		}
	}
	if (f.txtSenha) {
		if ((f.txtOperacao.value == 2) && ((f.txtSenha.value == "") || (f.txtSenha.value == "Sua Senha"))) {
			if (!(window.confirm("Você não informou uma senha. Deseja continuar?"))) {
				f.txtSenha.focus();
				return false;
			} else {
				f.txtSenha.value = "";
			}
		}
	}
	f.submit();
	return true;
}

// Valida o login do internauta no padrao E-commerce Suporty
function valida_login_cep(poForm, pnResumido) {
	var f = poForm;
	if (f.txtEmail.value == "") {
		alert("Digite seu email");
		f.txtEmail.focus();
		return false;
	} else {
		if (ValidaEmail(f.txtEmail) == false) {
			return false;
		}
	}
	// Se for o login resumido verifica somente a senha
	if (pnResumido == 1) {
		if (f.txtSenha.value == "") {
			if (!(window.confirm("Você não informou uma senha. Deseja continuar?"))) {
				alert("Digite sua senha");
				f.txtSenha.focus();
				return false;
			}
		}
		f.txtOperacao.value = 2;
	} else {
	// Senao verifica se é cadastro ou login
		if (f.txtOperacao[0].checked) {
			if (f.txtCep1.value.length < 6) {
				alert("O CEP informado parece não estar correto");
				f.txtCep1.focus();
				return false;
			}
			if (f.txtCep2.value.length < 3) {
				alert("O CEP informado parece não estar correto");
				f.txtCep2.focus();
				return false;
			}
			f.txtCep.value = f.txtCep1.value + "-" + f.txtCep2.value;
		} else {
			if (f.txtSenha.value == "") {
				if (!(window.confirm("Você não informou uma senha. Deseja continuar?"))) {
					alert("Digite sua senha");
					f.txtSenha.focus();
					return false;
				}
			}
		}
	}
	f.submit();
	f.reset();
	return true;
}

function valida_newsletter(pnAcao, poFormulario) {
	var f = poFormulario;
	f.txtOperacao.value = pnAcao;
	if (f.txtNome) {
		if ((f.txtNome.value == "") || (f.txtNome.value == "Seu Nome")) {
			alert("Digite seu nome para cadastrar.");
			f.txtNome.focus();
			return false;
		}
	}
	if ((f.txtEmail.value == "") || (f.txtEmail.value == "Seu E-mail")) {
		alert("O Email é obrigatório.");
		f.txtEmail.focus();
		return false;
	}
	else {
		if (ValidaEmail(f.txtEmail) == false) {
			return false;
		}
	}
	f.submit();
	f.reset();
}

// Verifica a quantidade de dias em fereveiro
function DiasInFevereiro (pnAno) {
    return (  ((pnAno % 4 == 0) && ( (!(pnAno % 100 == 0)) || (pnAno % 400 == 0) ) ) ? 29 : 28 );
}


// retira caracteres invalidos da string
function limparString(valor, validos) {
	var result = "";
	var aux;
	for (var i = 0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i + 1));
		if (aux >= 0) {
			result += aux;
		}
	}
	return result;
}

// Formata número tipo moeda usando o evento onKeyDown
function FormataMoeda(campo, tammax, teclapres, decimal, formataMilhar) {
	var tecla = teclapres.keyCode;
	vr = limparString(campo.value, "0123456789");
	tam = vr.length;
	dec = decimal;
	
	// Libera pra digitar numeros (48-57)
	// numeros do teclado numerico (96-105)
	// End (35) Home (36) Setas (37-40)
	// backspace (8)
	if (!( ((tecla >= 48) && (tecla <= 57)) || ((tecla >= 96) && (tecla <= 105)) || ((tecla >= 35) && (tecla <= 40)) || (tecla == 8) || (tecla == 46) )) {
		//alert(tecla);
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			teclapres.returnValue = false;
		} else if (browser == "Netscape") {
			teclapres.preventDefault();
			return false;
		} else {
			return false;
		}
	    //if (strtext != "") { 
	        //campo.value = ;
	    //}
	}
	
	// Verifica o delete (46)
	if (tecla == 46) {
		campo.value = "";
		return false;
	}
	
	if ( (tam < tammax) && (tecla != 8) ) {
		tam = vr.length + 1;
	}
	if ((tecla == 8) || (tecla == 46)) {
		tam = tam - 1;
	}
	
	if ( (tecla == 8) || ((tecla >= 48) && (tecla <= 57)) || ((tecla >= 96) && (tecla <= 105)) ) {
		if (tam <= dec) {
			campo.value = vr;
		}
		if ((tam > dec)) {
			campo.value = vr.substr(0, tam - dec) + "," + vr.substr(tam - dec, tam);
		}
	}
}

// Validar Data
function ValidaData(field) {
	if (field.value == "") {
		return true;
	}
	var hoje = new Date();
	var anoAtual = hoje.getFullYear();
	var barras = field.value.split("/");
	if (barras.length == 3) {
		var dia = barras[0];
		var mes = barras[1];
		var ano = barras[2];
		var resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4));
		if (!resultado) {
			alert("Formato de data inválido. Ex.: (dd/mm/aaaa)");
			field.focus();
			field.select();
			return false;
		}
		if (ano.length != 4) {
			alert("O ano deve ter 4 digitos.");
			field.focus();
			field.select();
			return false;
		}
		//if (ano < anoAtual) {
		//	alert("O ano não pode ser menor que o ano atual.");
		//	field.focus();
		//	field.select();
		//	return false;
		//}
		dias = new Array(13);
		dias[1] = 31;
		dias[2] = DiasInFevereiro(ano);   // deve ser verificado o caso de anos bissextos
		dias[3] = 31;
		dias[4] = 30;
		dias[5] = 31;
		dias[6] = 30;
		dias[7] = 31;
		dias[8] = 31;
		dias[9] = 30;
		dias[10] = 31;
		dias[11] = 30;
		dias[12] = 31;
		if (dia > dias[mes]) {
			alert("Dia inválido.");
			field.focus();
			field.select();
			return false;
		}
	} else {
		alert("Formato de data inválido. Ex.: (dd/mm/aaaa)");
		field.focus();
		field.select();
		return false;
	}
}

// Valida hora e minuto
function ValidaHora(field) {
	if (field.value == "") {
		return true;
	}
	if (field.value.length != 5) {
		alert("Formato de hora inválido. Ex.: (hh:mm)");
		field.focus();
		field.select();
		return false;
	}
	var barras = field.value.split(":");
	if (barras.length == 2) {
		var hora = barras[0];
		var minuto = barras[1];
		var resultado = (!isNaN(hora) && (hora >= 0) && (hora < 24)) && (!isNaN(minuto) && (minuto >= 0) && (minuto < 60));
		if (!resultado) {
			alert("Formato de hora inválido. Ex.: (hh:mm)");
			field.focus();
			field.select();
			return false;
		}
	}
	else {
		alert("Formato da hora inválido. Ex.: (hh:mm)");
		field.focus();
		field.select();
		return false;
	}
}

// Validar tecla nos campos de Email e usuario
function ValidaTeclaEmail() {
	//letras maiúsculas
	if ( (window.event.keyCode >= 65) && (window.event.keyCode <= 90) ) {
		// tranforma letras maiúsculas em minúsculas
		window.event.keyCode = window.event.keyCode + 32;
		return true;
	}
	else {
		// letras minusculas, numeros, hifen, ponto, arroba, underline
		if ( ((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
				|| ((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
				|| (window.event.keyCode == 45)
				|| (window.event.keyCode == 46)
				|| (window.event.keyCode == 64)
				|| (window.event.keyCode == 95) ) {
					return(true);
		}
		else {
			window.event.keyCode = 0;
			return false;
		}
	}
}

// Valida as teclas somente números
function ValidaNumero() {
	if (! ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) ) {
		window.event.keyCode = 0;
		return false;
	}
}

// Valida as teclas para numeros e virgula
function ValidaReal(poObj) {
	if (!( ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 44) )) {
		window.event.keyCode = 0;
		return false;
	} else {
		if (window.event.keyCode == 44) {
			if (poObj.value.length <= 0) {
				window.event.keyCode = 0;
			}
			if (poObj.value.indexOf(",") > 0) {
				window.event.keyCode = 0;
			}
		}
		
		if ((poObj.value.indexOf(",") > 0) && (poObj.value.length - (poObj.value.indexOf(",") + 1) >= 2)) {
			window.event.keyCode = 0;
		}
	}
}

// Valida as teclas para data e hora ( numeros : / )
function ValidaTeclaData() {
	if (!( ((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 58) || (window.event.keyCode == 47) )) {
		window.event.keyCode = 0;
		return false;
	}
}

// Valida o CEP
function ValidaCEP(field) {
	var lcValor = new String(field.value); 
	if (lcValor.length == 0) {
		return true;
	}
	// Último Caracter Digitado
	var lcCaracter_Digitado = lcValor.substring(lcValor.length - 1, 10);
	
	// Verifica se o usuário entrou com um caracter válido
	if ( !(lcCaracter_Digitado.charCodeAt() >=48 && lcCaracter_Digitado.charCodeAt() <= 57) ) {
		field.value = lcValor.substring(0, lcValor.length - 1);
		alert("Caracter inválido!");
		field.focus();
	}
	if (lcValor.length < 5) {
		if (lcCaracter_Digitado == "/") {
			// Remove caracter
			field.value = lcValor.substring(0, lcValor.length - 1);
			field.value = "";
			field.focus();
		}
	}
	if (lcValor.length == 5) {
		// Adiciona caracter
		field.value = poObjeto.value + "-";
		field.focus();
	}
	if (lcValor.length > 9) {
		if (lcCaracter_Digitado == "/") {
			// Remove caracter
			field.value = lcValor.substring(0, lcValor.length - 1);
			field.value = "";
			field.focus();
		}
	}
	return true;
}

// Valida CPF e CGC
function ValidaCPF(field) {
	var i = 0, k = 0; i = 0, j = 0, soma = 0, mt = 0;
	var cpf = '', cgc = '', digito = '', digitoc = '', temp = '', dg = '';
	if (field.value == '') {
 		return false;
 	}
 	else {
 		cpf = field.value;
 	}
	if ( (field.value == "00000000000") || (field.value == "11111111111") || (field.value == "22222222222") ||
	     (field.value == "33333333333") || (field.value == "44444444444") || (field.value == "55555555555") ||
		 (field.value == "66666666666") || (field.value == "77777777777") || (field.value == "88888888888") ||
		 (field.value == "99999999999") || ((field.value.length != 11) && (field.value.length != 14)) ) {
		alert("CPF inválido!");
		field.value = '';
		field.focus();
		return false;
	}
	if (((cpf.length > 13) && (cpf.length < 19)) && (cpf.substring(3,4) !='.')) {
		if (cpf.length == 18) {
			temp = cpf.substring(0,2) + cpf.substring(3,6) + cpf.substring(7,10) + cpf.substring(11,15) + cpf.substring(16,18);
		}
		if (cpf.length == 16) {
			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(14,16);
		}
		if (cpf.length == 15 && cpf.substring(12,13) == '-') {
			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(13,15);
		}
		if (cpf.length == 15 && cpf.substring(8,9) == '/') {
			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(13,15);
		}
		if (cpf.length == 14) {
			temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(12,14);
		}
		cgc = temp.substring(0,12);
		digito = temp.substring(12,14);
		mult = '543298765432';
		for (j = 1; j <= 2; j++) {
			soma = 0;
			for (i = 0; i <= 11; i++) {
				k = i + 1;
				soma += parseInt((cgc.substring(i,k)) * (mult.substring(i,k)));
			}
			if (j == 2) {
				soma = soma + (2 * digitoc);
			}
			digitoc = ((soma * 10) % 11);
			if (digitoc == 10) {
				digitoc = 0;
			}
			dg += digitoc;
			mult = '654329876543';
		}
		if (dg != digito) {
			alert('O CGC informado não é válido!');
			field.value = '';
			field.focus();
			return false;
		}
		else {
			field.value=temp.substring(0,2)+'.'+temp.substring(2,5)+'.'+temp.substring(5,8)+'/'+temp.substring(8,12)+'-'+temp.substring(12,14);
			return true;
		}
	}
	else {
		if (cpf.length < 11) {
			alert( 'Tamanho do campo CPF/CGC inválido. Verifique.');
			field.value = '';
			field.focus();
			return false;
		}
		if (cpf.length == 11) {
			temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(9,11);
		}
		if (cpf.length == 12) {
			temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(10,12);
		}
		if (cpf.length == 14) {
			temp = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,15);
		}
		cpf = temp.substring(0,9);
		digito = temp.substring(9,11);
		for (j = 1; j <= 2; j++) {
			soma = 0;
			mt = 2;
			for (i = 8 + j; i >= 1; i--) {
				soma += parseInt(cpf.charAt(i-1),10) * mt;
				mt++;
			}
			dg = 11 - (soma % 11);
			if (dg > 9) { dg = 0 };
			cpf += dg;
		}
		if (digito != cpf.substring(9,11)) {
			alert('O CPF informado não é válido!');
			field.value = '';
			field.focus();
			return false;
		}
		else {
			field.value = cpf.substring(0,3) + '.' + cpf.substring(3,6) + '.' + cpf.substring(6,9) + '-' + cpf.substring(9,11);
			return true;
		}
	} // fim if (cpf.length < 15)
	return true;
}

// Verifica o email
function ValidaEmail(field) {
	var mail='';
	if (field.value == '') { return false; }
	else { mail = field; }
	
	if (mail.value == "") {
		alert("Informe seu e-mail.");
		mail.focus();
		mail.select();
		return false;
	}
	else {
		prim = mail.value.indexOf("@")
		if (prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("zipmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
		if (mail.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			mail.focus();
			mail.select();
			return false;
		}
	}
	return true;
}