	function ValidaFormCC(frm){
		if((frm.f_nom_titular.value.length < 5) || (frm.f_nom_titular.value=='') || (!CheckSpaces(frm.f_nom_titular.value))){
			alert('Atenção! O campo Nome do Titular deve ser preenchido.');
			frm.f_nom_titular.focus();
			return false;
		}
		if(frm.f_cpf_titular.value==''){
			alert('Atenção! O campo CPF Titular deve ser preencido.');
			frm.f_cpf_titular.focus();
			return false;
		}
		if(!valida_CPF(document.getElementById('f_cpf').value)){
			frm.f_cpf_titular.focus();
			return false;
		}
		if(frm.f_banco.value==''){
			alert('Atenção! O campo Banco deve ser preenchido.');
			frm.f_banco.focus();
			return false;
		}
		if((frm.f_cod_agencia.value=='') || (!CheckSpaces(frm.f_cod_agencia.value))){
			alert('Atenção! O campo Agência deve ser preenchido.');
			frm.f_cod_agencia.focus();
			return false;
		}
		if((frm.f_num_conta_corrente.value=='') || (!CheckSpaces(frm.f_num_conta_corrente.value))){
			alert('Atenção! O campo Conta Corrente deve ser preenchido.');
			frm.f_num_conta_corrente.focus();
			return false;
		}
		return true;
	}
	
	function ValidaFormCard(frm){
		if((!frm.f_admcard[0].checked) && (!frm.f_admcard[1].checked) && (!frm.f_admcard[2].checked)){
			alert('Atenção! A administradora de cartão de crédito deve ser selecionada.');
			frm.f_admcard[0].focus();
			return false;
		}
		if(frm.f_num_cartao.value==''){
			alert('Atenção! O campo Número do Cartão deve ser preenchido.');
			frm.f_num_cartao.focus();
			return false;
		}
		if(!ValidaNumCard(frm.f_num_cartao.value)){
			alert("Atenção! O número do Cartão é inválido.");
			f.f_num_cartao.focus();	
			return false;
		}
		if(frm.f_dth_val_cartao.value==''){
			alert('Atenção! O campo Data de Validade do cartão deve ser preenchido.');
			frm.f_dth_val_cartao.focus();
			return false;
		}else{
			if(isCardDate(frm.f_dth_val_cartao.value)==false){
				alert('Atenção! A data digitada é inválida, favor redigitar.');
				frm.f_dth_val_cartao.focus();
				return false;
			}
		}
		if(frm.f_cod_seg_cartao.value==''){
			alert('Atenção! O campo Código de Segurança deve ser preenchido.');
			frm.f_cod_seg_cartao.focus();
			return false;
		}
		if((frm.f_nome_cartao.value.length < 5) || (frm.f_nome_cartao.value=='')){
			alert('Atenção! O campo Nome Impresso no Cartão deve ser preenchido.');
			frm.f_nome_cartao.focus();
			return false;
		}
		if((frm.f_titular_cartao.value.length < 5) || (frm.f_titular_cartao.value=='')){
			alert('Atenção! O campo Nome Titular do Cartão deve ser preenchido.');
			frm.f_titular_cartao.focus()
			return false;
		}
		return true;
	}
	
	function ValidaForm(frm){
		if((!frm.f_tipo_pessoa[0].checked) && (!frm.f_tipo_pessoa[1].checked)){
			alert('Atenção! O campo Tipo Pessoa deve ser selecionado.');
			frm.f_tipo_pessoa[0].focus();
			return false;
		}
		if((frm.f_tipo_pessoa[0].checked==true) && (!valida_CPF(document.getElementById('f_cpf').value))){
			document.getElementById('f_cpf').focus();
			return false;
		}else{
			if((frm.f_tipo_pessoa[1].checked==true) && (!valida_CNPJ(document.getElementById('f_cnpj').value))){
				document.getElementById('f_cnpj').focus();
				return false;
			}
		}
		if(frm.f_tipo_pessoa[1].checked==false){
			if((!frm.f_sexo[0].checked) && (!frm.f_sexo[1].checked)){
				alert('Atenção! O campo Sexo deve ser selecionado.');
				frm.f_sexo[0].focus();
				return false;
			}
			if(frm.f_dth_nascimento.value==''){
				alert('Atenção! O campo Data de Nascimento deve ser preenchido.');
				frm.f_dth_nascimento.focus();
				return false;
			}
			if(!isDate(frm.f_dth_nascimento)){
				frm.f_dth_nascimento.focus();
				return false;
			}
			if(!ValidaDataNasc(frm.f_dth_nascimento)){
				alert('Atenção! Não é permitida a venda a menores de 18 anos.');
				frm.f_dth_nascimento.focus();
				return false;
			}
		}else{
			frm.f_dth_nascimento.value='';
			frm.f_sexo.value='';
		}
		if((frm.f_nom_pessoa.value.length < 5) || (frm.f_nom_pessoa.value=='') || (!CheckSpaces(frm.f_nom_pessoa.value))){;
			alert('Atenção! O campo Nome deve ser preenchido.');
			frm.f_nom_pessoa.focus();
			return false;
		}
		if((frm.f_tel_celular.value=='') && (frm.f_tel_residencial.value=='') && (frm.f_tel_comercial.value=='')){
			alert('Atenção! Ao menos um dos telefones deve ser preenchido.');
			frm.f_ddd_celular.focus();
			return false;
		}
		if((frm.f_tel_celular.value!='') && (frm.f_ddd_celular.value=='')){
			alert('Atenção! O campo DDD Celular deve ser preenchido.');
			frm.f_ddd_celular.focus();
			return false;
		}
		if((frm.f_tel_residencial.value!='') && (frm.f_ddd_residencial.value=='')){
			alert('Atenção! O campo DDD residencial deve ser preenchido.');
			frm.f_ddd_residencial.focus();
			return false;
		}
		if((frm.f_tel_comercial.value!='') && (frm.f_ddd_comercial.value=='')){
			alert('Atenção! O campo DDD Comercial deve ser preenchido.');
			frm.f_ddd_comercial.focus();
			return false;
		}
		if(frm.f_num_cep.value==''){
			alert('Atenção! O campo CEP deve ser preenchido.');
			frm.f_num_cep.focus();
			return false;
		}
		if((frm.f_logradouro.value.length < 5) || (frm.f_logradouro.value=='') || (!CheckSpaces(frm.f_logradouro.value))){
			alert('Atenção! O campo logradouro deve ser preenchido.');
			frm.f_logradouro.focus();
			return false;
		}
		if(frm.f_numero.value==''){
			alert('Atenção! O campo número deve ser preenchido.');
			frm.f_numero.focus();
			return false;
		}
		if((frm.f_municipio.value.length < 5) || (frm.f_municipio.value=='') || (!CheckSpaces(frm.f_municipio.value))){
			alert('Atenção! O campo Município deve ser preenchido.');
			frm.f_municipio.focus();
			return false;
		}
		if(frm.f_uf.value==''){
			alert('Atenção! O campo UF deve ser preenchido.');
			frm.f_uf.focus();
			return false;
		}
		if((!frm.f_forma_pgto[0].checked) && (!frm.f_forma_pgto[1].checked)){
			alert('Atenção! O campo Forma de Pagamento deve ser selecionado.');
			return false;
		}
		if(frm.f_email.value!=''){
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.f_email.value))){ 
				alert("Atenção! O e-mail informado é inválido.");
				frm.f_email.focus();
				return false;
			}
		}
		return true;
	}

	function ValidaDataNasc(obj){
		var vData = obj.value;
		var dt_hj = new Date();
		var datahoje = zero(dt_hj.getDate()) + '/' + zero(dt_hj.getMonth()) + '/' + dt_hj.getFullYear();
		var idade = comparaDatas(datahoje,vData) - 6544;
		if(idade < 0){
			return false;
		}else{
			return true;
		}
	}

	var xml;
	function BuscaCep(valor, host){
		f = document.frmCadastro;
		valor = limpa_string(valor);
		if ((valor != "") && (valor.length == 8)){
				xml = null;
				if (window.XMLHttpRequest) 
					{
						xml = new XMLHttpRequest();
						xml.onreadystatechange = Monta;
						xml.open("GET", "http://"+host+"/cep/ConsultaCep/Consulta_Cep.asp?Cep="+valor+"&Tipo=1", true);
						xml.send(null);	
					} 
				else 
					if (window.ActiveXObject) 
						{
							xml = new ActiveXObject("Microsoft.XMLHTTP");
							xml.onreadystatechange = Monta;
							xml.open("GET", "http://"+host+"/cep/ConsultaCep/Consulta_Cep.asp?Cep="+valor+"&Tipo=1", true);
							xml.send(null);
						}
			}
		else
			{
				f.f_logradouro.value = "";
				f.f_bairro.value = "";
				f.f_municipio.value = "";
				f.f_uf.value = "";
				
				f.f_logradouro.readOnly = false;
				f.f_bairro.readOnly = false;
				f.f_municipio.readOnly = false;
				f.f_uf.readOnly = false;
			}
	}
	function Monta(){	
		f = document.frmCadastro;
		var exibe = document.getElementById('procurandocep');

		if (xml.readyState == 1)
			exibe.style.display = 'block';
			exibe.innerHTML = "<img src='../imgs/refresh.gif' /><font color='red' size='-2'> Procurando Cep. Aguarde...</font>";
		
		if (xml.readyState == 4)
			{
				exibe.innerHTML = "";
				exibe.style.display = 'none';
				
				if (xml.status == 200)
					{
						response = xml.responseText;
						response = unescape(response);
						response = response.replace(/\+/g," ");
						result = response.split("|");
						
						tam_endereco = f.f_logradouro.maxLength;
						tam_bairro = f.f_bairro.maxLength;
						tam_municipio = f.f_municipio.maxLength;
						
						if (result[0] == '0')
							{
								f.f_tipo_logradouro.value = result[1].substring(0,1);

								var logra = result[1].substr(result[1].indexOf(" ")+1 );
								
								if(logra.substr(0,logra.indexOf(","))!=""){
									f.f_logradouro.value = logra.substr(0,logra.indexOf(","));
								}else{
									f.f_logradouro.value = logra;

								}
								
								f.f_bairro.value = result[2].substring(0, tam_bairro);
								f.f_municipio.value = result[3].substring(0, tam_municipio);
								f.f_uf.value = result[4];
								var pref = result[1].substr(result[1].indexOf(",")+1 );
								f.f_prefixo.value = pref;
								
								/*f.f_prefixo.readOnly = true;
								f.f_logradouro.readOnly = true;
								f.f_bairro.readOnly = true;
								f.f_municipio.readOnly = true;
								f.f_uf.readOnly = true;*/
								
								if(f.f_prefixo.value != '') f.f_prefixo.readOnly = true;
								if(f.f_logradouro.value != '') f.f_logradouro.readOnly = true;
							  if(f.f_bairro.value != '') f.f_bairro.readOnly = true;
		  					if(f.f_municipio.value != '') f.f_municipio.readOnly = true;
						    if(f.f_uf.value != '') f.f_uf.readOnly = true;
							}
						else
							{
								f.f_tipo_logradouro.value ="";
								f.f_logradouro.value = "";
								f.f_bairro.value = "";
								f.f_municipio.value = "";
								f.f_uf.value = "";
								
								f.f_logradouro.readOnly = false;
								f.f_bairro.readOnly = false;
								f.f_municipio.readOnly = false;
								f.f_uf.readOnly = false;
								/*if (confirm('Cep não encontrado. Deseja ir para o site dos correios?') == 1)
									{
										window.open('http://www.correios.com.br/servicos/cep/cep_loc_log.cfm');
									}*/
								
							}
					}
				else
					{
						f.f_tipo_logradouro.value="";
						f.f_logradouro.value = "";
						f.f_bairro.value = "";
						f.f_municipio.value = "";
						f.f_uf.value = "";
					}
					
			}
	}
	function BuscaLogin(valor){
		f = document.frmCadastro;
		if ((valor != "") && (valor.length > 0)){
				xml = null;
				if (window.XMLHttpRequest){
						xml = new XMLHttpRequest();
						xml.onreadystatechange = MontaLogin;
						xml.open("GET", "consultaLogin.php?f_login="+valor, true);
						xml.send(null);
					}
				else{ 
					if (window.ActiveXObject) 
						{
							xml = new ActiveXObject("Microsoft.XMLHTTP");
							xml.onreadystatechange = MontaLogin;
							xml.open("GET", "consultaLogin.php?f_login="+valor, true);
							xml.send();
						}
			   }
		}else{
				f.f_login.value = valor;
			}
	}
	function MontaLogin(){
		f = document.frmCadastro;
		var exibe = document.getElementById('validandologin');
		
		if (xml.readyState == 1){
			exibe.style.display = 'block';
			exibe.innerHTML = "<img src='imgs/refresh.gif' /><font color='red' size='-2'> Validando Login. Aguarde...</font>";
		}
		if (xml.readyState == 4){
			exibe.innerHTML = "";
			exibe.style.display = 'none';
			if (xml.status == 200){
					response = xml.responseText;
					if(response.length > 70){
						response = 	"<tr><td class='t3'></br>  Login já existe, por favor, escolha outro ou aproveite as sugestões abaixo:</br></br></td></tr>" + response;
						document.getElementById('validandologin').innerHTML = response;
						document.getElementById('validandologin').style.display = 'block';
						document.frmCadastro.f_login.value = "";
					}
			}else{
				alert('Ocorreu um erro: ' + xml.statusText);
			}
		}
			
	}
