function fetchAd() {
// pulls from a list of candidates, does not repeat last seen
	var ads = new Array('caribbean_banner.png',
											'gastips.png',
											'travelstore.png',
											'Travel.gif',
											'ERSOL.png');
	var links = new Array('http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=aaa&club=032&page=PartnerRedirect&PID=412',
												'http://www.aaa.com/aaa/032/home/safety/GasWatchersGuide2004.pdf',
												'http://www.aaa.com/aaa/032/offices/Palomar.html',
												'http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=aaa&club=032&page=FareFinder',
												'http://www.aaa.com/aaa/032/home/automotive/ERSOnline.html');
	var cGet = unescape(document.cookie);
	var cLen = document.cookie.length;           // length of cookie
	var cBase = cGet.indexOf('last_ad', 0);      // find the index of the cookie
	if (cBase == -1) cVal = -1;                  // name/value not found
	else {
		var cEnd = cGet.indexOf (";", cBase+8);    // start at end of 'last_ad=' and look for ';'
		if (cEnd == -1)                            // no trailing ';' (last n/v pair in cookie)
			cEnd = cGet.length;                      // ...so will go to the end
		var cVal = unescape(cGet.substring(cBase+8, cEnd)); // read from '=' to ';' or end
	}

	var nextad = Number(cVal)+1;	// increment ads in order
	if(nextad == links.length) { nextad = 0; }
	
	document.writeln('<a href=\"'+links[nextad]+'\"><img src="/aaa/032/images/bannerads/'+ads[nextad]+'" alt="special offers from AAA" width="468" height="60" border="0" /></a>');
	cookieContent = 'last_ad=' + nextad + ';path=/';
	document.cookie = cookieContent;					// write cookie
}


function randInt(upper) {
	do {
		var rand = Math.floor(Math.random()*10);  // returns 0 - 9
	} while(rand >= upper);
	return(rand);
}


function fetchSidebar() {
// generates data in otherwise empty div#sidebar
	//document.writeln('<p>[sidebar dynamic content here]</p>');
}


function randInt(upper) {
	do {
		var rand = Math.floor(Math.random()*10);  // returns 0 - 9
	} while(rand >= upper);
	return(rand);
}


function glueTo(to,about) {
/*	assembles address from pieces to help
		minimize adress harvesting */
// http://forums.devshed.com/t87460/s.html
	var dom = 'aaabluegrass';
	var tld = 'com';
	var ful = to + '@' + dom + '.' + tld;
	document.location = 'mai' + 'lto:' + ful + '?su' + 'bject=' + escape(about);
}

function todaysDate() {
/*	returns string in form DDDD, MMMM dd, YYYY */
// http://developer.irt.org/script/34.htm
	var months = new Array('January','February','March',
			'April','May','June','July','August','September',
			'October','November','December');
	var days = new Array('Sunday','Monday','Tuesday',
			'Wednesday','Thursday','Friday','Saturday');
	var date = new Date();
	var dow  = date.getDay();
	var day  = date.getDate();
	var month = date.getMonth();
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy; // yy = years since 1900, add 1900
	return(days[dow] + ', ' + months[month] + ' ' + day + ', ' + year);
}

function writeDate() {
	var today = todaysDate();
	document.write(today);
}

function toggleClub() {
/*	identical to menu.js::menuToggleClub(), but formatted for one line */
	var cVal = readCookie('branch');
	if (cVal == 'BF')
		document.writeln('<a href="javascript:setBranch(\'BG\',\''+ location.href + '\')">I am a member of AAA Blue Grass</a>');
	else
		document.writeln('<a href="javascript:setBranch(\'BF\',\''+ location.href + '\')">I am a member of AAA Bluefield</a>');
}


function writeHome() {
/*	adds BG/BF specific links to home page */
	var cName = 'branch';
	var cGet = unescape(document.cookie);
	var cLen = document.cookie.length;           // length of cookie
	var nLen = cName.length+1;                   // length of cookie name + '='
	var cBase = cGet.indexOf(cName, 0);          // find the index of the desired name/value pair
	if (cBase == -1)                             // name/value not found
		cVal = 'NOT FOUND';
	else {
		var cEnd = cGet.indexOf (";", cBase+nLen); // start at end of 'cName=' and look for ';'
		if (cEnd == -1)                            // no trailing ';' (last n/v pair in cookie)
			cEnd = cGet.length;                      // ...so will go to the end
		var cVal = unescape(cGet.substring(cBase+nLen, cEnd)); // read from '=' to ';' or end
	}
	if(cVal == 'BF') {
		document.writeln('<p style="font-size:7pt;"><a href="javascript:setBranch(\'BG\',\'/aaa/032/index.html\');">Click here</a> if you are a member of AAA Blue Grass.</p>');
	}
	else {
		document.writeln('<p style="font-size:7pt;"><a href="javascript:setBranch(\'BF\',\'/aaa/032/index.html\');">Click here</a> if you are a member of AAA Bluefield.</p>');
	}
}

