var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)} 

TINY.dropdown=function(){
	function menu(n){this.n=n; this.h=[]; this.c=[]; this.z=99}
	menu.prototype.init=function(p,c,f){
		this.m=c; var w=T$(p), s=T$$('ul',w), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',1)');
			h.onmouseout=new Function(this.n+'.st('+i+')')
		}
	};
	menu.prototype.st=function(x,z){
		var c=this.c[x], h=this.h[x], p=T$$('a',h)[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(z){
			p.className+=' '+this.m; c.style.display='block';
			if(!c.mh){c.mh=parseInt(TINY.style.value(c,'height')); c.style.height=0}
			if(c.mh==parseInt(c.style.height)){c.style.overflow='visible'}
			else{c.style.zIndex=this.z; this.z++; c.t=setInterval(function(){sl(c,c.mh)},25)}
		}else{
			p.className=p.className.replace(this.m,''); c.t=setInterval(function(){sl(c,0)},25)
		}
	};
	function sl(c,t){
		var h=parseInt(c.style.height);
		if(h==t){
			clearInterval(c.t); if(!t){c.style.display='none'}
		}else{
			var n=h+((t-h)*.5); n=t?Math.ceil(n):Math.floor(n); var o=n/c.mh; c.style.height=n+'px';
			c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'
		}
	};
	return{menu:menu}
}();

TINY.style=function(){
	return{
		value:function(e,p){
			return e.currentStyle?e.currentStyle[p]:document.defaultView.getComputedStyle(e,null).getPropertyValue(p)
		}
	}
}();


/* Modified Dialog Boxes from www.leigeber.com */

/* Modified Dialog Boxes from www.leigeber.com */

// global variables //
var TIMER = 1;
var SPEED = 99;
var WRAPPER = 'container';

// calculate the current window width //
function pageWidth() {
  return window.top.innerWidth != null ? window.top.innerWidth : window.top.document.documentElement && window.top.document.documentElement.clientWidth ? window.top.document.documentElement.clientWidth : window.top.document.body != null ? window.top.document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.top.innerHeight != null? window.top.innerHeight : window.top.document.documentElement && window.top.document.documentElement.clientHeight ? window.top.document.documentElement.clientHeight : window.top.document.body != null? window.top.document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.top.pageYOffset != 'undefined' ? window.pageYOffset : window.top.document.documentElement && window.top.document.documentElement.scrollTop ? window.top.document.documentElement.scrollTop : window.top.document.body.scrollTop ? window.top.document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.top.pageXOffset != 'undefined' ? window.top.pageXOffset : window.top.document.documentElement && window.top.document.documentElement.scrollLeft ? window.top.document.documentElement.scrollLeft : window.top.document.body.scrollLeft ? window.top.document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!window.top.document.getElementById('dialog')) {
    dialog = window.top.document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = window.top.document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = window.top.document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = window.top.document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = window.top.document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = window.top.document.createElement('div');
    dialogmask.id = 'dialog-mask';
    window.top.document.body.appendChild(dialogmask);
    window.top.document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);;
    dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
  } else {
    dialog = window.top.document.getElementById('dialog');
    dialogheader = window.top.document.getElementById('dialog-header');
    dialogtitle = window.top.document.getElementById('dialog-title');
    dialogclose = window.top.document.getElementById('dialog-close');
    dialogcontent = window.top.document.getElementById('dialog-content');
    dialogmask = window.top.document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  var content = window.top.document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) {
    dialogclose.style.visibility = "visible";
    window.setTimeout("hideDialog()", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
}

// hide the dialog box //
function hideDialog() {
  var dialog = window.top.document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

function showDialog_refresh(title,message,type,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  if(!window.top.document.getElementById('dialog')) {
    dialog = window.top.document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = window.top.document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = window.top.document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = window.top.document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = window.top.document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = window.top.document.createElement('div');
    dialogmask.id = 'dialog-mask';
    window.top.document.body.appendChild(dialogmask);
    window.top.document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);;
    dialogclose.setAttribute('onclick','refreshPage()');
    dialogclose.onclick = refreshPage;
  } else {
    dialog = window.top.document.getElementById('dialog');
    dialogheader = window.top.document.getElementById('dialog-header');
    dialogtitle = window.top.document.getElementById('dialog-title');
    dialogclose = window.top.document.getElementById('dialog-close');
    dialogcontent = window.top.document.getElementById('dialog-content');
    dialogmask = window.top.document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 3) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  var content = window.top.document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) {
    //dialogclose.style.visibility = "hidden";
    window.setTimeout("refreshPage()", (autohide * 1000));
  } else {
    dialogclose.style.visibility = "visible";
  }
}