/*
a1=new Image(149,21)
a1.src="imgs/b_blarga.png"
a2=new Image(149,21)
a2.src="imgs/b_blarga1.png"

a3=new Image(149,21)
a3.src="imgs/b_dial.png"
a4=new Image(149,21)
a4.src="imgs/b_dial1.png"

a5=new Image(149,21)
a5.src="imgs/b_promo.png"
a6=new Image(149,21)
a6.src="imgs/b_promo1.png"

a7=new Image(149,21)
a7.src="imgs/b_empresas.png"
a8=new Image(149,21)
a8.src="imgs/b_empresas1.png"

a9=new Image(149,21)
a9.src="imgs/b_conteudo.png"
a10=new Image(149,21)
a10.src="imgs/b_conteudo1.png"

a11=new Image(149,21)
a11.src="imgs/b_servicos.png"
a12=new Image(149,21)
a12.src="imgs/b_servicos1.png"
*/
function filter(imagename,objectsrc){
	if (document.images)
		document.images[imagename].src=eval(objectsrc+".src")
}

function Corrigir(pdestino){
	var f = document.forms[0];
	if(pdestino == 0){
		f.action = "validaForm.php";
	}else{
		f.action = "cadastro.php";
	}
	f.submit();
}


// ======================== CADASTRO ==========================

