function ExportPdfSettings(link, id, title){
    hs.width = 500;
    hs.height = 200;
    hs.objectWidth  = 500;
    hs.objectHeight  = 200;
    hs.minWidth  = 500;
    hs.minHeight = 200;
    hs.maxWidth  = 500;
    hs.maxHeight = 200;
    return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );
}


var saveactivationemail = false;
function ChangeGameStatus (link, id, groupId, status, newtext, title, hs)
{
    var newstatus;
    if (status == 1) {


        var url = 'games.php';
        data = 'ID=' + id + '&group_id='+ groupId +'&action=activate';
        jQuery.ajax({
            url: url,
            type:'POST',
            data:data
        });

        if ( canGoHighSlide(link) ) {
            hs.width = 750;
            hs.height = 450;
            hs.objectWidth  = 750;
            hs.objectHeight  = 450;
            hs.minWidth  = 750;
            hs.minHeight = 450;
            hs.maxWidth  = 750;
            hs.maxHeight = 450;

            hs.Expander.prototype.onBeforeClose = function (sender) {
                var EditForm = sender.content.getElementsByTagName("iframe")[0];
                if ( typeof EditForm != 'undefined' && EditForm.src.search(/game_message\.php/i) != -1 ) {
                    if( !saveactivationemail ){
                        if (confirm('Are you sure ?')) {
                            saveactivationemail = false;
                            var visibletext = '#status_notice_'+ id;
                            if (status == 1) {
                                newstatus = 0;
                            } else {
                                newstatus = 1;
                            }
                            var oldtext = jQuery(link).text();
                            if (status == 1) {
                                jQuery(visibletext).addClass("hidden");
                            } else {
                                jQuery(visibletext).removeClass("hidden");
                            }
                            jQuery(link).attr('onclick','');
                            jQuery(link).text(newtext);
                            jQuery(link).unbind('click');
                            jQuery(link).click(function () {
                                ChangeGameStatus(this, id, groupId, newstatus, oldtext, title, hs);
                                return false;
                            });
                        } else {
                            return false;
                        }

                    }else if ( saveactivationemail ){
                        saveactivationemail = false;
                        var visibletext = '#status_notice_'+ id;
                        if (status == 1) {
                            newstatus = 0;
                        } else {
                            newstatus = 1;
                        }
                        var oldtext = jQuery(link).text();
                        if (status == 1) {
                            jQuery(visibletext).addClass("hidden");
                        } else {
                            jQuery(visibletext).removeClass("hidden");
                        }
                        jQuery(link).attr('onclick','');
                        jQuery(link).text(newtext);
                        jQuery(link).unbind('click');
                        jQuery(link).click(function () {
                            ChangeGameStatus(this, id, groupId, newstatus, oldtext, title, hs);
                            return false;
                        });
                    }
                }
            }
            return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );
        } else {
            return false;
        }
    } else {
        if ( confirm('Are you sure ?') ){
            var url = 'games.php?ID=' + id + '&group_id=' + groupId + '&action=';
            var visibletext = '#status_notice_'+ id;
            if (status == 1) {
                url = url + 'activate';
                newstatus = 0;
            } else {
                url = url + 'deactivate';
                newstatus = 1;
            }

            var oldtext = jQuery(link).text();
            jQuery.ajax({
                url: url,
                type:'GET',
                success: function(){
                    if (status == 1) {
                        jQuery(visibletext).addClass("hidden");
                    } else {
                        jQuery(visibletext).removeClass("hidden");
                    }
                    jQuery(link).attr('onclick','');
                    jQuery(link).text(newtext);
                    jQuery(link).unbind('click');
                    jQuery(link).click(function () {
                        ChangeGameStatus(this, id, groupId, newstatus, oldtext, title, hs);
                        return false;
                    });
                }
            });
        }
        return false;
    }
}

function SaveGameAnswersEmail(id,groupId,subject,message)
{
    var url = 'games.php';
    data = 'ID=' + id + '&group_id='+ groupId +'&action=saveanswersemail&subject=' + subject + '&message=' + message;
    jQuery.ajax({
        url: url,
        type:'POST',
        data:data,
        success: function(){
            if (parent.window.hs) {
                parent.window.hs.close();
            }
        }
    });
}

function SaveGameActivationEmail(id,groupId,subject,message)
{
    parent.saveactivationemail = true;
    var url = 'games.php';
    data = 'ID=' + id + '&group_id='+ groupId +'&action=saveactivationemail&subject=' + subject + '&message=' + message;
    jQuery.ajax({
        url: url,
        type:'POST',
        data:data,
        success: function(){
            if (parent.window.hs) {
                parent.window.hs.close();
            }
        }
    });
}

