if(window.location.hostname=='localhost') {
	var base_url_app = 'http://localhost/bspcu/app/';
	var base_urll = 'http://localhost/bspcu';
	console.log("\nFuncionando en local.");
} else {
	var base_url_app = 'http://pcu.ls-rp.es/app/';
	var base_urll = 'http://pcu.ls-rp.es';
}

jQuery(document).ready(function()
{

    // Dropdown for topbar nav
    jQuery("body").bind("click", function(e) {
        jQuery('.dropdown-toggle, .menu').parent("li").removeClass("open");
    });
    jQuery(".dropdown-toggle, .menu").click(function(e) {
        var $li = jQuery(this).parent("li").toggleClass('open');
        return false;
    });
    
    // Autoselect text
	$('#auto_select_text,#auto_select_text2').mouseenter(function() {
		this.focus();
		this.select();
	});
	
	$(".alert-message").alert();
	
	$('.tabs').tabs();

	$("#misamigos").tablesorter();
	$("#certificaciones").tablesorter();
	

	
	// Crear cuenta 
    jQuery("a#crear_cuenta").click(function(e) {
		e.preventDefault();
		
		jQuery("div#crear_cuenta").toggle("slow");
		
		console.log("crear_cuenta() ");
    });
	
	
	// Clic en votos de preguntas
		jQuery(function() {
		    jQuery("a.vote").click(function(evento) {
				evento.preventDefault();
		        var name = jQuery(this).attr("name"); //up
		        var parent = jQuery(this);
				var votoRef = jQuery(this).attr( 'href' );
		        if(name == 'up')
		        {
		            jQuery.ajax({
		                type: "POST",
		                url: base_urll+"/jquery/pregunta_voto_positivo"+votoRef,
		                cache: false,
		                success: function(html)
		                {
		                	if(parseFloat(html)==111){
		                		jQuery(parent).fadeIn(1000).html('<span class="up_v"></span>');
		                	}
		                	else
		                	{
			                	//alert(html);
								if(html!=1) {
									$('div.modal-body').text(html);
									$('#modal_negativa').modal('show');
								} else {
									$('div.modal-body').text("Solo se permite un voto &uacute;nico.");
									$('#modal_negativa').modal('show');
								}
		                	}
		                },
						error: function (XMLHttpRequest, textStatus, errorThrown)
						{
							console.log("deal with errors vote up");
						}
		            });
		        }
		        else
		        {
		            jQuery.ajax({
		                type: "POST",
		                url: base_urll+"/jquery/pregunta_voto_negativo"+votoRef,
		                cache: false,
		                success: function(html) {
		                	if(parseFloat(html)==111){
		                		jQuery(parent).fadeIn(1000).html('<span class="down_v"></span>');
		                	}
		                	else
		                	{
			                	//alert(html);
								if(html!=1) {
									$('div.modal-body').text(html);
									$('#modal_negativa').modal('show');
								} else {
									$('div.modal-body').text("Solo se permite un voto &uacute;nico.");
									$('#modal_negativa').modal('show');
								}
		                	}
		                },
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							console.log("deal with errors vote down");
						}
		            });
		        }
		        return false;
		    });
		});
			 
	// Clic en votos de respuestas
		jQuery(function() {
		    jQuery("a.voteres").click(function(evento) {
				evento.preventDefault();
		        var name = jQuery(this).attr("name"); //up
		        var parent = jQuery(this);
				var votoRef = jQuery(this).attr( 'href' );
				
		        if(name == 'up')
		        {
		            jQuery.ajax({
		                type: "POST",
		                url: base_urll+"/jquery/respuesta_voto_positivo"+votoRef,
		                cache: false,
		                success: function(html)
		                {
		                	if(parseFloat(html)==111){
		                		jQuery(parent).fadeIn(1000).html('<span class="up_v"></span>');
		                	}
		                	else
		                	{
			                	//alert(html);
								if(html!=1) {
									$('div.modal-body').text(html);
									$('#modal_negativa').modal('show');
								} else {
									$('div.modal-body').text("Solo se permite un voto unico.");
									$('#modal_negativa').modal('show');
								}
		                	}
		                },
						error: function (XMLHttpRequest, textStatus, errorThrown)
						{
							console.log("deal with errors vote up");
						}
		            });
		        }
		        else
		        {
		            jQuery.ajax({
		                type: "POST",
		                url: base_urll+"/jquery/respuesta_voto_negativo"+votoRef,
		                cache: false,
		                success: function(html) {
		                	if(parseFloat(html)==111){
		                		jQuery(parent).fadeIn(1000).html('<span class="down_v"></span>');
		                	}
		                	else
		                	{
			                	//alert(html);
								if(html!=1) {
									$('div.modal-body').text(html);
									$('#modal_negativa').modal('show');
								} else {
									$('div.modal-body').text("Solo se permite un voto &uacute;nico.");
									$('#modal_negativa').modal('show');
								}
		                	}
		                },
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							console.log("deal with errors vote down");
						}
		            });
		        }
		        return false;
		    });
		});
		//********** FIN VOTOS ****************



	// Color filas de tablas par/inpar
	jQuery('th').parent().addClass('cabecera');
	jQuery('tr:not([th]):even').addClass('even');
	jQuery('tr:not([th]):odd').addClass('odd');
	jQuery('td:contains("No tiene")').addClass('sin_info');
	
	
	jQuery("tr").not(':first').hover(
	  function () {
	    jQuery(this).css("background","#65A6D1");
	  }, 
	  function () {
	    jQuery(this).css("background","");
	  }
	);
	//********** FIN COLOR FILAS TABLAS***


	// Respuestas predefinidas para certificar usuarios
	jQuery(function() {
		jQuery('#respuestapredefinida01').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Respuestas poco elaboradas\n');
		});
		jQuery('#respuestapredefinida02').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Revisa tu ortografia\n');
		});
		jQuery('#respuestapredefinida03').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Respuestas incorrectas\n');
		});
		jQuery('#respuestapredefinida04').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Respuestas copiadas\n');
		});
		jQuery('#respuestapredefinida05').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Debes mejorar mas el rol que desarrollara tu personaje. Intentalo de nuevo.\n');
		});
		jQuery('#respuestapredefinida06').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Faltan algunos atributos a rellenar\n');
		});
		jQuery('#respuestapredefinida07').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Respuestas incorrectas\n');
		});
		jQuery('#respuestapredefinida08').click(function() { 
			var areaValue = jQuery('#comentario').val();
			jQuery('#comentario').val(areaValue + 'Respuestas incorrectas\n');
		});
	});
	//********** FIN RESPUESTAS PREFAB **************
}); // EOF DOC RDY


	
	// Buscar RPC
	function lookup(inputString) {
		if(inputString.length == 0) {
			jQuery('#suggestions').fadeOut(); // Hide box
		} else {
			//
			jQuery.post(base_url_app+"libraries/rpc.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
				jQuery('#suggestions').fadeIn(); // Show box
				jQuery('#suggestions').html(data); // Fill box
			});
		}
	}
//********** FIN RPC *****************