var vObj;
var menuOn;
var pHeight=0, pWidth=0;
var vHTML_mostraFiltro, vWidth_mostraFiltro, vHTML_FiltroImg;

function isNumberKey(Key)
	{
       var charCode = (Key.which) ? Key.which : event.keyCode
       if (charCode > 47 && charCode < 58 || charCode == 8)
          return true;
       return false;
    }

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {		
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function ParseNumb(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
}

function Verify(CNUMB,CTYPE)
{
  CNUMB=ParseNumb(CNUMB)
  if(CNUMB == 0)
  {
    return(false);
  }
  else
  {
    g=CNUMB.length-2;
    if(TestDigit(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(TestDigit(CNUMB,CTYPE,g))
      {	
        return(true);
      }
      else
      {
        return(false);
      }
    }
    else
    {
      return(false);
    }
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return(false);
  }
  else
  {
    return(true);
  }
}

function limpa_string(S){
 // Deixa so' os digitos do numero
 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 }
 } //for

 return temp
}

function valida_CNPJ(s){
	var i;
	erro = new String;
	s = limpa_string(s);
	if(s.length != 14){
		erro +="ass";
	}
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) {
		erro +="a";
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		erro +="aa";
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){

	}

	if (erro.length > 0){
		alert("Atenção! O número de CNPJ é inválido ou não está preenchido!");
		document.getElementById('f_cnpj').focus();
		return false;
	}

	return true;
}

