
if(typeof BIA=="undefined"){var BIA={};}

BIA.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; ++i) {
        d=a[i].split(".");
        o=BIA;

        // BIA is implied, so it is ignored if it is included
        for (j=(d[0] == "BIA") ? 1 : 0; j<d.length; ++j) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
};

BIA.namespace("keyNav");
BIA.namespace("forms");
BIA.namespace("util");
BIA.namespace("autoScroll");
BIA.namespace("dom");
BIA.namespace("b2");
BIA.namespace("store");

//
//
//
// AjaxForm
//
//

BIA.forms.AjaxForm = function( formName ) {

    this.form = document.getElementById( formName );
    if( !this.form )
        return false;

    this.block = YAHOO.util.Dom.getAncestorByClassName( this.form, "block" );
    if( !this.block )
        return false;

    this.windowID = this.block.id.substring(this.block.id.lastIndexOf("-")+1);

    for(var n = 0; n < this.form.elements.length; n++ ) {
        if( this.form.elements[n].name == "goto" || this.form.elements[n].name == "gotoSuccess" || this.form.elements[n].name == "gotoError" ) {
            this.form.elements[n].value="/ajax"+document.location.pathname+"?windowID="+this.windowID;
        }
    }

    YAHOO.util.Event.addListener( this.form, "submit", this.submit, this, true );
}

BIA.forms.AjaxForm.prototype.submit = function( e ) {

    YAHOO.util.Event.preventDefault(e);
    var method = this.form.getAttribute('method');
    var action = this.form.getAttribute('action');
    var callback = {
            success:this.handleSuccess,
            failure:this.handleFailure,
            scope: this
    };

    YAHOO.util.Connect.setForm(this.form);
    YAHOO.util.Connect.asyncRequest(method, action, callback);
}

BIA.forms.AjaxForm.prototype.handleSuccess = function( o ) {

    if( !o.responseXML ) {
        if(o.responseText && o.responseText.toLowerCase() != "ok")
            BIA.util.setNotification( o.responseText );
        YAHOO.util.Dom.removeClass(this.form, "changed");
        return true;
    }

    var notificationXML = o.responseXML.getElementsByTagName("notification");
    if( notificationXML.length == 1 )
        o.notification = BIA.util.getNodeText( notificationXML[0] );

    var contentXML = o.responseXML.getElementsByTagName("content");
    if( contentXML.length == 1 )
        o.content = BIA.util.getNodeText( contentXML[0] );

    if( o.notification )
        BIA.util.setNotification( o.notification );

    if( o.content ) {
        this.block.innerHTML = o.content;
        var scripts = this.block.getElementsByTagName("script");

        for( var n =0; n < scripts.length; n++ ) {
            if(scripts[n].type == "text/javascript") {
                if( scripts[n].text )
                    eval( scripts[n].text );
                else if( scripts[n].childNodes[0].nodeValue )
                    eval( scripts[n].childNodes[0].nodeValue );
            }
        }
    }
}

BIA.forms.AjaxForm.prototype.handleFailure = function( o ) {
    throw new Error("Failure loading link content");
    //console.log( o );
}

//
//
// AjaxLink
//
//

BIA.forms.AjaxLink = function( obj, target ) {

    this.href = "";
    this.block = "";
    this.target = target;

    if( target )
        this.block = document.getElementById( target );

    if( typeof(obj) == "string" ) {

        this.href = "/ajax" + obj;

    } else if( obj.tagName.toLowerCase() == "a" ) {

        this.href = "/ajax" + ((obj.pathname.indexOf("/") != 0)?"/":"") + obj.pathname;
        if(obj.search)
            this.href += obj.search;

        // If no target was given, I assume the link is in the target
        if( !this.block )
            this.block = YAHOO.util.Dom.getAncestorByClassName( obj, "block" );
    }

    // If still no target, try to find the main page block
    if( !this.block )
        this.block = document.getElementById( "block-main" );

    // Ok... now we give up...
    if( !this.block )
        throw new Error("No target for AjaxLink");

}

BIA.forms.AjaxLink.prototype = new BIA.forms.AjaxForm();

