
//=========================================================
// Enables button when text is typed in a specified field
//=========================================================
function enableButton(button, target)
{	
	var string = target.value;
	if(string.length > 0)
	{
		button.disabled = false;
	}
	else
	{
		button.disabled = true;
	}
}

//=====================================
// Determines what button was clicked
//=====================================
function buttonClick(buttonID, hiddenSubmit)
{
	hiddenSubmit.value = buttonID;
}

//=====================================
// Determines what button was clicked
// and forces a submit
//=====================================
function buttonClickAndSubmit(buttonID, hiddenSubmit, submitForm)
{
	document.getElementById(hiddenSubmit).value	= buttonID;
	document.forms[submitForm].submit();
}

//=====================================
// Closes the status message summary
//=====================================
function closeStatusMessage()
{
	document.getElementById("Status-Msg").style.display = "none";
}
//=====================================
// Checks all checkboxes
//=====================================
function checkAll(checked)
{
	var checkBoxes = document.getElementsByName('chbDelete');
	var size = checkBoxes.length - 1;
	var x;
	for (x=0;x<=size;x++)
	{
		checkBoxes[x].checked = checked;
	}
}
//===================================
// Adds page to Favorite
//===================================
function addToFavorites(pageName, urlAddress) 
{ 
	if (window.sidebar) 
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(pageName, urlAddress,"");
	} 
	else if( window.external ) 
	{ // IE Favorite
		window.external.AddFavorite(urlAddress, pageName); 
	}
	else if(window.opera && window.print) 
	{ // Opera Hotlist
		var elem = document.createElement('a');
		elem.setAttribute('href',urlAddress);
		elem.setAttribute('title',pageName);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else
	{ // Other Browsers
		alert("Sorry. Your browser doesn't support this feature. Hold Crtl-D to add bookmark.");
	}
}

//====================================
// Date Validation
//====================================
function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
		alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
	}

	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn`t have 31 days!")
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn`t have " + day + " days!");
			return false;
		}
	}
	return true; // date is valid
}


//=====================================
// Menu rollover functionality
//=====================================
menuLi = function() {
	if (document.getElementById("menu"))
	{
		var sfEls = document.getElementById("menu").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" menuLiOver";
			}         
			sfEls[i].onmouseout=function() {  
				this.className=this.className.replace(new RegExp(" menuLiOver\\b"), "");         
			}
		} 
	}
} 
if (window.attachEvent) window.attachEvent("onload", menuLi);

memorialMenuLi = function() {
	if (document.getElementById("memorialMenu"))
	{
		var sfEls = document.getElementById("memorialMenu").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" memorialMenuLiOver";
			}         
			sfEls[i].onmouseout=function() {  
				this.className=this.className.replace(new RegExp(" memorialMenuLiOver\\b"), "");         
			}     
		} 
	}
} 
if (window.attachEvent) window.attachEvent("onload", memorialMenuLi);

membersMenuLi = function() {
	if (document.getElementById("membersMenu"))
	{
		var sfEls = document.getElementById("membersMenu").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" membersMenuLiOver";
			}         
			sfEls[i].onmouseout=function() {  
				this.className=this.className.replace(new RegExp(" membersMenuLiOver\\b"), "");         
			}     
		}
	}
} 
if (window.attachEvent) window.attachEvent("onload", membersMenuLi);



HoverDIV = function() {
	if (document.getElementById("RandomMemorials"))
	{
		var sfEls = document.getElementById("RandomMemorials").getElementsByTagName("div");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" jsHover";
			}         
			sfEls[i].onmouseout=function() {  
				this.className=this.className.replace(new RegExp(" jsHover\\b"), "");         
			}
		} 
	}
} 
if (window.attachEvent) window.attachEvent("onload", HoverDIV);


/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {

    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
} 

/*-----------------------------------------------------------------------
    Counts the amount of characters
    Input: textAreaID = The text area id of the field you want to count
		   limit = An integer representing what the character limit is
    Output: A count of how many characters are left
    ---------------------------------------------------------------------*/
function messageCount(textAreaID, limit) {
	var textArea = document.getElementById(textAreaID);
	
	if (textArea) {
		if (textArea.value.length <= limit) {
			return true;
		}
		else {
			alert('Sorry, your message exceeds the maximum ' + limit + ' characters.');
			return false;
		}
	}
	else {
		return false;
	}
}
