


// this is how long it should take the scroller to animate when the user clicks a marker (in milliseconds)
Scroller.aniLen = 2500

function init_scroll(theid, show_thumb) {

    this.id = theid;
    this.show_thumb = show_thumb;

    this.gRef = "Scroller_"+theid;
    eval(this.gRef+"=this");

    var r = this.getMembers();


    if(!r){
        
        //TODO FIXME: clean up global references, to make them stay only in an array.  so they are cleaned up
        //     correctly.

        //this.gRef = "Scroller_"+theid
        //eval(this.gRef+"=this")

        var runagain = function () {
            aref_name= "Scroller_"+theid;
            eval("reftoit=" + aref_name);

            reftoit.init_scroll(theid, show_thumb);
        }
        setTimeout(runagain, 200);
        return;
    }


    this.init_sizes();

    this.thumb.obj	= this
    this.thumb.onmousedown = this.startDrag

    this.up.onmousedown = this.scrollUp;
    this.up.onmouseup = this.endScroll;
    this.down.onmousedown = this.scrollDown;
    this.down.onmouseup = this.endScroll;
    this.up.obj	= this;
    this.down.obj = this;
    this.track.obj = this;

    this.container.obj = this;
    this.amount = 0;

    var scroll_func = function(e) {
        if (!e) e = window.event
        var obj = this.obj;
	Scroller.current = this.obj


        //TODO: 
        //  scroll an amount according to :
        //     - how big the scroll height is
        //     - how much the wheelDelta is.


        // if we suppose onmousewheel do this:
        if(e.wheelDelta) {

            if(obj.content.offsetHeight >= obj.container.offsetHeight) {

                if (e.wheelDelta >= 0) {
                    amount = -10;
                } else {
                    amount = 10;
                }

                obj.scrollDy(amount);
            }
        } else {
            if(obj.content.offsetHeight >= obj.container.offsetHeight) {

                //firefox is backwards from the rest.
                if (e.detail <= 0) {
                    amount = -10;
                } else {
                    amount = 10;
                }

                obj.scrollDy(amount);
            }



        }

    }


    //this.container.onmousewheel= this.mouse_scroll;

    var container_todo = this.container;

    var blur_func = function(e) {
        if (!e) e = window.event;

        firefox_container_to_scroll = container_todo;

    }



    // if it supports addEventListener we use that else use onmousewheel
    if(window.addEventListener) {
        this.container.onmousewheelff= scroll_func;
        this.container.onmousewheel= false;
        this.container.onmouseover= blur_func;
    } else {
        this.container.onmousewheel= scroll_func;
        this.container.onmousewheelff= false;
    }

    //this.container.addEventListener("DOMMouseScroll", scroll_func, false);
    //window.addEventListener("DOMMouseScroll", scroll_func, true);

}

function scroll_firefox(e) {
    if(firefox_container_to_scroll) {
        firefox_container_to_scroll.onmousewheelff(e);
    }
}


firefox_container_to_scroll = false;
if( window.addEventListener ) {
    window.addEventListener("DOMMouseScroll", scroll_firefox, false);
}





/*
const WHEEL_INCREMENT = 5;

var scale = 1;

resizeImage = function(e) {
	scale += (e.detail > 0 ? 1 :-1);
	document.title = 
		document.images[0].style.height = 100  + (scale * WHEEL_INCREMENT) + "%";
};

onload = function(e) {
	window.addEventListener("DOMMouseScroll", resizeImage, true);
}
*/











function Scroller(theid) {
}

Scroller.prototype.init_sizes= function() {
    this.init_sizes_just_size();
    this.last_moved = (new Date()).getTime()
}

Scroller.prototype.init_sizes_just_size= function() {

    this.clipH		= parseInt(this.container.offsetHeight);
    //this.scrollH	= this.clipH
    //this.scrollH	= parseInt(this.content.offsetHeight) - self.clipH
    var scrollH	= parseInt(this.content.offsetHeight);
    this.scrollH = scrollH - this.clipH;

    this.thumbMax	= parseInt(this.thumbContainer.style.height) - this.thumbImg.height;
}

Scroller.prototype.get_scrollH= function() {
    return parseInt(this.content.offsetHeight)- parseInt(this.container.offsetHeight);
}




Scroller.prototype.init_scroll = init_scroll;

Scroller.prototype.getMembers = function() {

	this.container=ypGetElementById(this.id + 'Container');
        if(!this.container) { return false; }

	this.content=ypGetElementById(this.id + 'Content');
        if(!this.content) { return false; }

	//this.markers=ypGetElementById(this.id + 'Markers');
	this.thumb=ypGetElementById(this.id + 'Thumb');
	this.thumbImg=ypGetElementById(this.id + 'ThumbImg');
        if(!this.thumbImg) { return false; }

	this.thumbContainer=ypGetElementById(this.id + 'ThumbContainer');

	this.track=ypGetElementById(this.id + 'Track');

	this.up=ypGetElementById(this.id + 'Up');
	this.upImg=ypGetElementById(this.id + 'UpImg');
	this.down=ypGetElementById(this.id + 'Down');
	this.downImg=ypGetElementById(this.id + 'DownImg');

        if(!this.downImg) { return false; }

        if((this.content.offsetHeight <= this.container.offsetHeight) || !this.show_thumb) {
            this.thumb.style.visibility= "hidden";
        }


        return true;
}

Scroller.prototype.reset_stuff= function(e) {
    // resets the things which may have changed, if the content has changed.
    if(this.content) {
        // check to see if the content is less than the container,
        //  and then do not show the scroller if so.
        if((this.content.offsetHeight <= this.container.offsetHeight) || !this.show_thumb) {
            this.thumb.style.visibility= "hidden";
            this.up.innerHTML = this.up.innerHTML.replace("scroller-up.gif", "scroller-up-pressed.gif");
            this.down.innerHTML = this.down.innerHTML.replace("scroller-down.gif", "scroller-down-pressed.gif");

        } else {
            this.thumb.style.visibility= "inherit";
            this.up.innerHTML = this.up.innerHTML.replace("scroller-up-pressed.gif", "scroller-up.gif");
            this.down.innerHTML = this.down.innerHTML.replace("scroller-down-pressed.gif", "scroller-down.gif");

        }

        // scroll content to the top.
        this.init_sizes();

        //this.content.style.top = 0;
        this.jumpTo(0);


    }

}

Scroller.prototype.startDrag = function(e) {
	if (!e) e = window.event
	var ey = e.pageY ? e.pageY : e.clientY
	this.dragLastY = ey
	this.dragStartOffset = ey - parseInt(this.style.top)

	Scroller.current = this.obj
	document.onmousemove = this.obj.doDrag
	document.onmouseup = this.obj.stopDrag
	if (this.obj.aniTimer) window.clearInterval(this.obj.aniTimer)

	return false;
}





Scroller.prototype.doDrag= function(e) {


        //this.init_sizes_just_size();


	if (!e) e = window.event
	var obj = Scroller.current;

	var now = (new Date()).getTime()

        //NOTE: toggle this for how often the scroll bar is updated.
        //  make it higher for slower computers.
        if (now - obj.last_moved < 50) {
            return false;
        } else {
            obj.last_moved = now;
        }


	var ey = (e.pageY ? e.pageY : e.clientY)
	var dy = ey - obj.thumb.dragLastY

	var ny = parseInt(obj.thumb.style.top) + dy
	if (ny >= obj.thumbMax) obj.thumb.dragLastY = obj.thumbMax + obj.thumb.dragStartOffset
	else if (ny < 0) obj.thumb.dragLastY = obj.thumb.dragStartOffset
	else obj.thumb.dragLastY = ey

        // make sure it doesn't go over the top.
        if(ny <0) {
            ny = 0;
        } else if (ny > obj.thumbMax) {
            ny = obj.thumbMax;
        }

        if(obj.get_scrollH() != obj.scrollH) {
            obj.scrollH = obj.get_scrollH();
        }

        amount = ny * obj.scrollH / obj.thumbMax
        obj.jumpTo(amount);
	//obj.thumb.style.top	= parseInt( Math.round(amount * obj.thumbMax / obj.scrollH) )
	//obj.content.style.top	= -parseInt( amount );


	return false;
}


Scroller.prototype.scrollDy = function(dy) {
    var obj = Scroller.current;

    var ny = parseInt(obj.thumb.style.top) + dy
    // make sure it doesn't go over the top.
    if(ny <0) {
        ny = 0;
    } else if (ny > obj.thumbMax) {
        ny = obj.thumbMax;
    }

    if(obj.get_scrollH() != obj.scrollH) {
        obj.scrollH = obj.get_scrollH();
    }


    amount = ny * obj.scrollH / obj.thumbMax

    obj.thumb.style.top	= parseInt( Math.round(amount * obj.thumbMax / obj.scrollH) )
    obj.content.style.top	= -parseInt( amount );
}

Scroller.prototype.scrollUp = function(e) {
    if (!e) e = window.event
    Scroller.current = this.obj
    var obj = Scroller.current;
    // make the up arrow depressed.
    obj.up.innerHTML = obj.up.innerHTML.replace("scroller-up.gif", "scroller-up-pressed.gif");
    obj.scrollTo(0);
}
Scroller.prototype.scrollDown = function(e) {
    if (!e) e = window.event
    Scroller.current = this.obj
    var obj = Scroller.current;

    // make the down arrow depressed.
    obj.down.innerHTML = obj.down.innerHTML.replace("scroller-down.gif", "scroller-down-pressed.gif");

    if(obj.get_scrollH() != obj.scrollH) {
        obj.scrollH = obj.get_scrollH();
    }

    var ny = obj.scrollH;
    obj.scrollTo(ny);
}

Scroller.prototype.endScroll = function(e) {
    if (!e) e = window.event

    // if this event is called from a scroller, set it as the current one.
    if(this.obj) {
        Scroller.current = this.obj;
    }
    var obj = Scroller.current;
    obj.down.innerHTML = obj.down.innerHTML.replace("scroller-down-pressed.gif", "scroller-down.gif");
    obj.up.innerHTML = obj.up.innerHTML.replace("scroller-up-pressed.gif", "scroller-up.gif");

    //obj.jumpTo(this.endPos)
    if(obj.aniTimer) {
        obj.aniTimer = window.clearInterval(obj.aniTimer)
    }
}



Scroller.prototype.stopDrag = function(e) {
        // make sure it gets to move in the last bit.
        this.onmousemove(e);
	this.onmousemove = null
	this.onmouseup   = null
}

Scroller.prototype.scrollTo = function(ny) {

        if(this.get_scrollH() != this.scrollH) {
            this.scrollH = this.get_scrollH();
        }


	this.endArrow = Math.round(ny * this.markersMax / this.scrollH)
	this.startTime = (new Date()).getTime()
	this.startPos = parseInt(this.content.style.top) * -1
	this.endPos = ny
	this.dist = this.endPos - this.startPos
	this.accel = this.dist / Scroller.aniLen / Scroller.aniLen
	if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer)
	this.aniTimer = window.setInterval(this.gRef + ".scroll()", 10)
}

Scroller.prototype.scroll = function() {
	var now = (new Date()).getTime()
	var elapsed = now - this.startTime
	if (elapsed > Scroller.aniLen) {
            this.endScroll()
        } else {
		var t = Scroller.aniLen - elapsed
		var ny = this.endPos - t * t * this.accel
		this.jumpTo(ny)
	}
}


Scroller.prototype.jumpTo = function(ny) {

        if(this.content.offsetHeight < this.container.offsetHeight){
            // content is smaller than scrollable area.  don't scroll.
            return;
        }

        if(this.get_scrollH() != this.scrollH) {
            this.scrollH = this.get_scrollH();
        }
 
	this.thumb.style.top	= Math.round(ny * this.thumbMax / this.scrollH)
	this.content.style.top	= -ny
}


function ypGetChildNodes(objParent) {
	return (objParent.childNodes ? objParent.childNodes : objParent.children)
}

function ypGetElementById(id) {
	return (document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : false)
}

function ypGetDescendantsByTagName(sTag, objParent) {
	return (objParent.getElementsByTagName ? objParent.getElementsByTagName(sTag) : objParent.all && objParent.all.tags ? objParent.all.tags(sTag) : false)
}
function Event(shortName,description,linkTo,linkToText,active,id) {
  this.shortName = shortName;
  this.description = description;
  this.linkTo = linkTo;
  this.linkToText = linkToText;
  this.active = active;
  this.id = id;
}
function TimesEvent(start_date,end_date,id) {
  this.start_date = start_date;
  this.end_date = end_date;
  this.id = id;
}
function PricesEvent(description,price,id) {
  this.description = description;
  this.price = price;
  this.id = id;
}
function Location(streetNumber,streetName,streetType,cityName,suburb,postCode,stateCode,countryCode,id) {
  this.streetNumber = streetNumber;
  this.streetName = streetName;
  this.streetType = streetType;
  this.cityName = cityName;
  this.suburb = suburb;
  this.postCode = postCode;
  this.stateCode = stateCode;
  this.countryCode = countryCode;
  this.id = id;
}
function Venue(shortName,description,linkTo,linkToText,active,directions,bandBookPhone,phone,id) {

  this.shortName = shortName;
  this.description = description;
  this.linkTo = linkTo;
  this.linkToText = linkToText;
  this.active = active;
  this.directions = directions;
  this.bandBookPhone = bandBookPhone;
  this.phone = phone;
  this.id = id;
}
function Genre(name,id) {
  this.name = name;
  this.id = id;
}
function News(shortName,description,body,linkTo,linkToText,id) {
  this.shortName = shortName;
  this.description = description;
  this.body = body;
  this.linkTo = linkTo;
  this.linkToText = linkToText;
  this.id = id;
}
function Review(shortName,description,id) {
  this.shortName = shortName;
  this.description = description;
  this.id = id;
}
function User(username,password,email,id) {
  this.username = username;
  this.password = password;
  this.email = email;
  this.id = id;
}
function Role(name,id) {
  this.name = name;
  this.id = id;
}
function Change(whenChanged,id) {
  this.whenChanged = whenChanged;
  this.id = id;
}
function ChangeReview(whenChanged,id) {
  this.whenChanged = whenChanged;
  this.id = id;
}
function ChangeNews(whenChanged,id) {
  this.whenChanged = whenChanged;
  this.id = id;
}
function ChangeEvent(whenChanged,id) {
  this.whenChanged = whenChanged;
  this.id = id;
}
function ChangeVenue(whenChanged,id) {
  this.whenChanged = whenChanged;
  this.id = id;
}

/*
**   Copyright (C) 2004, 2005, 2006, 2007 Rene Dudfield.
*/


// We have some constants for the scroller positions and sizes.
// NOTE: there are some style sheet parts that need to change for width too.
//    div.small
// If you want to change the height... you need to change:
//   tabs2_body_td and tabs1_body_td in the index.html



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

    var width_height = new Array(myWidth, myHeight);
    return width_height;
}


// these are the original sizes.  The expected sizes.
T_ORIGINAL_SCROLLER_WIDTH= 377;
T_ORIGINAL_SCROLLER_HEIGHT= 400;

// these are the current sizes.
T_SCROLLER_WIDTH= T_ORIGINAL_SCROLLER_WIDTH;
T_SCROLLER_HEIGHT= T_ORIGINAL_SCROLLER_HEIGHT;
T_SCROLLER_TOP_HALF_HEIGHT = 223;
T_SCROLLER_BOTTOM_TOP_DIFF = 20;
T_SCROLLER_BOTTOM_HALF_HEIGHT = T_SCROLLER_HEIGHT - T_SCROLLER_TOP_HALF_HEIGHT - 20;

