/* ##########################################################################
    Copyright 2005 BBB Systems, LLC, All rights reserved

    We don't mind if you learn from our scripts, or even use portions of
    them, but please be tactful and ethical.  If you find our scripts
    useful, let us know, we would like to hear from you.
    (www.bbbsystems.net has a contact form)

    AJAX Note:
    We got much of our information for fixing the broken back button here:
    http://www.contentwithstyle.co.uk/Articles/38/

########################################################################## */

/*
var plusImg = new Image( );
plusImg.src = "/images/plus.gif";
var minusImg = new Image( );
minusImg.src = "/images/minus.gif";
*/
var sGlobals = new Object( );
sGlobals.bScrollAmount = 20;
sGlobals.slowScroll = 75;
sGlobals.fastScroll = 25;
sGlobals.isScrollingR = false;
sGlobals.isScrollingL = false;

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.

var fieldLen = 0;//personalizedProduct

//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;

var imgRotatorThinking = false;

var stopProdRotator = false;
var allowedPRIndex = 1;
function init(gInit){
    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;
    }

    initTopMenuLinks( );
    //initLeftMenuLinks( ); //but there is a left menu! uh... no there isn't
    initA( );

    initInputButtons( );

    initObjects( );
    initImgRotator( );
    initProductRotator( );

    appThink( );

    if(gInit){
        loadGoogleMaps( );
    }

    popupDirections( )
    balanceColumns( );
}

function xmlInit( ){
    initA( );
    initAppObjects( );
    initInputButtons( );
    initImgRotator( );
    initObjects( );
}

