﻿var domain = document.domain;

$(function() {
$(".categoryDropdown").change(function(e) {
        RefreshList();
    });

    $(".regionDropdown").change(function(e) {
        RefreshList();
    });

    $(".addReviewNextButton").click(function(e) {
    if ($(".selectPartner").val() == null) {
            e.preventDefault();
            $("#errorMessage").html("Please select a partner");
        }
    });
});

function RefreshList() {   
    $(".selectPartner").empty();

    var categoryId = $(".categoryDropdown").val();
    var regionId = $(".regionDropdown").val();

    $.get("http://" + domain + "/WebServices/GetCategoryRegionProducts.aspx?categoryId=" + categoryId + "&regionId=" + regionId, function(xml) {
    	$("productContent", xml).each(function() {
    		var productId = $("productId", this).text();
    		var productName = $("productName", this).text();

    		$(".selectPartner").append("<option value=\"" + productId + "\">" + productName + "</option>");
    	});
    });
}