TAB_BODY_HEIGHT= T_SCROLLER_HEIGHT;
TAB_BODY_WIDTH = T_SCROLLER_WIDTH - 4;

T_DO_RESIZE_WINDOW_HEIGHT = 1;

function change_tab_size(width, height) {
    //NOTE: this is not working... need to have some tab resizing code.
    var el1 = getElement('tabs1_body_td');
    var el2 = getElement('tabs2_body_td');

    if(!el1 || !el2) {
        setTimeout("change_tab_size(" + width + "," + height + ")", 30);
        return;
    }



    T_SCROLLER_WIDTH= width;
    T_SCROLLER_HEIGHT= height;
    T_SCROLLER_TOP_HALF_HEIGHT = 223;
    T_SCROLLER_BOTTOM_TOP_DIFF = 20;
    T_SCROLLER_BOTTOM_HALF_HEIGHT = T_SCROLLER_HEIGHT - T_SCROLLER_TOP_HALF_HEIGHT - 20;

    TAB_BODY_HEIGHT= T_SCROLLER_HEIGHT;
    TAB_BODY_WIDTH = T_SCROLLER_WIDTH - 4;
    el1.style.height = height + "px";
    //el.style.width= width + "px";
    el2.style.height = height + "px";

    if(0) {
        setTimeout("tabs1.position_tabs()",105);
        setTimeout("tabs2.position_tabs()",105);
        setTimeout("tabs3.position_tabs()",105);
        setTimeout("tabs5.position_tabs()",105);
        setTimeout("tabs7.position_tabs()",105);
        setTimeout("tabs9.position_tabs()",105);
    }

}

// should we change the window size?
if(T_DO_RESIZE_WINDOW_HEIGHT) {


    var width_height = get_window_width_height();
    var wwidth = width_height[0];
    var wheight = width_height[1];
    var space_at_bottom = 20;
    var total_pp_height = 560;

    if (wheight > (total_pp_height + space_at_bottom)) {
        change_tab_size(T_SCROLLER_WIDTH, T_SCROLLER_HEIGHT + (wheight - (total_pp_height + space_at_bottom)));
    }
}



function getElement(id) {
    return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null;
}

