// JavaScript Document


// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}


function DoPrinting(){
window.print()
}

function validaNumero(tecla){
 if (!(isNumber(tecla)))
  {
   alert('Por favor, digite apenas números!');
  }
}

function Enter(tecla,objeto){
			alert("AAAAAAAAAAAAAAAAAAHhh eu to maluco !! ");
	if(tecla.keyCode== '13'){
			alert("AAAAAAAAAAAAAAAAAAHhh eu to maluco 222222222!! ");
			objeto.focus();		
	}	
}
function validaNumero_enter(tecla,objeto){
 if (!(isNumber(tecla)))
  {
	alert('Por favor, digite apenas números!');
  }else{
	if(tecla.keyCode== '13'){
//		alert('TESTE 21');
//		alert(document.form.cod_produto.value);
		if(document.form.cod_produto.value.substring(0,3) == "200"){
			//Entrou aqui pq tem é do leitor do codigo de barras, tenho que dividir a strig para aliementar a QTDE:
			lixo = document.form.cod_produto.value.substring(0,1);
			cod_prod = document.form.cod_produto.value.substring(1,5);
			//peso = document.form.cod_produto.value.substring(7,13);
			// Do peso(separa[2]) precisa serapra a parte decimal:
			inteiro = document.form.cod_produto.value.substring(7,9);
			decimal = document.form.cod_produto.value.substring(9,13);
			peso_certo = inteiro+"."+decimal;
			//tira os zeros a esquerda
			tira_zero = cod_prod.replace(/^0+/,"");
			document.form.cod_produto.value=tira_zero;	
			objeto.value=peso_certo;
			document.form.cod_produto.focus();
/*			
			alert('SACO');
			alert(lixo);
			alert(tira_zero);
//			alert(peso);
			alert(inteiro);			
			alert(decimal);	
			alert(peso_certo);				
*/
		}else{
			objeto.focus();
		}

/*
		procurar = " ";
		if(document.form.cod_produto.value.search(procurar) != -1){
			//Entrou aqui pq tem Espaco em branco no Codigo de produto, entao é Cod.Barras, tenho que dividir a strig para aliementar a QTDE:
			separa = document.form.cod_produto.value.split(" ");
			tira_zero = separa[1].replace(/^0+/,"");
			document.form.cod_produto.value =tira_zero;
			// Do peso(separa[2]) precisa serapra a parte decimal:
			inteiro = separa[2].substring(0,2);
			decimal = separa[2].substring(2,6);
			peso = inteiro+"."+decimal;
			objeto.value=peso;
			document.form.cod_produto.focus();
		}else{
			objeto.focus();
		}
*/
}
  }
}

function validaNumeroDecimal(tecla){
 if (!(isNumberDecimal(tecla)))
  {
   alert('Por favor, digite apenas números e vírgula!');
  }

}

function validaNumeroDecimal_enter(tecla){
 if (!(isNumberDecimal(tecla)))
  {
   alert('Por favor, digite apenas números e vírgula!');
  }else{
	if(tecla.keyCode== '13'){
//		alert("objeto");	
		objeto.focus();
	}
  }
}

function isNumberDecimal_2(tecla){
//alert(tecla.keyCode);
 if ((!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '127' || tecla.keyCode == '46' || tecla.keyCode== '13')) )
  {
   return false;
  }
return true;
}
function validaNumeroDecimal_2(tecla){
 if (!(isNumberDecimal_2(tecla)))
 {
	if(tecla.keyCode == '44'){
	 	alert('Sr(a) Caixa, Utilize PONTO para valores Decimais !');		
	}else{
		tecla.keyCode = '127';
		alert('Sr(a) Caixa, digite apenas Números!');
	}
}

}

