// JavaScript Document

var PLCard;
if (!PLCard) PLCard = {};

// Submits a credit card application
PLCard.submitApp = function() {
	var form = document.getElementById("frmApplicationTermsCond");
	if (form) form.submit();
}

// Opens a window with information about the old credit card
PLCard.openPromo = function() {
	var popup = window.open('credit_card_promo.aspx', 'CreditCard','width=530,height=495,status=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes');
	if (window.focus) popup.focus();
}

// Opens a window with information about the old credit card
PLCard.openOldInfo = function() {
	var popup = window.open('credit_card_oldinfo.aspx', 'CreditCard','width=530,height=495,status=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes');
	if (window.focus) popup.focus();
}

// Initiates a purchase on the store credit card
PLCard.initAuth = function() {
	// Redirect to submit location
	setTimeout(function() { location.href = 'purchase_submit.aspx'; }, 0);
}

// Initiates a purchase on the store credit card
PLCard.initPurchase = function() {
	// Get the form from the parent frame
	var parentForm = parent.document.forms[0];
	var thisForm = document.forms[0];
	var baseURL = location.protocol + "//" + location.host;
	if (parentForm && thisForm) {
		thisForm.homeUrl.value = baseURL;
		thisForm.shopperId.value = parentForm.hdnOrderID.value;
		thisForm.clientTransactionId.value = parentForm.hdnTransID.value;
		thisForm.purchaseNotificationUrl.value = baseURL + thisForm.purchaseNotificationUrl.value;
		thisForm.creditApplyNotificationUrl.value = baseURL + thisForm.creditApplyNotificationUrl.value;
		thisForm.clientSuccessfulPurchaseUrl.value = baseURL + thisForm.clientSuccessfulPurchaseUrl.value;
		thisForm.clientUnsuccessPurchaseUrl.value = baseURL + thisForm.clientUnsuccessPurchaseUrl.value;
		thisForm.clientSuccessfulApplyUrl.value = baseURL + thisForm.clientSuccessfulApplyUrl.value;
		thisForm.clientUnsuccessApplyUrl.value = baseURL + thisForm.clientUnsuccessApplyUrl.value;
		thisForm.billToFirstName.value = parentForm.hdnFirstName.value;
		thisForm.billToLastName.value = parentForm.hdnLastName.value;
		thisForm.billToAddress1.value = parentForm.hdnAddress1.value;
		thisForm.billToAddress2.value = parentForm.hdnAddress2.value;
		thisForm.billToCity.value = parentForm.hdnCity.value;
		thisForm.billToState.value = parentForm.hdnState.value;
		thisForm.billToZipCode.value = parentForm.hdnZip.value;
		thisForm.billToHomePhone.value = parentForm.hdnPhone.value;
		thisForm.transactionAmount.value = parentForm.hdnAmount.value;
		thisForm.billToAccountNumber.value = parentForm.hdnStoreAcctNum.value;
		setTimeout(function() { thisForm.submit(); }, 0);
	}
}

// OnLoad method
PLCard.onLoad = function() {
	if (document.getElementById("frmStoreCC")) PLCard.initPurchase();
}

// Assign onload parameter
if (window.addEventListener) window.addEventListener("load", PLCard.onLoad, false);
else if (window.attachEvent) window.attachEvent("onload", PLCard.onLoad);