var REGALOS = {};

REGALOS.busquedaAvanz = function() {
	window.document.frmBusquedas.action = "/regalos-navidad/catalogo-productos/buscador/index.html";
	window.document.frmBusquedas.submit();
};

REGALOS.destacaProducto = function(indice) {
	$('.ZnotACT').each(function() {
		$(this).hide();
	});
	$('#rotatorio-' + indice).fadeIn();
};

REGALOS.productoAleatorio = function(indice) {
	var total = $('.ZnotACT').length;
	var aleaje = Math.floor(Math.random()*total);
	$('.ZnotACT').each(function(index) {
		if(index == aleaje) {
			$(this).show();
		}
	});

};

REGALOS.seleccionCheckbox = function() {
	if(jQuery.url.attr('query') == null) {
		return;
	}
	var arrReq = jQuery.url.attr('query').split('&');
	var i = 0;
	var datosGet = '';
	for(i=0; i<arrReq.length; i++) {
		datosGet = arrReq[i].split('=');
		if(datosGet[0] == 'perfiles') {
			$('#frmBusquedas input[name=perfiles]').filter(function () {
				if($(this).val() == datosGet[1]) {
					$(this).attr("checked", true);
				}
            })
		}
		if(datosGet[0] == 'categorias') {
			$('#frmBusquedas input[name=categorias]').filter(function () {
				if($(this).val() == datosGet[1]) {
					$(this).attr("checked", true);
				}
            })
		}
		if(datosGet[0] == 'precios') {
			$('#frmBusquedas input[name=precios]').filter(function () {
				if($(this).val() == datosGet[1]) {
					$(this).attr("checked", true);
				}
            })
		}
		if(datosGet[0] == 'edad') {
			$('#frmBusquedas input[name=edad]').filter(function () {
				if($(this).val() == datosGet[1]) {
					$(this).attr("checked", true);
				}
            })
		}
		if(datosGet[0] == 'producto') {
			$('#frmBuscar select[name=producto]').filter(function () {
				if($(this).val() == datosGet[1]) {
					$(this).attr("selected", true);
				}
            })
		}
		if(datosGet[0] == 'termino') {
			$('#frmBuscar input[name=termino]').val(datosGet[1]);
		}
	}

};

REGALOS.seleccion = function(id_chk) {
	$('#frmBusquedas input').filter(function () {
		if($(this).attr("id") == id_chk) {
			$(this).attr("checked", !$(this).is(':checked'));
		}
	})
};

$(document).ready(function() {
	REGALOS.seleccionCheckbox();
	REGALOS.productoAleatorio();
});

