function finalizarPedido() {
	location = '?on=loja&in=finalizar';
}

function limpaCarrinho() {
	if(confirm('Deseja Limpar o Carrinho?'))
		window.location = "?on=loja&in=limpar_carrinho";
	
}
//--------------------------------------------------
function buscasite() {
	var url;
	window.location = '?on=listar'
	
	url = '?on=lista';
	
	if($('categoria').value != '') 		url += '&categoria='+$('categoria').value;
	if($('fornecedor_id').value != '') 	url += '&fornecedor='+$('fornecedor_id').value;
	if($('busca').value != '') 			url += '&busca='+$('busca').value;
	
	window.location = url;
}
 
function open_info(id,img) {
	$('descricao_produto').style.display   = 'none';
	$('dados_tecnicos').style.display      = 'none';
	$('screenshots').style.display         = 'none';
	
	$(id).style.display  = 'block';
	
	if(img == '_btn_descricao')
	   $('info').innerHTML = '&nbsp; <a href="javascript:open_info(\'descricao_produto\',\'_btn_descricao\')" /><img src="resources/images/_btn_descricao_.jpg" id="_btn_descricao"/></a> <a href="javascript:open_info(\'dados_tecnicos\',\'_btn_dados_tecnicos\')" /><img src="resources/images/_btn_dados_tecnicos.jpg" id="_btn_dados_tecnicos"/></a>';
	else if(img == '_btn_dados_tecnicos') 
	  $('info').innerHTML = '&nbsp; <a href="javascript:open_info(\'descricao_produto\',\'_btn_descricao\')" /><img src="resources/images/_btn_descricao.jpg" id="_btn_descricao"/></a> <a href="javascript:open_info(\'dados_tecnicos\',\'_btn_dados_tecnicos\')" /><img src="resources/images/_btn_dados_tecnicos_.jpg" id="_btn_dados_tecnicos"/></a>';
	//else  if(img == '_btn_screenshots') 
	 //    $('info').innerHTML = '&nbsp; <a href="javascript:open_info(\'descricao_produto\',\'_btn_descricao\')" /><img src="resources/images/_btn_descricao.jpg" id="_btn_descricao"/></a> <a href="javascript:open_info(\'dados_tecnicos\',\'_btn_dados_tecnicos\')" /><img src="resources/images/_btn_dados_tecnicos.jpg" id="_btn_dados_tecnicos"/></a> <a href="javascript:open_info(\'screenshots\',\'_btn_screenshots\')" /><img src="resources/images/_btn_screenshots_.jpg" id="_btn_screenshots" /></a>';
  
}
//--------------------------------------------------
function scroll(position,id) {
    var timerTexto;
    var valor = 24;
    var total = 504;
    var cont = 0;
   
    if(position == 'right') {
        timerTexto =  setInterval(function () { 
	                                $(id).scrollLeft += valor;
	                                cont += valor;
	                                if(cont == total) { clearInterval(timerTexto) };
                                },10);
    }
    
    if(position == 'left') {
        timerTexto =  setInterval(function () { 
	                                $(id).scrollLeft -= valor;
	                                cont += valor;
	                                if(cont == total) clearInterval(timerTexto);
                                },10);
    }
}
//------------------------------------------------
function abreChat() {
	//window.open('chat/admin_chat.php?do_Activate=activate','chat','toolbar=0, location=0, directories=0, menubar=0, resizable=0, scrollbars=0, width=400px, height=490px, top=100, left=240');
	window.open('chat/cust_chat.php','chat','toolbar=0, location=0, directories=0, menubar=0, resizable=0, scrollbars=0, width=400px, height=490px, top=100, left=240');
}

//------------------------------------------------
function Filtra(campo) {
	var digits="ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvwxyz0123456789"
	var campo_temp
	
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)
	  if (digits.indexOf(campo_temp)==-1){
	     campo.value = campo.value.substring(0,i);
	     break;
	  }
	}
}
//-------------------------------------------------
function isAlpha(valor){
	var digits="ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvwxyz0123456789";
	var campo_temp;
	
	var achou;
	for (var i=0;i<valor.length;i++) {
	  campo_temp=valor.substring(i,i+1)
	  if (digits.indexOf(campo_temp)==-1)
	  	achou = '1';
	}
	
	if(achou == '1') return false
	else return true;
}

