function mudaCorFundo(elem,color){
			document.getElementById(elem).style.backgroundColor=color;
		}


function selecionarprod(sel,valores){
	var valsel = "";
	
		for(i=0;i<sel.length;i++){
			if(sel(i).value!=""){
				valsel = valsel + "'" + sel(i).value + "',";
			};
		}
	valores.value = valsel;
}

function ie(ori, dest)
{
	if(ori.length!=0 && ori.value!=""){
		var elemento1 = new Option(ori.value,ori.value);
		dest.add(elemento1);
		ori.remove(ori.selectedIndex);
	}
}
function selecionar(sel,valores){
	var valsel = "";
	
		for(i=0;i<sel.length;i++){
			if(sel(i).value!=""){
				valsel = valsel + sel(i).value + ';';
			};
		}
	valores.value = valsel;
}

function selecionarExclusivo(sel,valores){
var valsel = "";

	for(i=0;i<sel.length;i++){			
		if(sel(i).value!="" && sel(i).selected==true){
			valsel = valsel + sel(i).value + ';';
		};
	}
	valores.value = valsel;
}

function reloadme(form,pagina)
{
 form.OnSubmit="";
 form.action=pagina;
 form.submit();
}

function glogin(nome,apt){

	var i=0;
	var login = "";
	var j=0;
	//alert(nome.charAt(6)==" ");
	while(i<nome.length){	
		if(nome.charAt(i)==" "){
			if(j==0){
				j=1;
				i++;
			}else{
				i=nome.length;
			}
		}else{
			login = login + nome.charAt(i);
			i++;
		}	
	}
	login = login + apt;
	return(login);
}




function valida_email(email){
flag=0
i=0
if(email=="") {
return "";
   }
while((flag==0) && (i<email.length)){
if((email.charAt(i)=="@")&&(i>0)){
flag=1
}
i++
}
if(flag==0){
alert('E-mail inválido!')
return false
}
else{
return true
}
}

function comparasenha(a,b){
if(a!=b){
   alert("Senhas digitadas deverão ser iguais!");
return(false);
}else{
   return(true);
}
}


function gsenha(){
var senha;
senha="";
for(i=0;i<6;i++){
var aleatorio = Math.round(Math.random()*10);
senha = senha + aleatorio;
}
return(senha);
}


/*----------------------------------------------------------------------------
Formatação para qualquer mascara
-----------------------------------------------------------------------------*/
function formatarMascara(campo, mask, evt) {
 if(document.all) { // Internet Explorer
    key = evt.keyCode; }
    else{ // Nestcape
       key = evt.which;
     }

if (key == 8) {
return true;
}

 string = campo.value;  
 i = string.length;

 if (i < mask.length) {
  if (mask.charAt(i) == '?') {
       return (key > 47 && key < 58);
      } else {
       if (mask.charAt(i) == '!') {  return true;  }
   for (c = i; c < mask.length; c++) {
         if (mask.charAt(c) != '?' && mask.charAt(c) != '!')
         campo.value = campo.value + mask.charAt(c);
      else if (mask.charAt(c) == '!'){
                return true;
       } else {
         return (key > 47 && key < 58);
          }
       }
    }
  } else return false;
}


// # # # # # # # # # # # # # # # # # #
// Máscara para CEP , DATA e TELEFONE
// # # # # # # # # # # # # # # # # # #

