bt_ferramentas = new Image();
bt_servicos = new Image();
bt_voceofficer = new Image();

bt_ferramentas.src = 'bt_ferramentas_on.gif';
bt_servicos.src = 'bt_servicos_on.gif';
bt_voceofficer.src = 'bt_voceofficer_on.gif';

function trocaAbas(qualAba,botao) { 
		if (qualAba == 'fabricantes') {
				document.getElementById('btFabricantes').src = 'bt_fabricantes_on.gif';
				document.getElementById('btLinhas').src = 'bt_linhas_off.gif';
				document.getElementById('menuLinhas').style.display = 'none';	
				document.getElementById('menuFabricantes').style.display = 'block';
				document.getElementById("menuFabricantes").getElementsByTagName("ul")[0].style.display='block'
		}
		
		else {
				document.getElementById('btFabricantes').src = 'bt_fabricantes_off.gif';
				document.getElementById('btLinhas').src = 'bt_linhas_on.gif';
				document.getElementById('menuFabricantes').style.display = 'none';		
				document.getElementById('menuLinhas').style.display = 'block';
				document.getElementById("menuLinhas").getElementsByTagName("ul")[0].style.display='block';
		}
		
		if(botao) {
			document.getElementById("menuFabricanteInterno").style.display='none';
			document.getElementById("fechar_menu").style.display='block';
		}
	}


function toggle(oElemento,divReferencia) {
		if(document.getElementById(oElemento).style.display != 'block') {
			if(oElemento == 'boxCesta') //document.getElementById("btnCesta").style.visibility = 'visible';
			if(oElemento == 'boxProdutosCesta') document.getElementById("btnProdutosCesta").className="verProdutos hover";
			if(document.getElementById(divReferencia))
			{
			    document.getElementById(oElemento).style.top = document.getElementById(divReferencia).offsetTop + 35 + 'px';
			    document.getElementById(oElemento).style.left = 40 + '%';
			}
			document.getElementById(oElemento).style.display = 'block';						
		}
		else {
			if(oElemento == 'boxCesta') {
				//document.getElementById("btnCesta").style.visibility = 'hidden';
				document.getElementById("boxProdutosCesta").style.display = 'none';
			}
			if(oElemento == 'boxProdutosCesta') document.getElementById("btnProdutosCesta").className="verProdutos";
			document.getElementById(oElemento).style.display = 'none'; 
		}
}

function login() {
	document.getElementById("divAreaLogin").style.display='none';
	document.getElementById("divBoxLogado").style.display='block';
}

function logout() {
	document.getElementById("divBoxLogado").style.display='none';
	document.getElementById("divAreaLogin").style.display='block';
}

function showSearch(id) {
	document.getElementById(id).style.display = 'block';
}

function hideSearch(id) {
	document.getElementById(id).style.display = 'none';
}

function hideMenu(item) {
	document.getElementById("fechar_menu").style.display='none';
	document.getElementById("menuFabricantes").getElementsByTagName("ul")[0].style.display='none';
	document.getElementById("menuLinhas").getElementsByTagName("ul")[0].style.display='none';
	document.getElementById('btLinhas').src = 'bt_linhas_off.gif';
	document.getElementById('btFabricantes').src = 'bt_fabricantes_off.gif';
	document.getElementById(item).style.display='block';
}

function showMsgBox(e) {
	var popup = document.getElementById("boxMensagem");
	var home = document.getElementsByTagName("html")[0];
	var barra = home.scrollTop;
	x = e.clientX;
  	y = e.clientY;
	popup.style.left = (x + 20)+'px';
	popup.style.top = (y + 5 + barra)+'px';
	popup.style.display='block';
}
var controle =0; //linha adicionada

