function checkVal(res) {
  if (res.textContent) return res.textContent;
  else if (res.text) return res.text;
  else if (res.nodeValue) return res.nodeValue
  else if (res.firstChild) return res.firstChild.nodeValue;
  else return "";
}

var set = {
	'lpId' : function(id) {
          var lp="";
	   if (id.indexOf("_loop") > -1) {
		var ids=id.split("_loop");
		lp = "_loop" + ids.pop();
		id=ids.join("_loop");
	   }
	   return [id,lp];
	},		
	'scrSize' : function() {
	  var sWid,sHe;
	  if( typeof(window.innerWidth) === 'number' ) {
       sWid = window.innerWidth;
       sHe = window.innerHeight;
      } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
       sWid  = document.documentElement.clientWidth;
       sHe = document.documentElement.clientHeight;
     } else if(document.body && (document.body.clientWidth || document.body.clientHeight )) {
      sWid  = document.body.clientWidth;
      sHe = document.body.clientHeight;
     }
     return[sWid,sHe];
	},
	'stopBub' : function(e) {
	   if (!e) var e = window.event; e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();return e;
	},
	'offset' : function(el, lessPar) {
	  if (!el) return false;
		var wid = el.offsetWidth;
		var height=el.offsetHeight;
		var top=left=ptop=pleft=x=0;
		do {
		  if (x > 0) {
			ptop+=el.offsetTop;
			pleft+=el.offsetLeft;
		  }
		  x++
		  left += el.offsetLeft;
		  top += el.offsetTop;
		} while (el=el.offsetParent);
	  if (lessPar) {
		left= left - pleft;
		top = top - ptop;
	  }
	  pleft=ptop=null;
 	  return [top, left, wid, height];
	},
	'shDiv' : function(id, type) {
	  var el=(typeof id == "string") ? document.getElementById(id) : id;
	  if (el) {
		if (type) {
			el.style.visibility="visible";
			el.style.display="block";
		} else {
			el.style.visibility="hidden";
			el.style.display="none";
		}
	     el=null;
	     return true;
	  } else return false;
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };



function Ajax() {
  this.req = null;
  this.url = null;
  this.method = 'GET';
  this.async = true;
  this.status = null;
  this.statusText = '';
  this.postData = null;
  this.readyState = null;
  this.responseText = null;
  this.responseXML = null;
  this.handleResp = null;
  this.responseFormat = 'text', // 'text', 'xml' or object
  this.innerID = null;
  this.logout = null;
  this.tries=0;
  this.maxtries=2;
}

Ajax.prototype.init = function() {
    if (!this.req) {
       try {
         //Try to create object for firefox / safari etc
         this.req = new XMLHttpRequest();
        }
        catch (e) {
         try {
           //try to create object for later versions of IE
           this.req = new ActiveXObject("MSXML2.XMLHTTP");
         }
         catch(e) {
            try {
             //try to create object for earlier versions of IE
             this.req = new ActiveObject('Microsoft.XMLHTTP');
          } catch (e) {
            //could not create the object so return false
            return false;
         }
       }
    }
  }
  return this.req;
}

Ajax.prototype.doReq = function() {
  if (!this.init()) {
    alert("Could not create XMLHttp Object");
    return;
  }
 this.req.open(this.method, this.url, this.async);
  if (this.method == "POST") {
    this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this.req.setRequestHeader("Content-length", this.postData.length);
    this.req.setRequestHeader("Connection", "close");
  }
  var self = this;
  this.req.onreadystatechange = function() {
    var resp;
    if (self.req.readyState == 4) {
        switch(self.responseFormat) {
            case 'text':
                resp = self.req.responseText;
                break;
            case 'xml':
                resp = self.req.responseXML;
                break;
            case 'object':
                resp = req;
                break;
       }
        if (self.req.status >= 200 && self.req.status <= 299) {
            //find out what status resp is
            if (self.logout) {
               if (self.responseFormat=="xml") {
				var tgs = resp.getElementsByTagName("_logout_");
				 if (tgs.length > 1) {
					tgs=null;
					href.location = self.logout;
				 } 
			   } else if (resp.indexOf("_logout_=true ") > -1) {
				href.location=self.logout;
			   }
			  return false;  
	      }	   
	  if (self.innerID) {
	    document.getElementById(self.innerID).innerHTML = resp;
	  } 
	  if (typeof self.handleResp === 'function') self.handleResp(resp);
	  else if (self.handleResp==="alert") alert(resp);
     } else self.handleErr(resp);
    }
    resp=null;
  };
  try {
    this.req.send(this.postData);
    } catch (e) {
    }
    resp=null;
}

