/*Universal parameter validation http://javascript.about.com/library/blvalid02.htm*/

var numb='0123456789';
var lwr='abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var emlchars='@.-';
var phonechars='.-()';
var emailPat=/^(.+)@(.+)$/;
var space=' ';
var apostrophe="'";

function isValid(param,val){
	if(param==""){
		//alert('no params');
		return true;
		}else{
			for(i=0;i<param.length;i++){
			
				if(val.indexOf(param.charAt(i),0) == -1) return false;
			
			}
		return true;
			}
}

function isNum(param) {return isValid(param,numb);}
function isLower(param) {return isValid(param,lwr);}
function isUpper(param) {return isValid(param,upr);}
function isAlpha(param) {return isValid(param,lwr+upr);}
function isAlphaSpace(param) {return isValid(param,lwr+upr+space+apostrophe);}
function isAlphanum(param) {return isValid(param,lwr+upr+numb);}
function isSpecial(param) {return isValid(param,lwr+upr+numb+emlchars);}
function isPhone(param) {return isValid(param,numb+phonechars);}


/*pop ups*/

function new_window(url){
	link = 
	window.open(url,"Link",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,width=550,height=490,screenX=600,screenY=300,top=300,left=600');
	}
function new_windowLongTall(url){
	link = 
	window.open(url,"Link",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,scrollbars=1,width=300,height=600,screenX=600,screenY=300,top=300,left=600');
	}
function popCap(img,caption){
	if(caption=="undefined"){
		caption=" ";
		}
	newWindow=window.open("","Image",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,width=550,height=490,screenX=600,screenY=300,top=300,left=600');
	newWindow.document.writeln('<html><body bgcolor="#FFFFFF">');
	newWindow.document.writeln('<head><style>.caption{margin:15px 0 0 0;padding:10px 0 0 0;font-family:verdana;font-size:13px;line-height:14px;}.captionbox{margin:15px 0px 8px 8px;padding:10px 5px 5px 5px;border:1px solid #efefef;background-color: #FFFFFF;width:300px;}</style>');
	newWindow.document.writeln('</head><body>');

	newWindow.document.writeln('<img src="'+ img +'"><br>');
	newWindow.document.writeln('<div class="captionbox"><span class="caption">'+ unescape(caption) +'</span><br>');
	newWindow.document.writeln('</div>');
	newWindow.document.writeln('</body></html>');
	}
	
/*===============
#	function openpopup
#	note: Make sure you enclose the popurl string 
#	in single quotes. Escape them with a backslash if you need to
#	...like "openpopup(\'theurl.php\',500,400,true);
================*/
	
function openpopup(popurl, w, h, sizable) {
	str = 'width='+w+',height='+h;
	if ( sizable != true ) {
		str = str + ',scrollbars=no,resizable=no,status=no';
	} else {
		str = str + ',scrollbars=yes,resizable=yes,status=yes';
	}
	window.open(popurl,'',str);
}


	/*

===================================================
XHTML/CSS/DHTML Semantically correct drop down menu 
===================================================
Author: Sam Hampton-Smith
Site: http://www.hampton-smith.com
Timing Modification: Mark Royko
Site: http://www.markroyko.com

Description:	This script takes a nested set of <ul>s
		and turns it into a fully functional
		DHTML menu. All that is required is 
		the correct use of class names, and
		the application of some CSS.
		
Use:		Please leave this information at the
		top of this file, and it would be nice
		if you credited me/dropped me an email
		to let me know you have used the menu.
		sam AT hampton-smith.com
		
		Doesn't work on three-level drop downs, but works ok
		on two-leves. Plus, you can change the timing.


---------------------------------------------------
Credits: 	Inspiration/Code borrowed from Dave Lindquist (http://www.gazingus.org)
		Menu hide functionality was aided by some code I found on http://www.jessett.com/

*/


	var currentMenu = null;
	var mytimer = null;
	var timerOn = false;
	var opera = window.opera ? true : false;
	
	var timeoutID;
		
	

	if (!document.getElementById)
		document.getElementById = function() { return null; }
	
	function initialiseMenu(menu, starter, root) {
		var leftstarter = false;
	
		if (menu == null || starter == null) return;
			currentMenu = menu;	
			
			starter.onmouseover = function() {
			var thenode=this.parentNode.parentNode;

			clearTimeout(timeoutID);
			timeoutID=setTimeout("premouse()",300);
		
		premouse = function(){
			
			if (currentMenu) {
					if (thenode.parentNode!=currentMenu) {
					currentMenu.style.visibility = "hidden";

				}
			
				
					if (thenode.parentNode==root) {
				
					tempCurrentMenu = currentMenu

						while (tempCurrentMenu.thenode.parentNode!=root) {
						tempCurrentMenu.thenode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu = null;
				starter.showMenu();
				
	        	}
	        	
		}
		
	}
		
		

	
		menu.onmouseover = function() {
			if (currentMenu) {
				currentMenu = null;
				this.showMenu();
	        	}
		}	
	
		starter.showMenu = function(){
			if (!opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetTop + this.offsetHeight + "px";
				}
				else {
				 	menu.style.left = this.offsetLeft + this.offsetWidth + "px";
				 	menu.style.top = this.offsetTop + "px";
				}
			}
			else {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
				 	menu.style.left = this.offsetWidth + "px";
//					alert(this.offsetTop);
				 	menu.style.top = this.offsetTop + "px"; //menu.style.top - menu.style.offsetHeight + "px";
				}

			}
			menu.style.visibility = "visible";
			currentMenu = menu;
		}

		starter.onfocus	 = function() {
			starter.onmouseover();
		}
	
		menu.onfocus	 = function() {
//			currentMenu.style.visibility="hidden";
		}

		menu.showMenu = function() {
			menu.style.visibility = "visible";
			currentMenu = menu;
			stopTime();
		}

		menu.hideMenu = function()  {
			if (!timerOn) {
				//alert(this.id);
				mytimer = setInterval("killMenu('" + this.id + "', '" + root.id + "');", 10);
				timerOn = true;
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}

		menu.onmouseout = function(event) {
			this.hideMenu();
		}

		starter.onmouseout = function() {
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
			clearTimeout(timeoutID);
		}

}
	function killMenu(menu, root) {
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime();
	}
	function stopTime() {
		if (mytimer) {
		 	 clearInterval(mytimer);
			 mytimer = null;
			 timerOn = false;
		}
	} 

	window.onload = function() {
		//alert("loaded");
		var root = document.getElementById("menuList");
		//alert("About to execute getmenus");
		getMenus(root, root);
		
		
/*==================
VERY IMPORTANT!!!! The menu script hijacks the body onload call, so you must either
'drop your load' somewhere else in the page (say a photo or something), or, you can 
enter it within this function like so......
====================*/

//Add other body onload functions here!
		
		//startrotate();
	}

function getMenus(elementItem, root) {
	var selectedItem;
	var menuStarter;
	var menuItem;
	//alert("in getmenus");
	//alert(elementItem.childNodes.length);
	for (var x=0;x<elementItem.childNodes.length;x++) {
		//alert(elementItem.childNodes[x].nodeName);
		if (elementItem.childNodes[x].nodeName=="LI") {
			//alert("Yes!");
			if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
				//alert("Set up");
				menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
				menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
				getMenus(menuItem, root);
				initialiseMenu(menuItem, menuStarter, root);
			}
		}
	}
	//return true;
}

/*===============================
#	Suckerfish drop-down technique
#
#================================*/
/*sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

*/

/*===================================
# Rotation script: Rotates whatever element you want in the page.....(photos, etc.)
#
#====================================*/
	var rotate_delay = 6000; // delay in milliseconds (5000 = 5 secs)
	current = 0;
	var photoarray= new Array()
	photoarray[0]="images/rotate/p1.jpg";
	photoarray[1]="images/rotate/p2.jpg";
	photoarray[2]="images/rotate/p3.jpg";
	photoarray[3]="images/rotate/p4.jpg";
	photoarray[4]="images/rotate/p5.jpg";
	//photoarray[5]="p6.jpg";

	function rotate(){
	current = (current == photoarray.length-1) ? 0 : current+1;
	document.images.show.src = photoarray[current];
	window.setTimeout("rotate()", rotate_delay);
	}
	
	function startrotate(){
	window.setTimeout("rotate()", 6000);
	
	}
	
/*===================================
# Rotation script2: Rotates whatever element you want in the page.....(photos, etc.)
#	This works with the PHP Class for generating featured tombstones
#
#====================================*/
	var rotate_delay2 = 6000; // delay in milliseconds (5000 = 5 secs)
	currentb = 0;
	

	function rotate2(){
	currentb = (currentb == featuredarray.length-1) ? 0 : currentb+1;
	document.images.feach.src = featuredarray[currentb];
	window.setTimeout("rotate2()", rotate_delay2);
	}
	
/*===================JumpPage=======================*/
	

function switchpage(select) {
// JavaScript function for switching to web page when user
// selects option from the given list box.
// Copyright Kelly Yancey, 1997, 1998.
  var index;

  for(index=0; index<select.options.length; index++)
    if(select.options[index].selected)
      {
        if(select.options[index].value!="")
          window.location.href=select.options[index].value;
        break;
      }
}

/*=========================
#	function searchValid()
#	makes sure that search terms are valid before submiting them...
#	======================*/

function searchValid(term){

	if(term=="search"){
	alert(errors[26]);//no first name
	return false;
	
	}else
	
	if((term=="")||(term==null)){
	alert(errors[27]);//no first name
	return false;
	
	}else
	
	if(!isAlphanum(term)){
	alert(errors[28]);//non-alpha
	return false;
	
	}else{
	document.search.submit();
	return true;
	}
	

}

/*Clears content of the search box on click so that 'search' or whatever dummy term is inserted into the search box
is cleared before the user hits 'go';
*/

function clearSearch(box){
	//alert(box);
	box.value="";

}

/*======================
#	The following function set controls
#	toggling divs from visible to invisible. For original
#	source, check local/moofx.radio3
#=======================*/
function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}
function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}

/*=========================
#	radioOn()
#	enclose a radio button with a label and this clicks it on or off based on the area.
#	Usage: <label for="format" onclick="radioOn(getElementById('rad1'));">
#	<input type="radio" id="rad1" name="format" value="T" <?php echo $type_text;?>>&nbsp;Text</label>
#
=========================*/

function radioOn(el){
	el.checked=el.cheked ? false:true;
	return true;

}

/*From the top 10 javascripts of all time. http://www.dustindiaz.com/top-ten-javascript  This one toggles on and off objects. Really nice*/

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

/*Adds events: Another great one: http://www.dustindiaz.com/top-ten-javascript 
#	Usage: Say you want to add a function to be called on load.
#	function test(){
#		alert('loaded');
#		}
#	Just add it like so:
#	addEvent(window,'load',test,false);
#
*/

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

//Cookie functions: Makes Javascript handle cookies like PHP

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}


//Usage:deleteCookie('name','/','');
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function highlight(div_in){	
	var thearea=document.getElementById(div_in);
	thearea.style.backgroundColor='#FFFFCC';
}

function clearHighlight(div_in){
	var thearea=document.getElementById(div_in);
	thearea.style.backgroundColor='';
}

function popSS(){
winObj=window.open("SSlide/holder.html","","width=650,height=600,resizable=yes,scrollbars=yes,location=no");
winObj.focus();

}
