/////////////////// UTILITY FUNCTIONS ///////////////////
				
function getHeight(elem) {
	var divHeight=0; 
	divHeight=elem.offsetHeight; 
	return divHeight; 
}

function getWidth(elem) {
	var divWidth=0; 
	divWidth=elem.offsetWidth; 
	return divWidth; 
}

function hideshow(which){
	var layer; 
	layer=document.getElementById(which);
	if (layer.style.display=="block") {
		layer.style.display="none"; 
	} else {
		layer.style.display="block"; 
	} 
}

function get_loading_div() {
	var div='<div id="popup_content_holder"><div id="loading_div"><table><tr><td valign=top><img src="loading_arrow.gif"></td><td valign=top>Loading...</td></div></div>'; 
	return div; 
}

function update_popup(content) {
	var loading=$('popup_content_holder'); 
	loading.innerHTML=content;
}

// make sure they entered something when validating a form
function checkInput(str, output) {
	var msg="";
	if (str=="") msg=msg+output;
	return msg;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/////////////////// TOUR FUNCTIONS ///////////////////

// function to show a tour as being crossed off for whatever reason
function crossoffTour(tour, stripdate) {
	var datediv='date-'+tour;
	$(datediv).innerHTML=stripdate; 
	var timediv='time-'+tour; 
	var typediv='type-'+tour; 
	var optionsdiv='options-'+tour; 
	var alldivs=new Array(datediv, typediv, optionsdiv, timediv); 
	alldivs.each( function(div){
		div=$(div); 
		Element.addClassName(div, 'dropped');
		var content=div.innerHTML; 
		content=content.stripTags(); 
		div.innerHTML=content; 
	});
}

function do_dropTour(result) {
	eval("var customarray = "+result);
	var tour=customarray.tour_id; 
	$('droptour').innerHTML = customarray.message;
	$('droptour').style.padding='5px 0 30px 0;';
	crossoffTour(tour, customarray.stripdate); 
}

function dropTour(tour, guide) {
	x_dropTour(tour, guide, do_dropTour); 
}

function do_showdropTour(result) {
	// create a pop-up form and customize the hell out of it 
	var content='<div id="droptour">'+result+'</div>';
	update_popup(content); 
}

function showdropTour(tour, guide) {
	var loading=get_loading_div(); 
	overlib(loading, WIDTH, 240, STICKY, CAPTION, 'Drop a Tour', EXCLUSIVE, CSSW3C, DIVCLASS, 'ovDiv', BODYCLASS, 'bodyText', CAPTIONCLASS, 'captionText', CLOSECLASS, 'closeText', CLOSECLICK);
	x_showdropTour(tour, guide, do_showdropTour); 
}

/////////////////// CALENDAR FUNCTIONS ///////////////////

function show_loading(){
	document.getElementById('weekchange').style.display='none';
	document.getElementById('loading').style.display='block';
}

function showDates(newdates) {
	var div=document.getElementById('nav_dates_1');
	var wrapper=document.getElementById('nav_dates_wrapper');
	switchWeek();
	//Effect.Fade(div, { duration: 1.0, afterFinish: function(){ div.innerHTML=newdates; Effect.Appear(div, {duration: 1.0, afterFinish: function() { switchWeek(); document.getElementById('loading').style.display='none'; document.getElementById('weekchange').style.display='block'; }}); }});   
	div.innerHTML=newdates;
	// use the callback function instead -> window.setTimeout("makeChange()", 1000);  
}

function displayDates(result) {
	x_printDates(showDates); 
}

function changeDates(direction) {
	show_loading(); 
	x_changeDates(direction, displayDates); 	
}

function showWeek(newtours) {
	var div1=document.getElementById('weekchange');
	div1.innerHTML=newtours;
	document.getElementById('loading').style.display='none'; 
	document.getElementById('weekchange').style.display='block'; 
}

function switchWeek() {
	x_printWeek(showWeek); 
}

function jumpWeek() {
	show_loading();
	var date=document.calendarform.date.value; 
	x_jumpDate(date, displayDates); 
}

function do_updateDay(result) {
	eval("var customarray = "+result);
	document.getElementById(customarray.day_weekday).innerHTML = customarray.day_content;
}

function updateDay(date) {
	x_updateDay(date, do_updateDay); 
}

/////////////////// DISPLAY FUNCTIONS ///////////////////

function do_showGuide(result) {
	eval("var customarray = "+result);
	update_popup(customarray.output); 
}

function showGuide(id) {
	var loading=get_loading_div(); 
	overlib(loading, STICKY, CAPTION, 'Guide Profile', EXCLUSIVE, CSSW3C, DIVCLASS, 'ovDiv', BODYCLASS, 'bodyText_guide', CAPTIONCLASS, 'captionText', CLOSECLASS, 'closeText', CLOSECLICK);
	x_printGuide(id, do_showGuide); 
}

function show_TourCodes(codes) {
	overlib(codes, WIDTH, 320, STICKY, EXCLUSIVE, CLOSECLICK, CAPTION, 'IGIS Tour Codes', CSSW3C, DIVCLASS, 'ovDiv', BODYCLASS, 'bodyText', CAPTIONCLASS, 'captionText', CLOSECLASS, 'closeText');
}