function ChangeAnswersStatus (link, id, groupId, status, newtext, title, hs)
{
    var newstatus;
    if (status == 1) {
        hs.width = 750;
        hs.height = 450;
        hs.objectWidth  = 750;
        hs.objectHeight  = 450;
        hs.minWidth  = 750;
        hs.minHeight = 450;
        hs.maxWidth  = 750;
        hs.maxHeight = 450;

        hs.Expander.prototype.onBeforeClose = function (sender) {
            var EditForm = sender.content.getElementsByTagName("iframe")[0];
            if ( typeof EditForm != 'undefined' && EditForm.src.search(/game_message2\.php/i) != -1 ) {
                if ( confirm('Are you sure ?') ){
                    var url = 'games.php?ID=' + id + '&group_id=' + groupId + '&action=';
                    if (status == 1) {
                        url = url + 'showanswers';
                        newstatus = 0;
                    } else {
                        url = url + 'hideanswers';
                        newstatus = 1;
                    }
                    var oldtext = jQuery(link).text();
                    jQuery.ajax({
                        url: url,
                        type:'GET',
                        success: function(){
                            jQuery(link).attr('onclick','');
                            jQuery(link).text(newtext);
                            jQuery(link).unbind('click');
                            jQuery(link).click(function () {
                                ChangeAnswersStatus(this, id, groupId, newstatus, oldtext, title, hs);
                                return false;
                            });
                        }
                    });
                }
            }
        }
        return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );
    } else {
        if ( confirm('Are you sure ?') ){
            var url = 'games.php?ID=' + id + '&group_id=' + groupId + '&action=';
            if (status == 1) {
                url = url + 'showanswers';
                newstatus = 0;
            } else {
                url = url + 'hideanswers';
                newstatus = 1;
            }
            var oldtext = jQuery(link).text();
            jQuery.ajax({
                url: url,
                type:'GET',
                success: function(){
                    jQuery(link).attr('onclick','');
                    jQuery(link).text(newtext);
                    jQuery(link).unbind('click');
                    jQuery(link).click(function () {
                        ChangeAnswersStatus(this, id, groupId, newstatus, oldtext, title, hs);
                        return false;
                    });
                }
            });
        }
        return false;
    }
}

function UnlinkGame (link, id, groupId)
{
    if ( confirm('Are you sure ?') ){
        var url = 'games.php?ID=' + id + '&group_id=' + groupId + '&action=unlink';
        var oldtext = jQuery(link).text();
        jQuery.ajax({
            url: url,
            type:'GET',
            success: function(){
                window.location="grp.php?action=group&ID="+groupId;
            }
        });
    }
    return false;
}

function ChangeCalendarStatus (link, id, status, newtext, confirm_text, confirm_text2)
{
    if ( confirm(confirm_text) ){
        var url = 'grp.php?ID=' + id + '&action=';
        if (status == 1) {
            url = url + 'showcalendar';
            newstatus = 0;
        } else {
            url = url + 'hidecalendar';
            newstatus = 1;
        }
        var oldtext = jQuery(link).text();
        jQuery.ajax({
            url: url,
            type:'GET',
            success: function(){
                CalendarStatus = status;
                jQuery(link).attr('onclick','');
                jQuery(link).text(newtext);
                jQuery(link).unbind('click');
                jQuery(link).click(function () {
                    ChangeCalendarStatus(this, id, newstatus, oldtext, confirm_text2, confirm_text);
                    return false;
                });
            }
        });
    }
    return false;
}

function ShowQuestionsForm (link, title, hs, confirm_text) {
    var w=925;
    var h=500;

    if ( canGoHighSlide(link) ) {
        hs.width = w;
        hs.height = h;
        hs.objectWidth  = w;
        hs.objectHeight  = h;
        hs.minWidth  = w;
        hs.minHeight = h;
        hs.maxWidth  = w;
        hs.maxHeight = h;

        hs.Expander.prototype.onBeforeClose = function (sender) {
            var EditForm = sender.content.getElementsByTagName("iframe")[0];
            if ( typeof EditForm != 'undefined' && EditForm.src.search(/\/teachers\/index\.php/i) != -1 ) {
                return confirm(confirm_text);
            } else {
                return true;
            }
        }

        hs.Expander.prototype.onAfterClose = function (sender) {
            var EditForm = sender.content.getElementsByTagName("iframe")[0];
            if ( typeof EditForm != 'undefined' && EditForm.src.search(/\/teachers\/index\.php/i) != -1 ) {
                jQuery.ajax({
                    url: 'teachers/quest_build.php?act=clear',
                    type:'GET',
                    complete:function (XMLHttpRequest, textStatus) {
                        parent.window.location.reload();
                    }
                });
            }
            return true;
        }

        return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );
    } else {
        return false;
    }
}

function ShowDeleteMarksForm (link, title, hs)
{
    var w=650;
    var h=250;
    hs.width = w;
    hs.height = h;
    hs.objectWidth  = w;
    hs.objectHeight  = h;
    hs.minWidth  = w;
    hs.minHeight = h;
    hs.maxWidth  = w;
    hs.maxHeight = h;
    hs.wrapperClassName = 'draggable-header no-footer game-content';

    return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );

}

