/* #################################################################
Copyright © 2008 BBB Systems, LLC, All rights reserved
################################################################## */

var sGlobals = new Object( );
sGlobals.bScrollAmount = 10;
sGlobals.slowScroll = 65;
sGlobals.fastScroll = 25;
sGlobals.isScrollingR = false;
sGlobals.isScrollingL = false;
var is_safari = (document.childNodes)&&(!document.all)&&(!navigator.taintEnabled)&&(!navigator.accentColorName)?true:false;

var navHistory = new Array( );
var curNavPoint = -1;

var globals = new Array( );

var ajaxEnabled = false;
var bgzDDEnabled = true;

var stopProdRotator = false;
var allowedPRIndex = 1;

//format: html_id > type
var ajaxTabList = new Array( );

//don't forget to update the number in the loop
for(var i = 0; i < 2; i++){ ajaxTabList[i] = new Object( ); }
ajaxTabList[0].html_id = 'dirTabs';
ajaxTabList[0].ajax_type = 'dir';
ajaxTabList[1].html_id = 'pageTabs';
ajaxTabList[1].ajax_type = 'page';

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.
    }

    if(ajaxEnabled){
        ajaxCheck( );
    }

    initTopMenuLinks( );
    initInputButtons( );

    initDirPhoneNumbers( );

    initA( );

    initEditors( );

    initSearchBObjects( );
    initObjects( );
    initAppObjects( );

    initListingGallery( );
    resizeOverlay( );

    //loadCufonFonts( );

    //appThink( );

    if(window.load_maps){
        loadGoogleMaps( );
    }

    window.onresize = resizeOverlay;
}

window.xmlInit = function( ){
    initCalendarNav( );
    initAjaxTabs( );
    initObjects( );
    initListingGallery( );
    resizeOverlay( );

    if(window.load_maps){
        loadGoogleMaps( );
    }
}

function initDirPhoneNumbers( ){
    var l_divs = document.getElementsByTagName('div');

    for(var i = 0; i < l_divs.length; i++){
        l_div = l_divs[i];

        if(l_div.className == 'l_phone_div'){
            var l_span = l_div.getElementsByTagName('span')[0];
            var l_inputs = l_div.getElementsByTagName('input');
            var l_phone = l_inputs[0];
            var l_id = l_inputs[1];

            l_span.phone_number = l_phone.value;
            l_span.listing_id = l_id.value;

            l_span.onclick = function( ){
                this.innerHTML = this.phone_number;
                this.style.cursor = 'default';

                if(b_xml.isCurrentRequest){ return false; }//this shouldn't ever happen on this page.

                var newHREF = '/phone_click.php?lid=' + this.listing_id;
                b_xml.request(newHREF);
                if(b_xml.isSupported){ return false; }

                this.onclick = null;//only click once

                return true;
            }
        }
    }
}

function initInputButtons( ){
    if(document.getElementsByTagName){
        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"){
                /* not quite standardized yet, so apply them with javascript */
                inputs[i].style.borderRadius = '5px';
                inputs[i].style.MozBorderRadius = '5px';
                inputs[i].style.WebkitBorderRadius = '5px';

                inputs[i].onmouseover = function( ){ this.className = 'buttonOver'; }
                inputs[i].onmouseout = function( ){ this.className = 'button'; }
            }
            else if(window.ActiveXObject && (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')){
                inputs[i].style.border = '0px solid #ffffff';
                inputs[i].style.backgroundColor = 'transparent';
            }
        }
    }
}

//val = the block number, mode = (1|0 -> open|closed)
function setBlockControls(val, mode){
    var bk_cookie = getCookie('bk_cookie');

    if(!bk_cookie){
        setCookie('bk_cookie', '');
        bk_cookie = '';
    }


    var bkA = bk_cookie.split(/\,/);

    var found = false;
    var newCookieStr = '';

    for(i = 0; i < bkA.length; i++){
        var bk = bkA[i];

        if(bk == val){
            found = true;

            if(mode == 0){
                continue;
            }
        }

        if(newCookieStr != ''){
            newCookieStr += ',';
        }
        newCookieStr += bk;
    }

    if(!found && mode == 1){
        if(newCookieStr != ''){
            newCookieStr += ',';
        }

        newCookieStr += val;
    }

    setCookie('bk_cookie', newCookieStr);
}

