// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

jQuery(function() {

	jQuery("#kortingsactie").height(jQuery("#kortingsactie").height());

	jQuery("#archive-browser .fresh").change(function() {
	
		jQuery("#archive-pot")
			.empty()
			.html("<div style='text-align: center; padding: 30px;'><img src='/wp-content/themes/DiggingIntoWordPress-2/images/ajax-loader.gif' /></div>");
	
		var dateArray = jQuery("#month-choice").val().split("/");
		var y = dateArray[3];
		var m = dateArray[4];
		var c = jQuery("#cat").val();
		var u = jQuery("#subcat").val();
		var t = jQuery("#type").val();
		var d = jQuery("#discount").val();
		var a = jQuery("#user").val();
		var s = 0;
		if(jQuery(this).is("#shipping")) {
			if(jQuery(this).is(":checked")) {
				var s = jQuery(this).val();
			} 
		}

		var loc = window.location;
		//alert(c);

		var hcat = getUrlVars()["hcat"];
		var scat = getUrlVars()["scat"];
		

		if(hcat){				
				if(hcat != c){	
					if(u != '-1'){ 
						location.href = "http://www.korting.nl/?cat=" + u + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a + "&hcat=" + c
					}else if(c != '-1'){
						location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
					}else{
						location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
					}
				}else{	
					if(u == '-1'){ 
						location.href = "http://www.korting.nl/?cat=" + u + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a + "&hcat=" + c
					}else if(c == '-1'){
						location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
					}else{
						location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
					}
				}					
		}else if(u != '-1'){ 
			location.href = "http://www.korting.nl/?cat=" + u + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a + "&hcat=" + c
		}else if(c != '-1'){
			location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
		}else{
			location.href = "http://www.korting.nl/?cat=" + c + "&digwp_y=" + y + "&digwp_m=" + m + "&digwp_d=" + d + "&digwp_t=" + t + "&digwp_a=" + a
		}	


/*
		jQuery.ajax({
		
			url: "/filter/",
			dataType: "html",
			type: "POST",
			data: ({
				"digwp_y": y,
				"digwp_m" : m,
				"digwp_c" : c,
				"digwp_t" : t,
				"digwp_d" : d
			}),
			success: function(data) {
				jQuery("#archive-pot").html(data);
				
				jQuery("#kortingsactie").animate({
					height: jQuery("#archives-table tr").length * 50
				});
			
			}
			
		}); */
			
	});


});
