// JavaScript Document
function lib_bwcheck () 
{
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?true:false;
	this.op=(this.agent.indexOf("opera")>-1 && window.opera)?true:false;
	this.op5=(this.agent.indexOf("opera 5")>-1 && window.opera)?true:false;
	this.op6=(this.agent.indexOf("opera 6")>-1 && window.opera)?true:false;
	this.op7=(this.agent.indexOf("opera 7")>-1 && window.opera)?true:false;
  	this.ie5=(this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6 && !this.op7)?true:false;
  	this.ie55=(this.ie5 && this.agent.indexOf("msie 5.5")>-1)?true:false;
  	this.ie6=(this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6 && !this.op7)?true:false;
  	this.ie7=(this.agent.indexOf("msie 7")>-1 && !this.op5 && !this.op6 && !this.op7)?true:false;
  	this.ie=(this.ie4 || this.ie5 || this.ie6 || this.ie7)?true:false;
	this.mac=(this.agent.indexOf("mac")>-1)?true:false;
	this.sa=(this.agent.indexOf("safari")>-1)?true:false;
	this.ff=(this.agent.indexOf("firefox")>-1)?true:false;
	this.ff15=(this.agent.indexOf("firefox/1.5")>-1)?true:false;
	this.ff2=(this.agent.indexOf("firefox/2.0")>-1)?true:false;
	this.ns6=(this.agent.indexOf("gecko")>-1 &&!this.sa  || window.sidebar)?true:false;
	this.ns4=(!this.dom && document.layers)?true:false;
	this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ns4 || this.ns6 || this.op5 || this.op6)

	return this;
}
var bw=new lib_bwcheck()

//////////////////////////////////
// Calendar popup that uses the OverLib class to choose a date
//////////////////////////////////

