/**************************************************************
*				This script written by						   *
*		          Wesley B. Webster							   *
*				   Course4 Project							   *
***************************************************************/

// Global variables  ******************************************

var off = 0
var on = 1

var NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko")) ? true: false;
var msg = "This page requires version 4 or later of\n Netscape Navigator or Internet Explorer";

var nav=((navigator.appName=="Netscape")&&(navigator.userAgent.indexOf("Gecko")==-1));
var iex = (document.all) ? true : false;

//browser sniff
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = nav;


function getRef(disId) {
//alert("in getRef");
if (isDOM) return document.getElementById(disId);
if (isIE4) return document.all[disId];
if (isNS4) return document.HomeMenu;
}

function getSty(disId) {
return (isNS4 ? getRef(disId) : getRef(disId).style);
} 


//====== glow function ================//

var holdC = "";
function glow(t)
{
	holdC = t.className;
	t.className="wMnuGlow";
	t.style.cursor="pointer";
}
function restore(t)
{
	t.className=holdC;
}
function glowAll(par)
{
	var oColl = par.childNodes;
	for(var i=0;i<oColl.length;i++)
	{
		glow2(oColl[i].style);
	}
}
function restoreAll(par)
{
	var oColl = par.childNodes;
	for(var i=0;i<oColl.length;i++)
	{
		restore2(oColl[i].style);
	}
}

function glow2(itm)
{
	holdC = itm.backgroundColor;
	itm.backgroundColor = "#ff0000";
}

function restore2(itm)
{
	itm.backgroundColor = holdC;
}

//====== end glow functions ===========//


function disable(triggerObj, targetObj)
{
	targetObj.disabled = (triggerObj.checked)?false:true;
}

function get24HrTime(s, objAM)
{
	var aTime = s.split(":"); 
	var out = "";
	var notFirst = false;
	if(objAM[1].checked)
	{
		var hh = parseInt(aTime[0], 10);
		if(hh != 12)
		{
			aTime[0] = 12 + hh;
		}
	}
	for(var i=0;i<aTime.length;i++)
	{
		if(notFirst) out += ":";
		out+= aTime[i];
		notFirst = true;
	}
	return out;
}
function get24HrTime2(s, j)
{
	var aTime = s.split(":"); 
	var out = "";
	var notFirst = false;
	if(j == 1 )
	{
		var hh = parseInt(aTime[0], 10);
		if(hh != 12)
		{
			aTime[0] = 12 + hh;
		}
	}
	for(var i=0;i<aTime.length;i++)
	{
		if(notFirst) out += ":";
		out+= aTime[i];
		notFirst = true;
	}
	return out;
}
function doCount(f)
{
	if(f.innerText.length > 3500)
	{
		f.innerText = f.innerText.substring(0,3499);
			
		alert("You have exceeded 3500 characters, your text will be truncated");
	}
}

function disableThis(f, b)
{
	f.disabled = b;
	if(b)
	{
		f.style.backgroundColor="#cccccc";
		f.opts=0;
	}
	else
	{
		f.style.backgroundColor="#ffffff";
		f.opts=1;
	}
}

function doLinkType(field)
{
	//alert("value is:" + field);
	if(field.checked)
	{
		if(field.value==2)
		{
			disableThis(document.getElementById("txtLink"), false);
			document.getElementById("txtReqLink").innerText = "*";
			document.getElementById("txtLink").value="";
		}
		else if(field.value==1)
		{
			disableThis(document.getElementById("txtLink"), false);
			document.getElementById("txtReqLink").innerText = "";
			document.getElementById("txtLink").value="/home/viewEvent.jsp";

		}
		else
		{
			disableThis(document.getElementById("txtLink"), true);
			document.getElementById("txtReqLink").innerText = "";
			document.getElementById("txtLink").value="";

		}
	}
}
function doRSVP(field)
{
	if(field.checked)
	{
		if(field.value==1)
		{
			disableThis(document.getElementById("txtRSVP"), false);
			document.getElementById("txtReqRSVP").innerText = "*";
			document.getElementById("txtRSVP").opts="17";
			document.getElementById("txtValRSVP").value="1";
		}
		else
		{
			disableThis(document.getElementById("txtRSVP"), true);
			document.getElementById("txtReqRSVP").innerText = "";
			document.getElementById("txtValRSVP").value="0";

		}
	}
}


var bnMaps = new Array();
var survCookie
var wThankyou

