function include(xUrl,xId, chkValue) {

  var xmlhttp = false;
  
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }

  xmlhttp.open("GET", xUrl,true);
  xmlhttp.onreadystatechange=function() {

	if (xmlhttp.readyState==4) {
		arrValores = xmlhttp.responseText.split(";");
		objCombo = document.getElementById(xId);
		objCombo.length = 0;
		if(arrValores[0] != '')
			objCombo.options[objCombo.length] = new Option( "-= SELECIONE =-", "" );
		for(x=0;x<arrValores.length-1;x=x+2) {
			objCombo.options[objCombo.length] = new Option( arrValores[x+1], arrValores[x] );
		}
		if(chkValue)
			objCombo.value = chkValue;
		else
			objCombo.selectedIndex = 0;
			
	}
  }
  
  xmlhttp.send(null)
}

function includeCategoria(xUrl,xId) {

  var xmlhttp = false;
  
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }

  xmlhttp.open("GET", xUrl,true);
  xmlhttp.onreadystatechange=function() {

  
	if (xmlhttp.readyState==4) {
		arrValores = xmlhttp.responseText.split(";");
		objCombo = document.getElementById("InCdCategoria"+parseInt(parseInt(xId)+1));
		objCombo.length = 0;
		for(x=0;x<arrValores.length-1;x=x+2) {
			objCombo.options[objCombo.length] = new Option( arrValores[x+1], arrValores[x] );
		}
			
		if(xmlhttp.responseText!='')
			objCombo.style.display='';
		else
			objCombo.style.display='none';
			
		for(x=xId+2;x<=12;x++) {
			document.getElementById("InCdCategoria"+parseInt(x)).length=0;
			document.getElementById("InCdCategoria"+parseInt(x)).style.display='none';
		}
	}
	
  }
  xmlhttp.send(null)
}

function setSelecionarCategoria() {
	document.getElementById("InCdCategoria1").value = "";
	for(x=2;x<=12;x++) {
		document.getElementById("InCdCategoria"+parseInt(x)).length=0;
		document.getElementById("InCdCategoria"+parseInt(x)).style.display='none';
	}
}

function getEstado(InCdPais, InCdEstado) {
	if (InCdPais==1) {
		document.getElementById("InCdEstado").style.display = '';
		document.getElementById("TxEstado").style.display = 'none';
		window.open('scripts/getEstado.asp?InCdEstado=' + InCdEstado + '&InCdPais=' + InCdPais + '&obj=InCdEstado','iframeOculto');
	}
	else {
		document.getElementById("InCdEstado").style.display = 'none';
		document.getElementById("TxEstado").style.display = '';
	}
}
function getEstadoAdmin(InCdPais, InCdEstado) {
	if (InCdPais==1) {
		document.getElementById("InCdEstado").style.display = '';
		document.getElementById("TxEstado").style.display = 'none';
		window.open('../scripts/getEstado.asp?InCdEstado=' + InCdEstado + '&InCdPais=' + InCdPais + '&obj=InCdEstado','iframeOculto');
	}
	else {
		document.getElementById("InCdEstado").style.display = 'none';
		document.getElementById("TxEstado").style.display = '';
	}

}
	
function getCidade(InCdEstado, InCdCidade) {
	include('scripts/getCidade.asp?InCdEstado=' + InCdEstado, "InCdCidade", InCdCidade);
}
function getCategoria(InCdCategoria,x) {
	window.open('scripts/getCategoria.asp?InCdCategoria=' + InCdCategoria + '&xId=' + x,'iframeOculto');
}