function ShowEventForm (link, title, hs, confirm_text)
{
    hs.width = 600;
    hs.height = 420;
    hs.objectWidth  = 600;
    hs.objectHeight  = 420;
    hs.minWidth  = 600;
    hs.minHeight = 420;
    hs.maxWidth  = 600;
    hs.maxHeight = 420;
    hs.wrapperClassName = 'draggable-header no-footer game-content';
/*
    hs.Expander.prototype.onBeforeClose = function (sender) {
        var EditForm = sender.content.getElementsByTagName("iframe")[0];
        if ( typeof EditForm != 'undefined' && EditForm.src.search(/calendar_events\.php/i) != -1 ) {
            return confirm(confirm_text);
        } else {
            return true;
        }
    }
*/
    return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );

}

function ShowDescriptionForm (link, title, hs, confirm_text)
{
    hs.width = 600;
    hs.height = 420;
    hs.objectWidth  = 600;
    hs.objectHeight  = 420;
    hs.minWidth  = 600;
    hs.minHeight = 420;
    hs.maxWidth  = 600;
    hs.maxHeight = 420;
    hs.wrapperClassName = 'draggable-header no-footer game-content';
    return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );

}

function ShowBigCalendar (link, title, hs)
{
    hs.width = 900;
    hs.height = 560;
    hs.objectWidth  = 900;
    hs.objectHeight  = 560;
    hs.minWidth  = 900;
    hs.minHeight = 560;
    hs.maxWidth  = 900;
    hs.maxHeight = 600;
    hs.wrapperClassName = 'draggable-header no-footer game-content';

    return hs.htmlExpand(link, { objectType: 'iframe', headingText: title } );
}

function DeleteCalendarEvent (grp_id, id, edate, month, newurl, confirm_text)
{
    if ( confirm(confirm_text) ){
        var url = 'calendar_events.php?action=delete_event' + grp_id + '&eID=' + id;
        jQuery.ajax({
            url: url,
            type:'GET',
            success: function(){
                getHtmlData( 'calendar-listings', newurl + '?mode=ajax&action=show_date_events' + grp_id + '&date=' + edate);
                getHtmlData( 'calendar', newurl + '?mode=ajax&action=show_calendar' + grp_id + '&month=' + month );
                return false;
            }
        });
    }
    return false;
}

function ReloadCalendar (grp_id, edate, month, newurl)
{
    getHtmlData( 'calendar-listings', newurl + '?mode=ajax&action=show_date_events' + grp_id + '&date=' + edate);
    getHtmlData( 'calendar', newurl + '?mode=ajax&action=show_calendar' + grp_id + '&month=' + month );
    return false;
}


showCreateGame = function ( link , wTitle ) {
    if ( canGoHighSlide(link) ) {
        var hs2 = jQuery.extend(true, {}, hs );
        hs2.htmlExpand(link, {
            objectType: 'iframe',
            headingText: wTitle,
            wrapperClassName: 'draggable-header no-footer game-content',
            preserveContent: false,

            minWidth: 		650,
            width: 			650,
            objectWidth: 	650,

            minHeight: 		280,
            height: 		280,
            objectHeight: 	280

        } );
    }
    return false;
}
showEditGameTitle = function ( link , wTitle ) {
    if ( canGoHighSlide(link) ) {
        var hs2 = jQuery.extend(true, {}, hs );
        hs2.htmlExpand(link, {
            objectType: 'iframe',
            headingText: wTitle,
            wrapperClassName: 'draggable-header no-footer game-content',
            preserveContent: false,

            minWidth: 		650,
            width: 			650,
            objectWidth: 	650,

            minHeight: 		150,
            height: 		150,
            objectHeight: 	150

        } );
    }
    return false;
}
showGameStats = function ( link , wTitle ) {
    if ( canGoHighSlide(link) ) {
        hs.htmlExpand(link, {
            objectType: 'iframe',
            minWidth: 950,
            minHeight: 480,
            width: 950,
            height: 480,
            objectWidth: 950,
            objectHeight: 480,
            headingText: wTitle
        } );
    }
    return false;
}

ajaxGamesShowQuestions = function () {
}

ajaxGamesBackToClass = function () {
    parent.window.location.reload();
}

var __holdHighSlideFlag = false;
var __holdHighSlideClick = false;
var __holdHighSlideLink = false;

returnHighSlideTimeout = function () {
    setTimeout ( 'returnHighSlide()' , 1000 );
}
returnHighSlide = function () {
    __holdHighSlideLink.onclick=__holdHighSlideClick;
    __holdHighSlideFlag = false;
}
canGoHighSlide = function (link) {
    var result = false;
    if ( ! __holdHighSlideFlag ) {
        pauseHighSlide (link);
        setTimeout ( 'returnHighSlide()' , 1000 );
        // hs.Expander.prototype.onHideLoading =  function (sender) { returnHighSlideTimeout (); }
        result = true;
    }
    return result;
}
pauseHighSlide = function (link) {
    __holdHighSlideFlag = true;
    __holdHighSlideClick = link.onclick;
    link.onclick = returnFalse;
    __holdHighSlideLink = link;
}
returnFalse = function () {
    return false;
}