function showMsgBox2(e, indicador) { //função alterada
                var popup = document.getElementById("BoxMensagem_" + indicador);
                var home = document.getElementsByTagName("html")[0];
                var barra = home.scrollTop;
                x = e.clientX;
                y = e.clientY;
                var xx = window.screen.width;
                popup.style.display='block';
                if(controle == 0) {
                    popup.style.left = (x + 20)+'px';
                    popup.style.top = (y + 5 + barra)+'px';
                }
                var wd = popup.clientWidth;
                var t = getPageOffsetLeft(popup);
                if((wd+t) >= xx) {
                    var old = (x-(2*wd)-20);
                    popup.style.left = old +'px';
                    controle=1;
                }

}
function hideMsgBox(indicador) {//função alterada
                var popup = document.getElementById("BoxMensagem_" + indicador);
                popup.style.display='none';
                controle=0;

}
function add() {
  	var box1 = document.getElementById("listBox1")
  	var box2 = document.getElementById("listBox2");
	
	var qtde = box2.getElementsByTagName("option");
	if(qtde.length == 1 && qtde[0].className=="unico") box2.remove(0);
	
  	for(var i = 0; i < box1.length; i++) {
    	var opcao = box1.options[i];
    	if(opcao.selected) {
      		var novo = new Option(opcao.text, box2.length);
      		novo.value = opcao.value;
      		box1.remove(i);
      		try {
        		box2.add(novo,null);
      		} catch(e) {
        		box2.add(novo);
      		}
      		i--;
    	}
  	}
}

function remove() {
  	var box1 = document.getElementById("listBox1")
  	var box2 = document.getElementById("listBox2");
  	for(var i = 0; i < box2.length; i++) {
    	var opcao = box2.options[i];
    	if(opcao.selected) {
      		var novo = new Option(opcao.text, box1.length);
      		novo.value = opcao.value;
      		box2.remove(i);
      		try {
        		box1.add(novo,null);
      		} catch(e) {
        		box1.add(novo);
      		}
      		i--;
    	}
  	}
}

 function MoveItem(fonte, alvo, hdnValoreslstDir, lstMenuDir) 
  	  {
        var Source = document.getElementById(fonte)
        var Target = document.getElementById(alvo)
        var ListDireito = document.getElementById(lstMenuDir)
        var hiddenListDireito = document.getElementById(hdnValoreslstDir)
        
        if ((Source != null) && (Target != null)) 
        {
            while ( Source.options.selectedIndex >= 0 ) 
            {
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[Source.options.selectedIndex].text;
                newOption.value = Source.options[Source.options.selectedIndex].value;
                
                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(Source.options.selectedIndex);  //Remove the item from Source
            }
        }
        
        hiddenListDireito.value = ""
        for (var i = 0; i < ListDireito.options.length; i++)
        {
            hiddenListDireito.value += ListDireito.options[i].value + ',';   
        }
        
        
    }

function faq(idFaq, idMostrar) {
	asDuvidas = document.getElementById(idFaq).getElementsByTagName("dd").length;

	for(i=0; i<asDuvidas; i++) {
		
		if(document.getElementById(idFaq).getElementsByTagName("dd")[i].id != 'inst_' + idMostrar) {
			document.getElementById(idFaq).getElementsByTagName("dd")[i].style.display = 'none';
			document.getElementById(idFaq).getElementsByTagName("dt")[i].className = '';
		}
		else {
		
			if(document.getElementById(idFaq).getElementsByTagName("dd")[i].style.display != 'block') {
				document.getElementById(idFaq).getElementsByTagName("dd")[i].style.display = 'block';
				document.getElementById(idFaq).getElementsByTagName("dt")[i].className = 'ddHover';
			}
			else {
				document.getElementById(idFaq).getElementsByTagName("dd")[i].style.display = 'none';
				document.getElementById(idFaq).getElementsByTagName("dt")[i].className = '';
			}
			
		}
	}
}

function getPageOffsetLeft(_){var q;q=_.offsetLeft;if(_.offsetParent!=null)
q+=getPageOffsetLeft(_.offsetParent);return q}
function getPageOffsetTop(_){var q;q=_.offsetTop;if(_.offsetParent!=null)
q+=getPageOffsetTop(_.offsetParent);return q}

function showMenu(elemento,e) {
	
	var submenu = document.getElementById(elemento);


	var x = getPageOffsetLeft(e) + e.offsetWidth;
	var y = getPageOffsetTop(e);
	
	if(navigator.appName.indexOf('Internet Explorer')>0){
		var version=navigator.appVersion.substring(22,23);
		if ( version == '7') y = y - 5;
		else y = y - 20;
		x = x + 30;
    } else {
		x = x + 10;
		y = y - 5;
	}
	submenu.style.left = x+'px';
	submenu.style.top = y+'px';
	submenu.style.display='block';
	
}