function valida_CPF(s){
	var i;
	s = limpa_string(s);
	var cpf = s;
	var erro = new String;
	if (cpf.length != 11) erro += "aa \n\n"; 

	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "aaa \n\n";	

	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		  erro += "a"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		alert("Atenção! O número de CPF é inválido ou não está preenchido!");
		document.getElementById('f_cpf').focus();
		return false;
	}
	return true;
}

/*
* Mascara CPF e CNPJ
* Tipo 1 = CPF
* Tipo 2 = CNPJ 
*/
function retornaCPFCNPJFormatado(Campo, tipo){
	var vTipo = tipo;
	var vr = new String(Campo.value);
	vr = limpa_string(vr);
	if(Campo!=""){
		if ((vTipo == 1) && (vr.length == 11)){
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,2);
		} else {
			if ((vTipo == 2) && (vr.length == 14)){
				Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4) + '-' + vr.substr(12,2);
			}
		}
	}
}

function formataDoc(documento){
	
	var vr = new String(documento);
	vr = limpa_string(vr);
	if(documento!=""){
		if (vr.length == 11){
			documento = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,2);
		} else {
			if (vr.length == 14){
				documento = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4) + '-' + vr.substr(12,2);
			}
		}
	}
	return documento;
}

function formatCurrency(num) {	
	num = num.toString().replace('.','');	
	num = num.toString().replace(',','.');	
	num = num.toString().replace(/\$|\,/g,'');	

	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);	
	cents = num%100;		
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '' + num + ',' + cents);

}

