

//-----------------------------------------------------------------------------------------------

function stopError() {
  return true;
}

//-----------------------------------------------------------------------------------------------

function Copia(txt_origem) {
  window.onerror = stopError;
  if(txt_origem.name.substring(0,2)!="r_"){
    if(txt_origem.value==null || txt_origem.value==''){
      txt_origem.value = "00";
    }
  }
  txt_origem.value =  txt_origem.value.toUpperCase();
  if(txt_origem.name.substring(0,2)!="r_"){
    var txt_destino = txt_origem.name + "_c";
  }
  else{
    var txt_destino = txt_origem.name.substring(2,txt_origem.name.length) + "_c";
    //alert(txt_destino);
  }
  var txt_valor = txt_origem.value;
  document.frm(txt_destino).value = txt_valor; 
}

//-----------------------------------------------------------------------------------------------

function gera_email(){
  window.onerror = stopError;
  dest_assunto = (("web@theodorojr.com.br") + "?subject=" + document.frm.assunto.value);
  document.frm_envia.action = "mailto:" + dest_assunto;
}

//-----------------------------------------------------------------------------------------------

function envia_email(txt_frm){
  window.onerror = stopError;
  var certo = true;
  var texto = ""
  document.frm_envia.especificacao.value = "";
  if (document.images) {
    for (j=0;j<txt_frm.length;j++){
      var txt_campo = txt_frm.elements[j];
      if (txt_campo.type=="text" || txt_campo.type=="textarea"){
        if (txt_campo.name.indexOf("item_",0)!=-1 && txt_campo.name.indexOf("_c",0)==-1){
          document.frm_envia.especificacao.value +=txt_campo.value + "-";
        }
      }
      if (txt_campo.name.substring(0,2)=="r_"){
        if ((txt_campo.type=="text" || txt_campo.type=="textarea")&&(txt_campo.value=='')){
          certo=false;
          break;
        }
      }
    }
  }
  //for (j=0;j=document.frm_envia.especificacao.length;j++){
  //  texto += document.frm_envia.especificacao.indexOf(j,1);
  // }
  //document.frm_envia.especificacao.value=texto;
  if (!certo){
    var txt_campo_nome = (txt_campo.name.substring(2,txt_campo.name.length).toUpperCase());
    alert("O campo - " + txt_campo_nome + " deve ser preenchido!");
    txt_campo.focus();
    document.frm_envia.especificacao.value=null;
    return false;
  }
  else{
    var vr = gera_email();
    document.frm_envia.nome.value=document.frm.nome_cli.value;
	document.frm_envia.empresa.value=document.frm.empresa.value;
    document.frm_envia.email.value=document.frm.email_cli.value;
    document.frm_envia.telefone.value=document.frm.tel_cli.value;
    document.frm_envia.observacao.value=document.frm.outros.value;
    //document.frm.action += dest_assunto;
    //document.frm.submit();
    document.frm_envia.submit()
    return true;
  }
}

//-----------------------------------------------------------------------------------------------

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac")!=-1);

function imprimir(){
  window.onerror = stopError;
  if(pr) //NS4 ou IE5
    window.print()
  else if(da&&!mac) //IE4
    vbPrintPage()
  else //Outros
    alert("Lamento, seu navegador não suporta este recurso!");
  return false;
}

if(da && !pr && !mac) with(document){
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

//-----------------------------------------------------------------------------------------------

function bot_dir(x) {
  if(navigator.appName == 'Netscape' && (x.which == 3 || x.which == 2))return false;
  else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
    alert("Lamento, por questões de segurança você não tem permissão para abrir o menu.");
    return false;
  }
  return true;
}

document.onmousedown=bot_dir;
document.onmouseup=bot_dir;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=bot_dir;
window.onmouseup=bot_dir;  

//-----------------------------------------------------------------------------------------------

function mens_ajuda(header, hstyle, mstyle, message) {
  this.DEFAULTHSTYLE = "plain";
  this.DEFAULTMSTYLE = "plain";

  this.header = header;
  if (hstyle) this.hstyle = hstyle;
    else this.hstyle = this.DEFAULTHSTYLE;
  this.message = message;
  if (mstyle) this.mstyle = mstyle;
    else this.mstyle = this.DEFAULTMSTYLE;
  return this;
}

new mens_ajuda();
mens_ajuda.prototype.show = show;

function show() {
  var H = "<FONT FACE='arial'>" + this.header + "</FONT>";
  if (this.hstyle == "h1") H = "<H1>" + H + "</H1>";
    else if (this.hstyle == "h2") H = "<H2>" + H + "</H2>";
    else if (this.hstyle == "h3") H = "<H3>" + H + "</H3>";
    else if (this.hstyle == "h4") H = "<H4>" + H + "</H4>";
  if (this.hstyle == "fancyheader") H = "<table width='95%' border='0' cellspacing='0' cellpadding='0'>" + "<tr><td bgcolor='#6060ff' align='center' valign='center'>" + "<b><FONT COLOR='white' Face='Arial,Verdana' Size='2'>" + H + "</FONT></b>" + "</td></tr></table>";
    else if (this.hstyle == "italics") H = "<I>" + H + "</I>";
  var M = "<FONT FACE='arial' size='2'>" + this.message + "</FONT>";
  if (this.mstyle == "plain") {}
  if (this.mstyle == "italics") M = M.italics();
    else if (this.mstyle == "bold") M = M.bold();
  var htmlpage = "";
  if (this.hstyle.indexOf("header")>=0) htmlpage = H + M;
    else htmlpage = H + "<BR>" + M;
  return htmlpage;
}

function caixa_ajuda(name, hm, width, height, bgcolor) {
  this.name = name;
  this.helpmessage = hm;
  this.timerHandle = null;
  this.windowHandle = null;
  this.DEFAULTWIDTH = 250;
  this.DEFAULTHEIGHT = 150;
  this.DEFAULTBGCOLOR = "#ffffcc";
  this.POPUPDELAY = 100;
  if (width) this.width = width;
    else this.width = this.DEFAULTWIDTH;
  if (height) this.height = height;
    else this.height = this.DEFAULTHEIGHT;
  if (bgcolor) this.bgcolor = bgcolor;
    else this.bgcolor = this.DEFAULTBGCOLOR;
  return this;
}

function Abrir_Janela(msgindex) {
  var cmdstr="self." + this.name + ".showHelp('" + msgindex + "')";
  this.timerHandle = setTimeout(cmdstr, this.POPUPDELAY);
}

function showHelp(msgindex) {
  if (!this.windowHandle || !this.windowHandle.name || this.windowHandle.name=="") 
    this.windowHandle = window.open("", "subWindow", "toolbar=no," + "location=no," + "directories=no," + "status=no," + "menubar=no," + "scrollbars=no," + "resizable=no," + "width=" + this.width + "," + "height=" + this.height);
    else this.windowHandle.focus();
  this.windowHandle.document.open();
  var to_page ="<HTML>\n" + "<BODY BGCOLOR='" + this.bgcolor + "'><P>" + this.helpmessage[msgindex].show() + "</BODY></HTML>\n"; 
  this.windowHandle.document.write(to_page);
  this.windowHandle.document.close();
}

function Fecha_Janela() {
  clearTimeout(this.timerHandle);
  if (this.windowHandle && this.windowHandle.name) {
    this.windowHandle.close();
    this.windowHandle=null;
  }
}

new caixa_ajuda();
caixa_ajuda.prototype.Abrir_Janela = Abrir_Janela;
caixa_ajuda.prototype.showHelp = showHelp;
caixa_ajuda.prototype.Fecha_Janela = Fecha_Janela;
