function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function menu_left()
{
if(screen.width=='800')
{
comprar.style.left='22px'
vender.style.left='22px'
empresa.style.left='335px'
credito.style.left='281px'
}

if(screen.width=='1024')
{
comprar.style.left='133px'
vender.style.left='133px'
empresa.style.left='448px'
credito.style.left='393px'
}

if(screen.width=='1280')
{
comprar.style.left='260px'
vender.style.left='260px'
empresa.style.left='576px'
credito.style.left='522px'
}
}

function checkbusca(form)
{
	if(form.busca.value=='' || form.busca.value=='anúncios')
	{
	alert('Digite alguma palavra.');
	form.busca.focus();
	return false;
	}
}




//PopUp Gerenciador de fotos
function pop_gerenciador_foto(url){
	window.open(url,'pop_gerenciador_foto','width=500,height=300,left='+((screen.width*0.5)-250)+',top='+((screen.height*0.5)-150)+'');
}

function mCima(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'hand';
  src.bgColor = clrOver;
  src.color = 'black'
 }
}

function mFora(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}

function mClica(src) {
 window.location=(src)

}

function moeda(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
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 checacpf (cpf) 
{
if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
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)))
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)))
return false;
return true;
}


function mandacpf(x){
var numero = document.formcpf.xcpf.value
numero=x

if(numero!='CPF' && numero!=''){

if (checacpf(numero)) 
	{}else 
	{alert('CPF invalido!');
	document.form.cpf.focus();
	return false;}

document.formcpf.xcpf.value = x
document.formcpf.submit();
}
}




function mandacep(x){

if(document.form.cep.value.length != 8)
	{
		alert('Cep inválido!');
		document.form.cep.focus();
		return false;
	}
document.formcep.xcep.value = x
document.formcep.submit();
document.form.cep.value='Pesquisando...'
}



function checacnpj(pcnpj)
 {
       // verifica o tamanho
 if (pcnpj.length != 14) {
  sim=false
  //alert ("Tamanho Invalido de cnpj")
  return false;
  }
 else {sim=true}

  if (sim )  // verifica se e numero
  {
  for (i=0;((i<=(pcnpj.length-1))&& sim); i++)
  {
   val = pcnpj.charAt(i)
       // alert (val)
   if
((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }
   if (sim)  // se for numero continua
   {
    m2 = 2
    soma1 = 0
    soma2 = 0
    for (i=11;i>=0;i--)
    {
     val = eval(pcnpj.charAt(i))
       // alert ("Valor do Val: "+val)
     m1 = m2
  if (m2<9) { m2 = m2+1}
  else {m2 = 2}
  soma1 = soma1 + (val * m1)
  soma2 = soma2 + (val * m2)
    }  // fim do for de soma

  soma1 = soma1 % 11
  if (soma1 < 2) {  d1 = 0}
   else { d1 = 11- soma1}

     soma2 = (soma2 + (2 * d1)) % 11
  if (soma2 < 2) { d2 = 0}
   else { d2 = 11- soma2}
        // alert (d1)
       // alert (d2)
    if ((d1==pcnpj.charAt(12)) && (d2==pcnpj.charAt(13)))
   { 
   return true;   
    }
   else //alert("CCG inválido!")
   return false;
   }
 }
}


function mandacnpj(x){
var numero = document.formcnpj.xcnpj.value
numero=x

if(numero!='CNPJ' && numero!=''){

if (checacnpj(numero)) 
	{}else 
	{alert('CNPJ invalido!');
	document.form.cnpj.focus();
	return false;}

document.formcnpj.xcnpj.value = x
document.formcnpj.submit();
}
}

function mensagem(){

var msg = confirm('Você realmente forneceu todas as informações sobre seu anúncio?');

if(msg)
{
document.form.submit();
}else{
return false;
}
}

function abre_form_credito(param)
{
	var w = screen.width - 10
	var h = screen.height - 55
	window.open('../includes/form_credito.asp?'+param,'popcredito','width='+w+',height='+h+',left=0,top=0,scrollbars=yes');
}