// JavaScript Document
<!-- Begin Dica preenchimento
var DH = 0;var an = 0;var al = 0;var ai = 0;if (document.getElementById) {ai = 1; DH = 1;}else {if (document.all) {al = 1; DH = 1;} else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} function fd(oi, wS) {if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi); if (al) return wS ? document.all[oi].style: document.all[oi]; if (an) return document.layers[oi];}
function pw() {return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;}
function mouseX(evt) {if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return null;}
function mouseY(evt) {if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return null;}
function popUp(evt,oi) {if (DH) {var wp = pw(); ds = fd(oi,1); dm = fd(oi,0); st = ds.visibility; if (dm.offsetWidth) ew = dm.offsetWidth; else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } else {tv = mouseY(evt) + 20; lv = mouseX(evt) - (ew/8); if (lv < 2) lv = 2; else if (lv + ew > wp) lv -= ew/2; if (!an) {lv += 'px';tv += 'px';} ds.left = lv; ds.top = tv; ds.visibility = "visible";}}}
//  End Dica preenchimento -->

<!--// Scripts SWAP imagem com preload
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// End Scripts SWAP imagem com preload -->


function confirmaacao(page,ask,target) {
		clearTimeout();
		var answer = confirm (ask);
		if (answer) {
			if (target) {
				// var win = window.open("", target);
				//	if (win == null) {
				//		alert('Seu bloqueador de popup está habilitado, não será possível direcionado para página.');
				//	} else {
						//target.location.href = page;				
						window.parent.location.href=page;
						return true;
				//	}
			} else {
				window.location=page;
			}
		} else {
			//alert (page);
			return false;
		}
}
function chkcontrol(theform) {

		var total=0;        
        var inputs = document.getElementsByName('cod[]');
		var vcompara = document.getElementById('selectcompara');
		var vcompara1 = document.getElementById('selectcompara1');
		
		if(vcompara || vcompara1){
		vcompara.disabled=true;
		vcompara1.disabled=true;
		}
		
        for(var i=0; i < inputs.length; i++){

                if(inputs[i].checked){
                        total = total +1;
						
                }
				if(total > 1){
					if(vcompara || vcompara1){
						vcompara.disabled=false;
						vcompara1.disabled=false;
					}
				}
                if(total > 3){
					alert("Por favor selecione até 3 itens.")
					inputs[i].checked = false ;
					return false;
                }
        }
}

// Mostrar ou ocutar div usar id para o <div id='teste'> funcao para 'none' e '' para mostrar ou ocutar
function showhide(id,funcao){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		//if (obj.style.display == "none"){ 
		//	obj.style.display = ""; // MOSTRA
		//} else { 
		//	obj.style.display = "none";  // OCULTA
		//} 
		obj.style.display = funcao;
	} 
} 
//

// Inicio Swap Div
// sender nome da var, divchange nome do div que vai receber
function ChangeContent(sender,divchange) {
var obj=document.getElementById(divchange);
obj.style.display='block';
obj.innerHTML=sender;
}
// Fim Swap Div

// Mascara Moeda
// Ex: onKeyPress="return(MascaraMoeda(this,'.',',',event))"
// 000.000,00
documentall = document.all;   
/*  
* função para formatação de valores monetários retirada de  
* [url]http://jonasgalvez.com/br/blog/2003-08/egocentrismo[/url]  
*/  
function formatamoney(c) {   
    var t = this; if(c == undefined) c = 2;         
    var p, d = (t=t.split("."))[1].substr(0, c);   
    for(p = (t=t[0]).length; (p-=3) >= 1;) {   
           t = t.substr(0,p) + "." + t.substr(p);   
    }   
    return t+","+d+Array(c+1-d.length).join(0);   
}   
  
String.prototype.formatCurrency=formatamoney   
  
