var xcoord= 0;
var ycoord = 0;

//Check for IE
var isIE = false;
var browser = new String(navigator.appName);
if (browser.indexOf("Internet Explorer") != -1)
	isIE = true;

function showRestricted()
{
	var windowSize = 110;
	if (isIE)
		windowSize = 142;
    editAndDisplayPopup("Offer Restrictions", 
                        "This coupon may only be available at certain retailers and/or geographic locations.", 
                        "", 
                        "",
                        windowSize);
}


function showSomeCouponAvailable(storeList)
{
	var windowSize;
    //Use the "ACTIVE" link to determine if the user is in My Coupons
    var myCouponsActiveLink = document.getElementById("activelabel");
    if (myCouponsActiveLink != null)
    {
    	windowSize = 160;
        editAndDisplayPopup("Offer Restrictions", 
                            "This offer is available at the following retailers:", 
                            "", 
                            storeList,
                            windowSize);
    }
    else
    {
    	windowSize = 185;
        editAndDisplayPopup("Offer Restrictions", 
                            "This offer is available at the following retailers:", 
                            "Please click the Add icon in the bottom corner of the coupon to add it to your store card.", 
                            storeList,
                            windowSize);
	}
}


function showNoCouponAvailable(storeList)
{
	var windowSize = 185;
    editAndDisplayPopup("Offer Restrictions", 
                        "Please <a href=\"/myprofile/mycards\" style=\"color:#0860A8;\">add your store card</a> information from one of these retailers to your account to take advantage of this offer:", 
                        "", 
                        storeList,
                        windowSize);
}


function showGeoRestricted()
{
	var windowSize = 100;
	if (isIE)
		windowSize = 125;
    editAndDisplayPopup("Offer Restrictions", 
                        "This coupon is only available in certain geographic locations.", 
                        "",
                        "",
                        windowSize);
}


function showRedemption(date, storeRedeemed, hhRedemption)
{
    var displayString1;
    var windowSize;
    		
    if (!hhRedemption)
    {
            displayString1 = "This coupon was redeemed on <b>" + date + " at " + storeRedeemed + "</b>.";
            windowSize = 112;
            if (isIE)
            	windowSize = 127;
    }
    else
    {
            displayString1 = "This coupon was redeemed on <b>" + date + "</b>, by someone believed to be in your household.   If you feel this coupon has been redeemed incorrectly, or to determine the cards within your household, please contact " + storeRedeemed + " customer service.";
            windowSize = 192;
            if (isIE)
            	windowSize = 207;
    }

    editAndDisplayPopup("Redemption details",
                        displayString1,
                        "",
                        "",
                        windowSize);

}

function editAndDisplayPopup(headline, text1, text2, list, divHeight)
{
    //Change the headline
    var offerHeadObj = document.getElementById("offerHeadline");
    offerHeadObj.innerHTML = headline;
    
    //Edit text1
    var offerText1Obj = document.getElementById("offerText1");
    offerText1Obj.innerHTML = text1;
    
    //Edit text2
    var offerText2Obj = document.getElementById("offerText2");
    offerText2Obj.innerHTML = text2;
    
    //Edit list
    var offerListObj = document.getElementById("offerList");
    
    //empty list
    offerListObj.innerHTML = "";
    
    var numListItems = 0;
    //if the list has comma-delimited elements, insert them
    if(list != "")
    {
        var listStr = new String(list);
        var listItems = listStr.split(",");
        numListItems = listItems.length;
        for (var i=0; i < listItems.length; i++)
        {
            offerListObj.innerHTML += "<li>" + listItems[i] + "</li>";
        }
    }
    //display
    var offerPopupObj = document.getElementById("offerPopup");
    offerPopupObj.style.left = (xcoord-70) + "px";
    //only if not IE6
    offerPopupObj.style.top  = (ycoord-15) + "px";
    offerPopupObj.style.height = (divHeight + (numListItems * 10)) + "px";
    offerPopupObj.style.display = "block";
}

