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; //alert("[GetCookie] Found "+nmatch+document.cookie.substring(cvalue, cvend)); return unescape(document.cookie.substring(cvalue, cvend)); } cstart = document.cookie.indexOf(" ", cstart) + 1; if ( cstart == 0 ) break; } //alert("[GetCookie] No cookie for "+name); 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; //alert("[SetCookie] Set "+cv); } function PickerItem(item_text) { if ( !this.had_tokens ) this.tokens += this.token_order.charAt(this.n_items); this[this.n_items++] = item_text; //alert("[PickerItem] Total tokens="+this.tokens.length+"; item="+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); //alert("[PickOne] Picked "+this.token_order.indexOf(token)+" ("+token+"); new tokens="+this.tokens); 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); //alert("[Picker] Starting with "+pname+"="+this.tokens); 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 = ""; //if ( this.locn.substring(0,5) == "http:") this.locn = document.location.toString(); } }