function initA( ){
    if(document.getElementsByTagName){
        var as = document.getElementsByTagName("a");
        for(var i = 0; i < as.length; i++){

            var hostnm = as[i].href.replace(/http(s)?\:\/\//, "");
            hostnm = hostnm.replace(/\/.*/, "");

            var chostname = window.location.hostname.toString( );

            if( chostname.match(/bbbsystems/) && (hostnm != window.location.hostname || as[i].href.match(/\/ad\.\php\?/) || as[i].href.match(/\/ldir\.\php\?/)) ){
                if(!as[i].target){
                    as[i].target = "_blank";
                    continue;
                }
            }

            if(ajaxEnabled){
                if(b_xml){
                    as[i].onclick = function( ){
                        var newHREF = this.href;

                        if(newHREF.match(/\?/)){
                            newHREF += "&xmlOnly=1";
                        }
                        else{
                            newHREF += "?xmlOnly=1";
                        }

                        if(newHREF == navHistory[curNavPoint]){
                            return false;
                        }

                        for(var i = navHistory.length - 1; i > curNavPoint; i--){
                            navHistory.pop( );
                        }

                        curNavPoint += 1;
                        navHistory.push(newHREF);

                        b_xml.request(newHREF);

                        if(b_xml.isSupported){
                            return false;
                        }
                        return true;
                    }
                }
            }
        }

        initAjaxContentA( );

        initAjaxTabs( );
        initCalendarNav( );
    }
}

function initEditors( ){
    var t_areaA = document.getElementsByTagName('textarea');
    var bgzObj = null;
    for(var i = 0; i < t_areaA.length; i++){
        var t_area = t_areaA[i];
        if(t_area.className == 'bgz_input'){
            var base_id = t_area.id.replace(/^bgz_input_/gi, '');
            buildEditor(base_id);
        }
    }
    bgzObj = null;
}

function initObjects( ){
    if(document.getElementsByTagName){
        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';
                        }

                        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';
                //alert(obj.innerHTML);
                obj.style.display = 'block';
                obj.className = 'bgzobject_loaded';
            }//end if bgzobject
        }
    }
}

function initSearchBObjects( ){
    var searchZipMiles = document.getElementById('searchZipMiles');
    var searchZipCode = document.getElementById('searchZipCode');
    var searchRefresh = document.getElementById('searchRefresh');

    if(!searchZipMiles || !searchZipCode || !searchRefresh){
        return;
    }

    searchZipMiles.onchange = function( ){
        var sval = this.options[this.selectedIndex].value;
        setCookie('searchZipMiles', sval);
        document.getElementById('searchRefresh').style.visibility = 'visible';
    }
    searchZipCode.onchange = function( ){
        setCookie('searchZipCode', this.value);
        document.getElementById('searchRefresh').style.visibility = 'visible';
    }

    searchRefresh.onclick = function( ){
        window.location.reload( false );
    }
}

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 img = document.createElement('img');

        img.srcStr = imgName;
        img.src = "/uimages/" + imgName

        img.gid = gid;

        jsIR.appendChild(img);

        if(img.complete == null){
            //safari needs to fix these little issues.
            img.complete = true;
            img.style.width = "211px";
            img.style.height = "200px";
        }

        img.style.opacity = 0;
        if(document.all){
            img.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
        }

        img.onclick = function( ){
            var gHREF = "/content?gid=" + this.gid + "&img=" + this.srcStr;

            if(ajaxEnabled){
                gHREF += "&xmlOnly=1";
                b_xml.request(gHREF);
            }
            else{
                window.location = gHREF;
            }
        }
    }


    imgRotatorThink( );
}

function imgRotatorThink( ){
    var jsIR = document.getElementById('jsImgRotate');
    if(!jsIR || !imgRotatorA){
        return;
    }

    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.complete){

        /*
        if(confirm('die now?')){
            alert(jsIR.curImg);
            alert(jsIR.lastImg);
            alert(jsIR.innerHTML);
            return;
        }
        */
        curImgObj.style.opacity = 0;
        if(document.all){
            curImgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
        }
        curImgObj.style.visibility = 'visible';
        imgRotatorChange( );
    }
    else{
       imgRotatorWait( );
    }
}

function imgRotatorChange( ){
    var jsIR = document.getElementById('jsImgRotate');
    var jsImages = jsIR.getElementsByTagName('img');
    var curImgObj = jsImages[jsIR.curImg];
    var lastImgObj = null;
    if(jsIR.lastImg){
        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";
        }
        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.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);
    }
}

//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");
    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 imageSelectPopUp2(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;
}

function classImageSelectPopUp(pwinvar, pimgvar){
    imgSelectPopUp = window.open("./c_imageselect.php?mode=1&fieldID=" + pwinvar + "&imgID=" + pimgvar, "ImageSelector", "width=780,height=480, scrollbars=0, status=no,toolbar=no,resizable=no");
    imgSelectPopUp.focus( );
}

//drop down menus ##################################################

