﻿var createThemeDialog;
var settingsDialog;
var inviteDialog;
var vSearchDialog;
var reportDialog;

function settingsDialogInit() {
    //create new theme: dialog, callback: create form wizard
    settingsDialog = $('<div></div>')
		.dialog({
		    bgiframe: false,
		    autoOpen: false,
		    modal: true,
		    resizable: false,
		    width: 385,
		    height: 400,
		    close: settingsDialogInit
		});
}
function settingsDialogOpen(url, title) {
    if (settingsDialog == null)
        settingsDialogInit();
    settingsDialog.load(url);
    settingsDialog.dialog("option", "title", title);
    settingsDialog.dialog('open');
}
function settingsDialogClose() {
    settingsDialog.dialog('close');
}

function inviteDialogInit() {
    inviteDialog = $('<div></div>')
		.dialog({
		    bgiframe: false,
		    autoOpen: false,
		    modal: true,
		    resizable: false,
		    width: 455,
		    close: inviteDialogInit
		});
}
function inviteDialogOpen(url, title) {
    window.open(url, "invite", "menubar=no,width=600,height=320,toolbar=no,location=no,resizable=1");
}


function createThemeDialogInit() {

    //create new theme: dialog, callback: create form wizard
    createThemeDialog = $('<div></div>')
		.dialog({
		    bgiframe: false,
		    autoOpen: false,
		    modal: true,
		    resizable: false,
		    width: 385,
		    height: 400,
		    close: function() {
		        //If created go to theme page
		        try {
		            var newThemeId = parseInt($('#newThemeSuccessId').val());
		            if (!isNaN(newThemeId)) {
		                loadContentMain('/' + newThemeId);
		            }
		        }
		        catch (err) {
		            //Handle errors here
		        }
		    }
		});
}

function createThemeDialogOpen(url, title) {
    if (createThemeDialog == null)
        createThemeDialogInit();
    createThemeDialog.load(url, createThemeWizardInit);
    createThemeDialog.dialog("option", "title", title);
    createThemeDialog.dialog('open');
}

function createThemeDialogClose() {
    createThemeDialog.dialog('close');
}

function vSearchDialogInit() {
    vSearchDialog = $('<div></div>')
		.dialog({
		    bgiframe: false,
		    autoOpen: false,
		    modal: true,
		    resizable: false,
		    width: 480,
		    height: 470,
			close: vSearchDialogClose
		});
}
function vSearchDialogOpen(url, title) {
    if (vSearchDialog == null)
        vSearchDialogInit();
    vSearchDialog.load(url, vSearchInit);
    vSearchDialog.dialog("option", "title", title);
    vSearchDialog.dialog("option", "width", 400);
    vSearchDialog.dialog('open');
}
function vSearchDialogClose() {
	vSearchDialog.dialog('destroy');
	vSearchDialog.html('');
	vSearchDialog = null;
}




//////////////////////////

function reportDialogInit() {
    reportDialog = $('<div></div>')
		.dialog({
		    bgiframe: false,
		    autoOpen: false,
		    modal: true,
		    resizable: false,
		    width: 455,
		    close: reportDialogInit
		});
}
function reportDialogClose() {
    reportDialog.dialog('close');
}
function reportDialogOpen(url, title) {
    if (reportDialog == null)
        reportDialogInit();
    reportDialog.load(url, reportDialogInit);
    reportDialog.dialog("option", "title", title);
    reportDialog.dialog('open');
}


//dialoge
function dialogReportItemInit() {
    //Report item: dialog
    $('#dialogReportItem')
    .dialog({
        bgiframe: false,
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 455,
        buttons: {
            'Yes, Report inappropriate item': function() {
                var frm = $('form#ReportItem_form', this);
                $.ajax({
                    url: frm.attr('action'),
                    type: frm.attr('method'),
                    dataType: 'html',
                    data: $(frm).serialize(),
                    completed: $(this).dialog('close')

                });
            },
            'No, Never mind': function() {
                $(this).dialog('close');
            }
        }

    });
}



