//	COLLECTION OF UNIVERSAL FUNCTIONS FOR WEB SITE

var lIsIE = navigator.appVersion.indexOf("MSIE") >= 0;
var repositioned = false ;
// reposition elements according to content
function reposition() {
	if ( !repositioned ) {
	repositioned = true ;
	document.onload = '';
	if (isIE) {
	//	window.status = document.location.pathname ;
		if (document.location.pathname == '/index.html' || document.location.pathname == '' ) {
		//	document.getElementById("content").style.width="805px";
			document.getElementById("bottomlinks").style.width= "935px";
			document.getElementById("bottomlinks").style.left= "3px";
		}
	//	document.getElementById('content').style.width = "805px";
		var linkWidth = document.getElementById('content').offsetWidth - 2;
		document.getElementById("topvarlinks").style.width = linkWidth +'px';
	//	document.getElementById("topvarlinks").childNodes[1].style.width = linkWidth +'px';

		document.getElementById("bottomvarlinks").style.width = linkWidth +'px';
	//	document.getElementById("bottomvarlinks").childNodes[1].style.width = linkWidth +'px';

		document.getElementById("bottomlinks").style.left= "3px";
		document.getElementById("bottomlinks").style.width = (document.getElementById('content').offsetWidth + document.getElementById('content').offsetLeft - 3)+'px';
	//	window.status += " bottomlinks Width = " + document.getElementById("bottomlinks").style.width ;
	}
	else {
		var linkWidth = document.getElementById('content').offsetWidth-2 ;
		document.getElementById("topvarlinks").style.width = linkWidth +'px';
		document.getElementById("topvarlinks").childNodes[1].style.width = linkWidth +'px';

		document.getElementById("bottomvarlinks").style.width = linkWidth +'px';
		document.getElementById("bottomvarlinks").childNodes[1].style.width = linkWidth +'px';
	}
	// Move Content to adjust for variable links
	linkTop = document.getElementById('topvarlinks').offsetTop ;
	linkHeight = parseInt(document.getElementById('topvarlinks').offsetHeight);
	document.getElementById('content').style.top = (linkTop + linkHeight) + 'px' ;

	// Move bottom links according to height of content
	// BottomLinks.top is the greater of bottom of content
	// or bottom of verisign seal
	contentTop = document.getElementById('content').offsetTop ;
	contentHeight = parseInt(document.getElementById('content').offsetHeight);
	contentHeight += contentTop + 0;
	if (document.location.pathname == '/index.html' || document.location.pathname == '') {
		contentHeight -= lIsIE?10:4 ;
		window.status = "contentHeight = " + contentHeight ;
	}

	verisignsealTop = document.getElementById('verisignseal').offsetTop ;
	verisignsealHeight = parseInt(document.getElementById('verisignseal').offsetHeight);
	verisignsealHeight += 5 + verisignsealTop;

	if (verisignsealHeight > contentHeight) {
		contentHeight = verisignsealHeight - (lIsIE?10:0) ;
		contentStyleHeight = contentHeight - contentTop - 5;
		document.getElementById('content').style.height = contentStyleHeight+'px';
	}
	//window.status += " contentWidth = " + document.getElementById('content').offsetWidth ;
	document.getElementById('bottomvarlinks').style.top = contentHeight +'px';
	contentHeight = parseInt(contentHeight + document.getElementById('bottomvarlinks').offsetHeight);
	contentHeight -= 1;

	document.getElementById('bottomlinks').style.top = contentHeight+'px';
	}
}

function doc_onbeforeprint() {
	// Hide everything but logo and content
	document.getElementById('logo').style.display='none';
	document.getElementById('toplinks').style.display='none';
	document.getElementById('topvarlinks').style.display='none';
	document.getElementById('splash').style.display='none';
	document.getElementById('googlesearch').style.display='none';
	document.getElementById('verisignseal').style.display='none';
	document.getElementById('bottomvarlinks').style.display='none';
	document.getElementById('bottomlinks').style.display='none';
	document.getElementById('content').style.left='5px';
	tigra.menu_hide_root();
}

window.onbeforeprint = doc_onbeforeprint;

