// JavaScript Document
//
// This is used to force all div column heights to the match the highest column
//

function returnObjById( id ) {
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

/*
To get all a elements in the document with a "info-links" class.
    getElementsByClassName(document, "a", "info-links");
To get all div elements within the element named "container", with a "col" class.
    getElementsByClassName(document.getElementById("container"), "div", "col"); 
To get all elements within in the document with a "click-me" class.
    getElementsByClassName(document, "*", "click-me"); 
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function getheight( d ) {
    if (!d) {
        return 0;
    }
    if (d.offsetHeight){
        returnVar=d.offsetHeight;
    } else if(d.style.pixelHeight){
        returnVar=d.style.pixelHeight;
    }
    return returnVar;
}

function getStyle(oEl,styleProp)
{
    var x = oEl;
    if (x.currentStyle)
        var y = x.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    return y;
}

function detectBrowser() {
    var browser = navigator.appName;
    var version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    //alert (version);
    if (browser=="Microsoft Internet Explorer") {
        if (version<7) {
            return 2;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

function matchHeight() {
    var divs,contDivs,leftHeight,contHeight,d;
    
    var content_body = getElementsByClassName(document, "div", "content_body"); 
    content_body = content_body[0];
    if (!content_body) {
        return;
    }
    var module_body_news = getElementsByClassName(document, "div", "module_body_news");
    var module_body_event = getElementsByClassName(document, "div", "module_body_event");
    var module_body_link = getElementsByClassName(document, "div", "module_body_link");
    
    module_body_news = module_body_news.length>0?module_body_news[0]:null;
    module_body_event = module_body_event.length>0?module_body_event[0]:null;
    module_body_link = module_body_link.length>0?module_body_link[0]:null;

    // determine height for <div> element
    leftHeight = module_body_news?getheight(module_body_news) +22:0;
    leftHeight += module_body_event?getheight(module_body_event) +22:0;
    leftHeight += module_body_link?getheight(module_body_link) +22:0;
    
/*  alert(getheight(content_body));
    alert(getheight(module_body_news));
    alert(getheight(module_body_event));
    alert(getheight(module_body_link));
*/

    contHeight = getheight(content_body) + 24;
    if (contHeight > leftHeight) {
        var diff = contHeight - leftHeight;
        if (module_body_link) {
            var newHeight = getheight(module_body_link) + diff;
            var div = module_body_link;
        } else if (module_body_event) {
            var newHeight = getheight(module_body_event) + diff;
            var div = module_body_event;
        } else if (module_body_news) {
            var newHeight = getheight(module_body_news) + diff;
            var div = module_body_news;
        }
    } else if (leftHeight > contHeight) {
        var diff = leftHeight - contHeight;
        var newHeight = getheight(content_body) + diff;
        var div = content_body;
    } else {
        return;
    }
    if (detectBrowser()==2) {
        // IE 6 or less (dont need to subtract padding & margins from new height)
        div.style.height = newHeight+'px'
    } else {
        if (detectBrowser()>0) {
            // IE7+
            var padding = parseInt((getStyle(div, 'paddingTop').replace('px', ''))) + parseInt((getStyle(div, 'paddingBottom').replace('px', '')));
            var margin = parseInt((getStyle(div, 'marginTop').replace('px', ''))) + parseInt((getStyle(div, 'marginBottom').replace('px', '')));
        } else {
            // Moz
            var padding = parseInt((getStyle(div, 'padding-top').replace('px', ''))) + parseInt((getStyle(div, 'padding-bottom').replace('px', '')));
            var margin = parseInt((getStyle(div, 'margin-top').replace('px', ''))) + parseInt((getStyle(div, 'margin-bottom').replace('px', '')));      
        }
        newHeight = newHeight - (padding + margin);
        div.style.height = newHeight+'px';
    }
}

var onloads = new Array();
function bodyOnLoad() {
    for ( var i = 0 ; i < onloads.length ; i++ ) {
        onloads[i]();
    }
    matchHeight();
}

//onloads.push( accord ); function accord() { new Rico.Accordion( 'accordionExample', {panelHeight:227} ); }

// execute function when page loads
window.onload=function(){
    bodyOnLoad();
}

//
function validateDomain(email) {
    emailArr = new Array('xazz.com.au');
    
    for (var i = 0; i<emailArr.length; i++) {
     if (email.search(emailArr[i])>-1) {
        return true;
     }
    }
    return false;
}
