var rSeed = (new Date()).getTime();
function rnd() {
  rSeed = (rSeed*9301+49297) % 233280;
  return rSeed/(233280.0);
}

function getRandomInt(n) {
  if(getRandomInt.arguments.length == 0)
    return Math.ceil(rnd()*0xFFFFFFFF);
  else
    return (Math.ceil(rnd()*0xFFFFFFFF) % n);
}

function getDocWidth() {
  return (is_ie4up) ? document.body.clientWidth : window.innerWidth;
}
function getDocHeight() {
  return (is_ie4up) ? document.body.clientHeight : window.innerHeight;
}

function getLayer(name) {
  if(is_ie4up)
    return eval('document.all.' + name);
  else
    return findLayer(name, document);
}

function findLayer(name, doc) {
  var i, layer;
  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0) {
      layer = findLayer(name, layer.document);
      if (layer != null)
        return layer;
    }
  }
  return null;
}

function hideLayer(layer) {
  if(is_ie4up)
    layer.style.visibility = "hidden";
  else
    layer.visibility = "hide";
}

function showLayer(layer) {
  if(is_ie4up)
    layer.style.visibility = "visible";
  else
    layer.visibility = "show";
}

function isVisible(layer) {
  return (is_ie4up && layer.style.visibility == "visible") || layer.visibility == "show";
}

function moveLayerTo(layer, x, y) {
  if(is_ie4up) {
    layer.style.left = x;
    layer.style.top  = y;
  } else
    layer.moveTo(x, y);
}

function getWidth(layer) {
  if(is_ie4up) {
    return layer.style.pixelWidth ? layer.style.pixelWidth : layer.clientWidth;
  } else
    return layer.document.width ? layer.document.width : (layer.clip.right - layer.clip.left);
}

function getHeight(layer) {
  if(is_ie4up) {
    if (layer.style.pixelHeight)
      return(layer.style.pixelHeight);
    else
      return(layer.clientHeight);
  } else {
    if (layer.document.height)
      return(layer.document.height);
    else
      return(layer.clip.bottom - layer.clip.top);
  }
}

function getBottom(layer) {
  if(is_ie4up) {
    return(layer.style.pixelTop + getHeight(layer));
  } else
    return(layer.top + getHeight(layer));
}

function getTop(layer) {
  if(is_ie4up) {
    return(layer.style.pixelTop);
  } else
    return(layer.top);
}

function layerClipOrder(cssClipString) {
  var commaPos = cssClipString.lastIndexOf(",");
  return (cssClipString.substring(commaPos+1) + "," + cssClipString.substring(0,commaPos));
}

function genLayer(name,classname,content,left,top,z,width,height,visibility,bgdColor,bgdImage,clipStr) {
  var ss='';
  ss += (is_ie4up) ? '<SPAN' : '<LAYER'
  if(name) ss += ' id="'+name+'"';
  if(classname) ss += ' class="'+classname+'"';
  if(left || top || height || width || z || visibility || bgdColor || bgdImage || clipStr) {
    ss += (is_ie4up) ? (' style="'):('');
    if(left) ss += ' left'+((is_ie4up)?(':'):('='))+left+((is_ie4up)?('px;'):(''));
    if(top) ss += ' top'+((is_ie4up)?(':'):('='))+top+((is_ie4up)?('px;'):(''));
    if(height) ss += ' height'+((is_ie4up)?(':'):('='))+height+((is_ie4up)?('px;'):(''));
    if(width) ss += ' width'+((is_ie4up)?(':'):('='))+width+((is_ie4up)?('px;'):(''));
    if(z) ss += ' z-index'+((is_ie4up)?(':'):('='))+z+((is_ie4up)?(';'):(''));
    if(visibility) ss += ' visibility'+((is_ie4up)?(':'):('='))+visibility+((is_ie4up)?(';'):(''));
    if(bgdColor) ss += ' '+((is_ie4up)?('background-color:'):('bgcolor='))+bgdColor+((is_ie4up)?(';'):(''));
    if(bgdImage) ss += ' '+((is_ie4up)?("background-image:url('"):("background='"))+bgdImage+((is_ie4up)?("');"):("'"));
    if(clipStr) ss += ' '+((is_ie4up)?('clip:rect("'+clipStr+'");'):('clip='+layerClipOrder(clipStr)));
    if(is_ie4up) ss += '"';
  }
  ss += ('>')+(content?content:'')+((is_ie4up)?('</SPAN>'):('</LAYER>'));
  return(ss);
}

function writeLayer(name,classname,content,left,top,z,width,height,visibility,bgdColor,bgdImage,clipStr) {
  var ss;
  if (writeLayer.arguments.length < 12 || clipStr=='') clipStr=false;
  if (writeLayer.arguments.length < 11 || bgdImage=='') bgdImage=false;
  if (writeLayer.arguments.length < 10 || bgdColor=='') bgdColor=false;
  if (writeLayer.arguments.length < 9 || visibility=='') visibility=false;
  if (writeLayer.arguments.length < 8 || height=='') height=false;
  if (writeLayer.arguments.length < 7 || width=='') width=false;
  if (writeLayer.arguments.length < 6 || z=='') z=false;
  if (writeLayer.arguments.length < 5 || top=='') top=false;
  if (writeLayer.arguments.length < 4 || left=='') left=false;
  if (writeLayer.arguments.length < 3) content=false;
  if (writeLayer.arguments.length < 2 || classname=='') classname=false;
  ss=genLayer(name,classname,content,left,top,z,width,height,visibility,bgdColor,bgdImage,clipStr);
  document.write(ss);
}

function writeMouseable(name,classname,visible,fmover,pmover,smover,fmdown,pmdown,fmout,pmout,content,ahref,reftgt) {
  var ss='';
  ss += ((is_ie4up) ? "<DIV" : "<LAYER");
  if(name) ss += ' id="'+name+'"';
  if(classname) ss += ' class="'+classname+'"';
  if(visible)
    ss+= ((is_ie4up)?(' style="visibility:visible;"'):(' visibility="show"'));
  else
    ss+= ((is_ie4up)?(' style="visibility:hidden;"'):(' visibility="hide"'));
  if(fmover) {
    ss += " OnMouseOver='"+fmover+"("+pmover+");";
    if(smover) ss += " window.status=\""+smover+"\";";
    ss += " return true;'";
  }
  if(fmdown) ss += " OnMouseDown='"+fmdown+"("+pmdown+"); return true;'";
  if(fmout) ss += " OnMouseOut='"+fmout+"("+pmout+"); return true;'";
  ss += ">";
  if(ahref) ss += "<A href='"+ahref+"'"+(reftgt?(" target='"+reftgt+"'"):"")+">";
  ss += (content?content:"")+(ahref?"</A>":"")+((is_ie4up)?("</DIV>"):("</LAYER>"));
  document.write(ss);
}