Ajax.prototype.handleErr = function(str) {
  if (this.tries < this.maxtries) {
	this.tries++;
	this.abort();
	this.doReq();
 } else {
    alert ('An error has occured, Status code: ' + this.req.status + '\n Status description: ' + this.req.statusText + ' URL: ' + this.url);
  }
}

Ajax.prototype.abort = function() {
  if (this.req) {
    this.req.onreadystatechange = function () {};
    this.req.abort();
    this.req = null;
  }
}

Ajax.prototype.doGet = function(url, hand, format, innerID, logout) {
  this.url=url;
  this.handleResp=hand;
  this.innerID=innerID;
  this.logout=logout;
  this.responseFormat = format || 'text';
  this.doReq();
}


var hands = {
	'st' : {},
	'setHd' : function(el, ob, set) {
	  for ( var i in ob) {
	    try {
		el[i] = (set)?ob[i]:null;
		if (i==="onclick") el.style.cursor="pointer";
		} catch(e){}
	  }
	  el=ob=set=null;
	},
	'set' : function(set) {
	  var iob, el, y;
		for (var i in hands.st) {
		   iob=hands.st[i];
		   if (iob.loop) {
		    y=0;
		    do {
		     el=document.getElementById(i + "_loop" + y);
		     if (el) hands.setHd(el, iob, set);
		     y++;
		    } while (el);
		  } else hands.setHd(document.getElementById(i), iob, set);
		}
		scrl.loadOb();
	  iob=el=y=null;	
	},
	'reg' : function(id, type, func) {
	   if (!hands.st[id]) hands.st[id] = {};
	   hands.st[id][type] = func;
	} 
}

var win = {
   'wins' : {},
	'open' : function() {
	  var ob=win.wins[this.id];
		window.open(ob.src, "view_photo", "toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=" + b.width + ",height=" + ob.height + ",top=100,left=50");
		ob=null;
    return false;
	},
	'reg' : function(id, src, width, height) {
		win.wins[id] = {'src':src,'width':width,'height':height};
	},
	'popOver' : function(id) {
	  var id = (typeof id === "string") ? id : this.id;
      var ob=win.wins[id];
	  win.closePopOver();
	  var dv = document.createElement("div");
	 dv.setAttribute("id", "popover");
	 dv.style.cssText="width:100%;height:100%;position:fixed;margin:0px;padding:0px;top:0px;left:0px;background-image:url(/img/grey_popup_fade.png);background-repeat:repeat;z-index:6000;";
    var href= (ob.src.indexOf("?") > -1) ? ob.src + "&popover=true" : ob.src + "?popover=true";
	dv.innerHTML="<iframe id='popovercontent' src='" + href + "' FRAMEBORDER=0 style='position:absolute;margin:0px;padding:0px;top:10px;left:0px;border:0px;visibility:hidden;'></iframe></div>";
	document.body.appendChild(dv);
	dv=null;
	return false;
  },
  'resizePop' : function() {
    var arr=set.scrSize();
    var wid=0,he=0,l=0,t=0;
    var ob=document.getElementById("popovercontent");
  	if (!ob) return false;
  	var sWid=arr[0],sHe=arr[1];
	var bd=(ob.contentWindow) ?ob.contentWindow.document.body : ob.contentDocument.body;
	for (var i=0,n=bd.childNodes.length;i<n;i++) {
		if (bd.childNodes[i].nodeName.toLowerCase() === "div") {
  			l=bd.childNodes[i].offsetWidth + bd.childNodes[i].offsetLeft;
			t=bd.childNodes[i].offsetHeight + bd.childNodes[i].offsetTop;
			if (l > wid) wid = l;
			if (t > he) he=t;
		}
	}
	var sc=false;
  	if (he > arr[1] * 0.9) {
	    he = arr[1] * 0.9;
	    sc=true;
	}
	if(sc) {
  	  bd.style.overflow="hidden";
  	  var bdwid=bd.clientWidth;
  	  bd.style.overflow="scroll";
  	  bdwid -= bd.clientWidth;
  	  if (!bdwid) bdwid = bd.offsetWidth - bd.clientWidth;
  	  bd.style.overflow='auto';
  	  if (bdwid + wid < sWid * 0.8) wid += bdwid;
  	}  
  	bd=null;
  	ob.style.left=((sWid / 2) - (wid / 2)) + "px";
    ob.style.top=((sHe / 2) - (he / 2)) + "px";
    ob.style.width=(wid + 3) + "px";
    ob.style.height=(he + 3) +  "px";
    ob.style.visibility="visible";
    sHe=sWid=ob=wid=he=l=t=null;
  },
  'closePopOver' : function() {
     var ob=document.getElementById("popover");
     if (ob) document.body.removeChild(ob);
     ob=null;
   },
   'setZero' : function() {
    var bd;
    for (var i=0,n=document.body.childNodes.length; i<n; i++) {
    bd=document.body.childNodes[i];
    if (bd.nodeType==1 && bd.nodeName.toLowerCase() == "div") {
      bd.style.top="0px";
      bd.style.left="0px";
      break;
    }
  }
  bd=null;
  }

}