BIA.forms.AjaxLink.prototype.click = function( e ) {

    if(e)
        YAHOO.util.Event.preventDefault(e);

    var callback = {
            success:this.handleSuccess,
            failure:this.handleFailure,
            scope: this
    };

    var time = new Date().getTime();
    var href = this.href+(this.href.indexOf("?") != -1?"&":"?")+"nocache="+time;
    
    var pageLoader = document.getElementById(this.target + "-pageLoader");
    
    if (this.block.innerHTML == "")
        this.block.innerHTML = '<center><img src="/gfx/ajax-loader.gif" alt="loading" /></center>';
    else if(pageLoader) {
        pageLoader.innerHTML = '<img src="/gfx/ajax-loader-small.gif" alt="loading" />';
    }
    
    YAHOO.util.Connect.asyncRequest( "get", href, callback );
}

BIA.forms.ajaxLinkClick = function( obj, target ) {

    var link = new BIA.forms.AjaxLink( obj, target );
    link.click();
    return false;
}

BIA.forms.ajaxHomeTabClick = function( obj, target, view ) {

    // already active?
    if (YAHOO.util.Dom.hasClass(target + '-' + view, 'active'))
        return false;

    var children = YAHOO.util.Dom.getChildren(target + '-tools');
    for (var j = 0; j < children.length; j++) {
        YAHOO.util.Dom.removeClass(children[j], 'active');
    }

    // add active class to clicked tab
    YAHOO.util.Dom.addClass(target + '-' + view, 'active');

    // set loader
    if (target) {
        this.block = document.getElementById(target);
        this.block.innerHTML = '<center><img src="/gfx/ajax-loader.gif" alt="loading" /></center>';
    }

    var link = new BIA.forms.AjaxLink(obj, target);
    link.click();
    return false;
}


//
//
// CheckableField
//
//

BIA.forms.CheckableField = function( formName, fieldName, checkParams )
{
    if( formName && fieldName) {
        this.formName = formName;
        this.fieldName = fieldName;
        this.checkParams = checkParams;

        this.fieldId = formName + BIA.util.capitalize(this.fieldName);
        this.field = document.getElementById(this.fieldId);

        this.blockId = this.fieldId + "Block";
        this.block = document.getElementById(this.blockId);

        this.statusText = YAHOO.util.Dom.getElementsByClassName("statusText", "p", this.block)[0];

        YAHOO.util.Event.addListener(this.field, "blur", this.check, this, true);
        YAHOO.util.Event.addListener(this.field, "focus", this.clearStatus, this, true);
    }
}


BIA.forms.CheckableField.prototype = {
    check: function() {

        if(this.checkParams && this.checkParams.checkAjaxAction != undefined) {
            this.checkAjax();
        } else if (this.checkParams && this.checkParams.action != undefined) {
            this.checkValue(this.checkParams.action);
        }
    },

    getValue: function() {
        return this.field.value;
    },

    setValue: function( value ) {
        this.field.value = value;
    },

    checkAjax: function() {
        this.setStatus("loading");
        url = "/actions/"+this.checkParams.checkAjaxAction + "?" + encodeURIComponent(this.fieldName) + "="+encodeURIComponent(this.field.value);
        if(this.checkParams.userID)
            url += "&userID="+this.checkParams.userID;
        callback = {
            success:this.checkAjaxSuccess,
            failure:this.checkAjaxFailure,
            scope: this
        };
        YAHOO.util.Connect.asyncRequest('GET', url, callback );
    },

    checkAjaxSuccess: function( o ) {
        if(o.responseText && o.responseText != "ok")
            this.setStatus("error", o.responseText);
        else
            this.setStatus("ok", this.oldStatus);
    },
    checkAjaxFailure: function( o ) {
        this.setStatus("error", "Error checking value");
    },
    
    checkValue: function(type) {
        
        switch (type) {
            case "password":
                if (this.field.value.length >= 6)
                    this.setStatus("ok", this.oldStatus);
                else
                    this.setStatus("error");
            break;
            
            case "passwordConfirm":
                var normalPass = document.getElementById(this.fieldId.substr(0, this.fieldId.length - 7));
                if (normalPass.value == this.field.value && this.field.value.length >= 1) {
                    this.setStatus("ok", this.oldStatus);
                } else {                    
                    this.setStatus("error");
                }
            break;
        }
    },

    clearStatus: function() {
        this.setStatus("");
    },

    setStatus: function( status, text ) {

        var statusArray = ['loading', 'ok', 'error'];

        for( var i = 0; i < statusArray.length ; i++ ) {
            if( status == statusArray[i] )
                YAHOO.util.Dom.addClass( this.block, statusArray[i] );
            else
                YAHOO.util.Dom.removeClass( this.block, statusArray[i] );
        }

        if( this.statusText && text != undefined ) {
            if( !this.firstCheck ) {
                this.oldStatus = this.statusText.innerHTML;
                this.firstCheck = true;
            }
            this.statusText.innerHTML = text;
        }
        
        YAHOO.util.Dom.setStyle( this.statusText, 'display', 'block' );        
    }
}

