function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function colored(theRow,theColor,theRowNum){
	var theCells = null;
	if (typeof(document.getElementsByTagName) != 'undefined') {theCells = theRow.getElementsByTagName('td');}
	else if (typeof(theRow.cells) != 'undefined') {theCells = theRow.cells;}
	else {return false;}
	var rowCellsCnt  = theCells.length;
	for (c = 0; c < rowCellsCnt; c++) {theCells[c].style.backgroundColor = theColor;}
}

function sel(t){
try{
b=document.body.createTextRange();
b.moveToElementText(t);
b.select();	
} catch(e) {}
}

function chbg(t,f){
if (f==1){
t.style.background='#FFFFFF';
}
else {
t.style.background='#EFEFEF';	
}
}

function hideshow(fr,fl,id,flag){
      if (fr==''){fr='setup';}
      var f = eval('document.'+fr+'.'+fl);
      var d; var d1;
      try {d = eval('document.all.'+id); n = eval('document.ids.'+id);} catch(e) {}
      if ((!flag && f.checked==true) || (flag && f.checked==false)){
            try {d.style.display="";n.display="";} catch(e) {}
      }
      else {
            try {d.style.display="none";n.display="none";} catch(e) {}
      }
}

function hs(id) {
	var e=document.getElementById(id).style;	
	if(e.display=='none') e.display=''; else e.display='none';
}

// Layer Menu
var all_menus=[];
var have_active='';
var donothide=false;

function allmenus_hide(e) {
	if (e && e.button && e.button != 1 && e.type == 'click')
	{
		return;
	}
	if(have_active && !donothide) {
		for(var i=0;i<all_menus.length;i++) hide_menu(all_menus[i]);
		have_active='';
		}
	donothide=false;
	return;
}

if (window.attachEvent)
{
	document.attachEvent('onclick', allmenus_hide);
	window.attachEvent('onresize', allmenus_hide);
}
else if (document.addEventListener)
{
	document.addEventListener('click', allmenus_hide, false);
	window.addEventListener('resize', allmenus_hide, false);
}
else
{
	window.onclick = allmenus_hide;
	window.onresize = allmenus_hide;
}

function fetch_offset(obj)
{
	if(!obj) return { 'left' : 0, 'top' : 0 };
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;

	while ((obj = obj.offsetParent) != null)
	{
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}

	return { 'left' : left_offset, 'top' : top_offset };
};
function init_menu(id) {
	var obj=document.getElementById(id);
	if(!obj) return;
	obj.style.display = 'none';
	obj.onclick = function() {donothide=true;};
	var i;
	for(i=0;i<all_menus.length;i++) 
		if(all_menus[i]==id) break;
	if(i>=all_menus.length) all_menus[all_menus.length]=id;
	}

 function show_menu(id) {
	if(have_active==id) {hide_menu(id);return;}
	allmenus_hide();
	var obj=document.getElementById(id);
	if(!obj) return;
	var pos=fetch_offset(obj.parentNode);
	obj.style.left = pos['left'] + 'px';
	obj.style.top = (pos['top']+obj.parentNode.offsetHeight+3) + 'px';
	var ww=document.body && document.body.clientWidth>0 ? document.body.clientWidth : window.innerWidth-window.pageXOffset;
	obj.style.display = '';
	obj.style.visibility = 'visible';
	try { if (pos['left'] + obj.offsetWidth > ww-5) {
		pos['left'] = ww - obj.offsetWidth-5;
		obj.style.left = pos['left'] + 'px';
		}
	} catch(e) {}
		
	setTimeout("have_active='"+id+"';",100);
}

function hide_menu(id) {
	var obj=document.getElementById(id);
	if(!obj) return;
	obj.style.display = 'none';
	obj.style.visibility = 'hidden';
	have_active='';
}

function output_thelp(code) {
        var rr=/^((#[0-9a-fA-F]+):)?([^ {}]+)$/;
        var res='';
        var off=0,poff=0;
        var i,i2,r;
        while((i=code.indexOf('{{',off))>=0) {
            i2=code.indexOf('}}',i+3);
            r=code.substring(i+2,i2).match(rr);
            if(i2-i>40 || !r) {off=i+2;continue;}
            res+=code.substring(poff,i);
            res+='<input readonly style="'+(r[2] && r[2].length>0?'color:'+r[2]+';':'')+'font-family:\'courier new\';text-align:center;background: #E8FFFF;border:0" onmouseover="this.style.background=\'#C0C0C0\'" onmouseout="this.style.background=\'#E8FFFF\'" onclick="this.select()" class="chlp" value="'+r[3]+'" size="'+(r[3].length)+'">';
            off=poff=i2+2;
            }
        if(poff<code.length){res+=code.substring(poff,code.length);}
        document.write(res);
}
