// xAddEventListener3, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Modified by Ivan Pepelnjak, 11Nov06
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xAddEventListener3(e,eT,eL,cap)
{
  if(!(e=xGetElementById(e))) return;
  eT=eT.toLowerCase();
  if (e==window && !e.opera && !document.all) { // simulate resize and scroll events for all except Opera and IE
    if(eT=='resize') {
      e.xPCW=xClientWidth(); e.xPCH=xClientHeight();
      var pREL = e.xREL ;
      e.xREL= pREL ? function() { eL(); pREL(); } : eL;
      xResizeEvent(); return;
    }
    if(eT=='scroll') {
      e.xPSL=xScrollLeft(); e.xPST=xScrollTop();
      var pSEL = e.xSEL ;
      e.xSEL=pSEL ? function() { eL(); pSEL(); } : eL;
      xScrollEvent(); return; }
  }
  if(e.addEventListener) e.addEventListener(eT,eL,cap);
  else if(e.attachEvent) e.attachEvent('on'+eT,eL);
  else {
    var pev = e['on'+eT] ;
    e['on'+eT]= pev ? function() { eL(); typeof(pev) == 'string' ? eval(pev) : pev(); } : eL ;
  }
}

// xAddEventListener r8, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xAddEventListener(e, eT, eL, cap){
    if (!(e = xGetElementById(e)))
        return;
    eT = eT.toLowerCase();
    if (e.addEventListener)
        e.addEventListener(eT, eL, cap || false);
    else
        if (e.attachEvent)
            e.attachEvent('on' + eT, eL);
        else {
            var o = e['on' + eT];
            e['on' + eT] = typeof o == 'function' ? function(v){
                o(v);
                eL(v);
            }
 : eL;
        }
}

// called only from the above
function xResizeEvent()
{
  if (window.xREL) setTimeout('xResizeEvent()', 250);
  var w=window, cw=xClientWidth(), ch=xClientHeight();
  if (w.xPCW != cw || w.xPCH != ch) { w.xPCW = cw; w.xPCH = ch; if (w.xREL) w.xREL(); }
}
function xScrollEvent()
{
  if (window.xSEL) setTimeout('xScrollEvent()', 250);
  var w=window, sl=xScrollLeft(), st=xScrollTop();
  if (w.xPSL != sl || w.xPST != st) { w.xPSL = sl; w.xPST = st; if (w.xSEL) w.xSEL(); }
}

// xCamelize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xCamelize(cssPropStr)
{
  var i, c, a = cssPropStr.split('-');
  var s = a[0];
  for (i=1; i<a.length; ++i) {
    c = a[i].charAt(0);
    s += a[i].replace(c, c.toUpperCase());
  }
  return s;
}

// xClientHeight r5, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}

// xClientWidth r5, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xClientWidth()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
    {v=d.documentElement.clientWidth;}
  else if(d.body && d.body.clientWidth)
    {v=d.body.clientWidth;}
  else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
    v=w.innerWidth;
    if(d.height>w.innerHeight) v-=16;
  }
  return v;
}

// xDef r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

// written by Mike Bailey
function xDetectVertScrollbar() {
	var d = xDocSize();
	return d.h > xClientHeight();
}

// written by Mike Bailey
function xDetectHorzScrollbar() {
	var d = xDocSize();
	return d.w > xClientWidth();
}

// written by Mike Bailey
function xDetectElemVertScrollBar(e) {
	var d = xElemSize(e);
	return d.h > xHeight(e);
}

// written by Mike Bailey
function xDetectElemHorzScrollBar(e) {
	var d = xElemSize(e);
	return d.w > xWidth(e);
}