BIA.forms.CheckablePasswordConfirmField = function( formName, fieldName, checkParams )
{
    if( formName && fieldName) {
        this.formName = formName;
        this.fieldName = fieldName;
        this.checkParams = checkParams;

        this.fieldId = formName + BIA.util.capitalize(this.fieldName);
        this.field = document.getElementById(this.fieldId);

        this.blockId = this.fieldId + "Block";
        this.block = document.getElementById(this.blockId);

        this.statusText = YAHOO.util.Dom.getElementsByClassName("statusText", "p", this.block)[0];

        YAHOO.util.Event.addListener(this.field, "blur", this.check, this, true);
        YAHOO.util.Event.addListener(this.field, "focus", this.clearStatus, this, true);
    }
}

BIA.forms.CheckablePasswordConfirmField.prototype = new BIA.forms.CheckableField();
BIA.forms.CheckablePasswordConfirmField.prototype.checkValue = function(type) {
    if(type == "passwordConfirm") {
        var normalPass = document.getElementById(this.fieldId.substr(0, this.fieldId.length - 7));
        if (normalPass.value == this.field.value && this.field.value.length >= 1) {
            this.setStatus("ok", this.oldStatus);
        } else {                    
            this.setStatus("error");
            url = "/actions/user.register.check.passwordConfirm?"+(this.field.value.length >= 1?"confirmPassDiffers=1":"required=1");
            callback = {
                success:this.checkAjaxSuccess,
                failure:this.checkAjaxFailure,
                scope: this
            };
            YAHOO.util.Connect.asyncRequest('GET', url, callback );
        }
    }
};
BIA.forms.CheckablePasswordConfirmField.prototype.checkAjaxSuccess = function( o ) {
    if(o.responseText)
        this.setStatus("error", o.responseText);
};
    


//
//
// CheckableDateField
//
//

BIA.forms.CheckableDateField = function( formName, fieldName, checkParams )
{
    this.formName = formName;
    this.fieldName = fieldName;
    this.checkParams = checkParams;
    this.fieldId = formName + BIA.util.capitalize(fieldName);

    this.blockId = this.fieldId + "Block";
    this.block = document.getElementById(this.blockId);

    this.statusText = YAHOO.util.Dom.getElementsByClassName("statusText", "p", this.block)[0];

    YAHOO.util.Event.addListener(this.fieldId+"Day", "blur", this.check, this, true );
    YAHOO.util.Event.addListener(this.fieldId+"Month", "blur", this.check, this, true );
    YAHOO.util.Event.addListener(this.fieldId+"Year", "blur", this.check, this, true );
    YAHOO.util.Event.addListener(this.fieldId+"Day", "focus", this.clearStatus, this, true );
    YAHOO.util.Event.addListener(this.fieldId+"Month", "focus", this.clearStatus, this, true );
    YAHOO.util.Event.addListener(this.fieldId+"Year", "focus", this.clearStatus, this, true );

}

BIA.forms.CheckableDateField.prototype = new BIA.forms.CheckableField()

BIA.forms.CheckableDateField.prototype.check = function() {

    dayField = document.getElementById(this.fieldId+"Day");
    monthField = document.getElementById(this.fieldId+"Month");
    yearField = document.getElementById(this.fieldId+"Year");

    day = dayField.value;
    month = monthField.options[monthField.selectedIndex].value;
    year = yearField.value;

    if(day && month && year) {
        if(this.checkParams.checkAjaxAction != undefined) {
            this.checkAjax( year, month, day );
        }
    }
    return true;
}

BIA.forms.CheckableDateField.prototype.checkAjax = function( year, month, day ) {

        this.setStatus("loading");
        url = "/actions/"+this.checkParams.checkAjaxAction + "?" +
                encodeURIComponent(this.fieldName + "Year") + "=" + encodeURIComponent( year ) + "&" +
                encodeURIComponent(this.fieldName + "Month") + "=" + encodeURIComponent( month ) + "&" +
                encodeURIComponent(this.fieldName + "Day") + "=" + encodeURIComponent( day )

        callback = {
            success:this.checkAjaxSuccess,
            failure:this.checkAjaxFailure,
            scope: this
        };

        YAHOO.util.Connect.asyncRequest('GET', url, callback );
}


