var chaseWindowOpened = false;
var chaseWindowClosed = false;
var chasePopupWindow;
var chaseApprovalTime = 10000;
var pollingConstant = 300;
var popupWidth = 1024;
var popupHeight = 820;


function openAffiliatePopUp(url, name, bannerIdentifier, sourcePage)
{
	openAffiliatePopUp(url, name, bannerIdentifier, sourcePage, trackChaseWindow, false);
}

function openAffiliatePopUp(url, name, bannerIdentifier, sourcePage, trackChaseWindow)
{
    //First remember the banner
    //copyBannerClick(bannerIdentifier,'/intuit/scs/commerce/creditcard/AffliateCreditCardSessionBean.lastVisitedBanner');
    url = url+'?linkMap='+bannerIdentifier+'&sourcePage='+sourcePage;
    //first set the attributes of the popup window
    settings = "toolbar=yes,location=no,"+
               "status=yes,menubar=no,scrollbars=yes,"+
               "resizable=yes,width="+popupWidth+",height="+
               popupHeight;

    var bannerSource = document.getElementById("quickenChaseBannerSource");
    if (bannerSource != null) {
    	bannerSource.value = "Clicked";
    	chasePopupWindow = window.open(url, name, settings);
    }

    if (!chasePopupWindow || chasePopupWindow.closed)
    {
    	chasePopupWindow = window.open(url, name, settings);
    }
    else
    {
        chasePopupWindow.focus();
    }

	if (trackChaseWindow) {
		setTimeout(pollOnChaseWindow, chaseApprovalTime);
	}

}

function copyBannerClick(bannerIdentifier, lastVisited){

	var tField = document.getElementsByName(lastVisited).item(0);
	if(tField != 'undefined'){
		tField.value = bannerIdentifier;
	}
}

function pollOnChaseWindow() {

	if (chasePopupWindow == null) {
		alert('chase popup window is null');
		return;
	}
	try{
		if (chasePopupWindow.closed) {
			//alert('chase popup window closed');
			var refreshPageForm = document.getElementById("refreshPage");
			if (refreshPageForm != null) {
				refreshPageForm.submit();
			}
		}
		else {
			setTimeout(pollOnChaseWindow, pollingConstant);
		}
	}
	catch(err) {
		alert('error reading child page:' + err.name + err.message);
	}

}