
function populateShipAddress(copyfields,needRefresh) { // Populates the ShipAddress fields
	if (copyfields == true) {
		$("#ShipName").val($("#FirstName").val() + " " + $("#LastName").val());
		$(".shipfield").each(function(index){
			$(this).val($("#Bill"+$(this).attr('name').replace(/Ship/,'')).val());
		});
	} else {
		$("#ShipName").val("");
		$(".shipfield").each(function(index){
			$(this).val("");
		});
	}
	if (needRefresh == true) { fnRefreshShipping($("#ShipCountryCode")[0],$("#ShipTypeId")[0],$("#ShipProvStateId")[0]); }
}

function fnShipOptionChange(countryCode) {
	if ($("#ShipOption").val() == "ShipToMe") {
		$("#ShipName").removeAttr("disabled");
		$("#ShipAddress1").removeAttr("disabled");	
		$("#ShipAddress2").removeAttr("disabled");	
		$("#ShipCity").removeAttr("disabled");	
		$("#ShipCountryCode").removeAttr("disabled");	
		$("#ShipProvStateId").removeAttr("disabled");	
		$("#ShipPostalCode").removeAttr("disabled");	
		objFormfrmMain.ShipName.required = true;
		objFormfrmMain.ShipAddress1.required = true;
		objFormfrmMain.ShipCity.required = true;
		objFormfrmMain.ShipCountryCode.required = true;
		objFormfrmMain.ShipProvStateId.required = true;
		objFormfrmMain.ShipPostalCode.required = true;
		$("#ShipTypeId").removeAttr("disabled");
		populateShipAddress(true,false);
		fnRefreshShipping($("#ShipCountryCode")[0],$("#ShipTypeId")[0],$("#ShipProvStateId")[0]);
	} else {
		objFormfrmMain.ShipName.required = false;
		objFormfrmMain.ShipAddress1.required = false;
		objFormfrmMain.ShipCity.required = false;
		objFormfrmMain.ShipCountryCode.required = false;
		objFormfrmMain.ShipProvStateId.required = false;
		objFormfrmMain.ShipPostalCode.required = false;
		$("#ShipName").val("").attr("disabled", true);
		$("#ShipAddress1").val("").attr("disabled", true);	
		$("#ShipAddress2").val("").attr("disabled", true);	
		$("#ShipCity").val("").attr("disabled", true);	
		$("#ShipCountryCode").val("").attr("disabled", true);	
		$("#ShipProvStateId").val("").attr("disabled", true);	
		$("#ShipPostalCode").val("").attr("disabled", true);	
		if ($("#ShipOption").val() == "ShipToWishlister") {
			$("#ShipTypeId").removeAttr("disabled");
			$("#ShipCountryCode").val(countryCode);
			fnRefreshShipping($("#ShipCountryCode")[0],$("#ShipTypeId")[0],$("#ShipProvStateId")[0]);
		} else {
			$("#ShipCountryCode").val("CA");
			fnRefreshShipping($("#ShipCountryCode")[0],$("#ShipTypeId")[0],$("#ShipProvStateId")[0]);
			$("#ShipTypeId").val("4").attr("disabled", true);
		}
	}
}

