/*
 * Valida o tamanho m?ximo de um campo
 */
function validaTamanhoMaximo(obj, size) {
	if(obj != null && obj.value != null && obj.value.length > parseInt(size) ) {
		obj.value = obj.value.substr(0, parseInt(size));
	}
}


// Funcao que bloqueia CTRL + N
function checkCtrl() {
		   var ch = String.fromCharCode(event.keyCode)
		   if ((event.ctrlLeft || event.CtrlRight) && (ch == "n" || ch == "N"))
		     return false;
}
document.onkeydown = checkCtrl;

function docOnKeypress(evt) 
{ 
    var e = evt? evt : window.event; 

    if (!e)
       return; 

    var key = 0; 

    if (e.keycode) 
    { 
       key = e.keycode; 
    } 
     else if (typeof(e.which)!= 'undefined') 
      {
          key = e.which; 
          
       } 
    // n = 110
    if (key == 110  && e.ctrlKey ) {
       return false;
    }
      
} 
document.onkeypress = docOnKeypress; 


//fun??es para abrir popups
function popup(end, nome, width, height) {
	window.open(end,nome,'toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=' + width + ',height='+height);
}

function popReserva(param) {
	popup('popup/reserva.htm?'+param,'Reservas','360','330');
}

function popTransporta(param) {
	popup('popup/transportadora.htm?'+param,'titulo','width','height');
}

function popEtiqueta(param) {
	popup('popup/etiqueta.html?'+param,'Etiqueta','620','212');
}

function popLogin(param) {
	popup('popup/telaLogin.html?'+param,'confirmar','310','260');
}

<!--script para destacar a linha-->
function destacarLinha(obj){
  switch(obj.className){
	  case "linhaDestaque":
      if (obj.oldClassName != undefined)
        obj.className = obj.oldClassName;
      break;
    default:
      obj.oldClassName = obj.className;
      obj.className = "linhaDestaque";
      break;
	}
}

//script para destacar a linha do produto principal - usado apenas em venda/pedido/pedido_resultadoBusca
function destacarLinhaPrincipal(obj){
  switch(obj.className){
	  case "linhaDestaquePrincipal":
      if (obj.oldClassName != undefined)
        obj.className = obj.oldClassName;
      break;
    default:
      obj.oldClassName = obj.className;
      obj.className = "linhaDestaquePrincipal";
      break;
	}
}

//quando um input text recebe foco seleciona um check box ou radio button de acordo com o id mandado
function digitaSeleciona(id){
  itemSelec=document.getElementById(id);
  if(itemSelec.checked==false){
  itemSelec.click();
  }
}

//muda a p?gina exibida
function mudaPagina(src){
	document.location=src;
}

//retira sele??o de todos check box da p?gina
function limpaSelecao(){
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].type=="checkbox") {
				document.forms[i].elements[e].checked = false;
			}
		}
	}
}
	
//seleciona todo check box da p?gina
function selecionaTudo(obj){
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].type=="checkbox") {
				document.forms[i].elements[e].checked = obj.checked;
			}
		}
	}
}	

//seleciona todo check box da tabela
function selecionaTudoTabela(obj,idTable){
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			pageElement=document.forms[i].elements[e];
			if(pageElement.type=="checkbox"){
				if (pageElement.name.substring(6,8)==idTable){ 
					document.forms[i].elements[e].checked = obj.checked;
				}
			}
		}
	}
}	


/*codigo para mostrar e ocultar os hints*/
function startHint (divName, text){
    selectedDiv=document.getElementById(divName);
	    if (!selectedDiv.status){
             
            posX = event.clientX;
             
            // Verifica se o div pode ser cortado
            // ou seja se a posi??o do mouse (vent.clientX) mais o tamanho
            // do div (selectedDiv.offsetWidth) s?o maiores que o tamanho 
            // do iframe (window.frameElement.offsetWidth)
            if (window.frameElement){ // se existe o iframe

               if (event.clientX+selectedDiv.offsetWidth > window.frameElement.offsetWidth){
                  posX = event.clientX - (event.clientX+selectedDiv.offsetWidth - window.frameElement.offsetWidth);
               };
               
            };

			posY = event.clientY + window.document.documentElement.scrollTop;

			displayHint(selectedDiv,text,posX,posY);
		}else{
		   	hideHint(divName);
		}

}
 
function displayHint(div,text,posX,posY){
	div.style.visibility="visible";
	div.style.left=posX+"px";
	div.style.top=posY+"px";
	div.innerHTML= "<span class=textoHint>" + text + " </span>";
	div.status=true;
}

function hideHint(divName){
    selectedDiv=document.getElementById(divName);
	selectedDiv.style.visibility="hidden";
   	selectedDiv.status=false;
}

//c?digos de telas espec?ficas

//c?digo exclusivo da tela de alterar dados da venda
//mostra e esconde os detalhes do produto
function showDetails(){
	if (detalhePedido.style.visibility=="visible")
   		detalhePedido.style.visibility="hidden";
   	else
		detalhePedido.style.visibility="visible";
}


//c?digo para ir para a pr?xima tela ap?s a confirma??o no modal
function confirma(){
	hidePopWin(false);
	main=parent.window.document.getElementById("iconteudo");
	main.src="teste.htm";
}