function showICMS(oElemento) {
	document.getElementById(oElemento).style.visibility = 'visible';
}

function swap(nomeCont,nomeBox,opcao) {
	var x = document.getElementById(nomeCont).getElementsByTagName("fieldset").length;
	
	for( var i = 0; i < x; i++ ) {
	
	    var sAba = document.getElementById("aba"+(i+1));
	
		if(opcao == (i+1)) {
			document.getElementById(nomeBox+opcao).style.display='block';
			document.getElementById("aba"+opcao).className="abaOn";			
		}
		else if (sAba != null) {
			document.getElementById(nomeBox+(i+1)).style.display='none';
			document.getElementById("aba"+(i+1)).className="abaOff";			
		}
		if((i+1) == 1) document.getElementById("aba1").className= document.getElementById("aba1").className +" primeiraAba";
		if((i+1) == x && sAba != null) document.getElementById("aba"+x).className= document.getElementById("aba"+x).className +" ultimaAba";
	}
}

function swap2(nomeCont,nomeBox,opcao) {
	var x = document.getElementById(nomeCont).getElementsByTagName("fieldset").length;
	
	for( var i = 0; i < x; i++ ) {
		if(opcao == (i+1)) {
			document.getElementById(nomeBox+opcao).style.display='block';
			document.getElementById("abaX"+opcao).className="abaOn";			
		}
		else {
			document.getElementById(nomeBox+(i+1)).style.display='none';
			document.getElementById("abaX"+(i+1)).className="abaOff";			
		}
		if((i+1) == 1) document.getElementById("abaX1").className= document.getElementById("abaX1").className +" primeiraAba";
		if((i+1) == x) document.getElementById("abaX"+x).className= document.getElementById("abaX"+x).className +" ultimaAba";
	}
}
function getElementbyClass(classname){
partscollect=new Array()

var inc=0;
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
partscollect[inc++]=alltags[i]
}
return partscollect;
}

function showSubMenu(el,i) {
	hover(el);
	//$('submenu'+i).show();
	document.getElementById("submenu"+i).style.display='block';
	if(document.getElementById("boxCesta"))
	    //$('boxCesta').hideP();
	document.getElementById("boxCesta").style.display='none';
	if(document.getElementById("boxProdutosCesta"))	document.getElementById("boxProdutosCesta").style.display='none';
}

function hideSubMenu(el,i) {
	hide(el);
	document.getElementById("submenu"+i).style.display='none';
	//$('submenu'+i).hide();
}
function hover(el,t) {
	if(t) el.className = el.className +' ' + t +'MenuApoioLink02';
	else el.className = el.className +' MenuApoioLink02';
}

function hide (el,t) {
	if(t) el.className = t +'MenuApoioLink01';
	else el.className = 'MenuApoioLink01';
}

function showMenuInterno(el,tipo,t) {
	hover(el,t);
	var menu = el.getElementsByTagName("ul")[0];
	menu.style.display='block';
	
/*	if(tipo==1) {
			if(navigator.appName.indexOf('Internet Explorer')>0){
		var version=navigator.appVersion.substring(22,23);
			xy = getPosition(el);
			if ( version == '6') {
				//menu.style.top=(xy.y)-1+'px';
				//menu.style.left=(xy.x)+140+'px';
			}
			else {
			//	menu.style.top=(xy.y)-1+'px';
			}
		}
	}*/
}
function hideMenuInterno(el,t) {
	hide(el,t);
	var menu = el.getElementsByTagName("ul")[0];
	menu.style.display='none';	
}

//function showSubMenu(el,i,url) {
//	hover(el, url);
//	document.getElementById("submenu"+i).style.display='block';
//	if(document.getElementById("boxCesta"))
//	document.getElementById("boxCesta").style.display='none';
//}

//function hideSubMenu(el,i, url) {
//	hide(el, url);
//	document.getElementById("submenu"+i).style.display='none';
//}

