function showwinRPT(frm){

    var strFeatures = "height=320,"    +
                      "location=no,"   +
                      "menubar=yes,"   +
                      "width=690,"     +
                      "scrollbars=yes,"+
                      "toolbar=yes,"   +
                      "resizable=yes"  ;
    window.open("waitRPT?frm="+frm.name,frm.action,strFeatures);
    
    return frm.action;
    
}            

function cfloat(num){
	if(num.toString().length==0) num = 0;
	num = new String(num);	
	num = num.replace('.','');
	num = num.replace('.','');
	num = num.replace('.','');
	num = num.replace('.','');
	num = num.replace('.','');	
	num = num.replace(',','.');
	return Number(num); //+ 0.000000000001;
}

function formatDec(num,dec){	
	if(isNaN(num)|| num==0 ) return '';
	var numaux='',iaux=0; 
	var flgDot = 0;
    num = num + 0.005;
    window.status = "1: 0.0005";
	for(var i=0;i<num.toString().length;i++){
		if(num.toString().substr(i,1)!='.'){
			if(!flgDot){
				numaux+=num.toString().substr(i,1);
			}
			else if(iaux<dec){
				numaux+=num.toString().substr(i,1);
				iaux++;
			}
		}
		else{
			flgDot = 1 ;
			numaux+=',';
		}		
	}
	if(!flgDot)
	  	numaux+=',';
	for(var i=0;i<(dec-iaux);i++)
		numaux+='0';	
    if (dec == 0 ) numaux = numaux.replace(",","");    
	return numaux;
}

function toNum(p1){
    var retorno = "";
    for(var i=0 ; i < String(p1).length ; i++){
        if( !isNaN(String(p1).substr(i,1)) ){
            retorno = retorno + String(p1).substr(i,1);
        }
    }
    return retorno
}

function valida_CPF(p1){
    var i;
    var s = toNum(p1);
    var c = s.substr(0,9);
    var dv = s.substr(9,2);
    var d1 = 0;			 
    var dv1 = "";
    	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;	
    	alert(d1)
    	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;						
    	alert(d1);
    	if (dv.charAt(1) != d1){
    		return false;
    	}
    	return true;
}

function runTab(pdv,id){
    var cdivD = pdv.parentNode.childNodes;
    var cTblDivDados;
    var j = -1;
    for(var i = 0;i < cdivD.length;i++){
        if (cdivD[i].id=="divD") cdivD[i].className = "divFLDI";
        else if(cdivD[i].id=="tblDivDados") {
            if(navigator.appName=="Netscape")
                cTblDivDados = cdivD[i].childNodes[1].childNodes[0].childNodes[1].childNodes;
            else
                cTblDivDados = divDados;
        }
    }
    
    pdv.className = "divFLDA";
    
    for(var i=0 ;  i < cTblDivDados.length;i++){
        if(cTblDivDados[i].id=="divDados") j++;
        if(j==id){
            cTblDivDados[i].className="DivDadosA";
            if(id==1){
                if(document.getElementsByName("ifrmFormacCandidato").item(0).src.length==0){
                    document.getElementsByName("ifrmFormacCandidato").item(0).src="sbccw00101.wspx";
                }
            }            
            if(id==2){
                if(document.getElementsByName("ifrmCursos").item(0).src.length==0){
                    document.getElementsByName("ifrmCursos").item(0).src="sbccw00102.wspx";
                }
            }            
            if(id==3){
                if(document.getElementsByName("ifrmExpInst").item(0).src.length==0){
                    document.getElementsByName("ifrmExpInst").item(0).src="sbccw00103.wspx";
                }
            }            
            if(id==4){
                if(document.getElementsByName("ifrmExpProf").item(0).src.length==0){
                    document.getElementsByName("ifrmExpProf").item(0).src="sbccw00104.wspx";
                }
            }            
            if(id==5){
                if(document.getElementsByName("ifrmExpCons").item(0).src.length==0){
                    document.getElementsByName("ifrmExpCons").item(0).src="sbccw00105.wspx";
                }
            }            
            if(id==6){
                if(document.getElementsByName("ifrmExpOutr").item(0).src.length==0){
                    document.getElementsByName("ifrmExpOutr").item(0).src="sbccw00106.wspx";
                }
            }            
            if(id==7){
                if(document.getElementsByName("ifrmServ").item(0).src.length==0){
                    document.getElementsByName("ifrmServ").item(0).src="sbccw00107.wspx";
                }
            }            

        }
        else{
            cTblDivDados[i].className="DivDadosI";            
        } 
            
    
    }    
    

}


