﻿function revealModal(divID)
{

//    window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop;
//    document.getElementById(divID).style.left = document.body.scrollLeft; 
//     };
    document.getElementById(divID).style.display = "block";
    //document.getElementById(divID).style.top = document.body.scrollTop;

}

// $(window).scroll(function () {
//        $('#modalPage').center();
//        	});

function hideModal(divID)
{
    $(divID).fadeOut();
    document.getElementById(divID).style.display = "none";
}

 function getWindowHeight() 
     {
     
        var windowHeight = 0;
        if (typeof(window.innerHeight) == 'number')
        {
            windowHeight = window.innerHeight;
        }
        else 
        {
            if (document.documentElement && document.documentElement.clientHeight) 
            {
                windowHeight = document.documentElement.clientHeight;
            }
            else 
            {
                 if (document.body && document.body.clientHeight) 
                 {
                       windowHeight = document.body.clientHeight;
                 }
            }
        }
        return windowHeight;
    }
  function setContent() 
  {
        //if (document.getElementById) 
        {
            var windowHeight = getWindowHeight();
            var t= 0;
            if (document.documentElement && !document.documentElement.scrollTop)
            {
                
                // IE6 +4.01 but no scrolling going on
            }
            else if (document.documentElement && document.documentElement.scrollTop)
            {
                t = document.documentElement.scrollTop;
                // IE6 +4.01 and user has scrolled
            }
            else if (document.body && document.body.scrollTop)
            {
                t = document.body.scrollTop
                // IE5 or DTD 3.2 
            }
            
            if (windowHeight > 0) 
            {
                var contentElement = document.getElementById('mainContainer');
                var contentHeight = contentElement.offsetHeight;
                if (windowHeight - contentHeight > 0) 
                {
                    contentElement.style.position = 'absolute';
                    contentElement.style.top = (windowHeight / 2) + t + 'px';
                }
                else 
                {
                    contentElement.style.position = 'absolute';
                }
            }
        }
  }
 

     jQuery.fn.center = function () {
    this.css("position","absolute");
   var height = this.height() > 1500 ? (this.height()-1500) : this.height();
   var sTop=($(window).height() - height) / 2 + $(window).scrollTop();
	if(sTop<0)
	sTop=0;
 this.css("top", sTop + "px");
 /*alert($(window).height());
    alert(height);
    alert($(window).scrollTop());*/
     
    //alert(($(window).height()) / 2+$(window).scrollTop());
    //if((($(window).height() - this.height() ) / 2+$(window).scrollTop())>0)
    //    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
//        this.css("top", ( $(window).height()) / 2+$(window).scrollTop() + "px");
    return this;
}