function popOver(ob) {
 	win.reg(ob.id, ob.href);
	win.popOver(ob.id);
	ob=null;
	return false;
}

function closePopOver() {
	win.closePopOver();
}

var drop = {
  'drops' : {},
  'msO' : {},
  'sty' : {},
  'oM' : [],
  'curLevel' : 0,
  'scrollOut' : function(id,x, y) {
    ob=drop.cob;
    var cob=drop.drops[id];
    if (x > parseInt(cob.width)) x=parseInt(cob.width);
    if (y > parseInt(cob.height)) y = parseInt(cob.height);
	ob.style.overflow="hidden";
	ob.style.width = x + "px";
	ob.style.minHeight= y + "px";
	x+=10;
	y+=10;
	if (x < parseInt(cob.width) || y < parseInt(cob.height)) {
		window.setTimeout("drop.scrollOut('" + id + "', " + x + ", " + y + ");", 10);
	}
	ob=cob=null;
  },
  'startDrop' : function(id) {
    //if curmenu is not false then clear it out
    var cob=drop.drops[id];
    drop.curLevel = (isNaN(parseInt(cob.level)))? 0:  cob.level;
    if (!cob.status) {
      drop.checkTime();
      drop.oM[drop.oM.length] = id;
      set.shDiv(cob._dropMenu, true);
      if (cob.align) {
           //get the offset of the parent and then the child node
           var dropel=document.getElementById(cob._dropMenu);
           var el=set.offset(document.getElementById(id));
           dropel.style.left = (el[1] + cob.align[0]) + "px";
           dropel.style.top = (el[0] + cob.align[1]) + "px";
           dropel=el=null;
      }
      drop.cob=document.getElementById(cob._dropMenu);
      if (cob.type == "scrollin") drop.scrollOut(id, 0, 0);
    } 
	cob.status=1;
	cob=null;
    //finally start timer
  },
  'unSet' : function(id) {
	drop.drops[id].status=2;
	drop.drops[id].offsetTime = new Date();
	setTimeout("drop.checkTime();",200);
  },
  'checkTime' : function() {
    var recheck=false;
    var cob,now,dif;
    var i = drop.oM.length;
    while (i--) {
		cob=drop.drops[drop.oM[i]];
		if (cob.status==2 && cob.level >= drop.curLevel) {
		   now = new Date();
    	   dif = now.getTime() - cob.offsetTime.getTime();
    	if (dif > cob.delay) {
		   set.shDiv(cob._dropMenu, false);
		   cob.status=null;
		   drop.oM.splice(i, 1);
    	} else recheck=true;
		}
	}
    if (recheck) setTimeout("drop.checkTime()", 100);
    recheck=cob=now=dif=null;
 },
 'mouseO' : function(){
   var cob=drop.msO[this.id];
   if (cob) this.src=cob.mouseO;
   id=this.id.replace(/_dropdown/g, "");
   cob = drop.drops[id];
   if (cob) drop.startDrop(id);
   cob=drop.sty[this.id];
   if (cob){
    var or;
	 for (var i in cob) {
		or=this.style[i];
		if (cob[i]) this.style[i]=cob[i];
		cob[i]=or?or:i==="backgroundColor"?"transparent":i==="backgroundRepeat"?"repeat":"none";  
	 }
	or=null;
  }
   cob=null;
  },
  'mouseOt' : function() {
    var cob=drop.msO[this.id];
    if (cob) this.src=cob.src;
    id=this.id.replace(/_dropdown/g, "");
    cob = drop.drops[id];
	if (cob) drop.unSet(id);
	cob=this.sty;
	cob=drop.sty[this.id];
   if (cob){
    var or;
	 for (var i in cob) {
		or=this.style[i];
     	 this.style[i]=cob[i];
		 cob[i]=or;
	 }
	or=null;
  }
	cob=null;
  },
  'regDrop' : function(id, level, delay, align) {
   if (!delay) delay=0;
	drop.drops[id] = {'_dropMenu': id + "_dropdown", 'level':level, 'delay':delay, 'align':align};
	hands.reg(id, 'onmouseover', drop.mouseO);
	hands.reg(id, 'onmouseout', drop.mouseOt);
	hands.reg(id + "_dropdown", 'onmouseover', drop.mouseO);
	hands.reg(id + "_dropdown", 'onmouseout', drop.mouseOt);
  },
  'regM' : function(id, src, msO) {
	drop.msO[id] = {'src':src,'mouseO':msO};
	hands.reg(id, 'onmouseover', drop.mouseO);
	hands.reg(id, 'onmouseout', drop.mouseOt);
	var img = new Image();
    img.src = msO;
  },
  'regSt' : function(id, col, img, rep) {
	 drop.sty[id] = {'backgroundColor':col,'backgroundImage':img,'backgroundRepeat':rep};
	 hands.reg(id, 'onmouseover', drop.mouseO);
	hands.reg(id, 'onmouseout', drop.mouseOt);
  }
}