function demaskvalue(valor, currency){   
/*  
* Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as   
* casas decimais  
*/  
var val2 = '';   
var strCheck = '0123456789';   
var len = valor.length;   
   if (len== 0){   
      return 0.00;   
   }   
  
   if (currency ==true){      
      /* Elimina os zeros à esquerda   
      * a variável  <i> passa a ser a localização do primeiro caractere após os zeros e   
      * val2 contém os caracteres (descontando os zeros à esquerda)  
      */  
         
      for(var i = 0; i < len; i++)   
         if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break;   
         
      for(; i < len; i++){   
         if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i);   
      }   
  
      if(val2.length==0) return "0.00";   
      if (val2.length==1)return "0.0" + val2;   
      if (val2.length==2)return "0." + val2;   
         
      var parte1 = val2.substring(0,val2.length-2);   
      var parte2 = val2.substring(val2.length-2);   
      var returnvalue = parte1 + "." + parte2;   
      return returnvalue;   
         
   }   
   else{   
         /* currency é false: retornamos os valores COM os zeros à esquerda,   
         * sem considerar os últimos 2 algarismos como casas decimais   
         */  
         val3 ="";   
         for(var k=0; k < len; k++){   
            if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k);   
         }            
   return val3;   
   }   
}   
  
function reais(obj,event){   
  
var whichCode = (window.Event) ? event.which : event.keyCode;   
/*  
Executa a formatação após o backspace nos navegadores !document.all  
*/  
if (whichCode == 8 && !documentall) {      
/*  
Previne a ação padrão nos navegadores  
*/  
   if (event.preventDefault){ //standart browsers   
         event.preventDefault();   
      }else{ // internet explorer   
         event.returnValue = false;   
   }   
   var valor = obj.value;   
   var x = valor.substring(0,valor.length-1);   
   obj.value= demaskvalue(x,true).formatCurrency();   
   return false;   
}   
/*  
Executa o Formata Reais e faz o format currency novamente após o backspace  
*/  
FormataReais(obj,'.',',',event);   
} // end reais   
  
  
function backspace(obj,event){   
/*  
Essa função basicamente altera o  backspace nos input com máscara reais para os navegadores IE e opera.  
O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown.  
Como o opera suporta o infame document.all, tratamos dele na mesma parte do código.  
*/  
  
var whichCode = (window.Event) ? event.which : event.keyCode;   
if (whichCode == 8 && documentall) {      
   var valor = obj.value;   
   var x = valor.substring(0,valor.length-1);   
   var y = demaskvalue(x,true).formatCurrency();   
  
   obj.value =""; //necessário para o opera   
   obj.value += y;   
      
   if (event.preventDefault){ //standart browsers   
         event.preventDefault();   
      }else{ // internet explorer   
         event.returnValue = false;   
   }   
   return false;   
  
   }// end if         
}// end backspace   
  
function FormataReais(fld, milSep, decSep, e) {   
var sep = 0;   
var key = '';   
var i = j = 0;   
var len = len2 = 0;   
var strCheck = '0123456789';   
var aux = aux2 = '';   
var whichCode = (window.Event) ? e.which : e.keyCode;   
  
//if (whichCode == 8 ) return true; //backspace - estamos tratando disso em outra função no keydown   
if (whichCode == 0 ) return true;   
if (whichCode == 9 ) return true; //tecla tab   
if (whichCode == 13) return true; //tecla enter   
if (whichCode == 16) return true; //shift internet explorer   
if (whichCode == 17) return true; //control no internet explorer   
if (whichCode == 27 ) return true; //tecla esc   
if (whichCode == 34 ) return true; //tecla end   
if (whichCode == 35 ) return true;//tecla end   
if (whichCode == 36 ) return true; //tecla home   
  
/*  
O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script  
*/  
  
if (e.preventDefault){ //standart browsers   
      e.preventDefault()   
   }else{ // internet explorer   
      e.returnValue = false  
}   
  
var key = String.fromCharCode(whichCode);  // Valor para o código da Chave   
if (strCheck.indexOf(key) == -1) return false;  // Chave inválida   
  
/*  
Concatenamos ao value o keycode de key, se esse for um número  
*/  
fld.value += key;   
  
var len = fld.value.length;   
var bodeaux = demaskvalue(fld.value,true).formatCurrency();   
fld.value=bodeaux;   
  
/*  
Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror.  
*/  
  if (fld.createTextRange) {   
    var range = fld.createTextRange();   
    range.collapse(false);   
    range.select();   
  }   
  else if (fld.setSelectionRange) {   
    fld.focus();   
    var length = fld.value.length;   
    fld.setSelectionRange(length, length);   
  }   
  return false;   
  
}
//Fim

