﻿var PLACE_HOLDER_ID = "noticePopupHolder";
var isPopupDisplayed = false;
function NoticePopup()
{
    // define object properties
    this.div = document.createElement('div');
    this.div.id = PLACE_HOLDER_ID;
    //this.div.className = "noticeBubble";
    this.width = '350px';
    this.height = '159px';
    this.className = 'noticeBubble';
    this.backgroundImage = 'url(images/notice_bubble.gif)';
    this.backgroundRepeat = 'no-repeat';
    this.position = "absolute";
    this.y = '10px';
    this.x = '10px';
    //this.padding = '2px';
    //this.border = '1px solid #989898';
    //this.backgroundColor = '#ffffff';
    this.overflow = "auto";
    this.body = '';
    this.html = '';
    this.showCloseButton = true;
    // define 'display()' method
    this.display = function(){
        this.div.style.width = this.width;
        this.div.style.height = this.height;
        this.div.style.position = this.position;
        this.div.style.backgroundImage = this.backgroundImage;
        this.div.style.backgroundRepeat = this.backgroundRepeat;
        this.div.style.top = this.y;
        this.div.style.left = this.x;
        //this.div.style.padding = this.padding;
        //this.div.style.border = this.border;
        //this.div.style.background = this.backgroundColor;
        this.div.style.zIndex = 51200;
        this.div.style.overflow = this.overflow;
        this.html = '<div>';
        if (this.showCloseButton)
        {
            this.html +='    <div style="float:right;padding:5px;height:15px;cursor: pointer" onclick="HidePopup();"><img src="images/close_tiptool.jpg"></div>'
        }
        this.html +='    <div style="clear:right">';
        this.html +=        this.body;
        this.html +='    </div>';
        this.html +='</div>';
        this.div.innerHTML = this.html;
        document.getElementsByTagName('body')[0].appendChild(this.div);
        this.div.style.display = '';//'block';
    }
}

//------------------------------------------------------------------------------------------

function DownloadNoticePopup(senderObj, mediaItemGuid, adsAmount, usedAds)
{
    var html = null;
    var elementBounds = Sys.UI.DomElement.getBounds(senderObj);
    var posX = elementBounds.x;
    var posY = elementBounds.y;
    
    this.x = posX + 200 +  'px';
    this.y = posY - 100 +  'px';
         
    html ='     <div style="clear:right;margin-left:10px;width:320px">';
    html +='        <div class="fieldContainer">';
    html +='            <div style="text-align:left">Please note, video ads cannot be modified after purchase.<br/>Please make sure to preview your video ad before proceeding<br/> to checkout.</div>';
    html +='            <div class="grayLabel" style="text-align:center;margin-top:5px">You have ' + (adsAmount - usedAds) + ' of ' + adsAmount + ' ads left to create.<br/>Are you sure you want to download this ad ?</div>';
    html +='        </div>';
    html +='     </div>';
    html +='    <div style="clear:right;margin-left:100px;margin-top:10px;width:130px">';
    html +='        <div class="fieldContainer">';
    html +='            <div style="float:left;width:50px;cursor:pointer;color:#FFFFFF;text-align:center;font-weight:bold;padding:3px;background-color:#c1c61b" onclick="UpdateAdForDownload(\'' + mediaItemGuid + '\');">Yes</div>';
    html +='            <div style="float:left;width:50px;cursor:pointer;color:#FFFFFF;text-align:center;font-weight:bold;padding:3px;background-color:#c1c61b;margin-left:10px" onclick="HidePopup();">No</div>';
    html +='        </div>';
    html +='     </div>';
    
    this.body = html;
}
DownloadNoticePopup.prototype = new NoticePopup();

//------------------------------------------------------------------------------------------

function ShowDownloadNoticePopup(senderObj, mediaItemGuid, adsAmount, usedAds)
{
    var oDownloadNoticePopup = new DownloadNoticePopup(senderObj, mediaItemGuid, adsAmount, usedAds);
	oDownloadNoticePopup.display();
}

//------------------------------------------------------------------------------------------

function LeaveMixerNoticePopup(senderObj)
{
    var html = null;
    var elementBounds = Sys.UI.DomElement.getBounds(senderObj);
    var posX = elementBounds.x;
    var posY = elementBounds.y;
    
    this.x = posX - 300 + 'px';
    this.y = posY - 200 + 'px';
     
    html ='     <div style="clear:right;margin-left:10px;width:320px">';
    html +='        <div class="fieldContainer">';
    html +='            <div class="grayLabel" style="font-size:11px;text-align:center;margin-top:5px">All your changes will not be save.<br/>Are you sure you want to leave this page?</div>';
    html +='        </div>';
    html +='     </div>';
    html +='    <div style="clear:right;margin-left:100px;margin-top:50px;width:130px">';
    html +='        <div class="fieldContainer">';
    html +='            <div style="float:left;width:50px;cursor:pointer;color:#FFFFFF;text-align:center;font-weight:bold;padding:3px;background-color:#c1c61b;font-size:11px;" onclick="window.location.href=\'../default.aspx\'">Yes</div>';
    html +='            <div style="float:left;width:50px;cursor:pointer;color:#FFFFFF;text-align:center;font-weight:bold;padding:3px;background-color:#c1c61b;margin-left:10px;font-size:11px;" onclick="HidePopup();">No</div>';
    html +='        </div>';
    html +='     </div>';

    this.body = html;
}
LeaveMixerNoticePopup.prototype = new NoticePopup();

//------------------------------------------------------------------------------------------

function ShowLeaveMixerNoticePopup(senderObj)
{
    if (getXMLConfigObject().value != getSavedXMLObject().value)
    {
        var oLeaveMixerNoticePopup = new LeaveMixerNoticePopup(senderObj);
	    oLeaveMixerNoticePopup.display();
	}
	else
	{
	    window.location.href = "../default.aspx";
	}
}

//------------------------------------------------------------------------------------------

function HidePopup()
{
    document.getElementsByTagName('body')[0].removeChild(document.getElementsByTagName("body")[0].lastChild);
}