//===========================================================================
// FUNÇÕES GENÉRICAS
//===========================================================================
function validaVazio(obj, msgErro) {
    if (obj.value == "") {
	   alert(msgErro);
	   obj.focus();
	   return true;
    }
    return false;
}
function valida_mail(valor) {
	   prim = valor.indexOf("@")
	   if(prim < 1) return false;
	   if(valor.indexOf("@",prim + 1) != -1) return false;
	   if(valor.indexOf(".") < 1) return false;
	   if(valor.indexOf("zipmeil.com") > 0) return false;
	   if(valor.indexOf("hotmeil.com") > 0) return false;
	   if(valor.indexOf(".@") > 0) return false;
	   if(valor.indexOf("@.") > 0) return false;
	   if(valor.indexOf(".com.br.") > 0) return false;
	   if(valor.indexOf("/") > 0) return false;
	   if(valor.indexOf("[") > 0) return false;
	   if(valor.indexOf("]") > 0) return false;
	   if(valor.indexOf("(") > 0) return false;
	   if(valor.indexOf(")") > 0) return false;
	   if(valor.indexOf("..") > 0) return false;
	   if(valor.indexOf(",") > 0) return false;
	   return true;
}

function formata(campo, mask, evt) {

    if(document.all) { // Internet Explorer
	  key = evt.keyCode; }
	  else{ // Nestcape
           key = evt.which;
    }

    teclasPermitidas = Array(0, 8, 13);
    for (i=0; i < teclasPermitidas.length; i++) {
		if (key == teclasPermitidas[i]) return true;
    }

    string = campo.value;
    i	   = string.length;

    if (i < mask.length) {
    	if (mask.charAt(i) == '§') {

    return (key > 47 && key < 58);

    } else {

    if (mask.charAt(i) == '!') {  return true;  }

    for (c = i; c < mask.length; c++) {

    if (mask.charAt(c) != '§' && mask.charAt(c) != '!')

    campo.value = campo.value + mask.charAt(c);

    else if (mask.charAt(c) == '!'){

    return true;

    } else {

    return (key > 47 && key < 58);

    }

    }

    }

    } else return false;

}

//===========================================================================

//===========================================================================
// FORMULÁRIO DE CONTATO
//===========================================================================
function validaContato(form) {

	var erro 	  = false;
	var cont_erro = 0;

	if (form.nome.value == "") {
		cont_erro++;
		msg  = "<li>" + cont_erro + "- Campo nome Ã© <strong>obrigatÃ“rio</strong></li>";
		erro = true;
	}

	if (form.sobrenome.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo sobrenome Ã© <strong>obrigatÃ“rio</strong></li>";
		erro = true;
	}

	if (form.email.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo email Ã© <strong>obrigatÃ“rio</strong></li>";
		erro = true;
	}else if (!valida_mail(form.email.value)) {
		  cont_erro++;
		  msg += "<li>" + cont_erro + "- Campo email parece ser <strong>invÃ¡lido</strong></li>";
		  erro = true;
	}
	if (form.mensagem.value == "") {
		cont_erro++;
		msg  += "<li>" + cont_erro + "- Campo mensagem Ã© <strong>obrigatÃ“rio</strong></li>";
		erro = true;
	}

	if (erro) {
		document.getElementById("erro").style.display = "block";
		document.getElementById("ulErro").innerHTML   = msg;
		return false;
	} else {
		/*url = "login.php";
		tipo = "checaUsuario";
		tipo_envio = "POST";
		form_envio = form;
		loadXMLDoc(url);*/

		return true;
	}
}
//===========================================================================


var tbl0 = '';
var tbl1 = '';
var tbl2 = '';
var tbl3 = '';
var tbl4 = '';
var tbl5 = '';
var tbl6 = '';

var qtd0 = 1;
var qtd1 = 1;
var qtd2 = 1;
var qtd3 = 1;
var qtd4 = 1;
var qtd5 = 1;
var qtd6 = 1;