function selectTR(pTr,pbtnSufix){
    
    var cTR = pTr.parentNode.rows;
        
    for(var i = 1; i < cTR.length; i++){
        cTR.item(i).className = "trBrowser";
    }
    
    pTr.className="trBrowserSel";
        
    btnD = window.parent.document.getElementsByName("btn_del"+pbtnSufix).item(0);
    btnU = window.parent.document.getElementsByName("btn_upd"+pbtnSufix).item(0);
    
    btnD.disabled=0;
    btnU.disabled=0;
    
    
    
    btnD.id=btnU.id=pTr.id;
}

function selectTR2(pTr,pNrPedido){
    
    var cTR = pTr.parentNode.rows;
        
    for(var i = 1; i < cTR.length; i++){
        cTR.item(i).className = "trBrowser";
    }
    
    pTr.className="trBrowserSel";
    
    parent.document.forms[0].nrPedido.value = pNrPedido;        
    parent.viewedFolder[1] = -1;
    parent.viewedFolder[2] = -1;
    parent.viewedFolder[3] = -1;                


}

function selectTR3(pTr){
    
    var cTR = pTr.parentNode.rows;
        
    for(var i = 1; i < cTR.length; i++){
        cTR.item(i).className = "trBrowser";
    }
    
    pTr.className="trBrowserSel";
    

}

function selectTRBrw(pTr){
    
    var cTR = pTr.parentNode.rows;
        
    for(var i = 1; i < cTR.length; i++){
        cTR.item(i).className = "trBrowser";
    }
    
    pTr.className="trBrowserSel";
        
}






function copyValue(pTr, pFld, pFldLabel){
    pFld.value       = pTr.cells(1).innerText;
    pFldLabel.value  = pTr.cells(2).innerText;
    pFld.focus();
}






function regCreate(pUrl){
    vAltura = 188;
    if(navigator.appName=="Netscape"){
        var strFeatures = 'height='+vAltura+'px,'+
                          'width=690px,' +                          
                          'resizable=no,'+
                          'menubar=no,'+
                          'location=no,'+
                          'dependent=yes,'+
                          'alwaysRaised=yes,'+
                          'scrollbars=no';
        window.open(pUrl+'?v_action=insert',"form",strFeatures)
    }    
    else if(navigator.appName=="Microsoft Internet Explorer"){
        if(navigator.userAgent.indexOf("Opera")>-1){
            var strFeatures = 'height='+String(Number(vAltura)+30)+'px,'+
                              'width=690px,' +                          
                              'resizable=no,'+
                              'menubar=no,'+
                              'location=no,'+
                              'dependent=yes,'+
                              'alwaysRaised=yes,'+
                              'scrollbars=no';
                              
            window.open(pUrl+'?v_action=insert',"form",strFeatures)
        
        }
         else{
            var strFeatures = 'dialogHeight:'+String(Number(vAltura)+50)+'px;'+
                              'dialogWidth:690px;' +
                              'center:yes;' +
                              'help:no;' +
                              'resizable:no;'+
                              'scroll:no';														
            window.showModalDialog(pUrl+'?selTipoPedido='+'0'+'&cod_emitente='+document.frm1.txtCodCliente.value+"&v_action=insert",self,strFeatures);
        }
    }
}