// Date variables
var monthName = new Array("","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var monthDays = new Array(0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var week = new Array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
var today = new Date();
var disMonth = today.getMonth()+1;
var year = today.getFullYear();
var day = today.getDay();
var dayN = today.getDate();
var days = monthDays[disMonth];
if (year%4 == 0 && disMonth == 2) days = 29;

function getDays() {
	if ((year%4 == 0) && (disMonth == 2))
		d = 29;
	else
		d = monthDays[disMonth];
	return d;
}

// The OverLib class can't accept functions with arguments the following two classes work around that issue
function drawListEndDate() {
	return drawCalendar("end_date");
}

function drawListStartDate() {
	return drawCalendar("start_date");
}

function drawBusLicDate0() {
	return drawCalendar("bus_lic_date[0]");
}

function drawBusLicDate1() {
	return drawCalendar("bus_lic_date[1]");
}

function drawLicDate0() {
	return drawCalendar("lic_date[0]");
}

function drawLicDate1() {
	return drawCalendar("lic_date[1]");
}

function drawLicDate2() {
	return drawCalendar("lic_date[2]");
}

function drawOpenDate1() {
	return drawCalendar("open_1_date");
}

function drawOpenDate2() {
	return drawCalendar("open_2_date");
}

// Used as the template for display in the OverLib class
function drawCalendar(input) {
	txt='<table border="0" cellpadding="0" cellspacing="0" width="139">';
	txt+='<tr>';
	txt+='	<td class="popcalmonth">';
	txt+='	<table border="0" cellpadding="0" cellspacing="0" width="139">';
	txt+='	<tr>';
	txt+='		<td width="12"><a href="javascript:changeMonth(-1,\''+input+'\');"><img src="/resources/img/buttons/white-uparrow.gif" border="0" /></a></td>';
	txt+='		<td width="115" style="text-align: center;"><div id="monthDiv">'+loadMonth()+'</div></td>';
	txt+='		<td width="12"><a href="javascript:changeMonth(1,\''+input+'\');"><img src="/resources/img/buttons/white-downarrow.gif" border="0" /></a></td>';
	txt+='	</tr>';
	txt+='	</table>';
	txt+='	</td>';
	txt+='</tr>';
	txt+='<tr>';
	txt+='	<td><div id="daysDiv">'+loadDays(input)+'</div></td>';
	txt+='</tr></table>';

	return txt;
}

// Loads the current month and year along the top of drawCalendar function
function loadMonth () {
	return monthName[disMonth] + '  ' + year;
}

// Loads the current days in the drawCalendar function
function loadDays (input) {
	firstOfMonth = new Date (year,(disMonth-1),1);
	firstDay = firstOfMonth.getDay();
	txt='<table cellspacing="0" class="popcaldays">';
	txt+='<tr>';
	for (var i=0; i<7; i++) {
		txt+='<td class="weekday">' + week[i] + '</td>';
	}
	txt+='</tr>';
	var jumped = 0;
	var inserted = 1;
	var start = firstDay;
	if (start < 0) start += 7;
	var weeks = parseInt((start + days)/7);
	if ((start + days)%7 != 0) weeks++;
	for (var i=weeks; i>0; i--) {
	  txt+='<tr>';
	  for (var j=7; j>0; j--) {
	    // Build onClick for calendar
		if (inserted<10)
			clickDay='0'+inserted;
		else
			clickDay=inserted;
		if (disMonth<10)
			clickMonth='0'+disMonth;
		else
			clickMonth=disMonth;

		clickDate=' id="c'+inserted+'" onClick="changeInputDate(\''+input+'\',\''+clickDay+'\',\''+clickMonth+'\','+year+'); cClick();" onMouseOver="showHand(\'c'+inserted+'\');"';

	    if (jumped<start) {
	      txt+='<td></td>';
	      jumped++;
		} else if (inserted>days) {
		  txt+='<td></td>';
	      jumped++;
		} else {
		  txt+='<td class="day"'+clickDate+'>' + inserted + '</td>';
	      inserted++;
	    }
	  }
	  txt+='</tr>';
	}
	txt+='</table>';

	return txt;
}

// Used for the up and down arrows next to calendar month and year
function changeMonth(monthChange,input) {
	disMonth += monthChange;
	if (disMonth > 12) {
		disMonth -= 12;
		year += 1;
	} else if (disMonth <= 0) {
		disMonth += 12;
		year -= 1;
	}
	newMonth=loadMonth();
	days = getDays();
	newDays=loadDays(input);
	document.getElementById('monthDiv').innerHTML=newMonth;
	document.getElementById('daysDiv').innerHTML=newDays;
}

// Gets the day/month/year indexes as well as the days in month
function changeInputDate(input,day,month,year) {
	obj = eval("document.getElementById('" + input + "')");
	obj.value = month + "/" + day + "/" + year;
}

function popupPDF(sUrl, winName, w, h) {
	winContent = window.open(sUrl, winName, "top=10,left=10,height="+h+",width="+w+",resizable=yes,menubar=yes,toolbar=yes");
	winContent.focus();
	return true;
}

function popupWin(sUrl, target, w, h, scrollable) {
	x = Math.floor((screen.width - w) / 2);
	y = Math.floor((screen.height - h) / 2);

	winContent = window.open(sUrl, target, "top="+y+",left="+x+",height="+h+",width="+w+",resizable=yes,menubar=no,toolbar=no,location=no,scrollbars="+scrollable);
	winContent.focus();
	return true;
}

function popupFrm(sUrl, fUrl, w, h) {
	x = Math.floor((screen.width - w) / 2);
	y = Math.floor((screen.height - h) / 2);

	frmContent = window.open(sUrl, "frm", "top="+y+",left="+x+",height="+h+",width="+w+",resizable=yes,menubar=no,toolbar=no,location=no,scrollbars=yes");
	document.search.target = "frm";
	document.search.action = sUrl;
	document.search.submit();
	frmContent.focus();
	document.search.target = "_self";
	document.search.action = fUrl;
}

function refreshParent() {
    window.opener.location.reload();
    setTimeout("window.close()", 2000);
}

//////////////////////////////////
// returns the inner width of the browser window, outer width can't be used
// because of AOL and the Netscape 6 toolbar. Add around 15 to 20 pixels to compensate
// for outer width
//////////////////////////////////
function getWindowWidth () {
	if (bw.ie) {
		return document.body.offsetWidth;
	} else {
		return window.innerWidth;
	}
}

function getWindowHeight () {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

// Messages for New Message Notification
function splash(txt)
{
	WinHgt = document.documentElement.scrollHeight;
	WinWdt = document.documentElement.scrollWidth;

	document.getElementById('splashFrame').style.height = WinHgt+'px';
	document.getElementById('splashFrame').style.width = WinWdt+'px';
	document.getElementById('splashFrame').style.display = 'block';
	document.getElementById('splashContainer').style.height = WinHgt+'px';
	document.getElementById('splashContainer').style.width = WinWdt+'px';
	document.getElementById('splashContainer').style.visibility = 'visible';
	if(txt == true) {
		txt = 'While your request is being processed';
	}

	document.getElementById('splashText').innerHTML = txt;
	document.getElementById('splashImg').innerHTML = '<img src="images/busy.gif" />';
	positionSplash();
}

function positionSplash()  {
	WinHgt = (getWindowHeight() / 2) - 60;
	// set new height
	if(document.documentElement.scrollTop) {
		SpHgt = WinHgt + document.documentElement.scrollTop;
	} else {
		SpHgt = WinHgt + document.body.scrollTop;
	}
	document.getElementById('splash').style.top = SpHgt+'px';
	setTimeout('positionSplash()',50);
}

function hideSplash()
{
	document.getElementById('splashFrame').style.display = 'none';
	document.getElementById('splashContainer').style.visibility = 'hidden';
}
// Messages for New Message Notification

function displayDeleteSaved(txt,delhref) {
	overlib(txt+'<div id="centerbtn" style="padding-top:22px;"><div class="commonbtn" onClick="cClick();"><button type="button"><img src="/resources/img/buttons/cancel.gif">Cancel</button></div><div class="commonbtn" onClick="cClick();location.href=\''+delhref+'\';"><button type="button"><img src="/resources/img/buttons/ok.gif">Ok</button></div></div>', WIDTH, 300, HEIGHT, 100, CELLPAD, 10, 10, FGCOLOR, '#edf1f4', BGCOLOR, '#a4b3bf', STICKY, FOLLOWSCROLL, FOLLOWSCROLLREFRESH, 50, EXCLUSIVE, CENTERPOPUP, CENTEROFFSET, 0, -40);
}


function changeTab (tabfocus, len) {
	for (i=1; i<=len; i++) {
		hideObj('content'+i);
		document.getElementById('tab'+i).className='unfocus';
	}
	showObj('content'+tabfocus);
	document.getElementById('tab'+tabfocus).className='focus';
    setFooter();
}

function setFooter () {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			// First get page and footer height
			var contentHeight = document.getElementById('page').offsetHeight;
			var headerHeight = document.getElementById('header').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			// Next get left and right nav height if they exist
			var leftHeight = 0;
			if(document.getElementById('mainl')) {
				leftHeight = document.getElementById('mainl').offsetHeight;
			}

			// Get the longest Height
			var contentDiff  = 0;
			var longestHeight = contentHeight + footerHeight;
			//alert(longestHeight);
			if((leftHeight + headerHeight) > longestHeight) {
				longestHeight = leftHeight + headerHeight;
				if(bw.op) {
					contentDiff = longestHeight - 26;
				} else {
					contentDiff = longestHeight - contentHeight - footerHeight;
				}
			}
			//alert(longestHeight);
			if (windowHeight - longestHeight >= 0) {
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
				document.getElementById('leftbg').style.height = windowHeight + 'px';
			} else {
				footerElement.style.top = contentDiff + 'px';
				document.getElementById('leftbg').style.height = longestHeight + 'px';
			}
		}
	}
}

