﻿// JScript File

function getX(el)
{
	var ol=0;
	while (el != null)
	{
	    ol += el.offsetLeft;
	    el=el.offsetParent;
    }
	return ol;
}

function getY(el)
{
	var ot=0;
	while(el!= null)
	{
	    ot += el.offsetTop;
	    el=el.offsetParent;
    }
	return ot;
} /* */

function showel(el)
{
    var f = document.getElementById(el);
    if (f!=null)
    {
        f.style.display='';
    }
}

function hidel(el)
{
    var f = document.getElementById(el);
    if (f!=null)
    {
        f.style.display='none';
    }
}

function dropbelow(button, drop) {
    var pos = button.position();
    var height = button.outerHeight();
    //show the menu directly over the placeholder
    drop.css({ "left": (pos.left) + "px", "top": (pos.top + height) + "px", "position": "absolute" });
    drop.slideDown(150);
}
function dropbelowleft(button, drop) {
    var pos = button.position();
    var height = button.outerHeight();
    var width = drop.outerWidth();
    var btnwidth = button.outerWidth();
    //show the menu directly over the placeholder
    drop.css({ "left": (pos.left - width + btnwidth) + "px", "top": (pos.top + height) + "px", "position": "absolute" });
    drop.slideDown(150);
}

function dropleft(button, drop) {
    var pos = button.offset();
    var width = drop.outerWidth();
    //show the menu directly over the placeholder
    drop.css({ "left": (pos.left - width) + "px", "top": pos.top + "px", "position": "absolute" });
    drop.slideDown(150);
}

function dropright(button, drop) {
    var pos = button.offset();
    var width = button.outerWidth();
    //show the menu directly over the placeholder
    drop.css({ "left": (pos.left + width) + "px", "top": pos.top + "px", "position": "absolute" });
    drop.slideDown(150);
}

function dropdown(parent, menuid) {
    var f = document.getElementById(menuid);
    if (f.style.display == 'none') {
        f.style.display = '';
        f.style.left = (getX(parent) - getX(f) + parseInt(f.style.left)) + 'px';
        f.style.top = (getY(parent) + parent.offsetHeight - getY(f) + parseInt(f.style.top)) + 'px';
    }
}

function showright(parent, menuid) {
    var f = document.getElementById(menuid);
    if (f.style.display == 'none') {
        f.style.display = '';
        f.style.left = (getX(parent) + parent.offsetWidth - getX(f) + parseInt(f.style.left)) + 'px';
        f.style.top = (getY(parent) - getY(f) + parseInt(f.style.top)) + 'px';
    }
}

jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.keepCenter = function () {
    $(window).scroll(function () { this.center(); });
    this.center();
    return this;
}

function EsiteAjaxLoadAndShow(id, below, url) {
    var n = $("#" + id);
    n.load(url, function () {
        dropbelow($("#" + below),n);
    });    
}
