/* Copyright (C) 2005-2006 Six Ray Vision LLC.  All rights reserved.
 * $Id: functions.js,v 1.11 2006/02/02 15:33:56 doug Exp $
 */
// --------------------------------------------------------------------
// 1K DHTML API: http://www.dithered.com/javascript/1kdhtml/usage.html
d=document;l=d.layers;ie=d.all;op=navigator.userAgent.indexOf('Opera')!=-1;px='px';
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t}if(d.all)return d.all[e];return d.getElementById(e)}
function sE(e){l?e.visibility='show':e.style.visibility='visible'}
function hE(e){l?e.visibility='hide':e.style.visibility='hidden'}
function sZ(e,z){l?e.zIndex=z:e.style.zIndex=z}
function sX(e,x){l?e.left=x:op?e.style.pixelLeft=x:e.style.left=x+px}
function sY(e,y){l?e.top=y:op?e.style.pixelTop=y:e.style.top=y+px}
function sW(e,w){l?e.clip.width=w:op?e.style.pixelWidth=w:e.style.width=w+px}
function sH(e,h){l?e.clip.height=h:op?e.style.pixelHeight=h:e.style.height=h+px}
function sC(e,t,r,b,x){l?(X=e.clip,X.top=t,X.right=r,X.bottom=b,X.left=x):e.style.clip='rect('+t+px+' '+r+px+' '+b+px+' '+x+px+')'}
function wH(e,h){if(l){Y=e.document;Y.open();Y.write(h);Y.close()}if(e.innerHTML!=null)e.innerHTML=h}

// --------------------------------------------------------------------
// parent element
function pE(e){if(e&&e.parentElement)return e.parentElement;else if(e&&e.parentNode)return e.parentNode;else return null}
// show/hide/query/toggle style display
function sDE(e){if(e)e.style.display=''}
function hDE(e){if(e)e.style.display='none'}
function qDE(e){return e.style.display!='none'}
function togDE(e){if(e){if(qDE(e))hDE(e);else sDE(e)}}
// set class name
function sCE(e,c){if(e)e.className=c}

// --------------------------------------------------------------------
function gHt(d,ht,sh,oh){//get height
  ht=0;
  if(d.height)ht=d.height;
  else if(d.body){
    if(d.body.scrollHeight)ht=sh=d.body.scrollHeight;
    if(d.body.offsetHeight)ht=oh=d.body.offsetHeight;
    if(sh&&oh)ht=Math.max(sh,oh);
  }
  return ht;
}
function sFHt(id){//set frame height
  var w=window.frames[id]; var e=gE(id);
  if(e&&w){
    e.style.height="auto";
    var ht=gDHt(w.document);
    if(ht)e.style.height=ht+29+'px';
  }
}
function sFHtP(id){if(parent != window)parent.sFHt(id);sFHt(id)}

function unframe(){if(self!=top)top.location=self.location}
function frame(url){if(self==top)self.location=url}
function framechk(url,fwd){if(self==top)self.location=url;
                           else{if(top.location.pathname!=url)top.location=fwd}}

// --------------------------------------------------------------------
function preload(){
  if(document.images)
    for (var i=0; i<preload.arguments.length; ++i)
      (new Image()).src=preload.arguments[i];
}

// --------------------------------------------------------------------
function roSel(sel,dir){//dir is 1 (down) or -1 (up)
  for (var i=0; i<sel.length; ++i)
    if(sel.options[i].selected)break;
  if(i+dir>=0 && i+dir<sel.length){
    var tmp=new Option(sel.options[i+dir].text,sel.options[i+dir].value);
    sel.options[i+dir]=new Option(sel.options[i].text,sel.options[i].value);
    sel.options[i]    =tmp;
    sel.options[i+dir].selected=1;
  }
}
function gSel(sel){//get sel opt
  for (var i=0; i<sel.length; ++i)
    if(sel.options[i].selected)break;
  return sel.options[i];
}
function rmSel(sel){
  for (var i=0; i<sel.length; ++i)
    if(sel.options[i].selected)break;
  if(i<sel.length){
    var opt=new Option(sel.options[i].text,sel.options[i].value);
    for (var j=i+1; j<sel.length; ++j)
      sel.options[j-1]=new Option(sel.options[j].text,sel.options[j].value);
    if(ie)sel.remove(sel.length-1);
    else  sel.options[sel.length-1]=null;
  }
  return opt;
}
function addSel(sel,opt){
  if(ie)sel.add(opt);
  else   sel.options[sel.length]=opt;
}
function mvSel(src,dst){
  if(src&&dst){var opt=rmSel(src);
               addSel(dst,opt)}
}
function cpIdxSel(src,dst,idx){//cp selection to idx (default 0)
  if(!idx)idx=0;
  if(src&&dst){var opt=gSel(src);dst.options[idx]=new Option(opt.text,opt.value)}
}
function cpAddSel(src,dst){//cp selection append
  if(src&&dst){var opt=gSel(src);addSel(dst,new Option(opt.text,opt.value))}
}

// --------------------------------------------------------------------
String.prototype.trim=function(){return this.replace(/^\s*/g,'').replace(/\s*$/g,'')}
String.prototype.unspace=function(){return this.replace(/\s*/g,'')}

// --------------------------------------------------------------------
function stringify(obj){
  var re_eq=/=/g;
  function enc(s){var t=encodeURI(s);t=t.replace(re_eq, '%3D');return t}
  function emit(obj){
    if(typeof obj == "object"){
      var buf=''; var is_mapping=false; var is_empty=true;
      for (var k in obj){
        is_empty=false;
        if(isNaN(k)){ is_mapping=true; break}
      }
      if(!is_mapping)buf+='[';
      else           buf+='{';
      for (k in obj){
        if(buf.length>1)buf+='&';
        if(is_mapping)  buf+=enc(k)+'=';
        buf+=emit(obj[k]);
      }
      if(!is_mapping)buf+=']';
      else           buf+='}';
      return buf;
    }
    else return enc(obj);
  }
  return emit(obj);
}


// --------------------------------------------------------------------
function setImageWH(i,wf,hf) {
  // image, width field, height field
  img=new Image();
  img.src=(i.src);
  wf.value=img.width;
  hf.value=img.height;
}

