﻿function popupWindow(url, width, height) 
{
    var top, left;

    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
        top = window.screenTop;
        left = window.screenLeft;
             
//        alert("top = " + top);                   
//        alert("left = " + left);                   
//        alert("document.documentElement.offsetHeight = " + document.documentElement.offsetHeight);                   
//        alert("document.documentElement.offsetWidth = " + document.documentElement.offsetWidth);                   
        if (document.documentElement.offsetHeight > height)
        {
            top = top + (document.documentElement.offsetHeight - height) / 2;
        }
                
        if (document.documentElement.offsetWidth > width)
        {
            left = left + (document.documentElement.offsetWidth - width) / 2;
        }        
    }
    else
    {        
        top = window.screenY;
        left = window.screenX; 
        
        if (window.innerHeight > height)
        {
            top = top + (window.innerHeight - height) / 2;
        }
                
        if (window.innerWidth > width)
        {
            left = left + (window.innerWidth - width) / 2;
        }        
    }
            
    // adds for margin
    width = width + 10;
    height = height + 10;
    
    window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + width + ',height=' + height + ',screenX=' + left + ',screenY=' + top + ',top=' + top + ',left='+ left + '');
    
    return false;
}