var fms = {
  'vals' : {},  
  'reg' : function(id, def,err) {
	 fms.vals[id] = {'def':def,'error':err};
  },
  '_clickBlur' : function() {
	if (this.value=="") this.value =fms.vals[this.id].clickRemove;
  },
  '_clickFocus' : function() {
	if (this.value==fms.vals[this.id].clickRemove) this.value = "";
   },
    'shBD' : function(fm) {
     var tgs=fm.elements;
     var cob;
     var i=tgs.length;
     while (i--) {
		if (fms.vals[tgs[i].id]) {
			cob=fms.vals[tgs[i].id];
			if (cob.okay) {
				if (cob.border && tgs[i].type != "radio" ) tgs[i].style.border=cob.border;
			} else {
			if (tgs[i].type != "radio") {
				if (tgs[i].style.border != "2px solid red") cob.border=tgs[i].style.border;
				tgs[i].style.border="2px solid red";
			}
		   }	
		}
	 }
	tgs=cob=i=null;
    }, 
    '_chkForm' : function(fmName, del) {
       if (del==="1") {
		var ok=confirm("Are you sure you want to delete this?\nClicking ok will permanently delete this from the database. If you do not want to delete this, click cancel");
		return ok;
	  } else {
  		var ob, cob, fm = document.getElementById(fmName), typ;
  		var okay=true;
  		var tgs=fm.getElementsByTagName("*");
  		var i=tgs.length;
  		var rads={};
  		var err="The following action is required: ";
  		while (i--) {
  		  ob=tgs[i];
			if (fms.vals[ob.id]) {
				typ=ob.type;
				cob=fms.vals[ob.id];
				cob.okay=true;
				if (typ == "radio") {
					if (ob.checked) rads[ob.name] = true;
					else if (!rads[ob.name]) rads[ob.name] = false;
				} else if ((typ=="checkbox" && !ob.checked) || (typ !== "checkbox" && ob.value.trim() == cob.def)) {
				 if (cob.error) err += "<br>" + cob.error;
				 else err += "<br>" + ob.name;
				  okay=cob.okay=false;
				}  
			} 
		}
		for (var i in rads) {
		  if (!rads[i]) {
		    fms.vals[i].okay = okay = false;
		    err += (err.error) ? "<br>" + err.error : "<br>" + i;
		   }  
		}
		rads=typ=cob=ob=null;
		fms.shBD(fm);
  		if (!okay) {
	      var el=document.getElementById(fm.id + "_error");
	      if (el) {
		    el.firstChild.innerHTML = err;
		    set.shDiv(el);
		    el=null;
		  }  else alert(err.replace(/<br>/g, "\n"));
	      el=null;
  		} else if (mAjax.obs[fmName]) {
  		  var data = "";
			//make an ajax object of the data
	        var i=fm.elements.length;
	        var ob;
	        while (i--) {
	         ob=fm.elements[i];
	         if (data !== "") data += "&";
	         if (ob.type==="radio") {
	           var x=ob.length;
	           while (x--) {
				if (ob[x].checked) {
				   data += ob[x].name + "=" + escape(ob[x].value);
					break;
				} 
			   }	
			 } else if ((ob.type!=="checkbox" || ob.checked) && typeof ob.value === "string" ) data += ob.name + "=" + escape(ob.value);
		   }

		  mAjax.run(fmName, data);
		  tg=tgs=data=null;
		  return false;
		}
 		return okay;
 	 }	
   }
}
var cal = {
	'date' : null,
	'day' : ((1000 * 60) * 60) * 24,
	'curmonth' : null,
	'month' : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	'setDateId' : null,
	'origFunc' : false,
	'runCal' : function(e) {
		//get offset left and top
	  set.stopBub(e);
	  cal.close();
	  cal.setDateId = this.id;
	  cal.date = new Date();
	  var off=set.offset(this);
      var dv = document.createElement("div");
      dv.style.position="absolute";
      dv.style.top=off[0] + "px";
      dv.style.left=(off[1] + off[2] + 15 ) + "px";
      dv.setAttribute("id", "calendar");
      dv.onclick=set.stopBub;
      dv.style.backgroundColor="#ffffff";
      dv.style.border="1px solid #000000";
      dv.style.zIndex="400";
      document.body.appendChild(dv);
      cal.setCal();
      cal.origFunc = document.body.onclick;
      dv=off=null;
	},
	'setCal' : function() {
	  var el = document.getElementById("calendar");
	  if (el==null) return false;
	    var mon, htm, st, day, dt;
	    this.curmonth = this.date.getMonth()
	    mon = this.month[this.curmonth];
	    htm = "<table style='font-size:12px;font-family:Arial;'><tr><td colspan='7' style='text-align:right;cursor:pointer;' onclick='cal.close();'>close</td></tr>";
		htm += "<tr><td colspan='7' style='text-align:center;'><span style='position:relative;float:left;'><a id='backyear' style='cursor:pointer;'>&lt;&lt;</a>&nbsp;|&nbsp;<a id='back' style='cursor:pointer;'>&lt;</a></span>&nbsp;|&nbsp;<span>" + mon + " - " + cal.date.getFullYear() + "</span>&nbsp;|&nbsp;<span id='nextmonth' style='position:relative;float:right;'><a id='next' style='cursor:pointer;'>&gt;</a>&nbsp;|&nbsp;<a id='nextyear' style='cursor:pointer;'>&gt;&gt;</a></span></td></tr>";
		htm += "<tr><td id='sun'>Sun</td><td id='mon'>Mon</td><td id='tue'>Tue</td><td id='wed'>Wed</td><td id='thu'>Thu</td><td id='fri'>Fri</td><td id='sat'>Sat</td></tr>";
		var dto = new Date();
		dto.setDate(1);
		dto.setFullYear(this.date.getFullYear());
		dto.setMonth(this.date.getMonth());
		day = dto.getDay();
		st=0;
		while (dto.getMonth() == this.curmonth) {
		  for (var i=0; i<7; i++) {
		    if (i==0) htm += "<tr>";
		    if (i==day && st==0) st=1;
		    if (st==1) {
		     dt = dto.getDate();
		     htm += "<td id='date/" + dt + "' style='text-align:center;cursor:pointer;'>" + dt + "</td>";
		      dto.setTime(dto.getTime() + this.day);
			} else {
			 htm += "<td>&nbsp;</td>";
			}
		    if (i==6) htm += "<tr>";
		    if (dto.getMonth() != this.curmonth) st=2;
		  }
		}	 
	   el.innerHTML = htm;
	   var tgs =el.getElementsByTagName("td");
       for (var i=0; i<tgs.length; i++) {
		if (tgs[i].id!=null && tgs[i].id!="") {
		    tgs[i].onclick=cal.postDate;
		}
	  } 
	  document.getElementById("back").onclick=cal.prevMonth;
	  document.getElementById("next").onclick=cal.nextMonth;
	  document.getElementById("backyear").onclick=cal.prevYear;
	  document.getElementById("nextyear").onclick=cal.nextYear;
	  mon=htm=st=day=dt=dto=tgs=el=null;
	},	
	'setDate' : function(time) {
		this.date.setTime(time);
	},
   'postDate' : function(e) {
       set.stopBub(e);
		var day = this.id.split("/");
		var mon = cal.date.getMonth() + 1;
		if (mon < 10) mon = "0" + mon;
		if (day[1] < 10) day[1] = "0" + day[1];
		document.getElementById(cal.setDateId).value = day[1] + "/" + mon + "/" + cal.date.getFullYear();
		day=mon=null;
		cal.close();
	},	
	'nextMonth' : function() {
		var mon = cal.date.getMonth() + 1;
		if (mon>=12) {
			cal.date.setFullYear(cal.date.getFullYear() + 1);
			cal.date.setMonth(0);
		} else {
		    cal.date.setMonth(mon);
	    }
	  cal.setCal();
	},
	'nextYear' : function() {
		cal.date.setFullYear(cal.date.getFullYear() + 1);
		cal.setCal();
	},	
	'prevMonth' : function() {
		var mon = cal.date.getMonth() - 1;
		if (mon==-1) {
		   cal.date.setFullYear(cal.date.getFullYear() - 1);
		   cal.date.setMonth(11);
		} else {
		   cal.date.setMonth(mon);
	    }
	  cal.setCal();
	},
	'prevYear' : function() {
		cal.date.setFullYear(cal.date.getFullYear() - 1);
		cal.setCal();
	},
	'close' : function() {
	   var el = document.getElementById("calendar");
	   if (el!=null) document.body.removeChild(el);
	   el=null;
	   if (cal.origFunc != false) {
	       document.body.onclick=cal.origFunc;
	   	   cal.origFunc=null;
	   }
	} 
}

