// user verification
// function to send cookie to User

function setCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
// functions to read cookies from User (GetCookie() & getCookieVal() must be used together!)

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i=0;
	while (i < clen) {
		var j = i+alen;
		if (document.cookie.substring(i,j) == arg)
			return getCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// sets cookie time to 6 hrs

var expdate6 =new Date();
expdate6.setTime (expdate6.getTime() + (6 * 60 * 60 * 1000));

// sends the cookie

function sendLoggedInCookie() {
	setCookie("loggedIn","true",expdate6,"/");
}

// when the user tries to log on, checks psswd

function chkPass() {
	if (document.forms[0].password.value == "theboat") {
		sendLoggedInCookie();
		window.location = "members/index.html";
	} else {
		alert("Sorry, that is the wrong Password.  Please try again.");
		document.forms[0].password.focus();
		document.forms[0].password.select();
	}
}

// inside of pages' "onLoad" checks for cookie
	
function checkLoggedIn() {
	if (GetCookie("loggedIn") == "false"
 	 || GetCookie("loggedIn") == "null"
 	 || GetCookie("loggedIn") != "true") {
		window.location = "members.html"
	}
}	
// end of user verification

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		about_over = newImage("images/about2.gif");
		missions_over = newImage("images/missions2.gif");
		gear_over = newImage("images/gear2.gif");
		join_over = newImage("images/join2.gif");
		photo_over = newImage("images/photo2.gif");
		links_over = newImage("images/link2.gif");
		map_over = newImage("images/map2.gif");
		home_over = newImage("images/home2.gif");
		preloadFlag = true;
	}
}
function change()
{
number = Math.floor(Math.random()*7)
if (number==0)
document.write('<img src="images/hp1.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==1)
document.write('<img src="images/hp2.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==2)
document.write('<img src="images/hp3.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==3)
document.write('<img src="images/hp4.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==4)
document.write('<img src="images/hp5.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==5)
document.write('<img src="images/hp6.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
if (number==6)
document.write('<img src="images/hp7.jpg" width=334 height=188 alt="Routt County Search and Rescue">')
}

function openSS(path) {
popSS=window.open(path,"popSS","height=575,width=530,scrollbars=yes,resizable=yes,location=0,screenx=0,screeny=0,left=0,top=0");
popSS.focus()
}
function openSS2(path) {
popSS=window.open(path,"popSS","height=360,width=675,scrollbars=yes,resizable=yes,location=0,screenx=0,screeny=0,left=0,top=0");
popSS.focus()
}

function openSSv(path) {
popV=window.open(path,"popV","height=540,width=440,scrollbars=yes,resizable=yes,location=0,screenx=0,screeny=0,left=0,top=0");
popV.focus()
}


// random image generator
// Set up the image files to be used.
var theImages = new Array() 
// do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'hp_top1.jpg'
theImages[1] = 'hp_top2.jpg'
theImages[2] = 'hp_top3.jpg'
theImages[3] = 'hp_top4.jpg'
theImages[4] = 'hp_top5.jpg'
theImages[5] = 'hp_top6.jpg'
theImages[6] = 'hp_top7.jpg'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="images/'+theImages[whichImage]+'" width=780 height=165 alt=/"Routt County Search and Rescue/">');
}