function doc_onafterprint() {
	// Show everything 
	document.getElementById('logo').style.display='block';
	document.getElementById('toplinks').style.display='block';
	document.getElementById('topvarlinks').style.display='block';
	document.getElementById('splash').style.display='block';
	document.getElementById('googlesearch').style.display='block';
	document.getElementById('verisignseal').style.display='block';
	document.getElementById('bottomvarlinks').style.display='block';
	document.getElementById('bottomlinks').style.display='block';
	document.getElementById('content').style.left='150px';
	tigra.menu_show_root();
}
window.onafterprint = doc_onafterprint;

function doc_print() {
	doc_onbeforeprint();
	window.print();
	window.setTimeout("doc_onafterprint()",2000);
}

function showPicture(imageURL,nWidth,nHeight){
	// Sample usage
	// onclick="return showPicture(this.href);" target=_blank
    href = "/ShowImage.html?"+imageURL ;
    if (! nWidth ) {nWidth = 400}
    if (! nHeight ) {nHeight = 400}
    cOptions = "top=20,left=20,height="+nHeight+",width="+nWidth+",resizable=1,status=0,menubar=0,scrollbars=0 ," ;
    open(href,"",cOptions);
    return false;
}

function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function switchImage(obj) {
	// switches main image (framed<->printonly)
	// obj must be link to alternate image
	document.images['itemimage'].src=obj.href;
	document.images['itemimage'].scrollIntoView();
	reposition();
	return false;
}
// Variable (category and artist) link rollovers
function links_onmouseover(objLink) {
	objLink.parentNode.style.borderStyle = 'inset';
	objLink.parentNode.style.background = '#000088';
	objLink.parentNode.style.borderStyle = 'none';
}

function links_onmouseout(objLink) {
	objLink.parentNode.style.borderStyle = 'outset';
	objLink.parentNode.style.background = 'transparent';
	objLink.parentNode.style.borderStyle = 'none';
}

// Home page image rollovers (no current use!)
function link_onmouseover(imgName,color){
	return;
	myImg=document.images[imgName];
	myImg.style.borderColor=color;
	myImg.style.borderStyle='inset';
}

function link_onmouseout(imgName,color){
	return;
	myImg=document.images[imgName];
	myImg.style.borderColor=color;
	myImg.style.borderStyle='outset';
}

function mailer_onsubmit() {
	// Check for valid email address format
	// Request preferences
	if (	nobots() == false
		|| validName() == false
		|| validEmailAddress() == false
		|| validMailAddress() == false
		|| validPreferences() == false
		) {
		return false;
	}
	else {
		return true;
	}
}

function validEmailAddress() {
	// Check for valid email address format
	// Must have "@" sign
	// Must have "." following "@" sign
	strAddress = document.forms.mailer["email"].value;
	if ( strAddress.indexOf("@") <= 0
		|| strAddress.indexOf("@") > strAddress.lastIndexOf(".")
		|| strAddress.length - strAddress.lastIndexOf(".") < 3 ){
		alert("Invalid email address.\n" + strAddress + "\n"
			+ "Your email address must include your username \n"
			+ "followed by the @ sign\n"
			+ "followed by a domain name.\n"
			+ "Example: myscreenname@aol.com \n");
		document.forms.mailer["email"].focus() ;
		return false;
	}
	else {
		return true;
	}
}

var aPref = new Array (
		"10 - Ltd editions",
		"11 - Originals",
		"12 - Autographs",
		"13 - Sci Fi",
		"14 - Books",
		"15 - Landscapes",
		"16 - Posters",
		"17 - Framed miniatures",
		"18 - Auction",
		"19 - Giclees",
		"20 - Spacefest")

function validPreferences(){
	// Must indicate at least one preference
	bPrefOK = false ;
	for (i = 0 ; i < aPref.length && bPrefOK == false ; i++ ) {
		if (lIsIE) {
			bPrefOK = document.forms.mailer(aPref[i]).checked
		}
		else {
			bPrefOK = document.forms.mailer[aPref[i]].checked
		}
	}
	if (bPrefOK == false) {
		alert("Please check at least one area of interest!") ;
		if (lIsIE) {
			document.forms.mailer(aPref[0]).focus() ;
		}
		else {
			document.forms.mailer[aPref[0]].focus() ;
		}
	}
	return bPrefOK;
}