//-------------------------------------------------

function abreJanela(url,pagina,detalhe) {
	window.open(url,pagina,detalhe);
}
// ------------------------------------------------
function abreSelect(field) {
	var campo = document.getElementById(field);
	campo.style.display=(campo.style.display == 'none' || campo.style.display == '')?'block':'none';
	campo.parentNode.style.position = 'relative';
}

// ------------------------------------------------
function limpaCampos(campo,padrao){
	
	var obj = document.getElementById(campo);
	obj.select();
	if (obj.value == padrao)
		obj.value = '';
	
}

// ------------------------------------------------
function restauraCampos(campo,padrao){
	
	var obj = document.getElementById(campo);
	if (obj.value == '')
		obj.value = padrao;
	
}

// ------------------------------------------------
function validaEmail(val){
	var rep=val.replace(/^[^0-9a-zA-Z_\[\]\.\-@]+$/,"");
	return(val==""||(val==rep&&(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(val))));
}

// ------------------------------------------------
function formataCampo(e,src,mask) {
	
	if(window.event) 
		_TXT = e.keyCode;
	else if(e.which)
		_TXT = e.which;
		
	if(_TXT > 47 && _TXT < 58) { 
		var i = src.value.length; 
		var saida = mask.substring(0,1); 
		var texto = mask.substring(i)
		if (texto.substring(0,1) != saida) { 
			src.value += texto.substring(0,1); 
		} 
	return true; 
	} else { 
		if (_TXT != 8) { 
			return false; 
		} 
		else { 
			return true; 
		}
	}
}

// ------------------------------------------------
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 false;
		else
			return true;
	}
}

// ------------------------------------------------
function checkCPFCNPJ(obj,tipo) {

	var cnpj = document.getElementById(obj).value;
	
	vr = cnpj;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	cnpj = vr;
	
	if (tipo == 'cnpj') {
		   soma1 = (cnpj.charAt(0) * 5) +
			   (cnpj.charAt(1) * 4) +
			   (cnpj.charAt(2) * 3) +
			   (cnpj.charAt(3) * 2) +
			   (cnpj.charAt(4) * 9) +
			   (cnpj.charAt(5) * 8) +
			   (cnpj.charAt(6) * 7) +
			   (cnpj.charAt(7) * 6) +
			   (cnpj.charAt(8) * 5) +
			   (cnpj.charAt(9) * 4) +
			   (cnpj.charAt(10) * 3) +
			   (cnpj.charAt(11) * 2);
	   resto = soma1 % 11;
	   digito1 = resto < 2 ? 0 : 11 - resto;
	   soma2 = (cnpj.charAt(0) * 6) +
			   (cnpj.charAt(1) * 5) +
			   (cnpj.charAt(2) * 4) +
			   (cnpj.charAt(3) * 3) +
			   (cnpj.charAt(4) * 2) +
			   (cnpj.charAt(5) * 9) +
			   (cnpj.charAt(6) * 8) +
			   (cnpj.charAt(7) * 7) +
			   (cnpj.charAt(8) * 6) +
			   (cnpj.charAt(9) * 5) +
			   (cnpj.charAt(10) * 4) +
			   (cnpj.charAt(11) * 3) +
			   (cnpj.charAt(12) * 2);
	   resto = soma2 % 11;
	   digito2 = resto < 2 ? 0 : 11 - resto;
	   return ((cnpj.charAt(12) == digito1) && (cnpj.charAt(13) == digito2));
	}
	else
	
		if (cnpj.length == 11)	{
		   soma1 = (cnpj.charAt(0) * 10) +
				   (cnpj.charAt(1) * 9) +
				   (cnpj.charAt(2) * 8) +
				   (cnpj.charAt(3) * 7) +
				   (cnpj.charAt(4) * 6) +
				   (cnpj.charAt(5) * 5) +
				   (cnpj.charAt(6) * 4) +
				   (cnpj.charAt(7) * 3) +
				   (cnpj.charAt(8) * 2);
		   resto = soma1 % 11;
		   digito1 = resto < 2 ? 0 : 11 - resto;
		   soma2 = (cnpj.charAt(0) * 11) +
				   (cnpj.charAt(1) * 10) +
				   (cnpj.charAt(2) * 9) +
				   (cnpj.charAt(3) * 8) +
				   (cnpj.charAt(4) * 7) +
				   (cnpj.charAt(5) * 6) +
				   (cnpj.charAt(6) * 5) +
				   (cnpj.charAt(7) * 4) +
				   (cnpj.charAt(8) * 3) +
				   (cnpj.charAt(9) * 2);
		   resto = soma2 % 11;
		   digito2 = resto < 2 ? 0 : 11 - resto;
		   return ((cnpj.charAt(9) == digito1) && (cnpj.charAt(10) == digito2));	
		}
		else 
		   return false;
	
	return true;
		   
}