function formataCampo(e,src,mask) {
	if(window.event) { _TXT = e.keyCode; }
	else if(e.which) { _TXT = e.which; }
	if(_TXT > 47 && _TXT < 58) {
	 var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
	 if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); }
    	return true; } else { if (_TXT != 8) { return false; }
	 else { return true; }
	}
}

function comparaDatas(p_data1,p_data2){
/* 
//	###	comparaDatas(DATA_FINAL,DATA_INICIAL)
//	###	Objetivo: calcular a diferença em dias das duas datas
*/
	
	mDay = p_data1.substr(0,2);
	mMonth = p_data1.substr(3,2);
	mYear = p_data1.substr(6,4)
	datDate1 = mMonth+'/'+mDay+'/'+mYear;
			
	mDay = p_data2.substr(0,2);
	mMonth = p_data2.substr(3,2);
	mYear = p_data2.substr(6,4)
	datDate2 = mMonth+'/'+mDay+'/'+mYear;

	datDate1= Date.parse(datDate1);
	datDate2= Date.parse(datDate2);
			
	v_dateDiff = Math.round((datDate1-datDate2)/(24*60*60*1000));
	return v_dateDiff;
}

function zero(pValor){
	if(String(pValor).length<2){
		return String('0' + pValor);
	}else{
		return pValor;
	}
}
function sendFocus(origem, destino, tamanho)
	{
		if (tamanho == 0)
			document.getElementById(destino).focus();
		else
			if (origem.value.length == tamanho)
				document.getElementById(destino).focus();
	}
function FormataDataCard(data){
	if(data.value.length==2){
		data.value = data.value + '/';
	}
}
function isCardDate(valor){
	ano = new Date();
	hoje = ano.getFullYear();
	Mes = ano.getMonth() + 1;
	h = String(hoje).substr(2,2);
	m = Number(valor.substr(0,2));
	a = Number(valor.substr(5,2));

	if((isNaN(m))||(isNaN(a))||(m<1)||(m>12)||(a<Number(h))||(a>Number(h)+10))
	    return false;
       else
	    return true;
}

function ValidaNumCard(){
	f = document.frmCcard;
	if(f.f_num_cartao.value!='') {
		if ((f.f_admcard[0].checked && f.f_num_cartao.value.substr(0,1) != "4") || (f.f_admcard[1].checked && (f.f_num_cartao.value.substr(0,1) != "5" && f.f_num_cartao.value.substr(0,1) != "6"))|| (f.f_admcard[2].checked && f.f_num_cartao.value.substr(0,2) != "37")){
			return false;
		}
	}
	return true;
}

function showHide(){
	if(document.getElementById('fisica').checked){
		document.getElementById('cnpj').style.display = "none";
		document.getElementById('cpf').style.display = "block";
	}else{
		document.getElementById('cnpj').style.display= "block";
		document.getElementById('cpf').style.display= "none";
	}
}

var reDigits = /^\d+$/;
function doDigits(campo){
var pStr = campo.value;
	if (!reDigits.test(pStr)) {
		if (pStr != null && pStr != "") {	
			document.getElementById(campo.id).value = "";	
			alert(pStr + " N\u00E3o cont\u00EAm apenas n\u00FAmeros.");			
			return false;
		}else{
			return true;		
		}
	}else{
		return true;
	}
}

