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 showCouponDesc(headline, desc)
{
    var formattedTextHtml = "<b>" + headline + "</b> " + desc;
    editAndDisplayPopup("Coupon Details", 
                        formattedTextHtml, 
                        "", 
                        "");
}    
    
function showRestricted()
{
    editAndDisplayPopup("Offer Restrictions", 
                        "This coupon may only be available at certain retailers and/or geographic locations.", 
                        "", 
                        "");
}


function showSomeCouponAvailable(userStoreList, otherStoreList)
{
    var windowSize;
    //Use the "ACTIVE" link to determine if the user is in My Coupons
    var myCouponsActiveLink = document.getElementById("activelabel");
    if (myCouponsActiveLink != null)
    {
        editAndDisplayPopup("Coupon Restrictions", 
                            "This offer is available at the following retailers:", 
                            "", 
                            userStoreList,
                            otherStoreList);
    }
    else
    {
        editAndDisplayPopup("Coupon 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.", 
                            userStoreList,
                            otherStoreList);
    }
}


function showNoCouponAvailable(storeList)
{
    editAndDisplayPopup("Coupon 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);
}


function showGeoRestricted()
{
    editAndDisplayPopup("Coupon Restrictions", 
                        "This coupon is only available in certain geographic locations.", 
                        "",
                        "");
}


function showRedemption(date, storeRedeemed, hhRedemption)
{
    var displayString1;
    var windowSize;
            
    if (!hhRedemption)
    {
            displayString1 = "This coupon was redeemed on <b>" + date + " at " + storeRedeemed + "</b>.";
    }
    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.";
    }

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

}

function editAndDisplayPopup(headline, text1, text2, list, list2)
{
	var moreDetail = document.getElementById("moreDetail");
	if (moreDetail != null)
	{
		moreDetail.style.display = "none";
	}
	
    //Change the headline
    var offerHeadObj = document.getElementById("offerHeadline");
    offerHeadObj.innerHTML = headline;
    
    //Edit text1
    var offerText1Obj = document.getElementById("offerText1");
    offerText1Obj.innerHTML = text1;
    
    //Edit text2 (remove if not passed)
    var offerText2Obj = document.getElementById("offerText2");
    if (text2 == undefined || text2 == "")
    {
        offerText2Obj.innerHTML = "";
        offerText2Obj.style.height = "0px"; 
    } 
    else
    {
        offerText2Obj.innerHTML = text2;
        offerText2Obj.style.height = "auto";
    }
    
    //Edit list
    var offerListObj = document.getElementById("offerList");
    offerListObj.innerHTML = "";
    
    if(list == undefined || list == "")
        offerListObj.style.height = "0px";
    else
    {
        offerListObj.style.height = "auto";
        var numListItems = 0;
    
        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>";
        }
        
        if (listStr.indexOf("*") != -1)
        {
        	offerListObj.innerHTML += "<p style='margin-top:5px;'>* Coupon may already be loaded at this retailer.";
        }
    }
    
    if (list2 != null)
	{
    	var htmlForMore = "<ul class='offerPopupList'>";
    	
    	var listStr = new String(list2);
        var listItems = listStr.split(",");
        for (var i=0; i < listItems.length; i++)
        {
        	htmlForMore += "<li>" + listItems[i] + "</li>";
        }
    	htmlForMore += "</ul>";
    	if (document.getElementById("moreDetail") != null)
    		document.getElementById("moreDetail").innerHTML = htmlForMore;
    	if (document.getElementById("moreText") != null) 
    		document.getElementById("moreText").style.display = "block";
	}
    
    else
    {
    	if (document.getElementById("moreDetail") != null)
    		document.getElementById("moreDetail").innerHTML = "";    	
    	if (document.getElementById("moreText") != null) 
    		document.getElementById("moreText").style.display = "none";
	}
   
    
    //display
    var offerPopupObj = document.getElementById("offerPopup");
    offerPopupObj.style.left = (xcoord-142) + "px";
    //only if not IE6
    offerPopupObj.style.top  = (ycoord-15) + "px";
    offerPopupObj.style.zIndex = "1003";
    offerPopupObj.style.display = "block";
}