function initTopMenuLinks( ){
    var tmenu = document.getElementById('tmenu');

    if(!tmenu || !bgzDDEnabled){
        return;
    }

    var td = tmenu.getElementsByTagName('td')[0]

    while(td){
        if(!td.tagName || td.tagName.toLowerCase( ) != 'td'){
            td = td.nextSibling;
            continue;
        }

        var tbl = td.getElementsByTagName('table')[0];
        if(tbl){
            //add fancy css
            var nav = navigator.userAgent.toLowerCase();
            var is_bad_chrome = false;
            if(nav.match(/\b(chrome)\b/)){ if(nav.match(/525\.1/)){ is_bad_chrome = true; } }
            if(!is_bad_chrome){
                tbl.style.MozBoxShadow = '#063c52 4px 4px 10px';
                tbl.style.WebkitBoxShadow = '#063c52 4px 4px 10px';
            }

            td.bgzdd = new bgzDropDown( );
            td.bgzdd.init(td, tbl, 'down');
        }
        td = td.nextSibling;
    }

    //multi-dro ... -moz-hack ... text cuts off
    var liA = tmenu.getElementsByTagName('li')
    var len = liA.length;
    for(var i = 0; i < len; i++){
        var a = liA[i].getElementsByTagName('a')[0];
        a.innerHTML = a.innerHTML + ' &nbsp';
    }

}

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');
            }
        }
    }
}

//############################################################

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){
    var dateNow = new Date( );
    var expire = new Date();
    expire.setTime(dateNow.getTime() + 7200000);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString( ) + ";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 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 changeImg(newImg, imgProps, comment){
    var mainImg = document.getElementById('mainImg');
    var imgComment = document.getElementById('imgComment');
    var prodImgLnk = document.getElementById('prodImgLnk');
    var prodImgEnlarge = document.getElementById('prodImgEnlarge');

    if(!mainImg){
        return;
    }

    var oldHeight = mainImg.height;

    mainImg.src = newImg;
    mainImg.setAttribute('style', imgProps + 'border: 0px solid #FFF;');

    if(document.all && imgProps != ''){
        var imgPropsA = imgProps.split('; ');

        var widthStr = imgPropsA[0];
        var widthStrA = widthStr.split(': ');

        var heightStr = imgPropsA[1];
        var heightStrA = heightStr.split(': ');

        var newWidth = widthStrA[1];
        var newHeight = heightStrA[1];

        newHeight = newHeight.replace(';', '');

        mainImg.style.width = newWidth;
        mainImg.style.height = newHeight;

        if(navigator.userAgent.match('MSIE 7')){
            //all for IE7
            var newHeight = mainImg.height;
            var heightDiff = newHeight - oldHeight;
            var oldCHeight = document.getElementById('content').clientHeight;
            var newCHeight = oldCHeight + heightDiff - 26;
            document.getElementById('content').style.height = newCHeight + 'px';
        }
    }

    if(imgComment && comment){
        imgComment.innerHTML = comment;
    }

   var imgName = newImg.replace(/\/uimages/, '');
    if(prodImgLnk){
        var pLnk = prodImgLnk.href.replace(/pimg\=.+/, 'pimg=' + imgName);
        prodImgLnk.href = pLnk;
    }

    if(prodImgEnlarge){
        var pLnk = prodImgEnlarge.href.replace(/pimg\=.+/, 'pimg=' + imgName);
        prodImgEnlarge.href = pLnk;
    }
}

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 hideFlash(skip){
    var flashObj = document.getElementById('hpFlash');
    var fpObj = document.getElementById('hfpMainC');
    var npObj = document.getElementById('hnProd');

    flashObj.style.display = 'none';
    flashObj.style.visibility = 'hidden';

    fpObj.style.display = 'inline';
    fpObj.style.visibility = 'visible';
    npObj.style.display = 'block';
    npObj.style.visibility = 'visible';

    //if(skip){
        setCookie('skipFlash', true);
    //}
}

function changeHomeImage(newImg, newProps, newDesc){
    var imgObj = document.getElementById('hfpMImg');
    var descObj = document.getElementById('hfpDesc');

    if(!imgObj || !descObj){
        return;
    }

    imgObj.src = newImg;
    descObj.innerHTML = newDesc;
    imgObj.setAttribute('style', newProps);

    if(document.all){
        var imgPropsA = newProps.split('; ');

        var widthStr = imgPropsA[0];
        var widthStrA = widthStr.split(': ');

        var heightStr = imgPropsA[1];
        var heightStrA = heightStr.split(': ');

        var newWidth = widthStrA[1];
        var newHeight = heightStrA[1];

        imgObj.style.width = newWidth;
        imgObj.style.height = newHeight;
    }
}