//
//
// TabSet
//
//

BIA.forms.TabSet = function( id ) {

    this.id = id;
    var tabdiv = document.getElementById(this.id);
    if( !tabdiv )
        throw new Error('Invalid tab div');

    this.tabs = tabdiv.getElementsByTagName("a");
    for( var n = 0; n < this.tabs.length; n++) {
        YAHOO.util.Event.addListener(this.tabs[n], "click", this.tabSelect, this, true );
        var href = this.tabs[n].getAttribute( "href" );
        if( href.lastIndexOf("=") )
            href=href.substring( href.lastIndexOf("=")+1 );
        if( YAHOO.util.Dom.getStyle( href, "display" ) != "none" )
            YAHOO.util.Dom.addClass( this.tabs[n], "active" );
    }
    this.field = document.getElementById( id+"Field");
}

BIA.forms.TabSet.prototype.tabSelect = function( e ) {

    YAHOO.util.Event.preventDefault(e);
    var target = YAHOO.util.Event.getTarget(e);
    target.blur();

    for( var n = 0; n < this.tabs.length; n++) {
        var href = this.tabs[n].getAttribute( "href" );
        if( href.lastIndexOf("=") )
            href=href.substring( href.lastIndexOf("=")+1 );

        if( this.tabs[n] == target ) {
            YAHOO.util.Dom.addClass( this.tabs[n], "active" );
            BIA.util.showElement( href );
            if( this.field )
                this.field.value = href;
        } else {
            YAHOO.util.Dom.removeClass(this.tabs[n], "active");
            BIA.util.hideElement( href );
        }
    }

}



//
//
// Votebuttons
//
//

BIA.forms.voteButtons = function(name, plusButtonClass, minButtonClass, selectedValue, disabled ) {

    var noscript = document.getElementById( name );
    if( !noscript )
        return false;

    this.plus = document.createElement( "a" );
    this.plus.href="#";
    if( disabled )
        this.plus.className = plusButtonClass+"Disabled";
    else if( selectedValue > 0 )
        this.plus.className = plusButtonClass+"On";
    else
        this.plus.className = plusButtonClass;
    noscript.parentNode.appendChild(this.plus);

    this.min = document.createElement( "a" );
    this.min.href="#";
    if( disabled )
        this.min.className = minButtonClass+"Disabled";
    else if( selectedValue < 0 )
        this.min.className = minButtonClass+"On";
    else
        this.min.className = minButtonClass;
    noscript.parentNode.appendChild( this.min );

    this.hiddenField = document.createElement( "input" );
    this.hiddenField.type = "hidden";
    this.hiddenField.name = name;
    this.hiddenField.value = selectedValue;
    noscript.parentNode.appendChild( this.hiddenField );

    this.plusName = plusButtonClass;
    this.minName = minButtonClass;

//  YAHOO.util.Event.addListener( this.plus, "mousedown", this.handleClick, this, true );
//  YAHOO.util.Event.addListener( this.min, "mousedown", this.handleClick, this, true );
    YAHOO.util.Event.addListener( this.plus, "click", this.handleClick, this, true );
    YAHOO.util.Event.addListener( this.min, "click", this.handleClick, this, true );
    YAHOO.util.Event.addListener( this.plus, "keydown", this.handleClick, this, true );
    YAHOO.util.Event.addListener( this.min, "keydown", this.handleClick, this, true );
}

BIA.forms.voteButtons.prototype.handleClick = function( e ) {

    if( e.keyCode && e.keyCode != 32 )
        return true;

    YAHOO.util.Event.preventDefault(e);

    if(this.plus == YAHOO.util.Event.getTarget(e)) {
        if( this.plus.className != this.plusName+"Disabled" ) {
            if( this.plus.className == this.plusName+"On" ) {
                this.plus.className = this.plusName
                this.hiddenField.value = "0";
            } else {
                this.plus.className = this.plusName+"On";
                this.min.className = this.minName;
                this.hiddenField.value = "1";
            }
        }
    } else {
        if( this.min.className != this.minName+"Disabled" ) {

            if( this.min.className == this.minName+"On" ) {
                this.min.className = this.minName;
                this.hiddenField.value = "0";
            } else {
                this.min.className = this.minName+"On";
                this.plus.className = this.plusName;
                this.hiddenField.value = "-1";
            }
        }
    }
    var form = YAHOO.util.Dom.getAncestorByTagName(this.hiddenField, "form");
    YAHOO.util.Dom.addClass( form, "changed" );
}




