/*
//
//   Copyright © 2008 SolarWinds.Net, Inc. ipMonitor, the ipMonitor logo,
//   and Watching the Network are registered trademarks of SolarWinds.net, Inc.
//
*/

if( typeof ipmjsversion != "undefined" )
{
 if( (ipmjsversion > 91244) && ((window == window.parent) || ((typeof(window.parent.ipmjsversion) != "undefined") && (window.parent.ipmjsversion <= 91244))) )
 {
 alert( "ipMonitor has detected that your browser cache has old resources that may cause problematic behavior. Please clear your cache before logging in." );
 window.location.replace( "/" );
 }
}


if( !window.IPM ) window.IPM = {};
if( !IPM.dom ) IPM.dom = {};
if( !IPM.ui ) IPM.ui = {};
if( !IPM.pos ) IPM.pos = {};
if( !IPM.evt ) IPM.evt = {};
if( !IPM.form ) IPM.form = {};
if( !IPM.aux ) IPM.aux = {};
if( !IPM.caches ) IPM.caches = {};
if( !IPM.nv ) IPM.nv = {};
if( !IPM.anim_bases ) IPM.anim_bases = {};
if( !IPM.hit_bases ) IPM.hit_bases = {};
if( !IPM.hit_loc ) IPM.hit_loc = {};

IPM.is = IPM.is ||
 {
  ie: !!(document.uniqueID),
  ie7: false,
  safari: /Safari/.test( navigator.appVersion ),
  opera: !!window.opera,
  opera9: !!window.opera && !!window.getSelection,
  gecko: /Gecko/.test( navigator.userAgent ) && !/Safari|WebKit/.test( navigator.appVersion ),
  webkit: /KHTML|WebKit/.test( navigator.userAgent )
 };

/*@cc_on
  @if (@_jscript_version >= 5.7)
   IPM.is.ie7 = true;
  @else
   document.execCommand( 'BackgroundImageCache', false, true );
  @end
@*/


