/*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="'";
var quote='"';
var searchchar='-+';

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+space);}
function isSearch(param) {return isValid(param,lwr+upr+space+apostrophe+phonechars+quote+searchchar);}

/*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,width,height){
	if(caption=="undefined"){
		caption=" ";
		}
	var capdivwidth=width-50;//40 is the width assigned in the content formatting function for new window size...
	//var height=height+10;
	newWindow=window.open("","Image",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,scrollbars=1,width='+width+',height='+height+',screenX=600,screenY=300,top=300,left=600');
	newWindow.document.writeln('<html>');
	newWindow.document.writeln('<head>');
	newWindow.document.writeln('<title>'+img+'</title>');
	newWindow.document.writeln('<style>');//.caption{margin:15px 0 0 0;padding:10px 0 0 0;width:'+capdivwidth+'font-family:verdana;font-size:13px;line-height:14px;}');
	newWindow.document.writeln('.captionbox{margin:15px 8px 8px 8px;padding:10px 5px 5px 5px;background-color: #FFFFFF;');
	newWindow.document.writeln('width:'+capdivwidth+';font-family:verdana;font-size:13px;}</style>');
	newWindow.document.writeln('</head><body>');

	newWindow.document.writeln('<img src="'+ img +'"><br>');
	newWindow.document.writeln('<div class="captionbox">'+ unescape(caption) +'</div>');
	//newWindow.document.writeln('</div>');
	
	//newWindow.document.writeln('<div 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);
}
/*====================
#	browser detection function
#	http://www.quirksmode.org/js/detect.html
#
#=====================*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

	/*

===================================================
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-levels. 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";
					
					
					if(BrowserDetect.browser=='Safari'){//this is one case where mac gets a bad display: This fixes Safari skitchiness

						menu.style.top = this.offsetTop + this.offsetHeight -12 + "px";
					}else{
						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() {

		var root = document.getElementById("menuList");
		if(root != null){
			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)
	var 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)
	var 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(!isSearch(term)){
	alert(errors[28]+term);//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;
	}
}

//closes a pop-up and refreshes the parent

function closeNfresh(){
	window.opener.location.reload();
	window.close();

}
//highlights a div...call with onMouseover
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='';
}

/*Use this for checkboxes--lets you check all (or none) of the fields in a form. 
Usage:
<input type="checkbox" name="list" value="4">HTML<br>
<input type="checkbox" name="list" value="5">SQL<br>
<input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> */

function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function updateTime(itemid){

		
		var theitem;
		var mselect;
		var dselect;
		var yselect;
		
		var hselect;
		var minselect;
		var apselect;
		
		if(!itemid){
			theitem=document.Form1;
			mselect=theitem.month;
			dselect=theitem.day;
			yselect=theitem.year;
			hselect=theitem.hour;
			minselect=theitem.minute;
			apselect=theitem.ampm;
			
			mselect=theitem.month;
			dselect=theitem.day;
			yselect=theitem.year;
		
			hselect=theitem.hour;
			minselect=theitem.minute;
			apselect=theitem.ampm;
			
			}else{
			
			var amonth='month'+itemid;
			var aday='day'+itemid;
			var ayear='year'+itemid;
			var ahour='hour'+itemid;
			var aminute='minute'+itemid;
			var aampm='ampm'+itemid;
			
			var ahselect= 'hour'+itemid;
			var aminselect= 'minute'+itemid;
			var aapselect= 'ampm'+itemid;
			
			
			

			mselect=$(amonth);
			dselect=$(aday);
			yselect=$(ayear);
			hselect=$(ahour);
			minselect=$(aminute);
			apselect=$(aampm);
			
			
			}
		
		var now = new Date();
		var thehour = now.getHours();
		var theminute= now.getMinutes();
		var theyear = now.getFullYear();
		var themonth = now.getMonth();
			themonth=themonth+1;
		var theday= now.getDate();
		

		for (var i = 0; i < mselect.length; i++){
		
				if(mselect.options[i].value==themonth){
					
					mselect.options[i].selected=true;
					}else{
					mselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < dselect.length; i++){
		
				if(dselect.options[i].value==theday){
					dselect.options[i].selected=true;
					}else{
					dselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < yselect.length; i++){
		
				if(yselect.options[i].value==theyear){
					yselect.options[i].selected=true;
					}else{
					yselect.options[i].selected=false;
					}

		}
		
		
		
/* time select stuff */


var ap = "AM";
if (thehour   > 11) { ap = "PM";        }
if (thehour   > 12) { thehour = thehour - 12; }
if (thehour   == 0) { thehour = 12;        }
		
		
		
		for (i = 0; i < hselect.length; i++){
		
				if(hselect.options[i].value==thehour){
					hselect.options[i].selected=true;
					}else{
					hselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < minselect.length; i++){
		
				if(minselect.options[i].value==theminute){
					minselect.options[i].selected=true;
					}else{
					minselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < apselect.length; i++){
		
				if(apselect.options[i].value==ap){
					apselect.options[i].selected=true;
					}else{
					apselect.options[i].selected=false;
					}

		}
		
		
}