////////////////////////////
// Tab functions
////////////////////////////

function disDirView (dis, foot) {
	if (dis == 'pic') {
		changeTab(2,2);
	} else {
		changeTab(1,2);
	}
}

function getObjectStyle (obj) {
	if ((bw.dom) && (!bw.ie)) {
		return eval("document.getElementById('" + obj + "').style");
	} else if (bw.ie) {
		return eval("document.all." + obj + ".style");
	}
}

function showObj (obj) {
	var theObj = getObjectStyle(obj);
	theObj.display = 'block';
	theObj.visibility = 'visible';
}

function hideObj (obj) {
	var theObj = getObjectStyle(obj);
	theObj.display = 'none';
	theObj.visibility = 'hidden';
}

////////////////////////////////
// Show hand
////////////////////////////////
function showHand(obj) {
	var theObj = getObjectStyle(obj);
	theObj.cursor = 'pointer';
}

////////////////////////////////
// Thumbnail Navigator
////////////////////////////////

/**********************************************************************************
SideScrollMenu
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>  and modified by Michael van Ouwerkerk
*********************************************************************************/

/**************************************************************************
Scrolling functions
***************************************************************************/
function mLeft(){
	if (!noScroll && oMenu.x<sArrowwidth){
		oMenu.moveBy(sScrollPx,0)
		tim = setTimeout("mLeft()",sScrollspeed)
	}
	showObj('divArrowRight');
	if (!noScroll && oMenu.x>=sArrowwidth){
		hideObj('divArrowLeft');
	} else {
		showObj('divArrowLeft');
	}
}
function mRight(){
	if (!noScroll && oMenu.x>-(oMenu.scrollWidth-(pageWidth))){
		oMenu.moveBy(-sScrollPx,0)
		tim = setTimeout("mRight()",sScrollspeed)
	}
	showObj('divArrowLeft');
	if (!noScroll && oMenu.x<=-(oMenu.scrollWidth-(pageWidth))){
		hideObj('divArrowRight');
	} else {
		showObj('divArrowRight');
	}
}
function noMove(){
	clearTimeout(tim);
	noScroll = true;
	sScrollPx = sScrollPxOriginal;
}
/**************************************************************************
Object part
***************************************************************************/
function makeObj(obj,nest,menu){
	nest = (!nest) ? "":'document.'+nest+'.';
	this.elm = bw.ns4?eval(nest+"document.layers." +obj):bw.ie4?document.all[obj]:document.getElementById(obj);
   	this.css = bw.ns4?this.elm:this.elm.style;
	this.scrollWidth = bw.ns4?this.css.document.width:this.elm.offsetWidth;
	this.x = bw.ns4?this.css.left:this.elm.offsetLeft;
	this.y = bw.ns4?this.css.top:this.elm.offsetTop;
	this.moveBy = b_moveBy;
	this.moveIt = b_moveIt;
	this.clipTo = b_clipTo;
	return this;
}