function regUpdate(pUrl,pRowId){    
    vAltura = 188;
    if(navigator.appName=="Netscape"){
        var strFeatures = 'height='+vAltura+'px,'+
                          'width=690px,' +                          
                          'resizable=no,'+
                          'menubar=no,'+
                          'location=no,'+
                          'dependent=yes,'+
                          'alwaysRaised=yes,'+
                          'scrollbars=no';
        window.open(pUrl+'?v_action=update&rowid='+pRowId,"form",strFeatures)
    }    
    else if(navigator.appName=="Microsoft Internet Explorer"){
        if(navigator.userAgent.indexOf("Opera")>-1){
            var strFeatures = 'height='+String(Number(vAltura)+30)+'px,'+
                              'width=690px,' +                          
                              'resizable=no,'+
                              'menubar=no,'+
                              'location=no,'+
                              'dependent=yes,'+
                              'alwaysRaised=yes,'+
                              'scrollbars=no';
                              
            window.open(pUrl+'?v_action=update&rowid='+pRowId,"form",strFeatures)
        
        }
        else{

    
            var strFeatures = 'dialogHeight:'+String(Number(vAltura)+50)+'px;'+
                              'dialogWidth:690px;' +
                              'center:yes;' +
                              'help:no;' +
                              'resizable:no;'+
                              'scroll:no';
            window.showModalDialog(pUrl+'?v_action=update&rowid='+pRowId,self,strFeatures);
        }
    }
}

function regDelete(btn1,btn2,pUrl,pRowId,pIfrm){
    if(confirm('Aten\u00e7\u00e3o, confirma exclus\u00e7o do registro ?')){
        
        btn1.id        = btn2.id       = '';
	     btn1.disabled = btn2.disabled = 1; 
        
        pIfrm.location = pUrl+'?v_action=delete&rowid='+pRowId;
    }
}


function doClickTipPrec(pRd){
    if(pRd.value=='inf'){
    
        pRd.form.txtNrTabPrec.className = 'disabled';
        pRd.form.txtDesTabPrec.className = 'disabled';
    
        pRd.form.txtNrTabPrec.disabled = 1;
        pRd.form.txtDesTabPrec.disabled = 1;            
        
    }
    else if(pRd.value=='tab'){
    
        pRd.form.txtNrTabPrec.className = 'enabled';
        pRd.form.txtNrTabPrec.className = 'zoom';
        pRd.form.txtDesTabPrec.className = 'enabled';
                    
        pRd.form.txtNrTabPrec.disabled = 0;
        pRd.form.txtDesTabPrec.disabled = 0;
                    
    }
        
}