function LTrim(s){
	var i = 0;
	var j = 0;
	for (i = 0; i <= s.length - 1; i++)
		if (s.substring(i, i + 1) != ' ')
			{
				j = i;
				break;
			}
	return s.substring(j, s.length);
}
	
function RTrim(s){
	var j = 0;
	for (var i = s.length-1; i > -1; i--)
		if (s.substring(i, i + 1) != ' ')
			{
				j = i;
				break;
			}
	return s.substring(0, j + 1);
}

function Trim(obj, s){
	obj.value = LTrim(RTrim(s));
}

function CheckSpaces(s){
		var i = 0;
		var j = 0;
		var r;
		for (i = 0; i <= s.length; i++)
			if (s.substring(i, i + 1) != ' ')
				{
					j = i;
					break;
				}
		r = s.substring(j, s.length);
		if ((r != '') || (r.length < 5))
			return true;
		else
			return false;
	}

function ValidaData(obj){

	data = obj.value;
	dia = data.substring(0,2);
	mes = data.substring(3,5);
	ano = data.substring(6,10);
	barra1 = data.substring(2,3);
	barra2 = data.substring(5,6);
	
	hoje = new Date()
	// hoje.setDate(dia);
	// hoje.setMonth(mes-1);
	if (data != "" ){
		if ((barra1 != "/") || (barra2 != "/")) {
			alert("Atenção! O formato da data est\u00E1 inv\u00E1lido ! Exemplo: DD/MM/AAAA.");
			obj.value = "";
			return false;
		}
	
		if ( isNaN(dia) || (dia < 1) || (dia > 31)) {
			alert("Atenção! A data (dia) \u00E9 inv\u00E1lida.");
			obj.value = "";
			return false;
		}else if (isNaN(mes) || (mes < 1) || (mes > 12) ) {
			alert("Atenção! A data (m\u00EAs) \u00E9 inv\u00E1lida.");
			obj.value = "";
			return false;
			}else if (isNaN(ano)) {
				alert("Atenção! A data (ano) cont\u00EAm caracteres inv\u00E1lidos.");
				obj.value = "";
				return false;
			}else if (data.length != 10) {  
				alert("Atenção! O formato da data est\u00E1 inv\u00E1lido ! Exemplo: DD/MM/AAAA.");
				obj.value = "";
				return false;
			}

		quociente = (eval(ano) % 4);
	
		if (quociente == 0)
			biss = true;
		else
			biss = false;
	
		if (ano < 1900) {
			alert("Atenção! Ano menor que 1900 !");
			obj.value = "";
			return false;
		}
	
		if (mes == 2) {
			if ((dia == 29) && (biss == false)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido pois o ano n\u00E3o \u00E9 nissexto!");
				obj.value = "";
				return false;
			}else if ((dia == 30) || (dia == 31)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido para o m\u00EAs de fevereiro!");
				obj.value = "";
				return false;
			}
		}else if ((mes == 4) && (dia == 31)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido para o m\u00EAs de abril!");
				obj.value = "";
				return false;
			}else if ((mes == 6) && (dia == 31)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido para o m\u00EAs de junho!");
				obj.value = "";
				return false;
			}else if ((mes == 9) && (dia == 31)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido para o m\u00EAs de setembro!");
				obj.value = "";
				return false;
			}else if ((mes == 11) && (dia == 31)) {
				alert("Atenção! O dia \u00E9 inv\u00E1lido para o m\u00EAs de novembro!");
				obj.value = "";
				return false;
			}
	return true;
	}else{
		return true;
	}
}

function EnviaCadastroFinal(){
	var f = document.forms[0];
	if (f.f_valido.value==""){
		f.action = "cadastro_final.php"; 
	}else{
		f.action = "cadastro_ccorrente.php";
	}
	f.submit();
}

function validastr(ev){
	var codigos ='44,46,59,47,60,62,58,63,126,94,93,125,180,96,91,123,61,43,45,95,41,92,92,92,92,40,42,38,168,37,36,35,64,33,124,224,232,236,242,249,226,234,238,244,251,228,235,239,246,252,225,233,237,243,250,227,245,192,200,204,210,217,194,202,206,212,219,196,203,207,214,220,193,201,205,211,218,195,213,231,199,32,34';
	var keys = codigos.split(',');
	for(i=0;i<keys.length;i++){
		if(ev.keyCode == parseInt(keys[i])){
			return false;
		}else{
			if(ev.which == parseInt(keys[i])){
				return false;
			}
		}
	}
	return true;
}