function checkProduto(objeto)
{
	var nome  = objeto.name;
	var check = objeto.checked;
	var valor = objeto.value;

	var table = '<table width="750" border="0" align="left" bordercolor="#660000" bgcolor="#F9F2C3">' +
				'	<tr>' +
				'		<td width="30%" bgcolor="#F9F2C3"><strong>Produto</strong></td>' +
				'		<td width="5%"  bgcolor="#F9F2C3"><strong>Qtde</strong></td>' +
				'		<td width="18%" bgcolor="#F9F2C3"><strong>Pre&ccedil;o Unit&aacute;rio</strong></td>' +
				'		<td width="20%" bgcolor="#F9F2C3"><strong>Nome Promo&ccedil;&atilde;o </strong></td>' +	
				'		<td width="17%" bgcolor="#F9F2C3"><strong>Sub-Total </strong></td>' +			
				'		<td width="10%" bgcolor="#F9F2C3"><strong>&nbsp;</strong></td>' +
				'	</tr>';

				if ( check && valor == '0' && nome == 'check0' )
				{
					tbl0  = '	<tr>' +
							'		<td align="left" width="50%">DVD Vinho de Rosas</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade0" name="quantidade0" onKeyUp="calculaParcial(39.60, this.value, 0);" onFocus="this.value = \'\'; calculaParcial(39.60, this.value, 0);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">39,60' +
							'			<input type="hidden" id="valor00" name="valor00" value="39.60">' +
							'			<input type="hidden" id="descontoCalculado1" name="descontoCalculado1" value="NAO">' +							
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO1" name="CLI_DSC_CODIGO1" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO1\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(1);" name="calcular_desconto1" value="Ok" style="cursor: pointer;">' +
							'		</td>'+
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal00"></div>' +
							'			<input type="hidden" id="subtotal00" name="subtotal00" value="39.60">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check0.checked = false; checkProduto(document.frmLoja.check0)" name="remover0" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '0' && nome == 'check0' )
				{
					tbl0 = '';
					qtd0 = '1';
					document.getElementById('quantidade0').value = '1';
					document.getElementById('valor00').value     = '39.60';
					document.getElementById('subtotal00').value     = '39.60';

				}

				if ( check && valor == '1' && nome == 'check1' )
				{
					tbl1  = '	<tr>' +
							'		<td align="left"   width="50%">DVD + Kit Vinho de Rosas</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade1" name="quantidade1" onKeyUp="calculaParcial(99.90, this.value, 1);" onFocus="this.value = \'\'; calculaParcial(99.90, this.value, 1);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">99,90' +
							'			<input type="hidden" id="valor01" name="valor01" value="99.90">' +
							'			<input type="hidden" id="descontoCalculado2" name="descontoCalculado2" value="NAO">' +							
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO2" name="CLI_DSC_CODIGO2" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO2\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(2);" name="calcular_desconto2" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal01">99,90</div>' +
							'			<input type="hidden" id="subtotal01" name="subtotal01" value="99.90">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check1.checked = false; checkProduto(document.frmLoja.check1)" name="remover1" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '1' && nome == 'check1' )
				{
					tbl1 = '';
					qtd1 = '1';
					document.getElementById('quantidade1').value = '1';
					document.getElementById('valor01').value     = '99.90';
					document.getElementById('subtotal01').value     = '99.90';
				}

				if ( check && valor == '2' && nome == 'check2' )
				{
					tbl2  = '	<tr>' +
							'		<td align="left"   width="50%">DVD + Kit Vinho de Rosas</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade2" name="quantidade2" onKeyUp="calculaParcial(99.90, this.value, 2);" onFocus="this.value = \'\'; calculaParcial(99.90, this.value, 2);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">99,90' +
							'			<input type="hidden" id="valor02" name="valor02" value="99.90">' +
							'			<input type="hidden" id="descontoCalculado3" name="descontoCalculado3" value="NAO">' +							
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO3" name="CLI_DSC_CODIGO3" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO3\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(3);" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal02">99,90</div>' +
							'			<input type="hidden" id="subtotal02" name="subtotal02" value="99.90">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check2.checked = false; checkProduto(document.frmLoja.check2)" name="remover2" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '2' && nome == 'check2' )
				{
					tbl2 = '';
					qtd2 = '1';
					document.getElementById('quantidade2').value = '1';
					document.getElementById('valor02').value     = '99.90';
					document.getElementById('subtotal02').value     = '99.90';
				}

				if ( check && valor == '3' && nome == 'check3' )
				{
					tbl3  = '	<tr>' +
							'		<td align="left"   width="50%">Livro "Vinho de Rosas: Iconografia e Costumes"?</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade3" name="quantidade3" onKeyUp="calculaParcial(24.30, this.value, 3);" onFocus="this.value = \'\'; calculaParcial(24.30, this.value, 3);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">24,30' +
							'			<input type="hidden" id="valor03" name="valor03" value="24.30">' +
							'			<input type="hidden" id="descontoCalculado4" name="descontoCalculado4" value="NAO">' +														
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO4" name="CLI_DSC_CODIGO4" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO4\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(4);" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal03">24,30</div>' +
							'			<input type="hidden" id="subtotal03" name="subtotal03" value="24.30">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check3.checked = false; checkProduto(document.frmLoja.check3)" name="remover3" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '3' && nome == 'check3' )
				{
					tbl3 = '';
					qtd3 = '1';
					document.getElementById('quantidade3').value = '1';
					document.getElementById('valor03').value     = '24.30';
					document.getElementById('subtotal03').value     = '24.30';
				}

				if ( check && valor == '4' && nome == 'check4' )
				{
					tbl4  = '	<tr>' +
							'		<td align="left"   width="50%">Libreto Ã³pera Tiradentes</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade4" name="quantidade4" onKeyUp="calculaParcial(9, this.value, 4);" onFocus="this.value = \'\'; calculaParcial(9, this.value, 4);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">9,00' +
							'			<input type="hidden" id="valor04" name="valor04" value="9">' +
							'			<input type="hidden" id="descontoCalculado5" name="descontoCalculado5" value="NAO">' +														
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO5" name="CLI_DSC_CODIGO5" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO5\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(5);" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal04">9,00</div>' +
							'			<input type="hidden" id="subtotal04" name="subtotal04" value="9">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check4.checked = false; checkProduto(document.frmLoja.check4)" name="remover4" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '4' && nome == 'check4' )
				{
					tbl4 = '';
					qtd4 = '1';
					document.getElementById('quantidade4').value = '1';
					document.getElementById('valor04').value     = '9';
					document.getElementById('subtotal04').value  = '9';
				}

				if ( check && valor == '5' && nome == 'check5' )
				{
					tbl5  = '	<tr>' +
							'		<td align="left"   width="50%">CD Sons de Corda</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade5" name="quantidade5" onKeyUp="calculaParcial(24.30, this.value, 5);" onFocus="this.value = \'\'; calculaParcial(24.30, this.value, 5);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">24,30' +
							'			<input type="hidden" id="valor05" name="valor05" value="24.30">' +
							'			<input type="hidden" id="descontoCalculado6" name="descontoCalculado6" value="NAO">' +														
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO6" name="CLI_DSC_CODIGO6" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO6\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(6);" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal05">24,30</div>' +
							'			<input type="hidden" id="subtotal05" name="subtotal05" value="24.30">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check5.checked = false; checkProduto(document.frmLoja.check5)" name="remover5" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '5' && nome == 'check5' )
				{
					tbl5 = '';
					qtd5 = '1';
					document.getElementById('quantidade5').value = '1';
					document.getElementById('valor05').value     = '24.30';
					document.getElementById('subtotal05').value  = '24.30';
				}
				

				if ( check && valor == '6' && nome == 'check6' )
				{
					tbl6  = '	<tr>' +
							'		<td align="left"   width="50%">Revista Arte & Conhecimento</td>' +
							'		<td align="center" width="5%"><input type="text" id="quantidade6" name="quantidade6" onKeyUp="calculaParcial(19.90, this.value, 6);" onFocus="this.value = \'\'; calculaParcial(19.90, this.value, 6);" onBlur="if (this.value == \'\') this.value = \'1\'; calculaTotal();" value="1" size="5" maxlength="3" style="width: 40px; font-size: 10px; font-family: verdana"></td>' +
							'		<td align="right"  width="18%">19,90' +
							'			<input type="hidden" id="valor06" name="valor06" value="19.90">' +
							'			<input type="hidden" id="descontoCalculado7" name="descontoCalculado7" value="NAO">' +														
							'		</td>' +
							'		<td aling="center" width="20%">'+
							'			<input type="text" id="CLI_DSC_CODIGO7" name="CLI_DSC_CODIGO7" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO6\').value = this.value; style="width: 70px; font-size: 10px; font-family: verdana">&nbsp;' +
							'			<input type="button" onclick="calculaDesconto(6);" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							'		</td>'+							
							'		<td align="right"  width="17%">' +
							'			<div id="divSubTotal06">19,90</div>' +
							'			<input type="hidden" id="subtotal06" name="subtotal06" value="19.90">' +
							'		</td>' +
							'		<td align="center" width="10%"><input type="button" onclick="document.frmLoja.check6.checked = false; checkProduto(document.frmLoja.check6)" name="remover6" value="Remover" style="cursor: pointer;"></td>' +
							'	</tr>';
				}
				else if ( !check && valor == '6' && nome == 'check6' )
				{
					tbl6 = '';
					qtd6 = '1';
					document.getElementById('quantidade6').value = '1';
					document.getElementById('valor06').value     = '19.90';
					document.getElementById('subtotal06').value  = '19.90';
				}


				table +=
							(tbl0 ? tbl0 : '') +
							(tbl1 ? tbl1 : '') +
							(tbl2 ? tbl2 : '') +
							(tbl3 ? tbl3 : '') +
							(tbl4 ? tbl4 : '') +
							(tbl5 ? tbl5 : '') +
							(tbl6 ? tbl6 : '');

				table += 	'	<tr>' +
							'		<td colspan="6"> &nbsp; </td>' +
							'	</tr>' +
							'	<tr>' +
							'		<td align="right" colspan="6">' +
							'			<span class="textb">Digite o CEP do endere&ccedil;o de entrega para calcular o valor do servi&ccedil;o de entrega:</span> &nbsp; &nbsp;' +
							'			<input type="text" id="CLI_DSC_CEPFRETE" name="CLI_DSC_CEPFRETE" maxlength="9" onkeyup="mascaraCep(this, event); document.getElementById(\'CLI_DSC_CEP\').value = this.value; document.getElementById(\'CLI_DSC_CEP_vis\').value = this.value" onBlur="document.getElementById(\'CLI_DSC_CEP_vis\').disabled = true; document.getElementById(\'CLI_DSC_CEP\').value = this.value; document.getElementById(\'CLI_DSC_CEP_vis\').value = this.value" style="width: 90px; font-size: 10px; font-family: verdana"> &nbsp; &nbsp;' +
							'			<input type="button" onclick="calculaFrete();" name="calcular" value="Ok" style="cursor: pointer;">' +
							'		</td>' +
							'	</tr>' +
							//INICIO DA CHAMADA PARA CALCULO DE DESCONTO
							//'	<tr>' +
							//'		<td align="right" colspan="5">' +
							//'			<span class="textb">Digite o c&oacute;digo promocional:</span> &nbsp; &nbsp;' +
							//'			<input type="text" id="CLI_DSC_CODIGO" name="CLI_DSC_CODIGO" maxlength="20" document.getElementById(\'CLI_DSC_CODIGO\').value = this.value; style="width: 90px; font-size: 10px; font-family: verdana"> &nbsp; &nbsp;' +
							//'			<input type="button" onclick="calculaDesconto();" name="calcular_desconto" value="Ok" style="cursor: pointer;">' +
							//'		</td>' +
							//'	</tr>' +
							//FIM DA CHAMADA PARA CALCULO DE DESCONTO
							'	<tr>' +
							'		<td align="right" colspan="6"><div id="divTotal"></div></td>' +
							'		<input type="hidden" id="total" name="total" value="0">' +
							'	</tr>' +
							'	<tr>' +
							'		<td align="right" colspan="6"><div id="divFrete"></div></td>' +
							'		<input type="hidden" id="valorfrete" name="valorfrete" value="0">' +
							'	</tr>' +
							//INICIO MOSTRA DESCONTO
							'	<tr>' +
							'		<td align="right" colspan="6"><div id="divDesconto"></div></td>' +
							'		<input type="hidden" id="desconto" name="desconto" value="0">' +
							'	</tr>' +
							//FIM MOSTRA DESCONTO
							'	<tr>' +
							'		<td align="right" colspan="6"><div id="divTotalFrete"></div></td>' +
							'		<input type="hidden" id="totalfrete" name="totalfrete" value="0">' +
							'	</tr>' +
							'</table>';

	document.getElementById('formulario').innerHTML = table;
	atualizaQtde();
}

function atualizaQtde()
{
	if ( document.getElementById('quantidade0') )
		document.getElementById('quantidade0').value = qtd0;

	if ( document.getElementById('quantidade1') )
		document.getElementById('quantidade1').value = qtd1;

	if ( document.getElementById('quantidade2') )
		document.getElementById('quantidade2').value = qtd2;

	if ( document.getElementById('quantidade3') )
		document.getElementById('quantidade3').value = qtd3;

	if ( document.getElementById('quantidade4') )
		document.getElementById('quantidade4').value = qtd4;

	if ( document.getElementById('quantidade5') )
		document.getElementById('quantidade5').value = qtd5;

	if ( document.getElementById('quantidade6') )
		document.getElementById('quantidade6').value = qtd6;

	calculaTotal();
}

function calculaParcial(valor, qtde, numberDiv)
{
	var valorTotal = '';
	var valorSubTotal;

	if (qtde == '') qtde = 1;

	valorSubTotal = Number(valor * qtde);

	document.getElementById('divSubTotal0' + numberDiv).innerHTML = formata_numero(valorSubTotal, 2);
	document.getElementById('subtotal0' + numberDiv).value        = valorSubTotal;
}

function calculaTotal()
{
	var total   = 0;
	var valor00 = 0;
	var valor01 = 0;
	var valor02 = 0;
	var valor03 = 0;
	var valor04 = 0;
	var valor05 = 0;
	var valor06 = 0;	
	var aux = 0;

	if (document.getElementById('subtotal00'))
	{
		qtd0    = document.getElementById('quantidade0').value;
		valor00 = String(Number(document.getElementById('valor00').value) * Number(qtd0));
		document.getElementById('divSubTotal00').innerHTML = formata_numero(valor00, 2);
		calculaFrete(aux=1);
	}

	if (document.getElementById('subtotal01'))
	{
		qtd1    = document.getElementById('quantidade1').value;
		valor01 = String(Number(document.getElementById('valor01').value) * Number(qtd1));
		document.getElementById('divSubTotal01').innerHTML = formata_numero(valor01, 2);
		calculaFrete(aux=1);
	}

	if (document.getElementById('subtotal02'))
	{
		qtd2    = document.getElementById('quantidade2').value;
		valor02 = String(Number(document.getElementById('valor02').value) * Number(qtd2));
		document.getElementById('divSubTotal02').innerHTML = formata_numero(valor02, 2);
		calculaFrete(aux=1);
	}

	if (document.getElementById('subtotal03'))
	{
		qtd3    = document.getElementById('quantidade3').value;
		valor03 = String(Number(document.getElementById('valor03').value) * Number(qtd3));
		document.getElementById('divSubTotal03').innerHTML = formata_numero(valor03, 2);
		calculaFrete(aux=1);
	}

	if (document.getElementById('subtotal04'))
	{
		qtd4    = document.getElementById('quantidade4').value;
		valor04 = String(Number(document.getElementById('valor04').value) * Number(qtd4));
		document.getElementById('divSubTotal04').innerHTML = formata_numero(valor04, 2);
		calculaFrete(aux=1);
	}

	if (document.getElementById('subtotal05'))
	{
		qtd5    = document.getElementById('quantidade5').value;
		valor05 = String(Number(document.getElementById('valor05').value) * Number(qtd5));
		document.getElementById('divSubTotal05').innerHTML = formata_numero(valor05, 2);
		calculaFrete(aux=1);
	}
	
	if (document.getElementById('subtotal06'))
	{
		qtd6    = document.getElementById('quantidade6').value;
		valor06 = String(Number(document.getElementById('valor06').value) * Number(qtd6));
		document.getElementById('divSubTotal06').innerHTML = formata_numero(valor06, 2);
		calculaFrete(aux=1);
	}

	total = String(Number(valor00) + Number(valor01) + Number(valor02) + Number(valor03) + Number(valor04) + Number(valor05) + Number(valor06));

	document.getElementById('total').value        = total;
	document.getElementById('divTotal').innerHTML = '<strong>Total &nbsp; R$ </strong> &nbsp; ' + formata_numero(total, 2);
	//document.getElementById('divDesconto').innertHTML = '';
}

function calculaFrete(aux)
{
//alert('passou calcula frete');
	var totalpeso = 0;
	var peso0 = 0;
	var peso1 = 0;
	var peso2 = 0;
	var peso3 = 0;
	var peso4 = 0;
	var peso5 = 0;
	var peso6 = 0;	
	var peso        = '2';
	var cepDestino  = document.getElementById('CLI_DSC_CEPFRETE').value;
	
	if (document.getElementById('quantidade0'))
	{
		qtd0    = document.getElementById('quantidade0').value;
		peso0 = Number(peso) * Number(qtd0);
	}

	if (document.getElementById('quantidade1'))
	{
		qtd1    = document.getElementById('quantidade1').value;
		peso1 = Number(peso) * Number(qtd1);
	}

	if (document.getElementById('quantidade2'))
	{
		qtd2    = document.getElementById('quantidade2').value;
		peso2 = Number(peso) * Number(qtd2);
	}

	if (document.getElementById('quantidade3'))
	{
		qtd3    = document.getElementById('quantidade3').value;
		peso3 = Number(peso) * Number(qtd3);
	}

	if (document.getElementById('quantidade4'))
	{
		qtd4    = document.getElementById('quantidade4').value;
		peso4 = Number(peso) * Number(qtd4);
	}
	
	if (document.getElementById('quantidade5'))
	{
		qtd5    = document.getElementById('quantidade5').value;
		peso5 = Number(peso) * Number(qtd5);
	}

	if (document.getElementById('quantidade6'))
	{
		qtd6    = document.getElementById('quantidade6').value;
		peso6 = Number(peso) * Number(qtd6);
	}


	totalpeso = String(Number(peso0) + Number(peso1) + Number(peso2) + Number(peso3) + Number(peso4) + Number(peso5) + Number(peso6));

	
	if (cepDestino == '' && aux == 0)
	{
		alert('Por favor, informe o CEP');
		document.getElementById('CLI_DSC_CEPFRETE').focus();
		return false;
	}
	else if (cepDestino)
	{
		funcRetorno = "mostraValorFrete()";
		loadXMLDoc('calculafrete.php?cep=' + cepDestino + '&peso=' + totalpeso);
	}
}

function mostraValorFrete()
{

	if (req.responseText != "")
	{
		var valFrete   = req.responseText;
		var total      = document.getElementById('total').value;
		var totalFrete = Number(valFrete) + Number(total);
		

		document.getElementById('divFrete').innerHTML      = '<strong>Frete &nbsp; R$ </strong> &nbsp; ' + formata_numero(valFrete, 2);
		document.getElementById('divTotalFrete').innerHTML = '<strong>Total + Frete &nbsp; R$ </strong> &nbsp; ' + formata_numero(totalFrete, 2);
		//document.getElementById('divDesconto').innerHTML = '';
		
		document.getElementById('valorfrete').value = valFrete;
		document.getElementById('totalfrete').value = totalFrete;
	}
}


//CALCULO DO DESCONTO DO PROUTO 1
function valorDescontoProduto()
{
	if(reqDesc.responseText != "")
	{
		var total_geral    = 0;
		var total_produto1 = 0;
		var total_produto2 = 0;
		var total_produto3 = 0;
		var total_produto4 = 0;
		var total_produto5 = 0;
		var total_produto6 = 0;
		var total_produto7 = 0;		
		var aux = 0;
		var descon = 0;
		
		var retornoCalculoDesconto = reqDesc.responseText;
		
		retornoSplit = retornoCalculoDesconto.split('|');
		desconto = retornoSplit[0];
		PRD_SEQ = retornoSplit[1];		
		
		//alert(desconto);
		//alert(PRD_SEQ);	
		
		if(PRD_SEQ == 1){
			var total_produto = document.getElementById('subtotal00').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto1 = Number(total_produto) - Number(descontoGerado);
			document.getElementById('descontoCalculado1').value = "SIM";			
			document.getElementById('divSubTotal00').innerHTML = formata_numero(total_produto1,2);
			document.getElementById('valor00').value = total_produto1;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto DVD Vinho de Rosas';
			
		}
		if(PRD_SEQ == 2){		
			var total_produto = document.getElementById('subtotal01').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);			
			total_produto2 = Number(total_produto) - Number(descontoGerado);
			
			document.getElementById('descontoCalculado2').value = "SIM";
			document.getElementById('divSubTotal01').innerHTML = formata_numero(total_produto2,2);
			document.getElementById('valor01').value = total_produto2;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto DVD + Kit Vinho de Rosas';
			
		}

		if(PRD_SEQ == 3){		
			var total_produto = document.getElementById('subtotal02').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto3 = Number(total_produto) - Number(descontoGerado);

			document.getElementById('descontoCalculado3').value = "SIM";			
			document.getElementById('divSubTotal02').innerHTML = formata_numero(total_produto3,2);
			document.getElementById('valor00').innerHTML = formata_numero(total_produto3,2);
			document.getElementById('valor02').value = total_produto3;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto DVD + Kit Vinho de Rosas';

}
		if(PRD_SEQ == 4){		
			var total_produto = document.getElementById('subtotal03').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto4 = Number(total_produto) - Number(descontoGerado);
			
			document.getElementById('descontoCalculado4').value = "SIM";
			document.getElementById('divSubTotal03').innerHTML = formata_numero(total_produto4,2);
			document.getElementById('valor03').value = total_produto4;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto Livro "Vinho de Rosas: Iconografia e Costumes"?';
			
			
		}		
		if(PRD_SEQ == 5){		
			var total_produto = document.getElementById('subtotal04').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto5 = Number(total_produto) - Number(descontoGerado);

			document.getElementById('descontoCalculado5').value = "SIM";			
			document.getElementById('divSubTotal04').innerHTML = formata_numero(total_produto5,2);
			document.getElementById('valor04').value = total_produto5;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto Libreto ópera Tiradentes';
			
			
		}
		if(PRD_SEQ == 6){		
			var total_produto = document.getElementById('subtotal05').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto6 = Number(total_produto) - Number(descontoGerado);
			
			document.getElementById('descontoCalculado6').value = "SIM";
			document.getElementById('divSubTotal05').innerHTML = formata_numero(total_produto6,2);
			document.getElementById('valor05').value = total_produto6;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto CD Sons de Corda';
			
		}		
		if(PRD_SEQ == 7){		
			var total_produto = document.getElementById('subtotal06').value;
			var total = document.getElementById('total').value;
			descon = Number(desconto) / 100;
			descontoGerado = total_produto * Number(descon);
			total_produto6 = Number(total_produto) - Number(descontoGerado);
			
			document.getElementById('descontoCalculado7').value = "SIM";
			document.getElementById('divSubTotal06').innerHTML = formata_numero(total_produto7,2);
			document.getElementById('valor06').value = total_produto7;
			document.getElementById('divDesconto').innerHTML = '<strong>Desconto de '+desconto+'% para o produto Revista Arte & Conhecimento';
			
			
		}		
		
		calculaTotal();

	
	}
}

function calculaDesconto(PRD_SEQ)
{
	if(document.getElementById('CLI_DSC_CODIGO1')){
		if(document.getElementById('CLI_DSC_CODIGO1').value != '' && document.getElementById('descontoCalculado1').value == "NAO"){
			//alert('passou 1');	
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO1').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO2')){
		if(document.getElementById('CLI_DSC_CODIGO2').value != '' && document.getElementById('descontoCalculado2').value == "NAO"){
			//alert('passou 2');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO2').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO3')){
		if(document.getElementById('CLI_DSC_CODIGO3').value != '' && document.getElementById('descontoCalculado3').value == "NAO"){
			//alert('passou 3');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO3').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO4')){
		if(document.getElementById('CLI_DSC_CODIGO4').value != '' && document.getElementById('descontoCalculado4').value == "NAO"){
			//alert('passou 4');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO4').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO5')){
		if(document.getElementById('CLI_DSC_CODIGO5').value != '' && document.getElementById('descontoCalculado5').value == "NAO"){
			//alert('passou 5');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO5').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO6')){
		if(document.getElementById('CLI_DSC_CODIGO6').value != '' && document.getElementById('descontoCalculado6').value == "NAO"){
			//alert('passou 6');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO6').value;
		}
	}
	if(document.getElementById('CLI_DSC_CODIGO7')){
		if(document.getElementById('CLI_DSC_CODIGO7').value != '' && document.getElementById('descontoCalculado7').value == "NAO"){
			//alert('passou 6');		
			var calcDesconto = document.getElementById('CLI_DSC_CODIGO7').value;
		}
	}

var PRD_SEQ;
	
	//alert(PRD_SEQ);	
	//alert(calcDesconto);
	
	funcRetornoDesc = "valorDescontoProduto()";
	loadXMLDocDesc('calculaDesconto.php?calcDesconto='+calcDesconto+'&PRD_SEQ='+PRD_SEQ);
}




function validaLoja()
{
	if ( document.getElementById('totalfrete') )
	{
		if ( document.getElementById('totalfrete').value == '0' )
		{
			alert('Necessário calcular o frete antes de finalizar a compra!');
			return false;
		}
		else
		{
			if (document.getElementById('CLI_DSC_CPFCNPJ').value == '')
			{
				alert('Digite o CPF ou CNPJ');
				document.getElementById('CLI_DSC_CPFCNPJ').focus();
				return false;
			}
            else if (document.getElementById('CLI_DSC_RESPONS').value == '')
			{
				alert('Digite o nome do responsável');
				document.getElementById('CLI_DSC_RESPONS').focus();
				return false;
			}

			else if (document.getElementById('CLI_DSC_TELEFON').value == '')
			{
				alert('Digite o telefone de contato');
				document.getElementById('CLI_DSC_TELEFON').focus();
				return false;
			}

			else if (document.getElementById('CLI_DSC_EMAIL').value == '')
			{
				alert('Digite o e-mail');
				document.getElementById('CLI_DSC_EMAIL').focus();
				return false;
			}
			else if (document.getElementById('CLI_DSC_ENDEREC').value == '')
			{
				alert('Digite o logradouro');
				document.getElementById('CLI_DSC_ENDEREC').focus();
				return false;
			}
			else if (document.getElementById('CLI_DSC_NUMERO').value == '')
			{
				alert('Digite o número');
				document.getElementById('CLI_DSC_NUMERO').focus();
				return false;
			}
			else if (document.getElementById('CLI_DSC_BAIRRO').value == '')
			{
				alert('Digite o bairro');
				document.getElementById('CLI_DSC_BAIRRO').focus();
				return false;
			}
			else if (document.getElementById('CLI_DSC_CIDADE').value == '')
			{
				alert('Digite a cidade');
				document.getElementById('CLI_DSC_CIDADE').focus();
				return false;
			}
			else if (document.getElementById('CLI_DSC_ESTADO').value == '')
			{
				alert('Digite o estado');
				document.getElementById('CLI_DSC_ESTADO').focus();
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		alert('Necessário esconher algum produto!');
		return false;
	}
}

function formata_numero(numero, decimais) {

	if(isNaN(numero)) { return '0,00'; }
	if(numero == '') { return '0,00'; }

	var result = Math.round( numero * Math.pow( 10 , decimais ) ) / Math.pow( 10 , decimais );

	var num = new String(result);
	var num2 = num.split('.');

	if (num2.length == 1) {
		return num2[0]+',00';
	}
	else if (num2[1].length == 1) {
		return num2[0]+','+num2[1]+'0';
	}
	else {
		var resultado = String(result);
		resultado = resultado.replace('.', ',');

		return resultado;
	}
}

function mudaTipo(valor)
{
	if (valor == 'F')
	{
		document.getElementById('divCPFCNPJ').innerHTML = '<input type="text" id="CLI_DSC_CPFCNPJ" name="CLI_DSC_CPFCNPJ" maxlength="14" onkeypress="mascara(this, event,\'000.000.000-00\', 1)" size="20" class="campo-contato">';
	}
	else if (valor == 'J')
	{
		document.getElementById('divCPFCNPJ').innerHTML = '<input type="text" id="CLI_DSC_CPFCNPJ" name="CLI_DSC_CPFCNPJ" maxlength="18" onkeypress="mascara(this, event,\'00.000.000/0000-00\', 1)" size="20" class="campo-contato">';
	}
}

function mascara_telefone(obj, evento) {
     var BACKSPACE   = 8;
     var DEL         = 46;
     var FRENTE      = 39;
     var TRAS        = 37;
     var TAB         = 9;
     var SHIFT       = 16;

     var tecla       = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);

     if (tecla == BACKSPACE || tecla == DEL || tecla == FRENTE || tecla == TRAS || tecla == TAB || tecla == SHIFT)
         return true;

     if ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105)){
         obj.value = obj.value.substring(0, obj.value.length - 1);
         evento.returnValue = false;
         return false;
     }

     // sem nada
     var sn = '';
     sn = obj.value.replace('(','');
     sn = sn.replace(')','');
     sn = sn.replace('-','');

     if(sn.length >= 1 && sn.length <= 2)
             obj.value = '(' + sn;
     if(sn.length >= 3 && sn.length <= 6)
             obj.value = '(' + sn.substring(0,2) + ')' + sn.substring(2,sn.length);
     if(sn.length >= 7 && sn.length <= 10)
             obj.value = '(' + sn.substring(0,2) + ')' + sn.substring(2,6) + '-' + sn.substring(6,sn.length);
     if(sn.length >10)
             obj.value = '(' + sn.substring(0,2) + ')' + sn.substring(2,6) + '-' + sn.substring(6,10);
}

function mascaraCep(obj, evento) {
     var BACKSPACE   = 8;
     var DEL         = 46;
     var FRENTE      = 39;
     var TRAS        = 37;
     var TAB         = 9;
     var SHIFT       = 16;

     var tecla       = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);

     if (tecla == BACKSPACE || tecla == DEL || tecla == FRENTE || tecla == TRAS || tecla == TAB || tecla == SHIFT)
         return true;

     if ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105)){
         obj.value = obj.value.substring(0, obj.value.length - 1);
         evento.returnValue = false;
         return false;
     }

     if(obj.value.length == 5)
         obj.value = obj.value + '-';
}

/* CONJUNTO DE FUNÇÕES PARA VALIDAR CPF E CNPJ */
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|| Script language: JavaScript
|| Funcao para validacao de mascara pre-determinada
||
|| Ex:
|| <input type="text" onkeypress="mascara(this, evento,'000.000.000.000:000/00-00',1)">
||
|| this		= recebe o campo
|| formato	= formato da mascara
|| conteudo	= 1 - Só Numeros; 2 - Só Letras; 3 - Numeros e Letras; 4 - Alpha numerico(Qualquer caracter)
*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function mascara(campo, evento, formato, conteudo) {
    var i, j;
 	var auxPonto	= formato;
 	var auxBarra	= formato;
 	var auxHifen	= formato;
	var auxDblPonto = formato;
	var auxAbrePar	= formato;
	var auxFechaPar	= formato;
	var auxVirgula	= formato;
 	var tamanho     = formato.length;
 	var posPonto	= new Array(tamanho);
 	var posBarra	= new Array(tamanho);
 	var posHifen	= new Array(tamanho);
	var posDblPonto	= new Array(tamanho);
	var posAbrePar	= new Array(tamanho);
	var posFechaPar	= new Array(tamanho);
	var posVirgula	= new Array(tamanho);
	var keyPress	= evento.keyCode;

    var BACKSPACE   = 8;
    var DEL         = 46;
    var FRENTE      = 39;
    var TRAS        = 37;
    var TAB         = 9;
    var SHIFT       = 16;

    var tecla       = (keyPress ? keyPress: evento.which ? evento.which : evento.charCode);

    if (tecla == BACKSPACE || tecla == DEL || tecla == FRENTE || tecla == TRAS || tecla == TAB || tecla == SHIFT)
        return true;

    if ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105)){
        campo.value = campo.value.substring(0, campo.value.length - 1);
        return false;
    }

	campo.maxLength = tamanho;


	if(formato.length == 14)
	{
        if(campo.value.length == 14)
            isCPF(campo);
	}
    else if(formato.length == 18)
    {
        if(campo.value.length == 18)
            isCNPJ(campo);
    }


	if(keyPress == 8)
        return false;

	switch (conteudo){
		case 1: // Verifica se soh podem ser entrados valores numericos
			if (!(keyPress >= 48 && keyPress <= 57))
				keyPress = 0;
			break;
		case 2: // Somente Letras
			if (!( (keyPress >= 97 && keyPress <= 122) || (keyPress >= 65 && keyPress <= 90) ))
				keyPress = 0;
			break;
		case 3: // Letras e numeros
			if (!( (keyPress >= 48 && keyPress <= 57) || (keyPress >= 97 && keyPress <= 122) || (keyPress >= 65 && keyPress <= 90) ))
				keyPress = 0;
			break;
	}

 // ---------------------------------------- PEGA A FORMATACAO DA MASCARA -----------------------------------
 	for (i=0;i<tamanho;i++){

 		posPonto[i] 	= auxPonto.indexOf('.');
 		posBarra[i] 	= auxBarra.indexOf('/');
 		posHifen[i] 	= auxHifen.indexOf('-');
		posDblPonto[i]	= auxDblPonto.indexOf(':');
		posAbrePar[i]	= auxAbrePar.indexOf('(');
		posFechaPar[i]	= auxFechaPar.indexOf(')');
		posVirgula[i]	= auxVirgula.indexOf(',');

 		auxPonto 	= auxPonto.substring(posPonto[i]+1,tamanho);
 		auxBarra 	= auxBarra.substring(posBarra[i]+1,tamanho);
 		auxHifen	= auxHifen.substring(posHifen[i]+1,tamanho);
		auxDblPonto	= auxDblPonto.substring(posDblPonto[i]+1,tamanho);
		auxAbrePar	= auxAbrePar.substring(posAbrePar[i]+1,tamanho);
		auxFechaPar	= auxFechaPar.substring(posFechaPar[i]+1,tamanho);
		auxVirgula	= auxVirgula.substring(posVirgula[i]+1,tamanho);

 		if (i > 0){
 			posPonto[i]		= posPonto[i] + posPonto[i-1];
 			posBarra[i]		= posBarra[i] + posBarra[i-1];
 			posHifen[i]		= posHifen[i] + posHifen[i-1];
			posDblPonto[i]	= posDblPonto[i] + posDblPonto[i-1];
			posAbrePar[i]	= posAbrePar[i] + posAbrePar[i-1];
			posFechaPar[i]	= posFechaPar[i] + posFechaPar[i-1];
			posVirgula[i]	= posVirgula[i] + posVirgula[i-1];

 			posPonto[i]		= posPonto[i] + 1;
 			posBarra[i]		= posBarra[i] + 1;
 			posHifen[i]		= posHifen[i] + 1;
			posDblPonto[i]	= posDblPonto[i] + 1;
			posAbrePar[i]	= posAbrePar[i] + 1;
			posFechaPar[i]	= posFechaPar[i] + 1;
			posVirgula[i]	= posVirgula[i] + 1;
 		}

	// ---------------------------------------- APLICA A FORMATACAO DA MASCARA -----------------------------------
		tecla = keyPress;
		if (tecla != 8 && tecla != 45 && tecla != 46 && tecla != 47 && tecla != 58){
			if (campo.value.length == posPonto[i]){
				campo.value = campo.value + '.';
				campo.focus();
			}
			if (campo.value.length == posBarra[i]){
				campo.value = campo.value + '/';
				campo.focus();
			}
			if (campo.value.length == posHifen[i]){
				campo.value = campo.value + '-';
				campo.focus();
			}
			if (campo.value.length == posDblPonto[i]){
				campo.value = campo.value + ':';
				campo.focus();
			}
			if (campo.value.length == posAbrePar[i]){
				campo.value = campo.value + '(';
				campo.focus();
			}
			if (campo.value.length == posFechaPar[i]){
				campo.value = campo.value + ')';
				campo.focus();
			}
			if (campo.value.length == posVirgula[i]){
				campo.value = campo.value + ',';
				campo.focus();
			}
 		}
 	}
}

/*////////////////////////////////////////////////////////////////////////
|| Função para checagem de CPF padrao digito 11                         ||
||                                                                      ||
||   language="JavaScript"                                              ||
|| last modified: setember 5, 2001                                      ||
|| use: <input type="text" onblur="isCPF(this)">                        ||
/*////////////////////////////////////////////////////////////////////////

 function isCPF(campo) {
	CPF = campo.value;
	if (CPF == ''){
		return true;
	}else{
		for (i=0;i<CPF.length;i++){
			CPF = CPF.replace('.','');
			CPF = CPF.replace('/','');
			CPF = CPF.replace('-','');
		}
		if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
			CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
			CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
			CPF == "88888888888" || CPF == "99999999999"){
			alert('CPF invÃ¡lido.');
			campo.select();
			campo.value = '';
			return false;
		}
		soma = 0;
		for (i=0; i < 9; i ++)
			soma += parseInt(CPF.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(CPF.charAt(9))){
			alert('CPF invÃ¡lido.');
			campo.select();
			campo.value = '';
			return false;
		}
		soma = 0;
		for (i = 0; i < 10; i ++)
			soma += parseInt(CPF.charAt(i)) * (11 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(CPF.charAt(10))){
			alert('CPF invÃ¡lido.');
			campo.select();
			campo.value = '';
			campo.focus() = '';
			return false;
		}
		return true;
	}
 }

/*////////////////////////////////////////////////////////////////////////
|| Função para checagem de CNPJ padrao digito 11                         ||
||                                                                      ||
||   language="JavaScript"                                              ||
|| last modified: setember 5, 2001                                      ||
|| use: <input type="text" onblur="isCPF(this)">                        ||
/*////////////////////////////////////////////////////////////////////////


function isCNPJ(campo) {
   	var cnpj, i;

   	cnpj = campo.value

   	cnpj = cnpj.replace(".", "");
   	cnpj = cnpj.replace(".", "");
   	cnpj = cnpj.replace("/", "");
   	cnpj = cnpj.replace("-", "");
   	var c  = cnpj.substr(0,12);
   	var dv = cnpj.substr(12,2);

      if (cnpj == "00000000000000")
      {
			alert('CNPJ invÃ¡lido.');
			campo.value = '';
			return false;
      }

      var d1 = 0;
      var ms = "543298765432";

   	for (i = 0; i < 12; i++) {
   		d1 += c.charAt(i)*ms.charAt(i);
   	}
   	d1 = (d1 % 11);
      if (d1 == 0 || d1 == 1) {
         d1 = 0;
      } else {
         d1 = 11 - d1;
      }

      var d1 = 0;
      var ms = "543298765432";

   	for (i = 0; i < 12; i++) {
   		d1 += c.charAt(i)*ms.charAt(i);
   	}
   	d1 = (d1 % 11);
      if (d1 == 0 || d1 == 1) {
         d1 = 0;
      } else {
         d1 = 11 - d1;
      }

      var c = c + d1;

      var d2 = 0;
      var ms = "6543298765432";
   	for (i = 0; i < 13; i++) {
   		d2 += c.charAt(i)*ms.charAt(i);
   	}
   	d2 = (d2 % 11);
      if (d2 == 0 || d2 == 1) {
         d2 = 0;
      } else {
         d2 = 11 - d2;
      }

   	if (dv.charAt(0) != d1 || dv.charAt(1) != d2)
    {
		alert('CNPJ invÃ¡lido.');
		campo.value = '';
		return false;
   	}
      return true;
   }
/* ------------------------------------------- */