function doGetData(){                                                                  
   if(this.readOnly == 1) {

        return;
   }
  
   if(this.value.length){
      lockControls(this.form,true);
      switch(this.name){ 
          case "txtCodCliente":
            if (String(this.form.ctrlvendas) == "[object]")
                iFrmGlobal.location = "_ifrm/iFrm009.wspx" +                                  
                                      "?cod_emitente="     + this.value     +                 
                                      "&form="             + this.form.name +                 
                                      "&campo="            + "txtNomeAbrev" +                  
                                      "&campochave="       + this.name;                                                        
                                      
            else if (String(this.form.consultacliente) == "[object]")            
               iFrmGlobal.location = "_ifrm/iFrm010.wspx" +                                  
                                     "?cod_emitente="     + this.value     +                 
                                     "&form="             + this.form.name +                 
                                     "&campo="            + "txtNomeAbrev" +                  
                                     "&campochave="       + this.name;                  
            
               else
                    iFrmGlobal.location = "_ifrm/iFrm001.wspx" +                                  
                                          "?cod_emitente="     + this.value     +                 
                                          "&form="             + this.form.name +                 
                                          "&campo="            + "txtNomeAbrev" +                  
                                          "&campochave="       + this.name;                  
            break;
          case "txtNrTabPrec":
            iFrmGlobal.location = "_ifrm/iFrm002.wspx" +                                  
                                  "?nrTabPrec="        + this.value      +                 
                                  "&form="             + this.form.name  +                 
                                  "&campo="            + "txtDesTabPrec" +                  
                                  "&campochave="       + this.name       +
                                  "&txtCodCliente="    + this.form.txtCodCliente.value;
            break;    
          case "txtCodCondPag":
            iFrmGlobal.location = "_ifrm/iFrm003.wspx" +                                  
                                "?CodCondPag="         + this.value      +
                                "&form="               + this.form.name  +
                                "&campo="              + "txtDesCondPag" +
                                "&campochave="         + this.name       +
                                "&txtCodCliente="      + this.form.txtCodCliente.value;                       
            break;    
          case "txtCodItem":
            iFrmGlobal.location = "_ifrm/iFrm004.wspx" +                                  
                                "?CodItem="            + this.value                 +
                                "&form="               + this.form.name             +
                                "&campo="              + "txtDesItem"               +
                                "&campochave="         + this.name                  +
                                "&quantidade="         + this.form.quantidade.value +
                                "&nrTabPre="           + vNrTabPre                  +
                                "&codCliente="         + vCodCliente                +
                                "&codCondPag="         + vCodCondPag                +
                                "&Frete="              + vFrete                     ;                                
                                
            break;    

          case "txtCodItemAsat":
            vTipoItem = "";
            /*
            if (this.form.rdCodTipoItem[0].checked) 
                vTipoItem = this.form.rdCodTipoItem[0].value;
            else if (this.form.rdCodTipoItem[1].checked) 
                vTipoItem = this.form.rdCodTipoItem[1].value;
            */
            vTipoItem = this.form.rdCodTipoItem.value;
            
            iFrmGlobal.location = "_ifrm/iFrm006.wspx" +                                  
                                "?CodItemAsat="        + this.value     +
                                "&form="               + this.form.name +
                                "&campo="              + "txtDesItem"   +
                                "&campochave="         + this.name      +
                                "&tipoitem="           + vTipoItem;
                                
            break;    
            
          case "txtCodModelo":
            iFrmGlobal.location = "_ifrm/iFrm007.wspx" +                                  
                                "?fmCodigo="           + this.value     +
                                "&form="               + this.form.name +
                                "&campo="              + "txtDesModelo" +
                                "&campochave="         + this.name      ;
                                
                                
            break;    
            
          case "txtCodMotivo":
            iFrmGlobal.location = "_ifrm/iFrm008.wspx" +                                  
                                "?CodMotivo="          + this.value     +
                                "&form="               + this.form.name +
                                "&campo="              + "txtDesMotivo" +
                                "&campochave="         + this.name      ;
                                
                                
            break;    
          case "txtCodTransp":
            iFrmGlobal.location = "_ifrm/iFrm012.wspx" +                                  
                                "?txtCodTransp="       + this.value     +
                                "&form="               + this.form.name +
                                "&campo="              + "txtNomeTransp" +
                                "&campochave="         + this.name      ;
                                
                                
            break; 
          case "txtTipoPedido":
            iFrmGlobal.location = "_ifrm/iFrm013.wspx" +                                  
                                "?txtTipoPedido="      + this.value     +
                                "&form="               + this.form.name +
                                "&campo="              + "txtDesTipoPedido" +
                                "&campochave="         + this.name      ;
                                
                                
            break;       
      }                                                                                
   }
   else {
      switch(this.name){ 
          case "txtCodCliente":
            this.form.txtNomeAbrev.value="";
            break;
          case "txtNrTabPrec":
            this.form.txtDesTabPrec.value="";
            break;    
          case "txtCodCondPag":
            this.form.txtDesCondPag.value="";
            break;    
          case "txtCodItem":
            this.form.txtDesItem.value="";
            break;    
          case "txtCodItemAsat":
            this.form.txtDesItem.value="";
            break;    
          case "txtCodModelo":
            this.form.txtDesModelo.value="";
            break;    
          case "txtCodMotivo":
            this.form.txtDesMotivo.value="";
            break;    
          case "txtCodTransp":
            this.form.txtNomeTransp.value="";
            break; 
          case "txtTipoPedido":
            this.form.txtDesTipoPedido.value="";
            break;       
      }                                                                                
    
   }
}                   
                                                                   
