browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
url =  "http://www.goldkeys.com/webslr/";
urls = "http://www.goldkeys.com/webslr/";

// urls = "https://128.121.98.80/";

function GetCookie(name) {
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;

	if (startOfCookie != -1) {
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}
	return result;
}

function verify()
{

	var login;
	var loc = "";
	var golink = "";
	var search_for = "";

	login = GetCookie("WebSLRLogin");

	ref = document.referrer;
	ref = ref.substring(ref.indexOf("path=")+5, ref.length);
	ref = ref.substring(0, ref.indexOf("&"));

      if (browserName == "Netscape" || browserVer >= 4)
	{
		loc = document.location.href;
	} else
	{
		loc = document.location;
	}

	bolden = loc.lastIndexOf("file=");
	//alert ("TEST, please hit OK 1 location = " + loc + ", referrer = " + ref + ", login = " + login + ", bolden = " + bolden);

	if (bolden >= 0)
	{
		loc = "/" + loc.substring(bolden + 5, loc.length);
		bolden = loc.indexOf("&");
		if (bolden >= 0)
		{
			search_for = loc.substring(bolden + 12, loc.length)
			loc = loc.substring (0, bolden);
		}

	} else 
	{
		loc = loc.substring(loc.indexOf("/help"), loc.length);
	}

	//alert ("TEST, please hit OK 2c location = " + loc + ", referrer = " + ref + ", login = " + login + ", search_for = " + search_for);
	golink = "/bin/verify.cgi?login=" + login + "&path=" + loc + "&ref=" + ref + "&search_for=" + search_for; 
	gohref (golink, "help");
}


function mkframes_verify()
{

	login = GetCookie('WebSLRLogin');

	if (login == null)
	{
		gohref ('nocookie.html', 'top')
	}

}

function appstart()
{
	login = "sbg"

	
	document.writeln( '<APPLET CODEBASE="/webslr/classes" CODE="camera.class" LIBRARY="camera.jar" vspace=0 hspace=0 width=90% height=90%>');
	document.writeln ('<PARAM NAME=full VALUE="true">');
	document.writeln ('<PARAM NAME=login VALUE="' + login + '">');
	document.writeln ('<PARAM NAME=browser VALUE="' +  browserName + browserVer + '">');  
	//document.writeln ('</APPLET>');
}

function setLastVisit()
{
	var nameChapter="WebSLRChapter";
	var nameFile="WebSLRFile";
	var oneMonth = 31 * 24* 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + oneMonth);

	login=GetCookie("WebSLRLogin");

	document.cookie = nameChapter + "=" + escape(document.title)    + "; expires=" + expDate.toGMTString() + "; path=/";	
	document.cookie = nameFile    + "=" + escape(document.location) + "; expires=" + expDate.toGMTString() + "; path=/";
	
	navigate("Home", "Topics", "Tutorial")

}

function setLogin(loginValue)
{

	var loginName="WebSLRLogin";
	var halfDay = 12* 60 * 60 * 1000;

	var expDate = new Date();
	expDate.setTime(expDate.getTime() + halfDay);

	refer = document.referrer;
	document.cookie = loginName + "=" + escape(loginValue)        + "; expires=" + expDate.toGMTString() + "; path=/";	
	gohref (url + "bin/logon.cgi?login=guest" + "&refer=" + refer + "&browserName=" + browserName + "&browserVer=" + browserVer, "top");
}

function setREF()
{

	var wdc = new Array();
	wdc[0]="www.btinternet.com";
	wdc[1]="www.warehousephoto.com";
	wdc[2]="www.photoideas.com.sg";
	wdc[3]="www.betterphoto.com";
	wdc[4]="www.handcolor.com";
	wdc[5]="www.newimagephoto.ca";
	wdc[6]="lynnfarmerphoto.net";

	wdcCount = 6;

	var REFname = "WebSLRREF";

	var twoMonth = 60 * 24* 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + twoMonth);

	referrer = document.referrer;

	referrer = referrer.substring(7, referrer.length);
	slash = referrer.indexOf("/");
	if ( slash != -1)
	{
		referrer = referrer.substring(0, slash);
	}

	found = false;
	for (w = 0; w <= wdcCount; w++)
	{
		if (referrer == wdc[w])
		{
			found = true;
			break;
		}
	}
	if (found)
	{
		document.cookie = REFname + "=" + escape(referrer) + "; expires=" + expDate.toGMTString() + "; path=/";
	}

}