// xDocSize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xDocSize()
{
  var b=document.body, e=document.documentElement;
  var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
//  alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
  return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

// written by Mike Bailey
function xElemSize(el) {
	var b=document.getElementById(el);
	var bsw=0, bow=0, bsh=0, boh=0;
	if (b) {
		bsw = b.scrollWidth;
		bow = b.offsetWidth;
		bsh = b.scrollHeight;
		boh = b.offsetHeight;
	}

	return {w:Math.max(bsw,bow),h:Math.max(bsh,boh)};
}

// xGetComputedStyle r7, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetComputedStyle(e, p, i)
{
  if(!(e=xGetElementById(e))) return null;
  var s, v = 'undefined', dv = document.defaultView;
  if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(e,'');
    if (s) v = s.getPropertyValue(p);
  }
  else if(e.currentStyle) {
    v = e.currentStyle[xCamelize(p)];
  }
  else return null;
  return i ? (parseInt(v) || 0) : v;
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

function xGetElementsByClassName(c, p, t, f){
    var r = new Array();
    var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
    var e = xGetElementsByTagName(t, p);
    for (var i = 0; i < e.length; ++i) {
        if (re.test(e[i].className)) {
            r[r.length] = e[i];
            if (f)
                f(e[i]);
        }
    }
    return r;
}

function xGetElementsByTagName(t, p){
    var list = null;
    t = t || '*';
    p = p || document;
    if (typeof p.getElementsByTagName != 'undefined') {
        list = p.getElementsByTagName(t);
        if (t == '*' && (!list || !list.length))
            list = p.all;
    }
    else {
        if (t == '*')
            list = p.all;
        else
            if (p.all && p.all.tags)
                list = p.all.tags(t);
    }
    return list || new Array();
}

function xHasPoint(e, x, y, t, r, b, l){
    if (!xNum(t)) {
        t = r = b = l = 0;
    }
    else
        if (!xNum(r)) {
            r = b = l = t;
        }
        else
            if (!xNum(b)) {
                l = r;
                b = t;
            }
    var eX = xPageX(e), eY = xPageY(e);
    return (x >= eX + l && x <= eX + xWidth(e) - r && y >= eY + t && y <= eY + xHeight(e) - b);
}

function xPageX(e){
    var x = 0;
    e = xGetElementById(e);
    while (e) {
        if (xDef(e.offsetLeft))
            x += e.offsetLeft;
        e = xDef(e.offsetParent) ? e.offsetParent : null;
    }
    return x;
}

function xPageY(e){
    var y = 0;
    e = xGetElementById(e);
    while (e) {
        if (xDef(e.offsetTop))
            y += e.offsetTop;
        e = xDef(e.offsetParent) ? e.offsetParent : null;
    }
    return y;
}

function xResizeTo(e, w, h){
    xWidth(e, w);
    xHeight(e, h);
}

// xHeight r6, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xHeight(e,h)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(h)) {
    if (h<0) h = 0;
    else h=Math.round(h);
  }
  else h=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    h = xClientHeight();
  }
  else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(h>=0) {
      var pt=0,pb=0,bt=0,bb=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pt=gcs(e,'padding-top',1);
        if (pt !== null) {
          pb=gcs(e,'padding-bottom',1);
          bt=gcs(e,'border-top-width',1);
          bb=gcs(e,'border-bottom-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetHeight,e.style.height)){
          e.style.height=h+'px';
          pt=e.offsetHeight-h;
        }
      }
      h-=(pt+pb+bt+bb);
      if(isNaN(h)||h<0) return;
      else e.style.height=h+'px';
    }
    h=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(h>=0) e.style.pixelHeight=h;
    h=e.style.pixelHeight;
  }
  return h;
}

// xNum r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

function xLeft(e, iX){
    if (!(e = xGetElementById(e)))
        return 0;
    var css = xDef(e.style);
    if (css && xStr(e.style.left)) {
        if (xNum(iX))
            e.style.left = iX + 'px';
        else {
            iX = parseInt(e.style.left);
            if (isNaN(iX))
                iX = xGetComputedStyle(e, 'left', 1);
            if (isNaN(iX))
                iX = 0;
        }
    }
    else
        if (css && xDef(e.style.pixelLeft)) {
            if (xNum(iX))
                e.style.pixelLeft = iX;
            else
                iX = e.style.pixelLeft;
        }
    return iX;
}

function xTop(e, iY){
    if (!(e = xGetElementById(e)))
        return 0;
    var css = xDef(e.style);
    if (css && xStr(e.style.top)) {
        if (xNum(iY))
            e.style.top = iY + 'px';
        else {
            iY = parseInt(e.style.top);
            if (isNaN(iY))
                iY = xGetComputedStyle(e, 'top', 1);
            if (isNaN(iY))
                iY = 0;
        }
    }
    else
        if (css && xDef(e.style.pixelTop)) {
            if (xNum(iY))
                e.style.pixelTop = iY;
            else
                iY = e.style.pixelTop;
        }
    return iY;
}

function xMoveTo(e, x, y){
    xLeft(e, x);
    xTop(e, y);
}

