/*******************************************************************************\
|	Name:		Window handler													|
|	Filename:	window.js														|
|	Version:	2.0.0															|		
|	Author:		Eric van Blokland												|	
|	Project:	Shared library													|
|	Summary:	Javascript support for window classes (window.php)				|
|																				|
\*******************************************************************************/

var wnd_winW;
var wnd_winH;
var wnd_step;
var wnd_act_id;
var wnd_cxt_id=Array();
var wnd_top;
var wnd_clientx;
var wnd_clienty;

var wnd_context_menus=Array();

function wnd_property_listview(id,template,column,item,subitem)	{
	this.id=id;
	this.column=column;
	this.item=item;
	this.subitem=subitem;
	this.template=template;	
	this.container=document.getElementById(this.id+"_container");
	this.columns=Array();
	this.items=Array();
	this.oncontextmenu=null;	
	this.add_column=function(newcolumn) {
		this.columns.push(newcolumn);
	}	
	this.add_item=function(newitem) {
		newitem.parent=this;
		this.items.push(newitem);
	}	
	this.parse=function() {
		columns='';
		items='';
		for(i=0;i<this.columns.length;i++)	{
			columns=columns+this.column.replace(/\[BUTTON\]/,'<DIV ID="'+this.columns[i].id+'_container"></DIV>');
		}		
		for(i=0;i<this.items.length;i++)	{						
			items=items+this.items[i].parse(this.item,this.subitem);						
		}		
		this.container.innerHTML=this.template.replace(/\[COLUMNS\]/,columns).replace(/\[ITEMS\]/,items).replace(/\[ONCONTEXTMENU\]/,this.oncontextmenu).replace(/\[COUNT_COLUMNS\]/,this.columns.length);		
		for(i=0;i<this.columns.length;i++)	{
			this.columns[i].parse();
		}
	}
}

function wnd_property_listview_item(id,text,image,subitems,action,onmouseover,onmouseout)	{
	this.id=id;
	this.text=text;
	this.image=image;
	this.subitems=subitems;	
	this.action=action;	
	this.oncontextmenu='';
	this.onmouseover=onmouseover;
	this.onmouseout=onmouseout;
	this.parent=null;
	this.parse=function(item,subitem)	{
		subitems='';
		for(a=0;a<this.subitems.length;a++)	{
			align='left';
			if(this.parent && this.parent.columns[a+1])
				align=this.parent.columns[a+1].align;
			subitems=subitems+subitem.replace(/\[TEXT\]/,this.subitems[a]).replace(/\[ALIGN\]/,align);
		}				
		align='left';		
		if(this.parent && this.parent.columns[0])
			align=this.parent.columns[0].align;		
		return item.replace(/\[IMAGE\]/,(this.image? '<IMAGE ALIGN="left" SRC="'+this.image+'">' : '' )).replace(/\[TEXT\]/,this.text).replace(/\[SUBITEMS\]/,subitems).replace(/\[ACTION\]/,this.action).replace(/\[ONCONTEXTMENU\]/,this.oncontextmenu).replace(/\[ALIGN\]/,align).replace(/\[ONMOUSEOVER\]/,this.onmouseover).replace(/\[ONMOUSEOUT\]/,this.onmouseout);
	}
}

function wnd_property_listview_column(id,button_template_up,button_template_down,caption,image,align,direction) {
	this.id=id;
	this.button_template_up=button_template_up;
	this.button_template_down=button_template_down;
	this.caption=caption;
	this.image=image;
	this.button=null;
	this.align=align;
	this.direction=direction;
	this.parse=function()	{
		if(!this.button)	{
			//object=document.getElementById(this.id+'_object');
			//alert(object);			
			direction=this.direction;			
			if(!direction)
				direction='ASC';			
			else if(direction=='ASC') {
				this.image='images/listview_asc.gif';
				direction='DESC';
			}
			else if(direction=='DESC') {
				this.image='images/listview_desc.gif';
				direction='ASC'
			}
			image='';
			if(this.image)
				image='<IMG SRC="'+this.image+'">';			
			strLocation=window.location.href;			
			if(strLocation.indexOf('&direction=')>0)	{
				strLocation=strLocation.replace(/\&order_by\=[\w]+?\&direction\=[\w]+/,'&order_by='+this.id+'&direction='+direction );
			} else  {
				strLocation=strLocation+'&order_by='+this.id+'&direction='+direction;
			}
			this.button=new wnd_property_button(this.id,this.button_template_up.replace(/\[IMAGE\]/,image),this.button_template_down.replace(/\[IMAGE\]/,image),null,"window.location.href='"+strLocation +"';return false;",true,this.caption)			
			eval(this.id+'_object=this.button;');
		}
	}
}

