function addProduto(prod1_cod){
	frm = document.getElementById("add"+prod1_cod);
	var erro = 0;
        
        if ($('#tipoSelecao').val() == 'multi'){
            if ($(".opcao_produto:radio[checked]").val() == undefined){
                alert("Selecione a opção desejada.");
                erro = 1;
            }
        }
        
	if (frm.prod1_qtd.value.length < 1){
            if (erro == 0){
		alert("Preencha a quantidade desejada.");
		frm.prod1_qtd.focus();
                erro = 1;
            }
	}
        
        if (erro == 0){
            frm.submit();
	}
}

function inteiro(e){
	var tecla = (window.event)?event.keyCode:e.which;

	if((tecla > 47 && tecla < 58) || tecla == 0){
		return (true);
	}
	else{
		if (tecla != 8){
			return (false);
		}
		else {
			return (true);
		}
	}
}

function paginaBusca(pag, view){
	urlBase = $('#frmPaginacao #urlBase').attr('value');
	url = urlBase+pag+"/"+view+"/";

	$('#frmPaginacao').attr('action',url);
	$('#frmPaginacao').submit();
}

function validaNews(frm){
    if (frm.nome.value.length < 1){
        alert("Preencha seu nome.");
        frm.nome.focus();
        return (false);
    }
    if (frm.email.value.length < 1){
        alert("Preencha seu e-mail.");
        frm.email.focus();
        return (false);
    }
    return (true);
}

function validaComentario(frm){
    if (frm.nome.value.length < 1){
        alert("Preencha seu nome.");
        frm.nome.focus();
        return (false);
    }
    if (frm.msg.value.length < 1){
        alert("Preencha seu comentário.");
        frm.msg.focus();
        return (false);
    }
    return (true)
}

function validaContato(frm){
	if (frm.nome.value.length < 1){
		alert("O campo 'nome' é obrigatório.");
		frm.nome.focus();
		return (false);
	}
	if (frm.email.value.length < 1){
		alert("O campo 'e-mail' é obrigatório.");
		frm.email.focus();
		return (false);
	}
	if (frm.ddd.value.length < 1){
		alert("O campo 'ddd' é obrigatório.");
		frm.ddd.focus();
		return (false);
	}
	if (frm.telefone.value.length < 1){
		alert("O campo 'telefone' é obrigatório.");
		frm.telefone.focus();
		return (false);
	}
	if (frm.msg.value.length < 1){
		alert("O campo 'mensagem' é obrigatório.");
		frm.msg.focus();
		return (false);
	}
	return (true);
}

function alteraItemOrc(itpe1_cod){
    qtd = $('#qtd'+itpe1_cod).val();

    if (qtd < 1){
            alert("Preencha a quantidade corretamente.");
            $('#qtd'+itpe1_cod).focus();
    }
    else {
        document.location = root_path+"/carrinho/alterarItemOrc/"+itpe1_cod+"/"+qtd;
    }
}

function excluiItemOrc(itpe1_cod){
    if(confirm('Deseja realmente excluir o produto do Orçamento?')){
        document.location = root_path+"/carrinho/excluirItemOrc/"+itpe1_cod;
    }
}

function excluiOrc(pedi1_cod){
    if(confirm('Deseja realmente excluir este Orçamento?')){
        document.location = root_path+"/carrinho/excluirOrc/"+pedi1_cod;
    }
}

$(function(){

    $('.qtip').qtip({
       content: 'Para efetuar um novo orçamento  adicione mais produtos ao carrinho  <a href="../../index.php">clique aqui</a>',
       show: 'click',
       hide: 'click',
       //position: '',
       fixed: true,
       style: {
          width: 200,
          padding: 10,
          background: '#A2D959',
          color: 'black',
          textAlign: 'center',
          border: {
             width: 7,
             radius: 5,
             color: '#A2D959'
         },
         tip: { // Now an object instead of a string
            corner: 'topLeft', // We declare our corner within the object using the corner sub-option
            color: '#C20000',
            size: {
                x: 30, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                y : 10 // Depending on which corner your tooltip is at, x and y could mean either height or width!
            }
         }
      }
    });
})