function dispLogo() {
/*	adds BG/BF specific elements to any page */
	var cName = 'branch';
	var cGet = unescape(document.cookie);
	var cLen = document.cookie.length;           // length of cookie
	var nLen = cName.length+1;                   // length of cookie name + '='
	var cBase = cGet.indexOf(cName, 0);          // find the index of the desired name/value pair
	if (cBase == -1)                             // name/value not found
		cVal = 'NOT FOUND';
	else {
		var cEnd = cGet.indexOf (";", cBase+nLen); // start at end of 'cName=' and look for ';'
		if (cEnd == -1)                            // no trailing ';' (last n/v pair in cookie)
			cEnd = cGet.length;                      // ...so will go to the end
		var cVal = unescape(cGet.substring(cBase+nLen, cEnd)); // read from '=' to ';' or end
	}
	if(cVal == 'BF') {
		document.writeln('<img src="/aaa/032/images/banners/'+chooseBanner()+'BF.png" alt="Welcome to aaabluegrass.com" width="200" height="60" />');
	}
	else {
		document.writeln('<img src="/aaa/032/images/banners/'+chooseBanner()+'BG.png" alt="Welcome to aaabluegrass.com" width="200" height="60" />');
	}
}

function chooseBanner() {
/*	changes welcome banner on home page if a holiday */
	var date = new Date();
	var mo = date.getMonth()+1;		// getMonth uses 0=Jan
	var dom = date.getDate();
	var day = date.getDay()+1;		// getDay uses 0=Sunday
// variable dates set thru Oct 1 2004
/*	if(mo==10 && dom==31) return ('bnrseas_Hlwn');
	else if(mo==11 && dom>=22 && dom<=28 && day==5) return ('bnrseas_Tgvg');
	else if(mo==12 && dom==25) return ('bnrseas_Xmas'); 
	else */return('bnr_');
}

function balloonHelp(balloonID) {
	var obj = document.getElementById(balloonID);	// find the obj in the current doc
//	window.alert(x + ', ' + onMouseOver.pageY);
	obj.style.left = '500px';
	obj.style.top = '500px';
	obj.style.visibility = 'visible';
}








function formFieldDate(formname,fieldname) {
	var today = todaysDate();
	var i = 0;
	window.alert('got here 1');
	window.alert('length '+document.forms.length);
	for(i=0;i<=document.forms.length;i++) {
		window.alert(document.forms[i]);
		if(document.forms[i] == formname)
			window.alert('got here 2');
	}
	var myform = document.jobapp;
			window.alert(myform.date.value);
//	document.jobapp.date.value = 'test';
	myform.date.value = 'test 2';
}


function randomAd() {
	fetchAd();
/* pulls from a list of candidates, does not repeat last seen
	var ads = new Array('Gateway.png',
											'gastips.png',
											'travelstore.png',
											'volvo.png',
											'Travel.gif',
											'ERSOL.png',
											'TrvlChlng.png');
	var links = new Array('http://www.aaa.com/gateway/',
												'http://www.aaa.com/aaa/032/home/safety/GasWatchersGuide2004.pdf',
												'http://www.aaa.com/aaa/032/offices/Palomar.html',
												'http://www.aaa.com/aaa/032/home/sycs/volvo.html',
												'http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=aaa&club=032&page=FareFinder',
												'http://www.aaa.com/aaa/032/home/automotive/ERSOnline.html',
												'http://www.aaa.com/TravelChallenge/');
	do { // generate random ad, read cookie, and compare last_ad seen
		var rand = randInt(ads.length);
		var cGet = unescape(document.cookie);
		var cLen = document.cookie.length;           // length of cookie
		var cBase = cGet.indexOf('last_ad', 0);      // find the index of the cookie
		if (cBase == -1) cVal = -1;                  // name/value not found
		else {
			var cEnd = cGet.indexOf (";", cBase+8);    // start at end of 'last_ad=' and look for ';'
			if (cEnd == -1)                            // no trailing ';' (last n/v pair in cookie)
				cEnd = cGet.length;                      // ...so will go to the end
			var cVal = unescape(cGet.substring(cBase+8, cEnd)); // read from '=' to ';' or end
		}
	} while(rand == cVal);

	document.writeln('<a href=\"'+links[nextad]+'\"><img src="/aaa/032/images/bannerads/'+ads[nextad]+'" alt="special offers from AAA" width="468" height="60" border="0" /></a>');
	cookieContent = 'last_ad=' + nextad + ';path=/';
	document.cookie = cookieContent;					// write cookie
	*/
}