function b_moveIt(x,y){
	if (x!=null){this.x=x; this.css.left=this.x+px;}
	if (y!=null){this.y=y; this.css.top=this.y+px;}
}
function b_moveBy(x,y){this.x=this.x+x; this.y=this.y+y; this.css.left=this.x+px; this.css.top=this.y+px;}
function b_clipTo(t,r,b,l){
	if(bw.ns4){this.css.clip.top=t; this.css.clip.right=r; this.css.clip.bottom=b; this.css.clip.left=l;}
	else this.css.clip="rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}
/**************************************************************************
Object part end
***************************************************************************/

/**************************************************************************
Init function. Set the placements of the objects here.
***************************************************************************/
function sideInit(){
// Get table width to see if arrows are needed

	//Making the objects...
	oBg = new makeObj('divBg')
	oMenu = new makeObj('divMenu','divBg',1)
	oArrowRight = new makeObj('divArrowRight','divBg')

	//Placing the menucontainer, the layer with links, and the right arrow.
	oMenu.moveIt(sArrowwidth,null)
	oArrowRight.css.width = sArrowwidth;

	//Setting the width and the visible area of the links.
	if (!bw.ns4) oBg.css.overflow = "hidden";
	// Disabled because of Firefox 1.5 & 2
	if (bw.ns6 && !bw.ff15 &!bw.ff2) oMenu.css.position = "relative";
	oBg.css.width = pageWidth+px;
	oBg.clipTo(0,pageWidth+4,sMenuheight,0);
	oBg.css.borderColor = "#a9a9a9";
	oBg.css.borderWidth = "1px";
	oBg.css.borderStyle = "solid";
	oBg.css.visibility = "visible";

	// Get table width to see if arrows are needed
	tWidth = document.getElementById('divMenu').offsetWidth;
	if(tWidth > pageWidth) {
		showObj('divArrowRight');
	}
}

function swapImage(newImg, mpeg, key, type) {
	document.getElementById('imageMain').src     = newImg;
	if(mpeg != 0) {
		document.getElementById('hrefMain').href         = 'javascript:popupWin("/sitetools/video.php?listing_vid='+mpeg+'&listing_key='+key+'", "video","405","390");void(null);';
		document.getElementById('hrefMain').style.cursor = 'pointer';
	} else {
		document.getElementById('hrefMain').href         = 'javascript:void(null);';
		document.getElementById('hrefMain').style.cursor = 'default';
	}
}