function getRealLeft(id) {
    var el = getElement(id);
    if (el) {
        xPos = el.offsetLeft;
        tempEl = el.offsetParent;
        while (tempEl != null) {
            xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
        return xPos;
    }
}

function getRealTop(id) {
    var el = getElement(id);
    if (el) {
        yPos = el.offsetTop;
        tempEl = el.offsetParent;

        while (tempEl != null) {
            yPos += tempEl.offsetTop;
            tempEl = tempEl.offsetParent;
        }
        return yPos;
    }
}



function getRealRight(id) {
    return getRealLeft(id) + getElement(id).offsetWidth;
}

function getRealBottom(id) {
    return getRealTop(id) + getElement(id).offsetHeight;
}



function move_to_bot_center(mover_id, fixer_id) {
    var el = getElement(mover_id);
    if (el) {
        var fix_bot = getRealBottom(fixer_id);
        var fix_lt = getRealLeft(fixer_id);
        el.style.left = (fix_lt + getElement(fixer_id).offsetWidth/2) - (el.offsetWidth/2);
        el.style.top = fix_bot;
    }
}

function move_to_rt_center(mover_id, fixer_id) {
    var el = getElement(mover_id);
    if (el) {
        var fix_top = getRealTop(fixer_id);
        var fix_rt = getRealRight(fixer_id);
        el.style.left = fix_rt;
        el.style.top = (fix_top + getElement(fixer_id).offsetHeight/2) - (el.offsetHeight/2);
    }
}


function displayAbsPos(id) {
    var el = getElement(id);

    if (el) {
        var trueX = getRealLeft(id);
        tab_headers[i] = txtlyr;
        tab_header_text = '<a href="#" onClick="set_visible_tabidx(' + i +')">' + div_name + '</a>';
        tab_headers[i].setHTML(tab_header_text)
        var trueY = getRealTop(id);
        var aStr = 'Absolute X: ' + trueX + 'px\nAbsolute Y: '+ trueY + 'px\n';
        aStr += 'Absolute Right: ' + (trueX + el.offsetWidth) + 'px\n';
        aStr += 'Absolute Bottom: ' + (trueY + el.offsetHeight) + 'px';
        alert(aStr);
    }
}













function changeColour(newColour, the_id)  {    
    getElement(the_id).style.background = newColour;  
}



// ------------------------------------------------------------------
//   DATA.

function set_visible_tabidx(tabidx) {
    // sets the tab with the tabidx visible.  
    //   The current visible on invisible.  
    // Could also make the tab header highlighted.


    // make sure the index given is within bounds.  otherwise return.
    if(tabidx < 0 || tabidx >= this.tab_bodies.length) {
        alert("invalid tabidx error: " + tabidx);
        return;
    }

    // highlight tab header.
    if(this.tab_bodies[this.current_visible_tab_idx]) {
        this.tab_bodies[this.current_visible_tab_idx].setVisible(0);

        var tab_headerlyr = this.tab_headers[this.current_visible_tab_idx];
        tab_header_text = this.make_header_text(tab_headerlyr.tab_label, tab_headerlyr.tab_header_class_name, tab_headerlyr.closable, false, this.current_visible_tab_idx);
        tab_headerlyr.setHTML(tab_header_text);

    } else {
        this.current_visible_tab_idx = 0;
    }

    if(this.current_visible_tab_idx == tabidx) {
        //TODO: clicking on an allready visible tab.  So we reload it.
        // TODO: call a get content callback...
        if(this.tab_bodies.length != 1) {
            var stuff = this.tab_bodies[this.current_visible_tab_idx].get_tabbody_obj.callback(this.current_visible_tab_idx);
            this.tab_bodies[this.current_visible_tab_idx].setHTML( stuff[0] );

            var after_adding_func = stuff[1];
            after_adding_func();
        }
        

        //scroller_layer_id = "scroller" + this.tab_bodies[this.current_visible_tab_idx].id;
        //this.tab_bodies[this.current_visible_tab_idx].scroller = new Scroller(scroller_layer_id);
        //this.tab_bodies[this.current_visible_tab_idx].scroller.init_scroll(scroller_layer_id);


    }

    // this is highlighting a tab.  Need to regenerate the html for it.
    this.current_visible_tab_idx = tabidx;
    this.tab_bodies[this.current_visible_tab_idx].setVisible(1);

    var tab_headerlyr = this.tab_headers[this.current_visible_tab_idx];
    tab_header_text = this.make_header_text(tab_headerlyr.tab_label, tab_headerlyr.tab_header_class_name, tab_headerlyr.closable, true, this.current_visible_tab_idx);
    tab_headerlyr.setHTML(tab_header_text);


    //this.tab_headers[this.current_visible_tab_idx].setBgColor(this.tab_header_color);

    this.set_extra_bits_for_visible_tab(tabidx);
}

//TODO FIXME: swap around registered functions when they change tabidx.

function set_extra_bits_for_visible_tab(tabidx) {
    // sets any extra things for the visible tab.
    // run any registered functions for the tabs.
    if(tabidx < 0) {
        alert("note: invalid tab idx.");
    }


    var tab_top = this.tab_bodies[tabidx].get_tabbody_obj.get_tab_top();
    var tab_bottom = this.tab_bodies[tabidx].get_tabbody_obj.get_tab_bottom();


    var the_id = this.tab_body_id + '_top';
    el = getElement(the_id);
    if (!el) {
        setTimeout(this.tab_instance_name + ".set_extra_bits_for_visible_tab(" + tabidx + ")");
        return;
    }
    el.innerHTML = tab_top;
    
    var the_id = this.tab_body_id + '_bottom';
    el = getElement(the_id);
    if (!el) {
        setTimeout(this.tab_instance_name + ".set_extra_bits_for_visible_tab(" + tabidx + ")");
        return;
    }
    el.innerHTML = tab_bottom;

    // we try and set some strips at the bottom of the page.
    cn = this.tab_headers[tabidx].tab_header_class_name;
    this.set_strips(cn);
}



function set_strips(class_name) {
    var theid = this.tab_body_id.replace("body", "") + 'bottom_border';
    el = getElement(theid);
    if(!el) {
        // try again later, as the page may not have finished loading.
        setTimeout(this.tabs_instance_name +".set_strips('" + class_name + "')",37);
        return
    }
    bottom_html = '<table width="100%"  border="0" cellpadding="0" cellspacing="0"> <tr> <td class="button4_strip"><img src="images/spacer.gif" width="1" height="4" border="0" alt=""></td> </tr> </table>';

    el.innerHTML = bottom_html.replace('button4_strip', class_name + '_strip');

    var the_id = this.tab_body_id.replace("body", "") + 'border';

    el = getElement(the_id);
    bottom_html = '<table width="100%"  border="0" cellpadding="0" cellspacing="0"> <tr> <td class="button4_strip"><img src="images/spacer.gif" width="1" height="4" border="0" alt=""></td> </tr> </table>';

    el.innerHTML = bottom_html.replace('button4_strip', class_name + '_strip');

}


function get_next_tab_idx() {
    // returns the next available tab index.  Or returns a negative if there 
    //   are none.
    if (this.current_visible_tab_idx == this.tab_bodies.length - 1) {
        r = this.tab_bodies.length - 2;
    } else {
        r = this.tab_bodies.length - 1;
    }


    // do a find for the next one...  if the previous one is not there.


    if(r >= 0 && !this.tab_bodies[r]) {
        found_one = false;
        var i;
        for(i=r; i >= 0; i--) {
            if(this.tab_bodies[i] != false){
                if(i != this.current_visible_tab_idx) {
                    r = i;
                    found_one = true;
                    break;
                }
            }
        }
        if(!found_one) {
            r = -1;
        }
    }


    return r;
}


function make_header_text(tab_label, tab_header_class_name, closable, selected, i) {

    //tab_header_class_name = 'button3-selected';
    //number = tab_header_class_name[tab_header_class_name.length-1];


    number = tab_header_class_name.substr(tab_header_class_name.length-1, tab_header_class_name.length);


    if(selected) {
        the_tab_header_class_name = tab_header_class_name + '-selected';
        class_text = "basebutton" + number;
    } else {
        the_tab_header_class_name = tab_header_class_name;
        class_text = "basebutton" + number;
    }




    tab_header_text ='';
    //tab_header_text +='<img src="images/spacer.gif" width="1" height="4" border="0" alt="">';
    tab_header_text +='<table cellpadding="0" cellspacing="0" border="0" class="' + class_text + '">';

    tab_header_text +='      <tr>';
    tab_header_text +='        <td class="tborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    if(closable) {
     tab_header_text+='        <td colspan="2" class="tborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    } else {
     tab_header_text+='        <td class="tborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    }

    tab_header_text +='        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    tab_header_text +='      </tr>';
    tab_header_text +='      <tr>';
    tab_header_text +='        <td width="1" class="mborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    tab_header_text +='<td id="label_header_';
    tab_header_text += i;
    tab_header_text += '" class="' + the_tab_header_class_name + '">';
    tab_header_text +='<a href="#" class="';
    tab_header_text += the_tab_header_class_name;
    tab_header_text += '"';
    tab_header_text += ' onClick="';
    tab_header_text += this.tabs_instance_name;
    tab_header_text +='.set_visible_tabidx(' + i +')"';
    tab_header_text += '>' + tab_label;
    tab_header_text +='&nbsp;&nbsp;&nbsp;</a></td>';

    // The close button.
    if(closable) {
        tab_header_text += '<td id="closable_header_';
        tab_header_text += i;
        tab_header_text += '"><a href="" class="';
        tab_header_text += tab_header_class_name + 'x';
        if(selected) {
            tab_header_text += '-selected';
        }

        //tab_header_text +='">&nbsp;&nbsp;&nbsp;</a></td>';
        tab_header_text += '"';
        tab_header_text += ' onClick="return ';
        tab_header_text +=  this.tabs_instance_name;
        tab_header_text += '.remove_tab(' + i +')"';
        tab_header_text += '>&nbsp;&nbsp;&nbsp;</a></td>';

        //TODO: add the actual close button in there.
        //tab_header_text += '&nbsp;&nbsp;<a href="#" onClick="';
        //tab_header_text +=  this.tabs_instance_name;
        //tab_header_text += '.remove_tab(' + i +')">' + this.tab_close_text+ '</a>';

    }

    tab_header_text +='        <td width="1" class="mborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    tab_header_text +='      </tr>';


    if(selected) {

        tab_header_text +='      <tr>';

        tab_header_text +='        <td class="tborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';



        tab_header_text+='        <td '; 
        if(closable) {
            tab_header_text+=' colspan="2" '; 
        }

        if(selected) {
            tab_header_text+=' class="' + tab_header_class_name +'-selectedbg"'; 
        } else {
            tab_header_text+=' class="tborder"'; 
        }

        tab_header_text+='><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';

        tab_header_text +='        <td class="tborder"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
        tab_header_text +='      </tr>';
    }
    tab_header_text +='    </table>';


    return tab_header_text;
}



// -------------------------------------------
// Dyn replacements.

function PpObject() {
    this.id = "PpObject_"+PpObject._c++;
    PpObject.all[this.id] = this;
};
PpObject.all = [];
PpObject._c = 0;


function PpLayer(html,x,y,w,h,color,image) { 
    //this.DynLayer = DynLayer;
    //this.DynLayer();

    this.id = "PpObject_"+PpObject._c++;
    PpObject.all[this.id] = this;
};



function removeChild(alayer) {
    //
    if( document.layers && window.Layer && document.classes ) {
        alert("not implemented here line 798539");
    } else {
        //r = document.body.removeChild(alayer);
        document.body.removeChild(alayer.thediv);
    }
}


//PpLayer = DynLayer;
function addChild(alayer, html, xpos, ypos, visibility) {
    // create the layer.

    // set the x,y,w,h,color.

    //layerid = 'eeeeeee' + alayer.id;
    layerid = alayer.id;


    if( document.layers && window.Layer && document.classes ) {
      //create a layer 350px wide
      document.layers[layerid] = new Layer();
      //write its content
      //document.layers[layerid].document.open();
      //document.layers[layerid].document.write(alayer.html);
      //document.layers[layerid].document.close();
      //style it
      document.layers[layerid].left = xpos;
      document.layers[layerid].top = ypos;
      document.layers[layerid].visibility = 'hidden';
    } else {
        //var div = document.createElement('div'); document.body.appendChild(div); div.appendChild(document.createTextNode('foo'));
        var div = document.createElement('div'); 
        div.id = layerid;
        //div.style.visibility = 'inherit';

        // we create it invibile no matter what.
        div.style.visibility = 'hidden';
        div.style.position = "absolute";
        div.style.left = xpos + "px";
        div.style.top= ypos + "px";
        div.innerHTML = html;

        document.body.appendChild(div); 
        alayer.thediv = div;
        div.style.visibility = visibility;


        //div.appendChild(document.createTextNode('foo'));

        if(0){
            if( document.body ) {
              var theString = '<div style="position:absolute;left:0px;top:0px;" id ="' + layerid + '></div>';
              if( document.body.insertAdjacentHTML ) {
                document.body.insertAdjacentHTML( 'beforeEnd', theString );
              } else if( typeof( document.body.innerHTML ) != 'undefined' ) {
                document.body.innerHTML += theString;
              } else {
                //FAILURE, nothing works
              }
            } else {
              alert("can not make layer");
            }
        }
    }
}


//PpLayer.prototype = new DynLayer;

PpLayer.prototype.setHTML = function (html) {
    el = getElement(this.id);
    el.innerHTML = html;
};

PpLayer.prototype.setLocation = function (x,y) {

    el = getElement(this.id);
    el.style.left = x + "px";
    el.style.top = y + "px";

    var cx = (x!=null && x!=this.x);
    var cy = (y!=null && y!=this.y);

//	if (cx) this.x = x||0;
//	if (cy) this.y = y||0;
//	if (this.css!=null) {
//		if (cx) this.css.left = this.x+"px";
//		if (cy) this.css.top = this.y+"px";
//		// adjust parent size after being moved
//		//if((cx||cy) && this.parent._aSz) this.parent._adjustSize();
//	}
//	//if(this._hasLocationEvents) this.invokeEvent('locationchange');
    return (cx||cy);
};


PpLayer.prototype.setSize= function (width, height) {

    el = getElement(this.id);
    el.style.height = height + "px";
    el.style.width= width + "px";

};

PpLayer.prototype.setVisible= function (vis) {

    el = getElement(this.id);
    if(vis) {
        el.style.visibility= "inherit";
    } else {
        el.style.visibility= "hidden";
    }

};

function setVisible_id (id, vis) {

    el = getElement(id);
    if(vis) {
        el.style.visibility= "inherit";
    } else {
        el.style.visibility= "hidden";
    }
};
    






function get_login_box_html(num_users, status_message) {
    var login_box_html = '<form>\n       <table width=\"97%\" height=\"58\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n        <tr>\n          <td width=\"25%\" align=\"left\"><div id=\"username_div\"><input id=\"pp_username\" name=\"username\" type=\"text\" class=\"frm-input-login\" value=\"username\"></div></td>\n          <td width=\"25%\" align=\"left\"><div id=\"password_div\"><input id=\"pp_password\" name=\"password\" type=\"password\" class=\"frm-input-login\" value=\"password\"></div></td>\n          <td align=\"right\" valign=\"middle\">\n            <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"basebutton-default\">\n              <tr>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n              <tr>\n                <td width=\"1\" class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td align=\"right\"><a href=\"\" onclick=\"return login();\" class=\"default\">&nbsp;LOGIN&nbsp;&nbsp;</a></td>\n                <td width=\"1\" class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n              <tr>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n          </table>\n          </td>\n        </tr>\n        <tr>\n          <td colspan=\"2\" align=\"left\">users: ';
    login_box_html += num_users;
    login_box_html += '</td>\n          <td align=\"right\"><a href=\"#\" onclick=\"return new_user_tab();\">new user</a> </td>\n        </tr>\n        <tr>\n          <td colspan=\"3\" align=\"left\"><div id=\"status_bar\">';
    login_box_html += status_message;
    login_box_html += '</div></td>\n        </tr>\n    </table>\n    </form>\n';

    return login_box_html;
}

function get_logout_box_html(username, num_users, status_message) {
    var logout_box_html = '<table width=\"97%\" height=\"58\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n        <tr>\n          <td align=\"left\">user: <a href=\"#\" class=\"adminlink\">';
    logout_box_html += username;
    logout_box_html += '</a></td>\n          <td colspan=\"3\" align=\"right\" valign=\"middle\">\n            <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"basebutton-default\">\n              <tr>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n              <tr>\n                <td width=\"1\" class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                ';
    logout_box_html += '<td align=\"right\"><a href=\"\" onclick=\"return logout();\" class=\"default\">&nbsp;LOGOUT&nbsp;&nbsp;</a></td>\n                <td width=\"1\" class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n              <tr>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                ';
    logout_box_html += '<td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n                <td class=\"corner\"><img src=\"images/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>\n              </tr>\n          </table>\n          </td>\n        </tr>\n        <tr>\n          <td colspan=\"2\" align=\"left\">';
    //logout_box_html += num_users;
    logout_box_html += '</td>\n        ';
    logout_box_html += '<td align=\"right\"><a href=\"#\"  onclick=\"return admin_tab();\">admin stuff</a></td>';
    logout_box_html += '</tr>\n        <tr>\n          <td colspan=\"3\" align=\"left\"><div id=\"status_bar\">';
    logout_box_html += status_message;
    logout_box_html += '</div></td>\n        </tr>\n    </table>';

    return logout_box_html;
}

function check_login_status_update_loginbox() {
    // Check to see if the session is still valid.
    var logged_in = check_logged_in_session();
    if(logged_in) {
        // we set the box as logged in.
        // set the box to display their user name and stuff.
        var status_message = "&nbsp;";
        var num_users = "";
        var lout_html=get_logout_box_html(username, num_users, status_message);
        var el = getElement("login_nothing");
        el.innerHTML = lout_html;

        if(1) {
            var el = getElement("admin_stuff");
            var stuff = '';
            stuff += '<a href="#" onclick="return view_edit_screens(false, \'Event\');">new event</a><br>';
            //stuff += '<a href="#" onclick="return view_edit_screens(1, \'Event\');">edit test</a>';
            //stuff += '<br><a href="#" onclick="return event_tab_search(' + "'jam'" + ');">extra tab test</a>';
            //stuff += '<br><a href="#" onclick="return change_tab_size(377, 480);">change_tab_size test 377, 480</a>';

            el.innerHTML = stuff;
        }



        return true;
    } else {
        // not logged in.
        var el = getElement("login_nothing");
        var status_message = "&nbsp;";
        var num_users = "";
        var lin_html=get_login_box_html(num_users, status_message);
        el.innerHTML = lin_html;
        
        var el = getElement("status_bar");
        el.innerHTML = "&nbsp;";
    }
}

function set_login_box(wait_time) {
    // detects what to use as the login box.
    username = pp_getCookie("username");
    if(username) {


        var status_message = "checking your login status...";
        el = getElement("status_bar");
        if(el) {
            el.innerHTML = status_message;
        } else {
            el = getElement("login_nothing");
            if(el) {
                var num_users = "";
                var lin_html=get_login_box_html(num_users, status_message);
                el.innerHTML = lin_html;
            } else {
                // probably not loaded yet, try again in a little bit.
                setTimeout("set_login_box(" + wait_time+ ")",105);
                return;
            }
        }

        // check the login in the background.
        setTimeout("check_login_status_update_loginbox()",wait_time);

        //TODO: test this login updates after 0.105 seconds.

        return true;
    }
    
    // not logged in.
    el = getElement("login_nothing");
    if(el) {
        var status_message = "&nbsp;";
        var num_users = "";
        var lin_html=get_login_box_html(num_users, status_message);
        el.innerHTML = lin_html;
        
        el = getElement("status_bar");
        el.innerHTML = "&nbsp;";
    } else {
        setTimeout("set_login_box(" + wait_time+ ")",35);
    }
    
    return true;
}



function make_scroller_html(content_html, anid_prefix, height, width, top, left) {
    // applies a scroller to the given layer.
    // anid - an id for the scroller to be in.

    // old widths 290 254

    var scrollbar_width = 11;
    top += 5;
    left += 5;
    width -= 6;
    height -= 10;

    top_html = '<div id="filter" style="position:absolute; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height +'px;">\n\t';

    top_html += '<div id="filterTrack" style="position:absolute; top:10px; z-index:0; left:' + (width-scrollbar_width - 3) + 'px;"><img id="filterTrackImg" src="images/scroller-track.gif" width="'+ scrollbar_width + '" height="' + (height-11) +'" /></div><div id="filterUp" style="position:absolute; top:0px; z-index:2; left:' + (width-scrollbar_width - 3) + 'px;"><img id="filterUpImg" src="images/scroller-up.gif" width="'+ scrollbar_width + '" height="10" /></div><div id="filterDown" style="position:absolute; top:' + (height - 10) + 'px; z-index:3; left:' + (width-scrollbar_width - 3) + 'px;"><img id="filterDownImg" src="images/scroller-down.gif" width="'+ scrollbar_width + '" height="10" /></div>';
    top_html += '<div id="filterScrollBar" style="position:absolute; left:' + (width-scrollbar_width - 3) + 'px; width:'+ scrollbar_width + 'px; height:' + 10 +'px">\n\t\t\t<div id="filterThumbContainer" style="position:absolute; z-index:5; left:0px; top:10px; width:'+ scrollbar_width + 'px; height:' + (height -20)+'px"><div id="filterThumb" style="position:absolute; top:0px; z-index:6;  "><img id="filterThumbImg" src="images/scroller-bar.gif" width="'+ scrollbar_width + '" height="38" /></div></div>\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t</div>';

    //top_html += '<div id="filterContainer" style="position:absolute; width:' + (width - 36) + 'px; height:' + (height-1) +'px; overflow:hidden; clip:rect(0 ' + (width-36) + ' ' + (height-1) +' 0)">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div id="filterContent" style="position:absolute; top:0px">';

    top_html += '<div id="filterContainer" style="position:absolute; width:' + (width - scrollbar_width - 5) + 'px; height:' + (height-1) +'px; overflow:hidden; clip:rect(0 ' + (width-scrollbar_width-5) + ' ' + (height-1) +' 0)">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div id="filterContent" style="position:absolute; top:0px">';
    return top_html.replace(/filter/g, anid_prefix) + content_html + "</div></div></div>";
}




scrollers = new Array();

function place_scroller(content_html, content_id, height, width, top, left, show_thumb) {
    // places the content within a scroller with the given layer id.
    //  content_html - the content inside the scroller.
    //  content_id - the id to put the scroller within.
    //  height of the scroller.
    //  width of the scroller.
    //  show_thumb - should the thumb be shown.

    var el = getElement(content_id);


    var anid_prefix = "scroller" + content_id;
    var scroller_html = make_scroller_html(content_html, anid_prefix, height, width, top, left);

    scrollers[scrollers.length] = new Scroller(anid_prefix);
    scrollers[scrollers.length-1].init_scroll(anid_prefix, show_thumb);

    el.innerHTML = scroller_html;
    
    // returns the index for the new scroller.
    return scrollers.length-1;
}



//TODO: change callback to return two things.  a) html to go into layer. b) function to call afterwards.

function new_tab(tab_label, tab_header_class_name, closable, selected, get_tabbody_obj, max_number_same_tabs, visibility) {
    // 
    // max_number_same_tabs - the number of tabs you can have which are the same.  -1 means unlimited. -2 means replace existing tab.
    // selected - if the tab is selected.
    // closable - if the tab can be closed.
    // get_tab_body_html_callback - function which returns the content for the tab body.

    if(max_number_same_tabs != -1) {
        // see how many other tabs there are with this same label.
        var i = 0;
        var number_of_same_label = 0;
        for(i=0; i < this.tab_headers.length; i++) {
            if(this.tab_headers[i]) {
                if(this.tab_headers[i].tab_label == tab_label) {
                    number_of_same_label++;
                    if(max_number_same_tabs == -2) {
                        // replace the tab with the given one.
                        this.remove_tab(i);
                        var r = this.new_tab(tab_label, tab_header_class_name, closable, selected, get_tabbody_obj, max_number_same_tabs, visibility);
                        this.position_tabs();
                        return r;

                    } else {
                        if(number_of_same_label >= max_number_same_tabs) {
                            this.set_visible_tabidx(i);
                            return -1;
                        }
                    }
                }
            }
        }
    }



    // find a position for in the tab arrays.
    found_one = false;

    var ii;
    for(ii=0; ii < this.tab_headers.length; ii++) {
        if(!this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(found_one) {
        i = ii;
    } else {
        i = this.tab_headers.length;
    }





    // create the header.


    this.tab_close_text = "X";


    //div_name = "tab" + i;





    this.tab_header_width = 50;
    this.tab_header_height= 30;

    //this.tab_spacing = 10;
    this.tab_spacing = 0;




    //tab_headerlyr = new DynLayer();
    tab_headerlyr = new PpLayer();


    tab_headerlyr.closable = closable;
    tab_headerlyr.tab_label= tab_label;
    tab_headerlyr.tab_header_class_name= tab_header_class_name;



    tab_header_text = this.make_header_text(tab_label, tab_header_class_name, closable, selected, i);

    //NOTE TODO: may be able to make a new invisible layer with this html, 
    //   and then see how big it is.  Then set the tab header size.
    //alert(tab_header_text);



    //tab_header_left = getRealLeft(this.tab_headers[i].id)
    //tab_header_right = getRealRight(this.tab_headers[i].id)
    //tab_header_width = tab_header_right - tab_header_left;

    // alert("w: " + w + " x:" + x + " l:" + l + " r:" + r + " this.id:" + this.tab_headers[i].id);
    //tab_headerlyr.setSize(this.tab_header_width, this.tab_header_height);
    // Find the position that the new header should be placed.  
    //  Add up the header widths.
    // NOTE: TODO: depending on how many tabs are visible, and how much room there is, will depend on where it goes.
    //base_x = getRealLeft(this.tab_headers_id) + (i * (this.tab_header_width + this.tab_spacing));

    if(this.tab_headers.length != 0) {
        //thid = this.tab_headers[this.tab_headers.length-1].id;
        var last_idx= this.get_last_tab_idx();
        var thid = this.tab_headers[last_idx].id
        base_x = getRealRight(thid);
    } else {
        base_x = getRealLeft(this.tab_headers_id);
    }



    // count the widths of all, but the current one.  ie where index == -1.
    //for (i=0; i<tabs.tab_headers.length -1; i++) {
    //    thid = tabs.tab_headers[i].id;
    //    tab_header_left = getRealLeft(thid);
    //    tab_header_right = getRealRight(thid);
    //    tab_header_width = tab_header_right - tab_header_left;
    //    base_x += tab_header_width;
    //}

    //base_y = getRealTop(this.tab_headers_id);
    //base_y = getRealTop(this.tab_headers_id) - 1;
    base_y = getRealTop(this.tab_headers_id);

    // make the base_y the bottom of the tab headers.  So take the height of the tab headers from it.

    //alert("tabs.tab_headers.length:" + tabs.tab_headers.length + " base_x:" + base_x);


    addChild(tab_headerlyr, tab_header_text, base_x, base_y, visibility);

    //dynapi.document.addChild(tab_headerlyr);

    //var el = getElement(tab_headerlyr.id);
    //el.ppl = tab_headerlyr;

    


    //tab_headerlyr.setLocation(base_x,base_y);

    this.tab_headers[i] = tab_headerlyr;







    // store the tab_label in the layer.
    this.tab_headers[i].tab_label = tab_label;

    // store it's index in the array.
    this.tab_headers[i].idx = i;
    this.tab_headers[i].tabs_instance_name = this.tabs_instance_name;
    this.tab_headers[i].tabs_instance = this;

    //alert(this.tab_headers[i].id);


//    var el = {
//        onmousedown : function(e) {
//            var s = e.getSource();
//            var b = e.getBubbleChild();
//            var r = e.getRelative();
//            var o = e.getOrigin();
//
//            //s.setBgColor("blue");
//            // TODO: set this tab visible.
//            //  might need to keep an index of where it is in the
//            //   array inside itself.
//            s.tabs_instance.set_visible_tabidx(s.idx);
//        }
//    };

    //TODO: 

    //el = getElement(this.tab_headers[i].id);
    el = getElement("label_header_" + i);
    s = PpObject.all[this.tab_headers[i].id];
    el.s = s;


    /*
    el.onmousedown= function(e) {
                        //alert(this.id);
                        parts = this.id.split("_");
                        last_bit = parts[parts.length -1];
                        //last_bit = last_bit * 1;
                        //s = getElement(this.tab_headers[last_bit].id);
                        s = this.s;

                        //the_PpObject_id = "PpObject_" + last_bit;
                        //alert(":" + the_PpObject_id + ":");

                        //s = PpObject.all[this.tab_headers[last_bit].id];
                        //s = PpObject.all[this.id];
                        //s = PpObject.all[the_PpObject_id];
                        s.tabs_instance.set_visible_tabidx(s.idx);
                    }
    */

    /*
    if(closable) {
        el = getElement("closable_header_" + i);
        s = PpObject.all[this.tab_headers[i].id];
        el.s = s;

        el.onmousedown= function(e) {
                            alert("uuuuuuuuuuuuuiiiiiiii");
                            //s = PpObject.all[this.id];
                            s = this.s;
                            s.tabs_instance.remove_tab(s.idx);
                        }
    }

    */

    //this.tab_headers[i].addEventListener(el);




    //tab_header_text = '<a href="#" onClick="';
    //tab_header_text +=  this.tabs_instance_name;
    //tab_header_text += '.set_visible_tabidx(' + i +')">' + tab_label + '</a>';

    //tab_header_text += '&nbsp;&nbsp;<a href="#" onClick="';
    //tab_header_text +=  this.tabs_instance_name;
    //tab_header_text += '.remove_tab(' + i +')">' + this.tab_close_text+ '</a>';


    // Now add the tab bodies.

    base_x = getRealLeft(this.tab_body_id) + 1;
    base_y = getRealTop(this.tab_body_id);


    //tab_bodylyr = new DynLayer();
    tab_bodylyr = new PpLayer();


    //tab_bodylyr.setBgColor(this.tab_body_color);

    // from 370 to 400 height.
    tab_body_height = T_SCROLLER_HEIGHT;
    tab_body_width = T_SCROLLER_WIDTH;

    //scroller_layer_id = "scroller" + tab_bodylyr.id;
    //scroller_html = make_scroller_html(tab_body_html, scroller_layer_id, tab_body_height, tab_body_width);
    //tab_bodylyr.original_tab_body_html = scroller_html;


    tab_bodylyr.get_tabbody_obj = get_tabbody_obj;

    //alert(get_tabbody_obj.theID);
    //alert(get_tabbody_obj.ofwhat);

    // we pass in the index of this tab id.
    var stuff = get_tabbody_obj.callback(i);

    //alert(stuff[0]);

    tab_body_html = stuff[0];
    addChild(tab_bodylyr, tab_body_html, base_x,base_y, visibility);
    //tab_bodylyr.setVisible(0);


    tab_bodylyr.setSize(this.tab_body_width, this.tab_body_height);
    //tab_bodylyr.setLocation(base_x,base_y);

    this.tab_bodies[i] = tab_bodylyr;
    if(!selected) {
        this.tab_bodies[i].setVisible(0);
    } else {
        // set the little strips at the bottom.
        cn = this.tab_headers[i].tab_header_class_name;
        this.set_strips(cn);

    }

    //tab_bodylyr.setVisible(1);


    var after_adding_func = stuff[1];
    after_adding_func();


    this.tab_bodies[i].idx = i;
    if(selected) {
        this.set_visible_tabidx(i);
        //this.tab_bodies[i].setVisible(1);
        //if(this.registered_funcs[tabidx] != null) {
        //    f = this.registered_funcs[tabidx];
        //    f();
        //}
        var noop =1;
    }

    // added tab successfully.
    return i;
}


function remove_tab(idx) {
    // from the index given, remove the tab body, and tab header.


    
    // check to see if this tab is visible.  If so make the next tab visible.
    if(idx == this.current_visible_tab_idx) {
        //this.current_visible_tab_idx = this.get_next_tab_idx();
        vis_idx = this.get_next_tab_idx();
        //this.current_visible_tab_idx = vis_idx;
        if(vis_idx >= 0) {
            this.set_visible_tabidx(vis_idx);
        }
    }

    if(this.tab_bodies[idx]) {
        t = this.tab_bodies[idx];
        //dynapi.document.removeChild(t);
        removeChild(t);
        this.tab_bodies[idx] = false;
        //delete this.tab_bodies[idx];
    }
    
    if(this.tab_headers[idx]) {
        t = this.tab_headers[idx];
        //dynapi.document.removeChild(t);
        removeChild(t);
        this.tab_headers[idx] = false;
        //delete this.tab_headers[idx];
    }

    this.reshuffle_tabs();
    this.position_tabs();
    return false;
}


function swap_tabs(aidx, bidx) {
    // swap a and b tabs over.  note neither one need be a valid tab.

    // swap the places in the array over.
    a_header = this.tab_headers[aidx];
    a_body = this.tab_bodies[aidx];
    this.tab_headers[aidx] = this.tab_headers[bidx];
    this.tab_bodies[aidx] = this.tab_bodies[bidx];

    this.tab_headers[bidx] = a_header;
    this.tab_bodies[bidx] = a_body;
    
    //reset their index.
    this.tab_headers[bidx].idx = bidx;
    this.tab_bodies[bidx].idx = bidx;

    this.tab_headers[aidx].idx = aidx;
    this.tab_bodies[aidx].idx = aidx;



    // reposition them based on their index.
    if(this.tab_headers[aidx]) {
        this.position_tab_header_on_index(this.tab_headers[aidx], aidx);
    }
    if(this.tab_headers[bidx]) {
        this.position_tab_header_on_index(this.tab_headers[bidx], bidx);
    }

    // see if we need to swap over the currently selected tab.
    if(this.current_visible_tab_idx == aidx) {
        this.current_visible_tab_idx = bidx;
    } else if(this.current_visible_tab_idx == bidx) {
        this.current_visible_tab_idx = aidx;
    }

    // update the links with new index.
    if(this.tab_headers[aidx]) {
        this.set_tab_header_links(this.tab_headers[aidx], aidx);
        var selected = this.current_visible_tab_idx == aidx;

        var tab_headerlyr = this.tab_headers[aidx];
        tab_header_text = this.make_header_text(tab_headerlyr.tab_label, tab_headerlyr.tab_header_class_name, tab_headerlyr.closable, selected, aidx);
        tab_headerlyr.setHTML(tab_header_text);
    }
    if(this.tab_headers[bidx]) {
        this.set_tab_header_links(this.tab_headers[bidx], bidx);
        var selected = this.current_visible_tab_idx == bidx;

        var tab_headerlyr = this.tab_headers[bidx];
        tab_header_text = this.make_header_text(tab_headerlyr.tab_label, tab_headerlyr.tab_header_class_name, tab_headerlyr.closable, selected, bidx);
        tab_headerlyr.setHTML(tab_header_text);
    }


}

function get_previous_tab_idx(i) {
    // 

    var ii;
    var length = this.tab_headers.length;
    var found_one = false;

    for(ii=i-1; ii >= 0; ii--) {
        if(this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(found_one) {
        return ii;
    } else {
        // start looking from the end.

        for(ii=this.tab_headers.length-1; ii > i; ii--) {
            if(this.tab_headers[ii]) {
                found_one = true;
                break;
            }
        }
        if(found_one) {
            return ii;
        }
    }

    return -1;
}


function get_last_tab_idx() {
    // returns the last tab index.

    //return this.get_previous_tab_idx(this.tab_headers.length);


    var ii;
    var length = this.tab_headers.length;
    var found_one = false;

    if (length == 1) {
        if(this.tab_headers[0]) {
            return 0;
        } else {
            return -1;
        }
    }

    for(ii=length-1; ii > 0; ii--) {
        //alert(ii);
        if(this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(found_one) {
        return ii;
    } else {
        if(this.tab_headers[0]) {
            return 0;
        } else {
            return -1;
        }
    }

    return -1;
}


function get_next_tab_idx_new(i) {
    // finds the next valid tab from the given one.  or false if there are no other valid ones.
    //  loops over the array, and cycles to the begining.

    var ii;
    var length = this.tab_headers.length;
    var found_one = false;

    for(ii=i+1; ii < this.tab_headers.length; ii++) {
        if(this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(found_one) {
        return ii;
    } else {
        // start looking from the begining.

        for(ii=0; ii < this.tab_headers.length; ii++) {
            if(this.tab_headers[ii]) {
                found_one = true;
                break;
            }
        }
        if(found_one) {
            return ii;
        }
    }

    return -1;
}



function reshuffle_tabs() {
    // fills the gap in the tabs when a tab is removed by 
    // shuffling ones to the right over one.

    //NOTE: a better way might be to create a new array rather than swapping.
    
    found_one = false;

    var ii;
    for(ii=0; ii < this.tab_headers.length; ii++) {
        if(!this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(!found_one) {
        // nothing to do.
        return;
    } else {
        missing_idx = ii;
        // move everything on the right over by one.
        for(ii=missing_idx; ii < this.tab_headers.length; ii++) {
            if(!this.tab_headers[ii]) {
                if(this.tab_headers[ii+1]) {
                    // move the tab at ii+1 to ii.
                    this.swap_tabs(ii+1, ii);
                }
            }
        }
        
    }
    
    
}

function position_tab_header_on_index(tlyr, i) {
    base_x = getRealLeft(this.tab_headers_id) + (i * (this.tab_header_width + this.tab_spacing));
    base_y = getRealTop(this.tab_headers_id);
    tlyr.setLocation(base_x,base_y);
    
}

function set_tab_header_links(tlyr, i) {

    tab_header_text = '<a href="#" onClick="';
    tab_header_text +=  this.tabs_instance_name;
    tab_header_text += '.set_visible_tabidx(' + i +')">' + tlyr.tab_label + '</a>';

    tab_header_text += '&nbsp;&nbsp;<a href="#" onClick="';
    tab_header_text +=  this.tabs_instance_name;
    tab_header_text += '.remove_tab(' + i +')">' + this.tab_close_text+ '</a>';
    
    tlyr.setHTML(tab_header_text);
}



function position_tabs() {
    // positions the tabs in the correct places on the window.
    //  Useful for when the window resizes.


    // position the tab headers.
    for(ii=0; ii < this.tab_headers.length; ii++) {
        if(this.tab_headers[ii]) {
            if(ii == 0) {
                var base_x = getRealLeft(this.tab_headers_id);
            } else {
                //thid = tabs.tab_headers[ii-1].id;
                var prev_idx = this.get_previous_tab_idx(ii);
                thid = this.tab_headers[prev_idx].id;
                var base_x = getRealRight(thid);
            }

            var base_y = getRealTop(this.tab_headers_id);
            this.tab_headers[ii].setLocation(base_x,base_y);
        }
    }

    // position the tab bodies.

    for(ii=0; ii < this.tab_bodies.length; ii++) {
        if(this.tab_bodies[ii]) {
            base_x = getRealLeft(this.tab_body_id) + 1;
            base_y = getRealTop(this.tab_body_id);
            this.tab_bodies[ii].setLocation(base_x,base_y);
        }
    }

}








function Tabs(num_tabs, tab_headers_id, tab_body_id, tabs_instance_name, tab_body_height, tab_body_width) {
    this.current_visible_tab_idx = 0;
    this.num_tabs = num_tabs;
    this.tab_headers = new Array();
    this.tab_bodies = new Array();
    this.registered_funcs = new Array();
    this.tab_headers_id = tab_headers_id;
    this.tab_body_id = tab_body_id;
    this.tabs_instance_name = tabs_instance_name;
    this.tab_body_height = tab_body_height;
    this.tab_body_width = tab_body_width;


    // NOTE: these aren't used.
    this.tab_body_color = '#C0C0C0';
    this.tab_header_color = '#B2B2B2';

    this.visible = 0;
}





Tabs.prototype.set_visible_tabidx = set_visible_tabidx;
Tabs.prototype.new_tab = new_tab;
Tabs.prototype.remove_tab = remove_tab;
Tabs.prototype.get_next_tab_idx = get_next_tab_idx;

Tabs.prototype.position_tab_header_on_index= position_tab_header_on_index;
Tabs.prototype.reshuffle_tabs= reshuffle_tabs;
Tabs.prototype.swap_tabs= swap_tabs;
Tabs.prototype.set_tab_header_links= set_tab_header_links;
Tabs.prototype.make_header_text= make_header_text;

Tabs.prototype.position_tabs= position_tabs;
//Tabs.prototype.get_next_tab_idx= get_next_tab_idx;
Tabs.prototype.get_previous_tab_idx= get_previous_tab_idx;
Tabs.prototype.get_last_tab_idx= get_last_tab_idx;
Tabs.prototype.set_extra_bits_for_visible_tab = set_extra_bits_for_visible_tab;
Tabs.prototype.set_strips = set_strips;
Tabs.prototype.setVisible = function (tovisible) {
    // hides all of the tabs.
    var i = 0;
    for(i=0; i<this.tab_headers.length; i++) {
        if(this.tab_headers[i]) {
            this.tab_headers[i].setVisible(tovisible);
        }
    }
    if(this.tab_bodies[this.current_visible_tab_idx]) {
        this.tab_bodies[this.current_visible_tab_idx].setVisible(tovisible);
        if(tovisible) {
            this.set_extra_bits_for_visible_tab(this.current_visible_tab_idx);
        }
    }

    this.visible = tovisible;
}

Tabs.prototype.add_top_bottom_callback= function (tabidx, callback_top, callback_bottom) {
    // fills in the html for the top and bottom tab idx.
    var f = function () {
        var top = callback_top();
        var bottom = callback_bottom();

        return Array(top, bottom);
    }
    this.registered_funcs[tabidx] = f;
}


// finds the first available slot to put a tab in.
Tabs.prototype.find_available_slot= function () {
    var found_one = false;

    var ii;
    for(ii=0; ii < this.tab_headers.length; ii++) {
        if(!this.tab_headers[ii]) {
            found_one = true;
            break;
        }
    }

    if(found_one) {
        var i = ii;
    } else {
        var i = this.tab_headers.length;
    }

    return i;
}









function make_event_edit_html(an_event) {
    // returns the html for a form editing the event.
    id= an_event.id;
    if(!id) {
        id="empty";
    }

    short_name_id = 'Event_shortName_' + eventsID;
    description_id = 'Event_description_' + eventsID;


    //TODO: how are events supposed to be inserted?
    //        probably need to have the event id as some sort of null value.

    // the ids for edit forms will follow a naming convention.
    //   Where it contains the content type, field name, and the content id.


    r = "";
    r += '<form>';
    r += 'short name: <input type="text" name="short_name" value="' + an_event.shortName + '" ';
    r += 'id="' + short_name_id + '">';
    r += 'description: <input type="text" name="description" value="' + an_event.description + '" ';
    r += 'id="' + description_id + '">';
    r += '<br><a href="" onClick="return save_event_from_id(eventsID);">insert event</a>';
    r += '</form>';
    r += "";
    r += '';
    
    return r;
}





//   END DATA.
// ------------------------------------------------------------------




/*

*/


function pp_getCookie(name) { 
    // use: getCookie("name"); 
    var index = document.cookie.indexOf(name + "="); 
    if (index == -1) {
        return null;
    }
    index = document.cookie.indexOf("=", index) + 1;
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(index, endstr));
}

function pp_setCookie(name, value) { 
    // setCookie("name", value); 
    var today = new Date(); 
    var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days 

    if (value != null && value != "") {
        document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString(); 
    }
}

function pp_removeCookie(name) {
    var today = new Date(); 
    var expiry = new Date(today.getTime() - (28 * 24 * 60 * 60 * 1000)); // minus 28 days 
    var value = "asdf";

    if (value != null && value != "") {
        document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString(); 
    }
}




function reportException(exception){
    if(exception.toTraceString){
        var s= exception.toTraceString();
    }else{
        var s = exception.toString();
    }
    var ws = null;
    try{//see if WScript is available
        ws = WScript;
    }catch(e){
    }
    if(ws != null){
        WScript.stderr.write(s);
    }else{
        alert(s);
    }
}



var xmlrpc=null;
var the_server=null;

function get_server() {
    return get_server_reconnect(0, "");
}
function get_server_reconnect(do_reconnect, extra_url) {
    // returns a server object for calling xmlrpc stuff.
    // see if it is defined.
    if(xmlrpc == null) {
        try{
            var xmlrpc = importModule("xmlrpc");
        }catch(e){
            reportException(e);
            throw "importing of xmlrpc module failed.";
        }
    }

    methods = ['Event_get', 'Event_get_html', 'Event_new', 'Event_update', 'Event_get_html_list', 'Event_get_html_form', 'Venue_get_html_list', 'News_get', 'News_new', 'News_update', 'News_get_html_list', 'News_get_html_form', 'Review_get_html_list', 'Review_get_html', 'ProfileAlias_get_html_list', 'ProfileAlias_get_html', 'Article_get_html_list', 'Article_get_html', 'Latest_get_html', 'FrontPageGet', 'do_login', 'do_logout', 'doit', 'echo', 'check_logged_in_session', 'donothing'];


    if((the_server == null) || (do_reconnect)) {
        try{
            var url = "xmlrpc" + extra_url;
            the_server = new xmlrpc.ServerProxy(url, methods);
        } catch(e){
            reportException(e);
        }
    }
    return the_server;
}



function check_logged_in_session() {
    // checks to see if logged in still.

        var session_id = pp_getCookie("_SID_");
        if(!session_id){ 
            // not even a session cookie, no need to check.
            return false;
        }


        server = get_server();
        var loginok = server.check_logged_in_session(session_id);


        if(loginok) {
            return true;
        } else {
            return false;
        }


    return false;
}

function do_login(username, password) {
    // tries to log in.  returns the cookie id if successful.  else false.

    try{
        server = get_server();
        var sid = server.do_login(username, password);

        if(!sid) {
            // failed login.
            return false;
        }

        // set the cookie for further transactions.
        pp_setCookie("_SID_", sid);
        pp_setCookie("username", username);

        return sid;

    } catch(e){
        reportException(e);
    }

    return false;
}

function do_logout() {
    // logs out.  returns true if successful, else false.
    try{
        server = get_server();
        var r = server.do_logout();
        pp_removeCookie("_SID_");
        pp_removeCookie("username");

        return true;
    } catch(e){
        reportException(e);
    }
    return false;
}


/* -----------------------------------------------------------------
   event list viewing stuff.
*/


cached_results = Array();

function simple_function_cache(f, arg1, arg2) {
    if(cached_results[arg2][arg1]) {
        return cached_results[arg2][arg1];
    } else {
        var r = f(arg1);
        cached_results[arg2][arg1] = r;
        return r;
    }
}

cached_results_venue = Array();

function simple_function_cache_venue(f, arg1, arg2) {
    if(cached_results_venue[arg2][arg1]) {
        return cached_results_venue[arg2][arg1];
    } else {
        var r = f(arg1);
        cached_results_venue[arg2][arg1] = r;
        return r;
    }
}















// if one of the things is pinned.
var pinnedEvents = new Array();

function make_event_listing_pinned_no_toggle(Event_id, the_tabid) {
    var elname = "events_div_" + the_tabid + "_" + Event_id;
    var events_div = getElement(elname);

    events_div.innerHTML = events_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
    events_div.innerHTML = events_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
    pinnedEvents[the_tabid] = Event_id;
    different_one = true;
}

function make_event_listing_pinned(Event_id, the_tabid) {
    // makes one of the event listings pinned.  Or if it is allready pinned, make it unpinned.
    var elname = "events_div_" + the_tabid + "_" + Event_id;
    var events_div = getElement(elname);
    /*
    if(!events_div){
        setTimeout("make_event_listing_pinned('" + Event_id+"')", 3000);
        alert("what");
        return;
    }
    */


    //TODO: check if this one is allready pinned.
    //TODO: check if there is another on pinned.
        //TODO: store the id of the pinned one.
    //TODO:

    if(typeof pinnedEvents[the_tabid] == 'undefined') {
        pinnedEvents[the_tabid] = -1;
    }


    var different_one = false;
    if (pinnedEvents[the_tabid] == Event_id) {
        //alert("here1");

        // unpin the other one that is pinned.
        events_div.innerHTML = events_div.innerHTML.replace('class="listlinkpin"', 'class="listlink"');
        events_div.innerHTML = events_div.innerHTML.replace('class=listlinkpin', 'class=listlink');
        pinnedEvents[the_tabid] = -1;
    } else {

        if (pinnedEvents[the_tabid] != -1) {
            //alert("here2");
            // unpin the other one that is pinned.
            var pinned_events_div = getElement("events_div_" + the_tabid + "_" + pinnedEvents[the_tabid]);
            pinned_events_div.innerHTML = pinned_events_div.innerHTML.replace('class="listlinkpin"', 'class="listlink"');
            pinned_events_div.innerHTML = pinned_events_div.innerHTML.replace('class=listlinkpin', 'class=listlink');

            events_div.innerHTML = events_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
            events_div.innerHTML = events_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
            pinnedEvents[the_tabid] = Event_id;
            different_one = true;
        } else {
            //alert("here3");
            // it is not pinned.
            events_div.innerHTML = events_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
            events_div.innerHTML = events_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
            pinnedEvents[the_tabid] = Event_id;
            different_one = true;
        }
    }
    //alert(events_div.innerHTML);
    return different_one;
}

function change_event_being_viewed(Event_id, isclick, the_tabid) {
    var different_one = false;

    //alert("pinnedEvents[the_tabid]: " + pinnedEvents[the_tabid]);
    //alert("isclick: " + isclick);

    //alert("helloo there");

    if(typeof pinnedEvents[the_tabid] == 'undefined') {
        pinnedEvents[the_tabid] = -1;
    }

    if(isclick) {
        var different_one = make_event_listing_pinned(Event_id, the_tabid);
    } else {
        if(pinnedEvents[the_tabid]== -1) {
            different_one = true;
        }
    }


    //if(pinnedEvents[the_tabid]== -1) {
    if(different_one) {

        // change the div tags contents to be those of what is returned from the server.
        //ev = getElement("event_view");

        ev = getElement("scrollerevent_details_" + the_tabid + "Content");
        if(!ev) {
            // nothing to set.
            return;
        }

        try{
            server = get_server();
            //var r = server.Event_get_html(Event_id);
            var r = simple_function_cache(server.Event_get_html, Event_id, the_tabid);
        } catch(e){
            reportException(e);
        }



        // extract the details from it.
        var details_html = "";
 
        //eval('var details_regex = /<div id="event_details_' + the_tabid + '" class="details">([\\s\\S]*?)<\\/div>/m');
        eval('var details_regex = /<div id="event_details_' + the_tabid + '" class="details">([\\s\\S]*?)<\\/div>/m');

        var m1 = details_regex.exec(r);
        var details_html = m1[1];

        ev.innerHTML = details_html;

        eval('var header_details_regex = /<div id="event_details_heading_' + the_tabid + '" style="position:absolute;width:373px;">([\\s\\S]*?)<\\/div>/m');

        var m1 = header_details_regex.exec(r);
        // extract the header from it.
        var header_details_html = m1[1];

        ev = getElement("event_details_heading_" + the_tabid);
        if(!ev) { return; }
        ev.innerHTML = header_details_html;
        
        scrollers[event_details_scroller_index].reset_stuff();

    }

    return false;
}























// if one of the things is pinned.
var pinnedVenues = new Array();

function make_venue_listing_pinned_no_toggle(Venue_id, the_tabid) {
    var elname = "venues_div_" + the_tabid + "_" + Venue_id;
    var venues_div = getElement(elname);

    venues_div.innerHTML = venues_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
    venues_div.innerHTML = venues_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
    pinnedVenues[the_tabid] = Venue_id;
    different_one = true;
}

function make_venue_listing_pinned(Venue_id, the_tabid) {
    // makes one of the venue listings pinned.  Or if it is allready pinned, make it unpinned.
    var elname = "venues_div_" + the_tabid + "_" + Venue_id;
    var venues_div = getElement(elname);
    /*
    if(!venues_div){
        setTimeout("make_venue_listing_pinned('" + Venue_id+"', '" + the_tabid +"')", 100);
        return;
    }
    */


    //TODO: check if this one is allready pinned.
    //TODO: check if there is another on pinned.
        //TODO: store the id of the pinned one.
    //TODO:

    if(typeof pinnedVenues[the_tabid] == 'undefined') {
        pinnedVenues[the_tabid] = -1;
    }


    var different_one = false;
    if (pinnedVenues[the_tabid] == Venue_id) {
        //alert("here1");

        // unpin the other one that is pinned.
        venues_div.innerHTML = venues_div.innerHTML.replace('class="listlinkpin"', 'class="listlink"');
        venues_div.innerHTML = venues_div.innerHTML.replace('class=listlinkpin', 'class=listlink');
        pinnedVenues[the_tabid] = -1;
    } else {

        if (pinnedVenues[the_tabid] != -1) {
            //alert("here2");
            // unpin the other one that is pinned.
            var pinned_venues_div = getElement("venues_div_" + the_tabid + "_" + pinnedVenues[the_tabid]);
            pinned_venues_div.innerHTML = pinned_venues_div.innerHTML.replace('class="listlinkpin"', 'class="listlink"');
            pinned_venues_div.innerHTML = pinned_venues_div.innerHTML.replace('class=listlinkpin', 'class=listlink');

            venues_div.innerHTML = venues_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
            venues_div.innerHTML = venues_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
            pinnedVenues[the_tabid] = Venue_id;
            different_one = true;
        } else {
            //alert("here3");
            // it is not pinned.
            venues_div.innerHTML = venues_div.innerHTML.replace('class="listlink"', 'class="listlinkpin"');
            venues_div.innerHTML = venues_div.innerHTML.replace('class=listlink', 'class=listlinkpin');
            pinnedVenues[the_tabid] = Venue_id;
            different_one = true;
        }
    }
    //alert(venues_div.innerHTML);
    return different_one;
}

function change_venue_being_viewed(Venue_id, isclick, the_tabid) {
    var different_one = false;

    //alert("pinnedVenues[the_tabid]: " + pinnedVenues[the_tabid]);
    //alert("isclick: " + isclick);

    //alert("helloo there");

    if(typeof pinnedVenues[the_tabid] == 'undefined') {
        pinnedVenues[the_tabid] = -1;
    }

    if(isclick) {
        var different_one = make_venue_listing_pinned(Venue_id, the_tabid);
    } else {
        if(pinnedVenues[the_tabid]== -1) {
            different_one = true;
        }
    }


    //if(pinnedVenues[the_tabid]== -1) {
    if(different_one) {

        // change the div tags contents to be those of what is returned from the server.
        //ev = getElement("venue_view");

        ev = getElement("scrollervenue_details_" + the_tabid + "Content");
        if(!ev) {
            // nothing to set.
            return;
        }

        try{
            server = get_server();
            //var r = server.Venue_get_html(Venue_id);
            var r = simple_function_cache_venue(server.Venue_get_html, Venue_id, the_tabid);
        } catch(e){
            reportException(e);
        }



        // extract the details from it.
        var details_html = "";
 
        //eval('var details_regex = /<div id="venue_details_' + the_tabid + '" class="details">([\\s\\S]*?)<\\/div>/m');
        eval('var details_regex = /<div id="venue_details_' + the_tabid + '" class="details">([\\s\\S]*?)<\\/div>/m');

        var m1 = details_regex.exec(r);
        var details_html = m1[1];

        var are_we_editing = new Array();
        are_we_editing['Event'] = 1;

        if(are_we_editing['Event']) {
            venue_description = cached_results_short_venue_description[Venue_id];

            details_html = '<a href="#" onclick="return add_a_venue(' + Venue_id + ",'" + venue_description + "'" + ');" title="add a venue.">&lt;&lt;&lt; Add a venue to the event.</a> <br><br>' + details_html;
        }


        ev.innerHTML = details_html;

        eval('var header_details_regex = /<div id="venue_details_heading_' + the_tabid + '" style="position:absolute;">([\\s\\S]*?)<\\/div>/m');

        var m1 = header_details_regex.exec(r);
        // extract the header from it.
        var header_details_html = m1[1];

        ev = getElement("venue_details_heading_" + the_tabid);
        if(!ev) { return; }
        ev.innerHTML = header_details_html;
        
        scrollers[venue_details_scroller_index].reset_stuff();

    }

    return false;
}















//----------------------------------------------------
//  Review stuff.



function get_review_tab_stuff(reviewID) {

    var server = get_server();
    var review_html = server.Review_get_html(reviewID);


    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(review_html);
    review_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(review_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_review();
    }

    var return_stuff = new Array(review_html2, func_for_after);
    return return_stuff;
}

function place_scrollers_review() {
    var el = getElement("areview");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;

    var content_id = "areview";

    areview_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}




function view_something(theID, ofwhat, tab_text, switch_to_menu) {

    var tabbodycall = new TabBodyCall(theID, ofwhat);
    var tab_class = tab_info.tab_classes[ofwhat];
    //var the_tab = tab_info.get_tabs_object(ofwhat);
    var the_tab = tabs2;

    var r = the_tab.new_tab(tab_text, tab_class , true, true, tabbodycall, -2, "inherit");

    if(switch_to_menu) {
        setTimeout("tab_info.show_menu('" + ofwhat + "')", 10);
    }

    return false;
}







function place_scrollers_review_list() {
    var el = getElement("review_list");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "review_list";

    review_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}

function get_reviews_list_tab_stuff() {
    // returns the Array(html, func_to_call_after_tab_added).

    //var server = get_server();
    //var review_html = server.Review_get_html_list();

    var review_html = server_get('Review_get_html_list');

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(review_html);
    review_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(review_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_review_list();
    }

    var return_stuff = new Array(review_html2, func_for_after);
    return return_stuff;
}




// --------------------------------------
//  ProfileAlias stuff.


function get_profileAlias_tab_stuff(profileAliasID) {

    var server = get_server();
    var profileAlias_html = server.ProfileAlias_get_html(profileAliasID);

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(profileAlias_html);
    profileAlias_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(profileAlias_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_profileAlias();
    }

    var return_stuff = new Array(profileAlias_html2, func_for_after);
    return return_stuff;
}

function place_scrollers_profileAlias() {
    var el = getElement("aprofileAlias");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "aprofileAlias";

    aprofileAlias_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}





function place_scrollers_profileAlias_list() {
    var el = getElement("profileAlias_list");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "profileAlias_list";

    profileAlias_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}


function get_profileAliases_list_tab_stuff() {
    // returns the Array(html, func_to_call_after_tab_added).

    //var server = get_server();
    //var profileAlias_html = server.ProfileAlias_get_html_list();

    var profileAlias_html= server_get('ProfileAlias_get_html_list');

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(profileAlias_html);
    profileAlias_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(profileAlias_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_profileAlias_list();
    }

    var return_stuff = new Array(profileAlias_html2, func_for_after);
    return return_stuff;
}




// --------------------------------------
//  Article stuff.


function get_article_tab_stuff(articleID) {

    var server = get_server();
    var article_html = server.Article_get_html(articleID);

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(article_html);
    article_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(article_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_article();
    }

    var return_stuff = new Array(article_html2, func_for_after);
    return return_stuff;
}

function place_scrollers_article() {
    var el = getElement("aarticle");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "aarticle";

    aarticle_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}



function place_scrollers_article_list() {
    var el = getElement("article_list");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "article_list";

    article_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}


function get_articles_list_tab_stuff() {
    // returns the Array(html, func_to_call_after_tab_added).

    //var server = get_server();
    //var article_html = server.Article_get_html_list();

    var article_html= server_get('Article_get_html_list');

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(article_html);
    article_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(article_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_article_list();
    }

    var return_stuff = new Array(article_html2, func_for_after);
    return return_stuff;
}





// --------------------------------------
//  Latest stuff.



function place_scrollers_latest() {
    var el = getElement("latest_list");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_TOP_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "latest_list";

    latest_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 0);

    var realleft = getRealLeft(content_id);
    var realtop = getRealTop(content_id);


    var el = getElement("latest_news_heading");
    el.style.top = (height + 0) + "px";
    el.style.left = "0px";

    content_id = "latest_details";

    var el = getElement(content_id);
    t = getRealTop(content_id);
    l = getRealLeft(content_id);
    var top = height + T_SCROLLER_BOTTOM_TOP_DIFF;
    var left = 0;

    var content_html = el.innerHTML;
    var height = T_SCROLLER_BOTTOM_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;

    latest_details_scroller_index = place_scroller(content_html, content_id, height, width, top, left, 1);

}





function get_latest_tab_stuff() {

    //var server = get_server();
    //var latest_html = server.Latest_get_html();
    var latest_html= server_get('Latest_get_html');

    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(latest_html);
    latest_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(latest_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do = "";
    }


    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_latest();
    }

    var return_stuff = new Array(latest_html2, func_for_after);
    return return_stuff;
}












function open_search_tab(details) {
    debug_text = 'tab_type: ' + details["tab_type"] + ", ";
    debug_text += 'search_type: ' + details["search_type"] + ", ";
    debug_text += 'search data: ' + details[details["search_type"]] + ", ";

    alert(debug_text);
    return false;
}

// --------------------------------------
// Edit event Stuff.

// a global for storing what is returned from get_edit_tab_stuff.
//  keyed by what is editing.
results_of_edit_tab_stuff = new Array();

function get_edit_tab_stuff(theID, what_editing) {
    // what_editing - Event, Article, News, ProfileAlias etc.
    //  returns 

    var server = get_server();
    if(what_editing == "Event") {
        var the_results = server.Event_get_html_form(theID);
        results_of_edit_tab_stuff['Event'] = the_results;
    } else {
        alert("what else?");

    }


    var return_stuff = new Array();

    var the_edit_html1 = the_results[0][0];




    // extract the body.
    var body_regex1 = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m11 = body_regex1.exec(the_edit_html1);
    var the_edit_html12 = m11[1];

    // extract any script parts in it, and eval them.
    var body_regex21 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m21 = body_regex21.exec(the_edit_html12);

    if(m21) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do1 = m21[1].replace(new RegExp("<!--", "g"), "");
        code_to_do1 = code_to_do1.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do1 = "";
    }

    var edit_element_name1 = "a_edit_" + what_editing + "__0";


    var func_for_after = function() {
        eval(code_to_do1);
        var el = getElement(edit_element_name1);
        var content_html = el.innerHTML;
        var height = T_SCROLLER_HEIGHT;
        var width = T_SCROLLER_WIDTH;
        var content_id = edit_element_name1;

        edit_scroller_index1 = place_scroller(content_html, content_id, height, width, 0, 0, 1);
    }

    return_stuff[0] = new Array(the_edit_html12, func_for_after);












    var the_edit_html2 = the_results[0][1];

    // extract the body.
    var body_regex2 = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m12 = body_regex1.exec(the_edit_html2);
    var the_edit_html22 = m12[1];

    // extract any script parts in it, and eval them.
    var body_regex22 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m22 = body_regex22.exec(the_edit_html22);

    if(m22) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do2 = m22[1].replace(new RegExp("<!--", "g"), "");
        code_to_do2 = code_to_do2.replace(new RegExp("-->", "g"), "");
    } else {
        code_to_do2 = "";
    }

    var edit_element_name2 = "a_edit_" + what_editing + "__1";


    var func_for_after2 = function() {
        eval(code_to_do2);
        //.
        var el = getElement(edit_element_name2);
        var content_html = el.innerHTML;
        var height = T_SCROLLER_HEIGHT;
        var width = T_SCROLLER_WIDTH;
        var content_id = edit_element_name2;

        edit_scroller_index2 = place_scroller(content_html, content_id, height, width, 0, 0, 1);
    }

    return_stuff[1] = new Array(the_edit_html22, func_for_after2);





    return return_stuff;
}


function view_edit_screens(theID, what_editing) {

    var edit_stuff_r = get_edit_tab_stuff(theID, what_editing)

    var tabbodycall1 = new TabBodyCall(theID, "edit1_" + what_editing);
    tabbodycall1.set_text = edit_stuff_r[0][0];
    tabbodycall1.set_func = edit_stuff_r[0][1];
    tabbodycall1.top_text = "<strong>Edit 1.</strong>";

    var tabbodycall2 = new TabBodyCall(theID, "edit2_" + what_editing);
    tabbodycall2.set_text = edit_stuff_r[1][0];
    tabbodycall2.set_func = edit_stuff_r[1][1];
    tabbodycall2.top_text = "<strong>Edit 2.</strong>";

    var r1 = tabs1.new_tab("EDIT", "button3", true, true, tabbodycall1, -2, "inherit");
    var r2 = tabs2.new_tab("EDIT", "button3", true, true, tabbodycall2, -2, "inherit");


    return false;
}





// event editing stuff.
//---------------------------


function save_event_from_id(eventsID) {
    // given an event id, it reads from a form the values jah and saves it to the server.
    var ev = get_event_from_form(eventsID);
    if((!eventsID) || (eventsID =="false")) {
        add_new_event(ev);
    } else {
        update_event(ev);
    }
    return false;
}

function update_event(an_event) {
    try{
        server = get_server();
        var r = server.Event_update(an_event);
    }catch(e){
        reportException(e);
    }
    return r;
}

function add_new_event(an_event) {
    try{
        server = get_server();
        var r = server.Event_new(an_event);
    }catch(e){
        reportException(e);
    }
    return r;
}





function get_event_from_form(eventsID) {
// Returns an event for the given an event id.
// it reads from a form for the values for the event.
    if(!eventsID) {
        eventsID="false";
    }


    var id = eventsID;
    var shortName= getElement("events[" + eventsID + "]__shortName").value;
    var description = getElement("events[" + eventsID + "]__description").value;
    var linkTo = getElement("events[" + eventsID + "]__linkTo").value;
    var linkToText = getElement("events[" + eventsID + "]__linkToText").value;

    var active= getElement("events[" + eventsID + "]__active").value;

/*
    alert("events[" + eventsID + "]__venue_ids");
    eeee = getElement("events[" + eventsID + "]__venue_ids");
    alert(eeee);

    var venue_ids = getElement("events[" + eventsID + "]__venue_ids").value.split(",");
    var location_ids = getElement("events[" + eventsID + "]__location_ids").value.split(",");
    var price_ids = getElement("events[" + eventsID + "]__prices_ids").value.split(",");
    var time_ids = getElement("events[" + eventsID + "]__times_ids").value.split(",");

    var venue_ids = getElement("venue_ids");
    var location_ids = getElement("location_ids");
    var price_ids = getElement("prices_ids");
    var time_ids = getElement("times_ids");

*/



    // all the location stuff.


    //TODO: fix up the names of the fields.  need to put in new ones from events.py  location, and event has changed.


    if(eventsID == "false") {
        eventsID="";
    }


    var ev = new Event(shortName,description,linkTo,linkToText,active,eventsID);

    var extra = results_of_edit_tab_stuff['Event'][0][2];

    time_ids = extra['time_ids'];
    venue_ids = extra['venue_ids'];
    location_ids = extra['location_ids'];
    price_ids = extra['price_ids'];




/*


    var times = new Array();
    var keep_going = true;

    for(var i=0; i < time_ids.length; i++) {
        var el= getElement("Time['" + time_ids[i] + "']__start_date");
        if(el) {
            var start_date= el.value;
            var end_date= getElement("Time['" + time_ids[i] + "']__end_date").value;
            var t = new TimesEvent(start_date, end_date, time_ids[i]);
            times[times.length] = t;
        }
    }

    var venues = new Array();
    var keep_going = true;
    var i = 0;
    for(var i=0; i < venue_ids.length; i++) {
        var el= getElement("venues[" + venue_ids[i] + "]__name");
        if(el) {
            var venue_name = el.value;
            var v = new Venue(venue_name, venue_ids[i]);
            venues[venues.length] = v;
        }
    }

    var locations = new Array();
    var keep_going = true;
    var i = 0;

    for(var i=0; i < location_ids.length; i++) {
        var el = getElement("locations[" + location_ids[i] + "]__streetNumber");
        if(el) {
            var streetNumber= el.value;
            var streetName= getElement("locations[" + location_ids[i] + "]__streetName").value;
            var streetType= getElement("locations[" + location_ids[i] + "]__streetType").value;
            var cityName= getElement("locations[" + location_ids[i] + "]__cityName").value;
            var suburb= getElement("locations[" + location_ids[i] + "]__suburb").value;
            var postCode= getElement("locations[" + location_ids[i] + "]__postCode").value;
            var stateCode= getElement("locations[" + location_ids[i] + "]__stateCode").value;
            var countryCode= getElement("locations[" + location_ids[i] + "]__countryCode").value;
            var l = new Location(streetNumber,streetName,streetType,cityName,suburb,postCode,stateCode,countryCode,location_ids[i]);
            locations[locations.length] = l;
        }
    }


    var prices = new Array();
    var keep_going = true;
    var i = 0;
    for(var i=0; i < price_ids.length; i++) {
        var elname = "Price['" + price_ids[i] + "']__description";
        var el = getElement(elname);
        if(el) {
            var description = el.value;
            var price= getElement("Price['" + price_ids[i] + "']__price").value;
            var p = new PricesEvent(description,price,price_ids[i]);
            prices[prices.length] = p;
        } else {
            keep_going = false;
        }
    }


*/


    function EmptyObj() {
    }

    //TODO: make this search through all of the things linked here.
    // FROM: the edit screen.

    var field_data = new Array();

    for (akey in things_linked) {
        if(akey == "toXmlRpc") continue;
        field_data[akey] = new Array();

        for (anid in things_linked[akey]) {
            if(anid == "toXmlRpc") continue;
            //var p = new Array();
            var theobj = new EmptyObj();
            theobj['id'] = anid;

            // fill up the other field names.
            for(fieldnamekey in the_fields[akey]) {
                if(fieldnamekey == "toXmlRpc") continue;
                fieldname = the_fields[akey][fieldnamekey];

                var elname = akey + "['" + anid + "']__" + fieldname;
                var el = getElement(elname);
                if(el) {
                    theobj[fieldname] = el.value;
                }
            }
            field_data[akey][field_data[akey].length] = theobj;
        }
    }


    ev.venues= field_data['Venue'];
    ev.prices= field_data['Price'];
    ev.times= field_data['Time'];
    ev.meta_datas= field_data['MetaData'];
    ev.genres= field_data['Genre'];
    ev.profiles= field_data['Profile'];
    ev.reviews= field_data['Review'];

    return ev;
}




function UrlParser() {
    this.nMaxVars = 0;
    this.sVarLine = "";
    this.sName = new Array();
    this.sValue = new Array();
    this.key_value = new Array();
}

UrlParser.prototype.getMaxVars = function () { return this.nMaxVars; }
UrlParser.prototype.getVarString = function () { return this.sVarLine; }
UrlParser.prototype.getNameArray = function () { return this.sName; }
UrlParser.prototype.getValueArray = function () { return this.sValue; }

UrlParser.prototype.parseCallingURL = function (sCallingURL) {

    //Get the calling URL and parse out variables
    sCallingURL = String(sCallingURL);
    
    if (sCallingURL.length == 0)
            return;
            
    // Check if there are any variables
    if (sCallingURL.indexOf('?') != -1) {
            this.sVarLine = String(sCallingURL.substring(sCallingURL.indexOf('?') + 1, sCallingURL.length));
    } else {
            // No variables
            return;
    }
    
    var nPos = 0;
    var sChar = "";
    var sWord = "";
    this.nMaxVars = 0;
    
    // Parse
    while (nPos < this.sVarLine.length) {
            sChar = this.sVarLine.substring(nPos, nPos + 1);
            
            if (sChar == "=") {
                    this.sName[this.nMaxVars] = sWord;
                    sWord = "";
                    
            } else if (sChar == "&") {
                    this.sValue[this.nMaxVars] = sWord;
                    sWord = "";
                    this.nMaxVars++;

            } else if (sChar == "#") {
                    this.sValue[this.nMaxVars] = sWord;
                    sWord = "";
                    this.nMaxVars++;
                    
            } else if (nPos == this.sVarLine.length - 1) {
                    sWord += this.sVarLine.substring(nPos, nPos + 1);
                    this.sValue[this.nMaxVars] = sWord;
                    sWord = "";
                    this.nMaxVars++;
                    
            } else {
                    sWord += sChar;
            }
            nPos++;
    }

    // make a key/value array.
    for(var i =0; i < this.sName.length; i++) {
        this.key_value[this.sName[i]] = this.sValue[i];
    }


}

// ofwhat - this is used to see what thing this will return.
function TabBodyCall(theID, ofwhat) {
    this.theID = theID;
    this.ofwhat = ofwhat;
    this.top_text = "";
    this.bottom_text = "";
    this.set_text = "";
    this.set_func = false;
}

// this is for filling up the tab body.
//  - if this.set_text is not anything we use that.
TabBodyCall.prototype.callback = function (the_tab_id) {
    if(this.set_text) {
        if(this.set_func) {
            f = this.set_func;
        } else {
            var f = function (){return;};
        }

        var return_stuff = new Array(this.set_text, f);
        return return_stuff;
    }
    switch(this.ofwhat) {
        case "list_profileAlias":
            return get_profileAliases_list_tab_stuff();
        case "list_review":
            return get_reviews_list_tab_stuff();
        case "list_article":
            return get_articles_list_tab_stuff();
        case "list_news":
            return get_news_list_tab_stuff();
        case "list_event":
            return get_list_tab_stuff(the_tab_id, this.search_text, this.ofwhat)
        case "list_venue":
            return get_list_tab_stuff(the_tab_id, this.search_text, this.ofwhat)
        case "list_latest":
            return get_latest_tab_stuff();
        case "profileAlias":
            return get_profileAlias_tab_stuff(this.theID);
        case "review":
            return get_review_tab_stuff(this.theID);
        case "article":
            return get_article_tab_stuff(this.theID);



        default:
            alert("error:TabBodyCall.prototype.callback...");
            alert(this.ofwhat);
    }
}

// this returns the text for the tab header.
TabBodyCall.prototype.get_tab_top = function () {
    if(this.top_text) return this.top_text;
    if(tab_info.top_text[this.ofwhat]) {
        return tab_info.top_text[this.ofwhat];
    }
    return "";
}

TabBodyCall.prototype.get_tab_bottom = function () {
    if(this.bottom_text) return this.bottom_text;
    if(tab_info.bottom_text[this.ofwhat]) {
        return tab_info.bottom_text[this.ofwhat];
    }
    return "";
}


pp_js_done_loading = true;



//front_page = false;

front_tries = 0;
function get_front_page_listings() {

    if(front_page && pp_js_done_loading) {
        load_tabs();
        return
    }

    if(!pp_js_done_loading || !jsolait_done_loading) {
        setTimeout("get_front_page_listings()",35);
        return
    }


    try{
        var server = get_server_reconnect(1,"")

    }catch(e){
        //alert("oops");
        // try again repeatedly...
        front_tries++;
        if(front_tries > 5) {
            //reportException(e);
            alert( "Tried getting the front page 5 times failed...");
        } else {
            setTimeout(get_front_page_listings,1000);
        }
        return;

    }

    try{
        if(!front_page) {
            front_page = server.FrontPageGet();
        }

    }catch(e){


        front_page = false;

        front_tries++;
        if(front_tries > 5) {
            reportException(e);
            throw "call failed.";
        } else {

            setTimeout(get_front_page_listings,1000);
            return;
        }

    }

    load_tabs();

}

function server_get(what_to_get) {
    if(front_page == false) {
        alert('warn is false.' + what_to_get)
    }
    return front_page[what_to_get];
}


//get_front_page_listings();





















function submit_mp3_tab() {

    var tabbodycall = new TabBodyCall(-1, "submitmp3");
    tabbodycall.set_text = '<iframe src="submitmp3content.html" frameborder="0" width="100%" height="' + TAB_BODY_HEIGHT + '" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>MP3 submission</strong>";

    var r = tabs2.new_tab("SUBMIT MP3", "button1", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs2.set_extra_bits_for_visible_tab(r); }

    return false;
}


function contribute_tab() {

    var tabbodycall = new TabBodyCall(-1, "contribute");
    tabbodycall.set_text = '<iframe src="contribute.php" frameborder="0" width="100%" height="' + TAB_BODY_HEIGHT + '" scrolling="no" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Contribute</strong>";

    var r = tabs2.new_tab("CONTRIBUTE", "button1", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs2.set_extra_bits_for_visible_tab(r); }

    return false;
}


function new_user_tab() {
    
    var tabbodycall = new TabBodyCall(-1, "newuser");
    tabbodycall.set_text = '<iframe src="newuser.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your new user details</strong>";
    

    var r = tabs2.new_tab("NEW USER", "button2", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs2.set_extra_bits_for_visible_tab(r); }

    return false;
}



function submit_news_tab() {
    
    var tabbodycall = new TabBodyCall(-1, "submitnews");
    tabbodycall.set_text = '<iframe src="addnews.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your news</strong>";
    

    var r = tabs3.new_tab("SUBMIT NEWS", "button3", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs3.set_extra_bits_for_visible_tab(r); }

    return false;
}

function submit_event_tab() {
    
    var tabbodycall = new TabBodyCall(-1, "submitevent");
    tabbodycall.set_text = '<iframe src="addevent.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your event</strong>";
    

    var r = tabs1.new_tab("SUBMIT EVENT", "button3", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs1.set_extra_bits_for_visible_tab(r); }


    return false;
}


function submit_profile_tab() {
    
    var tabbodycall = new TabBodyCall(-1, "submitprofile");
    tabbodycall.set_text = '<iframe src="addprofile.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your profile</strong>";
    

    var r = tabs5.new_tab("SUBMIT PROFILE", "button2", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs5.set_extra_bits_for_visible_tab(r); }


    return false;
}


function submit_review_tab() {

    var tabbodycall = new TabBodyCall(-1, "submitreview");
    tabbodycall.set_text = '<iframe src="addreview.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your review</strong>";
    
    var r = tabs7.new_tab("SUBMIT REVIEW", "button4", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs7.set_extra_bits_for_visible_tab(r); }

    return false;
}


function submit_article_tab() {
    
    var tabbodycall = new TabBodyCall(-1, "submitarticle");
    tabbodycall.set_text = '<iframe src="addarticle.html" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>';
    tabbodycall.top_text = "<strong>Add your article</strong>";


    var r = tabs9.new_tab("SUBMIT ARTICLE", "button1", true, true, tabbodycall, 1, "inherit");
    if(r != -1) { tabs9.set_extra_bits_for_visible_tab(r); }


    return false;
}



function admin_tab() {

    var get_tab_body = function() {
        var f = function(){return;};
        return new Array('<iframe src="pp?mode=admin_stuff" frameborder="0" width="100%" height="366" scrolling="yes" name="left2"></iframe>', f);

    }

    var r = tabs2.new_tab("ADMIN", "button1", true, true, get_tab_body, 1, "inherit");


    var topf = function () { return "<strong>Temporary admin stuff page.</strong>"; }
    var bottomf = function () { return ""; }
    tabs2.add_top_bottom_callback(r, topf, bottomf);
    tabs2.set_extra_bits_for_visible_tab(r);


    /*
    if(urllib== null) {
        try{
            var urllib = importModule("urllib");
        }catch(e){
            reportException(e);
            throw "importing of urllib module failed.";
        }
    }
    sendRequest("get", "url");
    r = urllib.sendRequest("get", "http://grace.pretendpaper.com/reviews.html");
    */

    return false;
}




function login() {

    var username = getElement("pp_username").value;
    var password = getElement("pp_password").value;
    var logoutok = do_logout();

    var r = do_login(username, password);

    if(!r) {
        var el = getElement("status_bar");
        el.innerHTML = "incorrect username or password.";
    } else {
        // set the box to display their user name and stuff.
        set_login_box(10);
    }

    return false;
}
function logout() {
    var logoutok = do_logout();
    set_login_box(10);
    return false;
}


set_login_box(2000);

function get_search_text(anid, close_tab, ofwhat, tab_name) {
    var ael = getElement(anid);
    if(!tab_name){
        var thetabs = tab_info.get_tabs_object(ofwhat);
    } else {
        var thetabs = tab_info.get_tabs_object_from_name(tab_name);
    }

    if(close_tab) {
        thetabs.remove_tab(thetabs.current_visible_tab_idx);
    }
    if(ael) {
        tab_search(ael.value, ofwhat, tab_name);
    }

    return false;
}

function tab_search(search_text, ofwhat, tab_name) {
    if(!search_text) return false;
    if(!tab_name){
        var thetabs = tab_info.get_tabs_object(ofwhat);
    } else {
        var thetabs = tab_info.get_tabs_object_from_name(tab_name);
    }

    var tabbodycall = new TabBodyCall(-1, ofwhat);
    var input_id = escape("search_box__" + ofwhat + "__" + search_text);
    tabbodycall.search_text = search_text;
    //escaped_search_text = escape(tabbodycall.search_text);
    escaped_search_text = tabbodycall.search_text.replace("'", "\'");
    tabbodycall.top_text = "<input class='frm-input-eventsearch' type='text' id='" + input_id +"' value='" + escaped_search_text + "' onChange='return get_search_text(" + '"' + input_id + '"' + ", 1,";
    tabbodycall.top_text += '"' + ofwhat + '"' + ', "' + tab_name + '"' +")'>";

    //alert(tabbodycall.search_text);
    //alert(tabbodycall.top_text);

    
    // max 8 characters.
    if(tabbodycall.search_text.length > 8) {
        var tab_name = tabbodycall.search_text.substring(0,8);
        tab_name += ">"
    } else {
        var tab_name = tabbodycall.search_text;
    }
    var atab_class = tab_info.tab_classes[ofwhat];
    thetabs.new_tab(tab_name, atab_class, true, true, tabbodycall, -1, "inherit");

    return false;
}










// we get stuff differently on the first time.

first_time_get = new Array();
first_time_get['Event_get_html_list'] = 1;
first_time_get['Venue_get_html_list'] = 1;

function get_list_tab_stuff(the_tab_id, search_text, ofwhat) {
    // returns the Array(html, func_to_call_after_tab_added).
    if(ofwhat == "list_event") var get_what = "Event_get_html_list";
    else if(ofwhat == "list_venue") var get_what = "Venue_get_html_list";
    else alert("get_list_tab_stuff error2...");


    if(!first_time_get[get_what]) {
        var server = get_server();
        if(ofwhat == "list_event") {
            var the_html = server.Event_get_html_list(the_tab_id, search_text);
        } else if(ofwhat == "list_venue") {
            var the_html = server.Venue_get_html_list(the_tab_id, search_text);
        } else {
            alert("get_list_tab_stuff error...");
        }
    } else {
        var the_html = server_get(get_what);
        first_time_get[get_what] = 0;
    }

    //if(ofwhat == "list_venue") alert(the_html);

    // extract the body.
    //var body_regex = new RegExp("<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)", "m");
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(the_html);
    the_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(the_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<" + "!--", "g"), "")
        code_to_do = code_to_do.replace(new RegExp("-" + "->", "g"), "")
        //event_html2 = event_html2.replace(m2[1], "");
        //eval(code_to_do);
    } else {
        code_to_do = "";
    }


    if(ofwhat == "list_event") {
        var func_for_after = function() {
            eval(code_to_do);
            var atab_id = the_tab_id;
            place_scrollers_event_list(atab_id);
        }
    } else if(ofwhat == "list_venue") {
        var func_for_after = function() {
            eval(code_to_do);
            var atab_id = the_tab_id;
            place_scrollers_venue_list(atab_id);
        }
    }


    //dump("---------------------------------------\n\n\n\n\n\n\n");
    //dump(event_html2);
    var return_stuff = new Array(the_html2, func_for_after);
    return return_stuff;
}








function place_scrollers_event_list(tab_id) {
    //alert(el.offsetHeight);
    var height = T_SCROLLER_TOP_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "events_list_" + tab_id;
    var el = getElement(content_id);
    var content_html = el.innerHTML;


    event_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);

    var realleft = getRealLeft(content_id);
    var realtop = getRealTop(content_id);


    var el = getElement("event_details_heading_" + tab_id);
    el.style.top = (height + 0) + "px";
    el.style.left = "0px";

    content_id = "event_details_" + tab_id;

    var el = getElement(content_id);
    t = getRealTop(content_id);
    l = getRealLeft(content_id);
    var top = height + T_SCROLLER_BOTTOM_TOP_DIFF;
    var left = 0;

    var content_html = el.innerHTML;
    var height = T_SCROLLER_BOTTOM_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;

    event_details_scroller_index = place_scroller(content_html, content_id, height, width, top, left, 1);

}


function place_scrollers_venue_list(tab_id) {
    //alert(el.offsetHeight);
    var height = T_SCROLLER_TOP_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;
    var content_id = "venues_list_" + tab_id;
    var el = getElement(content_id);
    var content_html = el.innerHTML;


    venue_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);

    var realleft = getRealLeft(content_id);
    var realtop = getRealTop(content_id);


    var el = getElement("venue_details_heading_" + tab_id);
    el.style.top = (height + 0) + "px";
    el.style.left = "0px";

    content_id = "venue_details_" + tab_id;

    var el = getElement(content_id);
    t = getRealTop(content_id);
    l = getRealLeft(content_id);
    var top = height + T_SCROLLER_BOTTOM_TOP_DIFF;
    var left = 0;

    var content_html = el.innerHTML;
    var height = T_SCROLLER_BOTTOM_HALF_HEIGHT;
    var width = T_SCROLLER_WIDTH;

    venue_details_scroller_index = place_scroller(content_html, content_id, height, width, top, left, 1);

}





function place_scrollers_news_list() {
    var el = getElement("news_list");
    //alert(el.offsetHeight);
    var content_html = el.innerHTML;
    var height = T_SCROLLER_HEIGHT;
    var width = T_SCROLLER_WIDTH;

    var content_id = "news_list";

    news_scroller_index = place_scroller(content_html, content_id, height, width, 0, 0, 1);
}





function get_news_list_tab_stuff() {
    // returns the Array(html, func_to_call_after_tab_added).

    //var server = get_server();
    //var news_html = server.News_get_html_list();
    var news_html  = server_get('News_get_html_list');


    // extract the body.
    var body_regex = /<body[^>]*>([\s\S]*)<\/body>(?!<\/body>)/m
    var m1 = body_regex.exec(news_html);
    news_html2 = m1[1];

    // extract any script parts in it, and eval them.
    var body_regex2 = /<script[^>]*>([\s\S]*)<\/script>(?!<\/script>)/m
    var m2 = body_regex2.exec(news_html2);

    if(m2) {
        // have to remove any comment tags.  IE chokes on them.
        var code_to_do = m2[1].replace(new RegExp("<" + "!--", "g"), "");
        code_to_do = code_to_do.replace(new RegExp("-" + "->", "g"), "");
    } else {
        code_to_do = "";
    }

    var func_for_after = function() {
        eval(code_to_do);
        place_scrollers_news_list();
    }

    var return_stuff = new Array(news_html2, func_for_after);
    return return_stuff;
}












function load_tabs() {

    if(front_page == false) {
        // load a bit later.
        setTimeout(load_tabs, 35);
    }

    //e = new ScrollingLayerThere("topnewsid", 240);
    //e.prepare_scrolling();

    //alert("left:" + left + " right:" + right + " top:" + top + " bottom:" + bottom);


    // TODO: setup the tabs.
    tab_body_height = 366;
    tab_body_width = 378;
    tab_body_width = 375;

    el = getElement('tabs1_body_top');
    if(!el) {
        setTimeout("load_tabs()",35);
        return
    }

    // events
    tabs1 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs1", tab_body_height, tab_body_width);
    // right side.  latest etc.
    tabs2 = new Tabs(0, "tabs2_headers", "tabs2_body", "tabs2", tab_body_height, tab_body_width);


    setTimeout("load_tabs2()",100);
}

function load_tabs2() {


    //tab_body_html = '<iframe src="http://www.pretendpaper.com/dyn.py?mode=list_events" frameborder="0" width="100%" height="366" scrolling="yes" name="left0"></iframe>'
    //tab_body_html = '<iframe src="pp?mode=list_events" frameborder="0" width="100%" height="366" scrolling="yes" name="left0"></iframe>'

    //tab_body_html = 'hello there hi again.';
    //for(var iiiiii = 0; iiiiii < 40; iiiiii++) {
    //    tab_body_html += '<p description="Lessrain' + iiiiii + '">hello there hi again.<br>';
    //}

    //tab_body_html = '<iframe src="http://grace/~rene/pretendpaper/www/dyn.py?mode=list_events" frameborder="0" width="100%" height="366" scrolling="yes" name="left"></iframe>';
    //tab_body_html = '<iframe src="http://grace/~rene/pretendpaper/www/dyn.py?mode=list_events" frameborder="0" width="100%" height="366" scrolling="yes" name="left"></iframe>';
    


    // get all the text data first...
    //get_front_page_listings();


    tab_body_html = "";
    //tab_body_html = get_event_list_html();
    //var stuff = get_event_list_html();
    //tab_body_html = stuff[0];
    //code_to_do = stuff[1];

    // Get the events list html.
    // bottom part has a scroller on it.  Top part has a scroller on it.

    var tabbodycall = new TabBodyCall(-1, "list_event");
    var input_id = escape("search_box__EVENTS");
    tabbodycall.search_text = "";
    tabbodycall.top_text = "<input class='frm-input-eventsearch' type='text' id='" + input_id +"' value='" + tabbodycall.search_text + "' onChange='return get_search_text(" + '"' + input_id + '"' + ", 0,";
    tabbodycall.top_text +=  '"' +  "list_event" + '"' + ',"")' + "'>";

    tabs1.new_tab("EVENTS", "button3", false, true, tabbodycall, 1, "inherit");

    //eval(code_to_do);
    //place_scrollers_event_list();
    var tab_body_top_html = Array();
    t = tab_body_top_html;

    t[0] = '';
    t[0] += '<table width="100%"  border="0" cellspacing="0" cellpadding="0">';
    t[0] += '                  <tr>';
    t[0] += '                    <td><strong>events/melbourne</strong> </td>';
    t[0] += '                    <td align="right" width="10%"><a href="#" class="default" onclick="return submit_event_tab();">&nbsp;SUBMIT EVENT&nbsp;&nbsp;</a></td>';
    t[0] += '                  </tr>';
    t[0] += '              </table>';


    var topf = function () { return tab_body_top_html[0]; }
    var bottomf = function () { return ""; }
    tabs1.add_top_bottom_callback(0, topf, bottomf)
    tabs1.set_extra_bits_for_visible_tab(0);




    var OLDget_latest_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }


    var tabbodycall = new TabBodyCall(-1, "list_latest");
    r = tabs2.new_tab("LATEST", "button4", false, true, tabbodycall, 1, "inherit");

    var topf = function () { return "<strong>Latest stuff.</strong>"; }
    var bottomf = function () { return ""; }
    tabs2.add_top_bottom_callback(r, topf, bottomf);
    tabs2.set_extra_bits_for_visible_tab(0);

    var get_forum_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }

    /*
    r = tabs2.new_tab("FORUM", "button1", false, false, get_forum_list_tab_stuff, 1);
    var topf = function () { return "<strong>Forum.</strong>"; }
    var bottomf = function () { return ""; }
    tabs2.add_top_bottom_callback(r, topf, bottomf);
    */

    select_a_menu("menu_events");
    tabs1.set_extra_bits_for_visible_tab(0);


    // open up some reviews, articles, or profile aliases based on the id.
    //NOTE: a check to see if URLParser is there... for browsers who haven't refreshed js yet.
    try {
        up = new UrlParser();
        up.parseCallingURL(parent.document.URL);
        //alert(up.key_value['e']);
        for(var i =0; i < up.sName.length; i++) {

            if(up.sName[i] == 'r') {
                view_something(up.sValue[i], "review", "REVIEW", 0);
            }
            if(up.sName[i] == 'pa') {
                view_something(up.sValue[i], "profileAlias", "PROFILE", 0);
            }
            if(up.sName[i] == 'a') {
                view_something(up.sValue[i], "article", "ARTICLE", 0);
            }
        }
    } catch(e) {
        noop=1;
    }


    // leave a little time for the front tabs are loaded before loading the back ones.
    setTimeout("load_tabs3()",1000);
    //setTimeout("load_tabs3()",100);
    //load_tabs3();

    //load_tabs2();
}

function load_tabs3() {

    // news
    tabs3 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs3", tab_body_height, tab_body_width);
    // profiles
    tabs5 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs5", tab_body_height, tab_body_width);
    // reviews
    tabs7 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs7", tab_body_height, tab_body_width);
    // articles.
    tabs9 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs9", tab_body_height, tab_body_width);

    tabs10 = new Tabs(0, "tabs1_headers", "tabs1_body", "tabs10", tab_body_height, tab_body_width);


    var tabbodycall = new TabBodyCall(-1, "list_news");
    r = tabs3.new_tab("NEWS", "button3", false, true, tabbodycall, 1, "hidden");

    //clear_tab_bodies();
    //tabs.set_visible_tabidx(0);

    //place_scroller(tab_body_html, "somecontentplace");



    //tabs.tab_bodies[0].setHTML('<iframe src="http://www.pretendpaper.com/dyn.py?mode=list_events" frameborder="0" width="100%" height="366" scrolling="yes" name="left0"></iframe>');
    //tabs.tab_bodies[0].setHTML();
    //tabs.tab_bodies[1].setHTML();




    var tab_body_top_html = Array();

    t = tab_body_top_html;

    t[1] = '';
    t[1] += '              <table width="100%"  border="0" cellspacing="0" cellpadding="0">';
    t[1] += '                <tr>';
    t[1] += '                  <td><strong>PP Announcements </strong> </td>';
    t[1] += '                  <td align="right">';
    t[1] += '                    <table cellpadding="0" cellspacing="0" border="0" class="basebutton-default">';
    t[1] += '                      <tr>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                      </tr>';
    t[1] += '                      <tr>';
    t[1] += '                        <td width="1" class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                        <td><a href="#" class="default" onclick="return submit_news_tab();">&nbsp;SUBMIT NEWS&nbsp;&nbsp;</a></td>';
    t[1] += '                        <td width="1" class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                      </tr>';
    t[1] += '                      <tr>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                        <td class="corner"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>';
    t[1] += '                      </tr>';
    t[1] += '                    </table>';
    t[1] += '                  </td>';
    t[1] += '                </tr>';
    t[1] += '               </table>';







    var topf = function () { return tab_body_top_html[1]; }
    var bottomf = function () { return ""; }
    tabs3.add_top_bottom_callback(0, topf, bottomf)
    tabs3.set_extra_bits_for_visible_tab(0);

    var get_search_news_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }

    /*
    r = tabs3.new_tab("SEARCH", "button3", false, false, get_search_news_list_tab_stuff, 1, "hidden");

    var topf = function () { return "<strong>Search.</strong>"; }
    var bottomf = function () { return ""; }
    tabs3.add_top_bottom_callback(r, topf, bottomf);
    */

    tabs3.setVisible(0);

    var ttr = '';
    ttr += '<table width="100%"  border="0" cellspacing="0" cellpadding="0">';
    ttr += '<tr>';
    ttr += '<td><strong>Reviews.</strong> </td>';
    ttr += '<td align="right" width="10%"><a href="#" class="default" onclick="return submit_review_tab();">&nbsp;SUBMIT REVIEW&nbsp;&nbsp;</a></td>';
    ttr += '</tr>';
    ttr += '</table>';

    var tabbodycall = new TabBodyCall(-1, "list_review");
    r = tabs7.new_tab("REVIEWS", "button4", false, true, tabbodycall, 1, "hidden");

    tabs7.setVisible(0);
    var topf = function () { return ttr; }
    var bottomf = function () { return ""; }
    tabs7.add_top_bottom_callback(r, topf, bottomf);


    /*
     **  some search stuff.
     */

    var get_search_events_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }

    /*
    r = tabs1.new_tab("SEARCH", "button3", false, false, get_search_events_list_tab_stuff, 1, "hidden");

    var topf = function () { return "<strong>Search.</strong>"; }
    var bottomf = function () { return ""; }
    tabs1.add_top_bottom_callback(r, topf, bottomf);
    */










    var get_forum_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }







    var OLDget_profiles_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }

    var tabbodycall = new TabBodyCall(-1, "list_profileAlias");
    r = tabs5.new_tab("PROFILES", "button2", false, true, tabbodycall, 1, "hidden");


    var ttt = '';
    ttt += '<table width="100%"  border="0" cellspacing="0" cellpadding="0">';
    ttt += '<tr>';
    ttt += '<td><strong>Profiles.</strong> </td>';
    ttt += '<td align="right" width="10%"><a href="#" class="default" onclick="return submit_profile_tab();">&nbsp;SUBMIT PROFILE&nbsp;&nbsp;</a></td>';
    ttt += '</tr>';
    ttt += '</table>';


    var topf = function () { return ttt; }
    var bottomf = function () { return ""; }
    tabs5.add_top_bottom_callback(r, topf, bottomf);



    var get_search_profiles_list_tab_stuff = function() {
        var f = function(){return;};
        var r = new Array("Coming in a later beta.", f);
        return r;
    }

    /*
    r = tabs5.new_tab("SEARCH", "button2", false, false, get_search_profiles_list_tab_stuff, 1);

    var topf = function () { return "<strong>Search.</strong>"; }
    var bottomf = function () { return ""; }
    tabs5.add_top_bottom_callback(r, topf, bottomf);
    */

    tabs5.setVisible(0);



    var tta = '';
    tta += '<table width="100%"  border="0" cellspacing="0" cellpadding="0">';
    tta += '<tr>';
    tta += '<td><strong>Articles.</strong> </td>';
    tta += '<td align="right" width="10%"><a href="#" class="default" onclick="return submit_article_tab();">&nbsp;SUBMIT ARTICLE&nbsp;&nbsp;</a></td>';
    tta += '</tr>';
    tta += '</table>';



    var tabbodycall = new TabBodyCall(-1, "list_article");
    tabs9.new_tab("ARTICLES", "button1", false, true, tabbodycall, 1, "hidden");

    tabs9.setVisible(0);
    var topf = function () { return tta; }
    var bottomf = function () { return ""; }
    tabs9.add_top_bottom_callback(r, topf, bottomf);






    var do_venue_list = 1;

    if(do_venue_list) {

        var tta = '';
        tta += '<table width="100%"  border="0" cellspacing="0" cellpadding="0">';
        tta += '<tr>';
        tta += '<td><strong>Venues.</strong> </td>';
        tta += '<td align="right" width="10%"><a href="#" class="default" onclick="return submit_venue_tab();">&nbsp;SUBMIT VENUE&nbsp;&nbsp;</a></td>';
        tta += '</tr>';
        tta += '</table>';

        var tabbodycall = new TabBodyCall(-1, "list_venue");
        var input_id = escape("search_box__VENUES");
        tabbodycall.search_text = "";
        tabbodycall.top_text = "<input class='frm-input-eventsearch' type='text' id='" + input_id +"' value='" + tabbodycall.search_text + "' onChange='return get_search_text(" + '"' + input_id + '"' + ", 0,";
        tabbodycall.top_text +=  '"list_venue"' + ',"")' + "'>";
        //tabbodycall.top_text +=  '"list_venue"' + ',"tabs2")' + "'>";


        tabs10.new_tab("VENUES", "button1", false, true, tabbodycall, 1, "hidden");

        tabs10.setVisible(0);
        var topf = function () { return tta; }
        var bottomf = function () { return ""; }
        tabs10.add_top_bottom_callback(r, topf, bottomf);
    }





    function resize_tabs(e) {
        tabs1.position_tabs();
        tabs2.position_tabs();
        tabs3.position_tabs();
        tabs5.position_tabs();
        tabs7.position_tabs();
        tabs9.position_tabs();
        tabs10.position_tabs();
    }

    window.onresize = resize_tabs;
    /* commented these out to see if it makes any loading time difference.
    setTimeout("tabs1.position_tabs()",105);
    setTimeout("tabs2.position_tabs()",105);
    setTimeout("tabs3.position_tabs()",105);
    setTimeout("tabs5.position_tabs()",105);
    setTimeout("tabs7.position_tabs()",105);
    setTimeout("tabs9.position_tabs()",105);
    */


    select_a_menu("menu_events");
    tabs1.set_extra_bits_for_visible_tab(0);

    // NOTE: we should be all loaded here.


    



    //setVisible_id("login", 1);

    //tabs.set_visible_tabidx(0);
}