function xOpacity(e, o){
    var set = xDef(o);
    if (!(e = xGetElementById(e)))
        return 2;
    if (xStr(e.style.opacity)) {
        if (set)
            e.style.opacity = o + '';
        else
            o = parseFloat(e.style.opacity);
    }
    else
        if (xStr(e.style.filter)) {
            if (set)
                e.style.filter = 'alpha(opacity=' + (100 * o) + ')';
            else
                if (e.filters && e.filters.alpha) {
                    o = e.filters.alpha.opacity / 100;
                }
        }
        else
            if (xStr(e.style.MozOpacity)) {
                if (set)
                    e.style.MozOpacity = o + '';
                else
                    o = parseFloat(e.style.MozOpacity);
            }
            else
                if (xStr(e.style.KhtmlOpacity)) {
                    if (set)
                        e.style.KhtmlOpacity = o + '';
                    else
                        o = parseFloat(e.style.KhtmlOpacity);
                }
    return isNaN(o) ? 1 : o;
}

// xScrollLeft r3, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xScrollLeft(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollLeft) offset=w.document.documentElement.scrollLeft;
    else if(w.document.body && xDef(w.document.body.scrollLeft)) offset=w.document.body.scrollLeft;
  }
  else {
    e = xGetElementById(e);
    if (e && xNum(e.scrollLeft)) offset = e.scrollLeft;
  }
  return offset;
}

// xScrollTop r3, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xScrollTop(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
    e = xGetElementById(e);
    if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}

// xStr r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

function xStyle(sProp, sVal){
    var i, e;
    for (i = 2; i < arguments.length; ++i) {
        e = xGetElementById(arguments[i]);
        if (e.style) {
            try {
                e.style[sProp] = sVal;
            }
            catch (err) {
                e.style[sProp] = '';
            }
        }
    }
}

// xWidth r6, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xWidth(e,w)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
  }
  else w=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
  }
  else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
  }
  return w;
}

function hoverOn(e,col) {
	e.style.backgroundColor = col;
}

function hoverOff(e,col) {
	e.style.backgroundColor = col;
}

function goTo(u) {
	document.location.href = u;

	return false;
}

// Browser detection
var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
if (window.opera) {
  	var i=xUA.indexOf('opera');
  	if (i!=-1) {
    		var v=parseInt(xUA.charAt(i+6));
    		xOp7Up=v>=7;
    		xOp6Dn=v<7;
  	}
} else if (navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1) {
  	xIE4Up=parseFloat(navigator.appVersion) >= 4;
  	xIE4=xUA.indexOf('msie 4') != -1;
  	xIE5=xUA.indexOf('msie 5') != -1;
} else if (document.layers) {
	xNN4=true;
}
xMac = xUA.indexOf('mac')!=-1;

// xModalDialog r2, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xModalDialog(sDialogId,level2) // Object Prototype
{
    /*@cc_on @if (@_jscript_version >= 5.5) @*/
    //  not supported in IE until v5.5
    this.dialog = xGetElementById(sDialogId);
    xModalDialog.instances[sDialogId] = this;
    if (level2) {
    	var e = xModalDialog.grey2;
	    if (!e) { // only one per page
	        e = document.createElement('div');
	        e.className = 'xModalDialogGreyElement xModalDialogGreyElement_level2';
	        xModalDialog.grey2 = document.body.appendChild(e);
	    }
	    var s = xModalDialog.shadow2;
	    if (!s) { // only one per page
	        s = document.createElement('div');
	        s.className = 'xModalDialogShadowElement xModalDialogShadowElement_level2';
	        xModalDialog.shadow2 = document.body.appendChild(s);
	    }
    } else {
    	var e = xModalDialog.grey;
	    if (!e) { // only one per page
	        e = document.createElement('div');
	        e.className = 'xModalDialogGreyElement';
	        xModalDialog.grey = document.body.appendChild(e);
	    }
	    var s = xModalDialog.shadow;
	    if (!s) { // only one per page
	        s = document.createElement('div');
	        s.className = 'xModalDialogShadowElement';
	        xModalDialog.shadow = document.body.appendChild(s);
	    }
    }
    /*@end @*/
}

// Public Methods