function wnd_property_button(id,template_up,template_down,checked,action,enabled,value)	{		
	this.id=id+'_object';
	this.input=document.getElementById(id+'_input');
	this.container=document.getElementById(id+'_container');
	this.action=action;	
	this.value=value;
	this.template_up='<DIV onmousedown="'+this.id+'.onmousedown();" onmouseup="'+this.id+'.onmouseup();if('+this.id+'.enabled==false) {return false; };'+this.action.replace(/\[BUTTON_OBJECT_ID\]/g,this.id)+'" onmouseout="'+this.id+'.onmouseout();">'+template_up+'</DIV>';
	this.template_down='<DIV  onmousedown="'+this.id+'.onmousedown();" onmouseup="'+this.id+'.onmouseup();if('+this.id+'.enabled==false) { return false; }'+this.action.replace(/\[BUTTON_OBJECT_ID\]/g,this.id)+'" onmouseout="'+this.id+'.onmouseout();">'+template_down+'</DIV>';
	this.checked=checked;
	this.enabled=enabled;	
	this.down=false;	
	this.onmousedown=function()	{	
		this.down=true;
		if(this.enabled==true) 
			this.container.innerHTML=this.template_down.replace(/\[VALUE\]/g,this.value);
	}
	this.onmouseup=function(){		
		this.down=false;
		if(this.enabled==true)	{
			//eval(this.action);
			if(this.checked===true)
				this.checked=false;
			else if (this.checked===false)
				this.checked=true;
			if(this.input)
				this.input.value=(this.checked ? 1 : 0);
		}
		this.apply();
		
	}
	this.onmouseout=function()	{
		if(this.down==true) {
			this.apply();
			this.down=false;
		}
	}
	this.apply=function()	{			
		//alert(this.enabled);
		if(this.enabled==true)
			this.button_enabled='';
		else 
			this.button_enabled='DISABLED';		 
		if(this.checked==true)	{
			this.container.innerHTML=this.template_down.replace(/\[ENABLED\]/g,this.button_enabled).replace(/\[VALUE\]/g,this.value);
		} else {
			this.container.innerHTML=this.template_up.replace(/\[ENABLED\]/g,this.button_enabled).replace(/\[VALUE\]/g,this.value);
		}
	}	
	this.apply();
}

function wnd_register_context_menu(menu)	{
	wnd_context_menus.push(menu);
}
function wnd_parse_context_menu()	{
	for(i=0;i<wnd_context_menus.length;i++)	{
		wnd_context_menus[i].parse();
	}
}

function wnd_context_menu(name,template) {
	this.items=Array();
	this.parent=this;
	this.name=name;
	this.height=0;
	this.width=0;
	this.template=template;
	this.container=window.document.createElement('DIV');		
	this.container.id=this.name;
	this.container.style.position='absolute';
	this.container.style.visibility='hidden';			
	this.container.style.zIndex=0;
	//this.container.style.filter='alpha(opacity:100);';	
		
	this.structure_id=1;		
	this.add_item=function(item)	{
		item.parent=this;
		this.items.push(item);
	}	
	this.open=function(submenu)	{		
		this.parse();			
		clearInterval(this.interval);
		//if(submenu)
			//this.container.onmouseleave=wnd_context_close;		
		this.container.onmousemove=wnd_context_close;
		wnd_context_open(this.container.id,submenu,this.parent.container);
	}
	this.capture=function(submenu)	{		
		return;
		this.parse();
		clearInterval(this.interval);
		//if(submenu)
			//this.container.onmouseleave=wnd_context_close;
		this.container.onmousemove=wnd_context_close;
		wnd_context_capture(this.container.id,this.parent.container);
	}
	this.close=function()	{
	}
	this.validate=function(){
		
	}
	this.parse=function()	{
		if(window.document.readyState=="complete")	{			
			this.validate();			
			if(!window.document.getElementById(this.container.id)) {				
				window.document.body.insertAdjacentElement('beforeEnd',this.container);	
			}
			content='';
			this.height=0;
			for(i=0;i<this.items.length;i++)	{
				content=content+this.items[i].parse();
				if(this.items[i].visible===true)
					this.height=this.height+this.items[i].height;
			}
			this.container.style.height=this.height;
			this.container.style.width=this.width;
			this.container.innerHTML=window.document.getElementById(this.template).innerHTML.replace('[ITEMS]',content);
			window.document.body.attachEvent('onmouseup',wnd_context_close);
			return true;
		}
	}
}