function set_music_player() {

   el = getElement('music_player_goes_here');

   //NOTE: we're disabling the player here.
   return

   el.innerHTML = ' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="188" height="60"> <param name="movie" value="ppplayer.swf"> <param name="quality" value="high"> <embed src="ppplayer.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="188" height="60"></embed> </object> ';

}

function myonload() {
    set_music_player();
}

//setTimeout("get_front_page_listings()",1);
//alert("before get front");


//alert("after get front");


window.onload = myonload;

function set_left_tabs_sets_invisible() {
    // makes all the left tabs sets invisible, all the odd ones.
    for(i=1; i < 20; i+=2) {
        try {
            eval('tabs' + i + ".setVisible(0);");
        } catch(e) {
            var noop =1;
        }
    }
}


// e 1, n 3, p 5, r 7, a 9

//selected_menu_id = "menu_events";
selected_menu_id = "";

function select_a_menu(menu_id) {
    // don't do anything if we are already on the selected menu.
    if(menu_id == selected_menu_id) {
        return;
    }
    if(selected_menu_id == "") {
        selected_menu_id ="menu_events";
    } else {
        el = getElement(selected_menu_id);
        el.innerHTML = el.innerHTML.replace("topmenu-selected", "topmenu");
    }

    el = getElement(menu_id);
    el.innerHTML = el.innerHTML.replace("topmenu", "topmenu-selected");
    selected_menu_id = menu_id;
}





