function GetCookie(name) {
var nmatch = name + "=";
var cstart = 0;
while ( cstart < document.cookie.length ) {
var cvalue = cstart + nmatch.length;
if ( document.cookie.substring(cstart, cvalue) == nmatch ) {
var cvend = document.cookie.indexOf(";", cvalue);
if ( cvend < 0 ) cvend = document.cookie.length;
return unescape(document.cookie.substring(cvalue, cvend));
}
cstart = document.cookie.indexOf(" ", cstart) + 1;
if ( cstart == 0 ) break;
}
return "";
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var exp = (argc > 2)? argv[2] : "";
var edate = new Date();
if ( value.length == 0 ) {
edate.setTime(edate.getTime()-24*60*60*1000);
exp = edate.toGMTString();
value = "X";
}
var cv = name + "=" + escape(value) +
(exp.length? ("; expires=" + exp) : "") +
((argc > 3 && argv[3] != "")? ("; path=" + argv[3]) : "");
document.cookie = cv;
}
function PickerItem(item_text) {
if ( !this.had_tokens )
this.tokens += this.token_order.charAt(this.n_items);
this[this.n_items++] = item_text;
if ( this.name != "" && !this.had_tokens )
SetCookie(this.name, this.tokens, this.expdate, this.locn);
}
function PickOne() {
if ( this.n_items == 0 ) return "(NO ITEMS!)";
this.rand = (this.rand % 4652353) * 492113 + 1;
if ( !this.tokens.length )
this.tokens = this.token_order.substring(0, this.n_items);
var pick = Math.floor(this.rand % this.tokens.length);
var token = this.tokens.charAt(pick);
this.tokens = this.tokens.substring(0, pick) + this.tokens.substring(pick+1, this.tokens.length);
if ( this.name != "" )
SetCookie(this.name, this.tokens, this.expdate, this.locn);
return this[this.token_order.indexOf(token)];
}
function Picker(pname) {
this.name  = pname;
this.n_items = 0;
this.item  = PickerItem;
this.pick  = PickOne;
this.had_tokens = 0;
var now = new Date();
this.rand = Math.abs(now.getTime()/1000);
this.token_order = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789(){}[]+=|:;~!@#$%^&*?/.,";
if ( pname != "" ) {
this.tokens = GetCookie(pname);
this.had_tokens = this.tokens.length? 1 : 0;
var exptime = new Date();
exptime.setTime(exptime.getTime()+14*24*60*60*1000);
this.expdate = exptime.toGMTString();
this.locn = "";
}
}