
function $(id){
   return document.getElementById(id);
}


function findPos(obj) {
            var left=0, top = 0;
             while (obj) {
                left += obj.offsetLeft;
                 top += obj.offsetTop;
                 obj = obj.offsetParent;
             }
           if (navigator.userAgent.indexOf("Mac") != -1 &&  typeof document.body.leftMargin != "undefined") {
                  left += document.body.leftMargin;
                  top += document.body.topMargin;
            }
			  return new Array(left,top);
 }


function isIE(){
   return navigator.userAgent.toLowerCase().indexOf("msie")>-1;
}

function getIEVersion(str){
    var version = 0;
    var values = str.match(/(msie\s[\d]+)/);

     if(values && values.length>0)
         version = parseInt(values[0].substring(values[0].search(/[\d]+/)));
       
    return version;
}

function getCenter(w,h){
         position = {left:0,top:0}; 

            if (window.screenX) {
              position.left = window.screenX + ((window.outerWidth - w) / 2);
              position.top = window.screenY + ((window.outerHeight - h) / 2);
            } else if (window.screenLeft) {    
              CSSCompat = (document.compatMode && document.compatMode != "BackCompat");
              _w = (CSSCompat) ? document.body.parentElement.clientWidth : document.body.clientWidth;
              _h = (CSSCompat) ? document.body.parentElement.clientHeight :  document.body.clientHeight;
              _h -= 80;
              position.left = parseInt(window.screenLeft+ ((_w - w) / 2));
              position.top = parseInt(window.screenTop + ((_h - h) / 2));
            } else {  
            position.left = (screen.width - w) / 2;
            position.top = (screen.height - h) / 2;
        }
    return position;
}


function getCenterPoint(elemID) {
    var obj = $(elemID);
	var position = {top:0,left:0};
   
    var scrollX = 0, scrollY = 0;
    if (document.body && typeof document.body.scrollTop != "undefined") {
        scrollX += document.body.scrollLeft;
        scrollY += document.body.scrollTop;
        if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
            scrollX += document.body.parentNode.scrollLeft;
            scrollY += document.body.parentNode.scrollTop;
        }
    } else if (typeof window.pageXOffset != "undefined") {
        scrollX += window.pageXOffset;
        scrollY += window.pageYOffset;
    }
    position.left = Math.round((getInsideWindowWidth( )/2) - (getObjectWidth(obj)/2)) + scrollX;
    position.top = Math.round((getInsideWindowHeight( )/2) - (getObjectHeight(obj)/2)) + scrollY;
    return position;
}

function getInsideWindowWidth( ) {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}

function getInsideWindowHeight( ) {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}



function getObjectWidth(obj)  {
    var elem = obj;
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}


function getObjectHeight(obj)  {
    var elem = obj;
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}