function doShowZoom(){ 
      if(this.readOnly == 1) {
           alert("Campo somente leitura, impossivel alterar conteudo !");
           return;
      }

      window.status = 'Aguarde, gerando formul\u00e1rio de pesquisa';
            
      var pUrl = "";
      switch(this.name){ 
          case "txtCodCliente":
            pUrl = "_zoom/zwpv001.wspx?fldLabel=txtNomeAbrev";
            break;
          case "txtNrTabPrec":
            pUrl = "_zoom/zwpv002.wspx?fldLabel=txtDesTabPrec";
            break;    
          case "txtCodCondPag":
            pUrl = "_zoom/zwpv003.wspx?fldLabel=txtDesCondPag";
            break;
          case "txtCodItem":
            pUrl = "_zoom/zwpv004.wspx?fldLabel=txtDesItem" + 
                                      "&nrTabPre="          + vNrTabPre;                                                 
            break;            
          case "txtCodItemAsat":
            pUrl = "_zoom/zwpv005.wspx?fldLabel=txtDesItem";
            break;            
          case "txtCodModelo":
            pUrl = "_zoom/zwpv006.wspx?fldLabel=txtDesModelo";
            break;            
          case "txtCodMotivo":
            pUrl = "_zoom/zwpv007.wspx?fldLabel=txtDesMotivo";
            break;            
          case "txtCodTransp":
            pUrl = "_zoom/zwpv008.wspx?fldLabel=txtNomeTransp";
            break;
          case "txtTipoPedido":
            pUrl = "_zoom/zwpv009.wspx?fldLabel=txtDesTipoPedido";
            break;                                  
      }                                                                                

      var strFeatures = 'dialogHeight:345px;'+
                        'dialogWidth:570px;' +
                        'center:yes;'        +
                        'help:no;'           +
                        'resizable:no;'      +
                        'scroll:no';
                        
      lockControls(this.form,true);
                        
      if(pUrl.length)
          window.showModalDialog(pUrl      + 
                                 "&form="  + this.form.name + 
                                 "&field=" + this.name,
                                 self,
                                 strFeatures);
      //window.open(pUrl)
      
}

function lockControls(frm,flg){
    for(var i = 0 ; i < frm.length ; i++  ){
        frm[i].disabled = flg;          
    }    
}

function lockButtons(frm,flg){    
    for(var i = 0 ; i < frm.length ; i++  ){
        if(frm[i].type=='button'){
            frm[i].disabled = flg;
        }              
    }    
}


function doAutoNext(){
    var indice = -1;
    
    for(var i = 0 ; i < this.form.length ;i++){
        if(this.form[i] == this)
            indice = i + 1;
                        
    }
    
    if(indice == this.form.length)
        indice = 0;
        
    this.form[indice].focus();    
}                     

function doNextFocus(fld){

    var indice = -1;
    
    for(var i = 0 ; i < fld.form.length ;i++){
        if(fld.form[i] == fld)
            indice = i + 1;
                        
    }
    
    if(indice >= fld.form.length)
        indice = 0;
        
    fld.form[indice].focus();    

}


function doFormatDecimal(){    
    if(this.className == "decimal4" )
        this.value = formatDec(cfloat(this.value),4)
    else
        this.value = formatDec(cfloat(this.value),2)
    
}
function doFormatDecimal2(obj){    
    obj.value = formatDec(cfloat(obj.value),2)
}

function isOnlyNumber(param){
    var retorno = true;
    for(var i = 0;i < String(param).length; i++){
        if (isNaN(String(param).substr(i,1))){
            retorno = false;
            i = String(param).length;
        }
    }    
    return retorno;
}

function doShowFormMail(pNrPedido,pNrPedcli){
    var strFeatures = 'dialogHeight:270px;'+
                      'dialogWidth:550px;' +
                      'center:yes;'        +
                      'help:no;'           +
                      'resizable:no;'      +
                      'scroll:no';
    var vUrl = "wpvr10e.html?nr_pedido="+pNrPedido+"&Nr_PedCli="+pNrPedcli;
    
    window.showModalDialog(vUrl,self,strFeatures);                
}     