var mAjax = {
	'obs' : {},
	'addOb' : function(id, name, src, srcid, method, func, data, logout, time) {
		mAjax.obs[id] = {'src':src,'srcid':srcid,'name':name,'method':method,'func':func,'data':data,'logout':logout,'time':time};
	},
	'run' : function(id, data) {
		var id=(typeof id === "string") ? id : this.id;
		var cob=mAjax.obs[id];
		if (!cob) return false;
	    var ob=document.getElementById(cob.srcid);
		if (ob) ob.innerHTML = "loading... ";
		ob=null;
		var ajax = new Ajax();
		var src=cob.src + "?ajaxid=" + id;
		if (cob.method==="POST") ajax.postData = data;
		else src += "&" + cob.name + "=true&" + data;
		ajax.method=cob.method;
		ajax.doGet(src, cob.func, "text", cob.srcid, cob.logout);
		if (!isNaN(parseInt(cob.time))) window.setTimeout("mAjax('" + id + "');");
	    id=cob=src=ajax=null;
	}

}

var scrl = {
	'obs':{},
	'scr' : function(id) {
	  var obs=scrl.obs[id];
	    if(!obs.pause) {
			obs.vl=obs.vl <= 0 - obs.size? obs.st : obs.vl - 1;
			obs.ob.firstChild.style[obs.style] = obs.vl + "px";
		}	
		window.setTimeout("scrl.scr('" + id + "')", obs.speed);
	  obs=null;
	},
	'stpscr' : function() {
		scrl.obs[this.id].pause=true;
	},
	'setscr' : function() {
		scrl.obs[this.id].pause=false;
	},
	'regOb' : function(id, speed, style) {
		scrl.obs[id] = {'speed' : speed, 'id' :id, 'style' : style};
	},
	'loadOb' : function() {
	  var style,ob,dv;
		for (var id in scrl.obs) {
		ob=document.getElementById(id);
		scrl.obs[id].ob = ob;
		style=scrl.obs[id].style;
		dv=document.createElement("div");
		dv.className = ob.className;
		dv.style.top=0;
		dv.style.left=0;
		dv.style.position="relative"; 
		dv.style.padding=0;
		dv.innerHTML=ob.innerHTML;
		ob.innerHTML="";
		ob.style.overflow="hidden";
		ob.appendChild(dv);
		window.setTimeout("scrl.scr('" + id + "')", scrl.obs[id].speed / 10);
	var h = set.offset(dv.lastChild, true);
	if (style==="left") {
			scrl.obs[id].size=scrl.obs[id].vl=ob.offsetWidth;
			dv.style.width = (h[1] + h[2] + 5) + "px";
		} else {
			scrl.obs[id].size=scrl.obs[id].vl=ob.offsetHeight;			
			dv.style.height = (h[0] + h[3] + 5) + "px";
		}
	
	scrl.obs[id].st=scrl.obs[id].vl;
	}
      dv=ob=style=h=null;	
	}
}

