/**
 * Popups.
 * Decides which popup to
 * open. Currently is for
 * free and pay video and 
 * audio streaming
 */
 
var popupsConfig = {
    'radio' : {
        'free_de' : {
            'url'        : 'http://www.fcb.tv/misc/popups/radio/index.php?state=free&lang=de&fcb_sid=',
            'width'      : 303,
            'height'     : 168,
            'caption'    : 'Liveradio',
            'checklogin' : false
        },
        'pay_de' : {
            'url'        : 'http://www.fcb.tv/misc/popups/radio/index.php?state=pay&lang=de&fcb_sid=',
            'width'      : 303,
            'height'     : 168,
            'caption'    : 'Liveradio',
            'checklogin' : true
        },
        'free_en' : {
            'url'        : 'http://www.fcb.tv/misc/popups/radio/index.php?state=free&lang=en&fcb_sid=',
            'width'      : 303,
            'height'     : 168,
            'caption'    : 'Liveradio',
            'checklogin' : false
        },
        'pay_en' : {
            'url'        : 'http://www.fcb.tv/misc/popups/radio/index.php?state=pay&lang=en&fcb_sid=',
            'width'      : 303,
            'height'     : 168,
            'caption'    : 'Liveradio',
            'checklogin' : true
        }
    },
    'video' : {
        'free_de' : {
            'url'        : 'http://www.fcb.tv/misc/popups/video/index.php?state=free&lang=de&fcb_sid=',
            'width'      : 703,
            'height'     : 485,
            'caption'    : 'Livestream',
            'checklogin' : false
        },
        'pay_de' : {
            'url'        : 'http://www.fcb.tv/misc/popups/video/index.php?state=pay&lang=de&fcb_sid=',
            'width'      : 703,
            'height'     : 485,
            'caption'    : 'Livestream',
            'checklogin' : true
        },
        'free_en' : {
            'url'        : 'http://www.fcb.tv/misc/popups/video/index.php?state=free&lang=en&fcb_sid=',
            'width'      : 703,
            'height'     : 485,
            'caption'    : 'Livestream',
            'checklogin' : false
        },
        'pay_en' : {
            'url'        : 'http://www.fcb.tv/misc/popups/video/index.php?state=pay&lang=en&fcb_sid=',
            'width'      : 703,
            'height'     : 485,
            'caption'    : 'Livestream',
            'checklogin' : true
        },
        'chat' : {
            'url'        : 'http://www.fcbayern.telekom.de/misc/popups/chat_new/index.php?fcb_sid=',
            'width'      : 703,
            'height'     : 495,
            'caption'    : 'Livechat',
            'checklogin' : true
        }
    },
    'direktURL':{
        'free' : {
            'url'        : 'http://www.fcb.tv/misc/popups/video_player_direkt_url/index.php?url=',
            'width'      : 703,
            'height'     : 485,
            'caption'    : '',
            'checklogin' : false
        }
    }
};


/**
 * Opens a popup defined by type
 * (radio, video) and state (free,
 * pay)
 *
 * @type String the type of popup
 * @state String the state, free or pay
 * @return Boolean wether the popup could
 *         be created
 */
function showPopup(type, state) {
    if (checkLogin(popupsConfig[type][state].checklogin)) {
        //check pay status of user
        if (userHasFCBtv || !popupsConfig[type][state].checklogin) {
            var ok = window.open(
                popupsConfig[type][state].url + SESSIONID,
                popupsConfig[type][state].caption,
                'width='+popupsConfig[type][state].width +
                ',height='+popupsConfig[type][state].height
            );
            if (ok) return false;
        } else {
            $.prettyPhoto.open('http://www.fcbayern.telekom.de/' + LANG + '/user/index.php?c=c&msgGetFCBtv=true&iframe=true&width=620&height=90%25&fcb_sid='+SESSIONID,'','');
        }
    } else {
        var pre = '/';
        if (window.location.toString().indexOf("tv") < 0) pre = '/' + LANG + '/';
        $.prettyPhoto.open(pre + 'login_form.php?msgLive=true&cc=' + LANG + '&iframe=true&width=620&height=400&fcb_sid='+SESSIONID,'','');
    }
    return true;
}

/**
 * checks, if the user is logged in,
 * if a login is required
 *
 * @param required Boolean
 * @return Boolean
 */
function checkLogin(required) {
    if (!required) return true;
    if (userIsAuthorized) {
        return true;
    }
    return false;
}

/**
 * Opens registration window. Must not return anything!
 */
function openRegistration() {
    $.prettyPhoto.open('http://www.fcbayern.telekom.de/' + LANG + '/user/index.php?c=c&profile=true&fcb_id=' + SESSIONID + '&iframe=true&width=620&height=90%25','','');
}

/**
 * Opens the friend request ad window in a lightbox
 */
function openFriendNotifier() {
    $.prettyPhoto.open('https://www.fcbayern.de/de/user/?c=c&action=friendship&iframe=true&width=620&height=470', '', '');
}

/**
 * Opens the friend request form
 *
 * @param string requesting friend
 */
function openFriendRequest(friend) {
    $.prettyPhoto.open('https://www.fcbayern.de/de/user/?c=c&friend='+friend+'&iframe=true&width=620&height=600', '', '');    
}

/**
 * Opens a popup without any check. 
 * The URL to video must be given.
 *
 * @param high the high url
 * @param low the low url
 * 
 * @return True if popup could be created
*/
function showPopupDirektLink(high, low){
    var ok = window.open(
                popupsConfig['direktURL']['free'].url+high+"&url2="+low,
                popupsConfig['direktURL']['free'].caption,
                'width='+popupsConfig['direktURL']['free'].width +
                ',height='+popupsConfig['direktURL']['free'].height
            );
}

