/* #################################################################
    Copyright 2005 BBB Systems, LLC, All rights reserved
################################################################## */
var plusImg = new Image( );
plusImg.src = "/images/plus.gif";
var minusImg = new Image( );
minusImg.src = "/images/minus.gif";

var bScrollAmount = 20;

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

var globals = new Array( );

var ajaxEnabled = false;
var bgzDDEnabled = true;

var stopProdRotator = false;
var allowedPRIndex = 1;

if(imgRotatorThinking == undefined){
    var imgRotatorThinking = false;
}

function init( ){
    if(!document.getElementsByTagName){
        return;//if it doesn't support this, it doesn't support a whole lot.
    }

    if(ajaxEnabled){
        ajaxCheck( );
    }

    initTopMenuLinks( );
    initInputButtons( );
    initImgRotator( );
    initA( );
    initSearchBObjects( );
    initObjects( );

    initProductRotator( );

    balanceColumns( );

    appThink( );

}


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

//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(/\/.*/, "");

            if(hostnm != window.location.hostname || as[i].href.match(/\/ad\.\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;
                    }
                }
            }
        }
    }
}

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';
            }//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 image_table = getGalleryImageTable( );
    var display_image = getGalleryMainImage( );
    if(!image_table || !display_image){ return; }

    display_image.style.opacity = 1;

    var imageA = image_table.getElementsByTagName('img');

    //preload the gallery images for smoother transitions
    window.galleryImages = new Array( );

    j = 0;
    for(i = 0; i < imageA.length; i++){
        var img = imageA[i];

        if(!img.id || img.id == '' || img.id == display_image.id){
            continue;
        }

        var d_id = 'gallery_image_div_' + j;
        var next_id = 'gallery_image_div_' + parseInt(j + 1);
        if(i == imageA.length - 1){
            next_id = 'gallery_image_div_0';
        }

        img.parentNode.onmouseover = galleryImageHover;
        img.parentNode.onmouseout = galleryImageOut;
        img.parentNode.onclick = galleryImageClick;

        img.parentNode.id = d_id;
        img.parentNode.next_id = next_id;

        //preload the image
        window.galleryImages[d_id] = new Image( );
        window.galleryImages[d_id].src = img.src.replace(/\_t(\.\w+)$/, "$1");
        window.galleryImages[d_id].setAttribute('alt', img.getAttribute('alt'));

        if(i == 0){
            window.galleryCurImageDiv = d_id;
            window.galleryCurImage = window.galleryImages[d_id].src;
            window.galleryCurComment = window.galleryImages[d_id].getAttribute('alt');
        }
        j++;
    }

    var scale_time = 10000;
    if(image_table.id == 'home_img_gallery_tbl'){
        scale_time = 4000;
    }

    setGalleryNextRotation(scale_time);

    //imageRotatorThink( );//call this in appThink
}
function setGalleryNextRotation(t_offset){
    var dt = new Date( );
    window.galleryNextRotation = parseInt(dt.getTime( ) + t_offset);
    dt = null;
}
function getGalleryImageTable( ){
    var image_table = document.getElementById('hThumbs');
    //if(!image_table){ image_table = document.getElementById('hThumbs'); }
    return image_table;
}
function getGalleryMainImage( ){
    var display_image = document.getElementById('mainImg');
    //if(!display_image){ display_image = document.getElementById('gallery_img_main'); }
    return display_image;
}
function getGalleryMainImageLink( ){
    var image_link = document.getElementById('prodImgLnk');
    return image_link;
}
function getGalleryMainComment( ){
    var display_comment = document.getElementById('imgComment');
    return display_comment;
}