function wnd_context_menu_item(template,caption,image,href,target,onclick,description,enabled,grayed,visible) {
	this.submenu=null;
	this.template=template;
	this.caption=caption;
	this.image=image;
	this.onmouseover="";
	this.onmousemove="";
	this.onmouseout="";
	this.onmousedown="";
	if(grayed==true) {		
		enabled=false;	
	}
	this.enabled=enabled;	
	this.grayed=grayed;
	this.visible=visible;
	this.target=target;
	this.onclick=onclick;
	this.description=description;
	this.href=href;	
	this.parent=null;
	this.checked=null;
	this.parse=function()	{
		if(this.submenu)
			this.submenu.parent=this.parent;
		if(this.visible===true)	{
			content=window.document.getElementById(this.template).innerHTML;
			content=content.replace(/\[CAPTION\]/g,'<DIV '+(this.grayed==true? 'STYLE="position:absolute;Filter:alpha(Opacity=30);"' : '')+'>'+this.caption+'</DIV>');		
			if(this.checked===null)	{
				if(this.image)
					content=content.replace(/\[IMAGE\]/g,'<IMG '+(this.grayed==true? 'STYLE="Filter:Gray;Filter:alpha(Opacity=30);"' : '')+' BORDER="0" SRC="'+this.image+'" ALIGN="left">');				
				else
					content=content.replace(/\[IMAGE\]/g,'');	
			}
			else	{				
				content=content.replace(/\[IMAGE\]/g,(this.checked ? '<IMG BORDER="0" SRC="images/cxt_checked.gif" ALIGN="left">' : '<IMG BORDER="0" SRC="images/cxt_unchecked.gif" ALIGN="left">'));
			}
			content=content.replace(/\[onclick\]/g,(!this.enabled? '' :'"wnd_context_close(\'\',true);'+this.onclick+'"'));		
			content=content.replace(/\[HREF\]/g,(this.href && this.enabled ? 'HREF="'+this.href+'"': ''));					

			content=content.replace(/\[ENABLED\]/g,(this.enabled? '' : 'DISABLED'));
			/*
			if(this.grayed==false)
				content=content.replace(/\[STYLE\]/g,'');
			else
				content=content.replace(/\[STYLE\]/g,'filter: alpha(opacity:50);background-color:#FFFFFF;');
			*/
			content=content.replace(/\[TARGET\]/g,'"'+this.target+'"');					
			content=content.replace(/\[SUBMENU\]/g,(this.submenu!=null ? '<IMG BORDER="0" SRC="images/wnd_cxt_sub.gif">' : ''));					
			content=content.replace(/\[onmousedown\]/g,(!this.enabled? '' :'"'+this.onmousedown+'"'));
			content=content.replace(/\[ONMOUSEOVER\]/g,'"wnd_set_xy(event);'+(this.submenu!=null ? (this.submenu.container ? 'if(!'+this.submenu.container.id+'.id || '+ this.submenu.container.id+'.style.visibility!=\'visible\')':'') + this.submenu.name +'.interval=setInterval(\''+ this.submenu.name+'.open(true);\',1000);' :'')+this.onmouseover+'"');
			content=content.replace(/\[ONMOUSEMOVE\]/g,'"window.status=\''+this.description+'\';wnd_set_xy(event);'+this.onmousemove+'"');
			content=content.replace(/\[ONMOUSEOUT\]/g,'"window.status=\'\';'+(this.submenu!=null ? 'clearInterval('+this.submenu.name+'.interval);':'')+this.onmouseout+'"');					
		}
		else
			content='';
		return content;
	}
}

function wnd_set_xy(event)	{
	wnd_clientx=event.clientX;
	wnd_clienty=event.clientY;
}

function wnd_adialog(href)	{
	return openChild(href,null,480,160,true,true);
}