// Valid Canadian Provinces
var canadian = "|AB|BC|MB|NB|NF|NT|NS|NU|ON|PE|QC|SK|YT";

function validMailAddress(){
	// Just checking!
	var myForm = document.forms.mailer;
	if (lIsIE) {
		if ( (document.forms.mailer("12 - Autographs").checked == true
			|| document.forms.mailer("02 - Space Art Catalog").checked == true 
			|| document.forms.mailer("02 - Moonwalkers Catalog").checked == true
			) ){
			if (myForm['07 - Email'].value == 'No') {
				alert("You must provide an email address\n"
					+ "and agree to accept messages from us\n"
					+ "to qualify for a free catalog or if \n"
					+ "you indicated a special interest in \n"
					+ "Astronaut Autographs & Memorabilia.");
				myForm['07 - Email'].focus();
				return false;
			}
			if (myForm['addr1'].value == '') {
				alert("Please enter your mailing address\n"
					+ "so we can send you a catalog.\n");
				myForm["addr1"].focus();
				return false;
			}
			if (myForm['city'].value == '') {
				alert("Please enter your city\n"
					+ "so we can send you a catalog.\n");
				myForm["city"].focus();
				return false;
			}
			if (myForm['state'].value == '' && ( myForm['country'].value == '' || myForm['country'].value.toLowerCase() == 'canada' ) ) {
				alert("Please enter your state or province\n"
					+ "(U.S. and Canada only) or your country\n"
					+ "so we can send you a catalog.\n");
				myForm["state"].focus();
				return false;
			}
			if (myForm['zip'].value == '' ) {
				alert("Please enter your zip or postal code\n"
					+ "so we can send you a catalog.\n");
				myForm["zip"].focus();
				return false;
			}
			if  ( myForm['country'].value.toLowerCase() != 'canada' && canadian.indexOf(myForm['state'].value) > 0 ) {
				alert("That's a Canadian Province. Are you in Canada?")
				myForm["country"].focus();
				return false;
			}
			if (myForm['state'].value != '' && ( myForm['country'].value != '' && myForm['country'].value.toLowerCase() != 'canada' ) ) {
				alert("State/province accepted only for US and Canada.\nIf you are in the United States, leave country blank.");
				myForm["state"].selectedIndex = 0;
				myForm["state"].focus();
				return false;
			}
			if (myForm['country'].value == '' && myForm['state'].value == '') {
				alert("Please enter your country\n"
					+ "so we can send you a catalog.\n");
				myForm["country"].focus();
				return false;
			}
		}
	}
	else {
		if ( (myForm["12 - Autographs"].checked == true
			|| myForm["02 - Space Art Catalog"].checked == true 
			|| myForm["02 - Moonwalkers Catalog"].checked == true
			) ){
			if (myForm['07 - Email'].value == 'No') {
				alert("You must provide an email address\n"
					+ "and agree to accept messages from us\n"
					+ "to qualify for a free catalog or if \n"
					+ "you indicated a special interest in \n"
					+ "Astronaut Autographs & Memorabilia.");
				myForm['07 - Email'].focus();
				return false;
			}
			if (myForm['addr1'].value == '') {
				alert("Please enter your mailing address\n"
					+ "so we can send you a catalog.\n");
				myForm["addr1"].focus();
				return false;
			}
			if (myForm['city'].value == '') {
				alert("Please enter your city\n"
					+ "so we can send you a catalog.\n");
				myForm["city"].focus();
				return false;
			}
			if (myForm['state'].value == '' && ( myForm['country'].value == '' || myForm['country'].value.toLowerCase() == 'canada' ) ) {
				alert("Please enter your state or province\n"
					+ "(U.S. and Canada only) or your country\n"
					+ "so we can send you a catalog.\n");
				myForm["state"].focus();
				return false;
			}
			if (myForm['zip'].value == '' ) {
				alert("Please enter your zip or postal code\n"
					+ "so we can send you a catalog.\n");
				myForm["zip"].focus();
				return false;
			}
			if  ( myForm['country'].value.toLowerCase() != 'canada' && canadian.indexOf(myForm['state'].value) > 0 ) {
				alert("That's a Canadian Province. Are you in Canada?")
				myForm["country"].focus();
				return false;
			}
			if (myForm['state'].value != '' && ( myForm['country'].value != '' && myForm['country'].value.toLowerCase() != 'canada' ) ) {
				alert("State/province accepted only for US and Canada.\nIf you are in the United States, leave country blank.");
				myForm["state"].selectedIndex = 0;
				myForm["state"].focus();
				return false;
			}
			if (myForm['country'].value == '' && myForm['state'].value == '') {
				alert("Please enter your country\n"
					+ "so we can send you a catalog.\n");
				myForm["country"].focus();
				return false;
			}
		}
	}
	return true;
}

