var randstr="";
randnum = Math.random();
todyDate = new Date();
randstr="" + todyDate.getTime() + randnum;
function goto_rr(nurl)
{
  var urlstr = new String(nurl);
  var indx;
  var indy;

  indx = urlstr.lastIndexOf('?');
  if (indx < 0) {
    indy = urlstr.lastIndexOf('#');
    if (indy < 0) {
      location.href=nurl+'?rr='+randstr;
    } else {
      var urla = urlstr.substr(0, indy);
      var urlb = urlstr.substr(indy);
      location.href=urla+'?rr='+randstr+urlb;
    }
  }
  else {
    indy = urlstr.lastIndexOf('#');
    if (indy < 0) {
      location.href=nurl+'&rr='+randstr;
    } else {
      var urla = urlstr.substr(0, indy);
      var urlb = urlstr.substr(indy);
      location.href=urla+'&rr='+randstr+urlb;
    }
  }
}

function getvalue(offset)
{
    var end = document.cookie.indexOf(";",offset);
    if ( end == -1 )
    {
      end = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset,end));
}

function get(name)
{
    var arg = name + "=";
    var argLength = arg.length;
    var cokLength = document.cookie.length;
    var index = 0;

    while( index < cokLength )
    {
        var pos = index + argLength;

        if( document.cookie.substring(index,pos) == arg )
        {
            return this.getvalue(pos);
        }

        index = document.cookie.indexOf(" ",index) + 1;

        if( index == 0 )
        {
            break;
        }
    }

    return null;
}

function put(name,value,expires,path,domain,secure)
{
    document.cookie = name + "=" + escape(value) +
    ( (expires) ? "; expires=" + expires.toGMTString() : "" ) +
    ( (path) ? "; path=" + path : "" ) +
    ( (domain) ? "; domain=" + domain : "" ) +
    ( (secure) ? "; secure" : "" );
}

function remove(name,path,domain)
{
    if( this.get(name) )
    {
        document.cookie = name + "=" +
        ( (path) ? "; path=" + path : "" ) +
        ( (domain) ? "; domain=" + domain : "" ) + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function Cookie()
{
    this.getvalue = getvalue;

    this.get = get;
    this.put = put;
    this.remove = remove;
}

function GetCookie(name)
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
    
   while (i < clen)
   {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getvalue (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
   }
   return null;
}

function open_win(loc, form, id , name, error)
{
   var ldata = "" + loc;
   loc = loc+"?form="+form+"&form_id="+id+"&form_name="+name;
   if ( error ) {
      loc = loc + "&error=1";
   }
   self.win_child=open(loc,"getcode","directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes,height=400,width=630");
   self.win_child.rtn_id=id;
   self.win_child.rtn_name=name;
   self.win_child.win_parent=self;
}

function selid(loc, id, name)
{
   remote=window.open("","remote","directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes,height=600,width=800") ;
   remote.location.href="/~myhsu/stksel.php";
}

function FixCookieDate (date)
{
   var base = new Date(0);
   var skew = base.getTime(); // dawn of (Unix) time - should be 0
   if (skew > 0)  // Except on the Mac - ahead of its time
      date.setTime (date.getTime() - skew);
} 
function openWIN(url)
{   wchild = window.open (url, "print", "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,screenX=80,screenY=0,top=yes,height=600,width=650");
}

function openNEW(url)
{
  randnn=Math.random();
  toDate=new Date();
  rands=toDate.getTime() + randnn;
  openWIN(url+"?rand="+rands);
}

var uid = new String;
function reload() {
   now = new Date;
   if (now.getHours()>=9 && now.getHours()<=13)
      thetimer = setTimeout("changeimage()", 60000);
}

function changeimage(){
    var tmp ;
   now = new Date;
   uid = "?uid="+now.getHours().toString()+now.getMinutes().toString()+now.getSeconds().toString();
   //imagesource = "http://tw.chart.yahoo.com/q/q/2330.png" + uid;
   imagesource = window.document.image.src ;
   tmp = imagesource.split ("?") ;
   imagesource = tmp[0] + uid ;
   window.document.image.src = imagesource;
   if(now.getHours()>=9 && now.getHours()<=13 )
      thetimer = setTimeout("changeimage()", 60000);
}

/*
function SetCookie(name,value,expires,path,domain,secure)
{
   document.cookie = name + "=" + escape (value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}

function WriteRegister(id)
{
   var expdate = new Date ();
   FixCookieDate(expdate);
   var oneMonth=30*24*60*60*1000;
   var oneWeek=7*24*60*60*1000;
   if((id==null)||(id.length==0)||(id==""))
   {
      expdate.setTime(expdate.getTime()+oneWeek);
      SetCookie("user@kimo","guest",expdate,"/","yahoo.com");
   }
   else
   {
      expdate.setTime(expdate.getTime()+oneMonth);
      SetCookie("user@kimo",id,expdate,"/","yahoo.com");
   }
}
*/
