var win = null;

function NovaJanela(pagina,nome,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(pagina,nome,settings);
}

 function formata_data(x,tecla){
        separador="/";
        tecla=tecla.keyCode;
        valor=x.value.split('');
        formatado="";
        i=0;
        while(i<valor.length){
            caractere=valor[i];
            numeros=/^\d+$/;
            if(numeros.test(caractere) || caractere==separador){ formatado+=String(caractere);}
            if((formatado.length==2 || formatado.length==5) && tecla!=8){formatado+=separador; i++;}

            i++;
        }

        x.value=formatado;
    }


function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2")
    v=v.replace(/(\d{4})(\d)/,"$1-$2")
    return v
}

function SetaFornecedor(id,nome)
{
      document.form.idfornecedor.value = id;
      document.form.fornecedor.value = nome;
      x=document.getElementById("link");
      
      document.getElementById('link').innerHTML="Novo Produto";
      document.getElementById('link').href="pedido_consultar_produto.php?idfornecedor="+id;
      //document.getElementById('link').href="javascript:ConfirmaForm2(pedido_consultar_produto.php?idfornecedor="+id+")";
}

function SelecionaFornecedor(id,nome)
{
 window.opener.SetaFornecedor(id,nome);
 window.close();
}

function SetaCliente(id,nome)
{
      document.form.idcliente.value = id;
      document.form.cliente.value = nome;
}

function SelecionaCliente(id,nome)
{
 window.opener.SetaCliente(id,nome);
 window.close();
}

function SetaTransportador(id,nome)
{
      document.form.idtransportador.value = id;
      document.form.transportador.value = nome;
}

function SelecionaTransportador(id,nome)
{
 window.opener.SetaTransportador(id,nome);
 window.close();
}

function SetaCond_Pgto(id,nome)
{
      document.form.idcondpgto.value = id;
      document.form.condpgto.value = nome;
}

function SelecionaCond_Pgto(id,nome)
{
window.opener.SetaCond_Pgto(id,nome);
window.close();
}

      function SetaVendedor(id,nome)
      {
       document.form.idvendedor.value = id;
       document.form.vendedor.value = nome;
      }

      function SelecionaVendedor(id,nome)
      {
       window.opener.SetaVendedor(id,nome);
       window.close();
      }

function SetaCep(cep,uf)
{
      document.form.cep.value = cep;
      document.form.uf.value = uf;
}

function SelecionaCep(cep,uf)
{
 window.opener.SetaCep(cep,uf);
 window.close();
}

function SetaLinha(id,nome)
{
      document.form.linha.value = id;
}

function ConfirmaForm3(idpedido)
{
         var x=document.getElementById("idform");
      //x.action='pedido_update2.php?idpedido='+idpedido+'&acao=0';
      x.submit();
      window.document.form.submit();
}

function ConfirmaForm2(destino , idpedido)
{
      //window.document.all.form.submit();
      //window.opener.form.submit();
      var x=document.getElementById("idform");
      //x.action='pedido_update2.php?idpedido='+idpedido+'&acao=1';
      x.submit();
      //window.document.form.submit()
      //url = destino
     // location=(url);
}

function ConfirmaForm()
{
  window.document.form.submit();
}

function limitaText( p_objCampo, p_permitido ) {

   if (  p_objCampo.value.length > p_permitido ) {
      p_objCampo.value =  p_objCampo.value.substr( 0, p_permitido )

      if ( p_objCampo.value.length > p_permitido )
         p_objCampo.value =  p_objCampo.value.substr( 0, p_permitido-1 )
   }

}

function Imprimir()
{
    window.print();
    window.close();
}

function foco()
{
  window.document.getElementById("1").focus();
}

function volta()
{
  history.back();
}


navHover = function() {
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);