function isNumberDecimal(tecla){
//alert(tecla.keyCode);
 if ((!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '127' || tecla.keyCode == '44' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}

function isNumber(tecla){
//alert(tecla.keyCode);
 if ( (!(tecla.keyCode >= '48' && tecla.keyCode <= '57')) && (!(tecla.keyCode == '127' || tecla.keyCode== '13')) )
  {
   tecla.keyCode = '127';
   return false;
  }
return true;
}
//E-MAIL
function valida_email(elm) {
if (elm.value.indexOf("@") != "-1" &&
        elm.value.indexOf(".") != "-1" &&
        elm.value.indexOf("@.") == "-1" &&
        elm.value.indexOf(".br.") == "-1" &&
        elm.value.indexOf("\"") == "-1" &&
        elm.value.indexOf(" ") == "-1" &&
        elm.value.indexOf("'") == "-1" &&
        elm.value.indexOf(";") == "-1" &&
        elm.value.indexOf(",") == "-1" &&
        elm.value.indexOf("{") == "-1" &&
        elm.value.indexOf("}") == "-1" &&
        elm.value.indexOf("[") == "-1" &&
        elm.value.indexOf("]") == "-1" &&
        elm.value.indexOf("<") == "-1" &&
        elm.value.indexOf(">") == "-1" &&
        elm.value.indexOf("?") == "-1" &&
        elm.value.indexOf("|") == "-1" &&
        elm.value.length > 5 )
return false;
else return true;
}

function popup(name, url, width, height)
{
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;

	name_str = name ? name : "";
	toolbar_str = false ? 'yes' : 'no';
	menubar_str = false ? 'yes' : 'no';
	statusbar_str = false ? 'yes' : 'no';
	scrollbar_str = true ? 'yes' : 'no';
	resizable_str = false ? 'yes' : 'no';
	fullscreen_str = false ? 'yes' : 'no';
	var myWin = window.open(url, name_str, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str+',fullscreen='+fullscreen_str);
	myWin.focus()
	return myWin

/*
	return window.open(url, name_str, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str+',fullscreen='+fullscreen_str);
	widow.focus()
*/
;
}//popup
function fecha(){
	self.close();
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58 || tecla == 0)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function SomenteNumeroDecimal(e){
    var tecla=(window.event)?event.keyCode:e.which;
	//alert(tecla);
	// 46 = (.) ponto
	// 0 = (.) tab	
    if((tecla > 47 && tecla < 58) || tecla == '46' || tecla == 0) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function Mascara (formato, keypress, objeto){
campo = eval (objeto);

// cep
	if (formato=='cep'){
		separador = '-';
		conjunto1 = 5;
		if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;}
	}

// cpf
	if (formato=='cpf'){
		separador1 = '.';
		separador2 = '-';
		conjunto1 = 3;
		conjunto2 = 7;
		conjunto3 = 11;
		if (campo.value.length == conjunto1)
		  {
		  campo.value = campo.value + separador1;
		  }
		if (campo.value.length == conjunto2)
		  {
		  campo.value = campo.value + separador1;
		  }
		if (campo.value.length == conjunto3)
		  {
		  campo.value = campo.value + separador2;
		  }
	}

// nascimento
	if (formato=='nascimento'){
		separador = '/';
		conjunto1 = 2;
		conjunto2 = 5;
		if (campo.value.length == conjunto1)
		  {
		  campo.value = campo.value + separador;
		  }
		if (campo.value.length == conjunto2)
		  {
		  campo.value = campo.value + separador;
		  }
	}

	// telefone
	if (formato=='telefone'){
		separador1 = '(';
		separador2 = ')';
		separador3 = '-';
		conjunto1 = 0;
		conjunto2 = 3;
		conjunto3 = 8;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador1;
		}
		if (campo.value.length == conjunto2){
			campo.value = campo.value + separador2;
		}
		if (campo.value.length == conjunto3){
			campo.value = campo.value + separador3;
		}
	}
// moeda
	if (formato=='moeda'){
		separador = '.';
		conjunto1 = 2;
		if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;}
	}

}

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;  // BackSpace
if (whichCode == 0) return true;  // DEL TAB
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;
}

//MÁSCARA DE VALORES

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }

