//these are the scripts for FCCP web page


var gvCurrentPage=null;
var gvShow = false;
var oMenu1;
var oMenu2;
var oSubMenu1;
var oSubMenu2;
var debug=false;

function cachedImg(pImg){
	//for preloading images
	var vImg = new Image();
	vImg.src = pImg;
	return vImg;	
}

function checkBrowser(){
	if (!document.getElementById) document.location = "onepage.html";
	return false;
}

function doRollover(pElem){
	//image rollover
	var vElem, vElemName, vEndRoot, vRoot, vType, vSrc;
	vElemName = pElem.src;
	//alert (vElemName);
	if (vElemName.lastIndexOf("_r")!=-1) return; //don't change a clicked image
	vEndRoot = vElemName.lastIndexOf(".");
	vRoot = vElemName.substring(0,vEndRoot);
	vType = vElemName.substring(vEndRoot);
	vSrc = vRoot + "_r" + vType;
	pElem.src=vSrc;
}

function doRolloff(pElem){
	//image rolloff
	vElemName = pElem.src;
	if (vElemName.lastIndexOf("_d")!=-1) return; //don't change a clicked image
	vEndRoot = vElemName.lastIndexOf("_r");
	vRoot = vElemName.substring(0,vEndRoot);
	vType = vElemName.substring(vElemName.lastIndexOf("."));
	vSrc = vRoot + vType;
	pElem.src=vSrc;
}

function getRef(pElem){
	//alert ("W3C="+W3C+" & NS4="+NS4+" & IE4="+IE4);
	if (document.getElementById){
		return document.getElementById(pElem);
	}else if (document.layers){
		return eval("document." + pElem);
	}else{
		return eval("document.all." + pElem);
	}
}

function initMenu(){
		//create menus
			//create menu objects
			oSubMenu0 = new subMenu("0",3,["Home"],["index"]);
			oSubMenu1 = new subMenu("1",20,["Our People","Our Mission","Our Vision","Our History"],["people","mission","vision","history"]);
			oSubMenu2 = new subMenu("2",20,["Christian Education","Council","Diaconate","Stewardship","Trustees","World Ministries","Our Committees"],["boce","council","diaconate","stewardship","trustees","bowm","committees"]);
			oSubMenu3 = new subMenu("3",20,["Bible Study", "Sunday School", "Confirmation","Vacation Bible School"],["bible","sunschool","confirmation","vbs"]);
			oSubMenu4 = new subMenu("4",20,["Youth Group", "Deacon Families","Choir", "Men's Group"],["youth","families","choir","mensgroup"]);
			oSubMenu5 = new subMenu("5",3,["Calendar of Events"],["calendar"]);
			oSubMenu6 = new subMenu("6",3,["Contact Us"],["contact"]);
			oSubMenu7 = new subMenu("7",3,["Directions"],["directions"]);
			oMenu1 = new menu("1","Who We Are");
			oMenu1.setChild(oSubMenu1);
			oMenu2 = new menu("2","Boards/Committees");
			oMenu2.setChild(oSubMenu2);
			oMenu3 = new menu("3","Education");
			oMenu3.setChild(oSubMenu3);
			oMenu4 = new menu("4","Programs/Activities");
			oMenu4.setChild(oSubMenu4);
			//create menu html
			var vHTML=oSubMenu0.html;
			vHTML+="<div id='menu1' onclick='toggleSelected(\"oMenu1\")'><img id='arrow1' src='images/menuarrow.gif' style='position:relative;top:5'>"+oMenu1.text+oSubMenu1.html+"</div>";
			vHTML+="<div id='menu2' onclick='toggleSelected(\"oMenu2\")'><img id='arrow2' src='images/menuarrow.gif' style='position:relative;top:5'>"+oMenu2.text+oSubMenu2.html+"</div>";
			vHTML+="<div id='menu3' onclick='toggleSelected(\"oMenu3\")'><img id='arrow3' src='images/menuarrow.gif' style='position:relative;top:5'>"+oMenu3.text+oSubMenu3.html+"</div>";
			vHTML+="<div id='menu4' onclick='toggleSelected(\"oMenu4\")'><img id='arrow4' src='images/menuarrow.gif' style='position:relative;top:5'>"+oMenu4.text+oSubMenu4.html+"</div>";
			vHTML+=oSubMenu5.html;
			vHTML+=oSubMenu6.html;
			vHTML+=oSubMenu7.html;
			//alert (vHTML);
			getRef("menu").innerHTML = vHTML;
			oSubMenu0.setDisplay("block");
			oSubMenu5.setDisplay("block");
			oSubMenu6.setDisplay("block");
			oSubMenu7.setDisplay("block");
			if (getCookie("menu1",true) == "selected") toggleSelected("oMenu1");
			if (getCookie("menu2",true) == "selected") toggleSelected("oMenu2");
			if (getCookie("menu3",true) == "selected") toggleSelected("oMenu3");
			if (getCookie("menu4",true) == "selected") toggleSelected("oMenu4");
		}	