function isDate(obj){
	if (!ValidaData(obj)){
		obj.focus();
		return false;
	}
	return true;
 }


function RetornaPagamento(v_codigo){
	var f = document.forms[0];
	f.action = "cadastro.php"; 
	f.submit();
}

function Preenche(){
	var f = document.frmCadastro;
	f.f_tipo_pessoa[0].checked = true;
	document.getElementById('f_cpf').value='00000000191';
	f.f_nom_pessoa.value = 'Teste';
	f.f_sexo[1].checked = true;
	f.f_dth_nascimento.value = '10/05/1976';
	f.f_ddd_celular.value = '21';
	f.f_ddd_comercial.value = '21';
	f.f_ddd_residencial.value = '21';
	f.f_tel_residencial.value = '12345621';
	f.f_tel_celular.value = '23234561';
	f.f_tel_comercial.value = '22345671';
	f.f_num_cep.value = '30450-250';
	f.f_tipo_logradouro.value = 'R';
	f.f_logradouro.value = 'rua teste de rua';
	f.f_prefixo.value='Dr';
	f.f_numero.value='112312';
	f.f_complemento.value = 'apto 20000';
	f.f_bairro.value = 'bairro';
	f.f_municipio.value = 'belo horizonte';
	f.f_forma_pgto[1].checked = true;
	f.f_email.value='aaa@bbb.ccc.dd';
}

function abrePopUp(src)
{
	var vArguments='width=415,height=200,toolbar=no,status=no,titlebar=no,menubar=no,status=no,resizable=no,scrollbars=yes,top=120,left=300';
	var vParamList = new Object();
	//newWindow = window.open(vTarget,"ChooseColor",vArguments);
	newWindow = showModalDialog(src,vParamList,'dialogWidth:750px;dialogHeight:550px;center:yes;status:no;scroll:yes;help:no;resizable:yes');
}
	
function abre(){
	var foto = window.open("http://www.directtalk.com.br/server/directtalkr.dll/user?S=I&id_s=45910751B8580835854C","janela","width=350,height=360,resizable=no,toolbar=0,location=0,directories=0,status=no,menubar=0");
	var f = document.forms[0];
	function vai(){ f.submit();};
	f.action="http://www.directtalk.com.br/server/directtalkr.dll/user?S=I&id_s=45910751B8580835854C";
	setTimeout('vai();',10);
}

function VoltarCadastro(){
	var f = document.forms[0];
	f.action = 'produto.php'
	f.submit();
 }

/*a1=new Image(149,21)
a1.src="imgs/b_blarga.png"
a2=new Image(149,21)
a2.src="imgs/b_blarga1.png"

a3=new Image(149,21)
a3.src="imgs/b_dial.png"
a4=new Image(149,21)
a4.src="imgs/b_dial1.png"

a5=new Image(149,21)
a5.src="imgs/b_promo.png"
a6=new Image(149,21)
a6.src="imgs/b_promo1.png"

a7=new Image(149,21)
a7.src="imgs/b_empresas.png"
a8=new Image(149,21)
a8.src="imgs/b_empresas1.png"

a9=new Image(149,21)
a9.src="imgs/b_conteudo.png"
a10=new Image(149,21)
a10.src="imgs/b_conteudo1.png"

a11=new Image(149,21)
a11.src="imgs/b_servicos.png"
a12=new Image(149,21)
a12.src="imgs/b_servicos1.png"
*/
function filter(imagename,objectsrc){
	if (document.images)
		document.images[imagename].src=eval(objectsrc+".src")
}

function Envia(valor){
	document.produtos.codigogaleria.value = valor;
	document.produtos.action = "produto.php";
	document.produtos.submit();
}

function EnviaCadastro(valor){
	var f = document.forms[0];
	f.produto.value = valor;
	f.action = 'cadastro.php';
	f.submit();
}

function AvaliaDigitos(valor){
	if(valor && valor.value.length == 11){
		return retornaCPFCNPJFormatado(valor,1);
	}else{
		if(valor && valor.value.length == 14){
			return retornaCPFCNPJFormatado(valor,2);
		}
	}
	return '';
}

