﻿function headerClick(panel, state, imgClick, languagePrefix, panel)
{
    panel = document.getElementById(panel);
    state = document.getElementById(state);
    
  imgClick = document.getElementById(imgClick);
  
  if (panel.style.display != "none")
  {
    panel.style.display = "none"
    imgClick.src = '/imagens/btnClickToOpenHover_' + languagePrefix + '.gif';
  }  
  else
  {
    panel.style.display = "block";
    imgClick.src = '/imagens/btnClickToCloseHover_' + languagePrefix + '.gif';
  }
 
    state.value = panel.style.display;    
}

function headerMouseEnter(sender, imgLateralEsquerda, imgLateralDireita, Titulo, languagePrefix, panel, imgClick, lblMsg)
{
    imgLateralEsquerda = document.getElementById(imgLateralEsquerda);
    imgLateralDireita = document.getElementById(imgLateralDireita);
    
    lblMsg = document.getElementById(lblMsg);
    if (lblMsg != null)
        lblMsg.style.color = '#ffffff';
    
    sender.className = 'cabecalhoBoxOn';
    imgLateralEsquerda.src = '/imagens/box_topo_esquerdoOn.gif';
    imgLateralDireita.src = '/imagens/box_topo_direitoOn.gif';

  panel = document.getElementById(panel);    
  imgClick = document.getElementById(imgClick);
  
  if (panel.style.display != "none")
  {
    //panel.style.display = "none"
    imgClick.src = '/imagens/btnClickToCloseHover_' + languagePrefix + '.gif';
  }  
  else
  {
    //panel.style.display = "block";
    imgClick.src = '/imagens/btnClickToOpenHover_' + languagePrefix + '.gif';
  }    
}

function headerMouseLeave(sender, imgLateralEsquerda, imgLateralDireita, Titulo, languagePrefix, panel, imgClick, lblMsg)
{
    imgLateralEsquerda = document.getElementById(imgLateralEsquerda);
    imgLateralDireita = document.getElementById(imgLateralDireita);
    imgLateralEsquerda.src = '/imagens/box_topo_esquerdo.gif';
    imgLateralDireita.src = '/imagens/box_topo_direito.gif';
    sender.className = 'cabecalhoBox';
    
    lblMsg = document.getElementById(lblMsg);
    if (lblMsg != null)
        lblMsg.style.color = '#bf383c';
  
  panel = document.getElementById(panel);
  imgClick = document.getElementById(imgClick);
    
  if (panel.style.display != "none")
  {
    //panel.style.display = "none"
    imgClick.src = '/imagens/btnClickToClose_' + languagePrefix + '.gif';
  }  
  else
  {
    //panel.style.display = "block";
    imgClick.src = '/imagens/btnClickToOpen_' + languagePrefix + '.gif';
  }        
}


function ShowHidePanel(sender, panel)
{

  if (panel.style.display != "none")
    panel.style.display = "none"
  else
    panel.style.display = "block";
  
  
  state = document.getElementById("ctl00_ContentPlaceHolder1_" + panel.id + "State");
  
  if (state != null)
    state.value = panel.style.display;
 
}

function PersistPanelState(sender, panel)
{
  
  state = document.getElementById("ctl00_ContentPlaceHolder1_" + panel.id + "State");
  
  if (state != null)
    panel.style.display = state.value;

}

function SelectAllCheckboxes(spanChk){
    alert(spanChk.id);
   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox = (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
        
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       //elm[i].click();
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
     }
 }
 
function  mostra_flash(id, src, width, height){
document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'">');
document.write ('<param name="allowScriptAccess" value="sameDomain" />');
document.write ('<param name="movie" value="'+src+'" />');
document.write ('<param name="quality" value="high" />');
document.write ('<param name="scale" value="noborder" />');
document.write ('<param name="wmode" value="transparent" />');
document.write ('<param name="devicefont" value="true" />');
document.write ('<param name="bgcolor" value="#ffffff" />');
document.write ('<embed src="'+src+'" quality="high" scale="noborder" wmode="transparent" devicefont="true" bgcolor="#ffffff" width="'+width+'" height="'+height+'" id="'+id+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write ('</object>')
}

function textCounter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.innerHTML = maxlimit - field.value.length;
}