function validName(){
	// Needs first and last name (2 words)
	if (document.forms.mailer["firstname"].value.length == 0) {
		alert("Please enter your first name.") ;
		document.forms.mailer["firstname"].focus();
		return false;
	}
	if (document.forms.mailer["lastname"].value.length == 0) {
		alert("Please enter your last name.") ;
		document.forms.mailer["lastname"].focus();
		return false;
	}
	return true;
}


var chars = "A B C D E F G H J K L M N P Q R S T U V W X Y Z 2 3 4 5 6 7 8 9";
var aChars = chars.split(' ');

var aWords = new Array(
	'424116f0de37ae053279c35ac0b12d59',
	'ff2364a0be3d20e46cc69efb36afe9a5',
	'04d793ba9fbfcba14c079e07f69e8d56',
	'7b77dd76ae8e16caa9339ef6dd87786a',
	'12396e2cb51175f01c59d202302d75b4',
	'58347add101c2de2141b9ba2f0953a45',
	'370d1a454d439274acd8c85c32e4516d',
	'22d275c80d14b56139d5a381511295de',
	'6402e0c6362d943a3edbc2471d4dbf9d',
	'2eee287739ed005291ffdf97842d7f79'
	);

function setSrc() {
	if (document.images.si) {
		src = '/PIX/' + aWords[Math.round(Math.random()*(aWords.length-1))] + '.gif';
		document.images.si.src = src;
	}
}

function getRandom() {
	var nLength = 5 ;
	var str = '';
	for ( i = 0; i < nLength; i++) {
		l = Math.random()*aChars.length;
		str += aChars[parseInt(l)];
	}
	return str;
}

function getFilename() {
	fn = document.images.si.src;
	fn = fn.substring(fn.lastIndexOf('/')+1, fn.lastIndexOf('.'));
	return fn;
}

function nobots() {
	if (document.forms.mailer.s && getFilename() != hex_md5(document.forms.mailer.s.value.toLowerCase()) ) {
		alert('That entry is incorrect. Please try again.');
		document.forms.mailer.s.focus();
		return false;
	}
	else {
		return true;
	}
}

function whatIsSi() {
	alert("This image is used to prevent \nautomated programs from submitting requests.\nIf you can't read it, please refresh this page.");
}

function getQuery(cName) {
	// cName is the name of a query value to return
	var search = document.location.search.substr(1);
	var aNames = search.split("&");
	for (i=0;i<aNames.length;i++) {
		if (aNames[i].indexOf(cName+'=') == 0) {
			cValue = decodeURI(aNames[i].substr(cName.length+1));
			cValue = cValue.replace(/\+/g,' ');
			return cValue;
		}
	}
	return '';
}

// Show more info on link pages