function chkFormCadastro() {
	if(document.formulario.TxEmail.value != document.formulario.TxEmail2.value) {
		alert("Os e-mails digitados não conferem!");
		document.formulario.TxEmail.focus();
		return false;
	}
	if(document.formulario.TxSenha1.value != document.formulario.TxSenha2.value) {
		alert("As senhas digitadas não conferem!");
		document.formulario.TxSenha1.focus();
		return false;
	}
	if(document.formulario.TxSenha1.value.length < 6) {
		alert("A sua senha deve ter no mínimo 6 caracteres!");
		document.formulario.TxSenha1.focus();
		return false;
	}
	if(document.formulario.TxApelido.value.length < 3) {
		alert("O apelido deve ter no mínimo 3 caracteres!");
		document.formulario.TxApelido.focus();
		return false;
	}
	if(document.formulario.InCdPais.value != 1 && document.formulario.TxEstado.value == '') {
		alert("Se você não mora no Brasil, digite o Estado!");
		document.formulario.TxEstado.focus();
		return false;
	}
	if(document.formulario.InCdPais.value == 1 && document.formulario.InCdEstado.value == '') {
		alert("Se você mora no Brasil, selecione o Estado!");
		document.formulario.InCdEstado.focus();
		return false;
	}
	if (!document.formulario.TxDeAcordo.checked) {
		alert("Você deve estar de acordo com as políticas de uso do site para cadastrar-se!");
		document.formulario.TxDeAcordo.focus();
		return false;
	}
}
function chkFormAlteracaoSenha() {
	if(document.formulario.TxSenha1.value != document.formulario.TxSenha2.value) {
		alert("As senhas digitadas não conferem!");
		document.formulario.TxSenha1.focus();
		return false;
	}
	if(document.formulario.TxSenha1.value.length < 6) {
		alert("A sua senha deve ter no mínimo 6 caracteres!");
		document.formulario.TxSenha1.focus();
		return false;
	}
}
function chkCategoria() {
	TxValorSelecionado = "";
	for(x=1;x<=12;x++) {
		objCombo = document.getElementById("InCdCategoria"+parseInt(x));
		if(objCombo.value!='')
			TxValorSelecionado = objCombo.options[objCombo.selectedIndex].text;
		
	}
	
	if(TxValorSelecionado=="") {
		alert("Selecione uma categoria!")
		return false;
	}
	else if(Right(TxValorSelecionado,2) == " >") {
		alert("A categoria selecionada possui sub-categorias.\nVocê deve selecionar uma sub-categoria para seu produto.");
		return false;
	}
	
	return true;
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function setInicioImediato(chk) {
	objDtInicio = document.getElementById("DtInicio");
	objInHora = document.getElementById("InHora");
	objDtInMinuto = document.getElementById("InMinuto");
	if(chk) {
		objDtInicio.disabled = true;
		objDtInicio.value = "";
		objInHora.disabled = true;
		objDtInMinuto.disabled = true;
	}
	else {
		objDtInicio.disabled = false;
		objInHora.disabled = false;
		objDtInMinuto.disabled = false;
	}
}
nrFotosLiberadas = 6;
function setFoto(x) {
	objTdLbl 	= document.getElementById("lbl_foto" + parseInt(x));
	objTdFrm 	= document.getElementById("frm_foto" + parseInt(x));
	objTr 		= document.getElementById("tr_foto" + parseInt(x));
	objLnk = document.getElementById("lnk_foto" + parseInt(parseInt(x)-1));
	objTdLbl.style.display='';
	objTdFrm.style.display='';
	objTr.style.display='';
	objLnk.style.display='none';
}
function setExcluirFoto(InCdAnuncio,TxFoto,nrFoto) {
	window.open("cadastro_anuncio_dados.asp?nrFoto=" + nrFoto + "&InCdAnuncio=" + InCdAnuncio + "&acao=Excluir&foto=" + TxFoto,"iframeOculto");
}
function setEsconderFoto(nrFoto) {
	if(document.getElementById("tdImagem" + nrFoto)) { 
		document.getElementById("tdImagem" + nrFoto).style.display='none';
		document.getElementById("TxFoto" + parseInt(parseInt(nrFoto)+1)).value = '';
	}
	if(document.getElementById("lnk_foto" + nrFotosLiberadas)) document.getElementById("lnk_foto" + nrFotosLiberadas).style.display='';
	nrFotosLiberadas += 1;	
}
function setGarantia(chk) {
	objTdLbl = document.getElementById("lbl_garantia");
	objTdFrm = document.getElementById("frm_garantia");
	objTxGarantia = document.getElementById("TxGarantia");
	if(chk==1) {
		objTdLbl.style.display='';
		objTdFrm.style.display='';
	}
	else {
		objTdLbl.style.display='none';
		objTdFrm.style.display='none';
		objTxGarantia.value = '';
	
	}

}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mario Costa |  */
function currencyFormat(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = (window.Event) ? e.which : e.keyCode;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}

function maskInput(tipo,e) {
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
		
	keychar = String.fromCharCode(key);
	
	if(tipo=='H')
		chars = "0123456789:"
	else if (tipo=='I')
		chars = "0123456789"
	else if (tipo=='N')
		chars = "0123456789,"
	else if (tipo=='D')
		chars = "0123456789/"
		
	if ((key==null) || (key==0) || (key==8) ||(key==9) || (key==13) || (key==27) )
		return true;
	else if (((chars).indexOf(keychar) > -1))
		return true;
	
	return false;
}
function chkFormProduto(dt_atual,dt_maxima) {
	if(document.formulario.TxTitulo.value == '') {
		alert("Preencha o TÍTULO do anúncio!");
		document.formulario.TxTitulo.focus();
		return false;
	}
	if(document.formulario.InCdTipoVenda.value == '') {
		alert("Selecione o TIPO DE VENDA!");
		document.formulario.InCdTipoVenda.focus();
		return false;
	}
	if(document.formulario.InQuantidade.value == '') {
		alert("Preencha a QUANTIDADE!");
		document.formulario.InQuantidade.focus();
		return false;
	}
	else if(parseInt(document.formulario.InQuantidade.value) < 1 || parseInt(document.formulario.InQuantidade.value) > 1000) {
		alert("A quantidade deve ser de 1 a 1000 unidades!");
		document.formulario.InQuantidade.focus();
		return false;
	}
	if(document.formulario.DbValor.value == '') {
		alert("Preencha o VALOR do produto!");
		document.formulario.DbValor.focus();
		return false;
	}
	else {
		if(parseFloat(document.formulario.DbValor.value) <= 0) {
			alert("Valor inválido! Deve ser igual ou maior que R$ 1.");
			return false;
		}
	}
	if(document.formulario.InDuracao.value == '') {
		alert("Preencha a DURAÇÃO DO ANÚNCIO (2 a 60 dias)!");
		document.formulario.InDuracao.focus();
		return false;
	}
	else {
		if(parseInt(document.formulario.InDuracao.value)<2 || parseInt(document.formulario.InDuracao.value)>60) {
			alert("A duração do anúncio deve ser de 2 a 60 dias!")
			return false;
		}
	}
	if(document.formulario.DtInicio) {
		if(document.formulario.DtInicio.value == '' && !document.formulario.BoIniciar.checked) {
			alert("Preencha a DATA DE INÍCIO do anúncio ou marque para iniciar imediatamente!");
			document.formulario.DtInicio.focus();
			return false;
		}
		else if (!document.formulario.BoIniciar.checked) {
			if(FormatDate(document.formulario.DtInicio.value,"yyyy/mm/dd") < FormatDate(dt_atual,"yyyy/mm/dd") ) {
				alert("Data de início inválida. Deve ser igual ou maior que a data atual!")
				return false;
			}
			else if(FormatDate(document.formulario.DtInicio.value,"yyyy/mm/dd") > FormatDate(dt_maxima,"yyyy/mm/dd") ) {
				alert("Data de início inválida. Deve ser no máximo 60 dias após a data atual!")
				return false;
			}
		}	
	}
	if(document.formulario.InCdPais.value == '') {
		alert("Preencha a LOCALIZAÇÃO do produto!");
		document.formulario.InCdPais.focus();
		return false;
	}
	if(document.formulario.InCdPais.value == 1) {
		if(document.formulario.InCdEstado.value == '') {
			alert("Preencha a LOCALIZAÇÃO do produto!");
			document.formulario.InCdEstado.focus();
			return false;
		}
	}
	else {
		if(document.formulario.TxEstado.value == '') {
			alert("Preencha a LOCALIZAÇÃO do produto!");
			document.formulario.TxEstado.focus();
			return false;
		}
	}
	if(document.formulario.InCdTipoVenda.value == 3) {
		
		if(document.formulario.DbValorReserva.value == '') {
			alert("Por ser um leilão com preço de reserva, você deve preencher o campo VALOR DE RESERVA!");
			document.formulario.DbValorReserva.focus();
			return false;
		}
		else {
			DbValor = parseFloat(convertCurrency(document.formulario.DbValor.value),2);
			DbValorReserva = parseFloat(convertCurrency(document.formulario.DbValorReserva.value),2);
			if(DbValor > DbValorReserva) {
				alert("O preço de reserva deve ser maior que o preço do anúncio!");
				document.formulario.DbValorReserva.focus();
				return false;
			}
		}
	}
	
	if(document.formulario.InCdDestaqueFoto) {
		if(document.formulario.InCdDestaqueFoto.value!='') {
			arrInCdDestaqueFoto = document.formulario.InCdDestaqueFoto.value.split(",");
			for(i=0;i<arrInCdDestaqueFoto.length;i++) {
				//Divide para pegar o código de destaque e quantidade de fotos obrigatórias
				arrInCdDestaqueFoto2 = arrInCdDestaqueFoto[i].split(";");
				objDestaque = document.getElementById('InCdDestaque' + arrInCdDestaqueFoto2[0]);
				InFoto = arrInCdDestaqueFoto2[1];
				BoFoto = getExisteFotoAnuncio(objDestaque);
				if(parseInt(BoFoto)==0) {
					alert("Um ou mais destaques selecionados requerem foto para o seu anúncio. Verifique!");
					return false;
				}
				else if (parseInt(BoFoto) < parseInt(InFoto)) {
					alert("O tipo de destaque \"Rotação da foto\" exige no mínimo " + InFoto + " fotos!");
					return false;
				}
			}
		}

	}
	setValoresCadProduto();
}


function chkFormProdutoTeste(dt_atual,dt_maxima) {
	
	objDocumento = document.getElementById('TxDocumento');
	if(objDocumento) {
		if(objDocumento.value == '') {
			alert("Preencha o número do seu documento (CPF/CNPJ)!");
			objDocumento.focus();
			return false;
		}
		else {
			TxTipoDocumento = document.getElementById('TxTipoDocumento').value;
			BoInvalido=0;
			if(TxTipoDocumento=='CPF') {
				if(!isCpf(objDocumento.value))
					BoInvalido=1;
			}
			else if(TxTipoDocumento=='CNPJ') {
				if(!isCnpj(objDocumento.value))
					BoInvalido=1;
			}
			if(BoInvalido==1) {
				alert(TxTipoDocumento + " inválido.");
				objDocumento.focus();
				return false;
			}
		}
	}
	
	
	if(document.formulario.TxEndereco) {
		if(document.formulario.TxEndereco.value == '') {
			alert("Preencha o seu ENDEREÇO!");
			document.formulario.TxEndereco.focus();
			return false;
		}
	}
	
	if(document.formulario.TxTitulo.value == '') {
		alert("Preencha o TÍTULO do anúncio!");
		document.formulario.TxTitulo.focus();
		return false;
	}
	if(document.getElementById('InCdTipoVenda1').checked==false && document.getElementById('InCdTipoVenda2').checked==false && document.getElementById('InCdTipoVenda3').checked==false ) {
		alert("Selecione o TIPO DE VENDA!");
		document.getElementById('InCdTipoVenda1').focus();
		return false;
	}
	if(document.formulario.InQuantidade.value == '') {
		alert("Preencha a QUANTIDADE!");
		document.formulario.InQuantidade.focus();
		return false;
	}
	else if(parseInt(document.formulario.InQuantidade.value) < 1 || parseInt(document.formulario.InQuantidade.value) > 1000) {
		alert("A quantidade deve ser de 1 a 1000 unidades!");
		document.formulario.InQuantidade.focus();
		return false;
	}
	if(document.formulario.DbValor.value == '') {
		alert("Preencha o VALOR do produto!");
		document.formulario.DbValor.focus();
		return false;
	}
	else {
		if(parseFloat(document.formulario.DbValor.value) <= 0) {
			alert("Valor inválido! Deve ser igual ou maior que R$ 1.");
			return false;
		}
	}
	if(document.formulario.InDuracao.value == '') {
		alert("Preencha a DURAÇÃO DO ANÚNCIO (2 a 60 dias)!");
		document.formulario.InDuracao.focus();
		return false;
	}
	else {
		if(parseInt(document.formulario.InDuracao.value)<2 || parseInt(document.formulario.InDuracao.value)>60) {
			alert("A duração do anúncio deve ser de 2 a 60 dias!")
			return false;
		}
	}
	if(document.formulario.DtInicio) {
		if(document.formulario.DtInicio.value == '' && !document.formulario.BoIniciar.checked) {
			alert("Preencha a DATA DE INÍCIO do anúncio ou marque para iniciar imediatamente!");
			document.formulario.DtInicio.focus();
			return false;
		}
		else if (!document.formulario.BoIniciar.checked) {
			if(FormatDate(document.formulario.DtInicio.value,"yyyy/mm/dd") < FormatDate(dt_atual,"yyyy/mm/dd") ) {
				alert("Data de início inválida. Deve ser igual ou maior que a data atual!")
				return false;
			}
			else if(FormatDate(document.formulario.DtInicio.value,"yyyy/mm/dd") > FormatDate(dt_maxima,"yyyy/mm/dd") ) {
				alert("Data de início inválida. Deve ser no máximo 60 dias após a data atual!")
				return false;
			}
		}	
	}
	if(document.formulario.InCdPais.value == '') {
		alert("Preencha a LOCALIZAÇÃO do produto!");
		document.formulario.InCdPais.focus();
		return false;
	}
	if(document.formulario.InCdPais.value == 1) {
		if(document.formulario.InCdEstado.value == '') {
			alert("Preencha a LOCALIZAÇÃO do produto!");
			document.formulario.InCdEstado.focus();
			return false;
		}
	}
	else {
		if(document.formulario.TxEstado.value == '') {
			alert("Preencha a LOCALIZAÇÃO do produto!");
			document.formulario.TxEstado.focus();
			return false;
		}
	}
	
	if(document.formulario.InCdTipoVenda.value == 3) {
		
		if(document.formulario.DbValorReserva.value == '') {
			alert("Por ser um leilão com preço de reserva, você deve preencher o campo VALOR DE RESERVA!");
			document.formulario.DbValorReserva.focus();
			return false;
		}
		else {
			DbValor = parseFloat(convertCurrency(document.formulario.DbValor.value),2);
			DbValorReserva = parseFloat(convertCurrency(document.formulario.DbValorReserva.value),2);
			if(DbValor > DbValorReserva) {
				alert("O preço de reserva deve ser maior que o preço do anúncio!");
				document.formulario.DbValorReserva.focus();
				return false;
			}
		}
	}
	
	if(document.formulario.InCdDestaqueFoto) {
		if(document.formulario.InCdDestaqueFoto.value!='') {
			arrInCdDestaqueFoto = document.formulario.InCdDestaqueFoto.value.split(",");
			for(i=0;i<arrInCdDestaqueFoto.length;i++) {
				//Divide para pegar o código de destaque e quantidade de fotos obrigatórias
				arrInCdDestaqueFoto2 = arrInCdDestaqueFoto[i].split(";");
				objDestaque = document.getElementById('InCdDestaque' + arrInCdDestaqueFoto2[0]);
				InFoto = arrInCdDestaqueFoto2[1];
				BoFoto = getExisteFotoAnuncio(objDestaque);
				if(parseInt(BoFoto)==0) {
					alert("Um ou mais destaques selecionados requerem foto para o seu anúncio. Verifique!");
					return false;
				}
				else if (parseInt(BoFoto) < parseInt(InFoto)) {
					alert("O tipo de destaque \"Rotação da foto\" exige no mínimo " + InFoto + " fotos!");
					return false;
				}
			}
		}

	}
	setValoresCadProduto();
}
function autoMaskInput(str,textbox,loc,delim){
	var locs = loc.split(',');
	
	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
		 if (k == locs[i]){
		  if (str.substring(k, k+1) != delim){
		   if (event.keyCode != 8){ //backspace
			str = str.substring(0,k) + delim + str.substring(k,str.length);
		   }
		  }
		 }
		}
	 }
	textbox.value = str
}