Array.prototype.each = function()
{
if( !arguments.length ) return;
var fn = arguments[0];
for( var i = 0, imax = this.length ; i < imax ; ++i ) { arguments[0] = this[i]; fn.apply( this, arguments ); }
arguments[0] = null;
};
Array.prototype.locate = function()
{
if( !arguments.length ) return;
var fn = arguments[0];
for( var i = 0, imax = this.length ; i < imax ; ++i ) { arguments[0] = this[i]; if( fn.apply( this, arguments ) ) { arguments[0] = null; return i; } }
arguments[0] = null;
return -1;
};
IPM.$ = function(domobj)
{
if( domobj && (typeof(domobj)=="string") ) domobj = document.getElementById(domobj);
return domobj;
};
IPM.$$ = function(domobj,tagnames,max)
{
if( domobj && (typeof(domobj)=="string") ) domobj = document.getElementById(domobj);
if( !domobj || !tagnames ) return [];
if( typeof(tagnames)=="string" ) tagnames = tagnames.split("|");
max = max || 0;
if( tagnames.length == 1 && !max ) return domobj.getElementsByTagName(arguments[1]);
var ret = [];
var s = [];
s.push( "^(?:" );
for( var i = 0, imax = tagnames.length; i < imax ; ++i ) { if( i > 0 ) s.push("|"); s.push( tagnames[i] ); }
s.push( ")$" );
var re = new RegExp( s.join(''), "i" );
if( !max ) IPM.dom.walknodes( domobj, function(pos) { if( re.test(pos.tagName) ) ret.push(pos); return true; } );
else IPM.dom.walknodes( domobj, function(pos) { if( re.test(pos.tagName) ) ret.push(pos); return ret.length < max; } );
return ret;
};
IPM.copy = function( src, dest ) { if( !dest ) dest = {}; if( src ) for( var p in src ) { var val = src[p]; dest[p] = val; } return dest; };
IPM.bind = function( obj, fn ) { return function() { return fn.apply( obj, arguments ); }; };
IPM.pass = function()
{
var args = Array.prototype.slice.apply( arguments, [2] );
var obj = arguments[0];
var fn = arguments[1];
return function() { return fn.apply( obj, args ); };
};
IPM.fn_null = function(){return null;};
IPM.fn_true = function(){return true;};
IPM.fn_false = function(){return false;};
IPM.tostr = function(o,depth)
{
depth = (typeof(depth) == "undefined") ? 5 : depth-1;
var src = "";
if( !depth ) return "(depth)";
if( typeof(o) == "undefined" ) src = "undefined";
else if( o == null ) src = "null";
else if( (typeof(o) == "boolean") || (typeof(o) == "number") || (typeof(o) == "function") ) src = ""+o;
else if( typeof(o) == "string" ) src = "'" + o.replace(/([\\'"])/g, "\\$1" ) + "'";
else if( typeof(o) == "object" )
{
if( o.constructor == Boolean ) src = o.valueOf();
else if( o.constructor == Number ) src = o.valueOf();
else if( o.constructor == String ) src = "'" + o.toString().replace(/([\\'"])/g, "\\$1") + "'";
else if( o.constructor == Date ) src = "'" + o.valueOf() + "'";
else if( o.constructor == Array )
{
src = "{";
for( var i=0, imax = o.length; i < imax; i++ ) { if( i ) src = src + ", "; src = src + "" + i + ":" + IPM.tostr( o[i], depth ); }
src += "}";
}
else if( o.constructor == RegExp ) src = "'" + o.toString().replace( /\\/g, "\\\\" ).replace(/([\\'"])/g, "\\$1") + "'"; 
else if( (""+ o.constructor).match( /XMLHttpRequest|XMLDocument|HTML.*Element/ ) ) src = "void('" + o.constructor + "')";
else
{
src = "{";
var first = 1;
for( var key in o ) { if( first ) first = 0; else src += ", "; src = src + "" + key + ":" + IPM.tostr(o[key], depth ); }
src += "}";
}
}
else
{
src = "IPM.tostr error (unexpected type: " + typeof(o) + ")";
}
return src;
};
IPM.dom.newid = function(_s)
{
var _n = IPM._nextuuid || (IPM._nextuuid = 0);
IPM._nextuuid++;
return (_s || "__uuid_") + _n;
};
IPM.dom.up = function(domobj,tagname)
{
if( domobj = IPM.$(domobj) )
{
if( !tagname ) return domobj.parentNode;
for( domobj = domobj.parentNode; domobj && domobj.tagName != tagname ; ) domobj = domobj.parentNode;
}
return domobj;
};
IPM.dom.next = function(domobj)
{
if( domobj = IPM.$(domobj) )
for( domobj = domobj.nextSibling ; domobj && domobj.nodeType != 1 ; ) domobj = domobj.nextSibling;
return domobj;
};
IPM.dom.prev = function(domobj)
{
if( domobj = IPM.$(domobj) )
for( domobj = domobj.previousSibling; domobj && domobj.nodeType != 1 ; ) domobj = domobj.previousSibling;
return domobj;
};
IPM.dom.first = function(domobj)
{
domobj = IPM.$(domobj);
if( domobj )
{
domobj = domobj.firstChild;
if( domobj && (domobj.nodeType != 1) ) domobj = IPM.dom.next(domobj);
}
return domobj;
};
IPM.dom.walknodes = function(o,fn)
{
if( !(IPM.$(o)) || !fn ) return false;
var first = IPM.dom.first;
var next  = IPM.dom.next;
var stack = [];
var ret   = false;
o = first(o);
var pos = o;
var c;
for( ;; )
{
if( !pos )
{
if( !stack.length ) break;
pos = next(stack.pop());
continue;
}
if( !(ret = fn(pos)) ) break;
if( c = first(pos) ) { stack.push(pos); pos = c; }
else pos = next(pos);
}
stack.length = 0;
return ret;
};
IPM.dom.text = function(x)
{
return x.innerText || x.textContent || x.innerHTML.replace( /<br>/gi, "\n" ).replace( /<[^>]+>/g, "" );
};
IPM.dom.sethtml = function(domobj,markup)
{
domobj = IPM.$(domobj);
if( !domobj ) return null;
markup = markup || "";
if(typeof(markup)!="string") markup = markup.join('');
if( IPM.is.ie && /(TD|TR|TBODY|TABLE|THEAD)/.test( domobj.tagName ) )
{
var txts;
if( domobj.tagName == "TABLE" ) txts = ["",""];
else txts = ["<TABLE><" + domobj.tagName + ">","</" + domobj.tagName + "></TABLE>"];
var idiv = document.createElement("DIV");
IPM.setstyle(idiv,"display","none");
document.body.insertBefore( idiv, document.body.firstChild );
idiv.innerHTML = txts[0] + markup + txts[1];
var child = IPM.$$(idiv,domobj.tagName,1)[0];
while( fc = domobj.firstChild ) domobj.removeChild(fc);
if( child ) while( fc = child.firstChild ) domobj.appendChild(fc);
idiv.parentNode.removeChild( idiv );
}
else domobj.innerHTML = markup;
return domobj;
};
IPM.dom.getIndex = function(tag)
{
if( !tag ) return -1;
if( (tag.tagName == "TR") || (tag.tagName == "TD" && !IPM.is.safari) )
{
if( tag.tagName == "TR" ) return tag.sectionRowIndex;
if( tag.tagName == "TD" ) return tag.cellIndex;
}
var idx = 0;
var dom = tag;
while( dom = IPM.dom.prev( dom ) )
if( dom.tagName == tag.tagName ) idx++;
return idx;
};
IPM.pos.info = function(domobj)
{
domobj = IPM.$(domobj);
if( IPM.is.safari && (domobj.tagName == "TR") )
{
var _td = IPM.$$( domobj, "TD", 1 )[0];
var _tbl = IPM.dom.up( domobj, "TABLE" );
var ret = IPM.pos.info( _td );
ret.w = _tbl.offsetWidth;
return ret;
}
var _x = 0;
var _y = 0;
var _w = domobj.offsetWidth;
var _h = domobj.offsetHeight;
var _ol = domobj.style.left || "";
var _ot = domobj.style.top || "";
var _cl = 0;
var _ct = 0;
var _t  = 0;
var _l  = 0;
var _pos = domobj.style.position || "";
_cl = IPM.getstyle(domobj,"left");
_ct = IPM.getstyle(domobj,"top");
if( _cl == "auto" ) _cl = 0;
else _cl = IPM.ui.topx( _cl )[0];
if( _ct == "auto" ) _ct = 0;
else _ct = IPM.ui.topx( _ct )[1];
try{
for( ; domobj.offsetParent ; domobj = domobj.offsetParent )
{
_x += domobj.offsetLeft;
_y += domobj.offsetTop;
if( domobj.scrollLeft ) _x -= domobj.scrollLeft;
if( domobj.scrollTop ) _y -= domobj.scrollTop;
}}catch(err){}
if( /^absolute$/.test( _pos ) ) { _l = _x; _t = _y; }
else { _l = _cl || 0; _t = _ct || 0; }
return { x: _x, y: _y, w: _w, h: _h, left: _ol, top: _ot, cleft: _cl, ctop: _ct, position: _pos, l: _l, t: _t };
};
IPM.pos.cursor = function(e)
{
e = e||window.event;
var ret = { x: 0, y: 0, pgx: IPM.pos.pagex(), pgy: IPM.pos.pagey() };
ret.x = (typeof(e.pageX)!= "undefined") ? e.pageX : (e.clientX + ret.pgx - document.documentElement.clientLeft);
ret.y = (typeof(e.pageY)!= "undefined") ? e.pageY : (e.clientY + ret.pgy - document.documentElement.clientTop);
return ret;
};
IPM.pos.pagex = function()
{
return typeof(window.pageXOffset) != "undefined" ? window.pageXOffset : (document.documentElement.scrollLeft || document.body.scrollLeft);
};
IPM.pos.pagey = function()
{
return typeof(window.pageYOffset) != "undefined" ? window.pageYOffset : (document.documentElement.scrollTop || document.body.scrollTop);
};
IPM.pos.viewh = function(ignorescroll)
{
if( !IPM.is.ie && !IPM.is.gecko ) return window.innerHeight;
var sbar = 0;
var bh = document.body.scrollHeight;
var dh = document.documentElement.scrollHeight;
if( bh && dh && (dh > bh) ) sbar = dh-bh;
if( sbar > 30 || ignorescroll ) sbar = 0;
return document.documentElement.clientHeight - sbar;
};
IPM.pos.vieww = function(ignorescroll)
{
if( !IPM.is.ie && !IPM.is.gecko ) return window.innerWidth;
var sbar = 0;
var bw = document.body.scrollWidth;
var dw = document.documentElement.scrollWidth;
if( bw && dw && (dw > bw) ) sbar = dw-bw;
if( sbar > 30 || ignorescroll ) sbar = 0;
return document.documentElement.clientWidth - sbar;
};
IPM.pos.delta = function(ptr1,ptr2) { return { x: ptr2.x - ptr1.x, y: ptr2.y - ptr1.y }; };
IPM.pos.clip = function(ptr1,bounds)
{
var ret = { x: ptr1.x, y: ptr1.y };
if( ret.x < bounds.x ) ret.x = bounds.x;
if( ret.y < bounds.y ) ret.y = bounds.y;
if( bounds.x && (ret.x > (bounds.x+bounds.w)) ) ret.x = bounds.x+bounds.w;
if( bounds.y && (ret.y > (bounds.y+bounds.h)) ) ret.y = bounds.y+bounds.h;
return ret;
};
IPM.evt.nobubble = function(e) { e = e || window.event; e.cancelBubble = true; if( e.stopPropagation ) e.stopPropagation(); return true; };
IPM.evt.stop = function(e) { e = e || window.event; if( e.preventDefault ) e.preventDefault(); else e.returnValue = false; return false; };
IPM.evt.cancel = function(e) { e = e || window.event; e.cancelBubble = true; if( e.stopPropagation ) e.stopPropagation(); if( e.preventDefault ) e.preventDefault(); else e.returnValue = false; return false; };
IPM.f = IPM.evt.stop;
IPM.aux.writer = function()
{
var o = [];
o.dest  = arguments.length ? arguments[0] : null;
o.write = function() { for( var i=0,imax=arguments.length; i < imax; ++i ) { var a0 = arguments[i]; if( a0 ) o.push( a0 ); } };
o.flush = function(domobj) { var d = IPM.$(o.dest) || IPM.$(domobj); IPM.dom.sethtml(d,o); this.dest = d = null; };
return o;
};
var ipm_false = IPM.evt.stop;
IPM.aux.tojsrx = function(_rxstring)
{
var _match = _rxstring.match( /^(\\[iI])?(.*)/ );
if( !_match ) return null;
var _caseflag = "";
if( _match[1] && _match[1].substr(1,1) == "i" ) _caseflag = "i";
return [ _match[2], _caseflag ]; //.replace( /[\\"']/g, function(s) { return "\\" + s; } )
};
IPM.aux.round = function(_val,_pre)
{
if( typeof(_val) == "string" ) _val = parseFloat(_val);
if( isNaN(_val) ) return 0;
_pre = Math.pow( 10, _pre || 0 );
return Math.round( _val * _pre ) / _pre;
};

if( !window.IPM ) window.IPM = {};
if( !IPM.caches ) IPM.caches = {};
if( !IPM.evt ) IPM.evt = {};
IPM.caches.EVT =
{
_cache: [],
_ondom: [],
_onwin: [],
_onem:  [],
_dominit: false,
_wininit: false,
_emtimer: null,
_eminfo: null,
_winload: function()
{
var c = IPM.caches.EVT;
if( !c._dominit ) c._domload();
if( !c._wininit ) { c._wininit = true; c._onwin.each( function(fn) { fn.apply( this, [] ); } ); }
},
_domload: function()
{
var c = IPM.caches.EVT;
if( !c._dominit ) { c._dominit = true; c._ondom.each( function(fn) { fn.apply( this, [] ); } ); }
},
_emchange: function()
{
var c = IPM.caches.EVT;
if( c._dominit == false ) return;
var info = IPM.ui.getemsize();
if( !c._eminfo || (c._eminfo[0] != info[0] && c._eminfo[1] != info[1]) )
{ 
if( !c._eminfo ) c._eminfo = info;
else { c._eminfo = info; c._onem.each( function(a) { a[0].apply( this, [] ); } ); }
}
},
empty: function() 
{
var c = IPM.caches.EVT;
c._cache.each( function(a) { a[4] = true; IPM.evt.remove.apply( this, a ); } );
c._cache.length = 0;
c._ondom.length = 0;
c._onwin.length = 0;
c._onem.length = 0;
if( c._emtimer != null ) { window.clearInterval( c._emtimer ); c._emtimer = null; }
}
};
IPM.evt.winload = function( fnobj ) { for( var i = 0, imax = arguments.length ; i < imax ; ++i ) IPM.evt.add( null, arguments[i], "winload" ); };
IPM.evt.domload = function( fnobj ) { for( var i = 0, imax = arguments.length ; i < imax ; ++i ) IPM.evt.add( null, arguments[i], "domload" ); };
IPM.evt.add = function( domobj, fnobj, evttxt, capture, regid )
{
var c = IPM.caches.EVT;
if( typeof(fnobj) == "string" ) fnobj = new Function(fnobj);
regid = regid || null;
if( evttxt == "domload" ) { c._ondom.push( fnobj ); return; }
if( evttxt == "winload" ) { c._onwin.push( fnobj ); return; }
if( evttxt == "history" ) { IPM.aux.history.add( fnobj ); return; }
if( evttxt == "emchange" )
{
c._onem.push( [fnobj,regid] );
if( ! c._emtimer )
{
var fn = function() { IPM.caches.EVT._emtimer = window.setInterval( IPM.caches.EVT._emchange, 1000 ); };
if( c._dominit ) fn();
else IPM.evt.domload( fn );
}
return;
}
if( !(domobj = IPM.$(domobj)) ) return;
capture = capture || false;
if( (evttxt == "keypress") && (IPM.is.safari || domobj.attachEvent) ) evttxt = "keydown";
c._cache.push( [domobj, fnobj, evttxt, capture, regid] );
if( domobj.addEventListener ) domobj.addEventListener( evttxt, fnobj, capture );
else if( domobj.attachEvent ) domobj.attachEvent( "on" + evttxt, fnobj );
};
IPM.evt.remove = function( domobj, fnobj, evttxt, capture, noremove )
{
var c = IPM.caches.EVT;
if( !(domobj = IPM.$(domobj)) ) return;
if( evttxt == "history" ) { IPM.aux.history.remove( fn ); return; }
if( evttxt == "emchange" )
{
if( !noremove )
{
var found = false;
var ret = [];
c._onem.each( function(a) { if( a[0] == fnobj ) found = true; else ret.push(a); } );
if( found ) { c._onem.length = 0; c._onem = ret; }
else ret.length = 0;
}
return;
}
capture = capture || false;
if( (evttxt == "keypress") && (IPM.is.safari || domobj.attachEvent) ) evttxt = "keydown";
if( domobj.removeEventListener ) domobj.removeEventListener( evttxt, fnobj, capture );
else if( domobj.attachEvent ) domobj.detachEvent( "on" + evttxt, fnobj );
if( !noremove )
{
var pos = c._cache.locate( function(a){ return (a[0] == domobj) && (a[1] == fnobj) && (a[2] == evttxt) && (a[3] == capture); } );
if( pos >= 0 ) c._cache.splice( pos, 1 );
}
};
IPM.evt.unhook = function( regid )
{
if( regid == null ) return;
var c = IPM.caches.EVT;
var ret = [];
var found = false;
var rm = IPM.evt.remove;
c._cache.each( function(a) { if( a[4] == regid ) { found = a[4] = true; rm.apply( this, a ); } else ret.push(a); } );
if( found ) { c._cache.length = 0; c._cache = ret; ret = []; }
else ret.length = 0;
found = false;
c._onem.each( function(a) { if( a[1] == regid ) found = true; else ret.push(a); } );
if( found ) { c._onem.length = 0; c._onem = ret; }
else ret.length = 0;
};
IPM.caches.SING =
{
dtor: function()
{
var cc = IPM.caches.SING;
for( var n in cc )
{
var v = cc[n];
if( v.dtor ) v.dtor.apply( v, [] );
cc[n] = null;
}
}
};
IPM.caches.clear = function ()
{
IPM.caches.EVT.empty();
var c = IPM.caches;
for( var v in c ) { var obj = c[v]; if( obj && obj.dtor ) obj.dtor.apply( obj, [] ); }
};


(function()
{
 IPM.evt.add( window, IPM.caches.clear, "unload", false );
 if( window.onload ) IPM.caches.EVT._onwin.push( window.onload );
 window.onload = IPM.caches.EVT._winload;

 if( document.addEventListener )
 {
	IPM.evt.add( document, IPM.caches.EVT._domload, "DOMContentLoaded" );
 }

 if( /KHTML|WebKit/i.test( navigator.userAgent ) )
 { 
  var _t = null;
  _t = setInterval( function() { if( /loaded|complete/.test( document.readyState ) ) { clearInterval(_t); IPM.caches.EVT._domload(); } }, 10 );
 }

 /*@cc_on @*/
 /*@if (@_win32)
 if( !document.htmldomloadtrigger )
 {
  var p = "src='javascript:void(0)'";
  if (location.protocol == "https:") p = "src=//0";
  document.write("<scr"+"ipt id=_domloadscript defer " + p + "><\/scr"+"ipt>");
  var s = document.getElementById( "_domloadscript" );
  if(s) s.onreadystatechange = function() { if( this.readyState == "complete" ) { IPM.caches.EVT._domload(); } };
 }
 /*@end @*/
})();

IPM.aux.history =
{
_current: null,
_map: {},
_changefns: [],
update: function(){},
settitle: function(){},
add: function(fn)
{
var c = IPM.aux.history;
if( !c._initd ) { IPM.evt.domload( c._init ); c._initd = true; }
var cc = c._changefns;
var pos = cc.locate( function(p){ return fn == p; } );
if( pos < 0 ) cc.push(fn);
return true;
},
remove: function(fn)
{
var c = IPM.aux.history;
var cc = c._changefns;
var pos = cc.locate( function(p){ return fn == p; } );
if( pos >= 0 ) cc.splice( pos, 1 );
return true;
},
dtor: function()
{
var c = IPM.aux.history;
if( c._timer ) window.clearInterval( c._timer );
c._map = null;
c._changefns = null;
c._timer = null;
}
};
IPM.aux.history._init = function()
{
var c = IPM.aux.history;
c._current = location.hash;
if( IPM.is.ie )
{
{
var domobj = document.createElement("IFRAME");
domobj.id = "__historyiframe__";
domobj.src = "javascript:false;";
document.body.appendChild(domobj);
IPM.setstyles( domobj, [ "position", "absolute", "display", "none", "left", "-10em", "top", "-10em", "width", "1em" ] );
var doc = domobj.contentWindow.document;
doc.open();
doc.close();
if( c._current && c._current != '#' )
{
doc.location.hash = c._current.replace('#', '');
}
}
c.settitle = function(string)
{
var domobj = IPM.$('__historyiframe__');
if( domobj )
{
var doc = domobj.contentWindow.document;
doc.title = string;
document.title = string;
}
};
c.update = function(string)
{
var domobj = IPM.$('__historyiframe__');
if( domobj )
{
c._current = string;
var doc = domobj.contentWindow.document;
doc.open();
doc.close();
doc.location.hash = string.replace('#', '');
location.hash = string.replace('#', '');
}
};
c._watch = function()
{
var domobj = IPM.$('__historyiframe__');
if( domobj )
{
var doc = domobj.contentWindow.document;
var hash = doc.location.hash;
if( doc.readyState != "complete" ) return;
if( hash == '' && !c._ieinit ) return;
if( hash != c._current )
{
c._current = hash;
if( hash && hash != "#" )
{
location.hash = hash;
c._changefns.each( function(fn){ fn( { target: document, hash: hash } ); } );
}
else if( c._ieinit )
{
location.hash = '';
c._changefns.each( function(fn){ fn( { target: document, hash: null } ); } );
}
}
c._ieinit = true;
}
};
}
else if( IPM.is.safari )
{
; // do nothing
}
else
{
c.update = function(string)
{
c._current = string;
location.hash = string.replace('#', '');
};
c.settitle = function(string)
{
document.title = string;
};
c._watch = function()
{
var hash = location.hash;
if( hash )
{
if( c._current != hash )
{ 
c._current = hash;
c._changefns.each( function(fn){ fn( { target: document, hash: hash } ); } );
}
}
else if( c._current )
{
c._current = '';
c._changefns.each( function(fn){ fn( { target: document, hash: null } ); } );
}
};
}
c._timer = window.setInterval( IPM.aux.history._watch, 200 );
};
IPM.caches.SING.history = IPM.aux.history;

IPM.getstyle = function(domobj,name)
{
if( name == "float" )
{
name = (IPM.is.ie || IPM.is.opera) ? 'styleFloat' : 'cssFloat';
}
else if( name == "opacity" && IPM.is.ie )
{
try { return "" + (domobj.filters.item( "DXImageTransform.Microsoft.Alpha" ).opacity / 100); } catch(err) {}
return "1";
}
else if( name == "minWidth" && IPM.is.ie && !IPM.is.ie7 )
{
if( typeof(domobj.minWidth) == "undefined" ) return null;
else return domobj.minWidth;
}
var ret = null;
var view = document.defaultView;
if( view && view.getComputedStyle )
{
var s = view.getComputedStyle( domobj, '' );
try { ret = s[name]; } catch(err) { ret = null; }
}
else if( domobj.currentStyle )
{
ret = domobj.currentStyle[name];
}
return ret || null;
}
IPM.setstyle = function(domobj,name,value)
{
if( !domobj ) return;
var s = domobj.style;
if( name == "float" )
{
name = document.all ? 'styleFloat' : 'cssFloat';
}
else if( name == "opacity" && IPM.is.ie )
{
var val = parseFloat(value);
val = isNaN(val) ? 100 : val * 100;
if( val > 100 ) val = 100;
else if( val < 0 ) val = 0;
var fs = s.filter;
fs = fs ? fs.replace( /alpha\([^\)]*\)/gi, "" ) : "";
fs += " Alpha(opacity="+val+");";
var cs = domobj.currentStyle;
if( !cs || !(cs.hasLayout) ) s['zoom'] = '1';
name = "filter";
value = fs;
}
else if( name == "minWidth" )
{
IPM.ui.setminwidth( domobj, value );
return;
}
s[name] = value;
return domobj;
}
IPM.setstyles = function(domobj,a)
{
var i=0;
var imax = a.length || 0;
var name;
var val;
if( imax % 2 ) --imax;
var s = IPM.setstyle;
while( i < imax )
{
name = a[i++];
val  = a[i++];
s( domobj, name, val );
}
return domobj;
};
IPM.hasclass = function(domobj,name)
{
if( domobj = IPM.$(domobj) )
{
var txt = domobj.className || "";
var ret = [];
if( typeof(txt) != "string" ) return false;
if( txt.split(' ').locate( function(s) { return s == name; } ) >= 0 ) return true;
}
return false;
};
IPM.addclass = function(domobj,name)
{
if( domobj = IPM.$(domobj) )
{
var txt = domobj.className || "";
var ret = [];
var found = false;
txt.split(' ').each( function(s) { if( s == name ) found = true; else if( s ) ret.push(s); } );
if( !found ) { ret.push( name ); domobj.className = ret.join( " " ); }
}
return domobj;
};
IPM.delclass = function(domobj,name)
{
if( domobj = IPM.$(domobj) )
{
var txt = domobj.className || "";
var ret = [];
var found = false;
txt.split(' ').each( function(s) { if( s == name ) found = true; else if( s ) ret.push(s); } );
if( found ) domobj.className = ret.join( " " );
}
return domobj; 
};
IPM.ui.encode = function(t)
{
if( t ) return t.replace( /([<>&])/g, function($1) {  if( $1 == "<" ) return "&lt;"; if( $1 == ">" ) return "&gt;"; return "&amp;"; } );
return "";
};
IPM.ui.encodeattr = function(t)
{
if( t ) return t.replace( /([<>&\'\"])/g, function($1) { if( $1 == "<" ) return "&lt;"; if( $1 == ">" ) return "&gt;"; if( $1 == "\"" ) return "&quot;"; if( $1 == "\'" ) return "&apos;"; return "&amp;"; } );
return "";
};
IPM.ui.decode = function(t)
{
if( t ) return t.replace( /(&gt;|&lt;|&amp;|&quot;)/g, function($1) { switch( $1 ) { case "&gt;": return ">"; case "&lt;": return "<"; case "&amp;": return "&"; case "&quot;": return "\""; default: return $1; } } );
return "";
};
IPM.ui.getemsize = function()
{
var emdiv = IPM.$('__emdiv__');
if( !emdiv )
{
IPM.setstyles( emdiv = document.createElement("DIV"), ["position","absolute","width","10em","height","10em","top","-10em","left","-10em"] );
emdiv.id = "__emdiv__";
document.body.insertBefore( emdiv, document.body.firstChild );
}
return [emdiv.clientHeight/10, emdiv.clientWidth/10];
};
IPM.ui.topx = function(n)
{
if( typeof(n) == "string" )
{
if( (/em$/i).test(n) == false ) { n = parseInt(n); return [n,n]; }
n = parseFloat(n);
}
var s = IPM.ui.getemsize();
return [ n*s[0], n*s[1] ];
};
IPM.ui.toem = function(n)
{
if( typeof(n) == "string" )
{
if( (/em$/i).test(n) ) { n = parseInt(n); return { h: n, w: n }; }
n = parseFloat(n);
}
var s = IPM.ui.getemsize();
return [ n/s[0], n/s[1] ];
};
IPM.ui.setminwidth = function(domobj,width)
{
if( !(domobj = IPM.$(domobj)) ) return;
if( !IPM.is.ie || IPM.is.ie7 ) { domobj.style['minWidth'] = width; return; }
var defd = typeof(domobj.minWidth) != "undefined";
domobj.minWidth = width;
var fn = function(domobj)
{
var width = domobj.minWidth;
if( width == "auto" ) return;
var p = domobj.parentNode;
while( p && /DIV|TD|BODY/.test( p.tagName ) == false ) p = IPM.dom.up(p);
if( !p ) return;
var pwidth = ( p == document.body ) ? IPM.pos.vieww() : IPM.pos.info(p).w;
var ppadl = IPM.getstyle( p, "paddingLeft" );
var ppadr = IPM.getstyle( p, "paddingRight" );
var margl = IPM.getstyle( domobj, "marginLeft" );
var margr = IPM.getstyle( domobj, "marginRight" );
if( margr == "auto" ) margr = "0px";
if( margl == "auto" ) margl = "0px";
ppadl = IPM.ui.topx( ppadl )[1];
ppadr = IPM.ui.topx( ppadr )[1];
margl = IPM.ui.topx( margl )[1];
margr = IPM.ui.topx( margr )[1];
pwidth -= (ppadl+ppadr+margl+margr);
var px = Math.floor( IPM.ui.topx(width)[1] );
if( px > pwidth ) IPM.setstyle( domobj, "width", width );
else IPM.setstyle( domobj, "width", "auto" );
};
fn( domobj );
if( !defd ) IPM.evt.add( window, IPM.pass( domobj, fn, domobj ), "resize" );
};
// -- calc text width
IPM.ui.textwidth = function(_htmlblock,_oncomplete)
{
var _d = document.createElement('DIV');
IPM.setstyles( _d, [ "position", "absolute", "right", "-2px", "width", "1px", "overflow", "scroll", "whiteSpace", "nowrap" ] );
document.body.insertBefore( _d, document.body.firstChild );
IPM.dom.sethtml( _d, _htmlblock );
window.setTimeout( function(){ _oncomplete(_d.scrollWidth ); _d.parentNode.removeChild(_d); }, 10 );
}
// -- blocker / modal
IPM.ui.addblocker = function(zindex)
{
var h = IPM.pos.viewh();
var w = IPM.pos.vieww();
var blocker = IPM.$('__blocker__');
var idiv;
var found = blocker != null;
if( !blocker )
{
IPM.setstyles( blocker = document.createElement("DIV"), ["position","absolute","overflow","hidden"] );
IPM.z.add( blocker, 'blocker' );
blocker.appendChild( idiv = document.createElement("DIV") );
if( IPM.is.ie ) IPM.setstyles( blocker, "zoom", "1" );
}
IPM.setstyles( blocker, ["left",IPM.pos.pagex()+"px","top",IPM.pos.pagey()+"px","backgroundColor","#000","opacity","0.02","display",""] );
IPM.setstyles( idiv, ["width",""+w+"px","height",""+h+"px"] );
if( !found )
{
document.body.insertBefore( IPM.copy( {id: "__blocker__" }, blocker ), document.body.firstChild );
IPM.evt.add(window,IPM.ui.resizeblocker,"resize",false,'__blocker__');
IPM.evt.add(window,IPM.ui.resizeblocker,"scroll",false,'__blocker__');
}
return blocker;
};
IPM.ui.resizeblocker = function()
{
var blocker = IPM.$('__blocker__');
if( !blocker ) return;
var h = IPM.pos.viewh();
var w = IPM.pos.vieww();
var idiv = blocker.firstChild;
IPM.setstyles( blocker, ["left",IPM.pos.pagex()+"px","top",IPM.pos.pagey()+"px"] );
IPM.setstyles( idiv, ["width",""+w+"px","height",""+h+"px"] );
};
IPM.ui.delblocker = function()
{
IPM.evt.unhook('__blocker__');
var blocker = IPM.$('__blocker__');
if( blocker )
{
IPM.z.remove( blocker );
blocker.parentNode.removeChild( IPM.setstyles( blocker, ["width","0px","height","0px","display","none"] ) );
}
};
IPM.ui.ismodal = function()
{
return IPM.$('__modal__') != null;
};
IPM.ui.addmodal = function(parent,killparent)
{
var h = IPM.pos.viewh();
var w = IPM.pos.vieww();
parent = IPM.$(parent);
var zindex = 0;
var zi = IPM.getstyle( parent, "zIndex" );
if( typeof(zi) == "string" ) zi = parseInt(zi);
if( zi ) zindex = zi-1;
if( !zindex ) zindex = IPM.z.get_zindex('fauxwin') - 1;
killparent = parent && parent.id && !!killparent;
var modal = IPM.$('__modal__');
var idiv;
var found = modal != null;
if( !modal )
{
IPM.setstyles( modal = document.createElement("DIV"), ["position","absolute",/*"overflow","hidden",*/"zIndex",""+zindex,"backgroundColor","#000","opacity","0.4"] );
modal.appendChild( idiv = document.createElement("DIV") );
modal.id = "__modal__";
if( IPM.is.ie ) IPM.setstyles( modal, "zoom", "1" );
}
else if( modal.killid )
{
var domobj = IPM.$(modal.killid);
if( domobj ) domobj.parentNode.removeChild( domobj );
}
modal.killid = killparent ? parent.id : null;
IPM.setstyles( modal, ["left",IPM.pos.pagex()+"px","top",IPM.pos.pagey()+"px","display",""] );
IPM.setstyles( idiv, ["width",""+w+"px","height",""+h+"px"] );
if( !found ) document.body.insertBefore( modal, document.body.firstChild );
IPM.evt.unhook('__modal__');
IPM.evt.add(window,IPM.ui.resizemodal,"resize",false,'__modal__');
IPM.evt.add(window,IPM.ui.resizemodal,"scroll",false,'__modal__');
if( parent )
{
IPM.evt.add( document.body, IPM.bind( { rootdiv: parent }, IPM.ui.focusmodal ), IPM.is.ie ? "focusin" : "focus",false,'__modal__');
IPM.evt.add( document.body, IPM.bind( { rootdiv: parent }, IPM.ui.clickmodal ), "click",false,'__modal__');
}
return modal;
};
IPM.ui.resizemodal = function()
{
var modal = IPM.$('__modal__');
if( !modal ) return;
var h = IPM.pos.viewh();
var w = IPM.pos.vieww();
var idiv = modal.firstChild;
IPM.setstyles( modal, ["left",IPM.pos.pagex()+"px","top",IPM.pos.pagey()+"px"] );
IPM.setstyles( idiv, ["width",""+w+"px","height",""+h+"px"] );
};
IPM.ui.delmodal = function()
{
IPM.evt.unhook('__modal__');
var modal = IPM.$('__modal__');
if( modal )
{
if( modal.killid )
{
var domobj = IPM.$(modal.killid);
if( domobj ) domobj.parentNode.removeChild( domobj );
modal.killid = null;
}
modal.parentNode.removeChild( IPM.setstyles( modal, ["width","0px","height","0px","display","none"] ) );
}
};
IPM.ui.focusmodal = function(e)
{
e = e || window.event;
var item = e.target || e.srcElement;
var rootdiv = this.rootdiv;
// is this inside our div?
var tmp = item;
while( tmp && (tmp != rootdiv) ) tmp = tmp.parentNode;
if( tmp != null ) return;
item = IPM.$$(rootdiv,"A|INPUT|SELECT",1)[0];
if( item ) item.focus();
};
IPM.ui.clickmodal = function(e)
{
e = e || window.event;
var item = e.target || e.srcElement;
var rootdiv = this.rootdiv;
// is this inside our div?
var tmp = item;
while( tmp && (tmp != rootdiv) ) tmp = tmp.parentNode;
if( tmp != null ) return;
return IPM.evt.cancel(e);
};
// --- ui single error
IPM.ui.merror_txt = null;
IPM.ui.merror_clear = function() { IPM.ui.merror_txt = ''; IPM.ui.delmodal(); }
IPM.ui.merror_visible = function() { return IPM.$('modalitymsg') != null; }
IPM.ui.merror_set = function( _txt, _refreshjs )
{
IPM.ui.merror_txt = _txt;
if( !_txt )
{
IPM.ui.merror_clear();
return;
}
var modmsg = IPM.$('modalitymsg');
if( !modmsg )
{
modmsg = document.createElement("DIV");
modmsg.id = 'modalitymsg';
IPM.setstyles( modmsg, ["display","none","zIndex","" + IPM.z.get_zindex('cursor')] );
document.body.insertBefore( modmsg, document.body.firstChild );
var w = IPM.aux.writer(modmsg);
w.write( "<div class=warnhdr><span>", IPM.ui.encode(_txt), "</span></div><div class=warntm><input type=button onclick=\"", _refreshjs, "\" class=\"btn fright\" value=\"Refresh...\"><span>", (new Date()).toLocaleString() ,"</span></div>" );
w.flush();
IPM.ui.addmodal( modmsg, true );
IPM.setstyle( modmsg, "display", "" );
}
else
{
var col = IPM.$$( modmsg, "SPAN", 2 );
if( IPM.dom.text( col[0] ) != _txt )
{
IPM.dom.sethtml( col[0], IPM.ui.encode(_txt) );
IPM.dom.sethtml( col[1], (new Date()).toLocaleString() );
}
IPM.$$( modmsg, "INPUT", 1 )[0].onclick = _refreshjs;
}
};
// --- ui busy ability
IPM.caches.BUSY =
{
_cache: [],
_draganim: null,
startbusy: function()
{
var c = IPM.caches.BUSY;
if( c._cache.length < 1 ) return;
var o = c._cache[0];
var body_h = IPM.pos.viewh();
var body_w = IPM.pos.vieww();
var busy = IPM.$('__busy__');
var found = busy != null;
if( !busy )
{
var idiv  = document.createElement("DIV");
var ispan = document.createElement("SPAN");
var iimg  = document.createElement("IMG");
idiv.id = '__busy__';
IPM.copy( { src: "/cfg/v8/orange_eye.gif", border: "0", width: "65", height: "65", className: "ico65" }, iimg );
IPM.setstyles( iimg, ["verticalAlign","middle"] );
idiv.appendChild( iimg );
idiv.appendChild( ispan );
IPM.setstyles( idiv, ["display","none","position","absolute","border","1px solid #aaa","backgroundColor","#fff","opacity",""+o.opacity] );
document.body.insertBefore( idiv, document.body.firstChild );
busy = idiv;
}
var ispan = IPM.$$(busy,"SPAN",1)[0];
if( ispan )
{
while( ispan.firstChild ) ispan.removeChild( ispan.firstChild );
if( o.text ) { IPM.setstyle( ispan, "margin", "0" ); ispan.appendChild( document.createTextNode(o.text) ); }
else IPM.setstyle( ispan, "margin", "0" );
}
var w    = 64;
var h    = 64;
var x    = ((w > body_w) ? 0 : Math.round( (body_w - w) / 2 )) + IPM.pos.pagex();
var y    = ((h > body_h) ? 0 : Math.round( (body_h - h) / 2 )) + IPM.pos.pagey();
IPM.setstyles( busy, ["left",""+x+"px","top",""+y+"px","zIndex",""+IPM.z.get_zindex('top'),"opacity",""+o.opacity,"display",""] );
var is_nodrag = c._draganim && (IPM.drag.animitem() == c._draganim);
var is_follow = is_nodrag && (c._draganim.kind == "busyfollow");
if( !o.nodrag || (!!o.follow != !!is_follow) )
{
c._draganim = null;
if( is_nodrag ) IPM.drag.end();
}
if( o.nodrag && !c._draganim )
{
if( o.follow )
{
c._draganim = IPM.anim_bases.drag.create( { ghost: busy, killghost: false, newcursor: "busy", kind: "busyfollow", hitobj: null } );
IPM.drag.start( { target: busy }, c._draganim, null, { noesc: true, nomup: true } );
}
else
{
c._draganim = IPM.anim_bases.animobj.create( { fps: 0, kind: "busy", hitobj: null } );
IPM.drag.start( { target: busy }, c._draganim, null, { noesc: true, nomup: true } );
}
}
},
endbusy: function(o)
{
o.done = null;
var c = IPM.caches.BUSY;
var pos = c._cache.locate( function(obj) { return o == obj; } );
if( pos < 0 ) return;
if( !pos && (c._cache.length == 1) )
{
var busy = IPM.$('__busy__');
if( busy ) busy.parentNode.removeChild( busy );
if( c._draganim && (IPM.drag.animitem() == c._draganim) )
{
c._draganim = null;
IPM.drag.end();
}
}
c._cache.splice( pos, 1 );
if( !pos && c._cache.length ) c.startbusy();
},
dtor: function()
{
var c = IPM.caches.BUSY;
if( c._draganim && c._draganim.dtor ) c._draganim.dtor.apply( c._draganim, [] );
c._draganim = null;
c._cache.length = 0;
}
};
IPM.ui.addbusy = function(opts)
{
var c   = IPM.caches.BUSY;
var ret = { follow: false, nodrag: true, text: null, opacity: 0.5 };
IPM.copy( opts, ret );
ret.done = function(){IPM.caches.BUSY.endbusy(ret);};
c._cache.push( ret );
if( c._cache.length == 1 )
{
var delay = opts && opts.delay || 0;
if( delay ) window.setTimeout( c.startbusy, delay );
else c.startbusy();
}
return ret;
};
// --- ui indicator ability
IPM.ui.indicator = 
{
oncountdown: null,
onrefresh: null,
duration: 60,
fps: 2,
count: 5,
_isok: true,
_parent: null,
_timerh: null,
_waiting: false,
_f: 0,
_fmax: 0,
_fper: 0,
_items: null,
create: function(domobj,opts)
{
domobj = IPM.$(domobj);
if( !domobj )
{
domobj = document.createElement("DIV");
document.body.appendChild(domobj);
}
var ret = IPM.copy( IPM.ui.indicator, new Object() );
['oncountdown','onrefresh','duration','fps','count'].each( function(s,src,dest) { var v; if( v = src[s] ) dest[s] = v; }, opts, ret );
while( domobj.firstChild ) domobj.removeChild(domobj.firstChild);
ret._parent = domobj;
ret._items = [];
var styles =
[
"float","right",
"border","1px solid #d9971b",
"background","#d9971b url(/cfg/si/corner_icon_bg.png) top left repeat-x",
"verticalAlign","bottom",
"height","0.75em",
"width","0.75em",
"overflow","hidden",
"marginTop","0.14em",
"marginRight","0.5em"
];
for( var i=0, imax=ret.count ; i < imax ; )
{
++i;
var p = domobj;
if( (i == 1) && ret.onrefresh )
{
var a = document.createElement("A");
a.href = "#";
a.title = "Refresh...";
p.appendChild(a);
a.onclick = function(e){ IPM.evt.stop(e); IPM.drag.seed(e); ret.onrefresh(e,ret); };
p = a;
}
d = document.createElement("DIV");
IPM.setstyles( d, styles );
d.appendChild( document.createTextNode("\u00a0") );
p.appendChild(d);
ret._items.push( d );
}
if( opts.clear )
{
var d = document.createElement("DIV");
d.appendChild(document.createComment(""));
IPM.setstyle( d, "clear", "both" );
domobj.appendChild(d);
}
ret.restart.apply( ret, [{waiting:opts.waiting}] );
return ret;
},
restart: function(opts)
{
if( opts )
{
if( opts.fps ) this.fps = opts.fps;
if( opts.duration ) this.duration = opts.duration;
if( typeof(opts.fail) != "undefined" ) this._isok = !opts.fail;
}
var styles = ["backgroundColor",this._isok?"#d9971b":"#ae0000","backgroundPosition","top left","display",""];
this._items.each( IPM.setstyles, styles );
this._f    = 0;
this._fmax = Math.floor( this.duration * this.fps );
this._fper = this.duration * this.fps / this.count;
if( opts && opts.waiting ) { this._waiting = true; this._f = this._fmax; }
else this._waiting = false;
if( this._timerh ) window.clearInterval(this._timerh);
this._timerh = window.setInterval( IPM.bind( this, this.render ), 1000 / this.fps );
this._f--;
this.render();
},
render: function()
{
this._f++;
var blink = (this._f % 2) != 0;
var a = this._items;
var n = Math.floor( this._f / this._fper );
if( n >= a.length ) n = a.length - 1;
var ind = a[a.length-n-1];
var bg = this._isok ? "#f0ba55" : "#ae0000";
var fg = this._isok ? "#313132" : "#f0ba55";
for( ; n ; --n ) IPM.setstyle( a[a.length-n], "display", "none" );
if( this._f >= this._fmax )
{
if( this._waiting == false )
{
if( this.oncountdown )
{
this._waiting = true;
var that = this;
window.setTimeout( function(){that.oncountdown(that);}, 20 );
}
else
{
this.restart.apply( this, [] );
return;
}
this._waiting = true;
}
IPM.setstyles( ind, [ "backgroundColor", blink ? "#37ae30" : bg, "backgroundPosition", blink ? "top left" : "bottom left" ]);
}
else
{
IPM.setstyles( ind, [ "backgroundColor", blink ? fg : bg, "backgroundPosition", blink ? "top left" : "bottom left" ] );
}
},
dtor: function()
{
if( this._timerh ) window.clearInterval( this._timerh );
if( this._items ) { this._items.length = 0; this._items = null; }
if( this._parent ) this._parent = null;
this.oncountdown = null;
this.onrefresh = null;
}
};
// --- ui shadow ability
IPM.caches.SHADOW =
{
_cache: [],
show: function(domobj,id,noabs)
{
domobj = IPM.$(domobj);
if( !domobj ) return;
var c = IPM.caches.SHADOW;
var pos = c._cache.locate( function(o) { return o.id == id; } );
var o;
if( pos < 0 )
{
pos = c._cache.length;
o = { id: id, anchor: domobj };
o.id = id;
o.relative = !!noabs;
c._cache.push(o);
// construct the root div.
o.rootdiv = document.createElement( "DIV" );
IPM.setstyles( o.rootdiv, [ "position", "absolute", "zoom", "1" ] );
if( o.relative ) domobj.parentNode.insertBefore( o.rootdiv, domobj );
else document.body.insertBefore( o.rootdiv, document.body.firstChild );
var ml;
var mr;
var p = o.rootdiv;
var fn = function(p,ml,mt)
{
var nd = document.createElement("DIV");
IPM.setstyles( nd, [ "position", "absolute", "marginLeft", "" + ml + "px", "marginTop", "" + mt + "px", "backgroundColor", "#444", "zoom", "1" ] );
p.appendChild( nd );
IPM.setstyle( nd, "opacity", "0.2" );
return p;
};
if( IPM.is.opera && !IPM.is.opera9 ) fn( p, 2, 2 );
else fn( fn( fn( fn( p, 1, 2 ), 2, 1 ), 2, 3 ), 3, 2 );
if( !pos ) IPM.evt.add( window, c.sync, "emchange" );
}
else
{
o = c._cache[pos];
if( o.relative && (o.parentNode != domobj.parentNode) ) domobj.parentNode.insertBefore( o.rootdiv, domobj );
}
// sync o to the anchor
o.anchor = domobj;
var info = IPM.pos.info( o.anchor );
var divs = IPM.$$( o.rootdiv, "DIV", 10 );
divs.push( o.rootdiv );
divs.each( function(d) { IPM.setstyles( d, [ "width", "" + info.w + "px", "height", "" + info.h + "px", "zIndex", IPM.getstyle( o.anchor, "zIndex" ) - 1 ] ); } );
IPM.setstyles( o.rootdiv, [ "left", "" + ( o.relative ? info.cleft : info.x ) + "px", "top", "" + ( o.relative ? info.ctop : info.y ) + "px", "display", "" ] );
o.visible = true;
},
hide: function(id)
{
var c = IPM.caches.SHADOW;
var pos = c._cache.locate( function(o) { return o.id == id; } );
if( pos >= 0 )
{
var o = c._cache[pos];
IPM.setstyle( o.rootdiv, "display", "none" );
o.visible = false;
}
},
sync: function()
{
// sync o to the anchor
var c = IPM.caches.SHADOW;
c._cache.each( function(o) {
if( o.visible )
{
var info = IPM.pos.info( o.anchor );
var divs = IPM.$$( o.rootdiv, "DIV", 10 );
divs.push( o.rootdiv );
divs.each( function(d) { IPM.setstyles( d, [ "width", "" + info.w + "px", "height", "" + info.h + "px", "zIndex", IPM.getstyle( o.anchor, "zIndex" ) - 1 ] ); } );
IPM.setstyles( o.rootdiv, [ "left", "" + ( o.relative ? info.cleft : info.x ) + "px", "top", "" + ( o.relative ? info.ctop : info.y ) + "px", "display", "" ] );
}
});
},
dtor: function()
{
var c = IPM.caches.SHADOW;
c._cache.each( function(o) { o.anchor = null; o.rootdiv = null; } );
}
};
// --- ui delay hover
IPM.ui.delayhover =
{
delay: 250,
active: null,
_timer: null,
_want: null,
_stuck: false,
create: function(opts) { return IPM.copy( opts, IPM.copy( IPM.ui.delayhover, new Object() ) ); },
show: function(domobj)
{
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
this._want = null;
if( this.active ) { if( this.active == domobj ) return; this.onshow( null ); }
this.active = domobj;
if( this.active ) this.onshow(this.active);
},
keep: function(domobj)
{
if( !domobj )
{
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
this._want = null;
}
else if( this._active == domobj )
{
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
this._want = null;
}
},
leak: function()
{
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
this._want = null;
this.active = null;
},
want: function(domobj)
{
if( this._want == domobj && this._timer ) return;
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
if( (!domobj && this._stuck) || (this.active == domobj) )
{
this._want = null;
return;
}
this._want = domobj;
var that = this;
var want = this._want;
this._timer = window.setTimeout( function() { that.show.apply( that, [want] ); }, this.delay );
},
stick: function()
{
this._stuck = true;
if( this.active )
{
if( this._want ) this._want = null;
if( this._timer ) { window.clearTimeout( this._timer ); this._timer = null; }
}
},
unstick: function() { this._stuck = false; },
onshow: IPM.fn_null,
dtor: function() { if( this._timer ) window.clearTimeout( this._timer ); for( var x in this ) this[x] = null; }
};

IPM.caches.MENU =
{
_cache: [],
_anyvisible: false,
_initd: false,
_init: function()
{
var c = IPM.caches.MENU;
if( c._initd ) return;
c._initd = true;
IPM.evt.add( document, function(e)
{
e = e || window.event;
if( c._anyvisible )
{
var keycode = e.which || e.keyCode;
if( keycode == 27 ) c.show(null);
}
}, "keypress", false );
IPM.evt.add( document, function(e)
{
e = e || window.event;
if( c._anyvisible )
{
var _btn = e.button;
if( IPM.is.ie ) { if( _btn != 1 ) return; }
else if( _btn != 0 ) return; 
var _d = e.target || e.srcElement;
var _isinput = _d.tagName == "INPUT";
if( _d.tagName != "DIV" ) _d = IPM.dom.up(_d,"DIV");
for( var _pos = _d; _pos ; _pos = IPM.dom.up(_pos,"DIV") )
if( IPM.hasclass( _pos, "menu" ) )
{
if( _isinput ) return;
if( IPM.hasclass( _d, "expand" ) )
{
IPM.caches.MENU.show( _d.id.replace( /_link$/, '' ) );
}
return IPM.evt.cancel(e);
}
var cc = IPM.caches.SING;
if( cc.menuhov ) cc.menuhov.leak();
c.show(null);
}
}, "mousedown", false );
},
add: function(o)
{
var c = IPM.caches.MENU;
if( !c.item(o.id) ) c._cache.push(o);
return o;
},
remove: function(_s)
{
var c = IPM.caches.MENU;
var pos = c._cache.locate(function(o){ return o.id == _s; });
var ret = null;
if( pos >= 0 ) { c._cache[pos]; c._cache.splice( pos, 1 ); }
return ret;
},
item: function(_s)
{
var c = IPM.caches.MENU;
var pos = c._cache.locate(function(o){ return o.id == _s; });
if( (pos < 0) && (c._cache.length >= c._cache.length) ) return null;
return c._cache[pos];
},
show: function(_s,_anchor)
{
var c = IPM.caches.MENU;
c._init();
this._anyvisible = false;
var _seen = {};
var _item = c.item(_s);
while( _item )
{
_seen[_item.id] = true;
_item.show(_anchor);
_anchor = null;
_item = _item._parent;
this._anyvisible = true;
}
c._cache.each(function(o){ if( !_seen[o.id] ) o.hide(); });
},
dtor: function()
{
var c = IPM.caches.MENU;
c._cache.each(function(o){ if( o && o.dtor ) o.dtor.apply( o, [] ); });
c._cache.length = 0;
}
};
IPM.ui.menu =
{
id: null,
icon: null,
text: null,
_items: null,
_domobj: null,
_type: null,
_dirty: false,
_icos: false,
_exps: false,
_visible: false,
_parent: null,
_anchor: null,
_depth: 0,
create_menu: function(opts)
{
var _ret = IPM.copy( opts, IPM.copy( IPM.ui.menu, new Object() ) );
if( !_ret.id ) _ret.id = IPM.dom.newid();
_ret._items = [];
_ret._type = "m";
_ret._dirty = true;
return _ret;
},
create_item: function(opts)
{
var _item = IPM.copy(opts);
_item.id = IPM.dom.newid();
_item._type = "i";
return _item;
},
add_div: function()
{
this._items.push( { _type: 'd' } );
this._dirty = true;
return this;
},
add: function(item)
{
var _that = this;
if( item.each ) item.each( function(o){ _that.add(o); } );
else
{
this._items.push(item);
this._dirty = true;
if( item.icon ) this._icos = true;
if( item._type == "m" )
{
item._parent = this;
item._depth = this._depth + 1;
this._exps = true;
IPM.caches.MENU.add( item );
}
}
return this;
},
clear: function()
{
this._items.each( function(o){ if( o.dtor ) o.dtor(); } );
this._items.length = 0;
this._dirty = true;
this._icos = false;
this._exps = false;
return this;
},
item: function(_s)
{
var _pos = this._items.locate(function(o){ return o.id == _s; });
if( _pos < 0 ) return null;
return this._items[_pos];
},
_render: function()
{
if( !this._domobj )
{
var _d = document.createElement('DIV');
_d.id = this.id;
this._domobj = document.body.insertBefore( IPM.addclass( _d, "menu" ), null );
_d.onmouseover = IPM.ui.menu.mouseover;
_d.onclick = IPM.ui.menu.click;
_d.oncontextmenu = function(e){ return IPM.evt.cancel(e); };
IPM.setstyles( this._domobj, [ "display", "none", "position", "absolute", "zIndex", "" + (IPM.z.get_zindex('menu') + this._depth*2) ] );
}
if( this._dirty )
{
var _w = IPM.aux.writer( this._domobj );
var _w2 = IPM.aux.writer();
var enc = IPM.ui.encodeattr;
( this._icos ? IPM.addclass : IPM.delclass )( this._domobj, "menu-imgs" );
( this._exps ? IPM.addclass : IPM.delclass )( this._domobj, "menu-expands" );
var _cn = this._icos ? " class=menu-imgs>" : ">";
if( this.showheader )
{
_w2.write( "<div><b>", enc( this.text ), "</b></div>" );
_w.write( "<div class='header'>", enc(this.text), "</div><div class='divider'><!-- --></div>" );
}
_w2.write( "<div", this._icos ? " class=menu-imgs>" : ">" );
this._items.each(function(o){
if( o._type == 'd' ) { _w.write( "<div class='divider'><!-- --></div>" ); return; }
if( o._type == "m" ) _w.write( "<div id='", o.id, "_link' class='item expand" );
else _w.write( "<div id='", o.id, "' class='item" );
if( o.disabled ) _w.write( " disabled" );
if( o.title ) _w.write( "' title='", enc( o.title ), "'>" );
else _w.write( "'>" );
_w2.write( "<div><b>" );
if( o.icon ) _w.write( "<img class=ico16 style='margin-left: -20px; margin-right: 4px; vertical-align: top;' src='", enc(o.icon), "'>" );
if( o.text )
{
if( !o.ishtml ) { _w.write( "<a href='#' onclick='return false;'>", enc( o.text ), "</a>" ); _w2.write( enc(o.text) ); }
else { var _t = o.render ? o.render.apply( this, [o.text] ) : o.text; _w.write( _t ); _w2.write( _t ); }
}
_w2.write( "</b></div>" );
_w.write( "</div>" );
});
_w2.write( "</div>" );
_w.flush();
this._dirty = false;
var that = this;
IPM.ui.textwidth( _w2.join(''), function(param)
{
IPM.setstyles( that._domobj, [ "width", ( IPM.ui.toem(param)[1] + 2 ) + "em" ] );
IPM.caches.MENU.show( that.id );
} );
return false;
}
return true;
},
anchor: function()
{
var _top = 20;
var _left = 20;
if( this._anchor && !this._anchor.parentNode )
{
_top = this._anchor.y;
_left = this._anchor.x;
}
else if( this._anchor && this._anchor.parentNode )
{
var item = this._anchor;
var pos = IPM.pos.info(item);
_top = pos.y;
_left = pos.x;
if( item.tagName == "TD" ) _top += pos.h;
}
else
{
var item = IPM.$(this.id+"_link");
if( item )
{
var pos = IPM.pos.info(item);
if( item.tagName == "TD" )
{
_top = pos.y + pos.h;
_left = pos.x;
}
else
{
_top = pos.y;
_left = pos.x + pos.w;
}
}
}
{
var _mnusize = IPM.pos.info( this._domobj );
var _viewh   = IPM.pos.viewh() + IPM.pos.pagey();
var _vieww   = IPM.pos.vieww() + IPM.pos.pagex();
if( _mnusize.h + 4 > _viewh ) _top = 0;
else if( (_top + _mnusize.h + 4) > _viewh ) _top = _viewh - 4 - _mnusize.h;
if( _mnusize.w + 4 > _vieww ) _left = 0;
else if( (_left + _mnusize.w + 4) > _vieww ) _left = _vieww - 4 - _mnusize.w;
}
IPM.setstyles( this._domobj, [ "top", "" + _top + "px", "left", "" + _left + "px" ] );
IPM.caches.SHADOW.show( this._domobj, this.id );
},
hide: function()
{
if( !this._domobj || !this._visible ) return;
if( this.onhide ) this.onhide(this);
IPM.setstyle( this._domobj, "display", "none" );
IPM.caches.SHADOW.hide( this.id );
this._visible = false;
},
show: function(_anchor)
{
if( _anchor ) this._anchor = _anchor;
if( this._dirty )
if( ! this._render() ) return;
if( !this._visible )
{
IPM.setstyle( this._domobj, "display", "" );
this._visible = true;
}
this.anchor();
},
mouseover: function(e)
{
e = e || event;
var mnudiv = e.target || e.srcElement;
var mnup = null;
var mnui = null;
var pos;
var up = IPM.dom.up;
if( mnudiv.tagName != "DIV" ) mnudiv = IPM.dom.up(mnudiv,"DIV");
for( pos = mnudiv ; pos ; pos = up(pos,"DIV") )
if( IPM.hasclass( pos, 'menu' ) ) { mnup = pos; break; }
if( !mnup ) return;
for( pos = mnudiv ; pos ; pos = up(pos,"DIV") )
if( IPM.hasclass( pos, 'item' ) ) { mnui = pos; break; }
var c = IPM.caches.SING;
if( !c.menuhov ) c.menuhov = IPM.ui.delayhover.create( { delay: 1000, onshow: function(domobj){ if( domobj ) IPM.caches.MENU.show(domobj); } } );
if( !mnui || !IPM.hasclass( mnui, "expand" ) )
{
c.menuhov.want( mnup.id );
}
else
{
c.menuhov.want( mnui.id.replace( /_link$/, '' ) );
}
},
click: function(e)
{
var c = IPM.caches.MENU;
e = e || window.event;
var _d = e.target || e.srcElement;
if( _d.tagName == "INPUT" ) return IPM.evt.nobubble(e);
if( _d.tagName != "DIV" ) _d = IPM.dom.up(_d,"DIV");
for( var _pos = _d; _pos ; _pos = IPM.dom.up(_pos,"DIV") )
if( IPM.hasclass( _pos, "menu" ) )
{
if( IPM.hasclass( _d, "expand" ) ) c.show( _d.id.replace( /_link$/, '' ) );
else if( _d.id && IPM.hasclass( _d, "item" ) )
{
// locate this item in our list.
var _item = c.item( _pos.id );
if( _item ) _item = _item.item(_d.id);
if( _item && _item.onclick )
{
var cc = IPM.caches.SING;
if( cc.menuhov ) cc.menuhov.leak();
c.show( null );
window.setTimeout( function(){_item.onclick(e);}, 0 );
}
else c.show( _pos.id );
}
break;
}
return IPM.evt.cancel(e);
},
dtor: function()
{
IPM.caches.MENU.remove( this.id );
this.clear();
IPM.caches.SHADOW.hide( this._domobj, this.id );
this._domobj = null;
this._anchor = null;
}
};

IPM.ui.slider =
{
anchor: null,
offset: null,
minx: null,
maxx: null,
midx: null,
midpoint: false,
xadj: 0,
_last: null,
create: function( opts ) { return IPM.copy( opts, IPM.copy( IPM.ui.slider, new Object() ) ); },
start: function( e )
{
if( this.midpoint )
{
var xyc  = IPM.pos.cursor(e);
var xya  = IPM.pos.info(this.anchor);
xya.x += (this.offset ? this.offset.x : 0);
var diff = IPM.pos.delta( xya, xyc );
this.xadj += diff.x;
}
},
end: function() { this.render( this._last == null ? this.midx : this._last, true ); this.dtor(); },
revert: function() { this.render( this.midx, true ); },
render: function(px,fin) { },
movement: function(e,pos)
{
var xyc  = IPM.pos.cursor(e);
var xya  = IPM.pos.info(this.anchor);
xya.x += (this.offset ? this.offset.x : 0);
var diff = IPM.pos.delta( xya, xyc );
var x = diff.x - this.xadj;
if( (this.minx != null) && (this.minx > x) ) x = this.minx;
if( (this.maxx != null) && (this.maxx < x) ) x = this.maxx;
this._last = x;
this.render(this._last,false);
},
dtor: function() { this.anchor = null; }
};
IPM.caches.LAYOUT = 
{
_cache: [],
add: function(o)
{
var c = IPM.caches.LAYOUT;
var pos = c._cache.locate( function(o2){ return o2 == o; } );
if( pos < 0 ) { pos = c._cache.length; _cache.push(o); }
return pos;
},
dtor: function()
{
var c = IPM.caches.LAYOUT;
c._cache.each( function(o){ if( o.dtor ) o.dtor.apply( o, [] ); });
}
};
IPM.ui.layout =
{
barw: 6,
dockw: 24,
borders: { normal: {"8":1,"6":1,"2":1,"4":1}, top: {"8":1} },
imgs:
{
"w-expand": "/cfg/si/expand.gif"
}
};
IPM.ui.layout._tryresize = function(e,root,layout)
{
e = e || window.event;
var cursor = IPM.getstyle( document.body, "cursor" );
IPM.setstyle( document.body, "cursor", "e-resize" );
IPM.ui.addblocker( IPM.z.get_zindex("cursor") );
var _posinfo = IPM.pos.info( e.target || e.srcElement );
e = e || window.event;
IPM.drag.start( e, IPM.ui.slider.create(
{
kind: "resizer",
minx: 0-layout.fixedsize,
maxx: layout.fixedsize > 500 ? layout.fixedsize : 500 - layout.fixedsize,
midx: 0,
xadj: 0,
anchor: e.target || e.srcElement,
render: function(px,fin)
{
var _shadow = IPM.$('__resizebar__');
if( fin )
{
if( _shadow ) { _shadow.parentNode.removeChild( _shadow ); }
IPM.setstyle( document.body, "cursor", cursor );
IPM.ui.delblocker();
var ret = IPM.ui.layout.find( root, layout._domid );
if( (layout.fixedsize + px) < IPM.ui.layout.dockw )
{
if( ret && ret[1].dockable )
{
IPM.ui.layout.hide( layout._domid, root );
return;
}
}
layout.fixedsize += px;
IPM.ui.layout.reflow(root);
if( ret ) ret = ret[1];
if( ret && ret.dockable && ret.onresize ) ret.onresize( layout.fixedsize, layout.isdocked );
}
else
{
var _l = _posinfo.l + px;
if( !_shadow )
{
_shadow = document.createElement('DIV');
_shadow.id = '__resizebar__';
document.body.insertBefore( _shadow, document.body.firstChild );
IPM.setstyles( _shadow, [ "position", "absolute", "opacity", "0.2", "backgroundColor", "#666", "width", "" + _posinfo.w + "px", "height", "" + _posinfo.h + "px", "top", "" + _posinfo.t + "px", "zIndex", "" + IPM.z.get_zindex("cursor") ] );
}
IPM.setstyle( _shadow, "left", "" + _l + "px" );
}
}
} ), e.target || e.srcElement );
IPM.evt.cancel(e);
};
IPM.ui.layout.newV = function( _domid, _childs, opts )
{
var _ret = IPM.copy( opts );
_ret._t = "v";
_ret._domid = _domid;
_ret._childs = _childs;
return _ret;
};
IPM.ui.layout.newH = function( _domid, _childs, opts )
{
var _ret = IPM.copy( opts );
_ret._t = "h";
_ret._domid = _domid;
_ret._childs = _childs;
return _ret;
};
IPM.ui.layout.newPane = function( _domid, opts )
{
var _ret = IPM.copy( opts );
_ret._t = "p";
_ret._domid = _domid;
return _ret;
};
IPM.ui.layout.getPanelHeight = function(_domid)
{
var _domobj = IPM.$(_domid);
var _divs   = IPM.$$(_domobj,"DIV|TABLE",1000);
var _divpos = _divs.locate( function(o) { return IPM.hasclass(o,"panel-end"); } );
var _divend = _divpos >= 0 ? _divs[_divpos] : null;
return _divend ? _divend.offsetTop + _divend.offsetHeight : (_domobj ? _domobj.scrollHeight : 0);
};
IPM.ui.layout.getPanelWidth = function(_domid)
{
var _domobj = IPM.$$( IPM.$(_domid), "TABLE", 1)[0];
return _domobj.clientWidth + _domobj.offsetLeft;
};
IPM.ui.layout.find = function( root, id, parent )
{
if( root._domid && root._domid == id ) return [ root, parent || null ];
if( root._childs )
{
var _all = root._childs;
var o;
var _find = IPM.ui.layout.find;
for( var i=0,imax=_all.length; i < imax; ++i )
if( o = _find( _all[i], id, root ) ) return o;
}
return null;
};
IPM.ui.layout.hide = function( id, layout )
{
var o = IPM.ui.layout.find( layout, id );
if( !o ) return;
var obj = o[0];
var p   = o[1];
IPM.ui.layout._hidechilds(obj);
if( obj._resizehandle ) IPM.setstyle( IPM.$(obj._resizehandle), "display", "none" );
if( p.dockable )
{
obj.isdocked = true;
p.isfloating = false;
if( p.ondock ) p.ondock( obj.fixedsize, obj.isdocked );
}
else obj.ishidden = true;
IPM.ui.layout.reflow(layout);
};
IPM.ui.layout._float = function( root, layout )
{
var pos = layout._childs.locate( function(o){ return !!o.isfixed; } );
if( pos < 0 ) return;
var obj = layout._childs[pos];
if( obj.isdocked && layout.isfloating ) return;
var evt_in = function(e) { var c = IPM.caches.SING._layouthover; if( c ) c.want.apply( c, [layout] ); return IPM.evt.cancel(e); };
var evt_out = function(e) { var c = IPM.caches.SING._layouthover; if( c ) c.want.apply( c, [null] ); return IPM.evt.cancel(e); };
IPM.evt.unhook( layout._dockhandle );
if( layout._childs ) layout._childs.each( function(o){
if( o.isfixed )
IPM.ui.layout._collect( o, function(o2){ return !!o2._domid; } ).each(function(o3){
IPM.evt.add( IPM.$(o3._domid), evt_in, "mouseover", false, layout._dockhandle );
IPM.evt.add( IPM.$(o3._domid), evt_out, "mouseout", false, layout._dockhandle );
});
});
IPM.ui.layout._showchilds(obj);
if( obj._resizehandle ) IPM.setstyle( IPM.$(obj._resizehandle), "display", "none" );
obj.isdocked = true;
layout.isfloating = true;
IPM.ui.layout.reflow(root);
};
IPM.ui.layout._unfloat = function( root, layout )
{
var pos = layout._childs.locate( function(o){ return !!o.isfixed; } );
if( pos < 0 ) return;
IPM.evt.unhook( layout._dockhandle );
var obj = layout._childs[pos];
IPM.ui.layout._hidechilds(obj);
if( obj._resizehandle ) IPM.setstyle( IPM.$(obj._resizehandle), "display", "none" );
obj.isdocked = true;
layout.isfloating = false;
IPM.ui.layout.reflow(root);
};
IPM.ui.layout._dock = function( root, layout )
{
var pos = layout._childs.locate( function(o){ return !!o.isfixed; } );
if( pos < 0 ) return;
var obj = layout._childs[pos];
IPM.ui.layout._showchilds(obj);
if( obj._resizehandle ) IPM.setstyle( IPM.$(obj._resizehandle), "display", "" );
obj.isdocked = false;
layout.isfloating = false;
if( layout.ondock ) layout.ondock( obj.fixedsize, obj.isdocked );
IPM.ui.layout.reflow(root);
};
IPM.ui.layout.show = function( id, layout )
{
var o = IPM.ui.layout.find( layout, id );
if( !o ) return;
var obj = o[0];
var p   = o[1];
IPM.ui.layout._showchilds(obj);
if( obj._resizehandle ) IPM.setstyle( IPM.$(obj._resizehandle), "display", "" );
if( p.dockable )
{
obj.isdocked = false;
if( p.ondock ) p.ondock( obj.fixedsize, obj.isdocked );
}
else obj.ishidden = false;
IPM.ui.layout.reflow(layout);
};
IPM.ui.layout._calc = function(_maxsize,layout)
{
var _nonfix   = 0;
var _fixpx    = 0;
var _isresize = 0;
var _docking  = 0;
var _docked   = 0;
layout._childs.each( function(o) {
if( o.ishidden ) return;
if( layout.dockable )
{
if( o.isfixed )
{
++_docking;
if( o.isdocked ) { ++_docked; return; }
}
}
if( o.isfixed ) _fixpx += o.fixedsize;
else if( o.getsize )
{
var _tmp = o.getsize();
o._contentsize = _tmp;
_fixpx += _tmp;
}
else _nonfix++;
if( o.isresizable ) _isresize++;
} );
if( _docking && _docked ) _fixpx += IPM.ui.layout.dockw;
var _avail = _maxsize-_fixpx;
_avail -= _isresize * IPM.ui.layout.barw;
if( _avail < 0 ) _avail = 0;
return [ _avail, _nonfix ? Math.ceil(_avail/_nonfix) : 0, _docked != 0 ];
};
IPM.ui.layout._reflow_resizer = function(state,root,layout)
{
var _domobj;
if( !layout.isresizable ) return;
if( layout._resizehandle )
{
_domobj = IPM.$(layout._resizehandle);
}
else
{
_domobj = document.createElement("DIV");
_domobj.id = layout._resizehandle = IPM.dom.newid( "__resizeh_" );
_domobj.className = layout._t == "v" ? "placeable resize-v" : "placeable resize-h";
document.body.appendChild( _domobj );
_domobj.onmousedown = function(e) { return IPM.ui.layout._tryresize(e,root,layout); };
}
if( !_domobj ) return;
var _width  = IPM.ui.layout.barw;
var _height = state._h;
if( layout._t == "v" )
{
_width  = IPM.ui.layout.barw;
_height = state._h;
}
else
{
_height = IPM.ui.layout.barw;
_width = state._w;
}
IPM.setstyles( _domobj, [ "top", "" + state._t + "px", "left", "" + state._l + "px", "height", "" + _height + "px", "width", "" + _width + "px" ] );
};
IPM.ui.layout._reflow_dock = function(state,layout,wantdock)
{
var _domobj = IPM.$(layout._dockhandle);
if( !_domobj ) return;
if( !wantdock )
{
IPM.setstyle( _domobj, "display", "none" );
return;
}
IPM.setstyle( _domobj, "display", "" );
var _width  = IPM.ui.layout.dockw;
var _height = state._h;
if( layout._t == "h" )
{
_width  = IPM.ui.layout.dockw;
_height = state._h;
}
else
{
_height = IPM.ui.layout.dockw;
_width = state._w;
}
_height -= 2;
_width -= 3;
if( _height < 0 ) _height = 0;
if( _width < 0 ) _width = 0;
IPM.setstyles( _domobj, [ "top", "" + state._t + "px", "left", "" + state._l + "px", "height", "" + _height + "px", "width", "" + _width + "px" ] );
};
IPM.ui.layout._hidechilds = function(layout)
{
var _fn = IPM.ui.layout._hidechilds;
if( layout._domid ) IPM.setstyle( IPM.$(layout._domid), "display", "none" );
if( layout._childs ) layout._childs.each( function(o) { _fn(o); } );
};
IPM.ui.layout._showchilds = function(layout)
{
var _fn = IPM.ui.layout._showchilds;
if( layout._domid && !layout.ishidden ) IPM.setstyle( IPM.$(layout._domid), "display", "" );
if( layout._childs ) layout._childs.each( function(o) { _fn(o); } );
};
IPM.ui.layout._reflow_hv = function(state,root,layout)
{
if( !layout._childs ) return;
var _l = IPM.ui.layout;
var _w = 0;
if( layout._domid )
{
var _tmp;
if( layout.borders )
{
if( _tmp = layout.borders["8"] ) { state._h -= _tmp; }
if( _tmp = layout.borders["2"] ) { state._h -= _tmp; }
if( _tmp = layout.borders["4"] ) { state._w -= _tmp; }
if( _tmp = layout.borders["6"] ) { state._w -= _tmp; }
if( state._w < 0 ) state._w = 0;
if( state._h < 0 ) state._h = 0;
}
_l._reflow_p( state, root, layout );
if( layout.borders )
{
if( _tmp = layout.borders["8"] ) { state._t += _tmp; }
if( _tmp = layout.borders["4"] ) { state._l += _tmp; }
}
}
var _calc = IPM.ui.layout._calc( layout._t == "v" ? state._h : state._w, layout );
var _npos = 0;
var _n;
if( layout.dockable )
{
if( _calc[2] ) _npos += _l.dockw;
IPM.ui.layout._reflow_dock( state, layout, _calc[2] );
}
layout._childs.each( function(o) {
if( o.ishidden ) return;
if( layout.dockable && o.isdocked )
{
if( layout.isfloating )
{
IPM.ui.layout._showchilds(o);
}
else
{
IPM.ui.layout._hidechilds(o);
return;
}
}
if( o.isfixed )
{
_n = o.fixedsize;
}
else if( o.getsize )
{
_n = o._contentsize;
}
else
{
_n = _calc[1];
if( _n > _calc[0] ) _n = _calc[0];
_calc[0] -= _n;
}
var _s = IPM.copy( state );
if( layout._t == "v" )
{
_s._t = state._t + _npos;
_s._h = _n;
}
else
{
_s._l = state._l + _npos;
_s._w = _n;
}
if( !layout.dockable || !o.isdocked || !layout.isfloating )
{
_npos += _n;
}
( o._t == "p" ? _l._reflow_p : _l._reflow_hv)( _s, root, o );
if( (!layout.dockable || !o.isdocked || !layout.isfloating) && o.isresizable )
{
_s._l += _npos;
_l._reflow_resizer(_s,root,o);
_npos += IPM.ui.layout.barw;
_w = _s._w;
}
} );
};
IPM.ui.layout._reflow_p = function(state,root,layout)
{
var _domobj = IPM.$(layout._domid);
if( _domobj )
{
var _width  = state._w;
var _height = state._h;
var _top    = state._t;
var _left   = state._l;
var _tmp;
if( layout.borders && !layout._childs )
{
if( _tmp = layout.borders["8"] ) { _top += _tmp; _height -= _tmp;  }
if( _tmp = layout.borders["2"] ) { _height -= _tmp; }
if( _tmp = layout.borders["4"] ) { _left += _tmp; _width -= _tmp;  }
if( _tmp = layout.borders["6"] ) { _width -= _tmp; }
}
if( _height < 0 ) _height = 0;
if( _width < 0 ) _width = 0;
IPM.setstyles( _domobj, [ "top", "" + _top + "px", "left", "" + _left + "px", "height", "" + _height + "px", "width", "" + _width + "px" ] );
}
};
IPM.ui.layout._dockinit = function(root,parent,layout)
{
if( layout._t == "p" ) return;
if( layout.dockable && !layout._dockhandle )
{
var _domobj = document.createElement("DIV");
_domobj.id = layout._dockhandle = IPM.dom.newid( "__dockh_" );
_domobj.className = "placeable panel-dock";
document.body.appendChild( _domobj );
IPM.setstyle( _domobj, "display", "none" );
var _child = document.createElement("DIV");
_child.className = "panel-open";
_domobj.appendChild( _child );
IPM.evt.add(
_child,
function(e)
{
var c = IPM.caches.SING._layouthover;
if( c ) c.keep.apply( c, [layout] );
IPM.evt.unhook( layout._dockhandle );
IPM.ui.layout._dock(root,layout);
return IPM.evt.stop(e);
},
"click" );
IPM.evt.add(
_domobj,
function(e)
{
e = e || window.event;
var _d = e.target || e.srcElement;
if( _d.tagName == "DIV" )
{
IPM.ui.layout._float(root,layout);
var c = IPM.caches.SING._layouthover;
if( c ) c.show.apply( c, [c.active == layout ? null : layout] );
}
return IPM.evt.stop(e);
},
"click" );
var evt_in = function(e) { var c = IPM.caches.SING._layouthover; if( c ) c.want.apply( c, [layout] ); return IPM.evt.cancel(e); };
var evt_out = function(e) { var c = IPM.caches.SING._layouthover; if( c ) c.want.apply( c, [null] ); return IPM.evt.cancel(e); };
IPM.evt.add( _domobj, IPM.ui.layout._dockmousein, "mouseover" );
IPM.evt.add( _domobj, IPM.ui.layout._dockmouseout, "mouseout" );
IPM.evt.add( _domobj, function(e) { IPM.ui.layout._floattry(e,root,layout); return IPM.evt.stop(e); }, "mouseover" );
IPM.evt.add( _domobj, function(e) { var c = IPM.caches.SING._layouthover; if( c ) c.want.apply( c, [null] ); return IPM.evt.cancel(e); }, "mouseout" );
var w = IPM.aux.writer( _child );
w.write( "<a href='#' onclick='return false;'><img alt='dock' src='", IPM.ui.encode(IPM.ui.layout.imgs["w-expand"]), "'></a>" );
w.flush();
}
var _fn = IPM.ui.layout._dockinit;
layout._childs.each( function(o){ _fn( root, layout, o ); });
};
IPM.ui.layout.reflow = function(layout)
{
var _l = IPM.ui.layout;
if( !layout._init )
{
_l._dockinit(layout,{},layout);
layout._init = true;
}
var state = { _w: IPM.pos.vieww(true), _h: IPM.pos.viewh(true), _l: 0, _t: 0 };
( layout._t == "p" ? _l._reflow_p : _l._reflow_hv )( state, layout, layout );
};
IPM.ui.layout._dockmousein = function(e)
{
e = e || window.event;
var _d = e.target || e.srcElement;
if( _d.tagName != "DIV" ) _d = IPM.dom.up( _d, "DIV" );
IPM.addclass( _d, "panel-highlight" );
return true;
};
IPM.ui.layout._dockmouseout = function(e)
{
e = e || window.event;
var _d = e.target || e.srcElement;
if( _d.tagName != "DIV" ) _d = IPM.dom.up( _d, "DIV" );
IPM.delclass( _d, "panel-highlight" );
return true;
};
IPM.ui.layout._floattry = function(e,root,layout)
{
var c = IPM.caches.SING;
if( !c._layouthover )
{
c._layouthover = IPM.ui.delayhover.create(
{
delay: 750,
onshow: function(d)
{
if( !d )
{
if( c._layouthover._mylayout && c._layouthover._mylayout.isfloating )
{
IPM.ui.layout._unfloat( c._layouthover._myroot, c._layouthover._mylayout );
}
}
else
{
IPM.ui.layout._float( c._layouthover._myroot = c._layouthover._wantroot, c._layouthover._mylayout = d );
}
}
} );
}
c._layouthover._wantroot = root;
c._layouthover.want.apply( c._layouthover, [layout] );
return IPM.evt.stop(e);
};
IPM.ui.layout._collect = function(layout,fnmatch)
{
var _history = [];
var _ret = [];
_history.push(layout);
while( _history.length )
{
var _obj = _history.pop();
if( fnmatch(_obj) ) _ret.push(_obj);
if( _obj._childs ) _obj._childs.each( function(o){ _history.push(o); } );
}
return _ret;
};

/*
// tabs
*/
IPM.caches.TABS =
{
_cache: [],
item: function(ord)
{
var c = IPM.caches.TABS;
if( (typeof(ord) == "undefined") || (c._cache.length <= ord) ) return null;
return c._cache[ord];
},
dtor: function()
{
var c = IPM.caches.TABS;
c._cache.each(function(o){ if( o.dtor ) o.dtor.apply( o, [] ); });
c._cache.length = 0;
}
};
IPM.ui.tabs = {};
IPM.ui.tabs.create = function(_domobj,opts)
{
_domobj = IPM.$(_domobj);
if( !_domobj ) return null;
var c = IPM.caches.TABS;
var _ret = {};
_ret.ord = c._cache.length;
c._cache.push(_ret);
_domobj._tabord = _ret.ord;
IPM.ui.tabs._init.apply( _ret, [_domobj,opts] );
return _ret;
};
IPM.ui.tabs.dtor = function() {};
IPM.ui.tabs._init = function(_domobj,opts)
{
_domobj = IPM.$(_domobj);
if( !_domobj ) return null;
var activetab = (opts && opts.focus) || "";
var map = {};
var ord = this.ord;
this.focus = activetab;
if( opts && opts.tabs )
{
opts.tabs.each( function(o){ if( o.id && o.onclick ) map[o.id] = true; } );
this.tabs = opts.tabs;
}
else
{
this.tabs = [];
}
var tds = IPM.$$(_domobj,'TD',1000);
var td;
var first;
var active;
for( var i = 0, imax = tds.length; i < imax; ++i )
{
td = tds[i];
if( !IPM.hasclass( td, "tb" ) ) continue;
first = IPM.hasclass( td, "first" );
active = activetab == td.id;
if( map[td.id] )
{
// enabled.
var rm = active ? "off" : "on";
var add = active ? "on" : "off";
if( first ) IPM.addclass( IPM.delclass( IPM.delclass( tds[i-1], rm ), "disable" ), add );
IPM.addclass( IPM.delclass( IPM.delclass( td, rm ), "disable" ), add );
IPM.addclass( IPM.delclass( IPM.delclass( tds[i+1], rm ), "disable" ), add );
td.onclick = function(e){ IPM.ui.tabs._click(e,ord); return IPM.evt.cancel(e); };
}
else
{
if( first ) IPM.addclass( IPM.delclass( IPM.delclass( tds[i-1], "off" ), "on" ), "disable" );
IPM.addclass( IPM.delclass( IPM.delclass( td, "off" ), "on" ), "disable" );
IPM.addclass( IPM.delclass( IPM.delclass( tds[i+1], "off" ), "on" ), "disable" );
}
}
};
IPM.ui.tabs._click = function(e,ord)
{
e = e || window.event;
var _domobj = e.target || e.srcElement;
var _tbl = ( _domobj.tagName != "TABLE" ) ? IPM.dom.up( _domobj, "TABLE" ) : _domobj;
var _td  = (_domobj.tagName != "TD") ? IPM.dom.up( _domobj, "TD" ) : _domobj;
var tabitem = IPM.caches.TABS.item( _tbl._tabord );
if( tabitem && (tabitem.focus != _td.id) && IPM.hasclass( _td, "tb" ) && !IPM.hasclass( _td, "disable" ) )
{
var pos = tabitem.tabs ? tabitem.tabs.locate(function(o){ return o.id == _td.id; }) : -1;
if( pos >= 0 )
{
var tab = tabitem.tabs[pos];
if( tab && tab.onclick && tab.onclick.apply(tab,[tabitem]) )
{
if( IPM.ui.tabs.focus(_tbl,_td.id) ) tabitem.focus = _td.id;
}
}
}
return IPM.evt.cancel(e);
};
IPM.ui.tabs.focus = function(_tbl,activetab)
{
if( !_tbl ) return false;
var tds = IPM.$$(_tbl,'TD',1000);
var td;
var first;
var active;
var ret = false;
for( var i = 0, imax = tds.length; i < imax; ++i )
{
td = tds[i];
if( !IPM.hasclass( td, "tb" ) || IPM.hasclass( td, "disable" ) ) continue;
first = IPM.hasclass( td, "first" );
active = activetab == td.id;
var add = active ? "on" : "off";
var rm = active ? "off" : "on";
if( active ) ret = true;
if( IPM.hasclass( td, add ) ) continue;
if( first ) IPM.addclass( IPM.delclass( tds[i-1], rm ), add );
IPM.addclass( IPM.delclass( td, rm ), add );
IPM.addclass( IPM.delclass( tds[i+1], rm ), add );
}
return ret;
};
IPM.ui.tabs.enable = function(_tbl,_tab,_isenabled)
{
if( !_tbl ) return false;
var tds = IPM.$$(_tbl,'TD',1000);
var td;
var first;
var _fn = _isenabled ? IPM.delclass : IPM.addclass;
var ret = false;
for( var i = 0, imax = tds.length; i < imax; ++i )
{
td = tds[i];
if( !IPM.hasclass( td, "tb" ) || (td.id != _tab) ) continue;
first = IPM.hasclass( td, "first" );
if( first ) _fn( tds[i-1], "disable" );
_fn( td, "disable" );
_fn( tds[i+1], "disable" );
return true;
}
return ret;
};

IPM.$F = function()
{
var domobj, elemname;
if( arguments.length < 1 ) return null;
if( arguments.length < 2 ) { domobj = document.forms[0]; elemname = arguments[0]; }
else { domobj = arguments[0]; elemname = arguments[1]; }
if( typeof(domobj) == "string" ) domobj = document.getElementById(domobj);
else if( typeof(domobj) == "number" ) domobj = document.forms[domobj];
if( !domobj ) return null;
var found = null;
if( typeof(domobj.nodeType) && domobj.nodeType == 1 )
{
if( domobj.tagName == "FORM" ) return domobj.elements[elemname];
IPM.$$( domobj, "INPUT|SELECT|TEXTAREA" ).locate( function(o) { if( o.name == elemname ) found = o; return found != null; } );
}
else if( (typeof(domobj) == "object") && (domobj.constructor == Array) )
{
domobj.locate( function(o) { if( o.name == elemname ) found = o; return found != null; } );
}
return found;
};
IPM.$$F = function(domobj,formnames,max)
{
var re;
var re2;
max = max || 0;
if( domobj && (typeof(domobj)=="string") ) domobj = document.getElementById(domobj);
if( !domobj ) return [];
var ret = [];
if( typeof(formnames)=="string" )
{
formnames = formnames.split("|");
var s = [];
s.push( "^(?:" );
for( var i = 0, imax = formnames.length; i < imax ; ++i ) { if( i > 0 ) s.push("|"); s.push( formnames[i] ); }
s.push( ")$" );
re = new RegExp( s.join(''), "i" );
}
else
{
re = { test: function(){ return true; } };
}
re2 = /INPUT|SELECT|TEXTAREA/i;
if( !max ) IPM.dom.walknodes( domobj, function(pos) { if( re2.test(pos.tagName) && re.test(pos.name) ) ret.push(pos); return true; } );
else IPM.dom.walknodes( domobj, function(pos) { if( re2.test(pos.tagName) && re.test(pos.name) ) ret.push(pos); return ret.length < max; } );
return ret;
};
IPM.form.getpostd = function(elems,opts)
{
var notrim = false;
var noflip = false;
if( opts )
{
notrim = opts.notrim || false;
noflip = opts.noflip || false;
}
notrim = notrim || false;
var p = IPM.aux.writer();
var enc = function(t)
{
if( t ) return t.replace( /([%&])/g, function($1) { if( $1 == "%" ) return "%25"; if( $1 == "&" ) return "%26"; } );
return '';
};
var trim = notrim ? function(t) { return t; } : function(t) { return t.replace( /^[ \t]+|[ \t]+$/g, '' ); };
if( elems )
elems.each( function(domobj)
{
if( domobj.name )
{
var v = trim( domobj.value );
if( domobj.tagName == "INPUT" )
{
if( domobj.type == "button" ) return;
if( domobj.type == "checkbox" )
{
if( !domobj.checked && !noflip )
{
if( v == "true" ) v = "false";
else if( v == "false" ) v == "true";
}
}
}
p.write( domobj.name, "=", enc( v ), "&" );
}
} );
return p.join('');
};

IPM.drag =
{
_animobj: null,
_domobj: null,
_lastpos: null,
_noesc: false,
_nomup: false,
indrag: function() { return IPM.drag._animobj ? true : false; },
kind: function() { return (IPM.drag._animobj && IPM.drag._animobj.kind) ? IPM.drag._animobj.kind : null; },
domitem: function() { return IPM.drag._domobj; },
animitem: function() { return IPM.drag._animobj; },
seed: function(e)
{
e = e || window.event;
if( e && !IPM.drag._lastpos ) IPM.drag._lastpos = IPM.pos.cursor(e);
},
start: function( e, animobj, domobj, opts )
{
e = e || window.event;
if( !animobj ) return;
if( !domobj ) domobj = e.target || e.srcElement;
if( domobj && !(domobj = IPM.$(domobj)) ) return;
IPM.drag._noesc = (opts && opts.noesc) || false;
IPM.drag._nomup = (opts && opts.nomup) || false;
var that = IPM.drag;
if( !IPM.caches.DRAG )
{
IPM.evt.add( document, IPM.drag.evt_mm, "mousemove", false );
IPM.evt.add( document, IPM.drag.evt_mup, "mouseup", false );
IPM.evt.add( document, IPM.drag.evt_kp, "keypress", false );
IPM.evt.add( document, IPM.drag.evt_txt, "selectstart", false );
IPM.caches.DRAG = IPM.drag;
}
if( that._animobj )
{
if( that._animobj.is && that._animobj.is.apply( that._animobj, [domobj] ) ) return;
that._animobj.revert.apply( that._animobj, [e,that._domobj] );
that._animobj = null;
that._domobj = null;
}
that._animobj = animobj;
that._domobj = domobj;
document.body.focus();
animobj.start.apply( animobj, [e, domobj] );
return true;
},
revert: function( e, isdtor )
{
var that = IPM.drag;
if( that._animobj ) that._animobj.revert.apply( that._animobj, [e, that._domobj, isdtor || false] );
that._animobj = null;
that._domobj = null;
return false;
},
end: function(e)
{
var that = IPM.drag;
e = e || window.event;
if( that._animobj ) that._animobj.end.apply( that._animobj, [e, that._domobj] );
that._animobj = null;
that._domobj = null;
return false;
},
evt_mm: function(e)
{
var that = IPM.drag;
e = e || window.event;
var ptr = IPM.pos.cursor(e);
if( ptr.x < 0 ) ptr.x = 0;
if( ptr.y < 0 ) ptr.y = 0;
if( that._lastpos && (ptr.x == that._lastpos.x) && (ptr.y == that._lastpos.y) ) return;
that._lastpos = ptr;
ptr = null;
if( that._animobj ) that._animobj.movement.apply( that._animobj, [e, that._domobj, that._lastpos] );
},
evt_kp: function(e)
{
e = e || window.event;
var keycode = e.which || e.keyCode;
if( IPM.drag._noesc ) return;
if( keycode == 27 ) IPM.drag.revert(e); // escape
},
evt_mup: function(e) { if( IPM.drag._nomup ) return; IPM.drag.end(e); },
evt_txt: function(e) { if( IPM.drag._animobj ) { IPM.evt.cancel(e); return false; } },
dtor: function() { IPM.drag.revert({},true); }
};

IPM.caches.Z = 
{
_cache: [],
_maxs: [],
_maxz: 100,
add: function(domobj,level,topmost)
{
if( !domobj || (typeof(domobj.ipm_zlevel) != "undefined") || (domobj.ipm_zlevel >= 0)  ) return;
if( typeof(level) == "string" )
{
switch( level )
{
case 'page':    level = 0; break;
case 'lift':    level = 1; break;
case 'hover':   level = 2; break;
case 'fauxwin': level = 3; break;
case 'blocker': level = 4; break;
case 'menu':    level = 5; break;
case 'cursor':  level = 6; break;
default:        level = 0; break;
}
}
var c = IPM.caches.Z;
level = level || 0;
while( c._cache.length <= level ) { c._cache.push( [] ); c._maxs.push( 0 ); }
var a_lvl = c._cache[level];
var newz  = level * c._maxz;
domobj.ipm_zlevel = level;
if( c._maxs[level] < newz ) c._maxs[level] = newz;
a_lvl.push( domobj );
IPM.setstyle( domobj, "zIndex", ""+newz );
if( topmost ) c.up( domobj );
},
remove: function(domobj)
{
if( !domobj || (typeof(domobj.ipm_zlevel) == "undefined") || (domobj.ipm_zlevel < 0) ) return false;
var c     = IPM.caches.Z;
var level = domobj.ipm_zlevel;
if( c._cache.length > level )
{
var a_lvl = c._cache[level];
var pos   = a_lvl.locate( function(o) { return o == domobj; } );
if( pos >= 0 ) a_lvl.splice( pos, 1 );
}
domobj.ipm_zlevel = -1;
return true;
},
up: function(domobj)
{
if( !domobj ) return false;
while( domobj && (typeof(domobj.ipm_zlevel) == "undefined") ) domobj = domobj.parentNode;
if( domobj.ipm_zlevel < 0 ) return false;
var c     = IPM.caches.Z;
var level = domobj.ipm_zlevel;
var a_lvl = c._cache[level];
var pos   = a_lvl.locate( function(o) { return o == domobj; } );
var newz  = c._maxs[level] + 2;
if( pos == 0 ) return true;
if( pos >= 0 )
{
c._maxs[level] = newz;
var ret = a_lvl.splice( pos, 1 );
a_lvl.splice( 0, 0, ret[0] );
if( newz >= (level+1) * c._maxz ) c.reflow(level);
else IPM.setstyle( domobj, "zIndex", ""+newz );
return true;
}
return false;
},
reflow: function(level)
{
level = level || 0;
// create a hashtable of all the unique zindexs... then reassign them.
var c     = IPM.caches.Z;
var a_lvl = c._cache[level];
if( !a_lvl.length ) return true;
var lastz     = IPM.getstyle( a_lvl[a_lvl.length-1], "zIndex" );
var lastz_val = level * c._maxz + 2;
for( var i = a_lvl.length; i ; )
{
--i;
var o = a_lvl[i];
var zi = IPM.getstyle( o, "zIndex" );
if( zi != lastz ) { lastz = zi; lastz_val += 2; }
IPM.setstyle( o, "zIndex", lastz_val );
}
c._maxs[level] = lastz_val;
return true;
},
get_zindex: function(level)
{
if( typeof(level) == "string" )
{
switch( level )
{
case 'page':    level = 0; break;
case 'lift':    level = 1; break;
case 'hover':   level = 2; break;
case 'fauxwin': level = 3; break;
case 'blocker': level = 4; break;
case 'menu':    level = 5; break;
case 'cursor':  level = 6; break;
case 'top':     level = 7; break;
default:        level = 0; break;
}
}
return level * IPM.caches.Z._maxz;
},
dtor: function()
{
var c = IPM.caches.Z;
c._cache.each( function(o) { o.length = 0; } );
c._cache.length = 0;
}
};
IPM.z = IPM.caches.Z;
IPM.caches.WIN =
{
_cache: [],
_modal: null,
dtor: function()
{
var c = IPM.caches.WIN;
c._cache.each( function(o) { if( o.dtor ) o.dtor.apply( o, [] ); } );
c._cache.length = 0;
c._modal = null;
}
};
IPM.win =
{
_count: 0,
item: function(name,wantpos)
{
var a = IPM.caches.WIN._cache;
var pos;
if( (typeof(name)=="string") || (typeof(name.nodeType)!="undefined") ) pos = a.locate( function(o) { return o.is.apply( o, [name] ); } );
else pos = a.locate( function(o) { return o == name; } );
if( wantpos ) return pos;
return (pos < 0) ? null : a[pos];
},
add: function(win)
{
if( !win ) return;
var pos = IPM.win.item(win.named,true);
if( pos >= 0 )
{
var exist = IPM.caches.WIN._cache[pos];
if( exist != win ) IPM.win.close(win);
else return;
}
IPM.z.add(win._rootdiv,'fauxwin',true);
IPM.caches.WIN._cache.push(win);
},
show: function( domobj, opts, rbuttons, lbuttons )
{
var n = opts ? (opts.named || null) : null;
var win = n ? IPM.win.item( n ) : null;
if( !win )
{
win = IPM.win.fauxwin.create( domobj, opts, rbuttons, lbuttons );
IPM.z.add(win._rootdiv,'fauxwin',true);
IPM.caches.WIN._cache.push(win);
}
else if( IPM.is.safari && opts.url )
{
win.show.apply( win, [] );
IPM.z.up(win._rootdiv);
window.setTimeout( function() { win.reflow.apply( win, [opts,rbuttons,lbuttons] ); }, 100 );
return win;
}
else
{
win.reflow.apply( win, [opts,rbuttons,lbuttons] );
}
IPM.z.up(win._rootdiv);
win.show.apply( win, [] );
return win;
},
show_tab: function( winname, tabname, opts )
{
var win = IPM.win.item( winname );
if( !win ) return;
IPM.z.up( win._rootdiv );
win.show_tab.apply( win, [tabname,opts] );
},
close: function(name)
{
var pos = IPM.win.item(name,true);
if( pos >= 0 )
{
var win = IPM.caches.WIN._cache[pos];
if( win._iframe ) win._iframe.parentNode.removeChild( win._iframe );
if( win._rootdiv ) win._rootdiv.parentNode.removeChild( win._rootdiv );
if( win._ismodal ) IPM.ui.delmodal();
win.dtor.apply( win, [] );
IPM.caches.WIN._cache.splice( pos, 1 );
}
},
settitle: function(name,txt) { var win = IPM.win.item(name); if( win && win._titlespan ) IPM.dom.sethtml( win._titlespan,txt ); },
getdoc: function(name) { var win = IPM.win.item(name); return win ? win.getdoc.apply( win, [] ) : null; },
getdocwin: function(name) { var win = IPM.win.item(name); return win ? win.getdocwin.apply( win, [] ) : null; },
hide: function(name) { var win; if( win = IPM.win.item(name) ) win.hide.apply( win, [] ); },
remove: function(name) { var pos = IPM.win.item(name,true); if( pos >= 0 ) IPM.caches.WIN._cache.splice( pos, 1 ); },
xclick: function(name) { var win; if( win = IPM.win.item(name) ) (win.closex?IPM.win.close:IPM.win.hide)(win); },
refresh: function(name,opts) { var win; if( win = IPM.win.item(name) ) win.refresh.apply( win, [opts] ); }
};
IPM.win.fauxwin =
{
url: null,
title: null,
resize: true,
named: null,
closex: false,
modal: false,
x: null,
y: null,
h: null,
w: null,
_rootdiv: null,
_ftrdiv: null,
_titlespan: null,
_iframe: null,
_ismodal: false,
create: function( domobj, opts, rbuttons, lbuttons )
{
if( !opts || !opts.url ) return null;
var rootdiv = IPM.$(domobj);
var newobj  = IPM.copy( opts, IPM.copy( IPM.win.fauxwin, new Object() ) );
if( !newobj.named ) newobj.named = "_fw" + (IPM.win._count++);
if( !rootdiv ) rootdiv = IPM.setstyle( document.body.insertBefore( document.createElement("DIV"), document.body.firstChild ), "display", IPM.is.safari ? "" : "none" );
else IPM.dom.sethtml( rootdiv, "" );
IPM.addclass( rootdiv, "fauxwin" );
newobj._rootdiv = rootdiv;
var w2 = !newobj.w ? Math.round(IPM.pos.vieww() * 0.66666) + "px" : (typeof(newobj.w) == "string" ? newobj.w : newobj.w + "px");
var h2 = !newobj.h ? Math.round(IPM.pos.viewh() * 0.66666) + "px" : (typeof(newobj.h) == "string" ? newobj.h : newobj.h + "px");
IPM.setstyles( rootdiv, ["position","absolute","width",w2,"backgroundColor","#fff"] );
{
var hdr, ftr, tmp, img, a, ifr;
IPM.copy( { className: "hdr" }, rootdiv.appendChild( hdr = document.createElement( "DIV" ) ) );
hdr.appendChild( a = document.createElement("A") ).appendChild( img = document.createElement("IMG") );
hdr.appendChild( newobj._titlespan = document.createElement("SPAN") );
hdr.appendChild( (tmp = document.createElement("DIV")).appendChild( document.createComment("") ) );
tmp = IPM.setstyle( tmp, "clear", "both" );
rootdiv.appendChild(tmp = document.createElement( "DIV" ));
tmp.appendChild( document.createComment("") );
tmp.className = "dots";
var named = newobj.named;
IPM.copy( { href: "#", onclick: function(e){ IPM.win.xclick(named); IPM.evt.cancel(e); } }, a );
IPM.copy( { className: "ico16 fright", src: "/cfg/v8/button_close.png", alt: "Close" }, img );
tmp = IPM.setstyles( rootdiv.appendChild( document.createElement( "DIV" ) ), ["marginRight","1px","marginLeft","1px"] );
if( IPM.is.ie ) IPM.setstyle( tmp, "zoom", "1" );
if( IPM.is.ie ) IPM.setstyle( hdr, "zoom", "1" );
if( IPM.is.safari )
{
tmp.appendChild(
IPM.setstyles(
IPM.copy( { frameBorder: "0", border: "0", src: newobj.url, id: "__fwid" + newobj.named, name: "__fwid" + newobj.named }, ifr = document.createElement("IFRAME") ),
["width","100%","height",h2]
)
);
}
else
{
tmp.appendChild(
IPM.setstyles(
IPM.copy( { frameBorder: "0", border: "0", src: newobj.url }, ifr = document.createElement("IFRAME") ), ["width","100%","height",h2]
)
);
}
IPM.copy( { className: "ftr" }, ftr = document.createElement( "DIV" ) ).appendChild( document.createComment("") );
rootdiv.appendChild( ftr );
IPM.setstyle( ftr, "textAlign", "right" );
newobj._ftrdiv = ftr;
newobj._iframe = ifr;
newobj.reflow.apply( newobj, [null,rbuttons,lbuttons] );
}
rootdiv.onmousemove = function(e){IPM.hit.movement(e,[IPM.hit_loc.fauxwin]);};
rootdiv.onmousedown = function(e){e = e || event; IPM.z.up(e.target||e.srcElement); IPM.hit.mousedown(e,[IPM.hit_loc.fauxwin]);};
if( IPM.is.safari ) window.setTimeout( function(){ newobj.refresh.apply( newobj, [{skiprandom:true}] ); }, 1000 );
return newobj;
},
reflow: function( opts, rbuttons, lbuttons )
{
var urlchange = false;
if( opts )
{
var save = {};
var saveops = ['named'];
var that = this;
urlchange = opts.url && (opts.url != this.url);
if( typeof(opts.resize) == "undefined" ) opts.resize = true;
if( typeof(opts.modal) == "undefined" ) opts.modal = false;
if( urlchange )
{
if( !this.resize && opts.resize )
{
if( typeof(opts.w) == "undefined" ) { opts.w = null; opts.x = null; }
if( typeof(opts.h) == "undefined" ) { opts.h = null; opts.y = null; }
}
if( (typeof(opts.w) != "undefined") && (typeof(opts.x) == "undefined") ) opts.x = null;
if( (typeof(opts.h) != "undefined") && (typeof(opts.y) == "undefined") ) opts.y = null;
}
saveops.each( function(s) { save[s] = that[s]; } );
IPM.copy( opts, this );
saveops.each( function(s) { that[s] = save[s]; } );
}
if( this.resize ) IPM.addclass( this._ftrdiv, "grip" );
else IPM.delclass( this._ftrdiv, "grip" );
IPM.dom.sethtml( this._titlespan, IPM.ui.encode( this.title || "" ) );
var ftr = this._ftrdiv;
while( ftr.firstChild ) ftr.removeChild( ftr.firstChild );
if( lbuttons )
lbuttons.each( function(info,align)
{
if( typeof(info.parentNode) != "undefined" ) { ftr.appendChild(info); return; }
var btn = document.createElement( "INPUT" );
btn.type = "button";
btn.value = info.name;
btn.className = info.className || "btn";
IPM.setstyle( btn, "float", "left" );
ftr.appendChild( btn );
btn.onclick = info.onclick || IPM.evt.cancel;
IPM.copy( info.opts, btn );
}, "left" );
if( rbuttons )
rbuttons.each( function(info,align)
{
if( typeof(info.parentNode) != "undefined" ) { ftr.appendChild(info); return; }
var btn = document.createElement( "INPUT" );
btn.type = "button";
btn.value = info.name;
btn.className = info.className || "btn";
ftr.appendChild( btn );
btn.onclick = info.onclick || IPM.evt.cancel;
IPM.copy( info.opts, btn );
}, "left" );
var rcount = rbuttons ? rbuttons.length : 0;
var lcount = lbuttons ? lbuttons.length : 0;
if( !rcount && !lcount ) ftr.appendChild( document.createTextNode("\u00A0") );
IPM.setstyle( ftr, "display", ( rcount || lcount || this.resize ) ? "" : "none" );
if( urlchange ) this.refresh({skiprandom:true});
},
refresh: function(opts)
{
if( this._iframe == null ) return;
if( opts && typeof(opts.newurl) != "undefined" ) this.url = opts.newurl;
var l = this.url;
if( !opts || !opts.skiprandom )
{
if( l.indexOf( "?" ) < 0 ) l += "?";
else if( /&$/.test( l ) == false ) l += "&";
if( opts && opts.add ) { l += opts.add; if( /&$/.test( l ) == false ) l += "&"; }
var now = new Date();
l += "random=" + now.getTime() + "&";
}
var ifrwin = this.getdocwin();
if( ifrwin ) ifrwin.location = l;
},
show: function()
{
if( this._rootdiv == null ) return false;
if( this.modal )
{
if( !this._ismodal ) { this._ismodal = true; IPM.ui.addmodal( this._rootdiv ); }
}
else
{
if( this._ismodal ) { this._ismodal = false; IPM.ui.delmodal(); }
}
var body_h = IPM.pos.viewh();
var body_w = IPM.pos.vieww();
if( this.h == null )
{
this.h = Math.round( body_h * 0.66666 );
}
if( this.w == null )
{
this.w = Math.round( body_w * 0.66666 );
}
if( this.x == null )
{
this.x = ((this.w > body_w) ? 0 : Math.round( (body_w - this.w) / 2 )) + IPM.pos.pagex();
}
if( this.y == null )
{
var hdr = IPM.pos.info(this._rootdiv);
var ifr = IPM.pos.info(this._iframe);
var pad = hdr.h - ifr.h;
body_h -= pad;
this.y = ((this.h > body_h) ? 0 : Math.round( (body_h - this.h) / 2 )) + IPM.pos.pagey();
}
var h2 = (typeof(this.h) == "string") ? this.h : ""+this.h+"px";
var w2  = (typeof(this.w) == "string") ? this.w : ""+this.w+"px";
IPM.setstyle( this._iframe, "height", h2 );
IPM.setstyles( this._rootdiv, ["top",""+this.y+"px","left",""+this.x+"px","width",w2,"display",""] );
},
hide: function()
{
if( this._rootdiv )
{
if( this._ismodal ) { this._ismodal = false; IPM.ui.delmodal(); }
IPM.setstyle( this._rootdiv, "display", "none" );
}
},
is: function(name)
{
if( typeof(name) == "string" ) return this.named == name;
return (name == this._rootdiv || name == this._iframe);
},
getdoc: function()
{
var doc = null;
var ifr = this._iframe;
if( !ifr ) return null;
if( ifr.contentDocument ) doc = ifr.contentDocument;
else if( ifr.contentWindow ) doc = ifr.contentWindow.document;
else if( ifr.document ) doc = ifr.document;
return doc;
},
getdocwin: function()
{
var ret = null;
var ifr = this._iframe;
if( !ifr ) return null;
if( ifr.contentWindow ) ret = ifr.contentWindow;
else if( ifr.contentDocument && ifr.contentDocument.defaultView ) ret = ifr.contentDocument.defaultView;
else if( ifr.document && ifr.document.window ) ret = ifr.document.window;
return ret;
},
dtor: function()
{
IPM.z.remove( this._rootdiv );
this._rootdiv = null;
this._ftrdiv = null;
this._titlespan = null;
this._iframe = null;
}
};
IPM.win.fauxtab =
{
title: null,
resize: true,
named: null,
closex: false,
modal: false,
tabinfo: null,
active: null,
x: null,
y: null,
h: null,
w: null,
_rootdiv: null,
_ftrdiv: null,
_titlespan: null,
_tabctrls: null,
_iframe: null,
_ismodal: false,
create: function( domobj, opts, rbuttons, lbuttons )
{
var rootdiv = IPM.$(domobj);
var newobj  = IPM.copy( opts, IPM.copy( IPM.win.fauxtab, new Object() ) );
if( !newobj.named ) newobj.named = "_fw" + (IPM.win._count++);
if( !rootdiv ) rootdiv = IPM.setstyle( document.body.insertBefore( document.createElement("DIV"), document.body.firstChild ), "display", "none" );
else IPM.dom.sethtml( rootdiv, "" );
IPM.addclass( rootdiv, "fauxwin" );
IPM.addclass( rootdiv, "fauxtab" );
newobj._rootdiv = rootdiv;
var w2 = !newobj.w ? Math.round(IPM.pos.vieww() * 0.66666) + "px" : (typeof(newobj.w) == "string" ? newobj.w : newobj.w + "px");
var h2 = !newobj.h ? Math.round(IPM.pos.viewh() * 0.66666) + "px" : (typeof(newobj.h) == "string" ? newobj.h : newobj.h + "px");
IPM.setstyles( rootdiv, ["position","absolute","width",w2,"backgroundColor","#fff"] );
{
var hdr, ftr, tmp, img, a, ifr;
IPM.copy( { className: "hdr" }, rootdiv.appendChild( hdr = document.createElement( "DIV" ) ) );
hdr.appendChild( a = document.createElement("A") ).appendChild( img = document.createElement("IMG") );
hdr.appendChild( newobj._titlespan = document.createElement("SPAN") );
hdr.appendChild( (tmp = document.createElement("DIV")).appendChild( document.createComment("") ) );
tmp = IPM.setstyle( tmp, "clear", "both" );
rootdiv.appendChild(tmp = document.createElement( "DIV" ));
tmp.appendChild( document.createComment("") );
tmp.className = "dots";
var named = newobj.named;
IPM.copy( { href: "#", onclick: function(e){ IPM.win.xclick(named); IPM.evt.cancel(e); } }, a );
IPM.copy( { className: "ico16 fright", src: "/cfg/v8/button_close.png", alt: "Close" }, img );
if( newobj.tabinfo && (newobj.tabinfo.length > 1) )
{
tmp = rootdiv.appendChild( document.createElement( "DIV" ) );
IPM.addclass( tmp, "toptab" );
IPM.addclass( tmp, "tabctrls" );
newobj._tabctrls = tmp;
var wr = IPM.aux.writer( tmp );
newobj.init_tabs.apply( newobj, [wr] );
wr.flush();
tmp = rootdiv.appendChild( document.createElement( "DIV" ) );
tmp.appendChild( document.createComment("") );
IPM.addclass( tmp, "tabctrlsb" );
}
tmp = IPM.setstyles( rootdiv.appendChild( document.createElement( "DIV" ) ), ["marginRight","1px","marginLeft","1px","overflow","hidden"] );
if( IPM.is.ie ) IPM.setstyle( tmp, "zoom", "1" );
if( IPM.is.ie ) IPM.setstyle( hdr, "zoom", "1" );
if( IPM.is.safari || IPM.is.opera ) tmp.appendChild( IPM.setstyles( ifr = document.createElement("DIV"), ["width","100%","height",h2,"overflow","scroll"] ) );
else  tmp.appendChild( IPM.setstyles( ifr = document.createElement("DIV"), ["width","100%","height",h2] ) );
ifr.istabcontainer = true;
if( newobj.tabinfo )
{
var i = 0;
newobj.tabinfo.each( function(o) {
var d = IPM.$(o.divid);
if( d )
{
var ison;
if( !i ) ison = !newobj.active ? true : (o.name == newobj.active);
else ison = (o.name == newobj.active);
if( IPM.is.safari || IPM.is.opera ) IPM.setstyles( d, [ "display", ison ? "" : "none", "width", "auto", "height", "100%" ] );
else IPM.setstyles( d, [ "display", ison ? "" : "none", "width", "auto", "height", "100%", "overflow", "hidden", "overflowX", "hidden", "overflowY", "auto" ] );
ifr.appendChild( d );
}
++i;
});
}
IPM.copy( { className: "ftr" }, ftr = document.createElement( "DIV" ) );
tmp = document.createElement( "DIV" );
ftr.appendChild( tmp );
tmp.appendChild( document.createComment("") );
rootdiv.appendChild( ftr );
IPM.setstyle( ftr, "textAlign", "right" );
newobj._ftrdiv = ftr;
newobj._iframe = ifr;
newobj.reflow.apply( newobj, [null,rbuttons,lbuttons] );
if( newobj.onpreshow ) newobj.onpreshow.apply( newobj, [newobj.active] );
}
rootdiv.onmousemove = function(e){IPM.hit.movement(e,[IPM.hit_loc.fauxwin]);};
rootdiv.onmousedown = function(e){ e = e || event; IPM.z.up(e.target||e.srcElement);IPM.hit.mousedown(e,[IPM.hit_loc.fauxwin]);};
if( IPM.is.gecko || IPM.is.ie ) window.setTimeout( IPM.bind( newobj, function(){ newobj.refresh({skiprandom:true}); } ), 10 );
return newobj;
},
refresh: function(opts) { return; },
init_tabs: function( writer )
{
var infos = this.tabinfo;
var active = this.active;
var ord = this.named;
writer.write( "<table cellspacing=0 cellpadding=0><tr>" );
var i = 0;
var ilast = infos.length - 1;
var ison = false;
var encode = IPM.ui.encode;
infos.each( function(o) {
if( !i )
{
ison = !active ? true : (o.name == active);
writer.write( "<td class='sep sepf ", ison ? "on" : "off" ,"'><img style='margin-left: -1px;' width=2 height=2 alt='' src='/cfg/v8/part_dashtr.gif'>&nbsp;</td>" );
}
else ison = !active ? true : (o.name == active);
writer.write( "<td class='", !i ? "first " : "", "tb ", ison ? "on" : "off", "'><a href='#' onclick=\"IPM.win.show_tab('", encode(ord), "','", encode(o.name), "'); return false;\">", encode( o.text || "" ), "</a></td>" );
writer.write( "<td class='sep sepm ", ison ? "on" : "off", "'><img alt='' src='/cfg/v8/part_dasht", i == ilast ? "l" : "m", ".gif'>&nbsp;</td>" );
if( i == ilast ) writer.write( "<td class='sep sepl'>&nbsp;</td>" );
++i;
});
writer.write( "</tr></table>" );
},
show_tab: function(name,opts)
{
var active = this.tabinfo.locate( function(o,n) { return o.name == n; }, this.active );
var pos    = this.tabinfo.locate( function(o,n) { return o.name == n; }, name );
if( pos < 0 ) return;
if( opts && opts.wantrefresh )
{
if( this.onpreshow ) this.onpreshow( name, true );
if( opts && opts.nofocus ) return;
}
else
{
if( active == pos ) return;
if( this.onpreshow ) this.onpreshow( name );
}
var tds = IPM.$$( this._tabctrls, "TD", this.tabinfo.length * 3 );
if( active == 0 ) IPM.addclass( IPM.delclass( tds[0], "on" ), "off" );
IPM.addclass( IPM.delclass( tds[1+active*2], "on" ), "off" );
IPM.addclass( IPM.delclass( tds[2+active*2], "on" ), "off" );
if( pos == 0 ) IPM.addclass( IPM.delclass( tds[0], "off" ), "on" );
IPM.addclass( IPM.delclass( tds[1+pos*2], "off" ), "on" );
IPM.addclass( IPM.delclass( tds[2+pos*2], "off" ), "on" );
if( active >= 0 ) IPM.setstyle( IPM.$( this.tabinfo[active].divid ), "display", "none" );
IPM.setstyle( IPM.$( this.tabinfo[pos].divid ), "display", "" );
this.active = name;
},
reflow: function( opts, rbuttons, lbuttons )
{
if( opts )
{
var save = {};
var saveops = ['named'];
var that = this;
if( typeof(opts.resize) == "undefined" ) opts.resize = true;
if( typeof(opts.modal) == "undefined" ) opts.modal = false;
saveops.each( function(s) { save[s] = that[s]; } );
IPM.copy( opts, this );
saveops.each( function(s) { that[s] = save[s]; } );
}
if( this.resize ) IPM.addclass( this._ftrdiv, "grip" );
else IPM.delclass( this._ftrdiv, "grip" );
IPM.dom.sethtml( this._titlespan, IPM.ui.encode( this.title || "" ) );
var ftr = this._ftrdiv;
while( ftr.firstChild ) ftr.removeChild( ftr.firstChild );
if( lbuttons )
lbuttons.each( function(info,align)
{
if( typeof(info.parentNode) != "undefined" ) { ftr.appendChild(info); return; }
var btn = document.createElement( "INPUT" );
btn.type = "button";
btn.value = info.name;
btn.className = info.className || "btn";
IPM.setstyle( btn, "float", "left" );
ftr.appendChild( btn );
btn.onclick = info.onclick || IPM.evt.cancel;
IPM.copy( info.opts, btn );
}, "left" );
if( rbuttons )
rbuttons.each( function(info,align)
{
if( typeof(info.parentNode) != "undefined" ) { ftr.appendChild(info); return; }
var btn = document.createElement( "INPUT" );
btn.type = "button";
btn.value = info.name;
btn.className = info.className || "btn";
ftr.appendChild( btn );
btn.onclick = info.onclick || IPM.evt.cancel;
IPM.copy( info.opts, btn );
}, "left" );
var rcount = rbuttons ? rbuttons.length : 0;
var lcount = lbuttons ? lbuttons.length : 0;
if( !rcount && !lcount ) ftr.appendChild( document.createTextNode("\u00A0") );
IPM.setstyle( ftr, "display", ( rcount || lcount || this.resize ) ? "" : "none" );
},
show: function()
{
if( this._rootdiv == null ) return false;
if( this.modal )
{
if( !this._ismodal ) { this._ismodal = true; IPM.ui.addmodal( this._rootdiv ); }
}
else
{
if( this._ismodal ) { this._ismodal = false; IPM.ui.delmodal(); }
}
var body_h = IPM.pos.viewh();
var body_w = IPM.pos.vieww();
if( this.h == null )
{
this.h = Math.round( body_h * 0.66666 );
}
if( this.w == null )
{
this.w = Math.round( body_w * 0.66666 );
}
if( this.x == null )
{
this.x = ((this.w > body_w) ? 0 : Math.round( (body_w - this.w) / 2 )) + IPM.pos.pagex();
}
if( this.y == null )
{
var _h = this.h;
var hdr = IPM.pos.info(this._rootdiv);
var ifr = IPM.pos.info(this._iframe);
if( _h == "auto" ) _h = ifr.h;
var pad = hdr.h - ifr.h;
body_h -= pad;
this.y = ((_h > body_h) ? 0 : Math.round( (body_h - _h) / 2 )) + IPM.pos.pagey();
}
var h2 = (typeof(this.h) == "string") ? this.h : ""+this.h+"px";
var w2  = (typeof(this.w) == "string") ? this.w : ""+this.w+"px";
IPM.setstyle( this._iframe, "height", h2 );
IPM.setstyles( this._rootdiv, ["top",""+this.y+"px","left",""+this.x+"px","width",w2,"display",""] );
},
hide: function()
{
if( this._rootdiv )
{
if( this._ismodal ) { this._ismodal = false; IPM.ui.delmodal(); }
IPM.setstyle( this._rootdiv, "display", "none" );
}
},
is: function(name)
{
if( typeof(name) == "string" ) return this.named == name;
return (name == this._rootdiv || name == this._iframe);
},
getdoc: function() { return document; },
getdocwin: function() { return window; },
dtor: function()
{
IPM.z.remove( this._rootdiv );
this._rootdiv = null;
this._ftrdiv = null;
this._titlespan = null;
this._iframe = null;
}
};

IPM.ajax =
{
onsuccess: null,
onerror: null,
ontimeout: null,
onrschange: null,
timeout: null,
headers: null,
doeval: false,
acct: null,
pw: null,
verb: 'POST',
_postd: null,
_url: null,
_timeout: null,
_xhrobj: null,
_inuse: false,
_thandle: null,
create: function( url, opts, postd ) { var ret = IPM.copy( opts, IPM.copy( IPM.ajax, new Object() ) ); ret._url = url; if( postd ) ret._postd = postd; return ret; },
verify: function()
{
_xhr = null;
if( window.XMLHttpRequest ) { try { _xhr = new XMLHttpRequest(); } catch(err) { _xhr = null; } }
if( !_xhr && window.ActiveXObject )
{
try { _xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(err) { _xhr = null; }
if( !_xhr ) { try { _xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch(err) { _xhr = null; } }
}
return _xhr != null;
},
start: function( opts )
{
this.cancel();
if( opts )
{
['onsuccess','onerror','ontimeout','onrschange','timeout','verb','doeval','acct','pw'].each(
function(s,src,dest) { if( typeof(src[s]) != "undefined" ) dest[s] = src[s]; },
opts, this );
if( opts.url ) this._url = opts.url;
if( typeof(opts.postd) != "undefined" ) this._postd = opts.postd;
}
if( ! this._xhrobj )
{
if( window.XMLHttpRequest ) { try { this._xhrobj = new XMLHttpRequest(); } catch(err) { this._xhrobj = null; } }
if( !this._xhrobj && window.ActiveXObject )
{
try { this._xhrobj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(err) { _xhrobj = null; }
if( !this._xhrobj ) { try { this._xhrobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(err) { _xhrobj = null; } }
}
if( !this._xhrobj ) return false;
}
if( this.timeout )
this._thandle = window.setTimeout( IPM.pass( this, this.ontimeout, this ), this.timeout );
try
{
if( this.acct || this.pw ) this._xhrobj.open( this.verb, this._url, true, this.acct, this.pw );
else this._xhrobj.open( this.verb, this._url, true );
}
catch(err)
{
if( this.onerror ) window.setTimeout( IPM.pass( this, this.onerror, this ), 20 );
return false;
}
var ctypeseen = false;
if( this.headers )
{
var a = this.headers;
var imax = a.length;
if( imax % 2 ) --imax;
for( var i=0; i < imax ; )
{
var n = a[i++];
var v = a[i++];
try{this._xhrobj.setRequestHeader( n, v );}catch(err){}
if( (/content-type/i).test( n ) ) ctypeseen = true;
}
}
if( this.verb == "POST" && !ctypeseen )
try{this._xhrobj.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );}catch(err){}
this._xhrobj.onreadystatechange = IPM.bind( this, this.rschange );
this._inuse = true;
var xhrsendret = this._xhrobj.send( this._postd || "" );
return true;
},
cancel: function()
{
if( this._inuse && this._xhrobj )
{
try { this._xhrobj.onreadystatechange = null; } catch(err){ }
this._xhrobj.abort();
this._xhrobj = null;
}
if( this._thandle != null ) window.clearTimeout( this._thandle );
this._inuse = false;
this._thandle = null;
},
rschange: function()
{
var xhr = this._xhrobj;
if( this.onrschange ) window.setTimeout( IPM.pass( this, this.onrschange, this ), 10 );
if( this._xhrobj.readyState == 4 )
{
this._inuse = false;
if( this._thandle != null ) { window.clearTimeout( this._thandle ); this._thandle = null; }
var status;
try
{
status = typeof(xhr.status) != "undefined" ? xhr.status : 0;
if( IPM.is.safari ) status = 200;
}
catch(err)
{
status = 0;
}
if( (status >= 200) && (status < 400) )
{
if( this.onsuccess ) window.setTimeout( IPM.pass( this, this.onsuccess, this ), 20 );
if( this.doeval )
{
var ctype = xhr.getResponseHeader("Content-Type");
var fn = null;
var rt = xhr.responseText || "";
if( ctype && (/text\/html/i).test( ctype ) )
{
var a = rt.match( /<script[^>]*?>.*?<\/script>/ig );
if( a ) fn = function(){ a.each( function(txt) { eval( txt.replace( /^<script[^>]*?>/, '' ).replace( /<\/script>$/, '' ) ); } ); };
}
else
{
fn = function(){eval(rt);};
}
if( fn ) window.setTimeout( fn, 20 );
}
}
else if( this.onerror ) window.setTimeout( IPM.pass( this, this.onerror, this ), 20 );
window.setTimeout( function(){xhr.onreadystatechange=IPM.is.ie?IPM.fn_null:null;}, 0 );
}
},
dtor: function()
{
if( this._xhrobj ) this._xhrobj.onreadystatechange = null;
this.cancel();
this.onsuccess = null;
this.onerror = null;
this.ontimeout = null;
this.onrschange = null;
this.headers = null;
}
};
// modifications
IPM.ajax.mod = {};
IPM.ajax.mod.busy = function( ajobj, opts )
{
var busyobj = IPM.ui.addbusy( opts );
var fn_ontimeout = ajobj.ontimeout || null;
var fn_onerror = ajobj.onerror || null;
var fn_onsuccess = ajobj.onsuccess || null;
if( fn_ontimeout ) ajobj.ontimeout = function() { fn_ontimeout.apply( ajobj, arguments ); busyobj.done(); };
else ajobj.ontimeout = function() { busyobj.done(); };
if( fn_onerror ) ajobj.onerror = function() { fn_onerror.apply( ajobj, arguments ); busyobj.done(); };
else ajobj.onerror = function() { busyobj.done(); };
if( fn_onsuccess ) ajobj.onsuccess = function() { fn_onsuccess.apply( ajobj, arguments ); busyobj.done(); };
else ajobj.onsuccess = function() { busyobj.done(); };
if( opts && opts.autostart )
{
ajobj.start.apply( ajobj, [] );
}
return ajobj;
};
IPM.ajax.mod.loginaware = function( ajobj, opts )
{
var fn_onsuccess = ajobj.onsuccess || null;
var fn_onrelog = (opts && opts.onrelog) || null;
var mayrelog = (opts && opts.mayrelog) || false;
var attempts = 0;
var maxattempts = (opts && opts.maxattempts) || 5;
var pgrefresh = (opts && opts.refreshonlogin) || false;
ajobj.onsuccess =
function()
{
var that = ajobj;
var xhr = that._xhrobj;
var rt = xhr.responseText || "";
if( rt.match( /<title>[^<>]*Log\s*In[^<>]*<\/title>/i ) )
{
if( attempts > maxattempts )
{
if( that.onerror ) that.onerror.apply( that, [that] );
}
else if( !mayrelog )
{
if( that.onerror ) that.onerror.apply( that, [that] );
}
else
{
++attempts;
that._url = that._url.replace( /\?sid=[0-9]+&/i, '?sid=challenge&' );
that.start.apply( that, [] );
}
return;
}
if( rt.match( /document\.location\.replace\(\s*"[^"]+\?sid=([0-9]+)&nsid=true[^>]+<\/script>/i ) )
{
var sid = ""+RegExp.$1;
if( typeof(ipmsid) != "undefined" ) ipmsid = sid;
if( attempts > maxattempts )
{
if( that.onerror ) that.onerror.apply( that, [that] );
return;
}
if( pgrefresh )
{
var loc = ""+document.location;
loc = loc.replace( /\?sid=[^&]+&/i, "?sid=" + ipmsid + "&" );
document.location.replace( loc );
return;
}
if( fn_onrelog ) fn_onrelog.apply( that, [that] );
++attempts;
that._url = that._url.replace( /\?sid=([0-9]+|challenge)&/i, '?sid='+sid+'&' );
that.start.apply( that, [] );
return;
}
attempts = 0;
if( fn_onsuccess )
{
fn_onsuccess.apply( that, [that] );
}
};
if( opts && opts.autostart )
{
ajobj.start.apply( ajobj, [] );
}
return ajobj;
};
// temp ajax replacement
if( !IPM.caches ) IPM.caches = {};
IPM.caches.LIVESTATUS =
{
_cache: [],
nobusy: false,
add: function(obj)
{
var c = IPM.caches.LIVESTATUS;
var ret = c._cache.length;
c._cache.push(obj);
return ret;
},
item: function(n)
{
var c = IPM.caches.LIVESTATUS;
if( c._cache.length <= n ) return null;
return c._cache[n];
},
refreshall: function()
{
var c = IPM.caches.LIVESTATUS;
c._cache.each( function(o) { o.refresh.apply( o, [] ); } );
},
dtor: function()
{
var c = IPM.caches.LIVESTATUS;
c._cache.each( function(o) { o.dtor.apply( o, [] ); } );
c._cache.length = 0;
}
};
IPM.ajax.mod.livestatus = function( ajobj, opts )
{
// need indicator
// need server
// need acct
// need password
// need dest.
// need sound / refresh / etc
if( !ajobj ) ajobj = IPM.ajax.create();
if( !opts ) opts = {};
var ret = new Object();
var autostart = (typeof(opts.autostart) != "undefined") ? opts.autostart : true;
ajobj.ord = IPM.caches.LIVESTATUS.add(ret);
ret.ctx =
{
server: opts.server || "",
sid: (ajobj.acct||ajobj.pw) ? "challenge" : (ipmsid || "challenge"),
preset: opts.preset || "detail",
query: opts.query || "",
postd: opts.postd || null,
nosound: opts.nosound || false,
nomodal: opts.nomodal || false,
errortext: null
};
if( ret.ctx.server ) ret.ctx.sid = "challenge";
else
{
var m;
var loc = "" + window.location;
if( m = loc.match( /^(https?:\/\/[^\/]+)[\/]/i ) ) ret.ctx.server = m[1];
}
ret.oncols    = opts.oncols     || null;
ret.onrows    = opts.onrows     || null;
ret.onmove    = opts.onmove     || null;
ret.onresize  = opts.onresize   || null;
ret.onremove  = opts.onremove   || null;
ret.refresh = function()
{
if( ret.paused || IPM.drag.indrag() || IPM.$('dropitem-src') || (IPM.ui.ismodal() && !IPM.ui.merror_visible()) ) return;
if( IPM.caches.LIVESTATUS.nobusy == false )
ret.busyobj = IPM.ui.addbusy( { nodrag: IPM.drag._lastpos ? true : false, follow: IPM.drag._lastpos ? true : false, text: "Downloading..." } );
var url = ret.ctx.server + "/cfg/cgi?sid=" + ret.ctx.sid + "&area=ajax&action=json&" + ret.ctx.query;
if( /&$/.test( url) == false ) url += "&";
if( ret.ctx.preset != null ) url += "preset=" + ret.ctx.preset + "&";
ret.inds.restart.apply( ret.inds, [{waiting:true}] );
ajobj.start( { url: url, postd: ret.ctx.postd } );
};
ret.pause = function()
{
ret.paused = true;
ajobj.cancel();
};
ret.play = function()
{
ret.paused = false;
ret.refresh();
};
ret.process = function(doc)
{
// can return false
if( (ret.ctx.preset != null) && !ipm_ajaxproto_recvpreset.apply( ret, [doc] ) ) return;
if( !ipm_ajaxproto_recvset.apply( ret, [doc] ) ) return;
if( ret.oncols && !ret.oncols.apply( ret, [] ) ) return;
if( ret.onrows && !ret.onrows.apply( ret, [] ) ) return;
IPM.dom.sethtml( IPM.$(ret.html.datecontainer), ipm_ajax_xlat_datefull(ret.vars.utc) );
ret.error.apply( ret, [null] );
};
ret.lockcolumns = IPM.bind( ret, ipm_ajaxproto_lockcolumns );
ret.error = function(txt)
{
ret.ctx.errortext = txt;
if( !txt ) { IPM.ui.merror_clear(); return; }
if( !ret.ctx.nomodal ) IPM.ui.merror_set(txt,'IPM.caches.LIVESTATUS.refreshall();');
if( !ret.ctx.nosound && ret.vars.sound ) ipm_ajax_playsound(ret.vars.sound);
};
ret.doinsert = function( col, pos )
{
if( col == null || typeof(pos) == "undefined" ) return;
var fn_success = function()
{
ret.ctx.preset = "detail";
ret.refresh();
};
var query_vs = [];
query_vs.push( "add=$0,ui/cols/detail,c&set=$0/kind," + ( col.kind.match( /^t/ ) ? "t" : col.kind ) + "&" );
query_vs.push( "set=$0/value," + col.value + "&" );
query_vs.push( "set=$0/width," + col.width + "&" );
query_vs.push( "set=$0/linked,true&" );
query_vs.push( "set=$0/name," + ( col.name == "" ? col.title : col.name ) + "&set=$0/dirty,true&" );
query_vs.push( "move=$0,$0," + (pos) + ",abs&" );
IPM.ajax.create( ipm_getcfgloc( "ajax", "vs" ), { onsuccess: fn_success }, query_vs.join('') ).start();
};
ret.doresize = function( hdr )
{
if( !hdr || !ret.onresize ) return;
if( hdr.length == 0 ) return;
var parent  = ( IPM.dom.up( hdr[0].ref, "TR" ) );
var tdlen   = parent.childNodes.length;
var delta   = 0;
if( ret.cols.length < ( tdlen - 1 ) ) delta = ( ( tdlen - 1 ) - ret.cols.length );
var fn_success = function() { if( ret.onresize && !ret.onresize.apply( ret, [hdr] ) ) return; };
var postd = [];
hdr.each( function(o)
{
if( !IPM.hasclass( o.ref, "noresize" ) ) postd.push( "find=$0,ui/cols/detail&nth=$1,$0," + (o.ord-delta) + "&set=$1/width," + o.newwidth.replace( /em$/, '' ) + "&set=$1/dirty,true&" );
if( o.ord < ret.cols.length ) ret.cols[o.ord].width = o.newwidth.replace( /em$/, '' );
} );
var ajobj = IPM.ajax.create( ipm_getcfgloc( "ajax", "vs" ), { onsuccess: fn_success }, postd.join('') ).start();
};
ret.domove = function( tdn, tddir, tdlen )
{
if( !ret.onmove ) return;
if( typeof(tdn) == "undefined" || typeof(tddir) == "undefined" || typeof(tdlen) == "undefined" ) return;
var pos   = tdn;
var delta = tddir;
if( ret.cols.length < ( tdlen - 1 ) ) pos -= ( ( tdlen - 1 ) - ret.cols.length );
if( delta > 0 ) delta--;
var fn_success = function()
{
var col = ret.cols.splice( pos, 1 );
ret.cols.splice( ( pos + delta ), 0, col[0] );
ret.rows.each( function(r) { var row = r.v.splice( ( pos ), 1 ); r.v.splice( ( pos + delta ), 0, row[0] ); } );
if( IPM.is.safari || IPM.is.opera )
{
if( ret.oncols && !ret.oncols.apply( ret, [] ) ) return;
if( ret.onrows && !ret.onrows.apply( ret, [] ) ) return;
}
else { if( ret.onmove && !ret.onmove.apply( ret, [tdn, tddir] ) ) return; }
if( ret.lockcolumns ) ret.lockcolumns();
};
var query_vs = [];
query_vs.push( "find=$0,ui/cols/detail&" );
query_vs.push( "nth=$1,$0," + pos + "&" );
query_vs.push( "move=$1,$1," + (pos + delta ) + ",abs&" );
query_vs.push( "set=$1/dirty,true&" );
IPM.ajax.create( ipm_getcfgloc( "ajax", "vs" ), { onsuccess: fn_success }, query_vs.join('') ).start();
};
ret.doremove = function( ord, tdlen )
{
if( !ret.onremove ) return;
if( typeof(ord) == "undefined" || typeof(tdlen) == "undefined" ) return;
var pos = ord;
if( ret.cols.length < ( tdlen - 1 ) ) pos -= ( ( tdlen - 1 ) - ret.cols.length );
var fn_success = function()
{
ret.cols.splice( pos, 1 );
ret.rows.each( function(r) { r.v.splice( pos, 1 ); } );
if( IPM.is.safari || IPM.is.opera )
{
if( ret.oncols && !ret.oncols.apply( ret, [] ) ) return;
if( ret.onrows && !ret.onrows.apply( ret, [] ) ) return;
}
else
{
if( ret.onremove && !ret.onremove.apply( ret, [ord, tdlen] ) ) return;
}
if( ret.lockcolumns ) ret.lockcolumns();
};
IPM.ajax.create( ipm_getcfgloc( "ajax", "vs" ), { onsuccess: fn_success }, "nth=$0,ui/cols/detail," + pos + "&del=$0,&" ).start();
};
ret.dtor = function()
{
ajobj.cancel();
ret.busyobj = null;
ret.html.modality = null;
ret.inds.dtor.apply( ret.inds, [] );
ret.inds = null;
ajobj = null;
};
ret.vars = { refresh: opts.refresh || 1.0, sound: opts.sound || 0 };
ret.cols = null;
ret.rows = null;
ret.html = { tblcontainer: opts.ajaxc || "ajaxc", datecontainer: opts.datec || "datec" };
ret.inds = IPM.ui.indicator.create( opts.ajaxindicators || "ajaxindicators", { waiting: autostart ? true : false, duration: ret.vars.refresh*60, oncountdown: ret.refresh, onrefresh: ret.refresh } );
var fn_ontimeout = ajobj.ontimeout || null;
var fn_onerror = ajobj.onerror || null;
var fn_onsuccess = ajobj.onsuccess || null;
ajobj.ontimeout = function()
{
if( fn_ontimeout ) fn_ontimeout.apply( ajobj, arguments );
ret.error( "Unable to Retrieve Response from Server" );
ret.inds.restart.apply( ret.inds, [{fail:true}] );
if( ret.busyobj && ret.busyobj.done ) ret.busyobj.done();
};
ajobj.onerror = function()
{
if( fn_onerror ) fn_onerror.apply( ajobj, arguments );
ret.error( "Unable to Retrieve Response from Server" );
ret.inds.restart.apply( ret.inds, [{fail:true}] );
if( ret.busyobj && ret.busyobj.done ) ret.busyobj.done();
};
ajobj.onsuccess = function(that)
{
if( fn_onsuccess ) fn_onsuccess.apply( ajobj, arguments );
var xhr = that._xhrobj;
var txt = xhr.responseText;
var doc = eval('(' + txt + ')');
// should error or something.
if( doc ) ret.process(doc);
ret.inds.restart.apply( ret.inds, [{fail: !!ret.ctx.errortext }] );
if( ret.busyobj && ret.busyobj.done ) ret.busyobj.done();
};
IPM.ajax.mod.loginaware( ajobj, { mayrelog: true, refreshonlogin: typeof(opts.refreshonlogin) == "undefined" ? true : opts.refreshonlogin, onrelog: function(){ret.ctx.sid=ipmsid;} } );
if( autostart ) ret.refresh();
return ajobj;
};
function ipm_ajax_saveguardsession_impl()
{
IPM.caches.SING.keepalive.timerhandle = window.setTimeout( ipm_ajax_saveguardsession_impl, 60000 );
var aj = IPM.ajax.create( ipm_getcfgloc('ajax','vs' ), {}, '' );
IPM.ajax.mod.loginaware( aj, { mayrelog: true, refreshonlogin: false } ).start();
}
function ipm_ajax_saveguardsession()
{
var _c = IPM.caches.SING;
if( _c.keepalive ) return;
_c.keepalive =
{
timerhandle: window.setTimeout( ipm_ajax_saveguardsession_impl, 60000 ),
dtor: function()
{
var _k = IPM.caches.SING.keepalive;
if( _k.timerhandle != null ) window.clearTimeout( _k.timerhandle );
}
};
}

IPM.anim_bases.animobj =
{
fps: 25,
duration: 0.5,
next: null,
_f: 0,
_fmax: 0,
_evtitem: null,
_timer: null,
create: function(opts) { return IPM.copy( opts, IPM.copy( IPM.anim_bases.animobj, new Object() ) ); },
start: function( e, domobj, opts )
{
e = e || window.event;
if( this._evtitem ) this._evtitem[0] = null;
this._evtitem = [ IPM.$(domobj) ];
IPM.copy( opts, this );
this._f = 0;
this._fmax = Math.floor(this.duration*this.fps);
if( this.fps ) this._timer = window.setInterval( IPM.bind(this,this.evt_timer), Math.floor(1000/this.fps) );
},
morph: function(e,dest,opts)
{
var src = IPM.anim_bases.animobj;
if( this.fps ) dest.fps = this.fps;
if( this.duration ) dest.duration = this.duration;
['morph','end','render','start','movement','evt_timer','create','prenext'].each( function(s) { dest[s] = src[s]; } );
dest.next = this.next;
this.next = null;
IPM.copy( opts, dest );
},
render: function(e,pos){},
movement: function(e,pos){},
end: function(e){this.dtor();},
prenext: function(){},
revert: function(){},
evt_timer: function()
{
this._f++;
this.render( {}, this._f / this._fmax );
if( this._f >= this._fmax )
{
if( this._timer ) { window.clearInterval( this._timer ); this._timer = null; }
if( this.next )
{
this.prenext();
this.next.morph.apply( this.next, [{},this] );
this._f = 0;
this._fmax = Math.floor(this.duration*this.fps);
if( this.fps ) this._timer = window.setInterval( IPM.bind(this,this.evt_timer), Math.floor(1000/this.fps) );
}
else this.end({});
}
},
dtor: function()
{
if( this._timer ) { window.clearInterval(this._timer); this._timer=null; }
if( this.next && this.next.dtor ) this.next.dtor.apply( this.next, [] );
if( this._evtitem ) { var a = this._evtitem; for( var i=0, imax = a.length; i < imax ; ++i ) a[i] = null; this._evtitem = null; }
this.next = null;
}
};
IPM.anim_bases.move =
{
from: null,
to: null,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.move ) ); },
start: function( e, domobj, opts )
{
IPM.anim_bases.animobj.start.apply( this, [e,domobj,opts] );
if( this.from == null ) this.from = IPM.pos.info( this._evtitem[0] );
if( /^$/.test( this.from.position ) ) IPM.setstyle( this._evtitem[0], "position", "relative" );
},
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( this, [e,dest,opts] );
var src = IPM.anim_bases.move;
['morph','render','create'].each( function(s) { dest[s] = src[s]; } );
dest.from   = IPM.pos.info(dest._evtitem[0]);
dest.to     = this.to;
IPM.copy( opts, dest );
if( /^$/.test( dest._orig.position ) ) IPM.setstyle( dest._evtitem[0], "position", "relative" );
},
render: function(e,pos)
{
var x;
var y;
if( pos >= 1.0 ) { x = this.to.l; y = this.to.t; }
else if( pos <= 0 ) { x = this.from.l; y = this.from.t; }
else
{
x = Math.floor( this.from.l + (this.to.l - this.from.l) * pos );
y = Math.floor( this.from.t + (this.to.t - this.from.t) * pos );
}
IPM.setstyles( this._evtitem[0], ["left",x+"px","top",y+"px"] );
}
};
IPM.anim_bases.shake =
{
from: null,
dist: null,
vary: 0.2,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.shake ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( this, [e,dest,opts] );
var src = IPM.anim_bases.shake;
['morph','render','create'].each( function(s) { dest[s] = src[s]; } );
dest.from   = IPM.pos.info(dest._evtitem[0]);
dest.dist   = this.dist || dest.from.w * this.vary;
IPM.copy( opts, dest );
if( /^$/.test( dest._orig.position ) ) IPM.setstyle( dest._evtitem[0], "position", "relative" );
},
render: function(e,pos)
{
var x;
pos *= 100;
if( pos >= 100 ) x = 0;
else if( pos >= 75.0 ) x = this.dist - Math.floor( (pos-75.0) / 25.0 * this.dist ); // far right to mid
else if( pos >= 50.0 ) x = 0 - this.dist + Math.floor( (pos - 50.0) / 25.0 * this.dist * 2 ); // far left to far right
else if( pos >= 25.0 ) x = this.dist - Math.floor( (pos - 25.0) / 25.0 * this.dist * 2 ); // far right to far left
else x = Math.floor( pos/25.0 * this.dist ); // mid to far right
x += this.from.l;
IPM.setstyle( this._evtitem[0], "left", x + "px" );
}
};
IPM.anim_bases.fade =
{
to: 0.0,
from: 'auto',
kill: false,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.fade ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( this, [e,dest,opts] );
var src = IPM.anim_bases.fade;
['morph','render','create','end','to','from','kill'].each( function(s) { dest[s] = src[s]; } );
IPM.copy( opts, dest );
},
end: function(e)
{
IPM.setstyle( this._evtitem[0], "opacity", this.to );
if( this.kill && this._evtitem[0] )
{
this._evtitem[0].parentNode.removeChild( this._evtitem[0] );
}
IPM.anim_bases.animobj.end.apply( this, [e] );
},
revert: function(e)
{
IPM.setstyle( this._evtitem[0], "opacity", this.from );
IPM.anim_bases.animobj.revert.apply( this, [e] );
if( this.kill && this._evtitem[0] )
{
this._evtitem[0].parentNode.removeChild( this._evtitem[0] );
}
},
render: function(e,pos)
{
if( this.from == 'auto' )
{
this.from = parseFloat(IPM.getstyle(this._evtitem[0],"opacity"));
if( isNaN( this.from ) ) this.from = 1.0;
}
var dist = this.to - this.from;
var o    = this.from + (dist * pos);
if( o < 0.0001 ) o = 0;
else if( o > 0.9999 ) o = 0.9999;
IPM.setstyle( this._evtitem[0], "opacity", o );
}
};

IPM.ui.clone = function(domobj,styles)
{
domobj = IPM.$(domobj);
var pos    = IPM.pos.info(domobj);
var newobj = document.createElement("DIV");
for( var d = domobj.firstChild; d ; d = d.nextSibling ) newobj.appendChild( d.cloneNode(true) );
styles.each( function(s){ var v = IPM.getstyle(domobj,s); if( v != null ) newobj.style[s] = v; } );
var width = pos.w;
var height = pos.h;
// if *not* Internet Explorer
if( !IPM.is.ie || IPM.is.opera )
{
var padl = 0;
var padr = 0;
var padt = 0;
var padb = 0;
try { padl = parseInt( IPM.getstyle( newobj, 'paddingLeft' ).replace(/px$/,''), 10 ); } catch(err) { padl = 0; }
try { padr = parseInt( IPM.getstyle( newobj, 'paddingRight' ).replace(/px$/,''), 10 ); } catch(err) { padr = 0; }
try { padt = parseInt( IPM.getstyle( newobj, 'paddingTop' ).replace(/px$/,''), 10 ); } catch(err) { padt = 0; }
try { padb = parseInt( IPM.getstyle( newobj, 'paddingBottom' ).replace(/px$/,''), 10 ); } catch(err) { padb = 0; }
width -= padl;
width -= padr;
height -= padt;
height -= padb;
if( width < 1 ) width = 1;
if( height < 1 ) height = 1;
}
IPM.setstyles( newobj, ["position","absolute","left",pos.x + "px","top",pos.y + "px","width",width + "px","height",height + "px"] );
return newobj;
}
IPM.anim_bases.follow =
{
duration: 0.2,
slide: false,
_f: 0,
_fmax: 0,
_ptr: null,
_orig: null,
_from: null,
_delta: null,
_xyadj: null,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.follow ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( IPM.anim_bases.animobj, [e,dest,opts] );
alert( 'not supported ' );
},
start: function(e,domobj,opts)
{
e = e || window.event;
if( this._evtitem ) this._evtitem[0] = null;
this._evtitem = [ IPM.$(domobj) ];
this._ptr   = IPM.pos.cursor(e);
this._from  = IPM.pos.info(domobj);
this._orig  = IPM.copy( this._from );
this._delta = { x: 0, y: 0 };
if( opts ) IPM.copy( opts, this );
if( isNaN(this._ptr.x) ) this._ptr = IPM.copy( IPM.drag._lastpos );
if( /^$/.test( this._orig.position ) ) this._evtitem[0].style.position = "relative";
this._f = 0;
this._fmax = 0;
if( this.slide )
{
var moveto = IPM.copy( this._ptr );
moveto.x += 4;
moveto.y += 4;
this._xyadj = IPM.pos.delta( this._from, moveto );
this._fmax = Math.floor(this.duration*this.fps);
if( this._fmax ) this._timer = window.setInterval( IPM.bind(this,this.evt_timer), Math.floor(1000/this.fps) );
}
},
revert: function(e,domobj,isdtor)
{
if( isdtor ) { this.dtor(); return; }
if( this._timer ) { window.clearInterval( this._timer ); this._timer = null; }
IPM.anim_bases.move.morph.apply( IPM.anim_bases.move, [e,this] );
this.start( e, domobj, { to: IPM.copy( this._orig ), duration: 0.3, fps: 25, next: IPM.anim_bases.shake.create({dist:10,duration:0.3}) } );
},
render: function(e,pos)
{
var new_x = this._from.l + this._delta.x;
var new_y = this._from.t + this._delta.y;
IPM.setstyles( this._evtitem[0], ["left",new_x + "px","top",new_y + "px"] );
},
evt_timer: function()
{
this._f++;
var pos = this._fmax ? this._f / this._fmax : 0;
var newx = Math.floor( this._xyadj.x * pos );
if( newx ) { this._from.l += newx; this._from.x += newx; this._xyadj.x -= newx; }
var newy = Math.floor( this._xyadj.y * pos );
if( newy ) { this._from.t += newy; this._from.y += newy; this._xyadj.y -= newy; }
this.render( {}, 0 );
if( this._f >= this._fmax ) { window.clearInterval( this._timer ); this._timer = null; }
},
movement: function( e, domobj, ptr )
{
this._delta = IPM.pos.delta(this._ptr,ptr);
this.render( e, 0 );
}
};
IPM.anim_bases.fwfollow =
{
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.follow.create( IPM.anim_bases.fwfollow ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.follow.morph.apply( IPM.anim_bases.follow, [e,dest,opts] );
alert( 'not supported ' );
},
start: function(e,domobj,opts)
{
e = e || window.event;
IPM.ui.addblocker();
IPM.anim_bases.follow.start.apply( this, [e,domobj,opts] );
},
render: function(e,pos)
{
var new_x = this._from.l + this._delta.x;
var new_y = this._from.t + this._delta.y;
if( new_y < 0 ) new_y = 0;
IPM.setstyles( this._evtitem[0], ["left",new_x + "px","top",new_y + "px"] );
},
prenext: function()
{
IPM.ui.delblocker();
},
revert: function(e,domobj,isdtor)
{
this.prenext();
IPM.anim_bases.follow.revert.apply( this, [e,domobj,isdtor] );
},
end: function(e)
{
var win = IPM.win.item( this._evtitem[0] );
if( win )
{
var new_x = this._from.l + this._delta.x;
var new_y = this._from.t + this._delta.y;
if( new_y < 0 ) new_y = 0;
win.x = new_x;
win.y = new_y;
}
this.prenext();
this.dtor();
}
};
IPM.anim_bases.fwresize =
{
newcursor: "nw-resize",
_f: 0,
_fmax: 0,
_ptr: null,
_from: null,
_delta: null,
_xyadj: null,
_cursor: null,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.fwresize ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( IPM.anim_bases.animobj, [e,dest,opts] );
alert( 'not supported ' );
},
start: function(e,domobj,opts)
{
e = e || window.event;
if( this._evtitem ) this._evtitem[0] = null;
this._evtitem = [ IPM.$(domobj), null, null ];
this._ptr    = IPM.pos.cursor(e);
this._from   = IPM.pos.info(domobj);
this._delta  = { x: 0, y: 0 };
this._cursor = document.documentElement.style.cursor || "";
if( opts ) IPM.copy( opts, this );
if( isNaN(this._ptr.x) ) this._ptr = IPM.copy( IPM.drag._lastpos );
this._f       = 0;
this._fmax    = 0;
this._xyadj   = IPM.pos.delta( this._from, this._ptr );
this._xyadj.x = this._from.w - this._xyadj.x;
this._xyadj.y = this._from.h - this._xyadj.y;
IPM.setstyle( document.documentElement, "cursor", this.newcursor );
IPM.ui.addblocker();
var hilight = document.createElement("DIV");
this._evtitem[2] = hilight;
var new_w = this._from.w - this._xyadj.x;
var new_h = this._from.h - this._xyadj.y;
if( new_w < 60 ) new_w = 60;
if( new_h < 60 ) new_h = 60;
var borderstyle = IPM.$('__modal__') ? "1px dotted #000" : "1px dotted #888";
IPM.setstyles(
hilight,
[ "position", "absolute",
"border", borderstyle,
"left", this._from.x + "px",
"top", this._from.y + "px",
"width", new_w + "px",
"height", new_h + "px",
"zIndex", "" + IPM.z.get_zindex('cursor') ] );
document.body.insertBefore( hilight, document.body.firstChild );
hilight = null;
},
prenext: function()
{
IPM.ui.delblocker();
},
end: function(e)
{
// implement the resize ... and hide the original 'highlight'
// adjust the document element's cursor back to what it was
document.body.removeChild( this._evtitem[2] );
IPM.setstyle( document.documentElement, "cursor", this._cursor );
IPM.ui.delblocker();
var ifr;
if( IPM.hasclass( this._evtitem[0], "fauxtab" ) == true )
{
var divs = IPM.$$(this._evtitem[0],"DIV",10);
var pos = divs.locate( function(o) { return !!o.istabcontainer; } );
if( pos >= 0 ) ifr = divs[pos];
else ifr = null;
}
else
{
ifr = IPM.$$(this._evtitem[0],"IFRAME",1)[0];
}
if( ifr )
{
var objxy = IPM.pos.info( this._evtitem[0] );
var ifrxy = IPM.pos.info( ifr );
var new_w = objxy.w - this._xyadj.x + this._delta.x;
if( new_w < 60 ) new_w = 60;
var new_h = ifrxy.h - this._xyadj.y + this._delta.y;
if( new_h < 60 ) new_h = 60;
IPM.setstyle( this._evtitem[0], "width", new_w + "px" );
IPM.setstyle( ifr, "height", new_h + "px" );
var win = IPM.win.item( ifr );
if( win )
{
win.w = new_w;
win.h = new_h;
}
}
this.dtor();
},
revert: function(e,domobj,isdtor)
{
document.body.removeChild(this._evtitem[2]);
IPM.setstyle( document.documentElement, "cursor", this._cursor );
IPM.ui.delblocker();
if( isdtor ) { this.dtor(); return; }
},
render: function(e,pos)
{
var objxy = IPM.pos.info(this._evtitem[0]);
if( this._evtitem[2] )
{
var new_w = objxy.w - this._xyadj.x + this._delta.x;
if( new_w < 60 ) new_w = 60;
var new_h = objxy.h - this._xyadj.y + this._delta.y;
if( new_h < 60 ) new_h = 60;
IPM.setstyles( this._evtitem[2], [ "height", new_h + "px", "width", new_w + "px" ] );
}
},
movement: function( e, domobj, ptr )
{
this._delta = IPM.pos.delta(this._ptr,ptr);
this.render( e, 0 );
}
};
IPM.anim_bases.tdresize =
{
newcursor: "e-resize",
useemunits: false,
_f: 0,
_fmax: 0,
_ptr: null,
_from: null,
_delta: null,
_xyadj: null,
_cursor: null,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.tdresize ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( IPM.anim_bases.animobj, [e,dest,opts] );
alert( 'not supported ' );
},
start: function(e,domobj,opts)
{
e = e || window.event;
if( this._evtitem ) this._evtitem[0] = null;
this._evtitem = [ IPM.$(domobj), null, null ];
this._ptr    = IPM.pos.cursor(e);
this._from   = IPM.pos.info(domobj);
this._delta  = { x: 0, y: 0 };
this._cursor = document.documentElement.style.cursor || "";
if( opts ) IPM.copy( opts, this );
if( isNaN(this._ptr.x) ) this._ptr = IPM.copy( IPM.drag._lastpos );
this._f       = 0;
this._fmax    = 0;
this._xyadj   = IPM.pos.delta( this._from, this._ptr );
this._xyadj.x = this._from.w - this._xyadj.x;
this._xyadj.y = this._from.h - this._xyadj.y;
IPM.setstyle( document.documentElement, "cursor", this.newcursor );
var hilight = document.createElement("DIV");
this._evtitem[2] = hilight;
var new_w = this._from.w - this._xyadj.x;
if( new_w < 60 ) new_w = 60;
IPM.setstyles( hilight, [ "position", "absolute", "borderLeft","1px dotted #888", "width","2px", "height",this._from.h + "px", "left",this._from.x + new_w + "px", "top", this._from.y + "px", "zIndex", IPM.z.get_zindex('cursor') ] );
document.body.insertBefore( hilight, document.body.firstChild );
hilight = null;
},
absorb: function(a,ord,adj,minpx,dir)
{
if( (ord < 0) || (ord >= a.length) || !adj ) return 0;
var o = a[ord];
if( IPM.hasclass( o.ref, "noresize" ) )
{
return this.absorb( a, ord+dir, adj, minpx, dir );
}
if( minpx < (o.w - adj) )
{
o.w -= adj;
o.ow -= adj;
o.modified = true;
return adj;
}
var avail = o.w - minpx;
if( avail )
{
o.w -= avail;
o.ow -= avail;
o.modified = true;
adj -= avail;
}
return this.absorb( a, ord+dir, adj, minpx, dir ) + avail;
},
adjust: function(a,ord,adj,minpx)
{
if( !adj ) return;
var o = a[ord];
if( IPM.hasclass( o.ref, "noresize" ) ) return;
if( adj > 0 )
{
// we are to add pixels to this cell.
// to do that, we must absorb it from the cells to the right
var x = this.absorb( a, ord+1, adj, minpx, 1 );
if( x )
{
o.w += x;
o.ow += x;
o.modified = true;
}
}
else
{
var x = this.absorb( a, ord, Math.abs( adj ), minpx, -1 );
if( x )
{
o = a[ord+1];
o.w += x;
o.ow += x;
o.modified = true;
}
}
},
end: function(e)
{
// implement the resize ... and hide the original 'highlight'
// adjust the document element's cursor back to what it was
document.body.removeChild(this._evtitem[2]);
IPM.setstyle( document.documentElement, "cursor", this._cursor );
var src = this._evtitem[0];
if( src.tagName == "TD" )
{
var tbl = IPM.dom.up( src, "TABLE" );
if( !tbl )
{
this.dtor();
return;
}
var tr  = IPM.$$(tbl,"TR",1)[0];
var tds = IPM.$$(tr,"TD",250);
var adj = this._delta.x - this._xyadj.x;
if( !adj )
{
this.dtor();
return;
}
var td_sizes = [];
var autotd   = null;
var i        = 0;
var pos      = -1;
tds.each( function(td)
{
if( td == src ) pos = i;
++i;
var o = { ref: td, w: td.clientWidth, ow: td.offsetWidth };
if( (/^auto/i).test( "" + td.style.width ) )
{
if( !autotd )
{
o.auto = true;
autotd = td;
td_sizes.push( o );
return;
}
o.modified = true;
}
td_sizes.push( o );
});
this.adjust( td_sizes, pos, adj, IPM.ui.topx('2.5em')[0] );
var tmp = [];
i = 0;
td_sizes.each( function(o)
{
if( !o.auto && o.modified )
{
var emwidth = Math.round( IPM.ui.toem( o.w )[0] * 10 ) / 10;
tmp.push( { ord: i, ref: o.ref, newwidth: "" + emwidth + "em" } );
}
++i;
});
if( this.doresize )
{
this.doresize( tmp );
}
else
{
tmp.each( function(o) { IPM.setstyle( o.ref, "width", o.newwidth ); } );
}
}
this.dtor();
},
revert: function(e,domobj,isdtor)
{
if( isdtor ) { this.dtor(); return; }
// hide the original 'highlight'
// adjust the document element's cursor back to what it was
document.body.removeChild(this._evtitem[2]);
IPM.setstyle( document.documentElement, "cursor", this._cursor );
},
render: function(e,pos)
{
var objxy = IPM.pos.info(this._evtitem[0]);
if( this._evtitem[2] )
{
var new_w = objxy.w - this._xyadj.x + this._delta.x;
if( new_w < 40 ) new_w = 40;
IPM.setstyles( this._evtitem[2], [ "height", objxy.h + "px", "left", objxy.x + new_w + "px", "top", objxy.y + "px" ] );
}
},
movement: function( e, domobj, ptr )
{
this._delta = IPM.pos.delta(this._ptr,ptr);
this.render( e, 0 );
}
};
IPM.anim_bases.drag =
{
newcursor: "move",
ghost: null,
killghost: true,
cleanup: null,
_f: 0,
_fmax: 0,
_ptr: null,
_orig: null,
_from: null,
_delta: null,
_cursor: null,
create: function(opts) { return IPM.copy( opts, IPM.anim_bases.animobj.create( IPM.anim_bases.drag ) ); },
morph: function(e,dest,opts)
{
IPM.anim_bases.animobj.morph.apply( IPM.anim_bases.animobj, [e,dest,opts] );
alert( 'not supported' );
},
start: function(e,domobj,opts)
{
e = e || window.event;
if( this._evtitem ) this._evtitem[0] = null;
this._evtitem = [ IPM.$(domobj) ];
this._ptr   = IPM.pos.cursor(e);
this._from  = IPM.pos.info(domobj);
this._orig  = IPM.copy( this._from );
this._delta = { x: 0, y: 0 };
this._cursor = document.documentElement.style.cursor ? document.documentElement.style.cursor : "";
if( opts ) IPM.copy( opts, this );
if( isNaN(this._ptr.x) ) this._ptr = IPM.copy( IPM.drag._lastpos );
this._f = 0;
this._fmax = 0;
this._from.l = this._from.x;
this._from.t = this._from.y;
var delt = IPM.pos.delta( this._from, this._ptr );
this._from.l += delt.x + 4;
this._from.t += delt.y + 4;
IPM.setstyle( document.documentElement, "cursor", this.newcursor );
this.render(e,this._ptr);
},
end: function(e)
{
IPM.setstyle( document.documentElement, "cursor", this._cursor );
var hov = IPM.hit.hoveritem();
if( hov )
{
if( hov.drop )
{
hov.drop.apply( hov, [ e, this.hitobj || null ] );
IPM.hit.clear();
IPM.anim_bases.fade.morph( e, this, { kill: this.killghost, duration: 0.4 } );
this.start( e, this.ghost );
this.ghost = null;
return;
}
IPM.hit.clear();
}
this.dtor();
},
revert: function(e,domobj,isdtor)
{
if( isdtor ) { this.dtor(); return; }
IPM.setstyle( document.documentElement, "cursor", this._cursor );
IPM.hit.clear();
this.dtor();
},
render: function(e,pos)
{
var new_x = this._from.l + this._delta.x;
var new_y = this._from.t + this._delta.y;
if( this.ghost ) IPM.setstyles( this.ghost, ["left",""+new_x+"px","top",""+new_y+"px"] );
},
movement: function( e, domobj, ptr )
{
this._delta = IPM.pos.delta(this._ptr,ptr);
this.render( e, 0 );
},
dtor: function()
{
if( this.cleanup ) this.cleanup.apply( this, [] );
if( this.ghost && this.killghost && this.ghost.parentNode ) this.ghost.parentNode.removeChild( this.ghost );
this.ghost = null;
this.hitobj = null;
IPM.anim_bases.animobj.dtor.apply( this, [] );
}
};

IPM.caches.CAL = 
{
_cache: [],
add: function(calobj)
{
var c = IPM.caches.CAL._cache;
if( c ) { var n = c.length; c[n] = calobj; calobj._ord = ""+n; }
},
item: function(arg)
{
if( arguments.length < 1 ) return null;
var c = IPM.caches.CAL._cache;
var imax = c ? c.length : 0;
if( typeof(arg) == "number" ) return (arg < imax) ? c[arg] : null;
arg = IPM.$(arg);
if( !arg ) return null;
for( var i = 0 ; i < imax ; i++ )
{
var a0 = c[i];
if( a0.is.apply( a0, [arg] ) ) return a0;
}
return null;
},
coords: function(domobj)
{
var x1 = 0;
var y1 = 0;
if( domobj && (domobj.tagName != "TD") ) domobj = IPM.dom.up( domobj, "TD" );
if( domobj )
{
for( ;; )
{
var p = IPM.dom.prev( domobj );
if( !p ) break;
domobj = p;
if( domobj.tagName == "TD" ) ++x1;
}
domobj = IPM.dom.up( domobj, "TR" );
}
for( ; domobj ; )
{
var p = IPM.dom.prev( domobj );
if( !p ) break;
domobj = p;
if( domobj.tagName == "TR" ) ++y1;
}
return { x: x1, y: y1 };
},
click: function(e,ord)
{
if( !IPM.caches.CAL._cache || (IPM.caches.CAL._cache.length <= ord) ) return;
e = e || window.event;
var coords = IPM.caches.CAL.coords( e.target || e.srcElement );
var calobj = IPM.caches.CAL._cache[ord];
if( coords.y == 0 ) calobj.selectmonth.apply( calobj, [] );
else if( coords.x == 0 ) calobj.selectweek.apply( calobj, [coords.y-1] );
else calobj.selectday.apply( calobj, [(coords.y-1) * 7 + coords.x-1] );
calobj = null;
},
pgprev: function(e,ord)
{
if( !IPM.caches.CAL._cache || (IPM.caches.CAL._cache.length <= ord) ) return;
e = e || window.event;
var calobj = IPM.caches.CAL._cache[ord];
calobj.pgprev.apply( calobj, [] );
calobj = null;
},
pgnext: function(e,ord)
{
if( !IPM.caches.CAL._cache || (IPM.caches.CAL._cache.length <= ord) ) return;
e = e || window.event;
var calobj = IPM.caches.CAL._cache[ord];
calobj.pgnext.apply( calobj, [] );
calobj = null;
},
dtor: function()
{
var c = IPM.caches.CAL._cache;
if( c ) { c.each( function(o) { if( o && o.dtor ) o.dtor.apply( o, [] ); } ); c.length = 0; }
IPM.caches.CAL._cache = null;
}
};
IPM.ui.CALENDAR =
{
daymode: 0,
timeon: false,
selected: null,
onchange: null,
rangeon: false,
rangeforward: true,
title: null,
_caldiv: null,
_titletxt: null,
_tablediv: null,
_timediv: null,
_durdiv: null,
_tzdiv: null,
_timer: null,
_orig: null,
_start: null,
_end: null,
_origin: null,
_tzarray: null,
_tz: null,
create: function( opts, domobj, norender )
{
if( domobj ) domobj = IPM.$(domobj);
if( !domobj ) domobj = document.createElement("DIV");
var newobj = IPM.copy( opts, IPM.copy( IPM.ui.CALENDAR, new Object() ) );
IPM.caches.CAL.add( newobj );
newobj._caldiv = domobj;
var dinfo = ipm_parse_rangestring( newobj.selected ) || {};
if( !dinfo.start )
{
newobj.setmonth.apply( newobj, [] );
}
else
{
if( (newobj.daymode == 2) && dinfo.start )
{
var hh = dinfo.start.getHours();
var mm = dinfo.start.getMinutes();
var ss = dinfo.start.getSeconds();
if( !hh && !mm && !ss )
{
dinfo.start.setSeconds(-1);
dinfo.end = dinfo.start;
}
}
if( dinfo.advancement == "backtrack" ) newobj.rangeforward = false;
newobj._start  = dinfo.start;
newobj._end    = dinfo.end;
newobj._origin = dinfo.origin;
newobj._tz     = dinfo.tz || null;
newobj.setmonth.apply( newobj, [newobj._origin] );
}
if( !norender ) newobj.render.apply( newobj, [] );
return newobj;
},
is: function( domobj )
{
domobj = IPM.$(domobj);
if( this._caldiv == domobj ) return true;
return false;
},
reassertdate: function()
{
if( !this._start )
{
this.selected = null;
return;
}
if( this.rangeon )
{
var diff;
if( !this._start || !this._end ) diff = { days: 0, hh: 0, mm: 0, ss: 0 };
else diff = ipm_diff_range( this._start, this._end );
diff.days = ""+diff.days; if( diff.days.length < 2 ) diff.days = "0"+diff.days;
diff.hh = ""+diff.hh; if( diff.hh.length < 2 ) diff.hh = "0"+diff.hh;
diff.mm = ""+diff.mm; if( diff.mm.length < 2 ) diff.mm = "0"+diff.mm;
diff.ss = ""+diff.ss; if( diff.ss.length < 2 ) diff.ss = "0"+diff.ss;
var sel = ipm_stringdate( this._origin ) + (this.rangeforward?";+":";-") + diff.days + "." + diff.hh + ":" + diff.mm + ":" + diff.ss;
this.selected = sel;
}
else if( this._end && this.daymode != 2 )
{
this.selected = ipm_stringdate( this._start ) + ";" + ipm_stringdate( this._end );
}
else
{
var d1 = this._start;
this.selected = ipm_stringdate( d1 );
}
if( this._tz != null ) this.selected += ";tz:" + this._tz;
},
render: function(opts)
{
if( opts )
{
IPM.copy( opts, this );
if( opts.selected )
{
// selected is a read-only property after creation.
this.rangeforward = true;
var dinfo = ipm_parse_rangestring( this.selected ) || {};
if( dinfo.start )
{
if( this.daymode == 2 )
{
var hh = dinfo.start.getHours();
var mm = dinfo.start.getMinutes();
var ss = dinfo.start.getSeconds();
if( !hh && !mm && !ss )
{
dinfo.start.setSeconds(-1);
dinfo.end = dinfo.start;
}
}
if( dinfo.advancement == "backtrack" ) this.rangeforward = false;
this._start  = dinfo.start;
this._end    = dinfo.end;
this._origin = dinfo.origin;
this._tz     = dinfo.tz || null;
}
}
}
if( !this.timeon && this.rangeon ) this.rangeon = false;
var hh = "00";
var mm = "00";
var ss = "00";
var dd2 = "00", hh2 = "00", mm2 = "00", ss2 = "00";
var pdate = this.rangeon ? this._origin : this._start;
if( pdate )
{
hh = ""+pdate.getHours();
mm = ""+pdate.getMinutes();
ss = ""+pdate.getSeconds();
if( hh.length < 2 ) hh = "0"+hh;
if( mm.length < 2 ) mm = "0"+mm;
if( ss.length < 2 ) ss = "0"+ss;
pdate = null;
}
if( this.rangeon && this._start && this._end )
{
var ret = ipm_diff_range( this._start, this._end );
dd2 = ""+ret.days;
hh2 = ""+ret.hh; if( hh2.length < 2 ) hh2 = "0"+hh2;
mm2 = ""+ret.mm; if( mm2.length < 2 ) mm2 = "0"+mm2;
ss2 = ""+ret.ss; if( ss2.length < 2 ) ss2 = "0"+ss2;
}
if( !this._tablediv )
{
IPM.dom.sethtml(this._caldiv,"");
var inner    = document.createElement( "DIV" );
var pgleft   = document.createElement( "DIV" );
var pgright  = document.createElement( "DIV" );
var title    = document.createElement( "DIV" );
var titletxt = document.createElement( "SPAN" );
var tbldiv   = document.createElement( "DIV" );
var timediv  = document.createElement( "DIV" );
var durdiv   = document.createElement( "DIV" );
var brkdiv   = document.createElement( "DIV" );
var tzdiv    = document.createElement( "DIV" );
this._caldiv.appendChild( inner );
inner.appendChild( title );
title.appendChild( pgleft );
title.appendChild( pgright );
title.appendChild( titletxt );
inner.appendChild( tbldiv );
inner.appendChild( timediv );
inner.appendChild( durdiv );
inner.appendChild( tzdiv );
brkdiv.appendChild( document.createComment("") );
title.appendChild( brkdiv );
IPM.setstyle( brkdiv, "clear", "both" );
inner.className   = "calinner";
pgleft.className  = "pgleft";
pgleft.onclick    = new Function("IPM.caches.CAL.pgprev(arguments[0]," + this._ord + ");");
IPM.dom.sethtml(pgleft,"<a href='#' onclick='IPM.f(event);'><img alt='previous' src='/cfg/v8/icon_cal_arrow_left.png'></a>");
pgright.className = "pgright";
pgright.onclick   = new Function("IPM.caches.CAL.pgnext(arguments[0]," + this._ord + ");");
IPM.dom.sethtml(pgright,"<a href='#' onclick='IPM.f(event);'><img alt='next' src='/cfg/v8/icon_cal_arrow_right.png'></a>");
title.className   = "caltitle";
timediv.className = "caltime";
if( !this.timeon ) IPM.setstyle( timediv, "display", "none" );
IPM.dom.sethtml(timediv,"<span style='text-align: left;'>TIME</span><input type='text' onkeydown='ipm_cal_keydown(event,0);' onblur='ipm_cal_blur(event,0," + this._ord + ");' value='" + hh + "'>:<input type='text' onkeydown='ipm_cal_keydown(event,1);' onblur='ipm_cal_blur(event,1," + this._ord + ");' value='" + mm + "'>:<input type='text' onkeydown='ipm_cal_keydown(event,2);' onblur='ipm_cal_blur(event,2," + this._ord + ");' value='" + ss + "'>");
durdiv.className  = "caltime";
IPM.dom.sethtml(durdiv,"<span onclick='ipm_cal_rngtoggle("+ this._ord +"); IPM.evt.cancel(event);' style='text-align: left; padding-right: 12px; background: url(/cfg/v8/icon_cal_arrow_updown.png) no-repeat center right;'><a href='#' onclick='return false;'>" + (this.rangeforward?"ADVANCE":"BACKTRACK") + "</a></span><input type='text' onkeydown='ipm_cal_keydown(event,-1);' onblur='ipm_cal_blur(event,-1," + this._ord + ");' value='" + dd2 + "'>days, <input type='text' onkeydown='ipm_cal_keydown(event,0);' onblur='ipm_cal_blur(event,0," + this._ord + ");' value='" + hh2 + "'>:<input type='text' onkeydown='ipm_cal_keydown(event,1);' onblur='ipm_cal_blur(event,1," + this._ord + ");' value='" + mm2 + "'>:<input type='text' onkeydown='ipm_cal_keydown(event,2);' onblur='ipm_cal_blur(event,2," + this._ord + ");' value='" + ss2 + "'>" );
if( !this.rangeon ) IPM.setstyle( durdiv, "display", "none" );
{
tzdiv.className  = "caltime";
var wr = IPM.aux.writer(tzdiv);
wr.write( "<span style='text-align: left; margin-top: 0.2em;'>TIME ZONE</span><select onchange='ipm_cal_tzchange(event,", "" + this._ord, ");' style='border: 1px solid #fff; margin-top: 2px;'>" );
if( this.tzarray )
{
var tz = this._tz || null;
this.tzarray.each( function(s) {
var vals = s.split(';');
wr.write( "<option " );
if( (tz == parseInt(vals[0])) || ((tz == null) && parseInt(vals[1])) ) wr.write( "selected " );
wr.write( "value='", vals[0], "'>", vals[2], "</option>" );
} );
}
wr.write( "</select>" );
wr.flush();
if( !this.showtz ) IPM.setstyle( tzdiv, "display", "none" );
}
this._tablediv = tbldiv;
this._titletxt = titletxt;
this._timediv  = timediv;
this._durdiv   = durdiv;
this._tzdiv    = tzdiv;
inner    = null;
pgleft   = null;
pgright  = null;
title    = null;
tbldiv   = null;
titletxt = null;
timediv  = null;
durdiv   = null;
}
else
{
var col = IPM.$$(this._timediv,"INPUT");
col[0].value = hh;
col[1].value = mm;
col[2].value = ss;
var col = IPM.$$(this._durdiv,"INPUT");
col[0].value = dd2;
col[1].value = hh2;
col[2].value = mm2;
col[3].value = ss2;
IPM.setstyle( this._timediv, "display", this.timeon ? "" : "none" );
IPM.setstyle( this._durdiv, "display", this.rangeon ? "" : "none" );
IPM.setstyle( this._tzdiv, "display", this.showtz ? "" : "none" );
if( this.showtz )
{
var sel = IPM.$$( this._tzdiv, "SELECT", 1 )[0];
if( this._tz == null ) sel.selectedIndex = 0;
else sel.value = this._tz;
}
}
var w      = IPM.aux.writer(this._tablediv);
var info   = this._monthinfo;
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var ctxt   = "IPM.caches.CAL.click(event," + this._ord + ");";
w.write(
"<table class='caltable' style='clear: both; table-layout: fixed; width: 100%;' cellspacing=0 cellpadding=0 border=0>",
"<tr class=hdr><td class='sel",
this.daymode ? " nil2'>&nbsp;" : ("' onclick='" + ctxt + "'><a href='#' onclick='IPM.f(event);'><img alt='month' src='/cfg/v8/icon_cal_arrow_all.png'></a>" ),
"</td><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>" );
var start = 1;
var debt  = info.start;
var done  = false;
var dtnow = new Date();
var tday  = dtnow.getDate();
var isthism = (dtnow.getMonth() == this._monthinfo.monthord) && (dtnow.getFullYear() == this._monthinfo.year);
var isthist;
var mday;
for( var n = 0; !done ; ++n )
{
w.write( "</tr><tr><td class='sel", this.daymode ? " nil2'>&nbsp;" : ("' onclick='" + ctxt + "'><a href='#' onclick='IPM.f(event);'><img alt='select week' src='/cfg/v8/icon_cal_arrow_row.png'></a>"), "</td>" );
for( var j = 0; j < 7; ++j )
{
mday = debt ? info.prevdays - debt + 1 : start;
isthist = isthism && (mday == tday) && (debt == 0);
w.write( "<td class='", debt ? "empty" : "day", isthist ? " today" : "", "' onclick='", ctxt, "'><a href='#' onclick='IPM.f(event);'>", mday, "</a></td>" );
if( debt ) debt--;
else if( start >= info.days ) { debt = info.prevdays; done = true; }
else start++;
}
}
w.write( "</tr><tr>" );
for( var i = 0; i < 8; ++i ) w.write( "<td class=nil>&nbsp;</td>" );
w.write( "</tr></table>" );
IPM.setstyle( this._timediv, "display", !this.timeon ? "none" : "" );
IPM.dom.sethtml( this._titletxt, (this.title||"") + months[info.monthord] + ", " + info.year );
w.flush();
this._caldiv.className = "calouter";
if( this._timer )
{
window.clearTimeout( this._timer );
this._timer = null;
}
if( this.selected )
{
this._timer = window.setTimeout( IPM.bind( this, this.highlight ), 50 );
}
w    = null;
info = null;
},
gettime: function()
{
var ret = { hh: 0, mm: 0, ss: 0, dd2: 0, hh2: 0, ss2: 0 };
if( this.timeon && this._timediv )
{
var col = IPM.$$(this._timediv,"INPUT");
try { ret.hh = parseInt( col[0].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
try { ret.mm = parseInt( col[1].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
try { ret.ss = parseInt( col[2].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
if( isNaN( ret.hh ) ) ret.hh = 0;
if( isNaN( ret.mm ) ) ret.mm = 0;
if( isNaN( ret.ss ) ) ret.ss = 0;
if( this.rangeon && this._durdiv )
{
var col = IPM.$$(this._durdiv,"INPUT");
try { ret.dd2 = parseInt( col[0].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
try { ret.hh2 = parseInt( col[1].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
try { ret.mm2 = parseInt( col[2].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
try { ret.ss2 = parseInt( col[3].value.replace( /^\s*0+/, '' ) ); } catch(err) {}
if( isNaN( ret.dd2 ) ) ret.dd2 = 0;
if( isNaN( ret.hh2 ) ) ret.hh2 = 0;
if( isNaN( ret.mm2 ) ) ret.mm2 = 0;
if( isNaN( ret.ss2 ) ) ret.ss2 = 0;
}
}
return ret;
},
setmonth: function()
{
var now       = arguments.length ? arguments[0] : null;
now = now || new Date();
var year      = now.getFullYear();
var month     = now.getMonth();
var upyear    = (month == 11) ? year+1 : year;
var upmonth   = (month == 11) ? 0 : month+1;
var downyear  = (month == 0) ? year-1 : year;
var downmonth = (month == 0) ? 11 : month-1;
var thismonth = new Date( year, month, 1 );
var nextmonth = new Date( upyear, upmonth, 1 );
var lastmonth = new Date( downyear, downmonth, 1 );
this._monthinfo = {
days: Math.floor((((nextmonth.getTime() - thismonth.getTime()) / 1000) + 60*120) / 86400),
start: thismonth.getDay(),
monthord: month,
year: year,
prevdays: Math.floor((((thismonth.getTime() - lastmonth.getTime()) / 1000) + 60*120) / 86400) };
now       = null;
thismonth = null;
nextmonth = null;
lastmonth = null;
},
selectmonth: function()
{
var dayn = this._monthinfo.start;
var n    = this._monthinfo.days-1;
this._start  = new Date( this._monthinfo.year, this._monthinfo.monthord, 1 );
this._end    = new Date( this._monthinfo.year, this._monthinfo.monthord + 1, 1, 0, 0, 0 );
this._origin = this._start;
this.rangeforward = true;
this.reassertdate();
this.highlight(dayn,dayn+n);
if( this.onchange ) this.onchange( this.selected );
},
selectweek: function(n)
{
var dayn = n*7;
var d1       = this.getdate2(dayn);
this._start  = d1;
this._end    = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate()+7, 0, 0, 0 );
this._origin = this._start;
this.rangeforward = true;
this.reassertdate();
this.highlight(dayn,dayn+6);
if( this.onchange ) this.onchange( this.selected );
},
selectday: function(n)
{
var t = this.gettime();
var d1 = this.getdate2(n,t.hh,t.mm,t.ss);
if( !this.rangeon )
{
this.rangeforward = true;
if( this.daymode == 2 )
{
if( !this._start )
{
t.hh = 23;
t.mm = 59;
t.ss = 59;
// push changes.
if( this._timediv )
{
var col = IPM.$$(this._timediv,"INPUT");
col[0].value = t.hh;
col[1].value = t.mm;
col[2].value = t.ss;
}
}
this._origin = this._start = this._end = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate(), t.hh, t.mm, t.ss );
}
else
{
this._start = d1;
this._end   = this.timeon ? null : new Date( d1.getFullYear(), d1.getMonth(), d1.getDate()+1, 0, 0, 0 );
this._origin = this._start;
}
}
else
{
var diff;
if( !this._start || !this._end ) diff = { days: 0, hh: 0, mm: 0, ss: 0 };
else diff = ipm_diff_range( this._start, this._end );
var op = this.rangeforward ? 1 : -1;
var d2 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() + (diff.days*op), d1.getHours() + (diff.hh*op), d1.getMinutes() + (diff.mm*op), d1.getSeconds() + (diff.ss*op) );
this._origin = d1;
if( this.rangeforward ) { this._start = d1; this._end = d2; }
else { this._start = d2; this._end = d1; }
}
this.reassertdate();
this.highlight(n,n);
if( this.onchange ) this.onchange( this.selected );
},
timechange: function()
{
if( !this._start || !this.timeon ) return;
var t = this.gettime();
if( this.rangeon )
{
var op = this.rangeforward ? 1 : -1;
var d1 = this._origin;
var d2 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate(), t.hh, t.mm, t.ss );
var d3 = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() + (t.dd2*op), d2.getHours() + (t.hh2*op), d2.getMinutes() + (t.mm2*op), d2.getSeconds() + (t.ss2*op) );
if( this.rangeforward )
{
if( (this._start.getTime() == d2.getTime()) && (this._end == d3.getTime()) ) return;
this._start  = d2;
this._end    = d3;
this._origin = d2;
}
else
{
if( (this._start.getTime() == d3.getTime()) && (this._end == d2.getTime()) ) return;
this._start = d3;
this._end   = d2;
this._origin = d2;
}
}
else
{
var d1 = this._start;
var d2 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate(), t.hh, t.mm, t.ss );
if( d1.getTime() == d2.getTime() ) return;
this._start = d2;
}
this.reassertdate();
if( this.onchange ) this.onchange( this.selected );
},
tzchange: function()
{
if( !this.showtz ) return;
var val = IPM.$$(this._tzdiv,"SELECT",1)[0].value;
this._tz = val;
this.reassertdate();
if( this.onchange ) this.onchange( this.selected );
},
rangetoggle: function()
{
if( !this.rangeon || !this._durdiv ) return;
this.rangeforward = this.rangeforward ? false : true;
IPM.dom.sethtml( IPM.$$(this._durdiv,"A",1)[0], this.rangeforward ? "ADVANCE" : "BACKTRACK" );
var t  = this.gettime();
var d1 = this._origin;
var diff;
if( !this._start || !this._end ) diff = { days: 0, hh: 0, mm: 0, ss: 0 };
else diff = ipm_diff_range( this._start, this._end );
var op = this.rangeforward ? 1 : -1;
var d2 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() + (diff.days*op), d1.getHours() + (diff.hh*op), d1.getMinutes() + (diff.mm*op), d1.getSeconds() + (diff.ss*op) );
if( this.rangeforward ) { this._start = d1; this._end = d2; }
else { this._start = d2; this._end = d1; }
this.reassertdate();
if( this.onchange ) this.onchange( this.selected );
},
pgprev: function()
{
var dt = new Date(this._monthinfo.year,this._monthinfo.monthord,0-1);
if( dt.getFullYear() < 1993 ) return;
this.setmonth( dt );
this.render();
},
pgnext: function()
{
var dt = new Date(this._monthinfo.year,this._monthinfo.monthord,1+this._monthinfo.days);
if( dt.getFullYear() >= 2035 ) return;
this.setmonth( dt );
this.render();
},
getdate2: function(n1,hh,mm,ss)
{
var month = this._monthinfo.monthord;
var year  = this._monthinfo.year;
var start = this._monthinfo.start;
var days  = this._monthinfo.days;
var day;
if( n1 < start )
{
month--;
if( month < 0 ) { month = 11; year--; }
day = this._monthinfo.prevdays - (start - n1) + 1;
}
else if( n1 >= (start + days) )
{
month++;
if( month > 11 ) { month = 0; year++; }
day = n1 - (start + days) + 1;
}
else day = n1 - start + 1;
return new Date( year, month, day, hh || 0, mm || 0, ss || 0 );
},
getpos: function()
{
if( !this._start ) return null;
var RngStart;
var RngEnd;
{
var d1 = new Date( this._start.getFullYear(), this._start.getMonth(), this._start.getDate() );
var d2 = this._end ? new Date( this._end.getFullYear(), this._end.getMonth(), this._end.getDate() ) : d1;
var d1_ticks = d1.getTime();
var d2_ticks = d2.getTime();
if( d1_ticks > d2_ticks ) { RngStart = d2; RngEnd = d1; }
else { RngStart = d1; RngEnd = d2; }
if( this.rangeon )
{
var d1 = this._origin;
var d2 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate(), 0, 0, 0 );
RngEnd = RngStart = d2;
}
else if( this._end && (d1_ticks != d2_ticks) )
{
if( !this._end.getHours() && !this._end.getMinutes() && !this._end.getSeconds() )
{
RngEnd.setDate( RngEnd.getDate()-1 );
}
}
}
var overflow = (this._monthinfo.start + this._monthinfo.days) % 7;
if( overflow ) overflow = 7 - overflow;
var maxdays  = this._monthinfo.start + this._monthinfo.days + overflow;
var VisStart = new Date( this._monthinfo.year, this._monthinfo.monthord, 1 - this._monthinfo.start );
var VisEnd   = new Date( this._monthinfo.year, this._monthinfo.monthord, this._monthinfo.days + overflow );
var nstart   = null;
var ncollect = 0;
for( var n = 0; VisStart <= VisEnd ; )
{
if( (VisStart >= RngStart) && (VisStart <= RngEnd) )
{
if( !ncollect ) nstart = n;
++ncollect;
}
VisStart.setDate(VisStart.getDate()+1);
++n;
}
RngStart = null;
RngEnd   = null;
VisStart = null;
VisEnd   = null;
if( !ncollect ) return null;
return { n1: nstart, n: ncollect-1 };
},
highlight: function()
{
var n1;
var n2;
if( arguments.length < 2 )
{
if( !this.selected ) return;
var pos = this.getpos();
if( !pos ) return;
n1 = pos.n1;
n2 = pos.n1 + pos.n;
}
else
{
n1 = arguments[0];
n2 = arguments[1];
}
if( this._timer )
{
window.clearTimeout( this._timer );
this._timer = null;
}
var domobj = null;
try { domobj = IPM.$$(this._caldiv,"TABLE",1)[0]; } catch(err) {}
if( !domobj ) return;
var col = IPM.$$(domobj,"TD");
if( n1 < 0 ) n1 = 0;
if( n2 < n1 ) n2 = n1;
var tds = [];
var cls = [];
for( var i = 0, imax = col.length; i < imax ; ++i ) { tds[i] = col[i]; cls[i] = ""; }// col isn't *really* an array.
col = null;
var pos = 0;
for( var i = 8, imax = tds.length; i < imax; ++pos, ++i )
{
var mod  = i%8;
var plot = false;
var want = "b";
if( !mod )
{
// plot the 'left'
if( (pos >= n1) && (pos <= n2) ) cls[i] = "b66";
++i;
}
else
{
// plot the 'left'
if( pos == n1 ) cls[i-1] = "b66";
--mod;
}
// plot the 'top'
if( (pos >= n1) && (pos <= n2) && ((pos - 7) < n1) )
{
want += "8";
}
// plot the 'bottom'
if( (pos > n2) && ((pos-7) >= n1) && ((pos-7) <= n2) ) want += "88";
if( (pos >= n1) && (pos <= n2) )
{
// plot the 'right'
if( (pos == n2) || (mod == 6) ) want += "6";
}
// plot the 'middle'
if( want != "b" ) cls[i] = want;
else if( (pos >= n1) && (pos <= n2) ) cls[i] = "b0";
}
for( var i = 8, imax = tds.length; i < imax ; ++i )
{
var cn    = cls[i] || "";
var exist = tds[i].className || "";
if( cn ) cn = " " + cn;
var want  = exist.replace( /\sb[0-9]+$/g, '' ) + cn;
if( exist == want ) continue;
tds[i].className = want;
}
for( var i = 0, imax = tds.length; i < imax ; ++i ) tds[i] = null;
tds = null;
},
dtor: function()
{
if( this._timer != null ) window.clearTimeout( this._timer );
if( this._caldiv )
{
var col = IPM.$$(this._caldiv,"DIV",1);
try
{
col[0].onclick = null;
col[1].onclick = null;
}
catch(err)
{
}
col = null;
}
this._caldiv = null;
this._titletxt = null;
this._tablediv = null;
this._timediv = null;
this._timer = null;
this._durdiv = null;
this._tzdiv = null;
this.onchange = null;
}
};
IPM.ui.DATERANGE =
{
allownone: false,
onchange: null,
selected: null,
mode: 'normal',
tzarray: null,
_cont: null,
_cal1: null,
_cal2: null,
_rads: null,
_sel1: null,
_sel2: null,
create: function( opts, domobj )
{
if( domobj ) domobj = IPM.$(domobj);
if( !domobj ) domobj = document.createElement("DIV");
var newobj = IPM.copy( opts, IPM.copy( IPM.ui.DATERANGE, new Object() ) );
if( newobj.selected ) newobj.selected = newobj.normalizetz.apply( newobj, [newobj.selected] );
IPM.caches.CAL.add( newobj );
newobj._cont = domobj;
if( newobj.mode != "none" && newobj.mode != "range" && newobj.mode != "recent" ) newobj.mode = "normal";
if( newobj.mode == "none" && !newobj.allownone ) newobj.mode = "normal";
newobj._cal1 = IPM.ui.CALENDAR.create( { tzarray: newobj.tzarray, onchange: IPM.bind(newobj,newobj.cal1change) }, domobj.appendChild( document.createElement( "DIV" ) ), true );
newobj._cal2 = IPM.ui.CALENDAR.create( { onchange: IPM.bind(newobj,newobj.cal2change) }, domobj.appendChild( document.createElement( "DIV" ) ), true );
newobj._rads = document.createElement( "DIV" );
newobj._rads.className = "rngrads";
IPM.setstyle( newobj._cal1._caldiv, "display", "none" );
IPM.setstyle( newobj._cal2._caldiv, "display", "none" );
newobj._cal1._caldiv.className = "calouter";
newobj._cal2._caldiv.className = "calouter";
domobj.appendChild( newobj._cal1._caldiv );
domobj.appendChild( newobj._cal2._caldiv );
domobj.appendChild( newobj._rads );
IPM.setstyle( domobj.appendChild( document.createElement("DIV") ), "clear", "both" );
IPM.setstyles( newobj._cal1._caldiv, ["width","26em","marginTop","0.5em","float","left"] );
IPM.setstyles( newobj._cal2._caldiv, ["width","26em","marginTop","0.5em","float","left"] );
var w = IPM.aux.writer(newobj._rads);
var n = "" + newobj._ord;
w.write( "<div class='rngtitle' style='margin-bottom: 0.5em;'>SELECTION TYPE</div>" );
if( newobj.allownone ) w.write( "<div><input type='radio' class='chk' id=rng0id0", n, " name='rng0", n, "' ", newobj.mode == "none" ? "checked " : "", "onclick='IPM.caches.CAL.item(", n, ").render( { mode: \"none\" } );'><label for='rng0id0", n, "'>None</label></div>" );
w.write( "<div><input type='radio' class='chk' id=rng1id0", n, " name='rng0", n, "' ", newobj.mode == "normal" ? "checked " : "", "onclick='IPM.caches.CAL.item(", n, ").render( { mode: \"normal\" } );'><label for='rng1id0", n, "'>Normal</label></div>" );
w.write( "<div><input type='radio' class='chk' id=rng2id0", n, " name='rng0", n, "' ", newobj.mode == "range" ? "checked " : "", "onclick='IPM.caches.CAL.item(", n, ").render( { mode: \"range\" } );'><label for='rng2id0", n, "'>Date Range</label></div>" );
w.write( "<div><input type='radio' class='chk' id=rng3id0", n, " name='rng0", n, "' ", newobj.mode == "recent" ? "checked " : "", "onclick='IPM.caches.CAL.item(", n, ").render( { mode: \"recent\" } );'><label for='rng3id0", n, "'>Recent Activity</label></div>" );
w.write( "<div class='rngtitle' style='margin-top: 1em; margin-bottom: 0.5em;'>QUICK SELECT</div>" );
w.write( "<div><select id=rng0sel", n, ">" );
[
{ txt: '-- Options --', val: '' },
{ txt: 'Last 15 Minutes', val: 'm;0;-15;3' },
{ txt: 'Last 30 Minutes', val: 'm;0;-30;3' },
{ txt: 'Last 60 Minutes', val: 'm;0;-60;3' },
{ txt: 'This Hour', val: 'h;0;1;1' },
{ txt: 'Last Hour', val: 'h;-1;1;1' },
{ txt: 'Today', val: 'd;0;1;0' },
{ txt: 'Yesterday', val: 'd;-1;1;0' },
{ txt: 'Last 24 Hours', val: 'm;-1440;1440;1' },
{ txt: 'This Week', val: 'w;0;1;0' },
{ txt: 'Last 7 Days', val: 'd;-6;7;0' },
{ txt: 'Last Week', val: 'w;-1;1;0' },
{ txt: 'This Month', val: 'M;0;1;0' },
{ txt: 'Last Month', val: 'M;-1;1;0' }
].each( function(o) { w.write( "<option value='", IPM.ui.encode( o.val ), "'>", IPM.ui.encode( o.txt ), "</option>" ); } );
w.write( "</select><input type=button class=btn style='margin-left: 0.5em;' value='Select' onclick=\"ipm_cal_rngquick(event,", newobj._ord, ");\"><div>" );
w.flush();
newobj.render.apply( newobj, [] );
return newobj;
},
render: function(opts)
{
var m = this.mode || null;
if( opts ) IPM.copy( opts, this );
if( opts && opts.selected ) this.selected = this.normalizetz( this.selected );
// given the state of things, toggle certain divs & translate time selections.
if( this.mode != "range" )
{
this._sel1 = null;
this._sel2 = null;
}
if( this.mode == "none" )
{
IPM.setstyle( this._cal1._caldiv, "display", "none" );
IPM.setstyle( this._cal2._caldiv, "display", "none" );
if( this.onchange ) this.onchange( "" );
}
else if( this.mode == "range" )
{
// if no selections are present, extract them from the current selection text
// next, construct left & rights
if( !this._sel1 || !this._sel2 || opts.selected )
{
this._sel1 = ipm_parse_rangestring( this.selected );
this._sel1.advancement = null;
this._sel2 = IPM.copy( this._sel1 );
this._sel2.start = this._sel2.end;
this._sel2.end = this._sel1.end = null;
}
var sel2_start = this._sel2.start;
if( sel2_start )
{
var _y  = sel2_start.getFullYear();
var _mn = sel2_start.getMonth();
var _md = sel2_start.getDate();
var _h  = sel2_start.getHours();
var _m  = sel2_start.getMinutes();
var _s  = sel2_start.getSeconds();
if( (_md == 1) && _h == 0 && _m == 0 && _s == 0 ) sel2_start = new Date( _y, _mn-1, _md, _h, _m, _s );
}
this._cal1.setmonth.apply( this._cal1, [this._sel1.start] );
this._cal2.setmonth.apply( this._cal2, [sel2_start] );
IPM.setstyle( this._cal1._caldiv, "display", "" );
IPM.setstyle( this._cal2._caldiv, "display", "" );
this._cal1.render( { timeon: true, daymode: 1, rangeon: false, showtz: this.tzarray != null, selected: ipm_make_rangestring( this._sel1 ) } );
this._cal2.render( { timeon: true, daymode: 2, rangeon: false, showtz: false, selected: ipm_make_rangestring( this._sel2 ) } );
}
else if( this.mode == "recent" )
{
IPM.setstyle( this._cal1._caldiv, "display", "" );
IPM.setstyle( this._cal2._caldiv, "display", "none" );
var v = ipm_parse_rangestring( this.selected );
this._cal1.setmonth.apply( this._cal1, [v.origin] );
this._cal1.render( { timeon: true, daymode: 1, rangeon: true, showtz: this.tzarray != null, selected: this.selected } );
}
else
{
IPM.setstyle( this._cal1._caldiv, "display", "" );
IPM.setstyle( this._cal2._caldiv, "display", "none" );
var v = ipm_parse_rangestring( this.selected );
this._cal1.setmonth.apply( this._cal1, [v.start] );
this._cal1.render( { timeon: false, daymode: 0, rangeon: false, showtz: this.tzarray != null, selected: this.selected } );
}
if( m != this.mode )
{
var n = 0;
if( this.mode == "none" ) n = 0;
else if( this.mode == "recent" ) n = 3;
else if( this.mode == "range" ) n = 2;
else n = 1;
if( !this.allownone ) n--;
var chkd = IPM.$$(this._rads,"INPUT")[n];
if( chkd && !chkd.checked ) chkd.checked = true;
}
},
cal1change: function(sel)
{
if( this.mode == "none" ) return;
var dinfo = ipm_parse_rangestring(sel);
if( this.mode == "range" )
{
var tmp = ipm_parse_rangestring( sel );
tmp.origin = tmp.start;
tmp.end = this._sel2.start;
tmp.advancement = null;
this._sel1 = tmp;
this.selected = ipm_make_rangestring( tmp ) + ";uihint:1";
}
else
{
var sel1 = ipm_make_rangestring( dinfo ) + ";uihint:";
if( this.mode != "recent" ) sel1 += "0";
else if( dinfo.advancement == "backtrack" ) sel1 += "3";
else sel1 += "2";
this.selected = sel1;
}
if( this.onchange ) this.onchange( this.selected );
},
cal2change: function(sel)
{
if( this.mode != "range" ) return;
var v1  = ipm_parse_rangestring( sel );
var hh = v1.start.getHours();
var mm = v1.start.getMinutes();
var ss = v1.start.getSeconds();
if( hh==23 && mm==59 && ss==59 ) v1.start.setSeconds(v1.start.getSeconds()+1);
var tmp = IPM.copy( this._sel1 );
tmp.origin = tmp.start;
tmp.end = v1.start;
tmp.advancement = null;
this._sel1 = tmp;
this._sel2 = v1;
this.selected = ipm_make_rangestring( tmp ) + ";uihint:1";
if( this.onchange ) this.onchange( this.selected );
},
normalizetz: function(sel)
{
if( !sel ) return null;
var info = ipm_parse_rangestring( sel );
if( info.tz != null ) return sel;
if( typeof(this.currenttz) == "undefined" )
{
if( !this.tzarray ) return sel;
var that = this;
var pos = this.tzarray.locate( function(s) {
var vals = s.split(';');
if( vals[1] != "0" ) { that.currenttz = vals[0]; return true; }
return false;
} );
if( pos < 0 ) this.currenttz = null;
}
if( this.currenttz == null ) return sel;
info.tz = this.currenttz;
return ipm_make_rangestring( info );
},
dtor: function()
{
this._cont = null;
this._cal1 = null;
this._cal2 = null;
this._rads = null;
}
};
function ipm_cal_rngverify(dateselid)
{
dateselid = dateselid || "dateselection";
var found = [];
var pos   = IPM.$$( dateselid, "SELECT", 2000 ).each( function(o) { if( o.id && /^rng0sel/.test( o.id ) && o.value != "" ) found.push(o); } );
if( found.length )
{
found.each( function(o) { IPM.addclass( IPM.dom.up(o), "invalidindicator" ); } );
var msg = "You currently have " + ( found.length > 1 ? ("[" + found.length  + "]") : "a" ) + " partial Quick Selection" + ( found.length > 1 ? "s" : "" ) + ".\r\n\r\nClick OK to ignore the partially completed Quick Selection(s). The Report will use the time settings marked in the calendar and will ignore the values highlighted in red. Alternatively, click Cancel to return to the Time Selection screen and complete your Quick Selection(s).";
var ret = confirm( msg );
found.each( function(o) { IPM.delclass( IPM.dom.up(o), "invalidindicator" ); } );
if( !ret ) return false;
}
return true;
}
function ipm_cal_rngtoggle(calord)
{
var calitem = IPM.caches.CAL.item(calord);
calitem.rangetoggle.apply( calitem, [] );
calitem = null;
}
function ipm_cal_rngquick_txt(txt)
{
var m = txt.match( /^(h|m|d|w|M);(-?[0-9]+);(-?[0-9]+);([0-9]+)/ );
if( m )
{
var anchor = m[1];
var move   = parseInt( m[2] );
var inc    = parseInt( m[3] );
var uihint = parseInt( m[4] );
var d = new Date();
var ord = null;
var ord2;
var ret = { origin: null, start: null, end: null, tz: null, advancement: null };
switch( anchor )
{
case 'm': ord = new Date( d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() + move, 0 ); break;
case 'h': ord = new Date( d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() + move, 0, 0 ); break;
case 'd': ord = new Date( d.getFullYear(), d.getMonth(), d.getDate() + move, 0, 0, 0 ); break;
case 'w': ord = new Date( d.getFullYear(), d.getMonth(), (d.getDate() - d.getDay()) + (move*7), 0, 0, 0 ); break;
case 'M': ord = new Date( d.getFullYear(), d.getMonth() + move, 1, 0, 0, 0 ); break;
}
switch( anchor )
{
case 'm': ord2 = new Date( ord.getFullYear(), ord.getMonth(), ord.getDate(), ord.getHours(), ord.getMinutes() + inc, 0 ); break;
case 'h': ord2 = new Date( ord.getFullYear(), ord.getMonth(), ord.getDate(), ord.getHours() + inc, 0, 0 ); break;
case 'd': ord2 = new Date( ord.getFullYear(), ord.getMonth(), ord.getDate() + inc, 0, 0, 0 );  break;
case 'w': ord2 = new Date( ord.getFullYear(), ord.getMonth(), ord.getDate() + (inc * 7), 0, 0, 0 );  break;
case 'M': ord2 = new Date( ord.getFullYear(), ord.getMonth() + inc, ord.getDate(), 0, 0, 0 );  break;
}
if( ord2.getTime() < ord.getTime() ) { ret.start = ord2; ret.end = ord; }
else { ret.start = ord; ret.end = ord2; }
ret.uihint = uihint;
if( uihint == 3 )
{
ret.origin = ret.end;
ret.advancement = "backtrack";
}
else
{
ret.origin = ret.start;
ret.uihint = uihint;
}
var sel = ipm_make_rangestring(ret) + ";uihint:" + ret.uihint;
var tf_mode;
switch( ret.uihint )
{
case 0: tf_mode = 'normal'; break;
case 1: tf_mode = 'range'; break;
case 2: case 3: tf_mode = 'recent'; break;
}
return { sel: sel, mode: tf_mode };
}
return null;
}
function ipm_cal_rngquick(e,calord)
{
e = e || event;
var domobj = IPM.$$( IPM.dom.up( e.target || e.srcElement, "DIV" ), "SELECT", 1 )[0];
var ret = ipm_cal_rngquick_txt(domobj.value);
if( ret )
{
var calitem = IPM.caches.CAL.item(calord);
if( calitem )
{
// parse out the selection so that we might obtain the time zone.
var info = ipm_parse_rangestring( calitem.selected );
if( info.tz != null ) ret.sel += ";tz:" + info.tz;
domobj.value = '';
calitem.render.apply( calitem, [ { mode: ret.mode, selected: ret.sel } ] );
if( calitem.onchange ) calitem.onchange.apply( calitem, [ret.sel] );
}
}
}
function ipm_cal_parsenum(val,add,cap)
{
var n = 0;
try { n = parseInt( val.replace( /^\s*0*/, '' ) ); } catch(err) { n = 0; }
if( isNaN(n) ) n = 0;
if( typeof(add) != "undefined" ) n += add;
if( n < 0 ) n = 0;
if( cap && (n > 59) ) n = 59;
return n;
}
function ipm_cal_keydown(e,ord)
{
e = e || window.event;
var keycode = e.which || e.keyCode;
var add = 0;
if( keycode == 40 ) { IPM.evt.cancel(e); add = -1; } // down
else if( keycode == 38 ) { IPM.evt.cancel(e); add = 1; } // up
else if( keycode == 33 ) { IPM.evt.cancel(e); if( ord > 0 ) add = 15; else if( !ord ) add = 8; else add = 7; } // pgup
else if( keycode == 34 ) { IPM.evt.cancel(e); if( ord > 0 ) add = -15; else if( !ord ) add = -8; else add = -7; } // pgdown
else return;
var domobj = e.target || e.srcElement;
n = ipm_cal_parsenum(domobj.value,add,ord >= 0);
if( !ord && (n > 23) ) n = 23;
val = ""+n;
if( val.length < 2 ) val = "0"+val;
domobj.value = val;
domobj = null;
}
function ipm_cal_tzchange(e,ord)
{
e = e || window.event;
var calitem = IPM.caches.CAL.item(ord);
calitem.tzchange.apply( calitem, [] );
}
function ipm_cal_blur(e,ord,calord)
{
e = e || window.event;
var domobj = e.target || e.srcElement;
n = ipm_cal_parsenum(domobj.value,0,ord >= 0);
if( !ord && (n > 23) ) n = 23;
val = ""+n;
if( (ord >= 0) && (val.length < 2) ) val = "0"+val;
domobj.value = val;
domobj = null;
var calitem = IPM.caches.CAL.item(calord);
calitem.timechange.apply( calitem, [] );
}
function ipm_stringdate(d)
{
if( !d ) return "";
var hh = "" + d.getHours();
var mm = "" + d.getMinutes();
var ss = "" + d.getSeconds();
if( hh.length < 2 ) hh = "0" + hh;
if( mm.length < 2 ) mm = "0" + mm;
if( ss.length < 2 ) ss = "0" + ss;
return d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate() + "," + hh + ":" + mm + ":" + ss;
}
function ipm_parse_rangestring(string)
{
if( !string ) string = "";
var ret = { origin: null, start: null, end: null, tz: null, advancement: null };
var s   = string.replace( /[ \t]/, '' ).split( ';' );
for( var i = 0, imax = s.length ; i < imax ; ++i )
{
var str = s[i];
var match = str.match( /^([0-9]+)\/([0-9]+)\/([0-9]+)(?:,([0-9]+):([0-9]+):([0-9]+))?$/ );
if( match )
{
var y  = parseInt( match[1].replace( /^\s*0*(?!$)/, '' ) );
var m  = parseInt( match[2].replace( /^\s*0*(?!$)/, '' ) );
var d  = parseInt( match[3].replace( /^\s*0*(?!$)/, '' ) );
var hh = match[4] ? parseInt( match[4].replace( /^\s*0*(?!$)/, '' ) ) : 0;
var mm = match[5] ? parseInt( match[5].replace( /^\s*0*(?!$)/, '' ) ) : 0;
var ss = match[6] ? parseInt( match[6].replace( /^\s*0*(?!$)/, '' ) ) : 0;
if( m ) m--;
var d1 = new Date( y, m, d, hh, mm, ss );
if( !ret.start ) ret.start = d1;
else if( ret.start.getTime() > d1.getTime() ) { ret.end = ret.start; ret.end = d1;  }
else ret.end = d1;
ret.origin = ret.start;
continue;
}
if( ret.start && (match = str.match( /^([+-])([0-9]+)\.([0-9]+):([0-9]+):([0-9]+)$/ )) )
{
var forward = match[1] == "+";
var op = forward ? 1 : -1;
ret.advancement = forward ? "advance" : "backtrack";
var d   = parseInt( match[2].replace( /^\s*0*(?!$)/, '' ) );
var hh  = parseInt( match[3].replace( /^\s*0*(?!$)/, '' ) );
var mm  = parseInt( match[4].replace( /^\s*0*(?!$)/, '' ) );
var ss  = parseInt( match[5].replace( /^\s*0*(?!$)/, '' ) );
var d2  = ret.origin;
var d3  = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() + (d*op), d2.getHours() + (hh*op), d2.getMinutes() + (mm*op), d2.getSeconds() + (ss*op) );
if( d2.getTime() > d3.getTime() ) { ret.start = d3; ret.end = d2; }
else { ret.start = d2; ret.end = d3; }
}
else if( str.match( /^tz:([+-]?[0-9]+)$/ ) )
{
ret.tz = parseInt( RegExp.$1 );
}
else if( str.match( /^uihint:([0-9]+)$/ ) )
{
ret.uihint = parseInt( RegExp.$1 );
}
}
if( ret.uihint == 2 )
{
ret.advancement = "advance";
ret.origin = ret.start;
}
else if( ret.uihint == 3 )
{
ret.advancement = "backtrack";
ret.origin = ret.end;
}
return ret;
}
function ipm_make_rangestring(dinfo)
{
if( !dinfo || (!dinfo.start && !dinfo.end) ) return null;
var dstart = dinfo.start;
var dend   = dinfo.end;
var sel    = "";
if( !dstart || !dend )
{
sel = ipm_stringdate( dstart || dend );
}
else
{
if( dstart.getTime() > dend.getTime() ) { var t = dstart; dstart = dend; dend = t; }
if( !dinfo.advancement )
{
sel = ipm_stringdate( dstart ) + ";" + ipm_stringdate( dend );
}
else
{
if( !dinfo.end || !dinfo.start ) return null;
if( dinfo.advancement == "advance" ) sel += ipm_stringdate( dinfo.start ) + ";+";
else sel += ipm_stringdate( dinfo.end ) + ";-";
var diff = ipm_diff_range( dinfo.start, dinfo.end );
diff.hh = ""+diff.hh; if( diff.hh.length < 2 ) diff.hh = "0" + diff.hh;
diff.mm = ""+diff.mm; if( diff.mm.length < 2 ) diff.mm = "0" + diff.mm;
diff.ss = ""+diff.ss; if( diff.ss.length < 2 ) diff.ss = "0" + diff.ss;
sel += diff.days + "." + diff.hh + ":" + diff.mm + ":" + diff.ss;
}
}
if( dinfo.tz ) sel += ";tz:" + dinfo.tz;
return sel;
}
function ipm_diff_range(d1,d2)
{
if( d1.getTime() > d2.getTime() ) { var t = d1; d1 = d2; d2 = t; t = null; }
var t1   = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() );
var t2   = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() );
var days = Math.round( (t2.getTime() - t1.getTime()) / 86400000 );
t1 = d1.getHours() * 3600000 + d1.getMinutes() * 60000 + d1.getSeconds() * 1000 + d1.getMilliseconds();
t2 = d2.getHours() * 3600000 + d2.getMinutes() * 60000 + d2.getSeconds() * 1000 + d2.getMilliseconds();
var r = t2-t1;
if( r < 0 ) { --days; r = 86400000 + r; }
var ms = r % 1000; r -= ms; r /= 1000;
var ss = r % 60; r -= ss; r /= 60;
var mm = r % 60; r -= mm; r /= 60;
var hh = r;
return { days: days, hh: hh, mm: mm, ss: ss, ms: ms };
}
function ipm_range_desc(datestr)
{
var domobj = IPM.$(this.id);
if( !domobj ) return;
var rng = ipm_parse_rangestring(datestr);
if( !rng.start || !rng.end || (rng.start.getTime() == rng.end.getTime()) )
{
IPM.dom.sethtml( domobj, ": None" );
}
else
{
rng.end.setSeconds( rng.end.getSeconds()-1 );
IPM.dom.sethtml( domobj, ": " + ipm_stringdate( rng.start ) + " to " + ipm_stringdate( rng.end ) + " inclusive" );
}
}

if( !window.IPM ) window.IPM = {};
if( !IPM.hit_bases ) IPM.hit_bases = {};
if( !IPM.hit_loc ) IPM.hit_loc = {};
if( !IPM.aux ) IPM.aux = {};
IPM.aux.movetd = function( domtbl, tdn, tddir )
{
domtbl = IPM.$(domtbl);
if( !domtbl || !tddir ) return;
var trcol = domtbl.getElementsByTagName("TR");
var tdcol;
var tr;
var td;
var td2;
var ord = tdn+tddir;
try
{
var i = 0;
var islast = -1;
IPM.setstyle( domtbl, "visibility", "hidden" );
for( ;; ++i )
{
tr    = trcol[i];
tdcol = tr.getElementsByTagName("TD");
var td0 = tdcol[0];
if( (td0.colSpan) && (td0.colSpan > 1) ) continue;
if( islast < 0 ) islast = tdcol.length == ord ? 1 : 0;
if( islast == 1 )
{
td = tdcol[tdn];
tr.appendChild( td );
}
else
{
if( tdn > ord ) { td = tdcol[tdn]; td2 = tdcol[ord]; }
else { td2 = tdcol[ord]; td = tdcol[tdn]; }
tr.insertBefore( td, td2 );
}
}
}
catch(err)
{
}
IPM.setstyle( domtbl, "visibility", "visible" );
};
IPM.hit_bases.trdrop = 
{
kind: "trdrop",
edges: "123789",
_arrow: null,
create: function( domobj, xy, opts ) { var ret = IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.trdrop ) ); return ret; },
enter: function( e, xy )
{
var pos = IPM.pos.info( this._evtitem[0] );
if( !this._arrow )
{
var y = (this._lastn == 8) ? pos.y : pos.y + pos.h;
this._arrow = IPM.$("trmovearrow");
if( !this._arrow )
{
var arrow = document.createElement("DIV");
arrow.id  = "trmovearrow";
document.body.appendChild( arrow );
IPM.setstyles( arrow, ["display","none","marginLeft","-16px","marginTop","-8px"] );
IPM.dom.sethtml( arrow, "<img class='i16' src='/cfg/v8/icon_arrow_right.png'>" );
this._arrow = arrow;
}
IPM.setstyles( this._arrow, ["position","absolute","display","","left", pos.x + "px","top", y + "px" ] );
}
},
leave: function( e, xy )
{
if( this._arrow ) IPM.setstyle( this._arrow, "display", "none" );
this._arrow = null;
},
iswithin: function( e, xy, isclick )
{
var anim = IPM.drag.animitem();
if( !anim || !anim._evtitem[0] || anim._evtitem[0].tagName != "TR" || !IPM.dom.up( this._evtitem[0], "TABLE" ) ) return 0;
var pickuptbl = IPM.dom.up( anim.hitobj._evtitem[0], "TABLE" );
var droptbl   = IPM.dom.up( this._evtitem[0], "TABLE" );
var want      = pickuptbl == droptbl;
pickuptbl = null;
droptbl   = null;
if( !want ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, pos.h/2 );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( n == 7 || n == 8 || n == 9 ) n = 8;
else n = 2;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
},
drop: function( e )
{
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up( domobj, "TR" );
if( !domobj || typeof(domobj) == "undefined" ) return;
var anim = IPM.drag.animitem();
if( !anim || !anim._evtitem[0] ) return;
var src = ( anim._evtitem[0].tagName != "TR" ? IPM.dom.up( anim._evtitem[0], "TR" ) : anim._evtitem[0] );
var dst = ( domobj.tagName != "TR" ? IPM.dom.up( domobj, "TR" ) : domobj );
if( this._lastn == 2 ) dst = IPM.dom.next( dst );
if( ( src && dst ) && src.sectionRowIndex == dst.sectionRowIndex ) return;
if( this.dodrop ) this.dodrop( src, dst );
return; 
}
};
IPM.hit_bases.tdtrash =
{
kind: "tdtrash",
create: function( domobj, xy, opts ) { var ret = IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.tdtrash ) ); return ret; },
enter: function( e, xy )
{
IPM.setstyle( IPM.dom.up( 'trash', 'DIV' ), 'border', '1px solid green' );
IPM.caches.SHADOW.show( IPM.dom.up( 'trash', 'DIV' ), 'trash' );
},
leave: function( e, xy )
{
IPM.setstyle( IPM.dom.up( 'trash', 'DIV' ), 'border', '1px solid #9eb5bd' );
IPM.caches.SHADOW.hide( 'trash' );
},
iswithin: function( e, xy, isclick )
{
var anim = IPM.drag.animitem();
if( !anim || anim.kind != "tdmove" || !anim.hitobj ) { anim = null; return 0; }
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up( domobj );
if( !domobj.id.match( /^(trash)$/ ) ) return 0;
var pos = IPM.pos.info( IPM.dom.up( domobj, 'DIV' ) );
if( (xy.x < pos.x) || (xy.y < pos.y) || (xy.x > pos.x + pos.w) || (xy.y > pos.y + pos.h) ) return 0;
return 1;
},
drop: function( e )
{
var anim = IPM.drag.animitem();
if( !anim || !anim.hitobj || !anim._evtitem[0] ) { anim = null; return; }
var tr = IPM.dom.up( anim._evtitem[0], 'TR' );
if( !tr ) return;
IPM.setstyle( IPM.dom.up('trash', 'DIV'), 'display', 'none' );
var pos = IPM.dom.getIndex( anim._evtitem[0] );
if( this.doremove ) this.doremove( pos, tr.childNodes.length );
}
};
IPM.hit_bases.tdinsert =
{
edges: "741963",
kind: "tdinsert",
_arrow: null,
create: function( domobj, xy, opts ) { var ret = IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.tdinsert ) ); return ret; },
enter: function( e, xy )
{
var pos = IPM.pos.info( this._evtitem[0] );
if( !this._arrow )
{
var x = (this._lastn == 4) ? pos.x : pos.x + pos.w;
this._arrow = IPM.$("tdmovearrow");
if( !this._arrow )
{
var arrow = document.createElement("DIV");
IPM.setstyles( arrow, ["display","none","marginLeft","-8px","marginTop","-16px"] );
arrow.id = "tdmovearrow";
document.body.appendChild( arrow );
IPM.dom.sethtml( arrow, "<img class='i16' src='/cfg/v8/icon_arrow_down.png'>" );
this._arrow = arrow;
}
IPM.setstyles( this._arrow, ["position","absolute","display","","left",x + "px","top",pos.y + "px"] );
}
},
leave: function( e, xy )
{
if( this._arrow )
{
var domobj = this._arrow;
this._arrow = null;
IPM.setstyle( domobj, "display", "none" );
}
},
iswithin: function( e, xy, isclick )
{
var anim = IPM.drag.animitem();
if( !anim || anim.kind != "tdmove" || !anim.hitobj ) { anim = null; return 0; }
var pickupobj = anim.hitobj._evtitem[0];
if( this.exclude && this.exclude.test( pickupobj.tagName ) ) return 0;
if( /^ipm_(mon|tag)_col_[0-9]+$/.test( pickupobj.id ) == false ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, pos.w/2 );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( n == 7 || n == 1 || n == 4 )
{
if( IPM.hasclass( this._evtitem[0], "begin" ) ) n = 6;
else n = 4;
}
else
{
if( IPM.hasclass( this._evtitem[0], "end" ) ) n = 4;
else n = 6
}
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
},
drop: function( e )
{
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up( domobj );
var anim = IPM.drag.animitem();
if( !anim || !anim.hitobj ) { anim = null; return; }
var m = anim.hitobj._evtitem[0].id.match( /^(ipm_(mon|tag)_col)_([0-9]+)$/ );
var tr = IPM.dom.up( domobj, 'TR' );
if( m && tr && this.doinsert )
{
var src_array = m[1];
var pos_array = parseInt( m[3] );
var pos_insert= IPM.dom.getIndex( domobj );
if( this._lastn == 6 ) pos_insert++;
this.doinsert( src_array, pos_array, pos_insert, tr.childNodes.length );
}
}
};
IPM.hit_bases.tdresize =
{
edges: "741963",
kind: "tdresize",
_cursor: null,
_altresize: null,
_alttest: null,
_altdrag: null,
_action: null,
create: function( domobj, xy, opts )
{
var ret = IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.tdresize ) );
var pos = IPM.pos.info( domobj );
var n   = ret.getn( pos, xy, ret.borderwidth );
// if n is '7','4','1' ... we must see if this is the 'first' cell.
if( n == 7 || n == 4 || n == 1 )
{
var prev = IPM.dom.prev(domobj);
if( !prev || IPM.hasclass( prev, "noresize" ) ) ret.edges = ret.edges.replace( /[741]/g, '' );
}
// if n is '9','6','3' ... we must see this is the 'last' cell.
else if( n == 9 || n == 6 || n == 3 )
{
var next = IPM.dom.next(domobj);
if( !next || IPM.hasclass( next, "noresize" ) ) ret.edges = ret.edges.replace( /[963]/g, '' );
}
return ret;
},
enter: function( e, xy )
{
var cursors = ["sw-resize","n-resize","e-resize","w-resize","move","e-resize","nw-resize","n-resize","e-resize"];
this._cursor = this._evtitem[0].style.cursor ? this._evtitem[0].style.cursor : "";
IPM.setstyle( this._evtitem[0], "cursor", cursors[ this._lastn - 1 ] );
},
leave: function( e, xy )
{
if( this._cursor != null ) IPM.setstyle( this._evtitem[0], "cursor", this._cursor );
this._cursor = null;
},
mousedown: function( e )
{
this.leave( e, {} );
var domobj = this._evtitem[0];
if( this._lastn == 4 ) domobj = IPM.dom.prev(domobj);
var tdobj = this._altresize ? this._altresize.create() : IPM.anim_bases.tdresize.create();
if( this.doresize ) tdobj.doresize = this.doresize;
IPM.drag.start( e, tdobj, domobj );
IPM.evt.cancel(e);
return false;
},
iswithin: function( e, xy, isclick )
{
/* get coords */
if( IPM.drag.indrag() ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, this.borderwidth );
if( n == 9 || n == 3 ) n = 6;
else if( n == 7 || n == 1 ) n = 4;
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
}
};
IPM.hit_bases.tdpickup =
{
edges: "741852963",
kind: "tdpickup",
classname: null,
hoverclass: null,
_cursor: null,
_bgcolor: null,
_alttest: null,
_altdrag: null,
_action: null,
_hatelist: null,
create: function( domobj, xy, opts ) { return IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.tdpickup ) ); },
enter: function( e, xy )
{
this._cursor = this._evtitem[0].style.cursor || "";
IPM.setstyle( this._evtitem[0], "cursor", "move" );
if( this.hoverclass ) IPM.addclass( this._evtitem[0], this.hoverclass );
},
leave: function( e, xy )
{
if( this._cursor != null )  IPM.setstyle( this._evtitem[0], "cursor", this._cursor );
if( this.hoverclass ) IPM.delclass( this._evtitem[0], this.hoverclass );
this._cursor = null;
},
mousedown: function( e )
{
this.leave( e, {} );
var pos        = IPM.pos.info( this._evtitem[0] );
var cloneStyle = ['borderLeftStyle',
'borderLeftWidth',
'borderLeftColor',
'borderTopStyle',
'borderTopWidth',
'borderTopColor',
'borderRightStyle',
'borderRightWidth',
'borderRightColor',
'borderBottomStyle',
'borderBottomWidth',
'borderBottomColor',
'paddingLeft',
'paddingTop',
'paddingRight',
'paddingBottom',
'backgroundColor',
'color'];
var domobj  = ( this._evtitem[0].tagName == "DIV" ? this._evtitem[0] : IPM.$$( this._evtitem[0], "A", 1 )[0] );
var clone   = ( domobj ? IPM.ui.clone( domobj, cloneStyle ) : IPM.ui.clone( this._evtitem[0], cloneStyle ) );
IPM.addclass( clone, this.classname );
IPM.setstyles( clone, ["position","absolute","left",""+pos.x+"px","top",""+pos.y+"px","whiteSpace","normal","height","auto","overflow","visible","padding","0.25em","zIndex","" + IPM.z.get_zindex('top') ] );
document.body.insertBefore( clone, document.body.firstChild );
IPM.setstyles( clone, ["opacity","0.75","border"] );
var drag = IPM.anim_bases.drag;
var predrag  = this.predrag || null;
var postdrag = this.postdrag || null;
if( this._alttest && this._alttest( this._evtitem[0] ) ) drag = this._altdrag;
if( predrag ) predrag(this._evtitem[0]);
IPM.drag.start( e, drag.create( { action: this._action, cleanup: postdrag, ghost: clone, killghost: true, kind: "tdmove", hitobj: IPM.hit.leak() } ), this._evtitem[0] );
IPM.evt.cancel(e);
return false;
},
iswithin: function( e, xy, isclick )
{
/* get coords */
if( IPM.drag.indrag() ) return 0;
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up( domobj );
if(!domobj) return 0;
if( this._hatelist && this._hatelist.test( domobj.tagName ) ) return 0;
if( this.anchorhack )
{
if( domobj.tagName == "A" ) return 5;
return 0;
}
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, 0 );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
}
};
IPM.hit_bases.tddrop =
{
edges: "741852963",
kind: "tddrop",
_arrow: null,
create: function( domobj, xy, opts ) { return IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.tddrop ) ); },
enter: function( e, xy )
{
var pos = IPM.pos.info( this._evtitem[0] );
if( !this._arrow )
{
var x = (this._lastn == 4) ? pos.x : pos.x + pos.w;
this._arrow = IPM.$("tdmovearrow");
if( !this._arrow )
{
var arrow = document.createElement("DIV");
IPM.setstyles( arrow, ["display","none","marginLeft","-8px","marginTop","-16px"] );
arrow.id = "tdmovearrow";
document.body.appendChild( arrow );
IPM.dom.sethtml( arrow, "<img class='i16' src='/cfg/v8/icon_arrow_down.png'>" );
this._arrow = arrow;
}
IPM.setstyles( this._arrow, ["position","absolute","display","","left",x + "px","top",pos.y + "px"] );
}
},
leave: function( e, xy )
{
if( this._arrow )
{
var domobj = this._arrow;
this._arrow = null;
IPM.setstyle( domobj, "display", "none" );
}
},
iswithin: function( e, xy, isclick )
{
/* get coords */
var anim = IPM.drag.animitem();
if( !anim || anim.kind != "tdmove" || !anim.hitobj ) { anim = null; return 0; }
var pickuptbl = IPM.dom.up( anim.hitobj._evtitem[0], "TABLE" );
var droptbl = IPM.dom.up( this._evtitem[0], "TABLE" );
var want = pickuptbl == droptbl;
pickuptbl = null;
droptbl = null;
if( !want ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, pos.w/2 );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( n == 7 || n == 1 || n == 4 ) n = 4;
else n = 6;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
},
drop: function( e, draghitobj )
{
var n1      = 0;
var n2      = 0;
var domobj  = draghitobj ? draghitobj._evtitem[0] : null;
var parent  = IPM.dom.up( domobj, "TR" );
while( domobj = IPM.dom.prev(domobj) ) n1++;
domobj = this._evtitem[0];
while( domobj = IPM.dom.prev(domobj) ) n2++;
if( this._lastn == 6 ) n2++;
if( this.domove ) { this.domove( n1, n2-n1, parent.childNodes.length ); }
},
dtor: function()
{
if( this._arrow ) this.leave( e, {} );
IPM.hit_bases.hitobj.dtor.apply( this, [] );
}
};
IPM.hit_bases.tdpickup.postdrag= function() { IPM.setstyles( IPM.dom.up( 'trash', 'DIV' ), [ 'display', 'none', 'top', '0px' ] ); };
IPM.hit_bases.tdpickup.predrag = function( domobj )
{
if( !IPM.hasclass( domobj, "notrash" ) )
{
var trash = IPM.dom.up( 'trash', 'DIV' );
if( !trash )
{
trash = document.createElement( "DIV" );
document.body.insertBefore( trash, document.body.firstChild );
trash.className   = "noresize nomove";
trash.innerHTML   = "<img id=\"trash\" style=\"margin:0; border:0; margin: 8px;\" src=\"/cfg/v8/icon_trash.png\" width=64 height=64>";
IPM.setstyles( trash, [ 'position', 'absolute', 'right', '1em', 'border', '1px solid #9eb5bd', 'backgroundColor', '#fff', 'width', '78px', 'height', '78px', 'display', 'none', 'zIndex', '' + IPM.z.get_zindex('top') ] );
}
trash.onmouseout  = function( event ){ IPM.hit.movement(event, [ IPM.hit_loc.dbcolmgr ] ); };
trash.onmousemove = function( event ){ IPM.hit.movement(event, [ IPM.hit_loc.dbcolmgr ] ); };
trash.onmouseup   = function( event ){ IPM.hit.mouseup( event, [ IPM.hit_loc.dbcolmgr ] ); };
IPM.setstyles( trash, [ 'top', '' + (IPM.pos.viewh() + IPM.pos.pagey() - 84 - 24 ) + 'px', 'display', '' ] );
}
};
IPM.hit_loc.colmgr =
{
tdresize_create: IPM.hit_bases.tdresize.create,
tdpickup_create: IPM.hit_bases.tdpickup.create,
tddrop_create: 	 IPM.hit_bases.tddrop.create,
tdinsert_create: IPM.hit_bases.tdinsert.create,
tdtrash_create:  IPM.hit_bases.tdtrash.create,
findElement: function( e, xy, isclick )
{
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up( domobj );
var hasclass = IPM.hasclass;
var wantanchorhack  = IPM.is.gecko || IPM.is.safari || IPM.is.opera;
var found;
// specifically allow items within the properties pane, on gecko, from pickup always on an 'A'
if( wantanchorhack )
{
if( domobj.tagName == "A" && domobj.id && /^ipm_(mon|tag|grp)_col_[0-9]+$/.test( domobj.id ) ) return null;
var p = IPM.dom.up( domobj );
if( p.id && p.id.match( /^ipm_(mon|tag|grp)_col_([0-9]+)$/ ) )
{
found = this.tdpickup_create( p, xy, { classname: 'drag', hoverclass: 'pickuphover', anchorhack: true } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
}
else
{
if( domobj.tagName != "TD" && domobj.id && domobj.id.match( /^ipm_(mon|tag|grp)_col_([0-9]+)$/ ) )
{
found = this.tdpickup_create( domobj, xy, { classname: 'drag', hoverclass: ( domobj.tagName == "TD" ? '' : 'pickuphover' ) } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
}
for( ; domobj ; domobj = IPM.dom.up( domobj ) )
{
if( domobj.tagName == "A" && !IPM.drag.indrag() ) break;
if( !hasclass( domobj, "notrash" ) )
{
found = this.tdtrash_create( domobj, xy, { } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
if( domobj.tagName == "TD" )
{
var tr = IPM.dom.up( domobj, "TR" );
var tbl = IPM.dom.up( tr, "TABLE" );
if( !tbl || !(/(^|[ \t])(uilist|dblist)([ \t]|$)/.test( tbl.className )) ) continue;
if( !hasclass( domobj, "noresize" ) )
{
found = this.tdresize_create( domobj, xy, { edges: "741963" } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
var tr_ok = IPM.$$(tbl,"TR",1)[0] == tr;
if( tr_ok )
{
found = this.tdinsert_create( domobj, xy, { } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
if( hasclass( domobj, "nomove" ) ) continue;
found = this.tdpickup_create( domobj, xy, { classname: 'drag' } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
found = this.tddrop_create( domobj, xy, { } );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
}
}
return null;
}
};
IPM.hit_loc.dbcolmgr =
{
findElement: function( e, xy, isclick )
{
if( !IPM.hit_loc.dbcolmgr.section ) return null;
var c = IPM.hit_loc.colmgr;
var ret = c.findElement(e,xy,isclick);
if( !ret ) return null;
if( ret.kind == "tdresize" )      ret.doresize = IPM.hit_loc.dbcolmgr.doresize;
else if( ret.kind == "tddrop" )   ret.domove   = IPM.hit_loc.dbcolmgr.domove;
else if( ret.kind == "tdinsert" ) ret.doinsert = IPM.hit_loc.dbcolmgr.doinsert;
else if( ret.kind == "tdtrash" )  ret.doremove = IPM.hit_loc.dbcolmgr.doremove;
return ret;
},
domove: function( tdn, tddir, tdlen )
{
if( !IPM.hit_loc.dbcolmgr.section ) return;
var cache = IPM.caches[IPM.hit_loc.dbcolmgr.section];
if( !cache || !cache._cache[0] ) return;
var ajobj = cache._cache[0];
if( ajobj ) ajobj.domove( tdn, tddir, tdlen );
},
doresize: function(a)
{
if( !IPM.hit_loc.dbcolmgr.section ) return;
var cache = IPM.caches[IPM.hit_loc.dbcolmgr.section];
if( !cache || !cache._cache[0] ) return;
var ajobj = cache._cache[0];
if( ajobj ) ajobj.doresize( a );
},
doinsert: function( src_array, pos_array, pos_insert, tdlen )
{
if( !IPM.hit_loc.dbcolmgr.section ) return;
var cache = IPM.caches[IPM.hit_loc.dbcolmgr.section];
if( !cache || !cache._cache[0] ) return;
var ipm_array = window[src_array];
var ajobj = cache._cache[0];
if( ipm_array && ajobj ) ajobj.doinsert( ipm_array[pos_array], pos_insert, tdlen );
},
doremove: function( pos, tdlen )
{
if( !IPM.hit_loc.dbcolmgr.section ) return;
var cache = IPM.caches[IPM.hit_loc.dbcolmgr.section];
if( !cache || !cache._cache[0] ) return;
var ajobj = cache._cache[0];
if( ajobj ) ajobj.doremove( pos, tdlen );
}
};
IPM.hit_bases.fauxwinpickup =
{
edges: "741852963",
_cursor: null,
create: function( domobj, xy, opts ) { return IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.fauxwinpickup ) ); },
enter: function( e, xy )
{
this._cursor = this._evtitem[0].style.cursor || "";
IPM.setstyle( this._evtitem[0], "cursor", "move" );
},
leave: function( e, xy )
{
if( this._cursor != null ) IPM.setstyle( this._evtitem[0], "cursor", this._cursor );
this._cursor = null;
},
mousedown: function( e )
{
this.leave( e, {} );
IPM.drag.start( e, IPM.anim_bases.fwfollow.create( { kind: "fwmove" } ), IPM.dom.up( this._evtitem[0] ) );
IPM.hit.leak();
IPM.evt.cancel(e);
return false;
},
iswithin: function( e, xy, isclick )
{
/* get coords */
if( IPM.drag.indrag() ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, 0 );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up(domobj);
for( ; domobj && domobj.tagName != "DIV" ; domobj = IPM.dom.up(domobj) )
if( domobj.tagName == "A" ) return 0;
return n;
}
};
IPM.hit_bases.fauxwinresize =
{
edges: "63",
_cursor: null,
create: function( domobj, xy, opts ) { return IPM.copy( opts, IPM.hit_bases.hitobj.create( domobj, IPM.hit_bases.fauxwinresize ) ); },
enter: function( e, xy ) { this._cursor = this._evtitem[0].style.cursor || ""; IPM.setstyle( this._evtitem[0], "cursor", "nw-resize" ); },
leave: function( e, xy ) { if( this._cursor != null ) IPM.setstyle( this._evtitem[0], "cursor", this._cursor ); this._cursor = null; },
mousedown: function( e )
{
this.leave( e, {} );
var rootdiv = IPM.dom.up( this._evtitem[0] );
var fwobj = IPM.win.item(rootdiv);
if( fwobj )
{
// fwobj.tofront.apply( fwobj, [] );
IPM.drag.start( e, IPM.anim_bases.fwresize.create( { kind: "fwresize", cursor: "nw-resize" } ), rootdiv );
IPM.hit.leak();
}
IPM.evt.cancel(e);
return false;
},
iswithin: function( e, xy, isclick )
{
/* get coords */
if( IPM.drag.indrag() ) return 0;
var cn = this._evtitem[0].className || "";
if( /(^|[ \t])grip($|[ \t])/.test( cn ) == false ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, 18 );
if( n != 6 && n != 3 ) return 0;
var domobj = e.target || e.srcElement;
if( domobj.nodeType != 1 ) domobj = IPM.dom.up(domobj);
for( ; domobj && domobj.tagName != "DIV" ; domobj = IPM.dom.up(domobj) )
if( domobj.tagName == "A" ) return 0;
return n;
}
};
IPM.hit_loc.fauxwin =
{
findElement: function( e, xy, isclick )
{
var domobj = e.target || e.srcElement;
if( IPM.drag.indrag() || !domobj ) return null;
if( domobj.nodeType != 1 ) domobj = domobj.parentNode;
for( ; domobj && (domobj.tagName != "DIV") ; domobj = IPM.dom.up(domobj) )
if( domobj.tagName == "A" ) return null;
var parent = IPM.dom.up( domobj, "DIV" );
if( !parent || !domobj ) return null;
var cn = ""+parent.className;
if( /(^|[ \t])fauxwin($|[ \t])/.test( cn ) == false ) return null;
var cn = ""+domobj.className;
if( /(^|[ \t])hdr($|[ \t])/.test( cn ) )
{
// verify that it's within an 'fauxwin'
var found = IPM.hit_bases.fauxwinpickup.create( domobj, xy );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
if( /(^|[ \t])ftr($|[ \t])/.test( cn ) )
{
// verify that it's within an 'fauxwin' & over the grip
var found = IPM.hit_bases.fauxwinresize.create( domobj, xy );
if( found.iswithin( e, xy, isclick ) ) return found;
found.dtor();
}
return null;
}
};

IPM.hit =
{
_mo: null,
clear: function()
{
var m;
if( m = IPM.hit._mo )
{
m.leave.apply( m, [{},null] );
if( m.dtor ) m.dtor.apply( m, [] );
IPM.hit._mo = null;
}
},
hoveritem: function() { return IPM.hit._mo || null; },
leak: function() { var m = IPM.hit._mo; IPM.hit._mo = null; return m; },
movement: function( e, RuleSet, isclick )
{
e = e || window.event;
isclick = isclick || false;
var xy = IPM.pos.cursor(e);
if( IPM.hit._mo )
{
if( IPM.hit._mo.iswithin( e, xy, isclick ) ) { IPM.hit._mo.movement( e, xy, isclick ); IPM.evt.stop(e); return; }
IPM.hit._mo.leave( e, xy, isclick );
IPM.hit._mo.dtor();
IPM.hit._mo = null;
}
if( typeof(RuleSet.length) != "undefined" )
for( var i = 0, imax = RuleSet.length ; !IPM.hit._mo && (i < imax) ; ++i ) 
IPM.hit._mo = RuleSet[i].findElement( e, xy, isclick );
else IPM.hit._mo = RuleSet.findElement( e, xy, isclick );
if( IPM.hit._mo )
{
IPM.hit._mo.enter( e, xy, isclick );
IPM.hit._mo.movement( e, xy, isclick );
IPM.evt.stop(e);
}
},
mousedown: function( e, RuleSet )
{
e = e || window.event;
var _btn = e.button;
var _lclick = false;
if( IPM.is.ie ) _lclick = _btn == 1;
else _lclick = _btn == 0;
if( !_lclick ) return;
var domobj = e.target || e.srcElement;
if( (domobj.nodeType == 1) && (domobj.tagName == "INPUT") )
{
domobj = null;
return;
}
IPM.hit.movement( e, RuleSet, true );
if( IPM.hit._mo && ! IPM.hit._mo.mousedown( e ) ) IPM.hit.clear();
domobj = null;
},
mouseup: function( e, RuleSet )
{
IPM.hit.movement( e, RuleSet, true );
if( IPM.hit._mo && ! IPM.hit._mo.mouseup( e ) ) IPM.hit.clear();
},
dtor: function()
{
var m;
if( m = IPM.hit._mo )
{
if( m.dtor ) m.dtor.apply(m,[]);
IPM.hit._mo = null;
}
}
};
IPM.caches.HIT = IPM.hit;
IPM.hit_bases.hitobj =
{
edges: "",
borderwidth: 10,
_evtitem: null,
_lastn: null,
create: function( domobj, opts ) { var ret = IPM.copy( opts, IPM.copy( IPM.hit_bases.hitobj, new Object() ) ); ret._evtitem = [domobj]; return ret; },
enter: IPM.fn_null,
leave: IPM.fn_null,
getn: function( pos, xy, edgewidth )
{
var n = 5;
if( (xy.x < pos.x) || (xy.y < pos.y) || (xy.x > pos.x + pos.w) || (xy.y > pos.y + pos.h) ) return 0;
if( xy.y < pos.y + edgewidth ) n += 3;
if( xy.y >= pos.y + pos.h - edgewidth ) n -= 3;
if( xy.x < pos.x + edgewidth ) n -= 1;
if( xy.x >= pos.x + pos.w - edgewidth ) n += 1;
return n;
},
iswithin: function( e, xy, isclick )
{
/* get coords */
if( IPM.drag.indrag() ) return 0;
var pos = IPM.pos.info( this._evtitem[0] );
var n   = this.getn( pos, xy, this.borderwidth );
if( !n || this.edges.indexOf( ""+n ) < 0 ) return 0;
if( ! this._lastn ) { this._lastn = n; this.edges = ""+n; }
return n;
},
movement: IPM.fn_null,
mousedown: IPM.fn_true,
mouseup: IPM.fn_true,
dtor: function() { if( this._evtitem ) { this._evtitem[0] = null; this._evtitem = null; } }
};

IPM.ui.tree2 = 
{
vars:
{
indent: '16',
basepath: '/cfg/si/',
imgopen: 'icon_tree_minus.png',
imgclosed: 'icon_tree_plus.png',
imgnone: '../blank.gif'
},
_ulpgid: 'tree-contents',
_currentitem: null,
_currentparent: null,
_reflowdepth: 0,
_reflowtarget: null,
_archive: {},
// used for rendering.
_parents: [],
_markup: [],
_pending: [],
_opens: null,
_rendercount: 0,
_renderstart: null,
selected: null,
onclick: null,
doretrieve: null,
doprerender: null,
dorenderitem: null,
doxlaticon: null,
create: function(_domobj)
{
var _ret = IPM.copy( IPM.ui.tree2 );
var _newid = IPM.dom.newid('xtree-root-');
_domobj = IPM.$(_domobj);
if( _domobj )
{
if( _domobj.tagName == "UL" )
{
var _first = IPM.dom.first( _domobj );
if( _first && _first.tagName == "DIV" )
{
if( !_first.id ) _first.id = _newid;
_ret._ulpgid = _first.id;
return _ret;
}
_ret._ulpgid = _newid;
IPM.dom.sethtml( _domobj, "<div id='" + _newid + "'><!-- --><\/div>" );
return _ret;
}
}
var _newobj = document.createElement("UL");
if( _domobj ) document.appendChild( _newobj );
else document.body.appendChild(_domobj);
IPM.addclass( _newobj, "tree-root" );
IPM.dom.sethtml( _newobj, "<div id='" + _newid + "'><!-- --><\/div>" );
_ret._ulpgid = _newid;
return _ret;
},
startLayout: function(_opens)
{
if( !_opens ) _opens={};
IPM.evt.unhook( 'xtree-' + this._ulpgid );
this._rendercount = 0;
this._renderstart = new Date().getTime();
var _dest = IPM.$(this._ulpgid);
this._opens = _opens;
this._archive.length = 0;
this._markup.length = 0;
this._currentparent = {id:'',_ul:true};
this._reflowdepth = 0;
IPM.dom.sethtml( _dest, '' );
},
endLayout: function()
{
var _count = this._opens.length;
for( ; _count > 1 ; _count-- ) this.decDepth();
var _dest = IPM.$(this._ulpgid);
IPM.dom.sethtml( _dest, this._markup.join('') );
this._markup.length = 0;
if( this._pending )
{
var _that = this;
window.setTimeout( function(){
_that._pending.each( function(_item){
var _domobj = IPM.$(_item._pgid + "-expando");
if( _domobj )
{
if( _item._isopen )
{
_domobj.src = _that.vars.basepath + _that.vars.imgopen;
_domobj.alt = '-';
}
else
{
_domobj.src = _that.vars.basepath + _that.vars.imgclosed;
_domobj.alt = '+';
}
}
});
_that._pending.length = 0;
IPM.evt.add( IPM.$(_that._ulpgid), IPM.bind( _that, _that._recvclick ), "click", false, 'xtree-' + _that._ulpgid );
}, 10 );
}
this._flushperf();
},
incDepth: function(_item)
{
this._archive[_item.id] = _item;
if( !_item._pgid ) _item._pgid = IPM.dom.newid('xtree');
_item.depth = this._parents.length + this._reflowdepth;
if( _item._isopen = this._opens[_item.id] ) _item.more = true;
if( !this._currentparent._ul )
{
this._currentparent._ul = true;
if( !this._currentparent.more ) this._pending.push(this._currentparent).more = true;
this._markup.push( this._currentparent._isopen ? "<ul>" : "<ul class='tree-closed'>" );
}
this.doprerender( this, _item );
this._markup.push( "<li rel='" + this.vars.rel + (_item.id == this.selected ? "' class='tree-selected'>" : "'>" ) );
this.dorenderitem( this._markup, this.vars, _item );
this._markup.push( "<\/li>\r\n" );
this._parents.push(this._currentparent);
this._currentparent = _item;
this._rendercount++;
},
decDepth: function()
{
this._currentparent._ul = false;
if( (this._currentparent = this._parents.pop())._ul )
{
if( this._parents.length >= 1 )
this._markup.push("<\/ul>\r\n");
}
},
addItem: function(_item)
{
if( !this._currentparent._ul )
{
this._currentparent._ul = true;
if( !this._currentparent.more ) this._pending.push(this._currentparent).more = true;
this._markup.push( this._currentparent._isopen ? "<ul>" : "<ul class='tree-closed'>" );
}
_item._pgid = IPM.dom.newid('xtree');
this._archive[_item.id] = _item;
_item.depth = this._parents.length + this._reflowdepth;
this.doprerender( this, _item );
this._markup.push( "<li rel='" + this.vars.rel + "'>" );
this.dorenderitem( this._markup, this.vars, _item );
this._markup.push( "<\/li>\r\n" );
this._rendercount++;
},
updateItem: function(_item)
{
var _domobj;
if( _domobj = IPM.$(_item._pgid + '-state') )
{
var _iconinfo = this.doxlaticon(_item.ico);
_domobj.src = _iconinfo.src;
_domobj.alt = _iconinfo.alt;
}
if( _domobj = IPM.$(_item._pgid + '-expando') )
{
if( !_item.more )
{
_domobj.src = this.vars.basepath + this.vars.imgnone;
_domobj.alt = '&nbsp;';
}
else if( _item._isopen )
{
_domobj.src = this.vars.basepath + this.vars.imgopen;
_domobj.alt = '-';
}
else
{
_domobj.src = this.vars.basepath + this.vars.imgclosed;
_domobj.alt = '+';
}
IPM.dom.sethtml( IPM.$$( IPM.dom.up( _domobj ), "SPAN", 1 )[0], IPM.ui.encode( _item.lbl ) );
}
},
startReflow: function(_parentid)
{
var _sel = this._archive[_parentid];
if( !_sel ) return false;
_sel._ul = true;
this._reflowtarget = _parentid;
this._reflowdepth = _sel.depth + 1;
this._currentparent = _sel;
this._markup.length = 0;
this._rendercount = 0;
this._renderstart = new Date().getTime();
return true;
},
endReflow: function()
{
var _sel = this._archive[this._reflowtarget];
if( !_sel )
return false;
var _dest = IPM.$( _sel._pgid + '-state' );
var _li = IPM.dom.up( _dest, "LI" );
if( !_li )
return false;
var _next = IPM.dom.next( _li );
if( !_next || _next.tagName != "UL" )
{
if( this._markup.length == 0 )
{
this._flushperf();
return true;
}
var _ul = document.createElement( "UL" );
if( !_next ) _li.parentNode.appendChild( _ul );
else _li.parentNode.insertBefore( _ul, _next );
_next = _ul;
}
IPM.dom.sethtml( _next, this._markup.join('') );
this._flushperf();
return true;
},
toggleItem: function(_sel)
{
if( typeof(_sel) == "string" ) _sel = this._archive[_sel];
if( _sel && _sel.more ){
if( _sel._isopen ) this.collapseItem(_sel);
else this.expandItem(_sel);
}
},
selectItem: function(_sel,_allowtoggle,_forcetoggle)
{
if( typeof(_sel) == "string" )
{
if( _sel == '' && this.selected )
{
var _old = this._archive[this.selected];
if( _old )
{
_domobj = IPM.dom.up( IPM.$( _old._pgid + "-state" ), "LI" );
IPM.delclass( _domobj, "tree-selected" );
this.selected = '';
}
return;
}
_sel = this._archive[_sel];
}
if( !_sel ) return;
// ensure that all parent items are visible
if( _sel.id == this.selected )
{
if( !_allowtoggle || !_sel.more ) return;
// toggle the branch
if( _sel._isopen ) this.collapseItem(_sel);
else this.expandItem(_sel);
return;
}
// unselect the current item 
var _domobj;
if( this.selected )
{
var _old = this._archive[this.selected];
if( _old )
{
_domobj = IPM.dom.up( IPM.$( _old._pgid + "-state" ), "LI" );
IPM.delclass( _domobj, "tree-selected" );
}
}
var up = IPM.dom.up;
var prev = IPM.dom.prev;
_domobj = up( IPM.$( _sel._pgid + "-state" ), "LI" );
IPM.addclass( _domobj, "tree-selected" );
this.selected = _sel.id;
if( _forcetoggle ) this.toggleItem(_sel);
else this.expandItem(_sel);
// ensure that all parents are expanded.
for( ; _domobj ; )
{
var _ul = up( _domobj, "UL" );
if( IPM.hasclass( _ul, "tree-root" ) ) break;
var _parent = prev( _ul );
if( _parent && _parent.tagName == "LI" )
{
// ensure this is expanded and open.
var _rel = _parent.getAttribute('rel');
if( !_rel ) break;
_rel = _rel.substr(1);
this.expandItem( _rel );
_domobj = _parent;
}
else break;
}
},
collapseItem: function(_sel)
{
if( typeof(_sel) == "string" ) _sel = this._archive[_sel];
if( !_sel || !_sel.more || !_sel._isopen ) return;
var _expando = IPM.$( _sel._pgid + "-expando" );
if( _expando )
{
_expando.src = this.vars.basepath + this.vars.imgclosed;
_expando.alt = '+';
}
var _domobj = IPM.dom.up( _expando, "LI" );
var _ul = IPM.dom.next( _domobj );
if( !_ul || _ul.tagName != "UL" ) return;
IPM.addclass( _ul, "tree-closed" );
_sel._isopen = this._opens[_sel.id] = false;
},
expandItem: function(_sel)
{
if( typeof(_sel) == "string" ) _sel = this._archive[_sel];
if( !_sel || !_sel.more || _sel._isopen )
return;
var _expando = IPM.$( _sel._pgid + "-expando" );
if( _expando )
{
_expando.src = this.vars.basepath + this.vars.imgopen;
_expando.alt = '-';
}
var _domobj = IPM.dom.up( _expando, "LI" );
var _next = IPM.dom.next( _domobj );
if( !_next || _next.tagName != "UL" )
{
// construct & insert UL
// fill in with 'Loading...'
var _markup;
var _newid = IPM.dom.newid( 'xtreeload-' );
if( _markup = this.doretrieve( this, _sel, ((_sel.depth+2) * 16), _newid ) )
{
var _ul = document.createElement( "UL");
if( _next ) _domobj.parentNode.insertBefore( _ul, _next );
else _domobj.parentNode.appendChild( _ul );
IPM.dom.sethtml( _ul, "<li id='" + _newid + "' class='tree-loading'>" + _markup + "<\/li>\r\n" );
}
}
IPM.delclass( _next, "tree-closed" );
_sel._isopen = this._opens[_sel.id] = true;
},
hasItem: function(_id)
{
return this._archive[_id];
},
_recvclick: function(e)
{
e = e || event;
var _d = e.target || e.srcElement;
if( !_d ) return;
IPM.evt.nobubble(e);
var _tagn = _d.tagName;
var _expando = (_tagn == "IMG") && /expando$/i.test( _d.id );
if( _tagn != "LI" ) _d = IPM.dom.up( _d, "LI" );
if( !_d ) return;
var _rel = _d.getAttribute('rel');
if( !_rel ) return;
if( /^[a-zA-Z]/.test( _rel ) ) _rel = _rel.substr(1);
if( this.onclick && !this.onclick(e,{ rel: _rel, item: this._archive[_rel], obj: this }) ) return;
this.selectItem( _rel, true, _expando );
},
_flushperf: function()
{
var _rate = 0;
var _now = new Date().getTime();
var _diff = _now - this._renderstart;
if( _diff ) _rate = (Math.round( (this._rendercount*1000 / _diff) * 100 ) / 100) + "/s";
else _rate = " ...";
window.status = 'Tree Nodes: ' + _rate;
}
};

