function openWindow(url, width) {
	window.open(url, "wo", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=600,top=100,left=100");
}

$(document).ready(function() {
    
    $("input[name=tax]").bind("change", function() {
        location.href = "/Action.asp?mode=show_tax&value=" + $(this).val();
    });
    
    $("input.gotoCart").bind("click", function() {
        location.href = "?page=cart";
    });
    
    $("select.cartProducts").bind("change", function() {
        var val = $(this).val();

        if (val == -1)
            location.href = "?page=cart";
        else if (val != 0)
            location.href = "?page=product&ProductID=" + val;
    });    

	// Fields with inner help-text, such as "Sök..."
	var originalValue = "";
	
	$("input.help").focus(function() {
		if($(this).newValue === undefined) {
			$(this).originalValue = $(this).val();
			$(this).val("");
		}
		else {
			$(this).val($(this).newValue);
		}
	}).blur(function() {
		if($(this).val() === "") {
			$(this).val($(this).originalValue);
			$(this).newValue = "";
		}
		else {
			$(this).newValue = $(this).val();
		}
	});

	$(".product-listing td").mouseover(function() {
		$(this).parent().find("td").addClass("hover");
	}).mouseout(function() {
		$(this).parent().find("td").removeClass("hover");
	});
		
	$("#forgotPasswordLink").click(function() {
		if($(this).next().css("display") == "block") {
			$(this).next().hide();
			$(this).html("Glömt lösenord?");
		}
		else {
			$(this).next().show();
			$(this).html("Ångra");
		}
	});

	$("#sortBy").change(function() {
		$(this).parents("form").submit();
	});
	
	$("#onlyInStock").click(function() {
		$(this).parents("form").submit();
	});
	
	$("#sortingOrder").change(function() {
		$(this).parents("form").submit();
	});
	
	$("form.requestPassword").submit(function(e) {
		postVars = $(this).serialize();

		$.ajax({
			type: "POST",
			url: "/ajax.asp?mode=request_password",
			cache: false,
			data: postVars,
			success: function(response) {
				if (response == "true") {
					alert("Ett nytt lösenord har nu skickats till den angivna e-postadressen!");
				}
				else {
					alert("Lösenordet kunde inte skickas.");
				}
			}
		});

		return false;
	});

});