/* POPULATE ELEMENT */

function populateElement(selector, defvalue) {
	$(selector).each(function() {
		if($.trim(this.value) == "") {
			this.value = defvalue;
			$(this).css('color', 'gray');
		}
	});
	
	$(selector).focus(function() {
		if(this.value == defvalue) {
			this.value = "";
			$(this).css('color', 'black');
		}
	});
	
	$(selector).blur(function() {
		if($.trim(this.value) == "") {
			this.value = defvalue;
			$(this).css('color', 'gray');
		}
	});
}

$(document).ready(function () {
	
	$('select[name=buscamarca]').change(function() {
		window.location = base_url+'outlet/buscar/marca/'+$(this).val();
	});
	
	$('select[name=buscaprecio]').change(function() {
		window.location = base_url+'outlet/buscar/precio/'+$(this).val();
	});
	
	$('select[name=buscaong]').change(function() {
		window.location = base_url+'outlet/buscar/ong/'+$(this).val();
	});
	
	populateElement("#codigo", 'Introduce código');
	$("#codigo").change(function() {
		if ($(this).val().length == 12){
			$.post(base_url+'outlet/validarcodigo', {
				codigo: $(this).val()
			}, function(data) {
				window.location = base_url+'outlet/cesta';
			});
		}
	});
	
});