﻿function MiddleAlign(DivClass)
{
    var Div;
    var DivHeight;
    var BodyHeight;
    var OffsetHeight;
    
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined')
    {
        BodyHeight = window.innerHeight;
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {
        BodyHeight = document.documentElement.clientHeight;
    }

    // older versions of IE
    else
    {
        BodyHeight = document.getElementsByTagName('body')[0].clientHeight;
    }
    
    Div = getElementsByClass(DivClass);
    for (var i = 0, j = Div.length; i < j; i++)
    {
        DivHeight = Div[i].clientHeight;
        OffsetHeight = (BodyHeight - DivHeight) / 2;
        if (OffsetHeight > 0)
        {
            Div[i].style.position = 'relative';
            Div[i].style.top = OffsetHeight + 'px';
        }
    }
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}