// This function sets the survey cookie
function tookSurvey(frm)
{
	if (validate(frm))
	{
	
	var expDate = nextYear();
	var user = frm.txtName.value;
	var email = frm.txtEMail.value;

	for (var i=0;i<frm.rbInterest.length ;i++){
	
	  if (frm.rbInterest[i].checked){
		var interest = frm.rbInterest[i].value
	  }
	}	




setCookie("User", user, expDate);
setCookie("EMail", email, expDate);
setCookie("Interest", interest, expDate);

/*
alert(getCookie("User"));
alert(getCookie("EMail"));
alert(getCookie("Interest"));
*/


		if(nav){
	//		alert("before refresh");
			window.opener.location.reload();
		}
    window.close();
    wThankyou = window.open("../home/thankyou.html","bnThankyou","width=200,height=200");
		
	return true;
	}
  else
		return false;
}
// This function sets a date to a year from now *****************

function nextYear(){
var expDate;
var today = new Date();
var NextYear = new Date ();
today = today.getTime();
NextYear.setTime(today + 365 * 24 * 60 * 60 * 1000);
expDate= NextYear.toGMTString();
return expDate;
}

// This is to get cookie for the home page ***********************

function getUser(){
 var UserName = getCookie("User");
 return UserName;
}

function getInterest(){
	var strInterest = getCookie("Interest");
	return strInterest;
}
 


// This function closes the thankyou window

function closeThankyou(){

window.close();
}

// This is the clock function ***********************************

function myClock() {

var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}

if (nav) {
	if(document.navClock.document.clock.txtClock)
	{
		document.navClock.document.clock.txtClock.value = 
		(hours + ":" + minutes + ":" + seconds + " " + dn);
	}
}

if (NS6) {
	
	{
		document.getElementById("txtClock").value = 
		(hours + ":" + minutes + ":" + seconds + " " + dn);
	}
}

if (iex){
	
	if (document.clock)
	{ 
		
		document.clock.txtClock.value = 
		(hours + ":" + minutes + ":" + seconds + " " + dn);
	
	}
}


window.setTimeout("myClock()", 500);
}

// ******************** end clock function  ************************

// ******** on mouse over image object constructor *****************
// cache off-screen images  

function imgObj (imgOff, imgOn) {

	this[off] = new Image();
	this[off].src = imgOff;
	this[on] = new Image();
	this[on].src = imgOn;
}

// ********************** function to cache maps *******************
function cacheMaps() {

	

	for (i=0;i<arguments.length;i++){
		
		bnMaps[i] = new Image();
		bnMaps[i].src = "../maps/" + arguments[i];
	
	}

}

// ********************** cookie area ****************************


// setCookie stores data in a cookie
function setCookie(cName,cValue,eDate,cPath,cDomain,cSecurity) {
  var theCookie = cName + "=" + escape(cValue);                                 // Variable to hold the cookie string
  if (eDate)      theCookie += "; expires=" + eDate              // If an expire date was passed, then use it.
  if (cPath)      theCookie += "; path=" + cPath;                               // If a path was passed, then use it.
  if (cDomain)    theCookie += "; domain=" + cDomain;                           // If a domain was passed, then use it.
  if (cSecurity)  theCookie += "; secure";                                      // If this is for a secure connection, then request one.
  document.cookie = theCookie;
}

// getCookie retrieves data from the named cookie
function getCookie(cName) {
  if (cName) {
    cookieArray = split(";",document.cookie);
    for (i=0; i<cookieArray.length; i++) {
      thisCookie = cookieArray[i];
      if (thisCookie.indexOf(cName+"=") > -1) {
        var valueLoc = thisCookie.indexOf("=")+1;
        cookieValue = thisCookie.substring(valueLoc, thisCookie.length);
        return unescape(cookieValue);
      }
    }
  }
  return false; 
}

// split splits a string into an array
function split(delimiter, theString) {
  theArray = new Array();
  while (theString != "") {
    endOfChunk = theString.indexOf(delimiter);                                  // Find the delimiter.
    if (endOfChunk == -1) endOfChunk = theString.length;                        // If delimiter not found, find end of string.
    var thisChunk = theString.substring(0,endOfChunk);                          // Get the next chunk of text.
    theString = theString.substring(endOfChunk+1,theString.length);             // Remove the chunk we got from the original string.
    theArray[theArray.length] = thisChunk;                                      // Add this chunk to the array.
  }
  return theArray;
}


// Killcookie deletes a cookie
function KillCookie (cookieName, cookiePath, cookieDomain) {
	var theCookie = cookieName + "=";
	if (cookiePath) theCookie += "; path=" + cookiePath;
	if (cookieDomain) theCookie += "; domain=" + cookieDomain;
	theCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	document.cookie = theCookie;
}






// ************* end cookie area *******************************

// ************* last modified function ************************

function myLastMod(strD){
	var strOut = ""
	var dLastMod = new Date(strD);
	var lmYear = dLastMod.getFullYear();
	var lmDate = dLastMod.getDate();
	var lmMonth = dLastMod.getMonth();
	
	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	strOut = (months[lmMonth] + " " + lmDate + ", " + lmYear);
	return strOut;

}

