/* ##########################################################################
    Copyright 2005 BBB Systems, LLC, All rights reserved
########################################################################## */

var navHistory = new Array( );
var curNavPoint = -1;

var globals = new Array( );

var currentLocation = '';

var recursionCount = 0;//this is so we can better test recursive funtions.

//detect safari
//In my opinion, safari isn't quit up to speed with the other modern browsers,
//although I hate to have safari hacks, I think it's a necessity in this
//application.  Hopefully they will patch most of their bugs in the future.
var is_safari = (document.childNodes)&&(!document.all)&&(!navigator.taintEnabled)&&(!navigator.accentColorName)?true:false;

if(imgRotatorThinking == undefined){
    var imgRotatorThinking = false;
}

window.js_initialized = false;

if(window.special_init){
    window.load_function = special_init;
}
else{
    window.load_function = function( ){ init( ); }
}

if(document.addEventListener){
    document.addEventListener('DOMContentLoaded', function( ){ window.load_function( ); }, false);
    //just in case, if DomContentLoaded ran, load will quit right away
    document.addEventListener('load', function( ){ window.load_function( ); }, false);
}
else if(document.attachEvent){
    document.attachEvent('onreadystatechange', function( ){ window.load_function( ); });
}
else if(window.onload){
    window.onload = function( ){ window.load_function( ); }
}

if(window.load_maps && window.onunload){
    window.onunload = function( ){ GUnload( ); }
}

function init( ){
    if(window.js_initialized){ return; }
    window.js_initialized = true;


    if(!document.getElementsByTagName){
        return;//if it doesn't support this, it doesn't support a whole lot.
    }
    //force ie < 6 to fail (we can't support ie5 forever)
    document.getElementsByTagName("a")[0].style.cursor = 'pointer';

    if(window.ajaxEnabled){
        ajaxCheck( );
    }
    else{
        window.ajaxEnabled = false;
        window.b_xml = false;
    }
    if(window.limitedAjax != true){
        window.limitedAjax = false;
    }

    window.unfinishedFauxBlocks = new Array( );

    initFauxBlocks( );
    initImgRotator( );

    initTopMenuLinks( );
    initA( );
    initAppObjects( );
    initObjects( );

    appThink( );

    if(window.loadMaps){
        loadGoogleMaps( );
    }
}

function xmlInit( ){
    initFauxBlocks( );
    initImgRotator( );
    initA( );
    initAppObjects( );
    initObjects( );

    if(window.loadMaps){
        loadGoogleMaps( );
    }
}

function initFauxBlocks( ){
    if(window.noFauxBlocks){ return; }

    var content = document.getElementById('content');
    var divs = content.getElementsByTagName('div');

    var faux_blocks = new Array( );
    var j = 0;
    for(var i = 0; i < divs.length; i++){
        var div = divs[i];
        if(div.className && div.className.match(/faux\_block/)){
            faux_blocks[j] = div;
            j++;
        }
    }

    if(faux_blocks.length == 0){
        var div = document.createElement('div');
        div.className = 'faux_block faux_opacity_60';

        div.innerHTML = content.innerHTML;
        content.innerHTML = '';
        content.appendChild(div);
        faux_blocks[0] = div;
    }

    for(var i = 0; i < faux_blocks.length; i++){
        var div = faux_blocks[i];


        var faux_inner = document.createElement('div');
        faux_inner.className = 'faux_inner';

        faux_inner.innerHTML = div.innerHTML;
        div.innerHTML = '';
        div.appendChild(faux_inner);

        var faux_background = false;
        var faux_border_0 = document.createElement('div');
        var faux_border_1 = document.createElement('div');
        faux_border_0.className = 'faux_border_0';
        faux_border_1.className = 'faux_border_1';

        if(div.className.match(/faux\_opacity\_\d+/)){
            faux_background = document.createElement('div');
            faux_background.className = 'faux_background';

            faux_background.style.top = 0;
            faux_background.style.left = 0;

            var opacity = div.className.replace(/.*faux\_opacity\_(\d+).*/, "$1");
            var std_opacity = opacity / 100;

            faux_background.style.opacity = std_opacity;

            if(window.ActiveXObject){
                faux_background.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
            }

            div.style.backgroundColor = 'transparent';

            div.appendChild(faux_background);
        }

        div.appendChild(faux_border_0);
        div.appendChild(faux_border_1);
    }
}