function gonext(nextFile, nextName, lastFile)
{

      if (browserName == "Netscape" || browserVer >= 4)
	{
		source = document.location.href;
	} else
	{
		source = document.location;
	}

	dest = source;
	dest = dest.substring(dest.indexOf("&path=")+6, dest.length);
	dest = dest.substring(0, dest.indexOf("&"));
	dest = dest.substring(0, dest.lastIndexOf("/")+1);

	bolden = dest.lastIndexOf("file=");

	if (bolden >= 0)
	{
		dest = "/" + dest.substring(bolden + 5, dest.length);
	}

	here = source;
	here = here.substring(here.indexOf(".com")+4, here.length);
	here = here.substring(0, here.lastIndexOf("/")+1);

	source = source.substring(source.indexOf("&ref=")+5, source.length);
	source_dir = source.substring (0, dest.lastIndexOf("/")+1);


	//alert ("in go location.href = " + document.location.href + ", referer = " + document.referrer + ", source = " + source + ", dest = " + dest);
	/*
	 *	This is a speacial case we we came from the tutorial to controls 
	 *	and want to return back to the tutorial.
	 */
	if ( source_dir == "/help/tutorial/" && dest == "/help/controls/" )
	{
		document.writeln('Return to <a href="' + source + '">Tutorial</a>')
		return
	}

	if ( dest == "/help/tutorial/" || here == "/help/tutorial/" )
	{
		area="Tutorial";
	} else 
	{
		if ( dest == "/help/controls/" || here == "/help/controls/" )
		{
			area="Camera Controls";
		} else
		{
			area="Home";
		}
	}
	if (nextFile != "")
	{
		document.writeln('Next to <a href="' + dest + nextFile + '">' + nextName + '</a><P>')
	}
	if (lastFile != "")
	{
		document.writeln('Back to <a href="' + dest + lastFile + '">Previous Section</a><br>')
	}
	document.writeln('Return to <a href="' + dest + 'index.html">' + area + '</a>')
}


function getLastVisit(where)
{
	var lastChapter;
	var lastFile;
	var lastLen;

	lastChapter = GetCookie("WebSLRChapter");
	lastFile = GetCookie("WebSLRFile");
	login = GetCookie("WebSLRLogin");
	
	if (lastChapter == null || login == "guest" )
	{
		//alert ("lastChapter is null");
		gohref ("topics.html", "help");
	} else {
		//alert ("lastChapter is :" + lastChapter + ":");
		if (where == "stay") {
			document.writeln ('Start with<br><a href="' + lastFile + '">' + lastChapter + '</a><P>or<P>');
		} else {
			gohref ("start.html", "help");
		}
	}
}

		
function gohref(loc, where)
{

      if (browserVer >= 4)
	{
		//alert ("in gohref for 4, loc = " + loc);
		document.location.href=loc;
	} else 
	{
		//alert ("in gohref for MSIE, continue, loc = " + loc);
		document.writeln ('<html><body><bgcolor="#ffffea"><P><a href="' + loc + '">Continue</a>')
		for (i=1; i<=40;i++)
		{
			document.writeln('&nbsp;<br>');
		}
	}
}

var slideShowPix = new Array ("uluru.jpg","monum.jpg","monkey_land.jpg","maui.jpg","kzinti_land.jpg","green.jpg","Barc2.jpg", "fuji.jpg", "lonewalk.jpg", "wall.jpg", "tree_land.jpg", "budapest.jpg", "koi.jpg", "lambert2.jpg", "reflect.jpg", "hawaii.jpg" ) 
var thisPic=0
var imgCt=16