function Mascara (formato, keypress, objeto){
campo = eval (objeto);
//alert(campo);
// CEP
if (formato=='CEP'){
so_numeros();
separador = '-'; 
conjunto1 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

// DATA
if (formato=='data'){
separador = '/'; 
conjunto1 = 2;
conjunto2 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador;
}
}

// TELEFONE
if (formato=='telefone'){
separador = '-'; 
conjunto1 = 4;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

// Hora
if (formato=='hora'){
separador = ':'; 
conjunto1 = 2;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

}

// # # # # # # # #
// Validar CPF
// # # # # # # # #

function validar_cnpj(campo) {
 var invalid, s;
 invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
 var s;


// inicio de verificacao de cpf ou cpf

 s = limpa_string(campo.value);
 
 if (s.length == 14) {
  if (valida_CGC(campo.value) == false ) {
   alert("O CNPJ não é válido ! Confira o valor informado.");
   campo.focus();
   return false; }
   }
  else {
   alert("O CNPJ não é válido ! Confira o valor informado.");
   campo.focus();
   return false;
  }

// final da verificacao de cpf ou cpf
 
     return true;
}
// fim da funcao validar()




function validar_cpf_cnpj(Form) {
 var invalid, s;
 invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

 var s;


// inicio de verificacao de cpf ou cpf

 s = limpa_string(Form.cpf.value);
 
 // checa se é cpf 
 if (s.length == 11) {
  if (valida_CPF(Form.cpf.value) == false ) {
   alert("O CPF não é válido !");
   Form.cpf.focus();
   return false; }
     }
     
     // checa se é cgc
 else if (s.length == 14) {
  if (valida_CGC(Form.cpf.value) == false ) {
   alert("O CNPJ não é válido ! Confira o valor informado.");
   Form.cpf.focus();
   return false; }
   }
  else {
   alert("O CNPJ não é válido ! Confira o valor informado.");
   Form.cpf.focus();
   return false;
  }

// final da verificacao de cpf ou cpf
 
     return true;
}
// fim da funcao validar()


function limpa_string(S){
 // Deixa so' os digitos no numero
 var Digitos = "0123456789";
 var temp = "";
 var digito = "";

 for (var i=0; i<S.length; i++) {
  digito = S.charAt(i);
  if (Digitos.indexOf(digito)>=0) {
   temp=temp+digito }
 } //for
 
 return temp
}
// fim da funcao


function valida_CPF(s) {
 var i;
 s = limpa_string(s);
 var c = s.substr(0,9);
 var dv = s.substr(9,2);
 var d1 = 0;
 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;
 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;
 if (dv.charAt(1) != d1)
 {
  return false;
 }
        return true;
}

function valida_CGC(s)
{
 var i;
 s = limpa_string(s);
 var c = s.substr(0,12);
 var dv = s.substr(12,2);
 var d1 = 0;
 for (i = 0; i < 12; i++)
 {
  d1 += c.charAt(11-i)*(2+(i % 8));
 }
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1)
 {
  return false;
 }

 d1 *= 2;
 for (i = 0; i < 12; i++)
 {
  d1 += c.charAt(11-i)*(2+((i+1) % 8));
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1)
 {
  return false;
 }
 return true;
}


// # # # # # # # #
// Abrir POP-UP
// # # # # # # # #

function AbrePopUp(pagina,altura,largura,rolagem)
{

 top1=(screen.availHeight - altura)/2;
 left1=(screen.availWidth - largura)/2;
 
 window.open(pagina,"_blank","height="+altura+",width="+largura+",scrollbars="+rolagem+",left="+left1+",top="+top1); 
}


// # # # # # # # # # # # # # # # # # # # # # # # #
// Função para permitir somente digitação de números
// # # # # # # # # # # # # # # # # # # # # # # # #

function so_numeros() { 
if (event.keyCode == '13') 
{ 
	} 
		else if (event.keyCode < '48' || event.keyCode > '58') 
		{ 
			event.keyCode = '127'; 
		} 
} 

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58)) return true;
    else{
    	if (tecla==8 || tecla==0) return true;
	else  return false;
    }
}



// # # # # # # # # # # # # # # # # # # # # # # # #
// Função para permitir somente digitação de números Virgula e Ponto
// # # # # # # # # # # # # # # # # # # # # # # # #

function so_numerosvirgula() { 
if (event.keyCode == '13' || event.keyCode == '44' || event.keyCode == '46') 
{ 
	} 
		else if (event.keyCode < '48' || event.keyCode > '58') 
		{ 
			event.keyCode = '127'; 
		} 
} 