xModalDialog.prototype.show = function(displayOverModal){
	var ds;
	var e = (displayOverModal) ? xModalDialog.grey2 : xModalDialog.grey;
	var s = (displayOverModal) ? xModalDialog.shadow2 : xModalDialog.shadow;

	if (e) {
		// disable select elements for IE6 and older
		if (browser == 'msie' && browser_version <= '6') {
			var sels = xGetElementsByTagName('select');
			for (var i=0; i<sels.length; ++i) {
				sels[i].style.visibility = 'hidden';
			}
		}
		// hide all flash (object tags or embed tags)
		var objs = xGetElementsByTagName('object');
		for (var i=0; i<objs.length; ++i) {
			objs[i].style.visibility = 'hidden';
		}
		var embs = xGetElementsByTagName('embed');
		for (var i=0; i<embs.length; ++i) {
			embs[i].style.visibility = 'hidden';
		}

        this.dialog.greyZIndex = xGetComputedStyle(e, 'z-index', 1);
        e.style.zIndex = xGetComputedStyle(this.dialog, 'z-index', 1) - 2;
        ds = xDocSize();
        xMoveTo(e, 0, 0);
        xResizeTo(e, ds.w, ds.h);
        if (this.dialog) {
        	var fromLeft = xScrollLeft() + (xClientWidth() - this.dialog.offsetWidth) / 2;
        	var fromTop = xScrollTop() + (xClientHeight() - this.dialog.offsetHeight) / 2;
    		if (this.lb_type == 'win' && fromTop < 20) {
    			fromTop = 20;
    		} else if (fromTop < 0) {
    			fromTop = 0;
    		}
    		if (fromLeft < 0) {
    			fromLeft = 0;
    		}
        	xMoveTo(this.dialog, fromLeft, fromTop);
        }

        if (s) {
        	var sdim = 2; //1;
        	s.style.zIndex = xGetComputedStyle(this.dialog, 'z-index', 1) - 1;
        	xMoveTo(s, xGetComputedStyle(this.dialog, 'left', 1) - sdim, xGetComputedStyle(this.dialog, 'top', 1) - sdim);

        	var sheight = xGetComputedStyle(this.dialog, 'height', 1);
        	if (parseInt(sheight) == 0) {
        		sheight = xHeight(this.dialog) - 2;
        	} else {
        		sheight -= 1;
        	}

        	var scomp = 6 + (sdim - 1) * 2;
        	if (browser == 'msie') {
        		scomp = 4 + (sdim - 1) * 2;
        		if (browser_version <= '6') {
        			sheight += 1;
        		}
        	}

        	xResizeTo(s, xGetComputedStyle(this.dialog, 'width', 1) + scomp, sheight + scomp);
        }

        // focus on action in modal window
		if (this.focusElement) {
			try {
				xGetElementById(this.focusElement).focus();
			} catch (err) {}
		}
    }
};

xModalDialog.prototype.hide = function(displayOverModal){
    var e = (displayOverModal) ? xModalDialog.grey2 : xModalDialog.grey;
    var s = (displayOverModal) ? xModalDialog.shadow2 : xModalDialog.shadow;

    if (e) {
		// enable select elements for IE6 and older
		if (browser == 'msie' && browser_version <= '6') {
			var sels = xGetElementsByTagName('select');

			for (var i=0; i<sels.length; ++i) {
				sels[i].style.visibility = 'visible';
			}
		}
		// hide all flash (object tags or embed tags)
		var objs = xGetElementsByTagName('object');
		for (var i=0; i<objs.length; ++i) {
			objs[i].style.visibility = 'visible';
		}
		var embs = xGetElementsByTagName('embed');
		for (var i=0; i<embs.length; ++i) {
			embs[i].style.visibility = 'visible';
		}

        xResizeTo(e, 10, 10);
       	xMoveTo(e, -10, -10);

       	if (s) {
        	xMoveTo(s, 10, 10);
        	xResizeTo(s, -10, -10);
        }

       	if (this.dialog) {
            e.style.zIndex = this.dialog.greyZIndex;
            xMoveTo(this.dialog, -this.dialog.offsetWidth, 0);
        }
    }
};

function Confirm(sMsgHtml, fnCallback){
	buildConfirmBox();

    var y = xGetElementById('idCDYes');
    var n = xGetElementById('idCDNo');
    if (y && n) {
        xGetElementById('idCDMsg').innerHTML = sMsgHtml;
        y.onclick = n.onclick = function(){
			xModalDialog.instances.idConfirmDialog.hide(true);
			fnCallback(this.id == 'idCDYes');
        };
        xModalDialog.instances.idConfirmDialog.show(true);
    }
}