//
//
// autoScroll
//
//
BIA.autoScroll.init = function() {

    try {
        hash = document.location.hash;
        if( hash.substring(1,7) == "scroll" ) {
            window.scrollTo(0, hash.substring(7));
        }
    } catch(e) {
    }
    return true;
}
YAHOO.util.Event.addListener( window, "load", BIA.autoScroll.init );


//
//
// SubMenu
//
//
BIA.b2.DDSubMenu = function(targetID) {

    this.targetElm = (targetID)?document.getElementById(targetID):false;
    if (!this.targetElm)
        return false;

    YAHOO.util.Event.addListener( window, "load", BIA.b2.DDSubMenu.init, this, true );
}

BIA.b2.DDSubMenu.init = function() {
    
    YAHOO.util.Event.addListener( this.targetElm, "mouseover", BIA.b2.DDSubMenu.mouseOverHandler, this, true );
    YAHOO.util.Event.addListener( this.targetElm, "mouseout", BIA.b2.DDSubMenu.mouseOutHandler, this, true );
}

BIA.b2.DDSubMenu.mouseOverHandler = function() {
    
    YAHOO.util.Dom.addClass( this.targetElm, "over" );
}

BIA.b2.DDSubMenu.mouseOutHandler = function() {
    
    YAHOO.util.Dom.removeClass( this.targetElm, "over" );
}

//
//
// TabItem
//
//
var tabs = {};
BIA.b2.TabItem = function(targetID, group) {

    this.targetElm  = document.getElementById(targetID);
    this.handlerElm = document.getElementById(targetID+"_tab");
        
    if (!this.targetElm)
        return false;

    this.group = group;    
    if(!tabs[this.group])
        tabs[this.group] = [];
    
    tabs[this.group].push(this);
    
    YAHOO.util.Event.addListener( window, "load", this.init, this, true );    
}

BIA.b2.TabItem.prototype.init = function() {
    
    if(this.handles) {
        for(var i = 0; i < this.handles.length; i++) {
            YAHOO.util.Event.addListener( this.handles[i], 'click', this.mouseClickHandler, this, true );
            YAHOO.util.Dom.setStyle( this.handles[i], 'cursor', 'pointer' );
        }
    }
    YAHOO.util.Event.addListener( this.handlerElm, "mouseup", this.mouseClickHandler, this, true );
}

BIA.b2.TabItem.prototype.mouseClickHandler = function(e) {
    
    YAHOO.util.Event.preventDefault(e);
    this.select();   
}

BIA.b2.TabItem.prototype.select = function() {

    for(var i = 0; i < tabs[this.group].length; i++) {
        BIA.util.hideElement(tabs[this.group][i].targetElm.id);
        YAHOO.util.Dom.removeClass( tabs[this.group][i].handlerElm, "active" );
    }    
    BIA.util.showElement(this.targetElm.id);
    YAHOO.util.Dom.addClass( this.handlerElm, "active" );
}

BIA.b2.TabItem.prototype.addHandle = function(handleID) {
    
    var handle = document.getElementById(handleID);
    if(handle) {
        
        if(!this.handles)
            this.handles = [];
            
        this.handles.push(handle);
    }
}

//
//
// KeyNav
//
//
BIA.keyNav.init = function( e ) {

    YAHOO.util.Event.addListener( document, "keyup", BIA.keyNav.keyPress );
}

BIA.keyNav.keyPress = function( e ) {

    var target = YAHOO.util.Event.getTarget( e );

    // Check if the keypress origionated from a form
    while( target = target.parentNode )
        if( target && target.tagName )
            if(target.tagName.toLowerCase() == "form" )
                return true;
    // Try to find an element in the page with id = keyPress<code>
    if( !e.altKey && !e.ctrlKey && !e.shiftKey ) {
        if( link = document.getElementById( "keyPress"+e.keyCode ) ) {
            if( link.tagName && link.href )
                document.location = link.href;
        } else if ( e.keyCode == 27 || e.keyCode == 13 || e.keyCode == 32 ) {
            BIA.util.hideElement('notification');
            BIA.util.hideElement('notificationOverlay');
            return false;
        }
    }

    return true;
}

YAHOO.util.Event.addListener( window, "load", BIA.keyNav.init );