//***********Menu object*******************
function menu(pID,pText){
	//properties
	this.id=pID;
	this.state="unselected";
	this.text=pText;
	this.childMenu=null;
	//methods
	this.setChild=m_setChild;
	this.setState=m_setState;
	this.toggleSelected=m_toggleSelected;
}

function m_setChild(pObj){
	this.childMenu=pObj;
}

function m_setState(pState){
	this.state=pState;
}

function m_toggleSelected(){
	if (this.state=="unselected"){
		this.state="selected";
		getRef("arrow"+this.id).src="images/menuarrow_d.gif";
		//alert (this.state);
		this.childMenu.setDisplay("block");
	}else{
		this.state="unselected";
		getRef("arrow"+this.id).src="images/menuarrow.gif";
		this.childMenu.setDisplay("none");
		//alert(this.state);
	}
}

//***************************************************

//***********subMenu object*******************
function subMenu(pID,pPosition,pItemArray,pPagesArray){
	//properties
	this.id=pID;
	this.items = pItemArray;
	this.pages = pPagesArray;
	this.selected=new Array(pItemArray.length);
	this.parentMenu=null;
	this.display="none";
	this.html="";
	//methods
	this.setParent=m_setParent;
	this.setSelected=m_setSelected;
	this.setDisplay=m_setDisplay;
	this.setStyle=m_setStyle;
	this.setProperty = m_setProperty;
	//initialize
	var vHTML = "<div id='subMenu" + pID +"' style='display:none;position:relative;left:"+pPosition+"'>";
	for (i=0;i<pItemArray.length;i++){
		this.selected[i]=false;
		vHTML += "<div id='item"+pID+"_"+(i+1)+"' onclick='showPage(\""+this.pages[i]+"\");oSubMenu"+pID+".setSelected(\""+(i+1)+"\",true);event.cancelBubble=true'>" + this.items[i]+"</div>";
	}
	vHTML+="</div>";
	this.html=vHTML;
	//alert (vHTML);
}

function m_setParent(pMenuObj){
	this.parentMenu = pMenuObj;
}

function m_setSelected(pItem, pSelected){
/*
	for (i=0;i<this.items.length;i++){
		this.selected[i]=false;
		vItem = getRef("item"+this.id+"_"+(i+1));
		vItem.style.color="373DAD"; //set to normal color
		vItem.style.fontStyle="normal";
	}
	*/
	this.selected[pItem-1] = pSelected;
	if (pSelected){
		vItem = getRef("item"+this.id+"_"+pItem);
		vItem.style.color="326B32"; //set to selected color
		vItem.style.fontStyle="italic";
		vItem.style.fontWeight="bold";
	}
}

function m_setDisplay(pDisplay){
	this.display=pDisplay;
	vSubMenu = getRef("subMenu"+this.id);
	vSubMenu.style.display=pDisplay;	
}

function m_setProperty(pProperty, pValue){
	eval("subMenu" + this.id+ "." + pProperty + "=" + pValue);
}

function m_setStyle(pStyle, pValue){
	eval("subMenu" + this.id+ ".style." + pStyle + "=" + pValue);
}
//***************************************************

function openScrollingWindow(pURL,pWidth,pHeight, pName){
	if (pName==null) pName="Popup";
	vParams="menubar,scrollbars,height="+pHeight+",width="+pWidth;
	popupWindow=window.open(pURL, pName, vParams);
	popupWindow.focus();
}