/* 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';
}

var map;
var myPano;
var panoClient;
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 map_inner = curMap.innerHTML;

                var address = map_inner.replace(/address\:/, '');

                var info = '';
                var eid = 0;
                if(address.match(/\|\|info\:/g)){
                    var addA = address.split('||');
                    address = addA[0];

                    var info = addA[1].replace(/info\:/, '');

                    if(addA[2]){
                        eid = addA[2].replace(/^\s*|\s*$/, '');;
                    }
                }

                if(map_inner.match(/address\:/g)){
                    markAddress(address, curMap, info, eid);
                }
                else{
                    var coords = address.split(",");
                    if(!coords[1]){
                        return;
                    }

                    var map = new GMap2(curMap);
                    var point = new GLatLng(coords[0], coords[1]);

                    map.setCenter(point, 13);
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());

                    var marker = new GMarker(point);
                    map.addOverlay(marker);

                    /*var sv_container = document.getElementById("google_pano");
                    if(sv_container){
                        var myPano = new GStreetviewPanorama(sv_container);
                        GEvent.addListener(myPano, "error", handleNoFlash);
                        svOverlay = new GStreetviewOverlay( );
                        map.addOverlay(svOverlay);
                        GEvent.addListener(map, "click", function(overlay,latlng) {
                            sv_container.style.display = 'block';
                            myPano.setLocationAndPOV(latlng);
                        });
                    }*/

                    var sv_container = document.getElementById("google_pano");
                    if(sv_container){
                        panoClient = new GStreetviewClient();

                        GEvent.addListener(map, "click", function(overlay,latlng) {
                            panoClient.getNearestPanorama(latlng, showPanoData);
                        });

                        myPano = new GStreetviewPanorama(sv_container);
                        svOverlay = new GStreetviewOverlay( );
                        map.addOverlay(svOverlay);
                        myPano.setLocationAndPOV(point);
                        GEvent.addListener(myPano, "error", handleNoFlash);
                        panoClient.getNearestPanorama(point, showPanoData);

                    }

                    GEvent.addListener(marker, "click", function(overlay,latlng){
                        map.openInfoWindowHtml(point, "<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");
                    });

                    marker.openInfoWindowHtml("<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");

                }
            }
        }
    }
}

function markAddress(address, curMap, info, eid){
    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);

                var sv_container = document.getElementById("google_pano");
                if(sv_container){
                    panoClient = new GStreetviewClient();

                    GEvent.addListener(map, "click", function(overlay,latlng) {
                        panoClient.getNearestPanorama(latlng, showPanoData);
                    });

                    myPano = new GStreetviewPanorama(sv_container);
                    svOverlay = new GStreetviewOverlay( );
                    map.addOverlay(svOverlay);
                    myPano.setLocationAndPOV(point);
                    GEvent.addListener(myPano, "error", handleNoFlash);
                    panoClient.getNearestPanorama(point, showPanoData);

                }

                GEvent.addListener(marker, "click", function(overlay,latlng){
                    map.openInfoWindowHtml(point, "<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");
                });

                marker.openInfoWindowHtml("<div style=\"line-height: 1.2em; font-size: .9em\">" + info + "</div>");

                var lat_long = new String(point);
                var lat_long = lat_long.replace(/\)|\(/g, '');
                var lat_longA = lat_long.split(/,/);

                var lat = lat_longA[0].replace(/^\s*|\s*$/, '');
                var lon = lat_longA[1].replace(/^\s*|\s*$/, '');
            }
        }
    );

}

function handleNoFlash(errorCode){
    if(errorCode == 603){
        //alert("Error: Flash doesn't appear to be supported by your browser");
        return;
    }
}

function showPanoData(panoData) {
    if (panoData.code != 200) {
        //GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
        return;
    }

    var sv_container = document.getElementById("google_pano");
    sv_container.style.display = 'block';

    myPano.setLocationAndPOV(panoData.location.latlng);
}



/* END GOOGLE MAPS */

function overlayPopUp( ){
    var overlay = document.getElementById('pop_overlay_dir');
    var container = document.getElementById('pop_container_dir');

    if(!overlay || !container){
        return;
    }

    var cur_style = overlay.style.display;

    if(cur_style == 'none' || cur_style == ''){
        overlay.style.display = 'block';
        container.style.display = 'block';
    }
    else{
        overlay.style.display = 'none';
        container.style.display = 'none';
    }
}

