var oldContent;
var oldControl;
var bbTimeOutId;
var aryQuickCal = new Array(3);
var intQuickCal = 0;
var noshowtitle = false; // DEFAULT SHOW TITLE

// -------------------------
function PreloadThem() { //v3.3
// -------------------------	
  var d=document; 
  if(d.images) 
  { 
  	if(!d.imArr) 
  	   d.imArr=new Array();  	   
  	   
  	   j=d.imArr.length
  	   a=d.images; 
  	   for(var i=0; i<a.length; i++)
       {        	
						d.imArr[j]=new Image; 
						d.imArr[j++]=a[i].src;
    	 }    	
   }
}

// -------------------------
function SetPageTitle(ttl) { 
// -------------------------	
  if(!noshowtitle)
  {
	  if(document.getElementById('innerPageTitl'))
	  {
		  var menuTst = accHash.get(mainCat);		
			if(typeof(menuTst)!="undefined")
			{
				if (accHash.get(mainCat)=='0') {}
				else
				{
			 	    changeInnerHTML('innerPageTitl',ttl);
			 		 	document.getElementById('innerPageTitl').style.display='block';
			 	}
			}
	  }
  }
}

// -------------------------
function addEvent(func) {
// http://simon.incutio.com
// -------------------------
  var loader = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (loader) {
        loader();
      }
      func();
    }
  }
}

// CALL ONLOAD
// addEvent(PreloadThem());
// addEvent(function(){});

// -------------------------
function writeTime() {
// -------------------------	
	var tS, Hours, Mins, Time, s;
	tS = new Date();
	Hours = tS.getHours();
	if (Hours >= 12) {Time = " PM";}
	else {Time = " AM";}
	if (Hours > 12) {Hours -= 12;}
	if (Hours == 0) {Hours = 12;}
	Mins = tS.getMinutes();
	if (Mins < 10) {Mins = "0" + Mins;}
	s = Hours + ":" + Mins + Time;
	return s;
//-->
}

// -------------------------
function chooseDate () {
// -------------------------
		document.searchform.Interval.options[0].selected = true;
		document.searchform.Interval.options[document.searchform.Interval.options.length-1].selected = true;
} 	
//---------------------------	
function ResetDate () {
//---------------------------	
 if (document.searchform.Interval.selectedIndex != 0)
 {
  document.searchform.dateselected.value = "";
  document.searchform.mydate.value = document.searchform.Interval.options[document.searchform.Interval.selectedIndex].text;
 }
 if (document.searchform.Interval.selectedIndex != (document.searchform.Interval.options.length-1))
 {
  document.searchform.dateselected.value = "";
 }
}

//---------------------------	
function radioCheck(obj,msg) {
//---------------------------	
 var b = false;
 for(var i=0;i<obj.length;i++)
 {
	if(obj[i].checked==true)
	  b = true;
 }
 if(!b)
	alert(msg); 	
  return b; 	
}

//-------------------
function switchElements(intThisId, strBase, intTotalIds)
//-------------------
{
	document.getElementById(strBase+intThisId).style.display="block";
	for (var i=1; i<=intTotalIds; i++)
	{
		if (i != intThisId)
		{
			document.getElementById(strBase+i).style.display="none";
		}
	}
}
//-------------------
function init_topstory() {
	random_num = (Math.round((Math.random()*4)+1));
	document.getElementById('topS'+random_num).style.display="block";
	for (var i=1; i<=5; i++) {
			if (i != random_num) {
				document.getElementById('topS'+i).style.display="none";
			}
	}
}
//-------------------

//---------------------------	
function changeInnerHTML(divId,html)
//---------------------------
{
 if (document.getElementById) {
       document.getElementById(divId).innerHTML= html;
 }else{
     document.layers[divId].document.open();
     document.layers[divId].document.write(html);
     document.layers[divId].document.close();
 }
}

//---------------------------	
function NewWindow(w,h,u) {
//---------------------------	
	window.open(u,"_blank","menubars=0,scrollbars=1,resizable=1,height="+h+",width="+w);
}

//---------------------------	
function PopIt(nm,url,h,w) {
//---------------------------	
	newwindow=window.open(url,nm,'height='+h+',width='+w);
  if (window.focus) {newwindow.focus()}
	return false;
}

//---------------------------	
function NewWindowGallery(w,h,u) {
//---------------------------	
	window.open(u,"_blank","menubars=0,scrollbars=1,resizable=1,height="+h+",width="+w);
}

//---------------------------	
function jump(fe){
	//---------------------------	
		var opt_key = fe.selectedIndex;
		var uri_val = fe.options[opt_key].value;
		window.open(uri_val,'_top');
		return true;
}
 	
//---------------------------	
function jumpnew(fe){
	//---------------------------	
		var opt_key = fe.selectedIndex;
		var uri_val = fe.options[opt_key].value;
		window.open(uri_val,'_blank');
		return true;
}
//-------------------
function ShowHide(id)
//-------------------
 {
    obj = document.getElementsByTagName("div");
    if (obj[id].style.visibility == 'visible'){
    obj[id].style.visibility = 'hidden';
    }
    else {
    obj[id].style.visibility = 'visible';
    }
}

//-------------------
function checkIt(string) {
//-------------------
	var detect = navigator.userAgent.toLowerCase();
	var place,thestring;
	place = detect.indexOf(string) + 1;
	return place;
}