//c?digo exclusivo da tela de rastreamento e de reserva para mandar e-mail e registrar que cliente foi informado
function informado(tipo, checkName, campoInfo){
	rastreamento=document.getElementById(campoInfo);
	if (rastreamento.value==""){
//disparar mensagem de erro quando n?o foi informado 
//tela rastreamento: c?digo de rastreamento
//tela de reserva: data de expira??o
	}else{
		if(tipo=="email"){
		<!--mandar e-mail informando o c?digo de rastreamento-->
		}
		check=document.getElementById(checkName);
		check.checked=true;
	}
}

//c?digo exlcuiso da tela de cadastrar produto para abrir o link registrado pelo usu?rio
function abrirLinkProduto(){
	linkInput=document.getElementById("linkIn");
	linkText=linkInput.value;
	popup(linkText,'Link_promocional','800px','500px');
}


//in?cio c?digo da tela da cesta de compras

//mostra e esconde os detalhes do tipo de frete de acordo com a sele??o
 function frete(divName){
    divTrans=document.getElementById("transportadora");
    divSedex=document.getElementById("sedex");
	divTrans.style.display="none";
	divSedex.style.display="none";
	if (divName=="trans")
		divTrans.style.display="block";
	else if (divName=="sedex")
		divSedex.style.display="block";
}

//limpa o campo de dados do atualize-se se checkbox desativado
function atualize(checkbox, inputId){
	if(checkbox.checked==false){
		inputSelec=document.getElementById(inputId);
		inputSelec.value="";
	}
}

//fim c?digo da tela da cesta de compras


/*c?digo exclusivo para a tela de resultado de busca*/
function startDescHint(divName, detalhes, garantia, qtdMatriz)
{
	divText=".detalhes: &nbsp;" + detalhes + "<br> .garantia: &nbsp;" + garantia +"<br> .qtde matriz: " + qtdMatriz;
	startHint(divName, divText);
}

/*c?digo exclusivo para a tela de manter reserva*/
function startReservaHint(divName, vendedor, televenda, obs)
{
    selectedDiv=document.getElementById(divName);
	posX = event.clientX;
	posY = event.clientY + window.document.documentElement.scrollTop;
	divText=".vendedor: &nbsp;" + vendedor + "<br> .televenda: &nbsp;" + televenda +"<br> .observa&ccedil;&otilde;es: " + obs;
	displayHint(selectedDiv,divText,posX,posY);
}

/*fim de c?digo para mostrar e ocultar os hints*/

//c?digo exclusivo para editar forma de pagamento
function formaPagto(obj,id){
	document.getElementById("cheque"+id).style.display="none";
	document.getElementById("boleto"+id).style.display="none";
	document.getElementById("cartao"+id).style.display="none";	

	switch(obj.options[obj.selectedIndex].value){
	case "cheque":
		document.getElementById("cheque"+id).style.display="block";	
		break;
	case "chequePre":
		document.getElementById("cheque"+id).style.display="block";	
		break;		
	case "cc":
		document.getElementById("cartao"+id).style.display="block";	
		break;		
	case "cd":
		document.getElementById("cartao"+id).style.display="block";	
		break;	
	case "boleto":
		document.getElementById("boleto"+id).style.display="block";	
		break;	
	}
}
//fim do c?digo exclusivo para editar forma de pagamento

//c?digo exclusivo para a tela de efetiva??o de compar
function tipoVenda(obj) {
	if (obj.options[obj.selectedIndex].value=="ecf"){
		document.getElementById("vendaECF").style.display="block";		
	}else{
		document.getElementById("vendaECF").style.display="none";
	}	
}
//fim do c?digo exclusivo para a tela de efetiva??o de compar

/*in?cio c?digo destidano ? tela de edi??o do fechamento de caixa*/

<!-- ids dos divs: formaPagto; agrupar; pdv; -->

<!--AGRUPAR-->
function agrupar(obj,nNota){
    divAgrupar=document.getElementById("agrupar");
	if (divAgrupar.style.display=="block"){
		<!--quando est? vis?vel, s? h? a necessidade de se armazenar o id da nota selecionada para ser agrupada-->
	}else{
		hideGroup("agrupar");
		<!--guarda o n?mero da nota-->
		divAgrupar.style.display="block";
	}
}

<!--EDITAR-->
function editar(numero, tipo){ <!--numero da nota ou do pdv, e tipo entre nota e pdv-->
    div=document.getElementById(tipo);
	if (div.style.display=="none"){
		hideGroup(tipo);
		<!--guarda o n?mero da nota-->
		div.style.display="block";
	}
}

<!--script para enconder um grupo de divs-->
function hideGroup(divRef) {
	switch (divRef){
		case"agrupar": 
			hideDiv("pdv");
			hideDiv("formaPagto"); 
		break;
		case"pdv":
			hideDiv("agrupar");
			hideDiv("formaPagto");
		break;
		case"formaPagto":
			hideDiv("agrupar");
			hideDiv("pdv");
		break;
	}
}

<!--script para enconder um div espec?fico-->
function hideDiv(divId){
		divHide=document.getElementById(divId);
		if (divHide.style.display=="block"){
			<!--dispara mensagem de erro informando que as altera??es feiras no div foram perdidas-->
		divHide.style.display="none";
		}
}

/*fim c?digo destidano ? tela de edi??o do fechamento de caixa*/

/*c?digo ajuda r?pida e manual*/
function abrirManual(url) {
	window.open(url, 'Manual', 'width=750,height=500,scrollbars=1');
}

function abrirHelp(url, base) {
	window.open(base + '/manual/manual.do?nome=' + url, 'Ajuda', 'width=340,height=300,scrollbars=1');
}