function openWindow(pURL,pWidth,pHeight){
	vParams="menubar,height="+pHeight+",width="+pWidth;
	popupWindow=window.open(pURL, "Popup", vParams);
	popupWindow.focus();
}

function showPage(pID){
	//set temporary menu cookies
	setCookie("menu1",oMenu1.state,true,true);
	setCookie("menu2",oMenu2.state,true,true);
	setCookie("menu3",oMenu3.state,true,true);
	setCookie("menu4",oMenu4.state,true,true);
	document.location =  pID + ".html";	
}

function showText(vText){
	getRef("rollovertext").innerHTML = vText;
}

function setImg(pObj,pSrc){
	getRef(pObj).src="images/" + pSrc;
}

function toggleSelected(pObj){
	eval(pObj+".toggleSelected()");
}


//**************COOKIE FUNCTIONS**********************************

function getCookie(pName,pSingle){
	//retrieves a cookie with the given name
	//pSingle is set to true when cookie is a single value
	if (document.cookie.search(pName)==-1) return -1; //cookie of that name doesn't exist -- array element [0][0] will be null
	var vTemp = document.cookie.split(pName + "=");
	var vTemp2 = vTemp[1]; //this is the data after the parameter
	if (vTemp2.search("; ")){//there are additional parameters to split off
		var vTemp3 = vTemp2.split("; ")
	}
	
	if (pSingle){		
		vCookie = unescape(vTemp3[0]);  //this is the data before the next cookie parameter
	}else{
		//create two dimensional array
		vCookie = new Array();
		var vTemp4 = unescape(vTemp3[0]).split("^|");
		for (x in vTemp4){ 
			vCookie[x] = vTemp4[x].split("|");  //break cookie element into an array (2nd dimension)
		}//end for
	}//end if-else
	//alert (pName + " cookie = " + unescape(vCookie))
	return vCookie;
}

function setCookie(pName,pValue,pTemp,pSingle){
	//set cookie of passed name with the passed value
	//pTemp is passed as a parameter of true if the cookie is only temporary.  It will be written out without an expiration date, which means it won't persist past the current session.
	if (pSingle){
		vValue = pValue
	}else{
		//convert array value to string value
		var vStringValue = new Array(); //use a new array rather than changing the old array directly, because this routine can be called twice for the sort cookie and causes errors once the array value has been converted to a string.
		for (x in pValue){
			vStringValue[x] = makeDelimitedString(pValue[x],"|");
		}
		vValue = makeDelimitedString(vStringValue,"^|");
	}
	var vExp = "";
	if (!pTemp){
		//set the expiration date
		var exp = new Date();
		var v1WeekFromNow = exp.getTime() + (365*7*24*60*60*1000); //expire in a year
		exp.setTime(v1WeekFromNow);
		var vExp = ";expires=" + exp.toGMTString();
	}
	
	//confirmation is for testing so we don't write out a bogus cookie.
	if (debug){
		if (confirm(pName + " cookie = " + vValue + "\nDo you want to set this cookie?")) document.cookie = pName + "=" + escape(vValue) + vExp;
	}else{
	
		document.cookie = pName + "=" + escape(vValue) + vExp;
	}
}
//**********end of cookie functions

function screenml(pExt, pName, pDomain, pDisplay, pClass){
	//function to hide email addresses from Spambots.
	//first 3 parameters must be sent to the function
	//last 2 parameters must be sent as "" if they aren't relevant
	//pExt = domain extension, e.g. "com"
	//pName = email name, e.g. "webmaster"
	//pDomain = web domain, e.g. "msn"
	//pDisplay = display name for mailto link, e.g. "contact us".  If "", the concatonated email address will be used
	//pClass = any class definition you would like to assign to the email link.
	vEmail = pName + "&#064;" + pDomain + "." + pExt; //this is the concatonated email address
	vHREF = "<a ";
	if (pClass!="") vHREF += "class='"+pClass + "' ";
	vHREF += "href='mail" + "to:" + vEmail + "'>";
	if (pDisplay!="") vHREF += pDisplay
	else vHREF += vEmail;
	vHREF += "</a>";
	return (vHREF);
}