/*
these functions allow us to set the homepage height taller than the rest of the site.
First, we call setHomePageHeight, which gets the pageId from the URL.
If no pageId, then we check the page name.  If the page name is empty, we can alter the height of the divs.
This worked great before the 4.0 upgrade, but now JQuery is not allowed, so we had to use
old-school javascript and do it the hard way.
Note: Make sure this is called near the bottom of the page.
*/

/*
setHomePageHeight
Args: None.
Main function.
*/
function setHomePageHeight() {
    //var homePageHeaderHeight = 260;
    var pageID = getParameterByName('pageId');
    if (pageID == '') {
        var pg = GetPageName();
        //alert('page=' + pg);
        if (pg == '') {
            // on home page! show entire image.
            var attribName = "style";
            var newValue = "height:260px;";
//            appendAttrib("idHeaderContainer",     attribName, newValue);
            setStyle("idHeaderContainer");
            setStyle("idHeaderContentHolder");
            setStyle("header_headerContent");
            setStyle("idHeaderContent");
            setStyle("idHeaderHeightContainer");
            
            //$("#idHeaderContainer .inner, .header_headerContent, .headerContentHolder,  #idHeaderContent").height(homePageHeaderHeight);
        }
    }
}

/*
setStyle
Args: element ID.
Hard-codes the height.  This will set the height for us.
*/
function setStyle(elemId) {
    var x = document.getElementById(elemId);
    if (x == null)
        return;
    x.style.height = "260px";
}

/*
appendAttrib
Args: element ID.
Not used, but early attempt to set height by class. May still work, but I wasn't sure if classes would inherit
from ID or vice versa.  Styles will override any id or classes, for sure.
*/
function appendAttrib(elemId, name, val) {
    var x = document.getElementById(elemId);
    if (x == null)
        return;

    var existVal = x.getAttribute(name);
    var sep = '';
    if (existVal != null) sep = ' ';
    if (existVal == null) existVal = '';
    
    x.setAttribute(name, val);
}

/* get the filename of the page. */
function GetPageName() {
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if (sPage.indexOf('.com') > 0 || sPage.indexOf('.org') > 0 )
		sPage = '';
	return sPage;	
}

/* get a value from the querystring */
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

// call the main function.
setHomePageHeight();
