//single function used to read, write or update cookies
function writeGetCookieVal(cookieName,cookieNameVal)
{
	if(!cookieNameVal)//determines whether to read or write a cookie
	{
		//the following code reads a cookie
		var thisCookie = document.cookie.split("; ")//turns the cookie into an array
		
		for(nCount = 0; nCount < thisCookie.length; nCount++) //counts through the array
		{
			if(cookieName == thisCookie[nCount].split("=")[0]) //finds the name of the cookie
			{	
				return thisCookie[nCount].split("=")[1] //returns the value of the cookie
			}
		}
		return null //returns null if the cookie name cannot be found 
	}
	else //the following code writes or updates the cookie
	{
		var expireDate = new Date //gets current date
		expireDate.setMonth(expireDate.getMonth() + 6) //sets expiration date of cookie

		// this code writes the cookie
		document.cookie = cookieName + "=" + cookieNameVal + ";expires=" + expireDate.toGMTString()
	}
}// end writeGetCookieVal()

function cookieDel(delCookie)
{
	var thisCookie = document.cookie.split("; ")
	var expireDate = new Date
		expireDate.setDate(expireDate.getDay() - 1)

	for(nCount = 0; nCount < thisCookie.length; nCount++) //counts through the array
		{
			if(delCookie == thisCookie[nCount].split("=")[0]) //finds the name of the cookie
			{	
				document.cookie = delCookie + "=;expires = " + expireDate.toGMTString()
			}
		}
}

function modifyDate()
{
	//creates variable & places lastModified date in it
	var modDate = new Date(document.lastModified)
	var day = modDate.getDate()//gets day date from lastModified date
	var month = parseInt(modDate.getMonth()) + 1//gets month from lastModified date
	var year = modDate.getFullYear()//gets full year from lastModified date
	//creates the string about copyright, lastModified date & warning
	var date = day + "/" + month +  "/" + year
	var copyStr = "<table width = '100%'>"
		copyStr += "<tr>"
		copyStr += "<td>"
		copyStr += "<p align = 'center'>"	
		copyStr += "<font size='1' face='Times Roman' color = 'blue'>"		
		copyStr += "© Copyright 2002 <a href ='mailto:soriley@ozemail.com.au?subject=Teralba Scout Web Site'>Shane O'Riley </a>"
		copyStr += "<br>"
		copyStr += "last modified: " + date
		copyStr += "<br>All materials on this site MAY NOT be used without prior written permission."
		copyStr += "</font></p>"
		copyStr += "</td>"
		copyStr += "</tr>"
		copyStr += "<table>"
	return(copyStr)//returns the string
}

	//set first 3 vars to false & last 2 to empty
	var isDHTML = 0
	var isAll = 0
	var isId = 0

	//detects Dom used and sets is isAll & isDHTML to true
	if(document.all)
	{
		isAll = 1
		isDHTML = 1
	}

	//detects Dom used and sets is is Id & DHTML to true
	else if(document.getElementById)
	{
		isId = 1
		isDHTML = 1		
	}

	//detect if browser is not DHTML capable and displays error message
	else
	{
		document.write("This Browser is not DHTML capable you need to update your current browser to veiw this Site in full."); 
	}

function deterDom(objectId,withStyle)
{
	//return the correct DOM method so to change its style
	if(withStyle == 1)
	{
		if(isAll)
		{
			return(document.all[objectId].style)
		}

		else(isId)
		{
			return(document.getElementById(objectId).style)
		}
	}

	//return the correct DOM method so to add a new style
	else
	{
		if(isAll)
		{
			return(document.all[objectId])
		}

		else(isId)
		{
			return(document.getElementById(objectId))
		}
	
	}
}//end function deterDom()

 
function findLivePageWidth()
{	
	//gets the veiwing area of the current page forthe "all" model
	if(window.innerWidth != null)
		return(window.innerWidth)

	//gets the veiwing area of the current page forthe "getElementById" model
	if(document.body.clientWidth != null)
		return(document.body.clientWidth)

	return (null)
}//end function findLivePageWidth() 

function popUp(evt,objectId,imageName)
{
	if(isDHTML)
	{	
		//gets the viewable width dimension of the page
		var livePageWidth = findLivePageWidth()
			//gets correct dom method and inserts the object's Id
			domStyle = deterDom(objectId,1)
			dom = deterDom(objectId,0)
		//gets  current visibility value of popup window
		var state = domStyle.visibility 

		//method for getting the width of the layer in the "all" model
		if(dom.offsetWidth)
		{
			var elemWidth = dom.offsetWidth
		}
		
		//method for offsetWidth in the "getElementById" model
		else if(dom.clip.width)
		{
			var elemWidth = dom.clip.width

		}

		//makes layer invisible
		if(state == "visible")
		{
			domStyle.visibility = "hidden"
		}

		else
		{
			//get the position of the event in the "getElementById" model
			//and calculates left and top  value
			if(evt.pageY)
			{
				var topVal = evt.pageY + 4
				var leftVal = evt.pageX - (elemWidth / 2)
			}
			
			//get the position of the event in the "all" model 
			//and calculates left and top value
			else if(evt.y)
			{
				var topVal =  2 + document.body.scrollTop
				var leftVal = 2 + document.body.scrollLeft
			}
						
			//keeps layer on screen if calculation puts it off screen to the right
			if((leftVal + elemWidth) > livePageWidth)
			{
				leftVal = leftVal - (elemWidth / 2)
			}

			//keeps layer on screen if calculation puts it off screen to the left
			if(leftVal < 2)
			{
				leftVal = 2
			}
			
			//places the layer in the caculated positions
			domStyle.top = topVal
			domStyle.left = leftVal
			domStyle.visibility = "visible" //makes Popup screen visible
		}//end else
	}//end if(isDHTML)
}//end popUp(evt,objectId)

