﻿$(document).ready(function()
{

    // if user clicked on button, the overlay layer or the dialogbox, close the dialog	
    $('a.btn-ok, #dialog-overlay, #dialog-box').click(function()
    {
        $('#dialog-overlay, #dialog-box').hide();
        return false;
    });

    // if user resize the window, call the same function again
    // to make sure the overlay fills the screen and dialogbox aligned to center	
    $(window).resize(function()
    {

        //only do it if the dialog box is not hidden
        if (!$('#dialog-box').is(':hidden')) popup();
    });


});

//Popup dialog
function popup(message, popName)
{

    // get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    // calculate the values for center alignment
    var dialogTop = (maskHeight / 3) - ($('#' + popName + '-box').height());
    var dialogLeft = (maskWidth / 2) - ($('#' + popName + '-box').width() / 2);

    // assign values to the overlay and dialog box
    $('#' + popName + '-overlay').css({ height: maskHeight, width: maskWidth }).show();
    $('#' + popName + '-box').css({ top: dialogTop, left: dialogLeft }).show();

    // display the message
    $('#' + popName + '-message').html(message);

}

function apriGuida()
{
    if (state.GetText() == '')
    {
        var popupBox = document.getElementById('guide-box');
        popupBox.style.height = '450px';
        popupBox.style.width = '500px';

        var message = '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" style="float:left;">';
        message += 'Guida';
        message += '</span> <a href="javascript:void(0);" class="ui-dialog-titlebar-close ui-corner-all" style="float:right;"> <span class="ui-icon ui-icon-closethick">close</span> </a> </div>';
        message += '<div class="dialog-text">' + 'Questa pagina Le permetter&agrave; di iscriverti al sito dedicato ai clienti Kromoss.<br />La pagina &egrave; formata da quattro sezioni da compilare interamente.' + '</div>';

        message = message + '';
        state.SetText('initiated');
        popup(message, 'guide');

        popupBox.style.top = '125px';
        $('#guide-close').click(function() { location.href = 'login.aspx'; });

        var referDiv = document.getElementById('dialog-div-refer');
        referDiv.style.marginLeft = '150px';
    
        $('.ui-dialog-titlebar-close').click(function() 
        {
            $('#dialog-box').hide();
        });

        $('a.btn-ok, #guide-overlay, #guide-box').click(function()
        {
            $('#guide-overlay, #guide-box').hide();
            return false;
        });
    }
}

function showPopUpSaved()
{
    var popupBox = document.getElementById('dialog-box');
    popupBox.style.height = 'auto';
    popupBox.style.width = '390px';

    var message = '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" style="float:left;">';
    message += 'Esito';
    message += '</span> <a href="javascript:void(0);" class="ui-dialog-titlebar-close ui-corner-all" style="float:right;"> <span class="ui-icon ui-icon-closethick">close</span> </a> </div>';
    message += '<div class="dialog-text">' + 'La vostra richiesta di registrazione &egrave; andata a buon fine.<br />Il nostro staff provveder&agrave; a comunicarLe l\'esito in tempi brevi.' + '</div>';

    popup(message, 'dialog');

    var maskHeight = $(document).height();
    popupBox.style.top = (maskHeight / 3).toString() + 'px';
    
    $('.ui-dialog-titlebar-close').click(function() 
    {
        $('#dialog-box').hide();
    });
    
    $('a.btn-ok, #dialog-overlay, #dialog-box, #dialog-close').click(function() { location.href = 'login.aspx'; });
}

function showPopUpError()
{
    var popupBox = document.getElementById('dialog-box');
    popupBox.style.height = 'auto';
    popupBox.style.width = '390px';

    var message = '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" style="float:left;">';
    message += 'Esito';
    message += '</span> <a href="javascript:void(0);" class="ui-dialog-titlebar-close ui-corner-all" style="float:right;"> <span class="ui-icon ui-icon-closethick">close</span> </a> </div>';
    message += '<div class="dialog-text">' + 'Al momento il sistema non &egrave; capace di evadere la vostra richiesta.<br />Le chiediamo gentilmente di riprovare in un secondo momento.' + '</div>';
    
    popup(message, 'dialog');

    var maskHeight = $(document).height();
    popupBox.style.top = (maskHeight / 3).toString() + 'px';
    
    $('.ui-dialog-titlebar-close').click(function() 
    {
        $('#dialog-box').hide();
    });
    
    $('a.btn-ok, #dialog-overlay, #dialog-box, #dialog-close').click(function() { location.href = 'login.aspx'; });
}

function popupEsitoUpload(title, innerMessage, elementFocus)
{
    popupEsitoUpload(title, innerMessage, elementFocus, '');
}

function popupEsitoUpload(title, innerMessage, elementFocus, url)
{
    var popupBox = document.getElementById('dialog-box');
    popupBox.style.height = 'auto';
    popupBox.style.width = '390px';

    var message = '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" style="float:left;">';
    message += title;
    message += '</span> <a href="javascript:void(0);" class="ui-dialog-titlebar-close ui-corner-all" style="float:right;"> <span class="ui-icon ui-icon-closethick">close</span> </a> </div>';
    message += '<div class="dialog-text">' + innerMessage + '</div>';
    popup(message, 'dialog');

    var maskHeight = $(document).height();
    popupBox.style.top = (maskHeight / 4).toString() + 'px';
    
    if(url == '' || url == undefined)
    {
        $('.ui-dialog-titlebar-close').click(function() 
        {
            $('#dialog-box').hide();
        });
    }
    else
    {
        $('.ui-dialog-titlebar-close').click(function() 
        {
           location.href = url;
        });
        
        $('#dialog-close').click(function() 
        { 
            location.href = url; 
        });
    }

    if (elementFocus != null)
    {
        $('a.btn-ok, #dialog-overlay, #dialog-box, #dialog-close').click(function() { elementFocus.Focus(); });
    }

    $('a.btn-ok, #dialog-overlay, #dialog-box, #dialog-close').focus();
}

function showCampionarioHtml(serie)
{
    var popupBox = document.getElementById('dialog-box');
    popupBox.style.height = '600px';
    popupBox.style.width = '900px';

    $(".dialog-box > .dialog-content").css('height', '90%');    

    var message = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"\n' +
    '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"\n' +
    '  WIDTH="100%" HEIGHT="100%" id="flashMovie" align="middle">\n' +
    '  <PARAM NAME="allowScriptAccess" value="sameDomain" />\n' +
  	'  <PARAM NAME="allowFullScreen" value="true" />\n' +
    '  <PARAM NAME=movie ' +
    '    VALUE="CampionariHtml/' + serie + '/' + serie + '.swf?pageNumber=' + getURLParam('pageNumber') + '" />\n' +
    '  <PARAM NAME=quality VALUE=high />\n' +
    '  <PARAM NAME=bgcolor VALUE=#EEEEEE />\n' +
    '  <PARAM NAME=scale VALUE=noscale />\n' +
    '  <EMBED src="CampionariHtml/' + serie + '/' + serie + '.swf?pageNumber=' + getURLParam('pageNumber') + '"' +
    '    bgcolor=#EEEEEE WIDTH="100%" HEIGHT="100%" ' +
    '    quality="high"' +
    '    scale="noscale"' +
    '    name="flashMovie"' +
    '    allowFullScreen="true"' +
    '    TYPE="application/x-shockwave-flash"' +
    '  />\n' +
    '</OBJECT>\n';
    popup(message, 'dialog');

    var maskHeight = ($(document).height() / 8) + window.pageYOffset;
    popupBox.style.top = maskHeight + 'px';
}
