﻿function CenterDiv(divTarget) 
{
    //Written by Ram in October 2009.
    var divMain = document.getElementById(divTarget);

    //var browser = {"ie": Boolean(document.body.currentStyle), "ie5": (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 5.0") != -1), "ie6": (navigator.appVersion.indexOf("MSIE 6.0") != -1)};
    //UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
    var changepositionflag = false;
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {   //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 8)
            changepositionflag = false;
        else if (ieversion >= 7)
            changepositionflag = false;
        else if (ieversion >= 6)
            changepositionflag = true;
        else if (ieversion >= 5)
            changepositionflag = true;
    }
    else {
        changepositionflag = true;
    }



    //Center the window using the below logic
    //var vDivWidth = divQuickSnapShotMain.offsetWidth;
    //var vDivHeight = divQuickSnapShotMain.offsetHeight;
    //document.getElementById("elem").offsetWidth
    var vDivWidth = divMain.offsetWidth;
    var vDivHeight = divMain.offsetHeight;
    
    //alert(vDivWidth);
    //alert(vDivHeight);

    //var vWindowCurrentWidth = document.documentElement.clientWidth;
    //var vWindowCurrentHeight = document.documentElement.clientHeight;

    var vWindowCurrentWidth = 0;
    var vWindowCurrentHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        vWindowCurrentWidth = window.innerWidth;
        vWindowCurrentHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        vWindowCurrentWidth = document.documentElement.clientWidth;
        vWindowCurrentHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        vWindowCurrentWidth = document.body.clientWidth;
        vWindowCurrentHeight = document.body.clientHeight;
    }

    //alert(vWindowCurrentWidth);
    //alert(vWindowCurrentHeight);
    
    if (vDivHeight >= (vWindowCurrentHeight - 40)) {
        
        vDivHeight = vWindowCurrentHeight - 40;
        divMain.style.height = (vDivHeight - 40) + "px";
        
    }

    var vLeft = (vWindowCurrentWidth - vDivWidth) / 2;
    var vTop = (vWindowCurrentHeight - vDivHeight) / 2;

    //alert(vLeft);
    //alert(vTop);
    
    divMain.style.left = vLeft + "px";
    divMain.style.top = vTop + "px";
    
    /*
    alert("window.screen.height : " + window.screen.height);
    alert("window.screen.availHeight : " + window.screen.availHeight);
    alert("document.body.clientHeight : " + document.body.clientHeight);
    alert("document.documentElement.clientHeight : " + document.documentElement.clientHeight);

            alert("window.screen.width : " + window.screen.width);
    alert("window.screen.availWidth : " + window.screen.availWidth);
    alert("document.body.clientWidth : " + document.body.clientWidth);
    alert("document.documentElement.clientWidth : " + document.documentElement.clientWidth);

            alert("divQuickSnapShotSub O H : " + divQuickSnapShotSub.offsetHeight);
    alert("divQuickSnapShotSub O W : " + divQuickSnapShotSub.offsetWidth);

            alert("divQuickSnapShotMain O H : " + divQuickSnapShotMain.offsetHeight);
    alert("divQuickSnapShotMain O W : " + divQuickSnapShotMain.offsetWidth);
    */
}