//-------------------
function liaOn(num) {
//-------------------
	document.getElementById('LI'+num).style.border='1px solid #043D63';
	document.getElementById('LI'+num).style.padding='2px 2px 2px 1px';
	document.getElementById('A'+num).style.color='#444';
}

//-------------------
function liaOff(num) {
//-------------------
	document.getElementById('LI'+num).style.border='none';
	document.getElementById('LI'+num).style.padding='3px 3px 3px 2px';
	document.getElementById('A'+num).style.color='#043D63';
}

//-------------------
function switch_tabs(idbase, activebase, thisidnum, totalids) {
//-------------------
	document.getElementById(idbase+"cats"+thisidnum).className = activebase+"active";
	document.getElementById(idbase+"list"+thisidnum).style.display = "block";
	for(i=1; i<=totalids; i++) {
		if(i!=thisidnum) {
			document.getElementById(idbase+"cats"+i).className = activebase+"inactive";
			document.getElementById(idbase+"list"+i).style.display = "none";
		}
	}
}

function calChange(cmonth) {
	a = window.location.search.substr(1).split("&");
	var found = false;
	for (var i=0; i<a.length; i++) {
		if (a[i].substr(0,8).toLowerCase() == "caldate=") {
			a[i] = "CalDate=" + cmonth;
			found = true;
		}
	}
	if (!found) {
		a.length++;
		a[a.length-1] = "CalDate=" + cmonth;
	}

	var sLoc = (window.location.pathname=="/" || window.location.pathname.length == 0)?"/apps/pbcs.dll/frontpage?" + a.join("&"):window.location.pathname + "?" + a.join("&");
	sLoc = sLoc.replace(/\?\&/g, "?") + "#cal";
	window.location = sLoc;
}

var map;

function LoadYMap(lat, lng, zm, w, h) {
	var yS = new YSize(w, h);
	map = new YMap(document.getElementById('ymapContainer'),YAHOO_MAP_REG, yS);
	map.disableKeyControls();
	var startPoint = new YGeoPoint(lat,lng);
	map.drawZoomAndCenter(startPoint,zm);
	
	//map.addTypeControl();

	var zp = new YCoordPoint(5,5);
	zp.translate('right','top');
	map.addZoomLong(zp);

}

var removeControls = function(e) {
	//map.panToLatLon(this.YGeoPoint); 
	//map.drawZoomAndCenter(this.YGeoPoint,map.getZoomLevel());
	//console.debug(this.YGeoPoint);
	map.removeZoomControl();
}

var addControls = function(e) {
	//map.panToLatLon(this.YGeoPoint); 
	//map.drawZoomAndCenter(this.YGeoPoint,map.getZoomLevel());
	//console.debug(this.YGeoPoint);
	var zp = new YCoordPoint(5,5);
	zp.translate('right','top');
	map.addZoomLong(zp);

}

function searchMap(sTerm, startPoint) {
	if (sTerm != "search the map")
	{
	map.removeMarkersAll();
	
	var setupMarker = function(p,d) {
		var m = new YMarker(p);
		m.addAutoExpand(d);
		return m;
	};	
	
	
	// local search
	var searchF = function(e) {
		var _p = [];
		if (e.Data) {
			for (var a in e.Data.ITEMS) {
				var l = e.Data.ITEMS[a];
				if (l.TITLE) {
					var p = new YGeoPoint(l.LATITUDE,l.LONGITUDE);
					_p.push(p);
					var m = setupMarker(p,l.TITLE+"<br />"+l.ADDRESS+"<br /><a href='"+l.BUSINESSURL+"' target='_blank'>"+l.BUSINESSURL+"</a><br />"+l.PHONE);
					map.addOverlay(m);
					YEvent.Capture(m,EventsList.openExpanded,removeControls);
					YEvent.Capture(m,EventsList.closeExpanded,addControls);
				}
			}
		}
	};

	//args: point, query, radius, results n (max 20)
	map.searchLocal(startPoint,sTerm,20,10);

	// setup capture to process on completion of local search
	YEvent.Capture(map,EventsList.onEndLocalSearch,searchF);
	}
	else{alert("Enter search term first"); document.getElementById('search_map').focus()}
}

//-------------------
function clearMap() {
//-------------------	
	map.removeMarkersAll();
	document.getElementById('search_map').value = "search the map";
}

//-------------------
function getElementsByClassName(oElm, strTagName, oClassNames){
//-------------------				
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
    Add-ons by Eric Bonito, http:///www.ottaway.com
*/	
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
var arrRegExpClassNames = new Array();
          if(typeof oClassNames == "object"){
						for(var i=0; i<oClassNames.length; i++){
							arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
						}
					}
					else{
						arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
					}
					var oElement;
					var bMatchesAll;
					for(var j=0; j<arrElements.length; j++){
						oElement = arrElements[j];
						bMatchesAll = true;
						for(var k=0; k<arrRegExpClassNames.length; k++){
							if(!arrRegExpClassNames[k].test(oElement.className)){
								bMatchesAll = false;
								break;
							}
						}
						if(bMatchesAll){
							arrReturnElements.push(oElement);
						}
					}
				// Array support for the push method in IE 5
				if(typeof Array.prototype.push != "function"){
					Array.prototype.push = ArrayPush;
					function ArrayPush(value){
						this[this.length] = value;
					}
				}					
					return (arrReturnElements)
				}
				
//-------------------
function getURLParam(strParamName){
//-------------------
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("&") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}



// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}