// Abrir Popup no centro
function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

    newWindow = window.open(windowUri, windowName, 'resizable=0,scrollbars=auto,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);

	//newWindow.blur();
	if (is_chrome) {
		newWindow.parent.blur();
		newWindow.blur();
		setTimeout(newWindow.focus, 0); 		
	}
	newWindow.focus(); 	

	return newWindow.name;
}
//Fim

//Adicionar item no combo select <option value="Outro">
function inserir_combo(inForm,selected,nome) {
	if (selected == 'Outro') {
		newCountry = "";
		while (newCountry == ""){
			newCountry=prompt (nome, "");
		}
		if (newCountry != null) {
			inForm.options[(inForm.options.length-1)]=new Option(newCountry,newCountry,true,true);
			inForm.options[inForm.options.length]=new Option('Outro','Outro');
		}
	}
	//if(inForm.city.options[0].text == 'Escolha...') { //Apaga o item Escolha...
	//	inForm.city.options[0]= null;
	//}
}
//Fim

// Mascará formata vários campos
// Ex: onKeyPress="mascara(this,ivalor)"
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
function itelefone(v){
// (00) 0000-0000	
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function icpf(v){
// 000.000.000-00	
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function icep(v){
// 00000-00
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function icnpj(v){
//	00.000.000/0000-00
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}
function iie(v){
//	00.000.000-0
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1-$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    return v
}
function site(v){
// http:// sempre
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

function ivalor(v){
//	0000.00
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
	//v=v.replace(/(\d{3})(\d)/g,"$1,$2")
	v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
	return v
}
function inumeros(v){
	return v.replace(/\D/g,"")
}
function data(v){
// 00/00/0000
	v=v.replace(/\D/g,"") 
	v=v.replace(/(\d{2})(\d)/,"$1/$2") 
	v=v.replace(/(\d{2})(\d)/,"$1/$2") 
	return v
}
function hora(v){
// 00:00:00
	v=v.replace(/\D/g,"") 
	v=v.replace(/(\d{2})(\d)/,"$1:$2")
	v=v.replace(/(\d{2})(\d)/,"$1:$2")  
	return v
}
function area(v){
// 000.00
	v=v.replace(/\D/g,"") 
	v=v.replace(/(\d)(\d{2})$/,"$1.$2") 
	return v
}
function mreais(v){
        v=v.replace(/\D/g,"")
        v=v.replace(/(\d{2})$/,",$1")
        v=v.replace(/(\d+)(\d{3},\d{2})$/g,"$1.$2")
		// Modificação Rafael Ruscher
        v=v.replace(/(\d+)(\d{3})/,"$1.$2")
        v=v.replace(/(\d+)(\d{3})(\d)/,"$1.$2")
        return v
}
// Fim

// Desmarca o radio button com 2 cliques. Ex:
// <input type="radio" name="dutyid" value="1" ondblclick="javascript:unselect('dutyid')">One
// <input type="radio" name="dutyid" value="2" ondblclick="javascript:unselect('dutyid')">Two
// Desmarca os radios buttons com botão ao lado. Ex:
// <input type="button" name="do" value="Deselect" onclick="javascript:unselect('dutyid')">
function unselect(id)
{
var oRadio = document.getElementsByName(id); 
for(i=0;i<oRadio.length;i++) 
	oRadio[i].checked = false;	
}
//Fim

// Inicio Marcar e Desmarcar Checkboxes
function checkAll(field)
{
for (i = 0; i <= field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
// Fim Marcar e Desmarcar Checkboxes