var tree = {
 'obs' : {},
 'show':function() {
       var ids=set.lpId(this.id);
       var id=ids[0];
       var lp=ids[1];
        if (tree.obs[id]) {
		//is this on or off
          var cob=tree.obs[id];
	  var on;
	  if (lp != "") {
		cob[lp] = (cob[lp]) ? false : true;
	        on=cob[lp];
	  } else {
		cob.on = (cob.on) ? false : true;
	        on=cob.on;
          }
	  set.shDiv(cob.block_id + lp, on);
	  if (on) {
		//var re = new RegExp(cob.onval, 'i');
		var wit = cob.offval;
	  } else {
	    //    var re = new RegExp(cob.offval, 'i');
		var wit = cob.onval;
          }
        // this.innerHTML = this.innerHTML.replace(re, wit);
	re=wit=cob=id=lp=null;
    }
  },
  'reg' : function(id, blockid, onval, offval, loop) {
	tree.obs[id] = {'on':false,'block_id':blockid,'onval':onval,'offval':offval,'loop':true};
	hands.reg(id, 'onclick', tree.show);
        if (loop) {
	   hands.st[id].loop=true;
	   var i=0;
  	   while(set.shDiv(blockid + "_loop" + i, false)) {
		i++;
           }
        } else set.shDiv(blockid, false);
  }
}