function LimitaTexto(obj, limit){
	var size = obj.value.length; 
	if (size > limit){
		temp = obj.value; 
		obj.value = temp.substring(0, limit-1);
		//alert("Máximo de " + limit + " caracteres para a este campo.");
		alert("Este campo chegou ao seu limite de caracteres.");
		obj.focus();
		return false;
	} 
	return true;
}
function AlteraStatus(valor, codigo){
	if((document.frmRelatorio.co_atd_atual.value!=5)&&(valor==6)&&(document.frmRelatorio.desc_atd.value == "")){
		alert('Favor inserir um motivo para o cancelamento.');
		document.frmRelatorio.desc_atd.focus();
		return false;
	}
	document.frmRelatorio.co_matricu.value = codigo;
	document.frmRelatorio.status_atd.value = valor;
	document.frmRelatorio.submit();
}

//Calendário
var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;

	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/*
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for...
	2.Years also evenly divisible by 100 are not leap years, except for...
	3.Years also evenly divisible by 400 are leap years.
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];

		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/*
	Will return an 1-D array with 1st element being the calculated month
	and second being the calculated year
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}

	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/*
	Will return an 1-D array with 1st element being the calculated month
	and second being the calculated year
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}

	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";

	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";

	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;

	vCode = vCode + "</TABLE>";

	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";

	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("</head>");

	this.wwrite("<body " +
		"link=\"" + this.gLinkColor + "\" " +
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</B><BR>");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];

	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">><\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;

	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11)	vr = 3;

		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " +
		"link=\"" + this.gLinkColor + "\" " +
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</B><BR>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;

	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font><BR></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";

	vCode = vCode + "<TR>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
	vCode = vCode + "</TR>";

	return vCode;
}

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary.
	*/

	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
			"<A HREF='#' " +
				"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
				this.format_data(vDay) +
				"';window.close();\">" +
				this.format_day(vDay) +
			"</A>" +
			"</FONT></TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
				"<A HREF='#' " +
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
					this.format_data(vDay) +
					"';window.close();\">" +
				this.format_day(vDay) +
				"</A>" +
				"</FONT></TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}

	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
	}

	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + weekendColor + "\"");
	}

	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData =  vY4+ "\/" + vMonth + "\/" +vDD ;
			break;
		case "MM\/DD\/YY" :
			vData =  vY2+ "\/" +vMonth  + "\/" +vDD ;
			break;
		case "MM-DD-YYYY" :
			vData =  vY4+ "-" + vMonth + "-" + vDD;
			break;
		case "MM-DD-YY" :
			vData =  vY2+ "-" +vMonth  + "-" + vDD;
			break;

		case "DD\/MON\/YYYY" :
			vData = vY4 + "\/" +vMon  + "\/" +vDD ;
			break;
		case "DD\/MON\/YY" :
			vData = vY2+ "\/" + vMon + "\/" + vDD ;
			break;
		case "DD-MON-YYYY" :
			vData =  vY4+ "-" + vMon + "-" + vDD;
			break;
		case "DD-MON-YY" :
			vData =  vY2+ "-" + vMon + "-" +vDD ;
			break;

		case "DD\/MONTH\/YYYY" :
			vData =  vY4+ "\/" + vFMon + "\/" + vDD;
			break;
		case "DD\/MONTH\/YY" :
			vData =  vY2+ "\/" + vFMon + "\/" + vDD;
			break;
		case "DD-MONTH-YYYY" :
			vData =  vY4+ "-" + vFMon + "-" +vDD ;
			break;
		case "DD-MONTH-YY" :
			vData =  vY2+ "-" + vFMon + "-" + vDD;
			break;

		case "DD\/MM\/YYYY" :
			vData =  vDD+ "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vY2+ "\/" + vMonth + "\/" +  vDD;
			break;
		case "DD-MM-YYYY" :
			vData =  vY4+ "-" + vMonth + "-" + vDD;
			break;
		case "DD-MM-YY" :
			vData = vY2 + "-" + vMonth + "-" + vDD;
			break;

		default :
			vData =  vY4+ "\/" + vMonth + "\/" +vDD ;
	}

	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}

function show_calendar() {
	/*
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/

	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "DD/MM/YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar",
		"width=250,height=250,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "DD/MM/YYYY";

	var vWinCal = window.open("", "CALENDARIO", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}
//Fim Calendário