//function hover(el, url) {
//	var caminho = el.getElementsByTagName("a")[0].getElementsByTagName("img")[0].src;
//	var arquivo = caminho.substring(caminho.lastIndexOf("/"),caminho.lastIndexOf(".")-3)+"on.gif";
//	el.getElementsByTagName("a")[0].getElementsByTagName("img")[0].src = url + "Util/img"+arquivo;
//	//alert("Util/img"+arquivo);
//}

//function hide (el,url) {
//	var caminho = el.getElementsByTagName("a")[0].getElementsByTagName("img")[0].src;
//	var arquivo = caminho.substring(caminho.lastIndexOf("/"),caminho.lastIndexOf(".")-2)+"off.gif";
//	el.getElementsByTagName("a")[0].getElementsByTagName("img")[0].src = url + "Util/img"+arquivo;
//}

//function showMenuInternoMeuMenu(el) {
//	
//	var menu = el.getElementsByTagName("ul")[0];
//	menu.style.display='block';
//	
//	if(navigator.appName.indexOf('Internet Explorer')>0){
//		var version=navigator.appVersion.substring(22,23);
//			xy = getPosition(el);
//			if ( version == '6') {
//				menu.style.top=(xy.y)-1+'px';
//				menu.style.left=(xy.x)+140+'px';
//			}
//			else {
//				menu.style.top=(xy.y)-1+'px';
//			}
//	
//	}
//}

//function showMenuInterno(el,tipo,url) {
//	hover(el, url);
//	var menu = el.getElementsByTagName("ul")[0];
//	menu.style.display='block';
//	
//	if(tipo==1) {
//			if(navigator.appName.indexOf('Internet Explorer')>0){
//		var version=navigator.appVersion.substring(22,23);
//			xy = getPosition(el);
//			if ( version == '6') {
//				menu.style.top=(xy.y)-1+'px';
//				menu.style.left=(xy.x)+140+'px';
//			}
//			else {
//				menu.style.top=(xy.y)-1+'px';
//			}
//		}
//	}
//}

//function hideMenuInternoMeuMenu(el) {
//	var menu = el.getElementsByTagName("ul")[0];
//	menu.style.display='none';	
//}


//function hideMenuInterno(el,url) {
//	hide(el, url);
//	var menu = el.getElementsByTagName("ul")[0];
//	menu.style.display='none';	
//}

function getPosition(e){ 
	var left = 0;        
	var top  = 0;
	
	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top  += e.offsetTop;
	return {x:left, y:top};
}

function trocaFoto(qualFoto,qualLegenda, Cliente) {
    obj = document.getElementById(Cliente);
	obj.src = qualFoto;
	obj.alt = qualLegenda;		
}


/*
    Funcao Utilizada Para Bug em Repeaters do .NET
    FinalizaPedido.aspx
*/
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

/*-----------------------------------------------------------------------
Máscara para o campo data dd/mm/aaaa hh:mm:ss
Exemplo: <input maxlength="10" name="datahora" onKeyPress="DataHora(event, this)">
-----------------------------------------------------------------------*/
function DataHora(evento, objeto)
{
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00/00/0000 00:00:00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '/';
	separacao2 = ' ';
	separacao3 = ':';
	conjunto1 = 2;
	conjunto2 = 5;
	conjunto3 = 10;
	conjunto4 = 13;
	conjunto5 = 16;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (19))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao2;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao3;
		else if (campo.value.length == conjunto5)
		campo.value = campo.value + separacao3;
	}
	else
		event.returnValue = false;
}
/*
* Mascara de Formatacao de Valor
* Utilizado no Grid MasterDetail da janela Modal
*/
function FormataValor(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 == 13) return true;
key = String.fromCharCode(whichCode);  // Valor para o código da Chave
if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
len = fld.value.length;
for(i = 0; i < len; i++)
    if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    aux = '';
    for(; i < len; i++)
    if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) fld.value = '';
    if (len == 1) fld.value = '0'+ decSep + '0' + aux;
    if (len == 2) fld.value = '0'+ decSep + aux;
    if (len > 2) 
    {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
        if (j == 3) 
        {
            aux2 += milSep;
            j = 0;
        }
        aux2 += aux.charAt(i);
        j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
        fld.value += aux2.charAt(i);
        fld.value += decSep + aux.substr(len - 2, len);
    }
return false;
}
