// ****************************************************************************
//
// Funcoes disponiveis neste arquivo:
//
//
//    // Mostra a imagem e seu icone em ima nova janela
//
//    MostraImagem(id)
//        id = ID da imagem referente a tabela MODELOS_FOTOS
//
//    // Checa se os caracteres digitados no TEXTBOX (Campo) já possui o
//    // tamanho maximo indicado por (Maximo). Se sim, manda o foco para
//    // o objeto indicado por (VaiPara)
//
//    VerificaEntrada(Campo, Maximo, VaiPara)
//        Campo = Campo a ser checado
//        Maximo = Numero máximo de caracteres para este campo
//        VaiPara = Proximo objeto que receberá o foco do cursor
//
//
//    // Verifica se o caracter é um dígito (NUMERO)
//
//    isDigit(i)
//        i = caracter a ser verificado
//        <- Retorna Verdadeiro ou Falso
//
//
//    // Verifica se uma string é um valor numérico
//
//    isNumber(txt)
//        txt = string a ser verificada
//        <- Retorna Verdadeiro ou Falso
//
//
//    // Verifica se a string passada é uma data válida no formato 'dd/mm/yyyy'
//
//    function isDate(dt)
//        dt = string a ser verificada
//        <- Retorna Verdadeiro ou Falso
//
//
//    // Verifica se string passada é um valor numérico do tipo 99,99
//    function isCurrency(valor)
//        valor = string a ser verificada
//        <- Retorna Verdadeiro ou Falso
//
// ****************************************************************************

// checa se dado entrada no TEXTBOX (toCheck) já tem o tamanho
// máximo indicado por maxChar. Se alcançou o tamanho máximo,
// manda o focus para o objeto indicado por toGo.
function TrocaFocus(toCheck,maxChar,toGo) {
	var texto = toCheck.value;
	if(texto.length == maxChar) {
		toCheck.blur();
		if( toGo != null ) {
			toGo.focus();
			if( toGo.type == 'text' )
				toGo.select();
		}
	}
}


function VerificaEntrada(Campo,Maximo,VaiPara) {
	var texto = Campo.value;
	if(texto.length == Maximo) {
		Campo.blur();
		if( VaiPara != null ) {
			VaiPara.focus();
			if( VaiPara.type == 'text' )
				VaiPara.select();
		}
	}
}

function isDigit(i) {
	if( i >= '0' && i <= '9' )
		return true;
	else
		return false;
}

function isNumber(txt) {
	var j = 0;
	for(j=0;j<txt.length;j++) {
		if( !isDigit(txt.substring(j,j+1)) )
			return false;
	}
	return true;
}

function isDate(dt) {
	var i = 0;
	var dia = 0;
	var mes = 0;
	var ano = 0;
	if( dt.length == 10 ) {
		dia = (dt.substring(0,1)*10) + (dt.substring(1,2)*1);
		mes = (dt.substring(3,4)*10) + (dt.substring(4,5)*1);
		ano = (dt.substring(6,7)*1000) + (dt.substring(7,8)*100) + (dt.substring(8,9)*10) + (dt.substring(9,10)*1);

		if( (dia >= 1 && dia <= 31) && (mes >= 1 && mes <= 12) && (ano >= 1900 && ano <= 3000) ) {
			if( dt.substring(2,3) == "/" && dt.substring(5,6) == "/" ) {
				return true;
			}
		}
	}
	return false;
}

function isCurrency(valor) {
	var j = 0;
	var pto = 0;
	for(j=0;j<valor.length;j++) {
		if( valor.substring(j,j+1) == "," ) {
			pto++;
		}
		
		if( pto > 1 ) {
			return false;
		}

		if( !isDigit(valor.substring(j,j+1)) && (valor.substring(j,j+1) != ",") ) {
			return false;
		}
	}
	return true;
}

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_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_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];}
}

function AbreLineUp(arquivo) {
	window.open(arquivo,'LineUp','width=336,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no')
}

function AbrePopUp(arquivo,largura,altura,scroll) {
	data = new Date();
	numero = data.getSeconds();
	window.open(arquivo,'PopUp'+numero,'width='+altura+',height='+largura+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no')
}
