/* 
  We no longer include the script tags, so we can no longer include this file with shtml.
  We used to do this because IE 3.x did not support the SRC attribute of the <SCRIPT> tag. :-( 

	File:		contactAllBrowsers.js 
	Comments:	JavaScript code for the AM employee pager interface. This 
				code works on all browsers we care about (3rd & 4th generation) 
				and does not include employee unavailable code.  
	
	Last Modified:		2003-10-13
	Original Author:	Steven Conner
	Last Modified By:	Alex Hisen
*/

function displayBrowserGenerationAlert() { 
//
// Last Modified By: Jeff Huber
// Original Author: Jeff Huber
// Last Modified: 1999-07-23
//
// If browser is less then 4th generation display alert.
//

	if (checkBrowserGeneration() != 1) {
		alert("We have detected you are using a pre 4th generation browser. This application may not function correctly.")
	}
}

function checkBrowserGeneration() {
//
// Last Modified By: Jeff Huber
// Original Author: Jeff Huber
// Last Modified: 1999-07-23
//
// Checks the browser generation. Returns 1 if browser is 4th generation or higher and 0
// if not.
//

	if ((parseInt(navigator.appVersion)) >= 4) { 
		return 1
	} else {
		return 0
	}
}

function checkAll(catagory) {
/*
	Comments:	Attempts to check all the boxes on the pager grid.
*/
	var i;

	for(i=0; i < parent.frames[0].document.CheckForm.elements.length; i++) {
		if ((parent.frames[0].document.CheckForm.elements[i].name).substring(0,9) == "selected_") {
			checkAvailability(parent.frames[0].document.CheckForm.elements[i],catagory,"checkAll");
		}
	}
}

function unCheckAll(){
/*
	Comments:	Unchecks all the boxes in the pager grid.
*/
	for(i=0; i < parent.frames[0].document.CheckForm.elements.length; i++) {
		parent.frames[0].document.CheckForm.elements[i].checked = false;
	}
}

function checkAvailability(checkBox, catagory, callingFunction) {
/*
	Last Modified: 1999-07-24
	Last Modified By: Jeff Huber
	Original Author: Jeff Huber
	
	Comments:	This is a wrapper for the checkAvailabilityOfEmployee. We only run
				checkAvailabilityOfEmployee if browser is 4th generation or greater.
*/

	var empCode = checkBox.name.substring(9,13);  // Get employeeCode from name of checkbox

	if (checkBrowserGeneration() == 1) {
	    //alert ("check browsergeneration == 1!");
	    checkAvailabilityOfEmployee(checkBox, catagory, callingFunction);
	} else if ((callingFunction == "checkAll") 
		 && ((catagory == "all") 
		     || (eval("parent.frames[0].document.CheckForm.catagory_" + empCode + ".value") == catagory))
		 && (eval("parent.frames[0].document.CheckForm.selected_" + empCode + ".checked") != true)) {  
	    eval("parent.frames[0].document.CheckForm.selected_" + empCode + ".checked = true");	
	}


}

function checkPageData(){
/*
	Comments:	Validate form data and return true if it passes.
*/
	var tdce = parent.frames[0].document.CheckForm.elements;  // alias used to shorten some of the lines of code
	var oneChecked = false;
	for(i=0; i < tdce.length; i++) {  // make sure at least one box is checked
	   if (tdce[i].checked == true) {
	      oneChecked = true;
	      break;
	   }
	}
	if (oneChecked == false) {
	   alert("You must check at least one recipient for the page.");   
	   return false;
	}
	if (parent.frames[1].document.ContactForm.sender.value=="") {
	   alert('You must enter your name in the "Message from:" field.');
	   return false;
	}
	if (parent.frames[1].document.ContactForm.senderEmail.value=="") {
	   alert('You must enter your email address in the "at email:" field.');
	   return false;
	}
	if (parent.frames[1].document.ContactForm.data.value=="") {
	   alert("You have not entered a message.");   
	   return false;
	}


	// we use cookies to store the user's name and email address so we can automatically
	// put them in the "Message from:" and "at email:" boxes on the submit form next time
	
	// Set expiration to a year from now.
	var expiration = new Date();
	expiration.setFullYear(expiration.getFullYear() + 1);

	setCookie('pageFrom', parent.frames[1].document.ContactForm.sender.value, expiration, "/");
	setCookie('pageFromEmail', parent.frames[1].document.ContactForm.senderEmail.value, expiration, "/");

	// If we get to this point, the form data is ok so we copy hidden values
	// (basically, a list of page recipients) from CheckForm in topframe to 
	// ContactForm in bottomframe so it can be submitted along with that form.  

	var list = "";
	for(i=0; i < tdce.length; i++) {
		if ((tdce[i].checked == true) && (tdce[i].name.substring(0,9) == "selected_")) {
			list = list + ' ' + tdce[i].name.substring(tdce[i].name.indexOf('_')+1, tdce[i].name.length);
		}
	}
	parent.frames[1].document.ContactForm.recipient_list.value = list;
	return true;
}

/*
	Cookie Functions
	Snatched from the Net
*/
function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
	if (dc.length > 0) {
		begin = dc.indexOf(cname);       
		if (begin != -1) {           
			begin += cname.length;       
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
      		return unescape(dc.substring(begin, end));
		} 
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}