function wnd_handler_env()	{
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			wnd_winW = window.innerWidth;
			wnd_winH = window.innerHeight;
		}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
			wnd_winW = document.body.offsetWidth+window.document.body.scrollLeft;
			wnd_winH = document.body.offsetHeight+window.document.body.scrollTop;
		}
		else{			
			wnd_winW = window.innerWidth;
			wnd_winH = window.innerHeight;			
		}
	}
}
function wnd_handler_setup()
{
	wnd_handler_env();
	wnd_top=0;	
}

function wnd_context_capture(wnd_id,submenu)	{			
	if (navigator.appName == 'Netscape' && e.which == 3) {
		wnd_context_open(wnd_id,submenu);
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {		
		//wnd_context_open(wnd_id);
		return false;
	}
	else 
		return true;
}

function wnd_context_close(wnd_id,clear_all)	{		
	if(wnd_cxt_id.length==0)
		return;		
	if(clear_all || (wnd_id && wnd_id.srcElement))	{		
		index=0;		
		while(wnd_id=wnd_cxt_id[index++] )	{
			wnd_handler_close(wnd_id);
		}
		wnd_cxt_id=Array();
		return
	}
	else if(!wnd_id) {
		if(this) {			
			index=wnd_cxt_id.length-1;					
			while(this.id!=wnd_cxt_id[index--] )	{				
				wnd_id=wnd_cxt_id.pop();
				wnd_handler_close(wnd_id);				
			}
			return;			
		}			
		wnd_id=wnd_cxt_id.pop();
	}
	if(wnd_id) {		
		wnd_handler_close(wnd_id);
	}

}

function wnd_context_open(wnd_id,submenu,srcMenu)	{
	try	
	{			
		test=window.document.getElementById(wnd_id).id;	
		if(!submenu)
			wnd_context_close(null);				
		else{
			index=wnd_cxt_id.length-1;				
			while(srcMenu.id!=wnd_cxt_id[index--] )	{				
				wnd_id=wnd_cxt_id.pop();
				wnd_handler_close(wnd_id);
			}
		}			
		Xmo = window.document.body.scrollLeft+((navigator.appName=="Netscape") ? e.pageX-2 : (event ?event.clientX-2 : wnd_clientx-2 ));
		Ymo = window.document.body.scrollTop+((navigator.appName=="Netscape") ? e.pageY-2 : (event ? event.clientY-2 : wnd_clienty-2));		
										
		wnd_handler_env();
		wnd_top++;
		width = new Number(document.getElementById(wnd_id).style.width.replace(/px/,""))+20;
		height = new Number(document.getElementById(wnd_id).style.height.replace(/px/,""))+20;
		if(width+Xmo>wnd_winW)			
			Xmo=Xmo-(width+Xmo-wnd_winW);
		if(height+Ymo>wnd_winH)			
			Ymo=Ymo-(height+Ymo-wnd_winH)		
		document.getElementById(wnd_id).style.zIndex=wnd_top;		
		document.getElementById(wnd_id).style.visibility="visible";		
		document.getElementById(wnd_id).style.left=Xmo;
		document.getElementById(wnd_id).style.top=Ymo;
		//document.getElementById(wnd_id).filters.alpha.opacity=95;
		if(wnd_act_id)	{
			clearInterval(document['wnd_handler_fade']);
			//document.getElementById(wnd_act_id).filters.alpha.opacity=95;
		}		
		wnd_act_id=wnd_id;
		wnd_cxt_id.push(wnd_id);		
		//document['wnd_handler_fade'] = setInterval('wnd_handler_fadein("'+wnd_id+'")',10);		
		return false;
	}
	catch(e)
	{
		//alert('Can\'t display contextmenu: '+e.description);
	}
}

function wnd_handler_close(wnd_id)	{					
	document.getElementById(wnd_id).style.visibility="hidden";
}

function wnd_handler_open(wnd_id)	{	
	try	
	{								
		test=document.getElementById(wnd_id).id;	
		wnd_handler_env();		
		wnd_top++;
		if(wnd_act_id)	{
			clearInterval(document['wnd_handler_fade']);
			document.getElementById(wnd_act_id).filters.alpha.opacity=90;
		}						
		if(wnd_winW<500){						
			for(i=0;i<document.getElementById(wnd_id).all.length;i++)	{				
				if(document.getElementById(wnd_id).all(i).offsetWidth>=wnd_winW)	{
					document.getElementById(wnd_id).all(i).width=wnd_winW-10;
					document.getElementById(wnd_id).all(i).style.width=wnd_winW-10;
				}
			}
			document.getElementById(wnd_id).style.width=wnd_winW-10;
			document.getElementById(wnd_id).width=wnd_winW-10;
		}
		document.getElementById(wnd_id).style.zIndex=wnd_top;		
		document.getElementById(wnd_id).style.visibility="visible";				
		
		document.getElementById(wnd_id).style.left=wnd_winW/2-document.getElementById(wnd_id).offsetWidth/2 + 'px';
		document.getElementById(wnd_id).style.top=wnd_winH/2-document.getElementById(wnd_id).offsetHeight/2 + 'px';		
		document.getElementById(wnd_id).filters.alpha.opacity=10;				
		wnd_act_id=wnd_id;		
		document['wnd_handler_fade'] = setInterval('wnd_handler_fadein("'+wnd_id+'")',10);				
	}
	catch(e)
	{				
	}	
}

function wnd_handler_fadein(wnd_id)
{	
	clearInterval(document['wnd_handler_fade']);
	document.getElementById(wnd_id).filters.alpha.opacity=document.getElementById(wnd_id).filters.alpha.opacity+20;
	if(document.getElementById(wnd_id).filters.alpha.opacity<=90)			
		document['wnd_handler_fade'] = setInterval('wnd_handler_fadein("'+wnd_id+'")',10);
	else	{	
		wnd_act_id=null;
		document['wnd_handler_fade']=null;
		//alert(document.getElementById(wnd_id).filters.alpha.opacity);
	}
}





<!--
function MM_findObj(n, d) { //v4.01
  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_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01
  //Copyright 1998 Macromedia, Inc. All rights reserved.
  var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers;
  var NS6=(!IE&&document.getElementById), NS=(NS4||NS6); if (!IE && !NS) return false;
  retVal = true; if(IE && event) event.returnValue = true;
  if (MM_dragLayer.arguments.length > 1) {
    curDrag = MM_findObj(objName); if (!curDrag) return false;
    if (!document.allLayers) { document.allLayers = new Array();
      with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
        for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
          with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
      } else {
        if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div"); 
          for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];}
        for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i]; 
    } }
    curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
    curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
    curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
    curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
    curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
    curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex;
    curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft; 
    if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
    curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop; 
    if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
    curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
    curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
    curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
    document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
    if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  } else {
    var theEvent = ((NS)?objName.type:event.type);
    if (theEvent == 'mousedown') {
      var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
      var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
      var maxDragZ=null; document.MM_maxZ = 0;
      for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
        var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex);
        if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
        var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
        if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
          var parentL=0; var parentT=0;
          if (NS6) { parentLayer = aLayer.parentNode;
            while (parentLayer != null && parentLayer.style.position) {             
              parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop);
              parentLayer = parentLayer.parentNode;
          } } else if (IE) { parentLayer = aLayer.parentElement;       
            while (parentLayer != null && parentLayer.style.position) {
              parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
              parentLayer = parentLayer.parentElement; } }
          var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft);
          var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop);
          if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
          var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth);
          var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight);
          if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
              || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
      if (curDrag) {
        document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE);
        curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
        curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
        if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0;
        MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
        document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
        if(curDrag.MM_toFront) {
          eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1');
          if (!curDrag.MM_dropBack) document.MM_maxZ++; }
        retVal = false; if(!NS4&&!NS6) event.returnValue = false;
    } } else if (theEvent == 'mousemove') {
      if (document.MM_curDrag) with (document.MM_curDrag) {
        var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
        var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
        newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
        if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
        if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
        if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
        if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
        MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
        if (NS4) {left = newLeft; top = newTop;}
        else if (NS6){style.left = newLeft; style.top = newTop;}
        else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
        if (MM_dragJS) eval(MM_dragJS);
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mouseup') {
      document.onmousemove = null;
      if (NS) document.releaseEvents(Event.MOUSEMOVE);
      if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
      if (document.MM_curDrag) with (document.MM_curDrag) {
        if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
            (Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+
             Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) {
          if (NS4) {left = MM_targL; top = MM_targT;}
          else if (NS6) {style.left = MM_targL; style.top = MM_targT;}
          else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
          MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
        if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
        if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
        retVal = false; if(!NS) event.returnValue = false; }
      document.MM_curDrag = null;
    }
    if (NS) document.routeEvent(objName);
  } return retVal;
}
//-->

