﻿
var appPath;

function resolveUrl(url) {
    return url.replace("~/", appPath);
}

function resolveSectionUrl(actionPath) {
    return resolveUrl("~" + actionPath + ".bzls");
}

$.fn.initAjaxForm = function(destinationSelector)
{
    var mc = $(destinationSelector);
   
    var options = {
        target: mc
    };

    $(this).ajaxForm(options);
}

jQuery.fn.center = function () {
    this.css("position","fixed");
//    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
//    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    this.css("top", ( $(window).height() - this.height() ) / 2 + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2 + "px");

    return this;
}

$.showDialog = function (content) {
    $("body").css("overflow", "hidden");
    
    $.blockUI( { message : $(content),
        css : {
            left  : '0',
            top : '0',
            height : '100%',
            width : '100%'
            
        }, 
        overlayCSS:  { 
            backgroundColor: '#eeeeee', 
            opacity:         0.5 
        },
        centerX: false,
        centerY: false,        
        fadeIn:  0,  
        fadeOut:  0 
     } );

    return this;
}

$.hideDialog = function() {
    $.unblockUI( { onUnblock : function() { 
        $("body").css("overflow", "auto");    
    },
    fadeOut:  200
    } );
    return this;
}

$.fn.showDialog = function (content) {
    
    this.block( { message : $(content),
        css : {
            left  : '0',
            top : '0',
            height : '100%',
            width : '100%'
            
        }, 
        overlayCSS:  { 
            backgroundColor: '#eeeeee', 
            opacity:         0.5 
        },
        centerX: true,
        centerY: true,        
        fadeIn:  0,  
        fadeOut:  0 
     } );

    return this;
}

$.fn.hideDialog = function() {
    this.unblock( { onUnblock : function() { 
    },
    fadeOut:  200
    } );
    return this;
}

$.fn.showWaitingDialog = function ()
{
    var wd = $('<div class="waiting"></div>');    

    this.block( { message : wd,
        css : {
            left  : '0',
            top : '0',
            height : '100%',
            width : '100%'
            
        }, 
        overlayCSS:  { 
            backgroundColor: '#eeeeee', 
            opacity:         0.5 
        },
        centerX: false,
        centerY: false,        
        fadeIn:  0,  
        fadeOut:  0 
     } );

    return this;
}

function scrollWithMouse(event,Obj){
    var MouseY = event.clientY;
    var Ythis=$(Obj).offset().top;
    MouseY-=Ythis;
    var scrollHobj=$(Obj).get(0).scrollHeight;
    var Hobj=$(Obj).innerHeight();
    var DifH=scrollHobj-Hobj;
    var MultiDif=Hobj/MouseY; 
    var ScrollMe=parseInt(DifH/MultiDif);
    $(Obj).scrollTop(ScrollMe);
}

$.fn.loadAndAppend = function(url, hideFirstChild, callback)
{
    var $tmp = $(this);
    
    $.get(url,function(data){
        var d = $(data);
        if ( hideFirstChild )
        {
            d.css("display", "none");
        }
        $tmp.append(d)
        if ( callback != null )
        {
            callback(d);
        }
    },'html');     
};

function getJSONValue(json)
{
    return eval( "(" + json + ")" );
}


