/////////////////////////////////////////////////////////
function numbersv(campo, eve){
  		 if(navigator.appName == "Netscape"){tecla = eve.which;}else{tecla = eve.keyCode;}
		 var camp = document.getElementById(campo);
		 if ((tecla != 8) && (tecla != 0) && (tecla != 44)  && (tecla <= 45 || tecla >= 58))
 		 {return false;}
 		 else return true}
//////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////		 
function numbers(campo, eve){
  		 if(navigator.appName == "Netscape"){tecla = eve.which;}else{tecla = eve.keyCode;}
		 var camp = document.getElementById(campo);
		 if ((tecla != 8) && (tecla != 0) && (tecla <= 46 || tecla >= 58))
 		 {return false;}
 		 else return true}
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////

function Formats(campo , string){ 
         //campo = nome do campo
		 //string = * divide as ocorrencias
		 // # divide entre o value.length do cmapo e o caractere que deve ser inserido
		 var camp = document.getElementById(campo);
		 strings = string.split("*");
		 for(i = 0; i < strings.length;i++){
		 str = strings[i].split("#");
		 keys = str[0];
		 isn = str[1];
		 if(camp.value.length == keys){camp.value += isn;}
		 }}	

///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////		 
startList = function() {
if(navigator.appName == "Microsoft Internet Explorer"){
var sfEls = document.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}

}





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

 if(navigator.appName == "Netscape"){nTecla = evtKeyPress.which;}else{nTecla = evtKeyPress.keyCode;}

 sValue = objForm[strField].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( " ", "" );
 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) == "/"))
 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++;
 }

 objForm[strField].value = sCod;

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

function contagem(exp1,time){
	     var total = 0;
	     for(i=0;i < time.length;i++){
			 if(time[i].indexOf(exp1) !== -1){total++;}}
			 return total;}
/////////////////////////////////////////////////////

function divs(ndiv,check){
	 if(check == 1){document.getElementById(ndiv).style.display = "none";}else{
			        document.getElementById(ndiv).style.display = "block";}
}
	     

/////////////////////////////////////////////////////

function checkfield1(forms,campo,val,str1,msg){
	     data2 = document.getElementById(campo).value;
		 if(contagem(str1,data2) != val){
	     alert(msg);
		 document.getElementById(campo).focus();
		 return false;}
		 else{
	     return true;}
		 
}

//////////////////////////////////////////////////////

function proximocampo(car,campo,campo2){
	     if(document.getElementById(campo).value.length == car){document.getElementById(campo2).focus();}
		 }
//////////////////////////////////////////////////////

function inserirtxt(campo,txt){
	     document.getElementById(campo).value += txt;
		 }
		 
//////////////////////////////////////////////////////		 

function FormataReais(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 == 8 || whichCode == 0) return true;

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 = 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 formatmoney(fld, milSep, decSep){

var fld = document.getElementById(fld);

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

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);

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 substr_reset(vars){
         var temp = new Array();
         var temp2 = new Array();		 
		 var nvar = "";
		 var nvar2 = "";
		 temp = vars.split(',');
		 for(i = 0;i < temp.length;i++){
		 nvar += temp[i];}
 		 temp2 = nvar.split('.');
		 for(i = 0;i < temp2.length;i++){
		 nvar2 += temp2[i];}
		 return nvar2;
		 }

function getcomi(val){
	     
		 val = substr_reset(val);
	     var comi = document.getElementById('comissao'+document.getElementById('marca').value).value;
		 comi = comi.replace(",",".");
		 nval = (val * comi) / 100;
		 //var brokenstring = longstring.split(".");
		 
		 document.getElementById("dia").value = nval;
		 formatmoney("dia", ".", ",");

		 document.getElementById("repasse").value = nval;
		 formatmoney("repasse", ".", ",");
		
}
	
	
function getrepasse(){
	     
		 var val = substr_reset(document.getElementById('venda').value);
	     var comi = document.getElementById('comissao'+document.getElementById('marca').value).value;
		 comi = comi.replace(",",".");
		 nval = (val * comi) / 100;
		 
		 var val2 = document.getElementById('pecas').value;
		 
	     var repa = document.getElementById('doacao'+document.getElementById('marca').value).value;
 		 nval2 = val2 * repa;
		 
		 
		 var nval3 = substr_reset(document.getElementById('doacao').value);
		 if(nval3 == ""){nval3 = 0;}
		 
         totals = parseInt(nval) + parseInt(nval2) + parseInt(nval3);
		 
		 document.getElementById("dia").value = nval;
		 formatmoney("dia", ".", ",");
         
		 //var brokenstring = longstring.split(".");
		 
		 document.getElementById("repasse").value = totals;
		 formatmoney("repasse", ".", ",");
		 
		 if(document.getElementById("repasse").value != '' && document.getElementById("venda").value != 11){
			 
		 totals = parseInt(substr_reset(document.getElementById('venda').value)) - parseInt(substr_reset(document.getElementById('repasse').value));
		 
		 document.getElementById("saldos").value = totals;
		 formatmoney("saldos", ".", ",");
		 
		 }
		
		
}	
	