BIA.util.capitalize = function(text) {
    return text.charAt(0).toUpperCase()+text.substr(1);
}


BIA.util.toggleElement = function( elementId, defaultStyle ) {
    element = document.getElementById( elementId );
    style = defaultStyle ? defaultStyle : "block";
    if ( YAHOO.util.Dom.getStyle( element,"display" ) == "none" )
        YAHOO.util.Dom.setStyle( element,"display", style );
    else
        YAHOO.util.Dom.setStyle( element,"display", "none");
}

BIA.util.hideElement = function( elementId ) {
    element = document.getElementById( elementId );
    YAHOO.util.Dom.setStyle( element,"display", "none");
}


BIA.util.showElement = function( elementId, defaultStyle ) {
    element = document.getElementById( elementId );
    style = defaultStyle ? defaultStyle : "block";
    YAHOO.util.Dom.setStyle( element,"display", style);
}

BIA.util.setNotification = function( notification, extraClass ) {

    document.getElementById( "notificationMessage" ).innerHTML = notification;
    if (extraClass == "error")
        document.getElementById("notificationClass").className = "notification_error";
        
    document.getElementById( "notification" ).style.display = "block";
    var ntf = new BIA.util.Notification();

}

BIA.util.popup = function( url, width, height, resizable, scrollbars, menubar ) {

    if( !width )
        width = 640;
    if( !height )
        height = 400;
    if( !resizable )
        resizable = "1";
    if (!scrollbars )
        scrollbars = "1";
    if (!menubar )
        menubar = "0";

    var popup = window.open( url, "BIAwindow", "menubar="+menubar+",resizable="+resizable+",scrollbars="+scrollbars+",width="+width+",height="+height );

    try { popup.focus(); } catch(e) {}
    return false;
}