function formatPhone(elm, e) {
    var keychar;

    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }

        keychar = String.fromCharCode(keynum)
    }   

    // Allow a backspace to go through, so the user
    // can correct any typos.
    if (/[\b]/.exec(keychar) || keynum == null) {
        return true;
    } else {
        var p = elm.value + keychar;

        // Don't allow a leading 1 or 0. We also strip out all
        // non-numeric characters here to make the formatting
        // easier later on. This could be modified to allow
        // letters if you consider them valid.
        p = p.replace(/^[01]/,"");
        p = p.replace(/\D+/g, "");

        // You can easily change the formatting of the phone
        // number by editing the conditionals below.
        if (p.length > 0 && p.length < 3) {
            p = "("+p;
        }
        else if (p.length >= 3 && p.length < 7) {
            p = "("+p.substring(0,3)+") "+p.substring(3);
        }
        else if (p.length >= 7 && p.length < 10) {
            p = "("+p.substring(0,3)+") "+p.substring(3,6)+"-"+p.substring(6);
        }
        else if (p.length) {
            p = "("+p.substring(0,3)+") "+p.substring(3,6)+"-"+p.substring(6,10);
        }
        elm.value = p;

        return false;
    }
}

function formatSSN(elm, e) {
    var keychar;

    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }

        keychar = String.fromCharCode(keynum)
    }   

    // Allow a backspace to go through, so the user
    // can correct any typos.
    if (/[\b]/.exec(keychar) || keynum == null) {
        return true;
    } else {
        var p = elm.value + keychar;

                p = p.replace(/\D+/g, "");

        if (p.length > 0 && p.length < 3) {

        }
        else if (p.length >= 3 && p.length < 7) {
            p = p.substring(0,3)+"-"+p.substring(3);
        }
        else if (p.length >= 7) {
            p = p.substring(0,3)+"-"+p.substring(3,5)+"-"+p.substring(5, 9);
        }

        elm.value = p;

        return false;
    }
}

function formatDate(elm, e) {
    var keychar;
    
    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }

        keychar = String.fromCharCode(keynum)
    }
           
    // Allow a backspace to go through, so the user
    // can correct any typos.
    if (/[\b]/.exec(keychar) || keynum == null) {
        return true;
    } else {
        var p = elm.value + keychar;

        // Don't allow a leading 1 or 0. We also strip out all
        // non-numeric characters here to make the formatting
        // easier later on. This could be modified to allow
        // letters if you consider them valid.
//        p = p.replace(/^[01]/,"");
        p = p.replace(/\D+/g, "");

        // You can easily change the formatting of the phone
        // number by editing the conditionals below.
        if (p.length > 0 && p.length < 3) {
            //p = "("+p;
        }
        else if (p.length >= 2 && p.length < 4) {
            p = p.substring(0,2)+"/"+p.substring(2);
        }
        else if (p.length >= 2 && p.length < 8) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4);
        }
        else if (p.length) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4,8);
        }
        elm.value = p;

        return false;
    }
}


function formatCurrency(elm, e) {
    var keychar;
    
    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }

        keychar = String.fromCharCode(keynum)
    }
    
    
           
    // Allow a backspace to go through, so the user
    // can correct any typos.
    if (/[\b]/.exec(keychar) || keynum == null) {
        return true;
    } else {
        var p = elm.value + keychar;

        // Don't allow a leading 1 or 0. We also strip out all
        // non-numeric characters here to make the formatting
        // easier later on. This could be modified to allow
        // letters if you consider them valid.
//        p = p.replace(/^[01]/,"");
        p = p.replace(/\D+/g, "");

        // You can easily change the formatting of the phone
        // number by editing the conditionals below.
        if (p.length > 0 && p.length < 3) {
            //p = "("+p;
        }
        else if (p.length >= 2 && p.length < 4) {
            p = p.substring(0,2)+"/"+p.substring(2);
        }
        else if (p.length >= 2 && p.length < 8) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4);
        }
        else if (p.length) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4,8);
        }
        elm.value = p;

        return false;
    }
}

/*---------------------------------------------------------*/
function CapWords(str){ 
   str = str.toLowerCase();
   var words = str.split(" "); 
   for (var i=0 ; i < words.length ; i++){ 
      var testwd = words[i]; 
      var firLet = testwd.substr(0,1); 
      var rest = testwd.substr(1, testwd.length -1) 
      words[i] = firLet.toUpperCase() + rest 
   } 
   return words.join(" ");
} 