function showMore(e,obj) {
	return;
	var cWidth;
	if (e) {
		// ok, let's reposition the longdesc
		if (e.pageX) {
			ldLeft = obj.offsetParent.offsetParent.offsetLeft + obj.offsetParent.offsetLeft + obj.offsetLeft;
			ldTop = obj.offsetParent.offsetParent.offsetTop + obj.offsetParent.offsetTop + obj.offsetTop;
			cWidth = Math.max(280,e.currentTarget.offsetParent.offsetWidth) ;
		}
		if (e.offsetX) {
			ldLeft = obj.offsetParent.offsetParent.offsetLeft + obj.offsetParent.offsetLeft + obj.offsetLeft;
			ldTop = obj.offsetParent.offsetParent.offsetTop + obj.offsetParent.offsetTop + obj.offsetTop;
			cWidth = Math.max(280,e.srcElement.offsetParent.offsetWidth) ;
		}
	}
	if (lIsIE) {
		for (i=0; i < obj.parentNode.children.length; i++) {
			if (obj.parentNode.children(i)) {
				if (obj.parentNode.children(i).id == 'longdesc') {
					if (obj.parentNode.children(i).style.display != 'block') {
						obj.parentNode.children(i).style.top = ldTop + 'px';
						obj.parentNode.children(i).style.left = ldLeft + 'px';
						if ( cWidth ) {
							obj.parentNode.children(i).style.width = cWidth + 'px';
						}
						obj.parentNode.children(i).style.display = 'block';
						obj.parentNode.children(i).style.zIndex = 1;
						obj.parentNode.children(i).scrollIntoView();
					}
					else {
						obj.parentNode.children(i).style.display = 'none';
					}
				}
			}
		}
	}
	else {
		for (i=0; i<obj.parentNode.childNodes.length; i++) {
			if (obj.parentNode.childNodes[i].id == 'longdesc') {
				if (obj.parentNode.childNodes[i].style.display != 'block') {
					obj.parentNode.childNodes[i].style.top = ldTop + 'px';
					obj.parentNode.childNodes[i].style.left = ldLeft + 'px';
					if ( cWidth ) {
						obj.parentNode.childNodes[i].style.width = cWidth + 'px';
					}
					obj.parentNode.childNodes[i].style.display = 'block';
					obj.parentNode.childNodes[i].style.zIndex = 1;
					obj.parentNode.childNodes[i].scrollIntoView(false);
				}
				else {
					obj.parentNode.childNodes[i].style.display = 'none';
				}
			}
		}
	}
	return false;
}

//	Activate Sound player (or not!)
function getCookie(strName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		aCrumb = aCookie[i].split('=');
		if (aCrumb[0] == 'strName') {
			return unescape(aCrumb[1]);
		}
	}
	return null ;
}

//	Activate Sound player (or not!)
function soundStatus() {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		aCrumb = aCookie[i].split('=');
		if (aCrumb[0] == 'sound') {
			return unescape(aCrumb[1]);
		}
	}
	return 'on' ;
}

/*
if ( window.location.href.indexOf('AUTO') >= 0 ) {
	// compare paths of document and referer. If same, do not restart sounds
	myPath = document.location.pathname ;
	myPath = myPath.substring(0, myPath.lastIndexOf('/')) ;
	myReferer = document.referrer.substring(24);
	myReferer = myReferer.substring(0,myReferer.lastIndexOf('/')) ;
	myAstro = myPath.substr(myPath.lastIndexOf('/')+1) ;

	if (document.location.pathname.indexOf('Bean.html') >=0 || document.location.pathname.indexOf('ABorig') >=0 ) {
		myAstro="BEAN";
	}

	// Define Missions
	ALDRIN=11;
	BEAN=12;
	LOVELL=13;
	MITCHELL=14;
	YOUNG=16;
	DUKE=16;
	CERNAN=17;
	SCHMITT=17;
	COLLINS=11;
	Borman='08';
	BORMAN='08';
	Moonwalk=11;
	OTHER='09';
	MCDIVITT='09';

	if (myAstro != '' && myAstro != 'AUTO') {
		myMission = eval(myAstro);
	}
	else {
		myMission = 11;
	}

	if (myPath != myReferer) {
		if ( window.location.href.indexOf('AUTO') >= 0 
		     && myPath != myReferer
		     && window.location.href.indexOf('frame.html') < 0  
		     && window.location.href.indexOf('Sounds.html') < 0 
		     && window.location.href.indexOf('Schirra.html') < 0 
		     && window.location.href.indexOf('Moonphotos.html') < 0 
		     && window.location.href.indexOf('AAA.html') < 0 
		     && soundStatus() != 'off') {
			soundPlayer = window.open('/Sounds.html?m='+myMission,'soundPlayer','top=10,left=10,height=195,width=440,chrome=yes,alwaysLowered=yes');
		}
	}
}
*/