function fixFauxBorders( ){
    var content = document.getElementById('content');
    if(!content){ return; }

    var divs = document.getElementsByTagName('div');
    for(var i = 0; i < divs.length; i++){
        var div = divs[i];
        if(div.className == 'faux_border_0' || div.className == 'faux_border_1' || div.className == 'faux_background'){
            var pnode = div.parentNode;
            var f_width = 0;
            var f_height = 0;

            if(pnode.offsetWidth){
                f_width = pnode.offsetWidth;
                f_height = pnode.offsetHeight;
            }

            if(f_width == 0){
                return;//don't bother
            }

            if(div.className == 'faux_border_0'){
                f_width = f_width + 6;
                f_height = f_height + 2;
            }
            else if(div.className == 'faux_border_1'){
                f_width = f_width + 2;
                f_height = f_height + 6;
            }
            else{
                f_width = f_width;
                f_height = f_height;
            }
            div.style.width = f_width + 'px';
            div.style.height = f_height + 'px';
        }
        else if(div.className && div.className.match(/faux_block/) && window.isOldIE){
            if(div.style.minHeight != ''){
                div.style.height = div.style.minHeight;
            }
        }
    }
}

function initA( ){
    if(document.getElementsByTagName){
        var as = document.getElementsByTagName("a");
        for(var i = 0; i < as.length; i++){

            if(as[i].parentNode.id != ''){
                if(as[i].parentNode.id == 'bLeftArrow' || as[i].parentNode.id == 'bRightArrow'){
                    as[i].onclick = function( ){
                        return false;
                    }
                    continue;
                }
            }

            var hostnm = as[i].href.replace(/http(s)?\:\/\//, "");
            hostnm = hostnm.replace(/\/.*/, "");

            if((hostnm != window.location.hostname && hostnm != '') || as[i].href.match(/\/ad\.\php\?/)){
                as[i].target = "_blank";
                continue;
            }

            if(ajaxEnabled && as[i].className != "noAJAX" && !as[i].href.match(/\/members\//) && !as[i].href.match(/feed\.php/)){
                if(b_xml){
                    if( as[i].href.match(/(\#)$/) ){
                        continue;
                    }

                    if(as[i].href.match(/\#\w+/)){
                        continue;
                    }

                    as[i].onclick = function( ){
                        if(this.href.match(/\.pdf/)){
                            pdfPopup = window.open(this.href, "PDF");
                            pdfPopup.focus( );
                            return false;
                        }

                        //alert(b_xml.isCurrentRequest);
                        if(b_xml.isCurrentRequest){
                            return false;
                        }


                        //we need the protocol
                        hostnm = window.location.hostname;

                        var newHREF = this.href;

                        newHREF = newHREF.replace(/^(http(s)?\:\/\/)([^\/]+)/, '');
                        newHREF = newHREF.replace(/(\/\#)/, '');
                        newHREF = newHREF.replace(/([\&\?]*refer\=.*)$/, '');

                        this.href = '/#' + newHREF;

                        if(document.all && window.ieHistoryHack != undefined){
                            //add the anchor for our happy ie hack
                            ieHistoryHack.src = '/iehack.php?' + newHREF.replace(/^(\/\#)/, '');
                            ieHistoryHack.window.location = ieHistoryHack.src
                        }

                        currentLocation = newHREF;

                        if(newHREF.match(/\?/)){
                            newHREF += "&xmlOnly=1";
                        }
                        else{
                            newHREF += "?xmlOnly=1";
                        }

                        //safari hack
                        if(is_safari){
                            //fakeHistory gets initialized by safari
                            var tlen = window.history.length + 1;
                            if(window.fakeHistory == undefined){
                                window.fakeHistory = new Array( );
                            }

                            window.fakeHistory[tlen] = newHREF;
                        }

                        var tHREF = window.location.href.replace(/^(http(s)?\:\/\/)([^\/]+)/, '');
                        imgRotatorThinking = false;
                        b_xml.request(newHREF);

                        if(b_xml.isSupported){
                            return true;
                        }

                        return true;
                    }
                }
            }
        }//end for a

        if(ajaxEnabled){
            if(!b_xml){
                return;
            }

            var productsBlockTabs = document.getElementById('productsBlockTabs');
            if(productsBlockTabs){
                i = 0;
                as = productsBlockTabs.getElementsByTagName("a");
                for(i = 0; i < as.length; i++){
                    as[i].onclick = function( ){
                        if(b_xml.isCurrentRequest){ return false; }
                        //ul = a->li->ul (this->parent->parent)
                        var ul = this.parentNode.parentNode;
                        var p_as = ul.getElementsByTagName('a');

                        for(var j = 0; j < p_as.length; j++){ p_as[j].className = ''; }
                        this.className = 'cur';
                        var newHREF = this.href;
                        newHREF = newHREF.replace(/(\#.*)$/, '');
                        newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                        newHREF = newHREF + '/type/prodtabs';
                        //alert(newHREF);
                        b_xml.request(newHREF);
                        if(b_xml.isSupported){ return false; }
                        return true;
                    }//end onclick
                }//end foreach a in productsBlockTabs
            }

            var prodContentTabs = document.getElementById('prodContentTabs');
            if(prodContentTabs){
                i = 0;
                as = prodContentTabs.getElementsByTagName("a");
                for(i = 0; i < as.length; i++){
                    as[i].onclick = function( ){
                        if(b_xml.isCurrentRequest){ return false; }
                        //ul = a->li->ul (this->parent->parent)
                        var ul = this.parentNode.parentNode;
                        var p_as = ul.getElementsByTagName('a');

                        for(var j = 0; j < p_as.length; j++){ p_as[j].className = ''; }
                        this.className = 'cur';
                        var newHREF = this.href;
                        newHREF = newHREF.replace(/(\#.*)$/, '');
                        newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                        newHREF = newHREF + '/type/pctabs';
                        //alert(newHREF);
                        b_xml.request(newHREF);
                        if(b_xml.isSupported){ return false; }
                        return true;
                    }//end onclick
                }//end foreach a in prodContentTabs
            }
        }
    }
    var bbb = document.getElementById('bbb');
    if(bbb){
        bbb.innerHTML = '<a href="http://www.bbbsystems.net/" target="_blank">Arizona Web Design: BBB Systems, llc</a>';
    }
}

function initObjects( ){

    var objects = document.getElementsByTagName("div");
    var len = objects.length;

    var tLoc = window.location.href;

    var prot = 'http';
    if(document.all && tLoc.match(/^https/)){
        prot = 'https';
    }

    for(var i = 0; i < len; i++){
        var obj = objects[i];
        if(obj.className && obj.className == 'bgzobject'){
            var paramStr = '';
            var objStr = '\n<object ';
            var embedStr = '\n<embed ';
            var params = obj.getElementsByTagName('param');
            var plen = params.length;
            var o_type = '';
            var o_filename = '';
            var o_width = '';
            var o_height = '';
            //need o_type, it will be first or second in the list, but just in case.
            for(j = 0; j < plen; j++){
                var param = params[j];
                var pn = param.name;
                var pv = param.value;
                if(pn == 'o_type'){
                    o_type = pv;

                    //do this here because we have to force video type for wmv files
                    var isWindows = false;
                    //if( o_type != 'wmv' && !document.all){
                    //     isWindows = false;
                    //}else if(o_type == 'wmv' || navigator.userAgent.match(/windows/i)){
                    if(o_type == 'wmv' || navigator.userAgent.match(/windows/i)){
                        isWindows = true;
                    }

                    break;
                }
            }
            for(j = 0; j < plen; j++){
                var param = params[j];
                var pn = param.name;
                var pv = param.value;

                switch(pn){
                case 'o_type':
                    if(o_type == 'swf'){
                        embedStr += ' type="application/x-shockwave-flash" ';
                        objStr += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
                        objStr += ' codebase="' + prot + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
                    }
                    else if(isWindows && o_type != 'mov'){

                        embedStr += ' type="application/x-mplayer2" ';
                        embedStr += '  pluginspage="' + prot + '://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" ';
                        objStr += ' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
                        objStr += ' standby="Loading..." ';
                        objStr += ' type="application/x-oleobject" ';
                        objStr += ' codebase="' + prot + '://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ';
                    }
                    else{
                        embedStr += ' pluginspage="' + prot + '://www.apple.com/quicktime/download/" ';
                        objStr += ' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
                        objStr += ' codebase="' + prot + '://www.apple.com/qtactivex/qtplugin.cab" ';
                    }
                    break;
                case 'o_filename':
                    o_filename = pv;
                    if(o_type == 'swf'){
                        paramStr += ' <param name="movie" value="/docs/' + pv + '" /> \n';
                    }
                    else if(isWindows && o_type != 'mov'){
                        paramStr += ' <param name="filename" value="/docs/' + pv + '" /> \n';
                    }
                    else{
                        paramStr += ' <param name="src" value="/docs/' + pv + '" /> \n';
                    }
                    embedStr += ' src="/docs/' + pv + '" ';

                    break;
                case 'o_width':
                    o_width = pv;
                    obj.width = pv;
                    embedStr += ' width="' + pv + '" ';
                    objStr += ' width="' + pv + '" ';
                    break;
                case 'o_height':
                    o_height = pv;
                    obj.height = pv;
                    embedStr += ' height="' + pv + '" ';
                    objStr += ' height="' + pv + '" ';
                    break;
                default:
                    pn = pn.replace(/^(o\_)/, '');

                    if(!isWindows && pn == 'showcontrols'){
                        pn = 'controller';
                    }

                    if(pn == 'transparency'){
                        pn = 'wmode';
                        pv = 'transparent';

                        if(document.all){
                            //for some reason flash transparency is screwing up on this site,
                            //if we ever figure it out, delete this code
                            //seems to work now *shrug* - hobbit
                            //continue;
                        }
                    }

                    paramStr += ' <param name="' + pn + '" value="' + pv + '" /> ';

                    if(pv.toLowerCase( ) == 'false'){
                        pv = '0';
                    }
                    else if(pv.toLowerCase( ) == 'true'){
                        pv = '1';
                    }

                    if(pn == 'showcontrols'){
                        if(pv == '0'){
                            paramStr += ' <param name="ShowStatusBar" value="false" /> \n';
                            embedStr += ' showstatusbar="0" ';
                        }
                        else{
                            paramStr += ' <param name="ShowStatusBar" value="true" /> \n';
                            embedStr += ' showstatusbar="1" ';
                        }
                    }

                    embedStr += ' ' + pn + '="' + pv + '" ';


                    break;
                }
            }//end params

            embedStr += '></embed>\n';
            objStr += '>\n';
            //alert(objStr + paramStr + embedStr + '</object>');

            obj.innerHTML = objStr + paramStr + embedStr + '</object>\n';
            obj.style.display = 'block';

        }//end if bgzobject
    }//end foreach object

}

function initAppObjects( ){

}

function toggleDescription(e){
    var gallery_description = document.getElementById('gallery_description');

    if(!gallery_description){
        return;
    }

    if(gallery_description.style.display != 'none'){
        gallery_description.style.display = 'none';
    }
    else{
        gallery_description.style.display = 'block';
    }
}

function initImgRotator( ){
    var image_table = getGalleryImageTable( );
    var display_image = getGalleryMainImage( );

    var pcontainer = getPortfolioMainImageContainer( );

    if(!image_table || !display_image){ return; }

    if(pcontainer){
        pcontainer.onclick = toggleDescription;
    }

    display_image.style.width = 'auto';

    display_image.style.opacity = 1;

    var imageA = image_table.getElementsByTagName('img');

    //preload the gallery images for smoother transitions
    window.galleryImages = new Array( );

    j = 0;
    for(i = 0; i < imageA.length; i++){
        var img = imageA[i];

        if(!img.id || img.id == '' || img.id == display_image.id){
            continue;
        }

        var d_id = 'gallery_image_div_' + j;
        var next_id = 'gallery_image_div_' + parseInt(j + 1);
        if(i == imageA.length - 1){
            next_id = 'gallery_image_div_0';
        }

        img.parentNode.onmouseover = galleryImageHover;
        img.parentNode.onmouseout = galleryImageOut;
        img.parentNode.onclick = galleryImageClick;

        img.parentNode.id = d_id;
        img.parentNode.next_id = next_id;

        //preload the image
        window.galleryImages[d_id] = new Image( );
        window.galleryImages[d_id].src = img.src.replace(/\_t(\.\w+)$/, "$1");

        if(i == 0){
            window.galleryCurImageDiv = d_id;
            window.galleryCurImage = window.galleryImages[d_id].src;
        }
        j++;
    }

    var scale_time = 5000;
    if(image_table.id == 'home_img_gallery_tbl'){
        scale_time = 4000;
    }

    setGalleryNextRotation(scale_time);

    //imageRotatorThink( );//call this in appThink
}
function setGalleryNextRotation(t_offset){
    var dt = new Date( );
    window.galleryNextRotation = parseInt(dt.getTime( ) + t_offset);
    dt = null;
}
function getGalleryImageTable( ){
    var image_table = document.getElementById('home_img_gallery_tbl');
    if(!image_table){ image_table = document.getElementById('img_gallery_tbl'); }
    return image_table;
}
function getGalleryMainImage( ){
    var display_image = document.getElementById('home_img_main');
    if(!display_image){ display_image = document.getElementById('gallery_img_main'); }
    return display_image;
}
function getPortfolioMainImageContainer( ){
    return document.getElementById('portfolio_img_main_container');
}

function gallerySwapTransition( ){
    var display_image = getGalleryMainImage( );
    var image_table = getGalleryImageTable( );
    var gallery_description = document.getElementById('gallery_description');



    var pcontainer = getPortfolioMainImageContainer( );

    if(!display_image || !image_table){
        return;
    }

    var a_amt = .10;
    if(window.ActiveXObject){
        a_amt = .15;
    }

    var fadeObj = display_image;

    if(pcontainer){
        fadeObj = pcontainer;
        if(!fadeObj.style.opacity){
            fadeObj.style.opacity = 1;
        }
    }

    var cur_alpha = parseFloat((parseFloat(fadeObj.style.opacity) * 100)/100);

    var alpha = cur_alpha + (window.galleryCurDir * a_amt);

    if(alpha <= 0){
        alpha = 0;
        window.galleryCurDir = 1;
        display_image.src = window.galleryCurImage;

        if(gallery_description){
            gallery_description.innerHTML = window.galleryCurImageDescription + '<div id="gallery_x">X</div>';

            if(window.galleryCurImageDescription == '' || window.galleryCurImageDescription == '&nbsp;'){
                gallery_description.style.display = 'none';
            }
            else{
                gallery_description.style.display = 'block';
            }
        }
    }
    if(alpha >= 1){
        alpha = 1;
    }

    fadeObj.style.opacity = alpha;
    if(window.ActiveXObject){
        var ie_alpha = parseInt(alpha * 100);
        fadeObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + ie_alpha + ")";
    }

    if(alpha != 1){
        setTimeout('gallerySwapTransition( );', 50);
    }
}
function gallerySwapImage(imgObject){
    var display_image = getGalleryMainImage( );
    var image_table = getGalleryImageTable( );
    var gallery_description = document.getElementById('gallery_description');

    if(!display_image || !image_table){
        return;
    }

    window.galleryCurImageDiv = imgObject.parentNode.id;
    window.galleryCurImage = window.galleryImages[imgObject.parentNode.id].src;
    window.galleryCurDir = -1;
    var divs = image_table.getElementsByTagName('div');

    for(i = 0; i < divs.length; i++){
        var div = divs[i];
        div.className = '';
    }

    imgObject.parentNode.className = 'cur';
    imgObject.parentNode.classNameBak = 'cur';

    var i_id = imgObject.id.replace(/[^\d]+/, '');
    var g_desc_i = document.getElementById('gallery_description_' + i_id);

    if(g_desc_i){
        window.galleryCurImageDescription = g_desc_i.innerHTML;
        //gallery_description.innerHTML = g_desc_i.innerHTML;
    }
    else{
        window.galleryCurImageDescription = '';
    }

    if(display_image.style.opacity == 1){
        gallerySwapTransition( );
    }
}
function galleryImageClick( ){
    //make it long on the gallery pages.
    var scale_time = 10000;
    setGalleryNextRotation(scale_time);
    gallerySwapImage(this.getElementsByTagName('img')[0]);
}
function galleryImageHover( ){
    this.classNameBak = this.className;
    this.className = 'over';
}
function galleryImageOut( ){
    this.className = this.classNameBak;
}
function imageGalleryThink( ){
    var display_image = getGalleryMainImage( );
    var image_table = getGalleryImageTable( );

    if(!display_image || !image_table){
        return;
    }

    dt = new Date( );
    if(dt.getTime( ) >= window.galleryNextRotation){
        var scale_time = 5000;
        if(image_table.id == 'home_img_gallery_tbl'){
            scale_time = 4000;
        }
        setGalleryNextRotation(scale_time);
        var div = document.getElementById(window.galleryCurImageDiv);
        var next_div = document.getElementById(div.next_id);
        var img = next_div.getElementsByTagName('img')[0];
        gallerySwapImage(img);
    }
}

function appThink( ){

    //Add custom thinkers here.
    imageGalleryThink( );

    if(window.ActiveXObject){
        fixFauxBorders( );
    }

//from here down is all specificly ajax stuff

if(ajaxEnabled && !window.limitedAjax){

    var newHREF = window.location.href;

    //the big ieHack, this is sick, don't try this at home
    var didIE = false;
    var windowHREF = newHREF;//another piece of the ie hack
    //and the all new Safari hack, w00t

    if(is_safari){
        var tlen = window.history.length;
        if(window.cHistoryLength == undefined){
            window.cHistoryLength = tlen;
            window.fakeHistory = new Array( );

            var sfh = getCookie('safariFakeHistory');
            var sfhl = getCookie('safariFakeHistoryLength');

            if(sfh && sfhl == tlen){
                //Only for refreshing, it will bug up otherwise, not much we can do about it though
                window.fakeHistory = sfh.split("|");
            }
            else{
                //back will no longer work at this point, fair sacrifice though
                window.fakeHistory[tlen] = window.location.href;
            }
        }

        if(window.cHistoryLength != tlen){
            if(window.fakeHistory[tlen] != undefined && tlen != window.cHistoryLength){
                newHREF = window.fakeHistory[tlen];
            }
            window.cHistoryLength = window.history.length;
            window.fakeHistory[tlen] = newHREF;

            var cookStr = '';
            for(var i = 0; i < window.fakeHistory.length; i++){
                cookStr += window.fakeHistory[i] + '|';
            }
            setcookie('safariFakeHistory', cookStr);
            setcookie('safariFakeHistoryLength', tlen);
        }
        else{
            newHREF = window.fakeHistory[tlen];
        }
    }
    else if(document.all && window.ieHistoryHack != undefined){
        windowHREF = windowHREF.replace(/^(http(s)?\:\/\/)([^\/]+)/, '');
        windowHREF = windowHREF.replace(/(\/\#)/, '');

        //if(ieHistoryHack.document.body.innerHTML != '/'){
        if(ieHistoryHack && ieHistoryHack.document && ieHistoryHack.document.body && ieHistoryHack.document.body.innerHTML){
            newHREF = ieHistoryHack.document.body.innerHTML;
            didIE = true;
        }
        //}
    }

    newHREF = newHREF.replace(/^(http(s)?\:\/\/)([^\/]+)/, '');

    var tHREF = newHREF;

    newHREF = newHREF.replace(/(\/\#)/, '');

/*
    //debug information... pick an id, any id (it beats infinite alerts).
    var tvar = newHREF + ' - ' + currentLocation + '<br />hash: ' + window.location.hash + '<br />location: ' + window.location + '<br />doc-location:' + document.location;
    tvar += '<br />' + window.history.length;
    document.getElementById('bbb').innerHTML = tvar;
*/

    if(newHREF != '' && ( tHREF.match(/^\/#/) || tHREF == '/' || currentLocation == '' || currentLocation != newHREF) ){

        //if(recursionCount < 5){
        //    alert(newHREF + ' - ' + currentLocation + ' - ' + windowHREF);
        //    recursionCount++;
        //}

        //check to see if the location has changed
        if(newHREF != currentLocation && !b_xml.isCurrentRequest && window.location.protocol.toLowerCase( ) != 'https'){
            if(document.all && didIE){
                //update the location in the address bar to complete the ie hack
                var ieURL = '/';
                if(newHREF != windowHREF){
                    ieURL = '/#' + newHREF;
                    if(newHREF == '/'){
                        window.location.href = '/';
                    }
                    else{
                        window.location.href = ieURL;
                    }
                }
            }

            currentLocation = newHREF;
            //if(recursionCount < 5){
            //    alert(newHREF + ' - ' + currentLocation + ' - ' + windowHREF);
            //    recursionCount++;
            //}


            if(newHREF.match(/\?/)){
                newHREF += "&xmlOnly=1";
            }
            else{
                newHREF += "?xmlOnly=1";
            }
            b_xml.request(newHREF);
        }
    }
}//End if ajaxEnabled

    //make the program think every 10th of a second
    setTimeout('appThink( )', 100);
}

//Cool input effects
function inputOver(e){
    this.className = "buttonOver";
}

function inputOut(e){
    this.className = "button";
}

//Popups
function generalPopUp(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=0, status=no,toolbar=no,resizable=yes");
    gPopUp.focus( );
}
function generalPopUp2(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=yes,menubar=yes");
    gPopUp.focus( );
}

function imageSelectPopUp(pwinvar){
    imgSelectPopUp = window.open("./imageselect.php?mode=1&fieldID=" + pwinvar, "ImageSelector", "width=780,height=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openUploader( ){
    var imgSelectPopUp = window.open("./imageselect.php", "ImageSelector", "width=780,height=680, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );

    return false;
}

function fileSelectPopUp(pwinvar){
    imgSelectPopUp = window.open("./fileselect.php?mode=1&fieldID=" + pwinvar, "FileSelector", "width=780,height=580, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openFUploader( ){
    var imgSelectPopUp = window.open("./fileselect.php", "FileSelector", "width=780,height=580, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );

    if(document.all){
        window.event.cancelBubble = true;
    }
    else{
        e.stopPropagation( );
        e.preventDefault( );
    }
    return false;
}

//drop down menus ##################################################


var CurMenu = null;
var isDropped = false;
var isHideCheck = false;
var subCurMenu = null;
var subIsDropped = false;
var subIsHideCheck = false;

function initTopMenuLinks( ){
    var tmenu1 = document.getElementById('tmenu_1');
    var tmenu2 = document.getElementById('tmenu_2');

    initTopMenuLinks2(tmenu1);
    initTopMenuLinks2(tmenu2);
}

function initTopMenuLinks2(table_object){
    if(!table_object){ return; }

    var tdA = table_object.getElementsByTagName('td')
    var len = tdA.length;

    if(window.opera){
        //opera has some rendering issues with this cool stuff, not sure why
        var tlinks = table_object.getElementsByTagName('a');
        for(var i = 0; i < tlinks.length; i++){
            tlinks[i].style.opacity = 1;
        }
    }

    for(var i = 0; i < len; i++){
        var td = tdA[i];
        if(bgzDDEnabled){
            td.bgzdd = new bgzDropDown( );
            var ul = td.getElementsByTagName('ul')[0];
            if(ul){
                td.bgzdd.init(td, ul, 'down');
            }
        }
        else{
            td.onmouseover = pageON;
            td.onmouseout = pageOFF;
        }
    }
}

function pageON(index){
    var uls = this.getElementsByTagName('ul');
    if(uls.length > 0){
        show(uls[0]);
    }

}
function pageOFF(index){
    if(document.getElementById){
        if(!isHideCheck) hideMenu( );
    }
}
function show(menu){
    if(CurMenu)
        CurMenu.style.display = "none";
    menu.style.display = "block";
    isDropped = true;
    CurMenu = menu;
}
function hideMenu( ){
    if(CurMenu){
        isDropped = false;
        isHideCheck = true;
        setTimeout('checkDropped( );', 500);
        isHideCheck = false;
    }
}
function checkDropped( ){
    if(!isDropped) CurMenu.style.display = "none";
}
//############################################################

function setcookie(cookieName,cookieValue){
    //sets a cookie that expires at the end of the session
    document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/";
}

function getCookie(cname){
    var dc = document.cookie;
    var prefix = cname + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1){
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else{
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1){
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


/* GOOGLE MAPS */

function setDirections(toAddress, fromAddress){
    if(!fromAddress || !toAddress){
        return;
    }

    var mapObj = document.getElementById("google_map");
    if(!mapObj){
        return;
    }

    var directions = document.getElementById('directions');
    if(!directions){
        return;
    }

    var map = new GMap2(mapObj);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());

    gdir = new GDirections(map, directions);
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);

    gdir.load("from: " + fromAddress + " to: " + toAddress);

}

function handleErrors( ){
    if (gdir.getStatus( ).code == G_GEO_UNKNOWN_ADDRESS)
        alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_SERVER_ERROR)
        alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_MISSING_QUERY)
        alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_BAD_KEY)
        alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus( ).code == G_GEO_BAD_REQUEST)
        alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

    else alert("An unknown error occurred.");
}

function onGDirectionsLoad( ){
    var directions = document.getElementById('directions');
    directions.style.display = 'block';
}

function loadGoogleMaps( ){
    if(GBrowserIsCompatible( )){
        maps = document.getElementsByTagName("div");

        for(var i = 0; i < maps.length; i++){
            var curMap = maps[i];
            if(curMap.id == "google_map"){
                var coords = curMap.innerHTML;

                if(coords.match(/address\:/g)){
                    var address = coords.replace(/address\:/, '');

                    var info = '';
                    if(address.match(/\|\|info\:/g)){
                        var addA = address.split('||');
                        address = addA[0];

                        var info = addA[1].replace(/info\:/, '');
                    }

                    markAddress(address, curMap, info);
                }
                else{
                    coords = coords.split(",");
                    if(!coords[1]){
                        return;
                    }

                    var map = new GMap2(curMap);
                    map.setCenter(new GLatLng(coords[0], coords[1]), 16);
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());

                    //map.openInfoWindowHtml(map.getCenter(),"html goes here");
                    //map.setMapType(G_HYBRID_MAP);

                    //Create Custom Icon
                    //var icon = new GIcon();
                    //icon.image = "/images/map_icon.png";
                    //icon.iconSize = new GSize(65, 31);
                    //icon.iconAnchor = new GPoint(32.5, 31);
                    //icon.infoWindowAnchor = new GPoint(5, 1);

                    var point = new GLatLng(coords[0], coords[1]);
                    map.addOverlay(new GMarker(point, icon));

                }
            }
        }
    }
}

function markAddress(address, curMap, info){
    var map = new GMap2(curMap);
    var geocoder = new GClientGeocoder( );

    geocoder.getLatLng(address,
        function(point){
            if(!point){
                alert("Google was unable to find " + address + " at this time, please make sure the address provided, is correct.");
            }
            else{
                map.setCenter(point, 13);
                map.addControl(new GSmallMapControl());
                map.addControl(new GMapTypeControl());

                var marker = new GMarker(point);
                map.addOverlay(marker);
                map.openInfoWindowHtml(point, "<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");

                GEvent.addListener(marker, "click", function(overlay,latlng){
                    map.openInfoWindowHtml(point, "<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");
                });
            }
        }
    );

}
/* END GOOGLE MAPS */

function imagesLoaded(node){
    var imgA = node.getElementsByTagName('img');
    for(var i = 0; i < imgA.length; i++){
        if(!imgA[i].complete){ return false; }
    }
    return true;
}

function refreshSImg(sImg){
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomStr = '';
	for (var i = 0; i < string_length; i++) {
		var rnum = Math.floor(Math.random( ) * chars.length);
		randomStr += chars.substring(rnum, rnum+1);
	}

	var sImgSrc = sImg.src;
	if(sImgSrc.match('&')){
	    sImgSrcA = sImgSrc.split('&');
	    sImgSrc = sImgSrcA[0];
	}

    sImg.src = sImgSrc + '&' + randomStr;
}

function disableBoxes(form, check){
    for(var i = 0; i < form.elements.length; i++){
        if(form.elements[i].type == 'checkbox' && form.elements[i].id != 'acheck'){
            form.elements[i].disabled = check;
            form.elements[i].checked = check;
        }
    }
}