/*function loadContents(){
    
    $("#loadContent").prepend("<div id='ajax_message' class='ajax_loader'>Loading</div>");
    
    var highlight = $("input[@name='highlight']:checked").val();

    var url = "";
    var i = 1;
	$(".select_product").each(function(){
		url += "&prod"+i+"="+$(this).val();
		i++;
	});

    $.ajax({
		type: "POST",
		url: "?api=1&compare="+ $("#compareId").val() +"&highlight=" + highlight + url,
		success: function(html){
			$("#loadContent").html(html);
		},
		error: function(){
			$("#ajax_message").html("LOAD FAILED.  PLEASE TRY AGAIN");
			setTimeout('$("#ajax_message").remove();', 3000);
		}
	});	
}*/

function loadContents(){
    
    //var highlight = $("input[@name='highlight']:checked").val();

    var url = "";
    var i = 0;
    var field_id = "";
    var field_name = "";
	$(".select_criteria:checked").each(function(){
        field_name = $(this).attr('name');
		url += "&"+field_name+"="+$(this).val();
		i++;
	});
    
    $("#loadContent").html("");
    if(i == 0){
        $("#matches").hide();
    }else{ 
        $("#loadContent").prepend("<div id='ajax_message' class='ajax_loader'>Loading</div>");
        $("#matches").show();
        $.ajax({
    		type: "POST",
    		url: "?api=1&compare="+ $("#compareId").val() + url,
    		success: function(html){
    			$("#loadContent").html(html);
    		},
    		error: function(){
    			$("#ajax_message").html("LOAD FAILED.  PLEASE TRY AGAIN");
    			setTimeout('$("#ajax_message").remove();', 3000);
    		}
    	});	  
    }  
}

function bookmarksite(title,url){
    if (window.sidebar){ // firefox
        window.sidebar.addPanel(title, url, "");
    }else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } 
    else if(document.all){// ie
        window.external.AddFavorite(url, title);
    }else{
        alert("Sorry, your browser does not support this feature.  Please bookmark by copying the link below.");
    }
}

$(document).ready(function(){
    
    $(".select_criteria").click(function(){
        loadContents();
    });
    
    $(".field .title").click(function(){
        var parent = $(this).parent();
        if($(".selects", parent).is(":visible")){
            $(".selects", parent).hide();
            $(this).removeClass("activeTitle");
            $(".select_criteria", this).each(function(){
                $(this).attr("checked", false);
            }) 
        }else{
            $(".selects", parent).show();
            $(this).addClass("activeTitle");
        }
    }); 
});