var _cln = {
//id, par, num, cln
  '_obs' : {},
  'setEl' : function(el) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
	var nm;
    	while (i--) {
	 nm=tgs[i].nodeName.toLowerCase();
	  if ((nm==="input" && tgs[i].type != "submit") || nm==="select" || nm==="textarea") {
             if (tgs[i].name.indexOf("[") == -1) tgs[i].name = tgs[i].name + "[0]";
          }
        }
	el=tgs=nm=num=null;
   },
 'rsNum' : function(cln, num) {
 	var tgs=cln.getElementsByTagName("*");
	var i=tgs.length;
	var nm;
    	while (i--) {
	 nm=tgs[i].nodeName.toLowerCase();
	  if ((nm==="input" && tgs[i].type != "submit") || nm==="select" || nm==="textarea") {
	    var exp=tgs[i].name.split("[");
	    tgs[i].name = exp[0] + "[" + num + "]";

          }
        }
	cln=num=tgs=null;
 },
 '_clone' : function() {
	var id,ob,cln,q;
	id=this.id;
 	ob=_cln._obs[id];
	ob.num++;
	cln = ob.cln.cloneNode(true);
	_cln.rsNum(cln, ob.num);
	_cln.rsIds(cln, ob.num);
	ob.par.appendChild(cln);
	q=document.getElementById(ob.q);
	q.value=parseInt(q.value) + 1;
	if (ob.func) {
	try {
	  ob.func();
        } catch(e){}
        }
	id=ob=cln=q=null;
  },
  'rsIds' : function(el, num) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
	while (i--) {
	  if (tgs[i].id && tgs[i].id.indexOf("_0_") > -1) tgs[i].id = tgs[i].id.replace("_0_", "_" + num + "_");
	   if (tgs[i].value) tgs[i].value="";
	}
	tgs=i=null;
  },	
  'rem' : function() {
	//how to remove this one?
  },
  'reset' : function(el) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
    	while (i--) {
	  if ((tgs[i].nodeName==="input" && tgs[i].type != "submit") || tgs[i].nodeName==="select" || tgs[i].nodeName==="textarea") {
             if (tgs[i].name.indexOf("[") == -1) tgs[i].name = tgs[i].name + "[0]";
          }
        }
       i=tgs=null;
   },
   'reg' : function(id, clon, q, func) {
	_cln.setEl(clon);
	var par=clon.parentNode;
	var _clone = clon.cloneNode(true);
	_cln._obs[id] = {'cln':_clone,'par':par,'q':q,'num':0,'func':func};
	hands.reg(id, "onclick", _cln._clone);
	par=_clone=null;
   }
}

var sts = {}

window.onbeforeunload = function() {
     hands.set(false);
}