function isDate(objDateToCheck){
	DateToCheck = objDateToCheck.value;
	fl_erro = 0;
	if(DateToCheck!="") {
		var m_strDate = FormatDate(DateToCheck);
		if(m_strDate=="")
			fl_erro = 1;

		var m_arrDate = m_strDate.split("/");
		if(m_arrDate.length != 3)
			fl_erro = 1;
		else {
			var m_DAY = m_arrDate[0];
			var m_MONTH = m_arrDate[1];
			var m_YEAR = m_arrDate[2];
			if(m_YEAR.length > 4)
				fl_erro = 1;
			m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
			var testDate=new Date(m_strDate);
			if(testDate.getMonth()+1!=m_MONTH)
				fl_erro = 1;
		}
	}
	if(fl_erro==1) {
		alert("Data inválida!");
		objDateToCheck.value='';
		objDateToCheck.focus();
		return false;
	}
}

function FormatDate(DateToFormat,FormatAs){
	if(DateToFormat==""){return"";}
	if(!FormatAs){FormatAs="dd/mm/yyyy";}
	
	var strReturnDate;
	FormatAs = FormatAs.toLowerCase();
	DateToFormat = DateToFormat.toLowerCase();
	var arrDate
	var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var strMONTH;
	var Separator;
	
	while(DateToFormat.indexOf("st")>-1){
	DateToFormat = DateToFormat.replace("st","");
	}
	
	while(DateToFormat.indexOf("nd")>-1){
	DateToFormat = DateToFormat.replace("nd","");
	}
	
	while(DateToFormat.indexOf("rd")>-1){
	DateToFormat = DateToFormat.replace("rd","");
	}
	
	while(DateToFormat.indexOf("th")>-1){
	DateToFormat = DateToFormat.replace("th","");
	}
	
	if(DateToFormat.indexOf(".")>-1){
	Separator = ".";
	}
	
	if(DateToFormat.indexOf("-")>-1){
	Separator = "-";
	}
	
	
	if(DateToFormat.indexOf("/")>-1){
	Separator = "/";
	}
	
	if(DateToFormat.indexOf(" ")>-1){
	Separator = " ";
	}
	
	arrDate = DateToFormat.split(Separator);
	DateToFormat = "";
		for(var iSD = 0;iSD < arrDate.length;iSD++){
			if(arrDate[iSD]!=""){
			DateToFormat += arrDate[iSD] + Separator;
			}
		}
	DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
	arrDate = DateToFormat.split(Separator);
	
	if(arrDate.length < 3){
	return "";
	}
	
	var DAY = arrDate[0];
	var MONTH = arrDate[1];
	var YEAR = arrDate[2];
	
	
	
	
	if(parseFloat(arrDate[1]) > 12){
	DAY = arrDate[1];
	MONTH = arrDate[0];
	}
	
	if(parseFloat(DAY) && DAY.toString().length==4){
	YEAR = arrDate[0];
	DAY = arrDate[2];
	MONTH = arrDate[1];
	}
	
	
	for(var iSD = 0;iSD < arrMonths.length;iSD++){
	var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
	var MonthPosition = DateToFormat.indexOf(ShortMonth);
		if(MonthPosition > -1){
		MONTH = iSD + 1;
			if(MonthPosition == 0){
			DAY = arrDate[1];
			YEAR = arrDate[2];
			}
		break;
		}
	}
	
	var strTemp = YEAR.toString();
	if(strTemp.length==2){
	
		if(parseFloat(YEAR)>40){
		YEAR = "19" + YEAR;
		}
		else{
		YEAR = "20" + YEAR;
		}
	
	}
	
	
		if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
		MONTH = "0" + MONTH;
		}
		if(parseInt(DAY)< 10 && DAY.toString().length < 2){
		DAY = "0" + DAY;
		}
		switch (FormatAs){
		case "dd/mm/yyyy":
		return DAY + "/" + MONTH + "/" + YEAR;
		case "yyyy/mm/dd":
		return YEAR + "/" + MONTH + "/" + DAY;
		case "mm/dd/yyyy":
		return MONTH + "/" + DAY + "/" + YEAR;
		case "dd/mmm/yyyy":
		return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
		case "mmm/dd/yyyy":
		return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
		case "dd/mmmm/yyyy":
		return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
		case "mmmm/dd/yyyy":
		return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
		}
	
	return DAY + "/" + strMONTH + "/" + YEAR;;
}