BIA.util.setCookie = function( name, value, expires, path, domain, secure ) {

    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

BIA.util.getCookie = function ( name ) {
    var cookie_start, cookie_end;
    try {
        if (document.cookie.length > 0 && name !== "")
        {
            cookie_start = document.cookie.indexOf(name + "=");
            if (cookie_start !== -1)
            {
                cookie_start = cookie_start + name.length + 1;
                cookie_end = document.cookie.indexOf(";", cookie_start);
                if (cookie_end === -1) {
                    cookie_end = document.cookie.length;
                }

                return unescape(document.cookie.substring(cookie_start, cookie_end));
            }
        }
    } catch (ex) {
    }

    return "";
};

BIA.util.getNodeText = function( xmlNode )
{
    var strNodeText = '';
    var xmlChildNodes = xmlNode.childNodes;
    for( var i = 0; i < xmlChildNodes.length; i++ ) {
        if( xmlChildNodes[ i ].nodeType == 3 || xmlChildNodes[ i ].nodeType == 4 )
            strNodeText += xmlChildNodes[ i ].data;
        else
            strNodeText += getNodeText( xmlChildNodes[ i ] );
    }

    return strNodeText;
}



BIA.forms.DDList = function( targetId, formFieldName, sGroup ) {

    if( !YAHOO.util.DDTarget )
        throw new Error("DDList failed. Dependency YAHOO.util.dragdrop not found");
    if( !YAHOO.example.DDList )
        throw new Error("DDList failed. Dependency YAHOO.example.DDList not found");

    this.target = document.getElementById( targetId );
    if( !this.target )
        throw new Error("DDList failed. Target '"+targetId+"' not found.");

    YAHOO.util.Dom.addClass(this.target, "dd");

    this.form = YAHOO.util.Dom.getAncestorByTagName( this.target, "form" );

    // Add hidden form element to send the data
    this.formField = document.createElement("input");
    this.formField.type = "hidden";
    this.formField.name = formFieldName ? formFieldName : targetId;
    this.form.insertBefore( this.formField, this.form.firstChild );

    this.sGroup = sGroup ? sGroup : targetId;

    this.DDTarget = new YAHOO.util.DDTarget( targetId, this.sGroup );

    // Backup for if we need to reset the form
    this.backup = [];

    for( var i = 0; i < this.target.childNodes.length; i++ ) {
        if( this.target.childNodes[i].id ) {
            new YAHOO.example.DDList( this.target.childNodes[i].id, this.sGroup, {}, this.formField );
            this.backup[this.backup.length] = this.target.childNodes[i];
        }
    }
    this.updateFormField();
    YAHOO.util.Event.addListener( this.form, "reset", this.reset, this, true );
}


BIA.forms.DDList.prototype.reset = function(e) {

    for( i = this.target.childNodes.length-1; i >= 0; i-- )
        this.target.removeChild(this.target.childNodes[i]);

    for( i = 0; i < this.backup.length; i++ )
        this.target.appendChild(this.backup[i]);

    this.updateFormField();
}

BIA.forms.DDList.prototype.addElement = function( element ) {
    // Check if this element has an id
    if( !element.id )
        return false;

    // Check if this element is already in the list
    for( var i = 0; i < this.target.childNodes.length; i++ )
        if( this.target.childNodes[i].id == element.id )
            return false;

    this.target.appendChild( element );
    new YAHOO.example.DDList( element, this.sGroup, {}, this.formField );

    YAHOO.util.Dom.addClass( this.form, 'changed' );
    this.updateFormField();
}

BIA.forms.DDList.prototype.deleteElement = function( elementId ) {

    var element = YAHOO.util.Dom.get( elementId );
    var parent = element.parentNode;
    var elementTagName = element.tagName;
    parent.removeChild(element);

    YAHOO.util.Dom.addClass( this.form, 'changed' );
    this.updateFormField();
}

BIA.forms.DDList.prototype.updateFormField = function() {
    this.formField.value="";
    for( var i = 0; i < this.target.childNodes.length; i++ )
        if( this.target.childNodes[i].id )
            this.formField.value += this.target.childNodes[i].id+";";
}



BIA.forms.formSubmit = function( e, form ) {

    if( !form )
        form = YAHOO.util.Event.getTarget( e );
    var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;

    // Add the scroll value to the goto element (if found)
    for(i = 0; i < form.elements.length; i++ ) {
        if( form.elements[i].tagName.toLowerCase() == "input"
            && form.elements[i].name == "goto" ) {
            if( !form.elements[i].value )
                form.elements[i].value = document.location.pathname;
            if( form.elements[i].value.indexOf("#") == -1 )
                form.elements[i].value += "#scroll"+scrolly;
        }
        if( form.elements[i].tagName.toLowerCase() == "input"
            && !YAHOO.util.Dom.hasClass(form.elements[i], "nohash")
            && !YAHOO.util.Dom.hasClass(form.elements[i], "oz_field_input")
            && form.elements[i].type == "password"
            && form.elements[i].value ) {

            var passwordField = form.elements[i];
            var passwordHashField = document.createElement("input");
            passwordHashField.name = passwordField.name+"Hash";
            passwordHashField.type = "hidden";
            passwordHashField.value = SHA1( passwordField.value );
            form.appendChild( passwordHashField );
            passwordField.value = "";
        }
    }

    var buttons = form.getElementsByTagName("button");
    for (var j = 0; j < buttons.length; j++ ) {
        if (buttons[j].type == 'submit')
            buttons[j].disabled = true;
    }

    YAHOO.util.Dom.addClass( form, "disabled" );

    return true;
}

BIA.forms.init = function( e ) {

    var forms = document.getElementsByTagName("form");
    for( i = 0; i < forms.length; i++ )
        YAHOO.util.Event.addListener( forms[i], "submit", BIA.forms.formSubmit );
}

YAHOO.util.Event.addListener( window, "load", BIA.forms.init );


/**
*
*  Secure Hash Algorithm (SHA1)
*  http://www.webtoolkit.info/
*
**/

function SHA1 (msg) {

    function rotate_left(n,s) {
        var t4 = ( n<<s ) | (n>>>(32-s));
        return t4;
    };

    function lsb_hex(val) {
        var str=""; var i; var vh; var vl;

        for( i=0; i<=6; i+=2 ) {
            vh = (val>>>(i*4+4))&0x0f;
            vl = (val>>>(i*4))&0x0f;
            str += vh.toString(16) + vl.toString(16);
        }
        return str;
    };

    function cvt_hex(val) {
        var str=""; var i; var v;
        for( i=7; i>=0; i-- ) {
            v = (val>>>(i*4))&0x0f;
            str += v.toString(16);
        }
        return str;
    };
    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    };
    var blockstart; var i, j; var W = new Array(80); var H0 = 0x67452301; var H1 = 0xEFCDAB89; var H2 = 0x98BADCFE; var H3 = 0x10325476; var H4 = 0xC3D2E1F0; var A, B, C, D, E; var temp; msg = Utf8Encode(msg); var msg_len = msg.length; var word_array = new Array();
    for( i=0; i<msg_len-3; i+=4 ) {
        j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 | msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
        word_array.push( j );
    }
    switch( msg_len % 4 ) {
        case 0: i = 0x080000000; break;
        case 1: i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
        break;
        case 2: i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
        break;
        case 3: i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8    | 0x80;
        break;
    }
    word_array.push( i );
    while( (word_array.length % 16) != 14 ) word_array.push( 0 );
    word_array.push( msg_len>>>29 );
    word_array.push( (msg_len<<3)&0x0ffffffff );
    for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
        for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
        for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
        A = H0; B = H1; C = H2; D = H3; E = H4;
        for( i= 0; i<=19; i++ ) {
            temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
            E = D; D = C; C = rotate_left(B,30); B = A; A = temp;
        }
        for( i=20; i<=39; i++ ) {
            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
            E = D; D = C; C = rotate_left(B,30); B = A; A = temp;
        }
        for( i=40; i<=59; i++ ) {
            temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
            E = D; D = C; C = rotate_left(B,30); B = A; A = temp;
        }
        for( i=60; i<=79; i++ ) {
            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
            E = D; D = C; C = rotate_left(B,30); B = A; A = temp;
        }
        H0 = (H0 + A) & 0x0ffffffff;
        H1 = (H1 + B) & 0x0ffffffff;
        H2 = (H2 + C) & 0x0ffffffff;
        H3 = (H3 + D) & 0x0ffffffff;
        H4 = (H4 + E) & 0x0ffffffff;
    }
    var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
    return temp.toLowerCase();
}