function Prompt(sMsgHtml, default_value, fnCallback){
	buildPromptBox();

    var ok = xGetElementById('idPDOk');
    var cancel = xGetElementById('idPDCancel');
    if (ok && cancel) {
        xGetElementById('idPDMsg').innerHTML = sMsgHtml;
        xGetElementById('idPDInput').value = default_value;
        cancel.onclick = function(){
			xModalDialog.instances.idPromptDialog.hide(true);
        };
        ok.onclick = function(){
            xModalDialog.instances.idPromptDialog.hide(true);
            fnCallback(xGetElementById('idPDInput').value);
        };
        xModalDialog.instances.idPromptDialog.show(true);
    }
}

function Alert(sMsgHtml){
	buildAlertBox();

    var ok = xGetElementById('idADOk');
    if (ok) {
        xGetElementById('idADMsg').innerHTML = sMsgHtml;
        ok.onclick = function(){
            xModalDialog.instances.idAlertDialog.hide(true);
        };
        xModalDialog.instances.idAlertDialog.show(true);
    }
}

function Help(url){
	buildHelpBox();

	w = 400;
	h = 300;

	var close = xGetElementById('idHDClose');
    if (close) {
        xGetElementById('idHelpDialog').style.width = w + 'px';
        xGetElementById('idHelpDialog').style.height = h + 'px';
        close.onclick = function(){
            xModalDialog.instances.idHelpDialog.hide(true);
    		xGetElementById('idHDFrame').src = '/static/images/blank.gif';
    		return false;
        };

        try {
        	xModalDialog.instances.idHelpDialog.show(true);
        } catch (err) {
        	xGetElementById('idHDFrame').src = '/static/images/blank.gif';
        	return true; // the modal window did not open
        }

        if (url != '') {
	        // only load the requested url if the modal window was successfully displayed
	        xGetElementById('idHDFrame').src = url;
        }

        return false;
    }

    return true;
}

function Info(sMsgHtml, autoclose, timeToClose){
	buildInfoBox(autoclose);

	if (autoclose) {
		xGetElementById('idIADMsg').innerHTML = sMsgHtml;
		xModalDialog.instances.idInfoAutoDialog.show();
		if (!timeToClose) timeToClose = 3000;
		setTimeout("xModalDialog.instances.idInfoAutoDialog.hide();", timeToClose);
	} else {
		var ok = xGetElementById('idIDOk');
	    if (ok) {
	        xGetElementById('idIDMsg').innerHTML = sMsgHtml;
	        ok.onclick = function(){
	            xModalDialog.instances.idInfoDialog.hide();
	        };
	        xModalDialog.instances.idInfoDialog.show();
	    }
	}
}

function InProgress(sMsgHtml) {
	buildInProgressBox();
	xGetElementById('idIPDMsg').innerHTML = sMsgHtml;
	xModalDialog.instances.idInProgressDialog.show(true);
    ipd_scroller.togglePause(true);
}

function closeInProgress() {
    ipd_scroller.togglePause();
    xModalDialog.instances.idInProgressDialog.hide(true);
}

function closeMiniWin() {
	xModalDialog.instances.idMiniWinDialog.hide();
    xGetElementById('idMWDFrame').src = '/static/images/blank.gif';
    fnMiniWinCallback();
    fnMiniWinCallback = function(){};
    return false;
}

function MiniWinReceptor(w,h) {
	return MiniWin('', w, h);
}

function MiniWin_Task(f, fnCallback) {
	MiniWin('', 650, 350, fnCallback);
	return submitForm(f);
}

function MiniWin_Worksheet(url, fnCallback) {
	MiniWin(url, 650, 425, fnCallback);
	return false;
}

function openPreview(url) {
	MiniWin(url, 650, 450);
	return false;
}

var fnMiniWinCallback = function(){};
function MiniWin(url, w, h, fnCallback) {
	buildMiniWinBox();

	var close = xGetElementById('idMWDClose');
    if (close) {
    	if (fnCallback) fnMiniWinCallback = fnCallback;
        xGetElementById('idMiniWinDialog').style.width = w + 'px';
        xGetElementById('idMiniWinDialog').style.height = h + 'px';
        close.onclick = function(){
			return closeMiniWin();
        };

        try {
        	xModalDialog.instances.idMiniWinDialog.show();
        } catch (err) {
        	xGetElementById('idMWDFrame').src = '/static/images/blank.gif';
        	return true; // the modal window did not open
        }

        if (url != '') {
	        // only load the requested url if the modal window was successfully displayed
	        xGetElementById('idMWDFrame').src = url;
        }

        return false;
    }

    return true;
}

