//------------------------------
// uso:
  //onKeyPress="return funcao(event.keyCode)"
function funcao(k)
    {
        if(!(k >= 97 && k <= 122) && k != 95 && !(k <= 65 && k >= 90) && !(k >= 48 && k <= 57))
        {
            return false;
        }
    }

function numero_virgula(k)
    {
    //alert(''+k+'');
        if(!(k >= 48 && k <= 57) && !(k == 44))
        {
            return false;
        }
    }

function numero(k)
    {
        if(!(k >= 48 && k <= 57))
        {
            return false;
        }
    }
    
function SoNum(event) {  
    var tecla = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    // numeros de 0 a 9, backspace, delete, setas
	if((tecla > 47 && tecla < 58) || tecla == 8 || tecla == 46 || (tecla > 36 && tecla < 49)) return true; 
    return false;
}
    
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve ser um endereço de email válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve ser um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve ser um numero entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  } if (errors) alert('Verifique os seguintes campos:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

		function MM_jumpFunction(selObj,restore){ //v1.0 by moraes.leo@bol.com.br
		 //alert(selObj.options[selObj.selectedIndex].value);
		   eval(selObj.options[selObj.selectedIndex].value);
		   if (restore) selObj.selectedIndex=0;
		}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


//http://www.msdnbrasil.com.br/forum/ShowPost.aspx?PostID=11207
//http://www.evandroaraujo.cjb.net

function DPSCheckData(Valor, Mascara){
Mascara = Mascara.toUpperCase();

var separador = Mascara.substr(Mascara.indexOf("MM")+2,1);
var arrayData = Valor.split(separador);
var PosDia, PosMes, Meses;
var expressao, Numero;
var erro = false;

//setando as posições e a expressão regular
if (Mascara.indexOf("DD")==0) {
PosDia = 0; PosMes = 1;
if (Mascara.indexOf("YYYY")!=-1)
expressao = new RegExp("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/[12][0-9]{3}$");
else
expressao = new RegExp("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/[0-9]{2}$");

Numero = arrayData[0] +"/"+ arrayData[1] +"/"+ arrayData[2];
}
else {
PosDia = 1; PosMes = 0;
if (Mascara.indexOf("YYYY")!=-1)
expressao = new RegExp("^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/[12][0-9]{3}$");
else
expressao = new RegExp("^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/[0-9]{2}$");

Numero = arrayData[0] +"/"+ arrayData[1] +"/"+ arrayData[2];
}

if (expressao.test(Numero)) {
//Verificando se o ano é bissexto ou não e gerando o array de dias de cada mes
if (arrayData[2] % 100 == 0)
Meses = (arrayData[2] % 400 == 0) ? new Array(31,29,31,30,31,30,31,31,30,31,30,31) : new Array(31,28,31,30,31,30,31,31,30,31,30,31);
else
Meses = (arrayData[2] % 4 == 0) ? new Array(31,29,31,30,31,30,31,31,30,31,30,31) : new Array(31,28,31,30,31,30,31,31,30,31,30,31);

//Verificando se o dia está de acordo com o mês
erro = (arrayData[PosDia]>Meses[arrayData[PosMes]-1]) ? true : false;
}
else {
erro = true;
}

return(!erro);
}

//Verifica se a data1 é maior ou igual que a data 2
function datamaiorigual(dt1,dt2)
{
var hoje = new Date();
var ano = hoje.getYear();
if(ano >= 50 && ano <= 99)
ano = 1900 + ano
else
ano = 2000 + ano;

var pos1 = dt1.indexOf("/",0)
var dd = dt1.substring(0,pos1)
pos2 = dt1.indexOf("/", pos1 + 1)
var mm = dt1.substring(pos1 + 1,pos2)
var aa = dt1.substring(pos2 + 1,10)
if(aa.length < 4)
if(ano > 1999)
aa = (2000 + parseInt(aa,10))
else
aa = (1900 + parseInt(aa,10));
var data1 = new Date(parseInt(aa,10),parseInt(mm,10) - 1, parseInt(dd,10));
var pos1 = dt2.indexOf("/",0)
var dd = dt2.substring(0,pos1)
pos2 = dt2.indexOf("/", pos1 + 1)
var mm = dt2.substring(pos1 + 1,pos2)
var aa = dt2.substring(pos2 + 1,10)
if(aa.length < 4)
if(ano > 80 && ano <= 99)
aa = (1900 + parseInt(aa,10))
else
aa = (2000 + parseInt(aa,10));
var data2 = new Date(parseInt(aa,10),parseInt(mm,10) - 1,parseInt(dd,10));

if(data1 >= data2)
return true;
else
return false;
}


//------------------------------>


function ocultar(nome) {
    if (document.getElementById) {
        document.getElementById(nome).style.display = "none";
    } else if (document.all) {
        document.all[nome].style.display = "none";
    } else if(document.layers) {
        document[nome].style.display = "none";
    }
}

function mostrar(nome) {
    if (document.getElementById) {
        document.getElementById(nome).style.display = "";
    } else if (document.all) {
        document.all[nome].style.display = "";
    } else if(document.layers) {
        document[nome].style.display = "";
    }
}

//funcao necessaria para encontrar e alterar o conteudo do ID
//mygetElement('formContato').innerHTML = ' ';
function mygetElement(id) {
    if (document.getElementById) {
      return document.getElementById(id);
    } else if (document.all) {
      return document.all[id];
    } else if(document.layers) {
      return document[id];
    }
}

function buscaCodigo(frm){
	location.href='http://www.mardejurereimoveis.com.br/busca_por:'+frm.('code_clim').value;
}