BIA.forms.ImageCropper = function (img, w, h, ratio) {

    this.config = {
       maxWidth: w,
       maxHeight: h,
       xyratio: ratio
    };

    this.imgname = img;

    YAHOO.util.Event.addListener( window, "load", this.init, this, true );
}

BIA.forms.ImageCropper.prototype.init = function () {
    this.cropper = new YAHOO.widget.ImageCropper( this.imgname, this.config );
}

BIA.forms.ImageCropper.prototype.getCoords = function () {
    return this.cropper.getCropRegion();
}


/**
*
*  BIA.util.Notification
*
**/
BIA.util.Notification = function() {
    
    this.ntfDiv = document.getElementById("notification");
        
    // Set the initial size.
    var sizeVars    = this.getWindowSize();
    var diffOffset  = parseInt(sizeVars[1] / 2);
    if(this.ntfDiv && !isNaN(diffOffset)) {
        diffOffset  -= parseInt(this.ntfDiv.offsetHeight / 2);
        this.ntfDiv.style.top = diffOffset+'px';
    }
    
    // Reposition after window load.
    YAHOO.util.Event.addListener(window, "load", this.init, this, true);
}

BIA.util.Notification.prototype.init = function() {
    
    // Calc the position
    var scrollVars  = this.getScrollXY();
    var sizeVars    = this.getWindowSize();
    var diffOffset  = parseInt((sizeVars[1] / 2) + scrollVars[1]);
    if(this.ntfDiv && !isNaN(diffOffset)) {
        diffOffset  -= parseInt(this.ntfDiv.offsetHeight / 2);
        this.ntfDiv.style.top = diffOffset+'px';
    }
    
    // Hide after 4 secs.
    setTimeout(this.hideMe, 4000);    
}

BIA.util.Notification.prototype.hideMe = function() {
    
    BIA.util.hideElement("notification");
}

BIA.util.Notification.prototype.getScrollXY = function() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}


BIA.util.Notification.prototype.getWindowSize = function() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth , myHeight ];
}

/**
 * Fit images inside a specified width and height. When image is bigger than specified width
 * or height add the defined class name to the image.
 * 
 * @param string classIdentifier Classname to search images for
 * @param int    maxWidth        Maximum width of the image
 * @param int    maxHeight       Maximum height of the image
 * @param string addClass        Class to add to the image
 * 
 * @return void
 */
BIA.util.ImageFitter = function (classIdentifier, maxWidth, maxHeight, addClass) {
    
    // get all images
    var images = YAHOO.util.Dom.getElementsByClassName(classIdentifier, "img");
    
    if (images) {
        for (var x = 0; x < images.length; x++) {
            var image = images[x];
            if (image.width > maxWidth || image.height > maxHeight) {
                YAHOO.util.Dom.addClass(image, addClass);
            }
        }
    }
}

