/* Author:  Jim Needham (Vector Graphics - geneonet.com)

*/

// Retrieve cookie value...

function getCookieValu (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

// Retrieve cookie name...

function GetCookieNm (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var usernm = i + alen;
if (document.cookie.substring(i, usernm) == arg)
return getCookieValu (usernm);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; 
}
return null;
}  

function SetCookieNm (name, value) {
var argv = SetCookieNm.arguments;
var argc = SetCookieNm.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function auto_show_name() {
if(GetCookieNm("myname") != null)
document.write(""+ GetCookieNm('myname') +"");
else {
document.write("<FORM>Please enter your name so we'll recognize you: <INPUT TYPE = \"text\" NAME = \"nameinput\">" + 
"<BR><BR><INPUT TYPE = \"button\" VALUE = \"Remember Me\" onClick = \"set_name(this.form)\"></FORM>");
document.write("Please enter your first name in the input" + " box and press the \"Remember Me\" button, then the page will automatically reload. ");
   }
}

function auto_show_place() {
if(GetCookieNm("myplace") != null)
document.write(""+ GetCookieNm('myplace') +"");
else {
document.write("<FORM>Would you tell us your location? <INPUT TYPE = \"text\" NAME = \"placeinput\">" + 
"<BR><BR><INPUT TYPE = \"button\" VALUE = \"Remember where \" onClick = \"set_place(this.form)\"></FORM>");
document.write("Would you please tell us where you are in the location " + 
" box and press the \"Remember where\" button, then the page will automatically reload. ");
   }
}


function set_place(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var userplace = form.placeinput.value
if (userplace != "") {
if (confirm("Are you sure you want this saved as your location?")) {
SetCookieNm ("myplace", userplace, expdate);
window.history.go(0);
   }
}
else alert("Geez, at least enter something, entering nothing will cause an error.");
}

function set_name(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var username = form.nameinput.value
if (username != "") {
if (confirm("Are you sure you want this saved as your name?")) {
SetCookieNm ("myname", username, expdate);
window.history.go(0);
   }
}
else alert("Geez, at least enter something, entering nothing will cause an error.");
}

function show_count() {
var expdate = new Date();
var num;
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31)); 
if(!(num = GetCookieNm("mycount"))) 
num = 0;
num++;
SetCookieNm ("mycount", num, expdate);
if (num == 1) document.write("since this is the first time you have been here, we'd like you to take a moment to look around, and then...");
else document.write("you have been here " + num + " times"); 
}