function cycle() 
{

	if (document.images)
	{
		thisPic++
		if (thisPic == imgCt)
		{
		        thisPic = 0
            }
		
		setTimeout("cycle()",12*1000)
		document.slideShow.src = "pictures/SlideShow/" + slideShowPix[thisPic]
	}
}

function cycle1() 
{
	if (document.images)
	{
		setTimeout("cycle1()",6*1000)
		document.fireworks.src = "gif/fireworks.gif"
	}
}

function guestRegister()
{
	login = GetCookie('WebSLRLogin');

	if (login == "guest") 
	{
		document.writeln('<P><LI></font><font size=+1><a href="http://www.webslr.com/js_register.html" target=_top>Register</a></font><font size=-1>&nbsp;for just $US 18.95 for a one-year membership</font>')
	} else {
		//document.writeln ('<font size=-1><P>Comming Soon:<br> Exhibit Your Best Photos<br> and Manage Your Own Personal Page</font>')
		//document.writeln('<font size=0><a href="/bin/student_form.cgi?login=' + login + '" target=_top>.</a>')
		document.writeln('<P><LI></font><a href="/bin/student_form.cgi?login=' + login + '" target=_top>Exhibit Your Best Photos</a>')
		//document.writeln('<br><img src=/gif/newRed.gif WIDTH=20 BORDER=0>And Manage Your Own Personal Page!')
	}
		
}

function photoReturn()
{
	login = null;
	login = GetCookie('WebSLRLogin');


	if (login == "guest" || login == null ) 
	{
		document.writeln('<P><a href="../index.html">Return to Students Page</a>')
	} else {
		document.writeln('<P><a href="../index.html">Return to Students Page</a>')
		document.writeln('<P>or<P><a href="/bin/student_form.cgi?login=' + login + '">Make your own photo submission</a>')
		document.writeln('<P>or<P>Return to the <a href="/bin/logon_do.cgi?login=' + login + '">Tutorial</a>')
	}
		
}

function atTop()
{
	if (top.length == 0) 
	{
		gohref ("index.html", "null");
	}
}

function navigate()
{
	var gotop = null;
	document.writeln('<font face="Arial,Helvetica">Path&nbsp;:&nbsp;</font><b><font face="Arial,Helvetica">');

	for (i = 0; i < navigate.arguments.length; i++)
	{
		gotop = null;
		gonav = null;
		if  (navigate.arguments[i].charAt(0) == '*')
		{
			gotop='onClick=top.camera_frame.location.href="../appstart.html"';
			navigate.arguments[i] = navigate.arguments[i].substring(1, navigate.arguments[i].length);
		}

		if  (navigate.arguments[i].charAt(0) == '&')
		{
			gonav='/mkframes.html';
			navigate.arguments[i] = navigate.arguments[i].substring(1, navigate.arguments[i].length);
		}


		switch (navigate.arguments[i])
		{
			case "Home": 
				gonav='/index.html' ;
				gotop='target=_top' ;
				break;

			case "Topics": 
				if (gonav == null)
				{
					gonav='/help/topics.html';
				}
				break;

			case "Tutorial":

				gonav='/help/tutorial/index.html' ;
				break;

			case "Controls":
				gonav='/help/controls/index.html' ;
				break;

			case "About":
				gonav='/help/about.html' ;
				break;

			case "Trouble":
				gonav='/help/trouble/index.html' ;
				break;

			case "Students":
				gonav='/students/index.html' ;
				break;

			case "Index":
				gonav='/help/permute/index.html' ;
				break;

			case "Camera Equipment":
				gonav='/help/homelink/equip.html' ;
				break;
		}	
	
		linkh='<a href="' + gonav + '" ' + gotop + ' >' + navigate.arguments[i] + '</a>&nbsp;:&nbsp';
		document.writeln(linkh);
	}
	document.writeln('</b></font>');
}


