/**
 * Common Javascript Functions
 *
 * @author gUncle Development [http://www.guncle.com]
 * @version 2.0 2/3/2008
 */


/**
 * Recolors alt rows in table
 * @param string $element = id of table
 */
function colorAltRows(element) {
	if( document.getElementById(element) ) {
		var trs = document.getElementById(element).getElementsByTagName('tr');
		var num=0;
		for( var n=0; n<trs.length; n++ ) {
			var curclass = '';
			if( getClassName(trs[n]) ) {
				curclass += getClassName(trs[n]);
			}
			if( curclass.indexOf('table_header') < 0 ) {
				curclass = curclass.replace('alternate','');
				if( num%2 ) {
					curclass += ' alternate';
				}
				setClassName(trs[n],curclass);
				if( curclass.indexOf('hidden') < 0 ) {
					num++;
				}
			}
		}
	}
}


/**
 * Gets class name of specific element
 * @param string $element | the element to retrieve class name of
 */
function getClassName(element) {
	var className = (document.all && document.getElementById ? element.className : element.getAttribute("class"));
	return className;
}


/**
 * Sets class name of specific element
 * @param string $element = element to set class name for
 * @param string $style = class name to assign to element
 */
function setClassName(element,style) {
	if( document.all && document.getElementById ) element.className=style;
	else element.setAttribute("class", style);
}


/**
 * Displays pages dropdown
 * @param string $page = url of current page
 */
function pagesTop(page) {
	var url = document.getElementById("pagesDropdownTop").value;
	window.location = page + "?pstart=" + url;
}
function pagesBottom(page) {
	var url = document.getElementById("pagesDropdownBottom").value;
	window.location = page + "?pstart=" + url;
}


/**
 * Pop open photo window
 * @param string $url = folder name for photos
 * @param integer pyear = year of the photos for folder
 */
function photo(url,pyear) {
	var photos = "/photos/" + pyear + "/" + url + "/index.html";
	window.open(photos,"photos","toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=850,height=750");
}

/**
 * Processes an action when a select box is changed
 * @param string $page = url of current page
 * @param string $selectbox = name of select box
 * @param string $variable = name of url variable
 */
function select_refresh(page,selectbox,variable) {
	var obj = document.getElementById(selectbox).value;
	window.location = page + variable + "=" + obj;
}

/**
 * Toggle e-mail messages
 * @param string $key = id of message
 */
function toggleMessage(key) {
	if( document.getElementById('message' + key).style.display == 'none' ) {
		document.getElementById('message' + key).style.display = '';
	}
	else {
		document.getElementById('message' + key).style.display = 'none';
	}
}


/**
 * Toggles value in search field
 * @param bool $toggle = on off for if field is blank
 */
function toggleSearch(toggle) {
	var words = document.getElementById('words');
	if( words ) {
		if( toggle==1 && words.value=='Search' ) {
			words.value='';
		}
		else if( toggle==0 && words.value=='' ) {
			words.value='Search';
		}
	}
}


/**
 * Displays comment box
 */
function commentBox() {
	if( document.getElementById('commentbox').style.display == 'none' ) {
		document.getElementById('commentbox').style.display = '';
	}
	else {
		document.getElementById('commentbox').style.display = 'none';
	}
}


/**
 * Starts photo slideshow
 */
function viewSlideshow() {
	$('lightboxSSFirst').onclick();
	Lightbox.prototype.startSlideshow();
}