function setValoresCadProduto() {
	objInCdFormaPagamento 	= document.formulario.chkInCdFormaPagamento;
	objInCdFormaEnvio 		= document.formulario.chkInCdFormaEnvio;
	objInCdDestaque 		= document.formulario.chkInCdDestaque;
	
	InCdFormaPagamento = "";
	InCdFormaEnvio = "";
	InCdDestaque	= "";
	
	for (var i = 0; i < objInCdFormaPagamento.length; i++) {
		if(objInCdFormaPagamento[i].checked) {
			if(InCdFormaPagamento=="")
				InCdFormaPagamento = objInCdFormaPagamento[i].value;
			else
				InCdFormaPagamento += "," + objInCdFormaPagamento[i].value;
		}
	}
	document.formulario.InCdFormaPagamento.value = InCdFormaPagamento;
	
	for (var i = 0; i < objInCdFormaEnvio.length; i++) {
		if(objInCdFormaEnvio[i].checked) {
			if(InCdFormaEnvio=="")
				InCdFormaEnvio = objInCdFormaEnvio[i].value;
			else
				InCdFormaEnvio += "," + objInCdFormaEnvio[i].value;
		}
	}
	document.formulario.InCdFormaEnvio.value = InCdFormaEnvio;
	
	if(objInCdDestaque) {
		if(objInCdDestaque.length)
			for (var i = 0; i < objInCdDestaque.length; i++) {
				if(objInCdDestaque[i].checked) {
					if(InCdDestaque=="")
						InCdDestaque = objInCdDestaque[i].value;
					else
						InCdDestaque += "," + objInCdDestaque[i].value;
				}
			}
		else {
			if(objInCdDestaque.checked)
				InCdDestaque = objInCdDestaque.value;
		}
		document.formulario.InCdDestaque.value = InCdDestaque;
	}
	document.getElementById("div_enviar").style.display='';
	document.getElementById("btn_enviar").style.display='none';
	return true;
}
function writeDiv(objDiv,vlr) {
	document.getElementById(objDiv).innerHTML = vlr;
}
function setPrecoReserva(InCdTipoVenda) {
	objTr = document.getElementById('tr_reserva');
	DbValorReserva = document.getElementById('DbValorReserva');
	objInCdMoeda = document.getElementById('InCdMoeda');
	if(InCdTipoVenda==3)
		objTr.style.display='';
	else {
		DbValorReserva.value='';
		objTr.style.display='none';		
	}
	writeDiv('td_moeda_reserva',objInCdMoeda.options[objInCdMoeda.selectedIndex].text);
}