function gallerySwapTransition( ){
    var display_image = getGalleryMainImage( );
    var display_comment = getGalleryMainComment( );
    var image_table = getGalleryImageTable( );

    if(!display_image || !image_table){
        return;
    }

    var a_amt = .10;
    if(window.ActiveXObject){
        a_amt = .15;
    }

    var cur_alpha = (display_image.style.opacity * 100)/100;
    var alpha = cur_alpha + (window.galleryCurDir * a_amt);

    if(alpha <= 0){
        alpha = 0;
        window.galleryCurDir = 1;
        display_image.src = window.galleryCurImage;
        display_comment.innerHTML = window.galleryCurComment;

        var host_loc = window.location.hostname;
        var img_rel_loc = display_image.src.replace('http://' + host_loc, '');
        img_rel_loc = img_rel_loc.replace(/uimages\//, '');

        var image_link = document.getElementById('prodImgLnk');
        var image_enlarge_link = document.getElementById('prodImgEnlarge');

        var new_img_link = image_link.href.replace(/(pimg=.*)$/, 'pimg=' + img_rel_loc);

        image_link.href = new_img_link;
        image_enlarge_link.href = new_img_link;
    }
    if(alpha >= 1){
        alpha = 1;
    }

    display_image.style.opacity = alpha;
    if(window.ActiveXObject){
        var ie_alpha = alpha * 100;
        display_image.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + ie_alpha + ")";
    }

    if(alpha != 1){
        setTimeout('gallerySwapTransition( );', 50);
    }
}
function gallerySwapImage(imgObject){
    var display_image = getGalleryMainImage( );
    var image_table = getGalleryImageTable( );

    if(!display_image || !image_table){
        return;
    }

    window.galleryCurImageDiv = imgObject.parentNode.id;
    window.galleryCurImage = window.galleryImages[imgObject.parentNode.id].src;
    window.galleryCurComment = window.galleryImages[imgObject.parentNode.id].getAttribute('alt');
    window.galleryCurDir = -1;
    var divs = image_table.getElementsByTagName('div');

    for(i = 0; i < divs.length; i++){
        var div = divs[i];
        div.className = '';
    }

    imgObject.parentNode.className = 'cur';
    imgObject.parentNode.classNameBak = 'cur';

    if(display_image.style.opacity == 1){
        gallerySwapTransition( );
    }
}
function galleryImageClick( ){
    //make it long on the gallery pages.
    var scale_time = 20000;
    setGalleryNextRotation(scale_time);
    gallerySwapImage(this.getElementsByTagName('img')[0]);
}
function galleryImageHover( ){
    this.classNameBak = this.className;
    this.className = 'over';
}
function galleryImageOut( ){
    this.className = this.classNameBak;
}
function imageGalleryThink( ){
    var display_image = getGalleryMainImage( );
    var image_table = getGalleryImageTable( );

    if(!display_image || !image_table){
        return;
    }

    dt = new Date( );
    if(dt.getTime( ) >= window.galleryNextRotation){
        var scale_time = 10000;
        if(image_table.id == 'home_img_gallery_tbl'){
            scale_time = 4000;
        }
        setGalleryNextRotation(scale_time);
        var div = document.getElementById(window.galleryCurImageDiv);
        var next_div = document.getElementById(div.next_id);
        var img = next_div.getElementsByTagName('img')[0];
        gallerySwapImage(img);
    }
}

function appThink( ){

    //Add custom thinkers here.
    imageGalleryThink( );

    if(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 && bLeftArrow.style.display != "block"){
            bLeftArrow.style.display = "block";
            bRightArrow.style.display = "block";
        }
        else if(bbc.clientWidth == bbc.scrollWidth){
            bLeftArrow.style.display = "none";
            bRightArrow.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('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 * bScrollAmount * 2);
    }
    else{
        bottomBaseScroll(bScrollAmount * 2);
    }

    e.stopPropagation( );
    e.preventDefault( );
}

function bScrollLeft( ){
    var bLeftArrow = document.getElementById('bLeftArrow');

    if(bLeftArrow.isScrolling){
        bottomBaseScroll(-1 * bScrollAmount);
        setTimeout('bScrollLeft( );', 50);
    }
}
function bScrollRight( ){
    var bRightArrow = document.getElementById('bRightArrow');

    if(bRightArrow.isScrolling){
        bottomBaseScroll(bScrollAmount);
        setTimeout('bScrollRight( );', 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 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;
}

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


var CurMenu = null;
var isDropped = false;
var isHideCheck = false;
var subCurMenu = null;
var subIsDropped = false;
var subIsHideCheck = false;

function initTopMenuLinks( ){
    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 != null) 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){
    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 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'){

        //opera needs doesn't parse the new description
        //may need to add more later, I'm not sure
        prodDesc = prodDesc.replace(/\&gt\;/g, '>');
        prodDesc = prodDesc.replace(/\&lt\;/g, '<');
        prodDesc = prodDesc.replace(/\&quot\;/g, '"');
        prodDesc = prodDesc.replace(/\&amp\;/g, '&');

        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 = 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 #FF9727";

            //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 contentID = 'content';
    var content = document.getElementById(contentID);
    if(!content){
        contentID = 'contentFull';
        content = document.getElementById(contentID);
    }

    var leftColumn = document.getElementById('columnLeft');

    if(!content || !leftColumn){
        return;
    }

    var contentHeight = content.clientHeight;
    var leftColumnHeight = leftColumn.clientHeight;

    //alert("contentLeft: " + contentHeight);
    //alert("rightColumn: " + rightColumnHeight);

    if(contentHeight > leftColumnHeight){
        document.getElementById('columnLeft').style.height = (contentHeight) + 'px';
    }
    else{
        document.getElementById(contentID).style.height = (leftColumnHeight) + 'px';
        document.getElementById('columnLeft').style.height = (leftColumnHeight) + 'px';
    }

    //alert("contentLeft: " + document.getElementById('columnRight').style.height);
    //alert("rightColumn: " + document.getElementById('contentLeft').style.height);
}

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

function getColor(fieldID){
    winTool = window.open("./colorselect.php?fieldID=" + fieldID, "ColorTool", "width=256,height=512,status=no,toolbar=no,resizable=no,alwaysRaised=yes");
    winTool.focus();
}

//******************
// FLash Functions *
//******************

//Requires javascript dom support, gracefully fails otherwise
//Loads flash movie in the specified location

//not done yet.
function loadFlashDocument(movieLocation){

}