//	Highlight search terms
function highlight() {
	var ref = document.referrer ;
	var domain = ref.substr(0, ref.indexOf('?'));
	if ( domain.indexOf('google') >= 0 ) {
		domain = 'Google';
	}
	else if ( domain.indexOf('aol') >= 0 ) {
		domain = 'AOL';
	}
	else if ( domain.indexOf('msn') >= 0 ) {
		domain = 'MSN';
	}
	else if ( domain.indexOf('ask') >= 0 ) {
		domain = 'Ask';
	}
	else if ( domain.indexOf('yahoo') >= 0 ) {
		domain = 'Yahoo';
	}
	var search = ref.substr(ref.indexOf('?')+1);
	var aNames = search.split("&");
	var cValue='';
	cName='q';
	if ( domain == 'AOL' ) {
		cName = 'query';
	}
	if ( domain == 'Yahoo' ) {
		cName = 'p';
	}
	for (i=0;i<aNames.length;i++) {
		if (aNames[i].indexOf(cName+'=') == 0) {
			cValue += decodeURI(aNames[i].substr(cName.length+1));
			cValue = cValue.replace(/\+/g,' ');
		//	alert(cValue);
		}
	}
	if ( cValue ) {
		// Create a division to show search terms
		newDiv = document.createElement('div');
		newDiv.innerHTML = "<h3>You searched " + domain + " for:</h1><b><i>" + cValue + '</i></b>';
		newDiv.id = 'showQuery';
		newDiv.style.backgroundColor = '#000000';
		newDiv.style.color = '#ffff00';
		newDiv.style.borderStyle = 'solid';
		newDiv.style.borderColor = '#00aa00';
		newDiv.style.borderWidth = '1px';
		newDiv.style.position = 'absolute';
		newDiv.style.left = '350px';
		newDiv.style.top = '20px';
		newDiv.style.width = ' 500px';
		newDiv.style.height = '75px';
		newDiv.style.zIndex = 4 ;
		newDiv.onclick = "document.getElementById('showQuery').style.display = 'none'";
		document.body.insertBefore(newDiv, document.getElementById('content'));
		ndId = window.setTimeout("document.getElementById('showQuery').style.display = 'none'",10000);
	}
}


function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}
	else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

var aImgLinks = new Array();
function init_rotate() {
	// first, create collection of all imglinks tables
	// identify images in collection that define altimages
	// apply rotation object to image
	myImages = document.getElementsByTagName('img');
	for (i=0;i<myImages.length;i++) {
		if (myImages[i].attributes['altimages']) {
			aImgLinks[aImgLinks.length] = myImages[i];
			// This is a rotating node! Add a few properties so we can rotate
			myImgLink = aImgLinks[aImgLinks.length-1] ;
			myImgLink.index = aImgLinks.length-1 ;
			myImgLink.currentImage = -1;
			myImgLink.images = myImgLink.attributes['altimages'].value.split(';');
			myImgLink.rotate = Rotate ;
			myImgLink.rotate();
		}
	}
}

function Rotate() {
	if (this.tid) window.clearTimeout(this.tid);
	this.currentImage++ ;
	this.currentImage %= this.images.length ;
	this.src=this.images[this.currentImage];
	this.tid=window.setTimeout("aImgLinks["+this.index+"].rotate()",5000 * Math.random()+1000);
}

addLoadEvent(init_rotate);


// Create a cookie with the specified name and value.
function SetCookie(sName, sValue)
{
  var strCookie = sName + "=" + escape(sValue);
  // Expires the cookie in six months
  var date = new Date();
  date.setMonth(date.getMonth()+6);
  strCookie += ("; expires=" + date.toUTCString());
  strCookie += ("; path=/; domain=www.novaspace.com;");
  document.cookie = strCookie ;
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  // a cookie with the requested name does not exist
  return null;
}

if (document.referrer != '' && !GetCookie('referrer')) {
	SetCookie('referrer', document.referrer);
}


//	Set up test for incoming links from Google
//	Look for 'gclid' in query string
//	save data in cookie for later reference

if (document.location.search != '') {
	// if there's no search string  there's nothing to do
	// parse search string into NV pairs
	aSearch = new Array();
	aSearchRaw = document.location.search.substr(1).split("&");
	for (i=0;i<aSearchRaw.length;i++) {
		var aCrumb = aSearchRaw[i].split("=");
		aSearch[aCrumb[0]] = decodeURI(aCrumb[1]) ;
	}
	if (aSearch['gclid'] || aSearch['s'] || aSearch['utm_source']) {
		// this is Google adwords click, save the whole search string to a cookie
		SetCookie('adwords', decodeURI(document.location.search.substr(1)) );
	}
}