function initInputButtons( ){
    //new ie don't need this.
    if(window.isOldIE){
        var inputs = document.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if((inputs[i].type == "submit" || inputs[i].type == "reset" || inputs[i].type == "button") && inputs[i].className == "button"){
                inputs[i].onmouseover = inputOver;
                inputs[i].onmouseout = inputOut;
            }
        }
        var buttons = document.getElementsByTagName("button");
        for(var i = 0; i < buttons.length; i++){
            if((buttons[i].type == "submit" || buttons[i].type == "reset" || buttons[i].type == "button") && buttons[i].className == "button"){
                buttons[i].onmouseover = inputOver;
                buttons[i].onmouseout = inputOut;
            }
        }
    }
}

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(/\.pdf/)){
                if(b_xml){
                    if( as[i].href.match(/(\#)$/) ){
                        continue;
                    }
                    if(as[i].href.match(/(\#)(\w+)$/)){

                        as[i].onclick = function( ){
                            //do match
                            var lnA = this.href.split(/\#/);

                            ln = '';
                            if(lnA[1]){
                                var ln = lnA[1];
                            }
                            else{
                                return false;
                            }

                            var as = document.getElementsByTagName("a");
                            for(var j = 0; j < as.length; j++){
                                if(as[j].name == ln){
                                    var sy = as[j].offsetTop;
                                    var pys = as[j].offsetParent.offsetParent.offsetTop;

                                    var ty = sy + pys;

                                    window.scrollTo(0, ty);
                                    break;
                                }
                            }


                            return false;
                        }

                        continue;
                    }

                    as[i].onclick = function( ){
                        //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)?\:\/\/)([^\/]+)/, '');
                        //if(tHREF.match(/^\/\#/)){
                            //alert(newHREF);
                            b_xml.request(newHREF);
                        //}

                        if(b_xml.isSupported){
                            return true;
                        }

                        return true;
                    }
                }
            }
        }
    }
}

function initObjects( ){

    var objects = document.getElementsByTagName("div");
    var len = objects.length;

    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="http://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="http://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="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ';
                    }
                    else{
                        embedStr += ' pluginspage="http://www.apple.com/quicktime/download/" ';
                        objStr += ' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
                        objStr += ' codebase="http://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 bScrollLeft( ){
    if(sGlobals.isScrollingL){
        bottomBaseScroll(-1 * sGlobals.bScrollAmount);
        setTimeout('bScrollLeft( );', sGlobals.scrollTime);
    }
}

function bScrollRight( ){
    if(sGlobals.isScrollingR){
        bottomBaseScroll(sGlobals.bScrollAmount);
        setTimeout('bScrollRight( );', sGlobals.scrollTime);
    }
}

function initAppObjects( ){
    var bBaseGallery = document.getElementById('bBaseGallery');
    var bbc = document.getElementById('bottomBase');

    var i;
    if(curNavPoint < 0){
        curNavPoint = 0;

        var newHREF = window.location.href;
        if(newHREF.match(/\?/)){
            newHREF += "&xmlOnly=1";
        }
        else{
            newHREF += "?xmlOnly=1";
        }

        navHistory.push(newHREF);
    }

    if(bbc && bBaseGallery){
        var clientW = bbc.clientWidth;
        var scrollW = bbc.scrollWidth;
        if(bBaseGallery && bBaseGallery.clientWidth < bbc.scrollWidth){
            if(document.all){
                bBaseGallery.style.width = parseInt(bbc.scrollWidth + 32) + "px";
            }
            else{
                bBaseGallery.style.width = parseInt(bbc.scrollWidth) + "px";
            }
        }
        else if(bBaseGallery){
            bBaseGallery.style.width = "auto";
        }

        var bLeftArrow = document.getElementById('bLeftArrow');
        var bRightArrow = document.getElementById('bRightArrow');

        if(document.addEventListener){
            bbc.addEventListener('DOMMouseScroll', captureScroll, false);
        }
        else{
            //bbc.onscroll = captureScroll;
        }


        bLeftArrow.onmouseover = function( ){
            sGlobals.isScrollingL = true;
            sGlobals.scrollTime = sGlobals.slowScroll;
            bScrollLeft( );
        }
        bLeftArrow.onmouseout = function( ){
            sGlobals.isScrollingL = false;
            sGlobals.scrollTime = sGlobals.slowScroll;
        }
        bLeftArrow.onmousedown = function( ){
            if(is_safari){
                return false;
            }
            sGlobals.isScrollingL = true;
            sGlobals.scrollTime = sGlobals.fastScroll;
        }
        bLeftArrow.onmouseup = function( ){
            if(is_safari){
                return false;
            }
            sGlobals.isScrollingL = true;
            sGlobals.scrollTime = sGlobals.slowScroll;
            return false;
        }
        bLeftArrow.onclick = function( ){ return false }


        bRightArrow.onmouseover = function( ){
            sGlobals.isScrollingR = true;
            sGlobals.scrollTime = sGlobals.slowScroll;
            bScrollRight( );
        }
        bRightArrow.onmouseout = function( ){
            sGlobals.isScrollingR = false;
            sGlobals.scrollTime = sGlobals.slowScroll;
        }
        bRightArrow.onmousedown = function( ){
            if(is_safari){
                return false;
            }
            sGlobals.isScrollingR = true;
            sGlobals.scrollTime = sGlobals.fastScroll;
        }
        bRightArrow.onmouseup = function( ){
            if(is_safari){
                return false;
            }

            sGlobals.isScrollingR = true;
            sGlobals.scrollTime = sGlobals.slowScroll;
            return false;
        }
        bRightArrow.onclick = function( ){ return false }
    }


    //gallery caption box, onclick/contextmenu on the image will open it, click x will close it
    var gDisplayCloseBox = document.getElementById('gDisplayCloseBox');
    var gDisplayImage = document.getElementById('gDisplayImage');

    var gDisplayImageCaption = document.getElementById('gDisplayImageCaption');

    if(gDisplayImageCaption && gDisplayCloseBox && gDisplayImage){
        gDisplayImageCaption.style.opacity = '.65';
        if(document.all){
            gDisplayImageCaption.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=65)";
        }

        gDisplayImage.onclick = function( ){
            globals['dImageDir'] = 1;
            captionBoxRun( );
            return false;
        }
        gDisplayCloseBox.onclick = function( ){
            globals['dImageDir'] = -1;
            captionBoxRun( );
            return false;
        }
    }

    var navBack = document.getElementById('navBack');
    var navForward = document.getElementById('navForward');
    if(navBack && navForward && navHistory){
        if(curNavPoint == 0){ navBack.className = "navBackDisabled"; }
        else{ navBack.className = "navBack"; }

        if(curNavPoint == navHistory.length - 1){ navForward.className = "navForwardDisabled"; }
        else{ navForward.className = "navForward"; }
    }

    //init the thumbnails in bottom base
    if(bbc && bBaseGallery){
        var aS = bbc.getElementsByTagName('a');
        var span1, span2, span3;

        for(i = 0; i < aS.length; i++){
            span1 = document.createElement('span');
            span1.className = 'tpMiddle';
            span2 = document.createElement('span');
            span2.className = 'tpLeft';
            span3 = document.createElement('span');
            span3.className = 'tpRight';

            if(document.insertAdjacentElement){
                aS[i].insertAdjacentElement("beforeEnd", span1);
                aS[i].insertAdjacentElement("beforeEnd", span2);
                aS[i].insertAdjacentElement("beforeEnd", span3);
            }
            else{
                aS[i].appendChild(span1);
                aS[i].appendChild(span2);
                aS[i].appendChild(span3);
            }
        }
    }

}

function captionBoxRun( ){
    var gDisplayImageCaption = document.getElementById('gDisplayImageCaption');
    var alpha = parseInt(gDisplayImageCaption.style.opacity * 100)

    if(alpha > 0 && globals['dImageDir'] < 0){
        var newAlpha = alpha - 5;
        gDisplayImageCaption.style.opacity = (newAlpha)/100;

        if(document.all){
            gDisplayImageCaption.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + newAlpha + ")";
        }
        setTimeout('captionBoxRun( )', 50);
    }
    else if(alpha < 65 && globals['dImageDir'] > 0){
        var newAlpha = alpha + 5;
        gDisplayImageCaption.style.opacity = (newAlpha)/100;

         gDisplayImageCaption.style.display = 'block';

        if(document.all){
            gDisplayImageCaption.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + newAlpha + ")";
        }
        setTimeout('captionBoxRun( )', 50);
    }
    else if(alpha <= 0){
        gDisplayImageCaption.style.display = 'none';
    }
}

function initImgRotator( ){
    var jsIR = document.getElementById('jsImgRotate');
    if(!jsIR || !imgRotatorA){
        return;
    }

    jsIR.innerHTML = "";
    jsIR.curImg = -1;
    jsIR.lastImg = null;

    for(var i = 0; i < imgRotatorA.length; i++){
        var iObj = imgRotatorA[i];
        var gid = iObj.gid;
        var imgName = iObj.imgName;
        var pid = iObj.pid;
        var fullImg = iObj.fullImg;

        var img = document.createElement('img');

        img.srcStr = imgName;
        img.src = "/uimages/" + imgName

        img.gid = gid;
        img.pid = pid;
        img.fullImg = fullImg;

        img.className = 'noAJAX';

        jsIR.appendChild(img);

        if(img.complete == null){
            //safari needs to fix these little issues.
            img.complete = true;
            img.style.width = "290px";
            img.style.height = "200px";
        }

        img.style.opacity = 0;
        if(document.all){
            img.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
        }

        img.onclick = function( ){
            var anch = this.srcStr.replace(/\./, "_");

            var gHREF = "/content/?gid=" + this.gid + "&img=" + this.fullImg;

            if(ajaxEnabled){
                gHREF += "&xmlOnly=1";
                b_xml.request(gHREF);
            }
            else{
                window.location = gHREF;
            }
        }
    }

    if(!imgRotatorThinking){
        //alert('init think');
        imgRotatorThink( );
    }
    /*else{
        alert('already thinking');
    }*/
}

function imgRotatorThink( ){
    var jsIR = document.getElementById('jsImgRotate');

    if(!jsIR || !imgRotatorA){
        return;
    }

    //alert("cur" + jsIR.curImg);
    //alert("last" + jsIR.lastImg);
    //alert(jsIR.innerHTML);
    if(jsIR.curImg >= 0){
        jsIR.lastImg = jsIR.curImg;
    }
    jsIR.curImg++;
    if(jsIR.curImg >= imgRotatorA.length){
        jsIR.curImg = 0;
    }

    var jsImages = jsIR.getElementsByTagName('img');
    var curImgObj = jsImages[jsIR.curImg];

    if(!curImgObj){
        return;
    }

    if(curImgObj.complete){
        curImgObj.style.opacity = 0;
        if(document.all){
            curImgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
        }
        curImgObj.style.visibility = 'visible';
        //alert('initchange');
        imgRotatorChange( );
    }
    else{
       imgRotatorWait( );
    }
}

function imgRotatorChange( ){
    var jsIR = document.getElementById('jsImgRotate');
    var jsImages = jsIR.getElementsByTagName('img');

    if(jsIR.curImg < 0){
        jsIR.curImg = 0;
    }

    var curImgObj = jsImages[jsIR.curImg];
    var lastImgObj = null;

    if(!curImgObj){
        return;
    }

    if(jsIR.lastImg >= 0){
        lastImgObj = jsImages[jsIR.lastImg];
    }

    var alphaInc = 5;
    var speed = 80;

    var curAlpha = parseInt(curImgObj.style.opacity * 100);
    var newAlpha = curAlpha + alphaInc;

    if(newAlpha >= 100){
        newAlpha = 100;
    }

    curImgObj.style.opacity = newAlpha / 100;

    if(document.all){
        curImgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + newAlpha + ")";
    }

    if(lastImgObj){
        var lastAlpha = parseInt(lastImgObj.style.opacity * 100);
        var newLastAlpha = lastAlpha - alphaInc;

        if(lastAlpha <= 0){
            newLastAlpha = 0;
            lastImgObj.style.visibility = "hidden";
        }
        lastImgObj.style.opacity = newLastAlpha / 100;
        if(document.all){
            lastImgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + newLastAlpha + ")";
        }
    }

    if(newAlpha >= 100){
        if(lastImgObj){
            lastImgObj.style.visibility = "hidden";
        }
        //alert('think');
        imgRotatorThinking = true;
        setTimeout('imgRotatorThink( )', 3000);
    }
    else{
        setTimeout('imgRotatorChange( )', speed);
    }
}
function imgRotatorWait( ){
    var jsIR = document.getElementById('jsImgRotate');
    var jsImages = jsIR.getElementsByTagName('img');
    var curImgObj = jsImages[jsIR.curImg];
    var lastImgObj = jsImages[jsIR.lastImg];

    if(!curImgObj){
       return;
    }

    if(curImgObj.complete){
        curImgObj.style.opacity = 0;
        if(document.all){
            curImgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
        }
        curImgObj.style.visibility = 'visible';

        imgRotatorChange( );
    }
    else{
       setTimeout('imgRotatorWait( )', 50);
    }
}


function appThink( ){
    if(document.getElementById('bottomBaseContainer')){
        var bbc = document.getElementById('bottomBase');

        var bLeftArrow = document.getElementById('bLeftArrow');
        var bRightArrow = document.getElementById('bRightArrow');

        //alert(bbc.offsetWidth);
        //alert(bbc.clientWidth);
        //alert(bbc.scrollWidth);
//*
        if(bbc.clientWidth < bbc.scrollWidth && bRightArrow.style.display != 'block'){
            bLeftArrow.style.display = "block";
            bRightArrow.style.display = "block";

            bLeftArrow.style.opacity = 1;
            bRightArrow.style.opacity = 1;
        }
        else if(bbc.clientWidth >= bbc.scrollWidth){
            bLeftArrow.style.display = "none";
            bRightArrow.style.display = "none";
            bbc.scrollLeft = 0;
        }
        else if(bbc.scrollWidth < bbc.scrollLeft){
            bbc.scrollLeft = 0;
        }

        //else if(bbc.style.left != "0px"){
        //    bbc.style.left = "0px";
        //}
// */
    }

//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 != '/'){
            newHREF = ieHistoryHack.document.body.innerHTML;
            didIE = true;
        //}
    }

    newHREF = newHREF.replace(/^(http(s)?\:\/\/)([^\/]+)/, '');

    var tHREF = newHREF;

    newHREF = newHREF.replace(/(\/\#)/, '');

    //replace the & characters for ie :P
    newHREF = newHREF.replace(/(\&amp\;)/g, '&');

    //if(recursionCount < 10){
    //    alert(newHREF + ' - ' + currentLocation + ' - ' + windowHREF);
    //    recursionCount++;
    //}

/*
    //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 + ' - ' + tHREF + ' - ' + ' - ' + 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);
}

//bottomBase scroll (-n goes left, +n goes right)
//(to the user it's the other way around -1 pushes <---, 1 pushes ---->)
function bottomBaseScroll(direction){

    var bbc = document.getElementById('bottomBase');
    var clientW = bbc.clientWidth;
    var scrollW = bbc.scrollWidth;
    var currentPos = bbc.scrollLeft;


    if(isNaN(currentPos)){
        currentPos = 0;
    }

    var newPos = currentPos;

    if(direction > 0){
        if(currentPos + direction > (scrollW - clientW)){
            newPos = scrollW - clientW;
        }
        else{
            newPos += direction;
        }
    }
    else if(direction < 0){
        if(scrollW + direction < 0){
            newPos = 0
        }
        else{
            newPos += direction;
        }
    }

    bbc.scrollLeft = newPos;
}

function captureScroll(e){
    //alert(e.detail);
    var direction = e.detail;
    if(direction < 0){
        bottomBaseScroll(-1 * sGlobals.bScrollAmount * 2);
    }
    else{
        bottomBaseScroll(sGlobals.bScrollAmount * 2);
    }

    e.stopPropagation( );
    e.preventDefault( );
}

//Cool input effects
function inputOver(e){
    this.className = "button buttonOver";
}

function inputOut(e){
    this.className = "button";
}

//Popups
function generalPopUp(loc, w, h){
    gPopUp = window.open(loc, "gpopup", "width=" + w + ",height=" + h + ", scrollbars=1, status=no,toolbar=no,resizable=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=480, 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=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

function openFUploader( ){
    var imgSelectPopUp = window.open("./fileselect.php", "FileSelector", "width=780,height=480, 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( ){
    if(window.isOldIE || window.isNewIE){
        var mbar = document.getElementById('menubar');
        mbar.innerHTML = '<span style="display: inline-block; clear: both;">' + mbar.innerHTML + '</span>';
    }

    var hmenu = document.getElementById('tmenu');
    if(!hmenu){
        return;
    }

    var liA = hmenu.getElementsByTagName('li')
    var len = liA.length;

    for(var i = 0; i < len; i++){
        var li = liA[i];
        if(bgzDDEnabled){
            li.bgzdd = new bgzDropDown( );
            var ul = li.getElementsByTagName('ul')[0];
            if(ul){
                li.bgzdd.init(li, ul, 'down');
            }
        }
        else{
            li.onmouseover = pageON;
            li.onmouseout = pageOFF;
        }
    }
}
function initLeftMenuLinks( ){
    var dleftmenu = document.getElementById('dleftmenu');
    var liA = dleftmenu.getElementsByTagName('li')
    var len = liA.length;

    for(var i = 0; i < len; i++){
        var li = liA[i];
        if(bgzDDEnabled){
            li.bgzdd = new bgzDropDown( );
            var ul = li.getElementsByTagName('ul')[0];
            if(ul){
                li.bgzdd.init(li, ul, 'right');
            }
        }
        else{
            li.onmouseover = pageON;
            li.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 printView(plink) {
    var plink2 = "/print/p/" + plink;
    window.open(plink2, "ShoppingList", "width=620,height=400,status=yes,toolbar=no,resizable=yes,raised=yes,scrollbars=yes");
}

function printPage(buttonID) {
    var printButton = document.getElementById(buttonID);
    printButton.style.visibility = "hidden";
    window.print();
    window.close();
}

var ipreviewWin = null;
function ipreview(lnk){
    ipreviewWin = window.open(lnk, "ipreviewWin", "width=780,height=480, menubar=yes, location=yes, scrollbars=yes, status=yes,toolbar=yes,resizable=yes");
    ipreviewWin.focus( );
    return false;
}

//category function
function lCategoryPopup(pwinvar){
    lCatPopUp = window.open("/include/category.php?lckey=" + pwinvar, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function lCategoryPopupA(pwinvar){
    lCatPopUp = window.open("/include/category2.php?lckey=" + pwinvar, "CategorySelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function lClassifiedPopup(pwinvar){
    lCatPopUp = window.open("/include/classified.php?lckey=" + pwinvar, "ClassifiedSelect", "width=780,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    lCatPopUp.focus( );
}
function wsbPopup(loc){
    lCatPopUp = window.open(loc, "wsb", "width=782,height=480, menubar=yes, location=yes, scrollbars=yes, status=yes,toolbar=yes,resizable=yes");
    lCatPopUp.focus( );
}

function whatisPopup(loc){
    whatisPopUp = window.open(loc, "whatis", "width=300,height=300, menubar=no, location=no, scrollbars=yes, status=no,toolbar=no,resizable=yes");
    whatisPopUp.focus( );
}

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;
        }
    }
}

function optionInfoPopUp(povar){
    poInfoPopUp = window.open("/view_poption.php?poid=" + povar, "ProductOptionInfo", "width=500,height=480, scrollbars=yes, status=yes,toolbar=no,resizable=yes");
    poInfoPopUp.focus( );

    var winX = screen.width/2 - 500/2;
    var winY = screen.height/2 - 480/2;

    poInfoPopUp.moveTo(winX, winY)
}

function priceChk(rID, rClass, poiID, poiClass, poiPrice, newImg){
    var poiID = document.getElementById(poiID);
    var poiSpan = poiID.getElementsByTagName("span");
    var mainPrice = poiPrice;

    //update subtotal
    var radioID = document.getElementById(rID);
    var oldTotal = document.getElementById("total_price").innerHTML;
    var diff = poiSpan[0].innerHTML.replace(/\$/, "");

    var newTotal = parseFloat(oldTotal) + parseFloat(diff);
    var newTotal = newTotal.toFixed(2);
    document.getElementById("total_price").innerHTML = newTotal;

    inputs = document.getElementsByTagName("input");
    for(var z = 0; z < inputs.length; z++){
        var tmpin = inputs[z];
        if(tmpin.className == rClass){
            if(tmpin.id != radioID.id){
                //enable radio where it needs to be
                tmpin.disabled = false;
            }
            else{
                //disable radio so they can't keep clicking on it
                radioID.disabled = true;
            }
        }
    }
    spans = document.getElementsByTagName("span");
    for(var j = 0; j < spans.length; j++){
        var pois = spans[j];
        if(pois.className == poiClass){
            if(pois.id != poiID.id){
                //make sure everything is visibile where it needs to be
                pois.style.visibility = "visible";
                poiprices = pois.getElementsByTagName("span");

                for(var k = 0; k < poiprices.length; k++){
                    var prices = poiprices[k];
                    var pricesC = prices.className;

                    var otherPrice = pricesC.replace(/poi\_/, "");
                    var otherPrice = otherPrice.replace(/\_/, ".");

                    var totalp = otherPrice - mainPrice;
                    var total = totalp.toFixed(2);

                    if(total.match(/\-/)){
                        prices.innerHTML = total.replace(/\-/, "-$");
                    }
                    else{
                        //update prices
                        prices.innerHTML = "+$" + total;
                    }
                }
            }
            else{
                //hide the price
                poiID.style.visibility = "hidden";
            }
        }
    }

    if(newImg){
        var rcl1 = rClass.replace(/po/, "");
        var tmpid = rcl1.replace(/_radio/, "");
        var imgid = "img_" + tmpid;
        var img = document.getElementById(imgid);
        img.src = newImg;
    }
}

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));
}

function loadGoogleMaps( ){
    if(GBrowserIsCompatible( )){
        maps = document.getElementsByTagName("div");

        for(var i = 0; i < maps.length; i++){
            var curMap = maps[i];
            if(curMap.id == "googleMap"){
                var coords = curMap.innerHTML;
                coords = coords.split(",");


                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(),"<div style=\"color: #000000;\"><strong>Bruwer Saddlebreds</strong><br />2200 Route 47<br />Yorkville, IL 60560<br />(630) 553-8299</div>");
                //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 checkShippingInfo() {
	var check_box = document.form.sSameAsBilling;
	if (check_box.checked) {
		document.form.sStreet1.disabled = true;
		document.form.sStreet2.disabled = true;
		document.form.sCity.disabled = true;
		document.form.sState.disabled = true;
		document.form.sZIP.disabled = true;
		document.form.sStreet1.style.backgroundColor = "#FAFAFA";
		document.form.sStreet2.style.backgroundColor = "#FAFAFA";
		document.form.sCity.style.backgroundColor = "#FAFAFA";
		document.form.sState.style.backgroundColor = "#FAFAFA";
		document.form.sZIP.style.backgroundColor = "#FAFAFA";
	}
	else {
		document.form.sStreet1.disabled = false;
		document.form.sStreet2.disabled = false;
		document.form.sCity.disabled = false;
		document.form.sState.disabled = false;
		document.form.sZIP.disabled = false;
		document.form.sStreet1.style.backgroundColor = "";
		document.form.sStreet2.style.backgroundColor = "";
		document.form.sCity.style.backgroundColor = "";
	    document.form.sState.style.backgroundColor = "";
		document.form.sZIP.style.backgroundColor = "";
    }
}

function personalizedProduct(inputField, optionCost, charCost, maxChar){
    var diff = 0;

    //alert("fieldLen " + fieldLen);
    //alert("inputField " + inputField.value.length);
    if(fieldLen > inputField.value.length){
        diff = (inputField.value.length - fieldLen) * charCost;

        if(inputField.value.length <= 0 && optionCost != 0){
            diff = diff - optionCost;
        }
    }
    else if(fieldLen < inputField.value.length){
        diff = (inputField.value.length - fieldLen) * charCost;

        if((inputField.value.length == 1 || (fieldLen == 0 && inputField.value.length > 0)) && optionCost != 0){
            diff = diff + optionCost;
        }
    }

    //alert(diff);

    fieldLen = inputField.value.length;

    var inputVal = inputField.value;
    if(inputVal.length > maxChar){
        inputField.value = inputVal.substring(0, maxChar);
    }
    else if(inputVal != "" || (inputVal == "" && diff != 0)){

        var oldTotal = document.getElementById("total_price").innerHTML;

        var newTotal = parseFloat(oldTotal) + parseFloat(diff);
        var newTotal = newTotal.toFixed(2);
        document.getElementById("total_price").innerHTML = newTotal;
    }

}
function loadGalleryImage(gID, imgID, imgSrc, imgWidth){
    var prodImgC = document.getElementById("prodImgContain");
    var prodImg = prodImgC.getElementsByTagName("img");

    if(prodImg.length == 0){
        return;
    }

    var newSrc = "/uimages/" + imgSrc;

    prodImg[0].src = newSrc;

    if(imgWidth > 275){
        prodImg[0].width = 275;
    }
    else{
        prodImg[0].width = imgWidth;
    }

    if(is_safari){
        generalPopUp('/view_image.php?gid=' + gID + '&img=' + imgSrc, 400, 400);
        //redir ie: /gimgid/123/The_Pink_Pillow
        /*var curLoc = new String(window.location);

        if(curLoc.match(/gimgid\/\d/)){
            alert(imgID);
            newLoc = curLoc.replace(/gimgid\/\d+/, "gimgid/" + imgID);
            alert(newLoc);
        }
        else{
            var curLocA = curLoc.split("/");
            var curLocALen = curLocA.length;
            var n = curLocALen - 1;

            var newLoc = '';
            for(i = 0; i < curLocALen; i++){
                if(i > 0){
                    newLoc = newLoc + "/";
                }
                if(i == n){
                    newLoc = newLoc + "gimgid/" + imgID + "/";
                }

                newLoc = newLoc + curLocA[i];
            }
        }

        var tlen = window.history.length + 1;
        if(window.fakeHistory == undefined){
            window.fakeHistory = new Array( );
        }

        currentLocation = newLoc;

        if(newLoc.match(/\?/)){
            newLoc += "&xmlOnly=1";
        }
        else{
            newLoc += "?xmlOnly=1";
        }

        window.fakeHistory[tlen] = newLoc;
        b_xml.request(newLoc);

        alert(newLoc);
        window.location = newLoc;*/
    }
}

function initProductRotator( ){
    var prodContainer = document.getElementById('homeFeaturedProperties');
    var subProdContainer = document.getElementById('homeFeaturedProps');

    if(!prodContainer || !subProdContainer){
        return;
    }

    var subProds = subProdContainer.getElementsByTagName('td');
    var subProdLen = subProds.length;

    if(document.getElementById("hnpm_0_pr")){
        Product = document.getElementById("hnpm_0_pr");
        Product.id = "hnpm_0";
    }
    else{
        Product = document.getElementById("hnpm_0");
    }

    if(!Product){
        return;
    }

    stopProdRotator = false;

    var ProdAnchor = Product.getElementsByTagName('a')[0];

    var ProdOnclick = new String(ProdAnchor.getAttribute('onclick'));

    var ProdInfo = ProdOnclick.replace("prodRotatorThink('", "");
    var ProdInfo = ProdInfo.replace("');", "");
    var ProdInfo = ProdInfo.replace("return false;", "");

    var ProdA = ProdInfo.split("', '");

    var nextID = ProdA[0];
    if(document.all){
        nextID = nextID.replace(/[^0-9]/g, '');
    }

    var nextPGID = ProdA[1];
    var nextPID = ProdA[2];
    var nextImgLoc = ProdA[3];
    var nextProdName = ProdA[4];
    var nextProdDesc = ProdA[5];

    //alert("prodRotatorThink(" + nextID + ", " + nextPGID + ", " + nextPID + ", " + nextImgLoc + ", " + nextProdName + ", " + nextProdDesc + ");");
    prodRotatorThink(nextID, nextPGID, nextPID, nextImgLoc, nextProdName, nextProdDesc);
}

function prodRotatorThink(pIndex, pgid, pid, imgLoc, prodName, prodDesc, origin){
    if(origin == 'click'){
        stopProdRotator = true;
        prodRotatorChange(pIndex, pgid, pid, imgLoc, prodName, prodDesc)
    }
    else if(!stopProdRotator && origin != 'click'){
        prodRotatorChange(pIndex, pgid, pid, imgLoc, prodName, prodDesc);
    }
}

function prodRotatorChange(pIndex, pgid, pid, imgLoc, prodName, prodDesc){
    //alert('change');
    var mainProd = document.getElementById('homeFeaturedImg');
    //var mainProdDesc = document.getElementById('homeFeaturedDesc');
    //var mainProdLnk = document.getElementById('mainHomeProdLnk');

    var subProdContainer = document.getElementById('homeFeaturedProps');

    if(!mainProd){
        return;
    }

    //mainProdDesc.innerHTML = stripslashes(prodDesc);


    var newLnk = "/content/p/" + pgid + "/pid/" + pid;
    //mainProdLnk.setAttribute('href', newLnk);


    var mainImgLnk = mainProd.getElementsByTagName("a")[0];
    mainImgLnk.setAttribute('href', newLnk);
    mainImgLnk.setAttribute('title', prodName);
    mainImgLnk.setAttribute('name', prodName);

    var mainProdImg = mainProd.getElementsByTagName("img")[0];
    mainProdImg.src = "/uimages/" + imgLoc;
    mainProdImg.setAttribute('alt', prodName);
    mainProdImg.setAttribute('title', prodName);

    var subProds = subProdContainer.getElementsByTagName('td');
    var subProdLen = subProds.length;

    for(i = 0; i < subProdLen; i++){
        //hnpm_#index#
        var curSubProd = subProds[i];

        if(curSubProd.className == 'hnpm_spacer'){
            continue;
        }

        var curSubProdId = curSubProd.id;
        var indexA = curSubProdId.split('_');
        var curIndex = indexA[1];

        var subProd = document.getElementById(curSubProdId);
        var subProdImg = subProd.getElementsByTagName('img')[0];

        if(curIndex == pIndex){
            subProdImg.style.border = "1px solid #88A0BB";

            //protect this from borderChange!
            if(!subProd.id.match('_pr')){
                subProd.id = subProd.id + "_pr";
            }
        }
        else{
            subProdImg.style.border = "1px solid #000000";

            //unprotect the rest
            subProd.id = subProd.id.replace('_pr', '');
        }
    }

    if(!stopProdRotator){
        //next up - this could get messy
        if(parseInt(pIndex) + 2 > subProdLen){
            var nextIndex = 0;
        }
        else{
            var nextIndex =  parseInt(pIndex) + 1;
        }

        var nextProdID = "hnpm_" + nextIndex;

        var nextProduct = document.getElementById(nextProdID);
        if(!nextProduct || nextProduct.className == 'hnpm_spacer'){
            nextIndex = 0;
            nextProduct = document.getElementById("hnpm_" + nextIndex);
        }

        var nextProdAnchor = nextProduct.getElementsByTagName('a')[0];

        var nextProdOnclick = new String(nextProdAnchor.getAttribute('onclick'));

        var nextProdInfo = nextProdOnclick.replace("prodRotatorThink('", "");
        var nextProdInfo = nextProdInfo.replace("');", "");
        var nextProdInfo = nextProdInfo.replace("return false;", "");

        //must split at the single quote so we don't split the desc
        var nextProdA = nextProdInfo.split("', '");
        //alert(nextProdA);

        var nextID = nextProdA[0];
        if(document.all){
            nextID = nextID.replace(/[^0-9]/g, '');
        }
        var nextPGID = nextProdA[1];
        var nextPID = nextProdA[2];
        var nextImgLoc = nextProdA[3];
        var nextProdName = nextProdA[4];
        var nextProdDesc = nextProdA[5];

        //alert("prodRotatorThink('" + nextID + "', '" + nextPGID + "', '" + nextPID + "', '" + nextImgLoc + "', '" + nextProdName + "', '" + nextProdDesc + "');");
        setTimeout("prodRotatorThink('" + nextID + "', '" + nextPGID + "', '" + nextPID + "', '" + nextImgLoc + "', '" + nextProdName + "', '" + nextProdDesc + "');", 5000);
    }
}

function changeBorder(elementID, bSize, bColor){
    var bElement = document.getElementById(elementID);

    if(!bElement){
        return;
    }

    if(bColor.match('#')){
        var colorCode = bColor.replace('#', '');
        bColor = convert2RGB(colorCode);
    }

    if(bElement.style.borderTopColor != bColor){
        bElement.style.border = bSize + " solid " + bColor;
    }
}

function convert2RGB(color) {
    var rgb1 = parseInt(color.substr(0, 2), 16);
    var rgb2 = parseInt(color.substr(2, 2), 16);
    var rgb3 = parseInt(color.substr(4, 2), 16);

    return "rgb(" + rgb1 + ", " + rgb2 + ", " + rgb3 + ")";
}

function addslashes(str){
    str = str.replace(/\'/g, '\\\'');
    str = str.replace(/\"/g, '\\"');
    str = str.replace(/\\/g, '\\\\');
    str = str.replace(/\0/g, '\\0');
    return str;
}

function stripslashes(str){
    str=str.replace(/\\'/g, '\'');
    str=str.replace(/\\"/g, '"');
    str=str.replace(/\\\\/g, '\\');
    str=str.replace(/\\0/g, '\0');
    return str;
}

function balanceColumns( ){
    //hack job through and through

    var content = document.getElementById('content');
    var leftColumn = document.getElementById('columnLeft');

    var cdA = content.getElementsByTagName('div');
    var cdaLen = cdA.length;

    for(i = 0; i < cdaLen; i++){
        var curDiv = cdA[i];

        if(curDiv.className.match('contentText')){
            var ctDiv = curDiv;
            break;
        }
    }

    if(!ctDiv){
        return;
    }

    var contentHeight = document.getElementById('contentTextContainer').clientHeight;
    var leftColumnHeight = leftColumn.clientHeight;
    var footerHeight = document.getElementById('footer').clientHeight;

    //alert("contentText: " + contentHeight);
    //alert("leftColumn: " + leftColumnHeight);

    if(contentHeight > leftColumnHeight){
        if(ctDiv.className != 'contentTextNP0'){
            if(document.all){
                document.getElementById('columnLeft').style.height = (contentHeight + 2) + 'px';
            }
            else{
                document.getElementById('columnLeft').style.height = contentHeight + 'px';
            }
        }
        else{
            document.getElementById('columnLeft').style.height = (contentHeight - 8) + 'px';
            document.getElementById('content').style.height = (contentHeight - 8) + 'px';
        }
    }
    else{
        document.getElementById('columnLeft').style.height = '';
        document.getElementById('content').style.height = '';
    }
}

/* GOOGLE MAPS */
function loadGoogleMaps( ){
    if(GBrowserIsCompatible( )){
        maps = document.getElementsByTagName("div");

        for(var i = 0; i < maps.length; i++){
            var curMap = maps[i];
            if(curMap.id == "googleMap"){
                var coords = curMap.innerHTML;

                if(coords.match(/address\:/g)){
                    var address = coords.replace(/address\:/, '');
                    markAddress(address, curMap);
                }
                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){
    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);
                marker.openInfoWindowHtml("<div style=\"line-height: 1.2em; font-size: .9em\">The Law Office of James E. Novak<br />4500 South Lakeshore Drive<br />Tempe, Arizona 85282</div>");
            }
        }
    );

}

function popupDirections( ){
    var dirDiv = document.getElementById('drivingDirections');
    var dirA = document.getElementById('ddAddress');

    if(!dirDiv || !dirA){
        return;
    }

    var winLoc = dirA.getAttribute('href')

    drivingDirections = window.open(winLoc, "DrivingDirections", "menubar=yes,scrollbars=1,status=yes,toolbar=yes,resizable=yes");
    drivingDirections.focus( );
}
/* END GOOGLE MAPS */