function MiniWinClose() {
	return closeMiniWin();
}

function buildMiniWinBox() {
	if (xGetElementById('idMiniWinDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idMiniWinDialog';
	__box.className = 'clsModalDialog';
	__box.innerHTML = '<iframe id="idMWDFrame" name="submission_receptor" frameborder="0" src="/static/images/blank.gif"></iframe>';
	var __closewin = document.createElement('a');
	__closewin.href = '#';
	__closewin.id = 'idMWDClose';
	__closewin.className = 'close';
	__closewin.innerHTML = 'close';
	__box.appendChild(__closewin);

	document.body.appendChild(__box);
}

function buildHelpBox() {
	if (xGetElementById('idHelpDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idHelpDialog';
	__box.className = 'clsModalDialog';
	__box.innerHTML = '<iframe id="idHDFrame" name="help_frame" frameborder="0" src="/static/images/blank.gif"></iframe>';
	var __closewin = document.createElement('a');
	__closewin.href = '#';
	__closewin.id = 'idHDClose';
	__closewin.className = 'close';
	__closewin.innerHTML = 'close';
	__box.appendChild(__closewin);

	document.body.appendChild(__box);
}

function buildAlertBox() {
	if (xGetElementById('idAlertDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idAlertDialog';
	__box.className = 'clsModalDialog';
	var __h4 = document.createElement('h4');
	__h4.innerHTML = 'Alert';
	__box.appendChild(__h4);
	var __form1 = document.createElement('form');
	__form1.id = 'idADForm';
	__form1.action = '#';
	__form1.onsubmit = function() { return false; };
	__box.appendChild(__form1);
	var __div_msg = document.createElement('div');
	__form1.appendChild(__div_msg);
	var __div_msg_p = document.createElement('p');
	__div_msg_p.id = 'idADMsg';
	__div_msg.appendChild(__div_msg_p);
	var __div_act = document.createElement('div');
	__div_act.className = 'done';
	__form1.appendChild(__div_act);
	var __div_act_in = document.createElement('input');
	__div_act_in.id = 'idADOk';
	__div_act_in.type = 'button';
	__div_act_in.className = 'submit';
	__div_act_in.value = 'Ok';
	__div_act.appendChild(__div_act_in);

	document.body.appendChild(__box);
}

function buildInfoBox(autoclose) {
	if (autoclose) {
		if (xGetElementById('idInfoAutoDialog')) return;

		var __box = document.createElement('div');
		__box.id = 'idInfoAutoDialog';
		__box.className = 'clsModalDialog';
		var __div_msg = document.createElement('div');
		__box.appendChild(__div_msg);
		var __div_msg_p = document.createElement('p');
		__div_msg_p.id = 'idIADMsg';
		__div_msg_p.className = 'large_msg';
		__div_msg.appendChild(__div_msg_p);
		var __div_act_in = document.createElement('input');
		__div_act_in.id = 'idIADOk';
		__div_act_in.type = 'hidden';
		__div_act_in.value = 'Ok';
		__div_msg.appendChild(__div_act_in);
	} else {
		if (xGetElementById('idInfoDialog')) return;

		var __box = document.createElement('div');
		__box.id = 'idInfoDialog';
		__box.className = 'clsModalDialog';
		var __form1 = document.createElement('form');
		__form1.id = 'idIDForm';
		__form1.action = '#';
		__form1.onsubmit = function() { return false; };
	    __box.appendChild(__form1);
		var __div_msg = document.createElement('div');
		__form1.appendChild(__div_msg);
		var __div_msg_p = document.createElement('p');
		__div_msg_p.id = 'idIDMsg';
		__div_msg.appendChild(__div_msg_p);
		var __div_act = document.createElement('div');
		__div_act.className = 'done';
		__form1.appendChild(__div_act);
		var __div_act_in = document.createElement('input');
		__div_act_in.id = 'idIDOk';
		__div_act_in.type = 'button';
		__div_act_in.className = 'submit';
		__div_act_in.value = 'Ok';
		__div_act.appendChild(__div_act_in);
	}

	document.body.appendChild(__box);
}

function buildConfirmBox() {
	if (xGetElementById('idConfirmDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idConfirmDialog';
	__box.className = 'clsModalDialog';
	var __h4 = document.createElement('h4');
	__h4.innerHTML = 'Confirm';
	__box.appendChild(__h4);
	var __form1 = document.createElement('form');
	__form1.id = 'idCDForm';
	__form1.action = '#';
	__form1.onsubmit = function() { return false; };
	__box.appendChild(__form1);
	var __div_msg = document.createElement('div');
	__form1.appendChild(__div_msg);
	var __div_msg_p = document.createElement('p');
	__div_msg_p.id = 'idCDMsg';
	__div_msg.appendChild(__div_msg_p);
	var __div_act = document.createElement('div');
	__div_act.className = 'done';
	__form1.appendChild(__div_act);
	var __div_act_in1 = document.createElement('input');
	__div_act_in1.id = 'idCDYes';
	__div_act_in1.type = 'button';
	__div_act_in1.className = 'submit';
	__div_act_in1.value = 'Yes';
	__div_act.appendChild(__div_act_in1);
	var __div_act_text = document.createTextNode(" " + String.fromCharCode(160) + " ");
	__div_act.appendChild(__div_act_text);
	var __div_act_in2 = document.createElement('input');
	__div_act_in2.id = 'idCDNo';
	__div_act_in2.type = 'button';
	__div_act_in2.className = 'submit';
	__div_act_in2.value = 'No';
	__div_act.appendChild(__div_act_in2);

	document.body.appendChild(__box);
}

function buildPromptBox() {
	if (xGetElementById('idPromptDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idPromptDialog';
	__box.className = 'clsModalDialog';
	//var __h4 = document.createElement('h4');
	//__h4.innerHTML = 'Prompt';
	//__box.appendChild(__h4);
	var __form1 = document.createElement('form');
	__form1.id = 'idPDForm';
	__form1.action = '#';
	__form1.onsubmit = function() { return false; };
	__box.appendChild(__form1);
	var __div_msg = document.createElement('div');
	__form1.appendChild(__div_msg);
	var __div_msg_p1 = document.createElement('p');
	__div_msg_p1.id = 'idPDMsg';
	__div_msg_p1.className = 'large_msg';
	__div_msg.appendChild(__div_msg_p1);
	var __div_msg_p2 = document.createElement('p');
	__div_msg.appendChild(__div_msg_p2);
	var __div_msg_p2_in = document.createElement('input');
	__div_msg_p2_in.type = 'text';
	__div_msg_p2_in.id = 'idPDInput';
	__div_msg_p2_in.style.width = '400px';
	__div_msg_p2_in.onkeypress = function(event) {
		if (checkEnter(event)) xGetElementById('idPDOk').click();
	}
	__div_msg_p2.appendChild(__div_msg_p2_in);
	var __div_act = document.createElement('div');
	__div_act.className = 'done';
	__form1.appendChild(__div_act);
	var __div_act_in1 = document.createElement('input');
	__div_act_in1.id = 'idPDOk';
	__div_act_in1.type = 'button';
	__div_act_in1.className = 'submit';
	__div_act_in1.value = 'Ok';
	__div_act.appendChild(__div_act_in1);
	var __div_act_text = document.createTextNode(" " + String.fromCharCode(160) + " ");
	__div_act.appendChild(__div_act_text);
	var __div_act_in2 = document.createElement('input');
	__div_act_in2.id = 'idPDCancel';
	__div_act_in2.type = 'button';
	__div_act_in2.className = 'submit';
	__div_act_in2.value = 'Cancel';
	__div_act.appendChild(__div_act_in2);

	document.body.appendChild(__box);
}

var ipd_scroller;
function buildInProgressBox() {
	if (xGetElementById('idInProgressDialog')) return;

	var __box = document.createElement('div');
	__box.id = 'idInProgressDialog';
	__box.className = 'clsModalDialog';
	var __div_msg = document.createElement('div');
	__box.appendChild(__div_msg);
	var __div_msg_p = document.createElement('p');
	__div_msg_p.id = 'idIPDMsg';
	__div_msg_p.className = 'large_msg';
	__div_msg.appendChild(__div_msg_p);
	var __div_act = document.createElement('div');
	__div_act.id = 'idIPDBox';
	__div_act.className = 'done';
	__box.appendChild(__div_act);

	document.body.appendChild(__box);

	ipd_scroller = createBar(278, 10, '#fff', 1, '#444', '#64a520', 85, 7, 3, '', __div_act.id);
	ipd_scroller.togglePause();
}

var __cb_w3c = (document.getElementById) ? true : false;
var __cb_ie = (document.all) ? true : false;
var __cb_N = -1;

// This function builds the scrolling bar that shows up when called.
//
// @param w 		: width of the main box
// @param h 		: height of the main box
// @param bgc 		: the background color of the main box
// @param brdW 		: the border width of the main box
// @param brdC		: the border color of the main box
// @param blkC		: the background color of the individual blocks in the scrolling bar
// @param speed		: the scrolling speed of the blocks
// @param blocks	: the number of blocks to create in the scrolling bar
// @param count		: the number of times to scroll
// @param action	: the action to perform aftre scrolling 'count' times
// @param wrid		: the id of the parent element to write the scrolling bar out to
//
// @return reference to the scrolling bar object
function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action,wrid){
	try {
		if (wrid) {
			var wrid_block = document.getElementById(wrid);
		}

		if(__cb_ie||__cb_w3c){
			var sbar = document.createElement('div');
			sbar.id = '_xpbar' + (++__cb_N);
			sbar.style.visibility = 'visible';
			sbar.style.position = 'relative';
			sbar.style.overflow = 'hidden';
			sbar.style.width = w + 'px';
			sbar.style.height = h + 'px';
			sbar.style.backgroundColor = bgc;
			sbar.style.borderColor = brdC;
			sbar.style.borderWidth = brdW + 'px';
			sbar.style.borderStyle = 'solid';
			sbar.style.fontSize = '1px';

			var spb = document.createElement('span');
			spb.id = 'blocks' + __cb_N;
			spb.style.left = '-' + (h * 2 + 1) + 'px';
			spb.style.position = 'absolute';
			spb.style.fontSize = '1px';
			sbar.appendChild(spb);

			for(i=0;i<blocks;i++){
				var spn = document.createElement('span');
				spn.id = "blk_" + i;
				spn.style.backgroundColor = blkC;
				spn.style.left = '-' + ((h * i) + i) + 'px';
				spn.style.fontSize = '1px';
				spn.style.position = 'absolute';
				spn.style.width = h + 'px';
				spn.style.height = h + 'px';

				if (__cb_ie) {
					spn.style.filter = 'alpha(opacity=' + (Math.floor(100 - i * (100 / blocks))) + ')';
				} else {
					spn.style.setProperty('-moz-opacity', (Math.floor(100 - i * (100 / blocks))) / 100, '');
				}

				spb.appendChild(spn);
			}

			if (wrid_block) {
				wrid_block.appendChild(sbar);
			} else {
				document.body.appendChild(sbar);
			}

			var bA=(__cb_ie)?document.all['blocks'+__cb_N]:document.getElementById('blocks'+__cb_N);

			bA.bar=(__cb_ie)?document.all['_xpbar'+__cb_N]:document.getElementById('_xpbar'+__cb_N);
			bA.blocks=blocks;
			bA.N=__cb_N;
			bA.w=w;
			bA.h=h;
			bA.speed=speed;
			bA.ctr=0;
			bA.count=count;
			bA.action=action;
			bA.togglePause=togglePause;
			bA.showBar=function(){
				this.bar.style.visibility="visible";
			}
			bA.hideBar=function(){
				this.bar.style.visibility="hidden";
			}
			bA.toggleVisibility=function(){
				if(this.bar.style.visibility == "visible"){
					this.bar.style.visibility="hidden";
				}else{
					this.bar.style.visibility="visible";
				}
			}
			bA.tid=setInterval('startBar('+__cb_N+')',speed);

			return bA;
		}
	}
	catch (err) {
		displayErrorMsg("createBar()",err);
	}
}

function displayErrorMsg(fun,e) {
	var str = "Error in " + fun + ":";
	str += "\n\tnumber:" + e.number;
	str += "\n\tdescr: " + e.description;
	str += "\n\tname: " + e.name;
	str += "\n\tmessage: " + e.message;

	alert(str);
}

function startBar(bn){
	var t=(__cb_ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
	if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
		t.style.left=-(t.h*2+1)+'px';
		t.ctr++;

		if(t.ctr>=t.count){
			eval(t.action);
			t.ctr=0;
		}
	}else{
		t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
	}
}

function togglePause(forceStart){
	clearInterval(this.tid);
	if(this.tid == 0 || forceStart){
		this.tid=setInterval('startBar('+this.N+')',this.speed);
	}else{
		this.tid = 0;
	}
}

var enableCustomConfirm = false;
var enableCustomAlert = false;
var enableCustomPrompt = false;
var enableCustomInProgress = false;
var enableCustomInfo = false;
var enableCustomMiniWin = false;
var enableCustomHelp = false;
var enableAll = false;