function TabsInfo() {

    this.menuids = new Array();
    this.menuids['event'] = "menu_events";
    this.menuids['news'] = "menu_news";
    this.menuids['profileAlias'] = "menu_profiles";
    this.menuids['review'] = "menu_reviews";
    this.menuids['article'] = "menu_articles";
    this.menuids['venue'] = "menu_venues";
    
    this.tab_classes = new Array();
    this.tab_classes['event'] = 'button3';
    this.tab_classes['news'] = 'button3';
    this.tab_classes['profileAlias'] = 'button2';
    this.tab_classes['review'] = 'button4';
    this.tab_classes['article'] = 'button1';
    this.tab_classes['venue'] = 'button1';

    this.tab_classes['list_event'] = 'button3';
    this.tab_classes['list_news'] = 'button3';
    this.tab_classes['list_profileAlias'] = 'button2';
    this.tab_classes['list_review'] = 'button4';
    this.tab_classes['list_article'] = 'button1';
    this.tab_classes['list_venue'] = 'button1';

    this.top_text = new Array();
    this.top_text['event'] = "<strong>Event.</strong>";
    this.top_text['news'] = "<strong>News.</strong>";
    this.top_text['profileAlias'] = "<strong>Profile.</strong>";
    this.top_text['review'] = "<strong>Review.</strong>";
    this.top_text['article'] = "<strong>Article.</strong>";
    this.top_text['latest'] = "<strong>Latest.</strong>";
    this.top_text['venue'] = "<strong>Venue.</strong>";

    this.top_text['list_event'] = "<strong>Event.</strong>";
    this.top_text['list_news'] = "<strong>News.</strong>";
    this.top_text['list_profileAlias'] = "<strong>Profile.</strong>";
    this.top_text['list_review'] = "<strong>Review.</strong>";
    this.top_text['list_article'] = "<strong>Article.</strong>";
    this.top_text['list_latest'] = "<strong>Latest.</strong>";
    this.top_text['list_venue'] = "<strong>Venue.</strong>";

    this.bottom_text = new Array();
    this.bottom_text['event'] = "";
    this.bottom_text['news'] = "";
    this.bottom_text['profileAlias'] = "";
    this.bottom_text['review'] = "";
    this.bottom_text['article'] = "";
    this.bottom_text['latest'] = "";
    this.bottom_text['venue'] = "";

    this.bottom_text['list_event'] = "";
    this.bottom_text['list_news'] = "";
    this.bottom_text['list_profileAlias'] = "";
    this.bottom_text['list_review'] = "";
    this.bottom_text['list_article'] = "";
    this.bottom_text['list_latest'] = "";
    this.bottom_text['list_venue'] = "";



}




