﻿

var m_bExecuteAjaxOnComplete = true;
function CancelWait()
{
    m_bExecuteAjaxOnComplete = false;
    HideWait();
}

function ShowWait()
{
    m_bExecuteAjaxOnComplete = true;
    document.getElementById( "Wait" ).style.display = "block";
}

function HideWait()
{
    document.getElementById( "Wait" ).style.display = "none";
}

function AttemptDownload( downloadUri )
{

    var iframe;
    if( document.getElementById( "__frameDownload" ) == undefined )
    {
        iframe = document.createElement( "iframe" );
        iframe.id = "__frameDownload";
        iframe.style.display = "none";
        window.document.body.insertBefore( iframe, null );
    }
    else
    {
        iframe = document.getElementById( "__frameDownload" );
    }
    
    iframe.src = downloadUri;
}

function CreateAdditionalTextBox( txt ) {

    //$(txt).keydown(function() { });

    $(txt).unbind();

    //txt.onkeydown = null;

    var div = $("<div></div>"); //document.createElement( "div" );
    var input = $("<input type='text' class='TextboxLong' />");
    div.append(input);
    

    $(txt).parent().after(div);
    //var newText = document.createElement( "<input type='text' class='TextboxLong' >" );
 
    //div.insertBefore( newText )
    //txt.parentElement.insertAdjacentElement( "afterEnd", div );

    return input;
}

function CreateAdditionalTextArea( txt, rows )
{
    txt.onkeydown = null;

    var div = document.createElement( "div" );

    var newText = document.createElement( "textarea" );
    newText.className = "TextboxLong"; 
    newText.rows = rows;

    div.insertBefore( newText )
    txt.parentElement.insertAdjacentElement( "afterEnd", div );

    return newText;
}



function AddToFavorites() 
{ 
    if ( window.external ) 
    {
        window.external.AddFavorite( location.href, document.title ) 
    }
    else
    {
        alert( "Sorry! Your browser doesn't support this function." );     
    }
}



/*
* imgPreview jQuery plugin
* Copyright (c) 2009 James Padolsey
* j@qd9.co.uk | http://james.padolsey.com
* Dual licensed under MIT and GPL.
* Updated: 09/02/09
* @author James Padolsey
* @version 0.22
*/
(function(c) { c.expr[':'].linkingToImage = function(a, g, e) { return !!(c(a).attr(e[3]) && c(a).attr(e[3]).match(/\.(gif|jpe?g|png|bmp)$/i)) }; c.fn.imgPreview = function(j) { var b = c.extend({ imgCSS: {}, distanceFromCursor: { top: 10, left: 10 }, preloadImages: true, onShow: function() { }, onHide: function() { }, onLoad: function() { }, containerID: 'imgPreviewContainer', containerLoadingClass: 'loading', thumbPrefix: '', srcAttr: 'href' }, j), d = c('<div/>').attr('id', b.containerID).append('<img/>').hide().css('position', 'absolute').appendTo('body'), f = c('img', d).css(b.imgCSS), h = this.filter(':linkingToImage(' + b.srcAttr + ')'); function i(a) { return a.replace(/(\/?)([^\/]+)$/, '$1' + b.thumbPrefix + '$2') } if (b.preloadImages) { (function(a) { var g = new Image(), e = arguments.callee; g.src = i(c(h[a]).attr(b.srcAttr)); g.onload = function() { h[a + 1] && e(a + 1) } })(0) } h.mousemove(function(a) { TranslateCoordinates(d, a, b) }).hover(function() { var a = this; d.addClass(b.containerLoadingClass).show(); f.load(function() { d.removeClass(b.containerLoadingClass); f.show(); b.onLoad.call(f[0], a) }).attr('src', i(c(a).attr(b.srcAttr))); b.onShow.call(d[0], a) }, function() { d.hide(); f.unbind('load').attr('src', '').hide(); b.onHide.call(d[0], this) }); return this } })(jQuery);


function TranslateCoordinates(d, a, b) {

    var WIDTH = 300;
    var HEIGHT = 556;
    
    var windowHeight = $(window).height();
    var windowWidth = $(window).width();
    var bodyWidth = $("body").width();

    var mouseY = a.pageY - $(window).scrollTop();
    var mouseX = a.pageX - $(window).scrollLeft();


    var adjustedY = windowHeight - HEIGHT - 15 + $(window).scrollTop();
    var adjustedX = windowWidth - WIDTH - 15 + $(window).scrollLeft();

    //if (a.pageX + WIDTH > bodyWidth)
     //   adjustedX = a.pageX - WIDTH - 15;

    var top = Math.min(a.pageY, adjustedY);
    var left = Math.min(a.pageX , adjustedX);

    if (left < a.pageX)
        left = a.pageX - 30 - WIDTH - b.distanceFromCursor.left;

 
    //windowHeight + $(window).scrollTop() - 10 - HEIGHT;
    
    
    d.css({ top: top + b.distanceFromCursor.top  + 'px', left: left + b.distanceFromCursor.left + 'px' })

}


/* Dialog */







// MODAL CONFIRM POP UP
function ShowDialog(html) {
    CloseDialog();
    var html = "<div id=\"TempModalPopUp\" style=\"display:none;\">" + html + "</div>";
    var modal = $("body").append(html);

    var dialog = $("#TempModalPopUp").dialog({
        resizable: false,
        open: function(event, ui) { $(".ui-dialog-titlebar").hide(); } ,
        modal: true
    });
    //alert(dialog.find(".ui-dialog-titlebar").length);

    return dialog;
}

var m_magazine = null;
function ShowDialogFullScreen(html) {

    CloseDialog();
    
    
    var html = "<div id=\"TempModalPopUp\" class=\"full-screen\" style=\"display:none;\">" + html + "</div>";
    var modal = $("body").append(html);

    m_magazine = $("#TempModalPopUp").dialog({
        resizable: false,
        width: ($(window).width() / 100) * 90,
        height: ($(window).height() / 100) * 90,
        modal: true,
        draggable:false
    });

    $(window).resize(function() {
        if (m_magazine != null) {
            m_magazine.dialog("option", "position", "center");
            m_magazine.dialog("option", "height", ($(window).height() / 100) * 90);
            m_magazine.dialog("option", "width", ($(window).width() / 100) * 90);
        }
    });
}




function CloseDialog() {
    $("#TempModalPopUp").remove();
}


