
/*******************************************************************************************
*
* functions.js - JavaScript functions
*
* Date Created: 07/07/05
* Last Update:  07/26/07
*
* History
*
*  07/19/05 (MH): - File creation
*	               - Initial content
*
*	06/19/07 (MH): - Formatted for template
*
*  06/22/07 (MH): - Added ExternalLinks template
*
*	07/26/07 (MH): - Template signoff
*
*******************************************************************************************/

/**************************************************************
*
* 
* Generic Functions
*
*
***************************************************************/

/**
*
* EnableMessagingFields - Enable fields in the Messaging & Events app
*
*/
function EnableMessagingFields() {

	with(document.messagingForm)	 {
	
		messagingTo.disabled                   = !useMessaging.checked;
		messagingCC.disabled                   = !useMessaging.checked;

      if(document.forms['messagingForm'].messagingIncludeContacts)
         messagingIncludeContacts.disabled 	= !useMessaging.checked;
		
      
      messagingSubject.disabled              = !useMessaging.checked;
		messagingMessage.disabled              = !useMessaging.checked;
	}
}

/**
*
* LoadImages - Preload images to be used on the site for 
*					quicker performance
*
*/
function LoadImages()
{
	menuButtonInvertedAbout= new Image()
	menuButtonInvertedAbout.src = "../images/menuButtonInvertedAbout.jpg"
}

/**
*
* ValidEmail - Checks for a valid email address
*
* Arguments
*
*  - address: The email address
*
* Returns
*
*  - True if valid
*
*/
function ValidEmail(address)
{
	var amp = address.indexOf("@");
	var period = address.indexOf(".");
	var result = true;

	if(amp == -1 || period == -1)
		result = false;

	return result;
}

/**
*
* ValidDate - Checks for a a valid date
* 
* Author: Matt Hartzell
*
* Last Updated: 7/10/05
* 
* Arguments
*
*  - day: The day
*  - month: The month
*  - year: The year
*
* Returns
*
*  - True if valid
*
*/
function ValidDate(day, month, year)
{
	var result = true;
	
	if(day == 31 && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11))
	{
		result = false;
	}
	
	if((day == 28 || day == 29) && (month != 2))
	{
		result = false;
	}

	return result;
}

/**
*
* ExternalLinks - Makes links in a page external
*
* Copied from: http://www.sitepoint.com/article/standards-compliant-world/3
*
* Use: Set the rel attribute of an anchor to "external"
*
*/
function ExternalLinks() 
{
	if (!document.getElementsByTagName)
		return;

	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
  			anchor.target = "_blank";
	}
} 

/**
*
* SWFUpload Event Handlers
*
*/

// This function variable is assigned to upload_start_handler in the settings object

var myCustomUploadStartEventHandler = function (file) {

	var continue_with_upload;
	
	if (file.name === "the sky is blue") {
		continue_with_upload = true;
	} 
	
	else {
		continue_with_upload = false;
	}
	
	return continue_with_upload;
};

// This function variable is assigned to upload_success_handler in the settings object
var myCustomUploadSuccessEventHandler = function (file, server_data, receivedResponse) {
	alert("The file " + file.name + " has been delivered to the server. The server responded with " + server_data);
};

/**
*
* OnLoadFunction - Things to do when loading the page
*
*/
function OnLoadFunction()
{
	LoadImages();
	ExternalLinks();
}

/**************************************************************
*
* 
* OnLoad Directives
*
*
***************************************************************/

// Preload images
window.onload = OnLoadFunction;

var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
z}