function setCancelarAnuncio() {
	if(confirm("Você tem certeza que deseja cancelar este anúncio?\nTodos os dados digitados serão perdidos."))
		document.location.href = 'cadastro_anuncio_cancelar.asp';
	else
		return false;
}
function chkFormBusca(formBusca) {
	if(eval("document." + formBusca + ".TxChave").value.length < 2) {
		alert("Preencha um termo com no mínimo 2 caracteres para pesquisa!");
		eval("document." + formBusca + ".TxChave").focus();
		return false;
	}
}

function getPopPergunta(InCdAnuncio) {
	w = 550
	h = 300
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('pergunta.asp?BoOcultarMenu=1&InCdAnuncio=' + InCdAnuncio,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function xreplace(checkMe,toberep,repwith){
	var temp = checkMe;
	
	var i = temp.indexOf(toberep);
	
	while(i > -1) {
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	
	return temp;
}
function convertCurrency(str) {
	str = xreplace(str,".","");
	str = xreplace(str,",",".");
	return str
}

function getPopOferta(InCdAnuncio,DbValor,InQuantidade,BoAutoOferta) {
	w = 550
	h = 300
	DbValorMax = 10000000
	if(BoAutoOferta)
		BoAutoOferta = 1;
	else
		BoAutoOferta = 0;
		
	if(DbValor=='') {
		alert("Preencha um valor para sua oferta.");
		return false;
	}
	else {
		if(formulario.InQuantidadeDisp) {
			if(parseInt(InQuantidade) > parseInt(formulario.InQuantidadeDisp.value)) {
				alert("A quantidade de unidades ofertadas deve ser menor ou igual a quantidade disponível.")
				return false;
			}
		}
		else {
			if(formulario.DbValorMin) {
				frmDbValor = convertCurrency(DbValor);			
				frmDbValorMin = convertCurrency(formulario.DbValorMin.value);

				if(isNaN(frmDbValor)) {
					alert("O valor digitado deve ser numérico.");
					return false;
				}
				else {				
					if(parseFloat(DbValorMax*100) <= parseFloat(frmDbValor*100)) {
						alert("Valor máximo ultrapassado.");
						return false;
					}
					else if(parseFloat(frmDbValorMin*100) > parseFloat(frmDbValor*100)) {
						alert("A oferta deve ser maior que ser maior ou igual que " + formulario.DbValorMin.value + ".")
						return false;
					}
					else if(parseFloat(frmDbValorMin*100) == parseFloat(frmDbValor*100)) {
						BoAutoOferta = 0;
					}
				}
			}
		}
		var l = (screen.width - w) / 2
		var t = (screen.height - h - 60) / 2
		window.open('oferta.asp?BoOcultarMenu=1&BoAutoOferta=' + BoAutoOferta + '&InCdAnuncio=' + InCdAnuncio + '&DbValor=' + DbValor + '&InQuantidade=' + InQuantidade,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
	}
}

function getPopTipoVenda(InCdTipoVenda) {
	w = 400
	h = 240
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('tipo_venda.asp?InCdTipoVenda=' + InCdTipoVenda + '&BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAutoOferta() {
	w = 400
	h = 240
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('auto_oferta.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAjudaBusca() {
	w = 400
	h = 400
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('../ajuda_busca.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopTermosUso() {
	w = 772
	h = 500
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('textos/termos_uso.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopexemplodestaque() {
	w = 772
	h = 500
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('textos/exemplodestaque.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopPontuacao() {
	w = 400
	h = 240
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('pontuacao.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopSenha() {
	w = 400
	h = 200
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('esqueci_senha.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopQualificar(InCdAnuncio,InCdUsuario) {
	w = 450
	h = 400
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('qualificar.asp?BoOcultarMenu=1&InCdUsuario=' + InCdUsuario + '&InCdAnuncio=' + InCdAnuncio,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAlterarSenha() {
	w = 400
	h = 250
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('alterar_senha.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getImagem(TxImagem, w, h) {
	w += 40;
	h += 32;
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open(TxImagem,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function setDescadastroAnuncio(InCdAnuncio,TxTitulo,TxPersonalizado) {
	if (confirm("Você confirma o descadastramento do anúncio \"" + TxTitulo + "\" (código " + Right("00000" + InCdAnuncio,6) + ")?"))
		document.location.href = 'anuncio_lista.asp?InCdAnuncio=' + InCdAnuncio + '&acao=Descadastrar&TxPersonalizado=' + TxPersonalizado;
	else
		return false;
}
function setDescadastroAnuncioConfirm(InCdAnuncio,TxTitulo,TxPersonalizado) {
	if (confirm("Você confirma o descadastramento do anúncio \"" + TxTitulo + "\" (código " + Right("00000" + InCdAnuncio,6) + ")?\nEste anúncio possui lances. Caso você opte por descadastrá-lo, o usuário que está a frente das negociações\nreceberá seus dados para contato, lembrando que ambos receberão qualificações das partes."))
		document.location.href = 'anuncio_lista.asp?InCdAnuncio=' + InCdAnuncio + '&acao=Descadastrar&TxPersonalizado=' + TxPersonalizado;
	else
		return false;
}
function setProdutoEmVista(InCdAnuncio) {
	w = 550
	h = 300
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('produtoemvista.asp?BoOcultarMenu=1&InCdAnuncio=' + InCdAnuncio,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function setPaginaDados(TxPagina) {
	if(TxPagina!='')
		document.location.href = TxPagina;
}
function getExisteFotoAnuncio(objDestaque) {
	if(objDestaque.checked) {
		BoFoto = 0;
		for(j=1;j<=12;j++) {
			objFoto = document.getElementById('TxFoto' + j);
			if(objFoto) {
				if(objFoto.value!='')
					BoFoto += 1;
			}
		}
		return BoFoto
	}
	else
		return 10	
}
function setExisteFotoAnuncio(objDestaque,InFoto) {
	BoFoto = getExisteFotoAnuncio(objDestaque);
	if(BoFoto==0) {
		alert("O tipo de destaque selecionado só é permitido caso o seu produto tenha fotos!");
		objDestaque.checked = false;
	}
	else if (parseInt(BoFoto) < parseInt(InFoto)) {
		alert("O tipo de destaque \"Rotação da foto\" exige no mínimo " + InFoto + " fotos!");
		objDestaque.checked = false;
	}
}
function getReplica(InCdQualificacao) {
	objTd = document.getElementById("tdReplica" + InCdQualificacao);
	objTd.style.display = '';
}
function setReplica(InCdQualificacao) {
	objText = document.getElementById("TxReplica" + InCdQualificacao);
	if(objText.value=='') {
		alert("Campo obrigatório não preenchido!");
		objText.focus();
	}
	else
	{
		document.getElementById("InCdQualificacao").value = InCdQualificacao;
		document.formulario.submit();
	}
}
function chkFormQualificacao() {
	fl_checado = 0;
	
	
	for(i=1;i<=3;i++) {
		chkTipoQualificacao = document.getElementById("InCdTipoQualificacao" + i).checked;
		if(chkTipoQualificacao)
			fl_checado = 1;
	}
	if(fl_checado==0) {
		alert("Selecione um tipo de qualificacação: Positiva, Negativa ou Neutra.");
		return false;
	}
	else
		return true;
}
function naoPermiteAcento(obj,e)
{
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;

	if(key != 37 && key != 39 && key != 8 && key != 46 && key != 16) {
	    var str = new String(obj.value);
	    var acentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ');
	    var SemAcento = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');
	    var c = new String();
	    var i = new Number();
	    var x = new Number();
	    var res = '';
	    
	    for (i = 0; i<str.length; i++)
	    {
	        c = str.substring(i,i+1);
	        for (x=0; x< acentos.length; x++)
	        {
	            if (acentos.substring(x,x+1) == c)
	            {
	                c = SemAcento.substring(x,x+1);
	            }
	            
	        
	        }
	        res += c;
	    }
	    obj.value = res;
		
		deleteInvalidChar(obj);
	
	}
	
}
function deleteInvalidChar(obj)
{
    var str = new String(obj.value);
    var allowed = new String('1234567890-_.qwertyuiopasdfghjklzxcvbnm');
    var c = new String();
    var i = new Number();
    var x = new Number();
    var res = '';
    
    for (i = 0; i<str.length; i++)
    {
        c = str.substring(i,i+1);
		boPermitido = 0
        for (x=0; x< allowed.length; x++)
        {
            if (allowed.substring(x,x+1).toUpperCase() == c.toUpperCase())
            {
                boPermitido = 1
            }
            
        }
		if(boPermitido==1)
	        res += c;
    }
    obj.value = res.toUpperCase();
	
	
}
function setMinuscula(obj,e) {
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	if(key != 37 && key != 39 && key != 8 && key != 46 && key != 16)
		obj.value = obj.value.toLowerCase();
}



function getBoleto(InCdFatura) {
	window.open('financeiro_gerar_boleto.asp?InCdFatura=' + InCdFatura,"_blank");
}

function getPopFatura(InCdFatura) {
	w = 700
	h = 400
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('financeiro_lista_tarifas.asp?BoOcultarMenu=1&InCdFatura=' + InCdFatura,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAnuncioDestaque(InCdAnuncio, InCdFatura) {
	w = 450
	h = 300
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('financeiro_lista_destaques.asp?BoOcultarMenu=1&InCdAnuncio=' + InCdAnuncio + '&InCdFatura=' + InCdFatura,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAnuncioTaxa(InCdAnuncio,InCdFatura) {
	w = 450
	h = 300
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('financeiro_lista_taxas.asp?BoOcultarMenu=1&InCdFatura=' + InCdFatura + '&InCdAnuncio=' + InCdAnuncio,'_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function getPopAjudaTipoVenda() {
	w = 600
	h = 500
	
	var l = (screen.width - w) / 2
	var t = (screen.height - h - 60) / 2
	window.open('/textos/tipo_venda.asp?BoOcultarMenu=1','_blank','scrollbars=yes,resizible=no,toolbar=no,location=no,status=yes,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l)
}
function chkTipoFoto(objFoto) {
	if(objFoto.value!='') {
		if( Right(objFoto.value.toLowerCase(),3) != 'jpeg' && Right(objFoto.value.toLowerCase(),3) != 'jpg' && Right(objFoto.value.toLowerCase(),3) != 'gif' && Right(objFoto.value.toLowerCase(),3) != 'png' && Right(objFoto.value.toLowerCase(),3) != 'bmp') {
			alert("Tipo de arquivo inválido. Deve ser jpg, gif, png ou bmp. Selecione outro arquivo.");
			objFoto.value='';
		}
	}
}
function chkFormUsuario() {
	objTipoDocumento = document.getElementById("TxTipoDocumento");
	if(objTipoDocumento)
		TxTipoDocumento = objTipoDocumento.value;
		
	objDocumento 	= document.getElementById("TxDocumento");
	if(objDocumento)
		TxDocumento = objDocumento.value;
	else
		TxDocumento = '';
	
	TxEndereco 		= document.getElementById("TxEndereco").value;
	
	if(TxDocumento!='') {
		BoInvalido=0;
		if(TxTipoDocumento=='CPF') {
			if(!isCpf(TxDocumento))
				BoInvalido=1;
		}
		else if(TxTipoDocumento=='CNPJ') {
			if(!isCnpj(TxDocumento))
				BoInvalido=1;
		}
		if(BoInvalido==1) {
			alert(TxTipoDocumento + " inválido.");
			objDocumento.focus();
			return false;
		}
	}
	if(TxEndereco!='' && TxEndereco.length < 3) {
		alert("O campo endereço deve ter no mínimo 3 caracteres.");
		document.getElementById('TxEndereco').focus();
		return false;
	}
	return true;
}
function setTipoDocumento(TxTipoDocumento) {
	objTdTipoDocumento = document.getElementById('td_tipo_documento');
	if(objTdTipoDocumento)
		objTdTipoDocumento.innerHTML = TxTipoDocumento;
}