﻿function CountryChange(countryDropDownID, stateDivID, stateValidatorID, provinceDivID, provinceValidatorID) {
	if ($("#" + countryDropDownID).val() == "United States") {
		$("#" + stateDivID).show();
		$("#" + provinceDivID).hide();
		ValidatorEnable($("#" + stateValidatorID)[0], true);
		ValidatorEnable($("#" + provinceValidatorID)[0], false);
	} else {
		$("#" + stateDivID).hide();
		$("#" + provinceDivID).show();
		ValidatorEnable($("#" + stateValidatorID)[0], false);
		ValidatorEnable($("#" + provinceValidatorID)[0], true);
	}
}

function CopyAddressHandler(checkBox,
											fromAddress1Id,
											fromAddress2Id,
											fromCountryId,
											fromStateId,
											fromProvinceId,
											fromCityId,
											fromPostalId,
											toAddress1Id,
											toAddress2Id,
											toCountryId,
											toStateId,
											toProvinceId,
											toCityId,
											toPostalId) {
	if ($(checkBox).attr("checked")) {
		CopyAndDisable(fromAddress1Id, toAddress1Id);
		CopyAndDisable(fromAddress2Id, toAddress2Id);
		CopyAndDisable(fromCountryId, toCountryId);
		CopyAndDisable(fromStateId, toStateId);
		CopyAndDisable(fromProvinceId, toProvinceId);
		CopyAndDisable(fromCityId, toCityId);
		CopyAndDisable(fromPostalId, toPostalId);

		$("#" + toCountryId).change();
	} else {
		EnableAfterUnselect(toAddress1Id);
		EnableAfterUnselect(toAddress2Id);
		EnableAfterUnselect(toCountryId);
		EnableAfterUnselect(toStateId);
		EnableAfterUnselect(toProvinceId);
		EnableAfterUnselect(toCityId);
		EnableAfterUnselect(toPostalId);
	}
}

function CopyNameHandler(checkBox,
										fromFirstNameId,
										fromLastNameId,
										fromEmailId,
										fromPhoneId,
										toFirstNameId,
										toLastNameId,
										toEmailId,
										toPhoneId) {
	if ($(checkBox).attr("checked")) {
		CopyAndDisable(fromFirstNameId, toFirstNameId);
		CopyAndDisable(fromLastNameId, toLastNameId);
		CopyAndDisable(fromEmailId, toEmailId);
		CopyAndDisable(fromPhoneId, toPhoneId);
	} else {
		EnableAfterUnselect(toFirstNameId);
		EnableAfterUnselect(toLastNameId);
		EnableAfterUnselect(toEmailId);
		EnableAfterUnselect(toPhoneId);
	}
}

function CopyAndDisable(fromId, toId) {
	var from = $("#" + fromId);
	var to = $("#" + toId);

	to.val(from.val());

	// not doing this, but keeping it here just in case
	//to.attr("readonly", "true");
}

function EnableAfterUnselect(id) {
	// not doing this, but keeping it here just in case
	//$("#" + id).removeAttr("readonly");
}