function openSplash(tObj){
    var newHREF = tObj.href;

    //until the non-js part is done
    if(window.is_ie && tObj.innerHTML.match('Reviews')){
        window.location = newHREF;
    }

    newHREF = newHREF.replace(/(\#.*)$/, '');
    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
    newHREF = newHREF + '?type=splash_dir';
    //alert(newHREF);
    b_xml.request(newHREF);

    overlayPopUp( );
    makeWindowed('pop_container_dir');

    if(b_xml.isSupported){ return false; }
}

//http://www.actionscript.org/forums/showthread.php3?t=132324
function makeWindowed(div){
    var p_div = document.getElementById(div);
    if(window.isOldIE){
        var html = "<iframe style=\"filter: Alpha(Opacity=60, FinishOpacity=60, Style=2); background-color: #000000; position: absolute; display: inline; z-index: -1; width: 100%; height: 854px; top: 0; left: 0; filter: mask( );\"></iframe>";

        if(p_div){
            p_div.innerHTML += html;
        }

        //force refresh of div
        var olddisplay = p_div.style.display;
        p_div.style.display = 'none';
        p_div.style.display = olddisplay;

        initAjaxTabs( );
        initDirPhoneNumbers( );
        initInputButtons( );
    }
}

function disableButton(buttonID, msg){
   tButton = document.getElementById(buttonID);

   if(!tButton){
        return;
   }

   tButton.value = msg;
   tButton.style.color = "#606060";
   tButton.style.backgroundColor = "#C0C0C0";
   tButton.disabled = true;
}

function hideById(tid){
    tObj = document.getElementById(tid);

    tObj.style.display = 'none';
}
function showById(tid, dispType){
    tObj = document.getElementById(tid);

    if(!dispType || window.is_ie){
        dispType = 'block';
    }

    tObj.style.display = dispType;
}
function toggleById(tid, dispType){
    tObj = document.getElementById(tid);

    if(!dispType || window.is_ie){
        dispType = 'block';
    }

    if(tObj.style.display == dispType){
        tObj.style.display = 'none';
    }
    else{
        tObj.style.display = dispType;
    }
}

function clearBilling( ){
    document.getElementById('saved_billing').value = 'new billing';
    document.getElementById('billing_name').value = '';

    var ccnum = document.getElementById('cc_num');
    if(ccnum.value.match(/\*/)){
        ccnum.value = '';
    }
    var ach_account = document.getElementById('ach_account')
    if(ach_account.value.match(/\*/)){
        ach_account.value = '';
    }
    var ach_routing = document.getElementById('ach_routing');
    if(ach_routing.value.match(/\*/)){
        ach_routing.value = '';
    }
}

function fillBilling(newVal){
    if(newVal == 'new billing'){
        if(document.getElementById('billing_name')){
            document.getElementById('billing_name').value = '';
        }

        document.getElementById('cc_name').value = '';
        document.getElementById('cc_num').value = '';
        document.getElementById('cc_mon').value = '';
        document.getElementById('cc_year').value = '';

        document.getElementById('ach_name').value = '';
        document.getElementById('ach_bank_name').value = '';
        document.getElementById('ach_type').value = '';
        document.getElementById('ach_routing').value = '';
        document.getElementById('ach_account').value = '';

        document.getElementById('billing_street').value = '';
        document.getElementById('billing_street2').value = '';
        document.getElementById('billing_city').value = '';
        document.getElementById('billing_state').value = '';
        document.getElementById('billing_zip').value = '';
    }
    else{
        if(!billA[newVal]){
            return;
        }

        var thisBilling = billA[newVal];

        if(document.getElementById('billing_name')){
            document.getElementById('billing_name').value = thisBilling.billing_name;
        }

        if(thisBilling.cc_num){
            document.getElementById('payment_type_cc').checked = 'check';
            document.getElementById('payment_type_ach').checked = '';

            document.getElementById('cc_name').value = thisBilling.cc_name;
            document.getElementById('cc_num').value = thisBilling.cc_num;
            document.getElementById('cc_mon').value = thisBilling.cc_mon;
            document.getElementById('cc_year').value = thisBilling.cc_year;

            document.getElementById('ach_name').value = '';
            document.getElementById('ach_bank_name').value = '';
            document.getElementById('ach_type').value = '';
            document.getElementById('ach_routing').value = '';
            document.getElementById('ach_account').value = '';
        }
        else if(thisBilling.ach_account){
            document.getElementById('payment_type_cc').checked = '';
            document.getElementById('payment_type_ach').checked = 'check';

            document.getElementById('cc_name').value = '';
            document.getElementById('cc_num').value = '';
            document.getElementById('cc_mon').value = '';
            document.getElementById('cc_year').value = '';

            document.getElementById('ach_name').value = thisBilling.ach_name;
            document.getElementById('ach_bank_name').value = thisBilling.ach_bank_name;
            document.getElementById('ach_type').value = thisBilling.ach_type;
            document.getElementById('ach_routing').value = thisBilling.ach_routing;
            document.getElementById('ach_account').value = thisBilling.ach_account;
        }

        document.getElementById('billing_street').value = thisBilling.billing_street;
        document.getElementById('billing_street2').value = thisBilling.billing_street2;
        document.getElementById('billing_city').value = thisBilling.billing_city;
        document.getElementById('billing_state').value = thisBilling.billing_state;
        document.getElementById('billing_zip').value = thisBilling.billing_zip;
    }
}

function setAttendeeInfo(new_val){
    if(new_val <= 0){
        document.getElementById('first_name').value = '';
        document.getElementById('last_name').value = '';
        document.getElementById('company_name').value = '';
        document.getElementById('street1').value = '';
        document.getElementById('street2').value = '';
        document.getElementById('city').value = '';
        document.getElementById('state').value = '';
        document.getElementById('zip').value = '';
        document.getElementById('email_address').value = '';
    }
    else{
        if(!attendeeA[new_val]){
            return;
        }

        var this_attendee = attendeeA[new_val];

        document.getElementById('first_name').value = this_attendee.first_name;
        document.getElementById('last_name').value = this_attendee.last_name;
        document.getElementById('company_name').value = this_attendee.company_name;
        document.getElementById('street1').value = this_attendee.street1;
        document.getElementById('street2').value = this_attendee.street2;
        document.getElementById('city').value = this_attendee.city;
        document.getElementById('state').value = this_attendee.state;
        document.getElementById('zip').value = this_attendee.zip;
        document.getElementById('email_address').value = this_attendee.email;
    }
}

function initAjaxTabs( ){
    var html_id;
    var ajax_type;
    var hObj = null;

    for(var cnt = 0; cnt < ajaxTabList.length; cnt++){

        html_id = ajaxTabList[cnt].html_id;
        ajax_type = ajaxTabList[cnt].ajax_type;

        hObj = document.getElementById(html_id);

        if(hObj){
            i = 0;
            as = hObj.getElementsByTagName("a");
            for(i = 0; i < as.length; i++){
                as[i].parent_class = as[i].parentNode.className;

                as[i].ajax_type = ajax_type;
                as[i].onclick = function( ){
                    if(this.ajax_type == 'dir' && window.is_ie && this.innerHTML == 'Reviews'){
                        return true;
                    }

                    if(b_xml.isCurrentRequest){ return false; }
                    //ul = a->li->ul (this->parent->parent)
                    //table = a->td->tr->table (this->parent->parent-parent)
                    var table = this.parentNode.parentNode;
                    var p_as = table.getElementsByTagName('a');

                    for(var j = 0; j < p_as.length; j++){ p_as[j].className = ''; p_as[j].parentNode.className = 'page_tab_c'; }
                    this.className = 'a_cur';
                    this.parentNode.className = this.parent_class + ' li_cur';
                    var newHREF = this.href;
                    newHREF = newHREF.replace(/(\#.*)$/, '');
                    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                    newHREF = newHREF + '/type/' + this.ajax_type;
                    //alert('here');
                    //alert(newHREF);

                    b_xml.request(newHREF);

                    if(b_xml.isSupported){ return false; }

                    return true;
                }//end onclick

                as[i].onmouseover = function( ){
                    this.parentNode.className = this.parent_class + ' li_cur';
                }
                as[i].onmouseout = function( ){
                    if(this.className != 'a_cur'){
                        this.parentNode.className = this.parent_class;
                    }
                }
            }//end foreach a in homeArticlesMenu
        }

    }//end for each ajaxTabList
}

function initAjaxContentA( ){
    var tc_obj = document.getElementById('pageTabContent');
    if(tc_obj && b_xml){
        tc_as = tc_obj.getElementsByTagName('a');
        as_length = tc_as.length;
        for(var i = 0; i < as_length; i++){
            t_href = tc_as[i].href;
            if(t_href.match(/tab_index\//)){
                var parent_class = tc_as[i].parentNode.className;
                tc_as[i].onclick = function( ){
                    //check to see if classes need updated on tabs
                    pt_obj = document.getElementById('pageTabs');
                    var p_as = pt_obj.getElementsByTagName('a');

                    stripped_href = this.href.replace('#page_tabs', '');
                    for(var j = 0; j < p_as.length; j++){

                        if(p_as[j].href == stripped_href){
                            p_as[j].className = 'a_cur';
                            p_as[j].parentNode.className = parent_class + ' li_cur';
                        }
                        else{
                            p_as[j].className = '';
                            p_as[j].parentNode.className = 'page_tab_c';
                        }
                    }

                    //move to anchor
                    window.location.hash = 'page_tabs';

                    //update content
                    var newHREF = this.href;
                    newHREF = newHREF.replace(/(\#.*)$/, '');
                    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php/');
                    newHREF = newHREF + '/type/page';

                    b_xml.request(newHREF);

                    if(b_xml.isSupported){ return false; }

                    return true;
                }
            }
        }
    }
}

function initCalendarNav( ){
    //similar to tabs but for the calendar
    hObj = document.getElementById('ajaxCalNav');
    if(hObj){
        i = 0;
        as = hObj.getElementsByTagName("a");
        for(i = 0; i < as.length; i++){
            if(as[i].id == 'mainDate'){
                continue;
            }

            as[i].onclick = function( ){
                if(b_xml.isCurrentRequest){ return false; }

                var newHREF = this.href;
                newHREF = newHREF.replace(/(\#.*)$/, '');

                if(newHREF.match(/\/members\//)){
                    newHREF = newHREF.replace(/(\/members\/)/, '/members/ajax.php');
                }
                else if(newHREF.match(/content/)){
                    newHREF = newHREF.replace(/(\/content\/)/, '/ajax.php');
                }

                newHREF = newHREF + '&type=calnav';
                //alert(newHREF);
                b_xml.request(newHREF);
                if(b_xml.isSupported){ return false; }

                return true;
            }//end onclick
        }
    }
}

function submitComment(fieldID){
    var bgzFrame = document.getElementById('bgz');
    var hidField = document.getElementById(fieldID);
    var frameSrc = getDocHTML( );
    hidField.value = frameSrc;
}

function initListingGallery( ){
    var listing_gallery = document.getElementById('listing_gallery');
    var listing_gallery_image = document.getElementById('listing_gallery_image');

    if(!listing_gallery || !listing_gallery_image){ return; }

    var lnks = listing_gallery.getElementsByTagName('a');
    for(var i = 0; i < lnks.length; i++){
        lnks[i].onclick = function( ){ return false; }
    }

    var imgs = listing_gallery.getElementsByTagName('img');
    for(var i = 0; i < imgs.length; i++){
        imgs[i].onclick = function( ){
            var img_src = this.src.replace(/\_t(\.\w+)$/, "$1");
            listing_gallery_image.src = img_src;
            resizeOverlay( );
        }
    }
}

function resizeOverlay( ){
    var pop_overlay_dir = document.getElementById('pop_overlay_dir');
    var dirTabContent = document.getElementById('dirTabContent');
    var dirTabContentInner = document.getElementById('dirTabContentInner');

    var pad = 10;

    var default_height = 0;
    var dtc_inner_height = 0;
    var min_height = 350;

    var dtc_height = min_height;

    if(pop_overlay_dir && dirTabContent && dirTabContentInner){
        if(document.body.clientHeight && document.body.clientHeight > 0){
            default_height = parseInt(document.body.clientHeight - 200);
            dtc_inner_height = dirTabContentInner.clientHeight + pad;
        }
        else if(document.body.offsetHeight && document.body.offsetHeight > 0){
            default_height = parseInt(document.body.offsetHeight - 200);
            dtc_inner_height = dirTabContentInner.offsetHeight + pad;
        }

        if(dirTabContentInner.scrollHeight){
            dtc_inner_height = dirTabContentInner.scrollHeight + pad;
        }

        if(dtc_inner_height > default_height){
            dtc_height = default_height;
        }
        else if(dtc_inner_height > min_height){
            dtc_height = dtc_inner_height;
        }
        else{
            dtc_height = min_height;
        }

        dirTabContent.style.height = dtc_height + 'px';
        dirTabContent.style.minHeight = dtc_height + 'px';
    }
}

function checkListingTextLength(numChars){
    ListingTextArea = document.getElementById('ListingTextArea');
    if(ListingTextArea.value.length >= numChars){
        ListingTextArea.value = ListingTextArea.value.substr(0, numChars);
    }
}

function disableBilling(t_obj){
    var event_form = document.getElementById('event_billing_form');
    if(!event_form){ return; }

    var d_flag = false;
    if(t_obj.checked){
        d_flag = true;
    }

    var event_form_len = event_form.elements.length;
    for(var i = 0; i < event_form_len; i++){
        if(event_form.elements[i] == t_obj || event_form.elements[i].type == 'submit' || event_form.elements[i].type == 'hidden'){
            continue;
        }

        event_form.elements[i].disabled = d_flag;
    }
}

function loadCufonFonts( ){
    var tm_linksA = getElementsByClassName('tm_link', document.getElementById('tmenu'));
    tm_links_len = tm_linksA.length;
    for(var i = 0; i < tm_links_len; i++){
        tm_linksA[i].style.fontSize = '16px';
    }

    Cufon.replace('.tm_link', {
        fontFamily: 'Brush Script Std',
        textShadow: '1px 1px rgba(0, 0, 0, 0.2)',
        fontWeight: 'bold',
        color: '-linear-gradient(#d5edf7, 0.2=#fff, 0.6=#e0edf3, #3aaad8)'
    });
    Cufon.replace('h1', {
        fontFamily: 'Minion Pro'
    });
}


function getElementsByClassName(classname, node) {
    if(!node){
        node = document.getElementsByTagName("body")[0];
    }

    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");

    for(var i = 0, j = els.length; i < j; i++){
        if(re.test(els[i].className)){
            a.push(els[i]);
        }
    }
    return a;
}

function initAppObjects( ){
    var bBaseGallery = document.getElementById('vid_thumbs_outer');
    var bbc = document.getElementById('vid_thumbs_container');
    if(!bbc){
        return;
    }
    var clientW = bbc.clientWidth;
    var scrollW = bbc.scrollWidth;
    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(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 vid_thumbs_arrow_l = document.getElementById('vid_thumbs_arrow_l');
    var vid_thumbs_arrow_r = document.getElementById('vid_thumbs_arrow_r');

    if(document.addEventListener){
        bbc.addEventListener('DOMMouseScroll', captureScroll, false);
    }
    //else{
        //make opera happy, it lies about addEventListener!
        //bbc.onmousewheel = captureScroll;
    //}


    vid_thumbs_arrow_l.onmouseover = function( ){
        sGlobals.isScrollingL = true;
        sGlobals.scrollTime = sGlobals.slowScroll;
        bScrollLeft( );
    }
    vid_thumbs_arrow_l.onmouseout = function( ){
        sGlobals.isScrollingL = false;
        sGlobals.scrollTime = sGlobals.slowScroll;
    }
    vid_thumbs_arrow_l.onmousedown = function( ){
        if(is_safari){
            return false;
        }
        sGlobals.isScrollingL = true;
        sGlobals.scrollTime = sGlobals.fastScroll;
    }
    vid_thumbs_arrow_l.onmouseup = function( ){
        if(is_safari){
            return false;
        }
        sGlobals.isScrollingL = true;
        sGlobals.scrollTime = sGlobals.slowScroll;
        return false;
    }
    vid_thumbs_arrow_l.onclick = function( ){ return false }


    vid_thumbs_arrow_r.onmouseover = function( ){
        sGlobals.isScrollingR = true;
        sGlobals.scrollTime = sGlobals.slowScroll;
        bScrollRight( );
    }
    vid_thumbs_arrow_r.onmouseout = function( ){
        sGlobals.isScrollingR = false;
        sGlobals.scrollTime = sGlobals.slowScroll;
    }
    vid_thumbs_arrow_r.onmousedown = function( ){
        if(is_safari){
            return false;
        }
        sGlobals.isScrollingR = true;
        sGlobals.scrollTime = sGlobals.fastScroll;
    }
    vid_thumbs_arrow_r.onmouseup = function( ){
        if(is_safari){
            return false;
        }

        sGlobals.isScrollingR = true;
        sGlobals.scrollTime = sGlobals.slowScroll;
        return false;
    }
    vid_thumbs_arrow_r.onclick = function( ){ return false }

    vid_hrefA = bbc.getElementsByTagName('a');
    vid_hrefA_len = vid_hrefA.length;
    for(i = 0; i < vid_hrefA_len; i++){
        t_a = vid_hrefA[i];
        t_a.onclick = function( ){
            if(window.isOldIE){ return true; }
            var newHREF = this.href;
            newHREF = newHREF.replace(/(\#.*)$/, '');
            newHREF = newHREF.replace(/(\.\w+)\/(.*\.html)/, "$1/ajax.php/");
            newHREF = newHREF + '&type=vid';
            b_xml.request(newHREF);

            if(b_xml.isSupported){ return false; }

            return true;
        }
    }


    if(document.getElementById('vid_thumbs_outer')){
        var bbc = document.getElementById('vid_thumbs_container');

        var vid_thumbs_arrow_l = document.getElementById('vid_thumbs_arrow_l');
        var vid_thumbs_arrow_r = document.getElementById('vid_thumbs_arrow_r');

        //alert(bbc.offsetWidth);
        //alert(bbc.clientWidth);
        //alert(bbc.scrollWidth);

        if(bbc.clientWidth < bbc.scrollWidth && vid_thumbs_arrow_l.style.display != "block"){
            vid_thumbs_arrow_l.style.display = "block";
            vid_thumbs_arrow_r.style.display = "block";
        }
        else if(bbc.clientWidth == bbc.scrollWidth){
            vid_thumbs_arrow_l.style.display = "none";
            vid_thumbs_arrow_r.style.display = "none";
        }
        else if(bbc.style.left != "0px"){
            bbc.style.left = "0px";
        }

    }
}


function appThink( ){
    if(document.getElementById('vid_thumbs_outer')){
        var bbc = document.getElementById('vid_thumbs_container');

        var vid_thumbs_arrow_l = document.getElementById('vid_thumbs_arrow_l');
        var vid_thumbs_arrow_r = document.getElementById('vid_thumbs_arrow_r');

        //alert(bbc.offsetWidth);
        //alert(bbc.clientWidth);
        //alert(bbc.scrollWidth);

        if(bbc.clientWidth < bbc.scrollWidth && vid_thumbs_arrow_l.style.display != "block"){
            vid_thumbs_arrow_l.style.display = "block";
            vid_thumbs_arrow_r.style.display = "block";
        }
        else if(bbc.clientWidth == bbc.scrollWidth){
            vid_thumbs_arrow_l.style.display = "none";
            vid_thumbs_arrow_r.style.display = "none";
        }
        else if(bbc.style.left != "0px"){
            bbc.style.left = "0px";
        }

    }


    //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('vid_thumbs_container');
    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( );
}

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);
    }
}