/*****************************************************************/
/* Java Script file for Dove Valley Working Gundog Club pages 	 */
/* This file contains common functions used in one or more pages */
/* on the http://www.dovevalleygundogs.com website 		 */
/* This file was last modified on 04-2-01 by SL 		 */
/*****************************************************************/

/* Not a function, but run at start */
/* Browser detection makes browser type available to all */
/* functions by use of a global variable (OK so not good programming but handy ) */
var Browser=(document.all)?'IE':'Netscape';

/* function to open a small window for displaying latest news items */
/* called by function "doNews" which checks the cookie value */
/* but includes a check for the referrer to prevent news being displayed */
/* if loading index.htm from a link within dovevalleygundogs.com */
/* as that would be REALLY annoying */
/* Receives: Nothing */
/* Returns:  Nothing */

function news()
{
if (document.referrer.indexOf("dovevalley") == -1) /* do only if referrer is not this site */
	{
		window.open("news.htm","newswin","status=0,scrollbars=1,resizable=1,top=0,width=450,height=420");
	}
}



/* function to display an image in a new browser window */
/* receives:	Required - the relative or absolute URL of the image to display */
/*		Optional - the page title */
/* 		if no title is specified then title is set to 'DVWGC Picture Gallery' */
/* returns Null */
/* formats a HTML page on the fly to include border formatting, centering of image, */
/* and adds a button to close the window */
/* Also using the same name "picwin" causes any subsequent image to be displayed */
/* in the same window, overwriting the original. This prevents lots of confusing windows opening */

function PictureWindow(picturl,wintitle)
{
if (arguments.length<2)
	{
		wintitle='DVWGC Picture Gallery';
	}
picwin=window.open("","picwin","left=200,top=0,width=470,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
		picwin.document.write("<HTML><HEAD>");
/* Netscape does not present borders correctly & cant handle cursor:hand so dont bother */
/* Actually Netscape (4.6) does not show a border untill the window is re-sized when it draws */
/* an empty border under the image...close but no cigar Netscape */
		if (Browser=='IE')
		{
			picwin.document.write("<STYLE TYPE='text/css'>IMG{BORDER-STYLE:INSET;BORDER-WIDTH:14px;BORDER-COLOR:#C0C0C0;}INPUT{CURSOR:hand;} }</STYLE>");
		}
		picwin.document.write("<TITLE>"+wintitle+"</TITLE></HEAD><BODY><DIV ALIGN='CENTER'><IMG SRC='"+picturl+"'><BR><BR>");
		picwin.document.write("<FORM><INPUT TYPE='BUTTON' VALUE='Close this window' onClick='self.close()'></INPUT></FORM>");
		picwin.document.write("</DIV></BODY></HTML>");
		picwin.document.close();
		picwin.focus();
}

/* function to get the value of a named Cookie field */
/* Searches all the Cookies for the name passed to it */
/* and returns the Cookie value of that named field */
/* Recieves:	string containing name of field */
/* Returns:	value of the Name=Value pair if a matching name was found */
/*		or numeric 0 if no matching name found but cookies present */
/*		or numeric -1 if no cookies present */
function GetCookieVal(CookieName)
{
	if(document.cookie=="")	/* if no cookies passed from server return -1 */
	{
		return -1;
	}
	thisCookie=document.cookie.split("; ");	/* load an array thisCookie with all individual cookies */
	for (count=0; count < thisCookie.length; count++)
	{
		if(CookieName==thisCookie[count].split("=")[0])	/* then search each name field for match */
		{
			return thisCookie[count].split("=")[1];	/* found so return corresponding value */
		}
	}
	return 0;	/* not found so return 0 */
}

/* function to set a cookie */
/* Recieves:	name and value pair as seperate strings */
/*		optional integer duration of cookie in days */
/* Returns:	Nothing */
/* if duration is not specified, a default of 365 days is made */
function SetCookieVal(cname, cvalue, duration)
{
	if(arguments.length < 3)
	{
		duration=365;
	}
	var today=new Date();
	var expires=new Date();
	expires.setTime(today.getTime()+(duration*1000*60*60*24));
	document.cookie=cname +"="+ cvalue + ";expires=" + expires;
}

/* function to change the setting of ShowNews cookie */
/* Receives:	String of setting to make "yes" or "no" */
/* Returns:	Nothing */
function SetNews(newval)
{
	if (newval=="no")
	{
		SetCookieVal("ShowNews","no");
	}
	else
	{
		SetCookieVal("ShowNews","yes");
	}
}

/* function to display news page if cookie set to yes or no cookie */
/* called from index.htm onLoad event to determine if news is required */
/* Receives:	Nothing */
/* Returns:	Nothing */
/* Hardly worth a function but keeps onLoad of index neat */
function doNews()
{
	if (GetCookieVal("ShowNews")!="no")
	{
		news();
	}
}

/* function to return a string based on difference between */
/* todays date and September 22nd. used for display in the home page and march page*/
/* to countdown and then up, from the March in London */
/* receives: Nothing */
/* returns string for display */

function marchstring()
{
var now = new Date();
var retval;
// set this value to the countdown date.
var then = new Date("September 22, 2002");
var gap = then.getTime() - now.getTime();
gap = Math.ceil(gap / (1000 * 60 * 60 * 24));

if (gap > 0)
  {
  	retval= 'Only '+gap+((gap==1)?' day':' days')+' to the March';
  }
if (gap < 0)
  {
  	retval= Math.abs(gap)+((gap==-1)?' day':' days')+' since we marched';
  }
if (gap==0)
  {
  	retval= 'You should be marching today';
  }

return retval;
}
