/* ------------------------------------------------------------------------------ */
/* Copyright Sentido Virtual - http://www.sentidovirtual.com.br ----------------- */
/* contato@sentidovirtual.com.br ------------------------------------------------ */
/* ------------------------------------------------------------------------------ */


window.defaultStatus="ANDRÉ CENCIN -  Leiloeiro Oficial"



/* ------------------------------------------------------------------------------ */
/* Funções Dreamweaver ---------------------------------------------------------- */
/* ------------------------------------------------------------------------------ */
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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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];}
}



/* ------------------------------------------------------------------------------ */
/* Abre janela PopUp ------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
function OpenUp(resenha, w, h)
{
	remote = window.open(resenha,'comentario','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,width='+ w + ',height='+ h + '')
}



/* ------------------------------------------------------------------------------ */
/* abrir link de popup na janela atual  ----------------------------------------- */
/* ------------------------------------------------------------------------------ */
function go(pag)
{
	top.opener.top.location.href=pag;
	window.self.close();
}



/* ------------------------------------------------------------------------------ */
/* Verifica campo vazio no formulário ------------------------------------------- */
/* ------------------------------------------------------------------------------ */
function isFieldBlank(theField)
{
	inStr = theField.value;
	inLen = inStr.length;
	for(var i = 0; i < inLen; i++)
	{
		var ch = inStr.substring(i, i+1)
		if (ch != " ")
		return false;   
	}
	theField.Value = "";
	return true;
}



/* ------------------------------------------------------------------------------ */
/* Verifica caracter inválido em formulário ------------------------------------- */
/* ------------------------------------------------------------------------------ */
function Verifica()
{
	var caract = new RegExp(/^[a-z 0-9 ç ã á ê é í ó ü ú]+$/i); 
	var caract = caract.test(String.fromCharCode(event.keyCode));

	if(!caract){
		//alert("Caracter inválido.\n" +String.fromCharCode(event.keyCode));
		event.keyCode=0;
		return;
	}
}



/* ------------------------------------------------------------------------------ */
/* validação para qtd de caracters no campo  ------------------------------------ */
/* ------------------------------------------------------------------------------ */
function minLen(txtField, minVal)
{
	strExp = txtField.value;
	l = strExp.length;
	if (l < minVal)
		return(true);
	else
		return(false);
}



/* ------------------------------------------------------------------------------ */
/* restringe somente caracteres numéricos  -------------------------------------- */
/* ------------------------------------------------------------------------------ */
function key()
{
	theKey = event.keyCode;
	if ((theKey < 48) ||
	(theKey > 57))
	event.returnValue = false;
}



/* ------------------------------------------------------------------------------ */
/* função utilizada em formulário para aceitar somente entrada de números ------- */
/* ------------------------------------------------------------------------------ */
function soNumero(event)
{
	iKey = KeyStroke( event );
	if (!( ( iKey>47 && iKey<58 ) || iKey == 13 || iKey == 0 || iKey == 8 ) )
	{
		return false;
	}
	return true;
}

function KeyStroke( event )
{
	ikey = 0;
	if( event.which == undefined )
	{
		ikey = window.event.keyCode;
	}
	else
	{
		ikey = event.which;
	}
	return ikey;
}



/* ------------------------------------------------------------------------------ */
/* função utilizada para 'saltar' os campos quando o maxlength é atingido ------- */
/* ------------------------------------------------------------------------------ */
function DFchangeField(o,e) {
	if(window.event)key=window.event.keyCode;
	else if(e)key=e.which;
	else return true;
	if (key==9||key==2||key==16) return false;
	// Vai
	if(o.value.length==o.maxLength){
  		for(var i=0;i<o.form.length;i++){
			if(o.form[i]==o && o.form[i+1]){
	    		if (!o.form[i+1].disabled && o.form[i+1].type != "hidden" && o.form[i+1].style.display != "none") {
					o.form[i+1].focus();
					return true;
				}else{
					return false;
				}
	    	}
		}
	}
	// Volta
	if(o.value.length == 0 && key == 8){
  		for(var i=0;i<o.form.length;i++){
    		if(o.form[i]==o && o.form[i-1]){
				if (!o.form[i-1].disabled && o.form[i-1].type != "hidden" && o.form[i+1].style.display != "none") {
					setTimeout("document." + o.form.name + "[" + (i-1) +"].focus()",10);
    				o.form[i-1].value = o.form[i-1].value;
    				return;
    			}else{
					return;
				}
			}
		}
	}
}



/* ------------------------------------------------------------------------------ */
/* validação de CPF  ------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
function valida_CPF(s)
{
	var f, s2='';
	for (f = 0; f<=s.length; f++) {
		if ((s.charAt(f) != ".") && (s.charAt(f) != "/") && (s.charAt(f) != "-")) {
			s2 += s.charAt(f);
		} 
	}
	s=s2;

	var i;
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++){
    		d1 += c.charAt(i)*(10-i);
   	}
	if (d1 == 0) return false;
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1){
		return false;
    }
    
    d1 *= 2;
    for (i = 0; i < 9; i++){
    	d1 += c.charAt(i)*(11-i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1){
		return false;
    }
    document.formcad.cpf.value = s
		return true;
}



/* ------------------------------------------------------------------------------ */
/* validação de CNPJ  ----------------------------------------------------------- */
/* ------------------------------------------------------------------------------ */
function valida_CGC(s)
{
	var f, s2='';

	for (f = 0; f<=s.length; f++) {
		if ((s.charAt(f) != ".") && (s.charAt(f) != "/") && (s.charAt(f) != "-")) {
			s2 += s.charAt(f);
		} 
	}
	s=s2;

	var i;
	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) return false;
	d1 = 11 - (d1 % 11);
   	if (d1 > 9) d1 = 0;
   	if (dv.charAt(0) != d1){
   		return false;
   	}
	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){
		return false;
    }
    document.formcad.cnpj.value = s
		return true;
}



// ********************************************************************************
function checaCEP()
{
	var cep = document.formcad.cep1.value;
	cep += document.formcad.cep2.value;
	if (cep.length > 7)
	{
		openCEP(cep);
	}
}



// ********************************************************************************
function openCEP(cep)
{
	cep=window.open('cep.asp?cep='+cep , 'cep', 'width=1,height=1');
}



// ********************************************************************************
// validação para entrada de formato moeda
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, 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;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}



/* ------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