<!-- funçoes do editor HTML

 function set_desc(){
        form1.desc_materia.value = iView.document.body.innerHTML;
		//alert(iView.document.body.innerHTML);
		//alert(form1.desc_materia.value);
  }
  
 
  var viewMode = 1; // WYSIWYG

  function Init()
  {
    iView.document.designMode = 'On';
  }
  
  function selOn(ctrl)
  {
	ctrl.style.borderColor = '#000000';
	ctrl.style.backgroundColor = '#B5BED6';
	ctrl.style.cursor = 'hand';	
  }
  
  function selOff(ctrl)
  {
	ctrl.style.borderColor = '#D6D3CE';  
	ctrl.style.backgroundColor = '#D6D3CE';
  }
  
  function selDown(ctrl)
  {
	ctrl.style.backgroundColor = '#8492B5';
  }
  
  function selUp(ctrl)
  {
    ctrl.style.backgroundColor = '#B5BED6';
  }
    
  function doBold()
  {
	iView.document.execCommand('bold', false, null);
  }

  function doItalic()
  {
	iView.document.execCommand('italic', false, null);
  }

  function doUnderline()
  {
	iView.document.execCommand('underline', false, null);
  }
  
    function doSelecionaTudo()
  {
	iView.document.execCommand('SelectAll', false, null);
  }
  

  
  function doLeft()
  {
    iView.document.execCommand('justifyleft', false, null);
  }

  function doCenter()
  {
    iView.document.execCommand('justifycenter', false, null);
  }

  function doRight()
  {
    iView.document.execCommand('justifyright', false, null);
  }
  
    function doJustifica()
  {
    iView.document.execCommand('justifyFull', false, null);
  }

  function doOrdList()
  {
    iView.document.execCommand('insertorderedlist', false, null);
  }

  function doBulList()
  {
    iView.document.execCommand('insertunorderedlist', false, null);
  }
  
  function doForeCol()
  {
    var fCol = prompt('Enter foreground color', '');
    
    if(fCol != null)
      iView.document.execCommand('forecolor', false, fCol);
  }
  
    function doCorLetra(cor)
  {
    var fCol = cor
    
    if(fCol != null)
      iView.document.execCommand('forecolor', false, fCol);
  }

  function doBackCol()
  {
    var bCol = prompt('Enter background color', '');
    
    if(bCol != null)
      iView.document.execCommand('backcolor', false, bCol);
  }

  function doLink()
  {
    iView.document.execCommand('createlink');
  }
  
    function doRemoverLink()
  {
    iView.document.execCommand('unlink');
  }
  
   
  
  function doImage()
  {
    var imgSrc = prompt('Enter image location', '');
    
    if(imgSrc != null)    
     iView.document.execCommand('insertimage', false, imgSrc);
  }
  
  function doRule()
  {
    iView.document.execCommand('inserthorizontalrule', false, null);
  }
  
  
    function doCopiar()
  {
    iView.document.execCommand('copy', false, null);
  }
  
      function doColar()
  {
    iView.document.execCommand('paste', false, null);
  }
  
        function doDesfazer()
  {
    iView.document.execCommand('undo', false, null);
  }
  
        function doRefazer()
  {
    iView.document.execCommand('redo', false, null);
  }
  
          function doSalvar()
  {
    iView.document.execCommand('SaveAs', false, null);
  }
  
  function doFont(fName)
  {
    if(fName != '')
      iView.document.execCommand('fontname', false, fName);
  }
  
  function doSize(fSize)
  {
    if(fSize != '')
      iView.document.execCommand('fontsize', false, fSize);
  }
  
  function doHead(hType)
  {
    if(hType != '')
    {
      iView.document.execCommand('formatblock', false, hType);  
      doFont(selFont.options[selFont.selectedIndex].value);
    }
  }
  
  function doToggleView()
  {  
    if(viewMode == 1)
    {
      iHTML = iView.document.body.innerHTML;
      iView.document.body.innerText = iHTML;
      
      // Hide all controls
      tblCtrls.style.display = 'none';
      selFont.style.display = 'none';
      selSize.style.display = 'none';
      selHeading.style.display = 'none';
      iView.focus();
      
      viewMode = 2; // Code
    }
    else
    {
      iText = iView.document.body.innerText;
      iView.document.body.innerHTML = iText;
      
      // Show all controls
      tblCtrls.style.display = 'inline';
      selFont.style.display = 'inline';
      selSize.style.display = 'inline';
      selHeading.style.display = 'inline';
      iView.focus();
      
      viewMode = 1; // WYSIWYG
    }
  }
<!-- fim de funçoes do editor HTML


// Exibir a quantidade de caracteres permitidos em um Determinado campo ( Rafael 24/05/2005 )


var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(theform,thelimit){
var limit_text='<font color=#FF0000 size=2><b><span id="'+theform.toString()+'">'+thelimit+'</span></b></font> <font color=#000000 class=TextoGeral>caracteres restantes</font>'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


var maskpanel=function()
{
    this.divobj;
    this.show=function()
    {
      if(!document.getElementById("xdivmasking"))
      {
          var divEle=document.createElement('div');
          divEle.setAttribute("id","xdivmasking");
          document.body.appendChild(divEle);
          var divSty=document.getElementById("xdivmasking").style;
          divSty.position="absolute"; divSty.top="0px"; divSty.left="0px";
          divSty.zIndex="46"; divSty.opacity=".50";divSty.backgroundColor="#000";
          divSty.filter="alpha(opacity=50)";

          var divFram=document.createElement('iframe');
          divFram.setAttribute("id","xmaskframe");
          document.body.appendChild(divFram);
          divSty=document.getElementById("xmaskframe").style;
          divSty.position="absolute"; divSty.top="0px"; divSty.left="0px"; 
          divSty.zIndex="45";divSty.border="none";divSty.filter="alpha(opacity=0)";
       }

       this.divobj=document.getElementById("xdivmasking");
       this.waitifrm=document.getElementById("xmaskframe");
       
       var dsh=document.documentElement.scrollHeight;
       var dch=document.documentElement.clientHeight;
       var dsw=document.documentElement.scrollWidth;
       var dcw=document.documentElement.clientWidth;
       
       var bdh=(dsh>dch)?dsh:dch;
       var bdw=(dsw>dcw)?dsw:dcw;

       this.waitifrm.style.height=this.divobj.style.height=bdh+'px';
       this.waitifrm.style.width=this.divobj.style.width=bdw+'px';  
       this.waitifrm.style.display=this.divobj.style.display="block";
    };
    this.hide=function()
    {
        this.waitifrm.style.display=this.divobj.style.display="none";
    };
}