function dataValida(val) {
	var reDate = /^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
	
	return reDate.test(val);
	//return false;
}

String.prototype.capitalize = function(){ //v1.0
return this.replace(/\w+/g, function(a){
    return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

function slideMenu(source,itensMenu) {
	var calc;
	
	if($(source).style.display == 'none') {
		/*calc = $('menu').scrollHeight+(26*itensMenu);*/
		/*$('pseudo_menu').style.height	= calc+20+'px';*/
		Effect.SlideDown(source, {duration:0.3});
		
	} else {
		/*calc = $('menu').scrollHeight-(26*itensMenu);*/
		Effect.SlideUp(source, {duration:0.3});
		/*$('pseudo_menu').style.height	= calc+20+'px';*/
	}
	
}

function bg1(valor) { $(valor).style.background = '#FFFFFF'; }
function bg2(valor) { if($(valor).value == '') $(valor).style.background = '#E9E9E9'; }


function toggle(source) {
	
	if($(source).style.display == 'none') {
		Effect.SlideDown(source, {duration:0.3});
	} else {
		Effect.SlideUp(source, {duration:0.3});
	}
	
}


function toggleProduto(source,id) {
	
	if($(source).style.display == 'none') {
		Effect.SlideDown(source, {duration:0.3});
		$('imagem_'+id).src = 'resources/images/btn_fechar_detalhes.jpg';
	} else {
		Effect.SlideUp(source, {duration:0.3});
		$('imagem_'+id).src = 'resources/images/btn_exibir_detalhes.jpg';
	}
	
}

// ------------------------------------------------
function selecionaValor(disparador,alvo,label,value, hidden, flag) {
    var campo = document.getElementById(alvo);
    var lista = document.getElementById(disparador);
    var busca_secao = document.getElementById(hidden);
    
    campo.innerHTML = label;
    busca_secao.value = value;
    lista.style.display = 'none';
    campo.parentNode.parentNode.style.position = 'static';
    
    if(flag == 'TRUE'){
        
        campoEntidade = document.getElementById('simula_campo_outra_univ');
        inputEntidade = document.getElementById('outra_universidade');
        classeEntidade = campoEntidade.className;
        
        if(label == 'Outra Entidade'){
            campoEntidade.className = "sim_campo_enable";
            inputEntidade.disabled = false;
            inputEntidade.focus();
        }
        else {
            campoEntidade.className = "sim_campo_disable";
            inputEntidade.value = "";
            inputEntidade.disabled = true;
        }
    }
}
// ------------------------------------------------
function abreSelect(field) {
    var campo = document.getElementById(field);
    campo.style.display=(campo.style.display == 'none' || campo.style.display == '')?'block':'none';
    campo.parentNode.style.position = 'relative';
}


function FormataValor(campo,teclapres) {
	
	var tecla = teclapres.keyCode;
	
	var tammax = 15;

	vr = campo.value;
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "^", "" );
	tam = vr.length - 1;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
		
	/*
	for (var ct = 0; ct < document.form.elements.length; ct++) {
		if (document.form.elements[ct].name == document.form.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.form.elements[ct+1] && document.form.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
	*/
}