TabsInfo.prototype.get_tabs_object = function get_tabs_object(ofwhat) {

    switch(ofwhat) {
        case "event":
        case "list_event":
            return tabs1;
        case "latest":
        case "list_latest":
            return tabs2;
        case "news":
        case "list_news":
            return tabs3;
        case "profileAlias":
        case "list_profileAlias":
            return tabs5;
        case "review":
        case "list_review":
            return tabs7;
        case "article":
        case "list_article":
            return tabs9;
        case "venue":
        case "list_venue":
            return tabs10;
        default:
            alert("error:TabsInfo.prototype.get_tabs_object...");
            alert(this.ofwhat);
    }
}
TabsInfo.prototype.get_tabs_object_from_name = function get_tabs_object_from_name(tab_name) {
    eval('var return_the_tabs = ' + tab_name + ';');
    return return_the_tabs;
}




last_visible_ofwhat = "";
TabsInfo.prototype.show_menu =  function (ofwhat) {

    select_a_menu(this.menuids[ofwhat]);

    // we see if we can short cut setting them all invisible.
    if(!last_visible_ofwhat) {
        set_left_tabs_sets_invisible();
    } else {
        var last_thetabs = this.get_tabs_object(last_visible_ofwhat);
        last_thetabs.setVisible(0);
    }
    var thetabs = this.get_tabs_object(ofwhat);
    thetabs.setVisible(1);

    last_visible_ofwhat = ofwhat;

    return false;
}

var tab_info = new TabsInfo();








function clear_tab_bodies() {
    // set up the default tab bodies.
    //for (i=0; i<tabs.tab_bodies.length; i++) {
    //    tabs.tab_bodies[i].setHTML("");
    //}
    //tabs.tab_bodies[0].setHTML('<iframe src="reviews.html" frameborder="0" width="378" height="366" scrolling="yes" name="left"></iframe>');
    //alert("hi");


    return false;
}