// hide the dialog box //
function refreshPage() {
  window.top.document.getElementById('dialog-mask').style.visibility = "visible";
  window.top.location = window.top.location;
  window.top.document.getElementById('dialog-mask').style.visibility = "visible";
}


// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = window.top.document.getElementById('dialog');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    window.top.document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
  }
}

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.table=function(){
	function sorter(n){this.n=n; this.pagesize=100; this.paginate=0}
	sorter.prototype.init=function(e,f){
		var t=ge(e), i=0; this.e=e; this.l=t.r.length; t.a=[];
		t.h=T$$('thead',T$(e))[0].rows[0]; t.w=t.h.cells.length;
		for(i;i<t.w;i++){
			var c=t.h.cells[i];
			if(c.className!='nosort'){
				c.className=this.head; c.onclick=new Function(this.n+'.wk(this.cellIndex)')
			}
		}
		for(i=0;i<this.l;i++){t.a[i]={}}
		if(f!=null){var a=new Function(this.n+'.wk('+f+')'); a()}
		if(this.paginate){this.g=1; this.pages()}
	};
	sorter.prototype.wk=function(y){
		var t=ge(this.e), x=t.h.cells[y], i=0;
		for(i;i<this.l;i++){
      t.a[i].o=i; var v=t.r[i].cells[y]; t.r[i].style.display='';
      while(v.hasChildNodes()){v=v.firstChild}
      t.a[i].v=v.nodeValue?v.nodeValue:''
    }
		for(i=0;i<t.w;i++){var c=t.h.cells[i]; if(c.className!='nosort'){c.className=this.head}}
		if(t.p==y){t.a.reverse(); x.className=t.d?this.asc:this.desc; t.d=t.d?0:1}
		else{t.p=y; t.a.sort(cp); t.d=0; x.className=this.asc}
		var n=document.createElement('tbody');
		for(i=0;i<this.l;i++){
			var r=t.r[t.a[i].o].cloneNode(true); n.appendChild(r);
			r.className=i%2==0?this.even:this.odd; var cells=T$$('td',r);
			for(var z=0;z<t.w;z++){cells[z].className=y==z?i%2==0?this.evensel:this.oddsel:''}
		}
		t.replaceChild(n,t.b); if(this.paginate){this.size(this.pagesize)}
	};
	sorter.prototype.page=function(s){
		var t=ge(this.e), i=0, l=s+parseInt(this.pagesize);
		if(this.currentid&&this.limitid){T$(this.currentid).innerHTML=this.g}
		for(i;i<this.l;i++){t.r[i].style.display=i>=s&&i<l?'':'none'}
	};
	sorter.prototype.move=function(d,m){
		var s=d==1?(m?this.d:this.g+1):(m?1:this.g-1);
		if(s<=this.d&&s>0){this.g=s; this.page((s-1)*this.pagesize)}
	};
	sorter.prototype.size=function(s){
		this.pagesize=s; this.g=1; this.pages(); this.page(0);
		if(this.currentid&&this.limitid){T$(this.limitid).innerHTML=this.d}
	};
	sorter.prototype.pages=function(){this.d=Math.ceil(this.l/this.pagesize)};
	function ge(e){var t=T$(e); t.b=T$$('tbody',t)[0]; t.r=t.b.rows; return t};
	function cp(f,c){
		var g,h; f=g=f.v.toLowerCase(), c=h=c.v.toLowerCase();
		var i=parseFloat(f.replace(/(\$|\,)/g,'')), n=parseFloat(c.replace(/(\$|\,)/g,''));
		if(!isNaN(i)&&!isNaN(n)){g=i,h=n}
		i=Date.parse(f); n=Date.parse(c);
		if(!isNaN(i)&&!isNaN(n)){g=i; h=n}
		return g>h?1:(g<h?-1:0)
	};
	return{sorter:sorter}
}();