$(function() {
	$('#productcategory').change(function() {
		//alert('you have selected ' + $(this).val());
		
		var dataString = "pfid=" + $(this).val();
		
		$.ajax({
		    type: "POST",
		    url: "../bin/process_productfinder.php",
 		    dataType: 'json',
		    data: dataString,
		    success: function(data) {
		    	var options = '<option value="">Select a Product</option>';
		    	$.each(data, function(ProductType,ProductTypeId) {
		    		options += '<option value="' + ProductTypeId + '">' + ProductType + '</option>';
		    		//alert(ProductType);
		    	});
		    	//alert(data);
		    	$('#newLocation').html(options);
		    	$('#newLocation').removeAttr( 'disabled' );
		    }
		});
		return false;
	});
	
	$('#newLocation').change(function() {
		var url = window.location.pathname;  
        var myPageName = url.substring(url.lastIndexOf('/') + 1);   
        var prefix = '';
		if(myPageName=='login.cfm' || myPageName=='index.cfm'){
			prefix = "../Products/";
		} 
		
		window.location.href = prefix + "product.php?pfid=" + $('#productcategory').val() + "&ptid=" + $(this).val();
	});
	
});
