// $Header: /Kahlan/WebControls/kahlan_ctrls/1_0/utils.js 6     3-08-03 21:03 M.kieslich $
// Zbiór ogólnych procedur narzędziowych wykorzystywanych przez kontrolki
var _d=document;
var ns4=(_d.layers)?true:false
var ns6=(navigator.userAgent.indexOf("Gecko")!=-1)?true:false
var mac=(navigator.appVersion.indexOf("Mac")!=-1)?true:false
var mac45=(navigator.appVersion.indexOf("MSIE 4.5")!=-1)?true:false
if(ns6||ns4)
  mac=false
var opra=(navigator.userAgent.indexOf("Opera")!=-1)?true:false
if(mac&&opra)
  mac=0
var ns61=(parseInt(navigator.productSub)>=20010726)?true:false
var ie4=(!_d.getElementById&&_d.all)?true:false;
ta=0;
var ie55=((navigator.appVersion.indexOf("MSIE 6.0")!=-1||navigator.appVersion.indexOf("MSIE 5.5")!=-1))?true:false;
var ie = ie4||ie55;
if(ie55&&opra)
  ie55=false;
var konq=(navigator.userAgent.indexOf("Konqueror")!=-1)?true:false
var IEDtD=0;
if((_d.all&&_d.compatMode=="CSS1Compat")||(mac&&_d.doctype&&_d.doctype.name.indexOf(".dtd")!=-1))
  IEDtD=1;
var mp=(ns6)?"pointer":"hand";
var KCPath = "/fileadmin/templates/kahlan_ctrls/1_1_0008";
var KCBlankPage = KCPath+"/blank.htm";
var KCImagesPath = KCPath+"/images";
var KCStylesPath = KCPath+"/styles";
var kc_pureSubmit=false;
var kc_submited=false;
function kc_disposeArray(array)
{
  if(array)
  {
    for(var i=0;i<array.length;i++)
      if(array[i]!=null)
        delete array[i];
    array.length = 0;
  }
}
function kc_form()
{
  return document.forms[0];
}
function kc_typeOf(obj)
{
  return (obj!=null && typeof(obj)=="object" && typeof(obj.typeOf)=="function") ? obj.typeOf() : typeof(obj);
}
function kc_checkType(obj,typeName)
{
  return kc_typeOf(obj)==typeName;
}
// Example: obj = findObj("image1");
function kc_findObj(theObj, theDoc)
{
//  if(document.getElementById) 
//    return document.getElementById(theObj);
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = kc_findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function kc_showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = kc_findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}
function kc_setDisplay(name,value)
{
	var obj
	if ((obj = kc_findObj(name)) != null)
	{
		if (obj.style)
			obj = obj.style;
		obj.display = value;
	}
}
function kc_getDisplay(name)
{
	var obj
	if ((obj = kc_findObj(name)) != null)
	{
		if (obj.style)
			obj = obj.style;
		return obj.display;
	}
	return "";
}
function kc_setStyle(objInstance,cssText)
{
  try
  {
    if(typeof(objInstance.style.cssText)=="undefined")
      objInstance.style = cssText;
    else
      objInstance.style.cssText = cssText;
  }
  catch(e)
  {
  }
}
function kc_setWidth(object,value)
{
  try
  {
    object.style.width = value;
  }
  catch(e)
  {
  }
}
function kc_setHeight(object,value)
{
  try
  {
    object.style.height = value;
  }
  catch(e)
  {
  }
}
function kc_copyStyle(destInstance,srcInstance)
{
  kc_setStyle(destInstance,srcInstance.style.cssText);
}
function KCBound(l,t,r,b)
{
  this.l = l;
  this.t = t;
  this.r = r;
  this.b = b;
}
function KCPos(x,y)
{
  this.x = x;
  this.y = y;
}
KCPos.prototype.move = function(x,y)
{
  this.x += x;
  this.y += y;
}
function KCSize(w,h)
{
  this.w = w;
  this.h = h;
}
function KCBox(x,y,w,h)
{
  this.__constructorPos = KCPos;
  this.__constructorSize = KCSize;
  this.__constructorPos(x,y);
  this.__constructorSize(w,h);
  this.move = KCPos.prototype.move;
  this.contains = function(point)
  {
    return (point.x>=this.x && point.x<this.x+this.w && point.y>=this.y && point.y<this.y+this.w);
  }
}
function kc_mousePos(e)
{
  var result = new KCPos(0,0);
  if(window.event)
  {
    result.x=window.event.clientX;
    result.y=window.event.clientY
  }
  else if(window.Event)
  {
    result.x=window.Event.clientX;
    result.y=window.Event.clientY
  }
  else if(ns4||ns6)
  {
    result.x=e.pageX;
    result.y=e.pageY;
  }
  if(!opra&&_d.all)
  {
    result.x+=_d.body.scrollLeft;
    result.y+=_d.body.scrollTop;
    if(IEDtD)
      result.y=result.y+1
  }
  return result;
}
/*---------------------*/
function KCEventObject(e)
{
  this.mousePos = kc_mousePos(e);
}
function KCEvent(source,eventName)
{
  this.source = source;
  this.eventName = eventName;
}
KCEvent.prototype.attach = function(funcBody)
{
  this.attachCallback(new Function(funcBody));
}
KCEvent.prototype.attachCallback = function(callback)
{
  this.callback = callback;
  if(this.source.addEventListener)
    this.source.addEventListener(this.eventName,this.callback,false);
  else if(this.source.attachEvent)
    this.source.attachEvent("on"+this.eventName,this.callback);
}
KCEvent.prototype.detach = function()
{
  if(typeof(this.callback)=="function")
  {
    if(this.source.removeEventListener)
      this.source.removeEventListener(this.eventName,this.callback,false);
    else 
      if(this.source.detachEvent)
        this.source.attachEvent("on"+this.eventName,this.callback);
    this.callback = null;
  }
}
KCEvent.prototype.toString = function()
{
  return "eventName:<"+this.eventName+">";
}
function KCEventListener(obj,method,custom,callback)
{
  this.obj = obj;
  this.method = method;
  this.custom = custom;
  this.events = new Array();
  this.callback = callback;
}
KCEventListener.prototype.toString = function(ident)
{
  if(ident==null)
    ident="";
  var result = "";
  ident+="    ";
  for(var i=0;i<this.events.length;i++)
    result += ident+"["+i.toString()+"]:"+this.events[i].toString()+"\n";
  return result;
}
KCEventListener.prototype.typeOf = function()
{
  return "KCEventListener";
} 
KCEventListener.prototype.addEvent = function(source,eventName)
{
  var e = new KCEvent(source,eventName);
  this.events[this.events.length]=e;
  e.attachCallback(this.callback);
}
KCEventListener.prototype.fire = function(e)
{
  mousePos = kc_mousePos(e);
  if(typeof(this.method)=="function" && typeof(this.obj)=="object")
    this.method.call(this.obj,this,new KCEventObject(e));
}
KCEventListener.prototype.dispose = function()
{
  for(var i=0;i<this.events.length;i++)
  {
    this.events[i].detach();
    delete this.events[i];
  }
  this.events.length = 0;
  this.obj = null;
  this.method = null;
  this.custom = null;
  this.events = null;
  this.callback = null;
}
function KCEvents()
{
  this.listeners = new Array();
  this.disposed = false;
}
KCEvents.prototype.toString = function(ident)
{
  if(ident==null)
    ident="";
  var result = ident+"listeners:("+this.listeners.length.toString()+")\n";
  ident += "    ";
  for(var i=0;i<this.listeners.length;i++)
  {
    result += ident + "[" + i.toString() + "]\n";
    result += this.listeners[i].toString(ident);
  }
  return result;
}
KCEvents.prototype.addListener = function(source,eventName,obj,method,custom)
{
//  if(typeof(source.typeOf)=="function" && source.typeOf()=="KCEventListener")
  if(kc_checkType(source,"KCEventListener"))
    return this._AddListener(source);
  var result = this._AddListener(new KCEventListener(obj,method,custom));
  this.listeners[result].addEvent(source,eventName);
  return result;
}
KCEvents.prototype._AddListener = function(listener)
{
  var result = this.listeners.length;
  listener.callback = new Function("kc_events.fire("+result.toString()+");");
  listener.index = result;
  this.listeners[result]=listener;
  return result;
}
KCEvents.prototype.addListener2Predecessors = function(source,eventName,obj,method,custom)
{
  var result = this._AddListener(
      (typeof(obj.typeOf)=="function" && obj.typeOf()=="KCEventListener")
        ? obj
        : new KCEventListener(obj,method,custom)
    );
  var listener = this.listeners[result];
  var parent = source.parentNode;
  while(parent!=null)
  {
    listener.addEvent(parent,eventName);
    parent = parent.parentNode;
  }
  return result;
}
KCEvents.prototype.removeListener = function(id)
{
  if(typeof(id)=="object" && id.index!=null)
    id = id.index;
  if(id<this.listeners.length && this.listeners[id]!=null)
  {
    this.listeners[id].dispose();
    delete this.listeners[id];
  }
}
KCEvents.prototype.dispose = function()
{
  if(!this.disposed)
  {
    for(var i=0;i<this.listeners.length;i++)
      this.removeListener(i);
    this.listeners.length = 0;      
  }
  this.disposed=true;
}
KCEvents.prototype.fire = function(id)
{
  if(id<this.listeners.length && this.listeners[id]!=null)
  {
    this.listeners[id].fire();
  }
}
var kc_events = new KCEvents();
function kc_attachEvent(objInstance,eventName,funcPrototype)
{
//  if(objInstance.addEventListener)
//    objInstance.addEventListener(eventName,funcPrototype,false);
//  else if(objInstance.attachEvent)
//    objInstance.attachEvent("on"+eventName,funcPrototype);
    kc_events.addListener(objInstance,eventName,window,funcPrototype);
}
function kc_attachEvent2Parents(objInstance,eventName,funcPrototype)
{
  var parent = objInstance.parentNode;
  while(parent!=null)
  {
    kc_attachEvent(parent,eventName,funcPrototype);
    parent = parent.parentNode;
  }
}
//if(!kc_aeds)
var kc_aeds = new Array();
function kc_aedsAdd(obj)
{
  var result = kc_aeds.length;
  kc_aeds[result] = obj;
  return result;
};
function _kc_attachEventExInvoke(e,id,methodName)
{
  if(id<kc_aeds.length)
  {
    var obj = kc_aeds[id];
    if(obj!=null)
      return eval("obj."+methodName+"(e)");
  }
}
function kc_attachEventEx(objInstance,eventName,objDestination,methodName)
{
  var result = kc_aedsAdd(objDestination);
  var expr =
        "  kc_attachEvent(objInstance,eventName,\n"+
        "     function(e)\n"+
        "     {\n"+
        "       return _kc_attachEventExInvoke(e,"+result.toString()+",\""+methodName+"\");\n"+
        "     }\n"+
        " );";
  eval(expr);
  return result;
}
function kc_attachEvent2ParentsEx(child,eventName,objDestination,methodName)
{
  var result = kc_aedsAdd(objDestination);
  var func = new Function("e"," _kc_attachEventExInvoke(e,"+result.toString()+",\""+methodName+"\");");
  var expr = "kc_attachEvent(parent,eventName,func);";
  var parent = child.parentNode;
  while(parent!=null)
  {
    eval(expr);
    parent = parent.parentNode;
  }
  return result;
}
//if(!document.kc_tds)
var kc_tds = new Array();
function kc_tdsAdd(obj)
{
  var result = kc_tds.length;
  kc_tds[result] = obj;
  return result;
};
function KCTimer(obj,method,periodic)
{
  this.disposed = false;
  this.obj = obj;
  this.method = method;  
  this.periodic = periodic;
  this.index = kc_tdsAdd(this);
  this.code = "kc_tds["+this.index.toString()+"].fire();";
  this.id = null
}
KCTimer.prototype.dispose = function()
{
  if(!this.disposed)
  {
    this.stop();
    kc_tds[this.index] = null;
    this.id = null;
    this.code = null;
    this.obj = null;
    this.method = null;
  }
  this.disposed = true;
}
KCTimer.prototype.isRunning = function()
{
  return this.id!=null;
}
KCTimer.prototype.start = function(interval)
{
  if(this.isRunning())
    this.stop();
  if(this.periodic)
    this.id = setInterval(this.code,interval);
  else
    this.id = setTimeout(this.code,interval);
}
KCTimer.prototype.stop = function()
{
  if(this.id!=null)
  {
    if(this.periodic)
      clearInterval(this.id);
    else
      clearTimeout(this.id);
    this.id = null;
  }
}
KCTimer.prototype.fire = function()
{
  if(!this.periodic)
    this.id = null;
  if(this.obj!=null && this.method!=null)
    this.method.call(this.obj);
}
function kc_close()
{
}
function kc_findA(obj,attr,value)
{
  if(obj.attributes)
  {
    var v=obj.attributes.getNamedItem(attr);
    if(v!=null && v.value==value)
      return obj;
    else if(obj.hasChildNodes())
      for(var i=0; i<obj.childNodes.length; i++)
      {
        var result = kc_findA(obj.childNodes.item(i),attr,value);
        if(result!=null)
          return result;
      }    
  }
  return null; 
}
var kc_ap_bad = new Array("BODY","TABLE");
kc_ap_bad.contain = function(tag)
{
  for(var i=0; i<this.length; i++)
    if(this[i]==tag)
      return true;
  return false;
}
function kc_absolutePos(control,client)
{
  var result;
  var parent;
  if(client==null || client)
  {
    if(typeof(control.clientLeft)!="undefined")
      result = new KCBox(control.clientLeft,control.clientTop,control.clientWidth,control.clientHeight);
    else
      result = new KCBox(
        (control.offsetWidth-control.clientWidth)/2,
        (control.offsetHeight-control.clientHeight)/2,
        control.clientWidth,
        control.clientHeight);
    result.move(control.offsetLeft,control.offsetTop);
  }
  else
  {
    result = new KCBox(control.offsetLeft,control.offsetTop,control.offsetWidth,control.offsetHeight);
  }
  parent = control.offsetParent;
  while(parent!=null)
  {
    result.move(parent.offsetLeft,parent.offsetTop);
    if(!kc_ap_bad.contain(parent.tagName))
    {
      if(typeof(parent.clientLeft)!="undefined")
        result.move(parent.clientLeft,parent.clientTop);
//     else if (typeof(window.getComputedStyle)!="undefined")
//      {
//        var style = window.getComputedStyle(parent,"");
//        if(typeof(style.borderLeftWidth)!="undefined")
//          result.move(parseInt(style.borderLeftWidth),parseInt(style.borderTopWidth));
//      }
    }
    parent = parent.offsetParent;
  }
  return result;
}
function kc_isOverControl(control,mousePos)
{
  var p = kc_absolutePos(control)
  return (mousePos.x>=p.x && mousePos.x<p.x+p.w && mousePos.y>=p.y && mousePos.y<p.y+p.w);
}
function kc_offsetPos(parentBox,childBox,hpos,vpos,offsetX,offsetY)
{
  var result = new KCPos(offsetX==null?0:offsetX,offsetY==null?0:offsetY);
  if(parentBox!=null && childBox!=null)
  {
		hpos = hpos==null?"left":hpos;
		vpos = vpos==null?"top":vpos;
    if(hpos=="before")
      result.x += parentBox.x-childBox.w;
    else if(hpos=="left")
      result.x += parentBox.x;
    else if(hpos=="center")
      result.x += parentBox.x+(parentBox.w-childBox.w)/2;
    else if(hpos=="right")
      result.x += parentBox.x+parentBox.w-childBox.w;
    else if(hpos=="after")
      result.x += parentBox.x+parentBox.w;
		if(vpos=="before")
		  result.y += parentBox.y-childBox.h;
    else if(vpos=="top")
      result.y += parentBox.y;
    else if(vpos=="middle")
      result.y += parentBox.y+(parentBox.h-childBox.h)/2;
    else if(vpos=="bottom")
      result.y += parentBox.y+parentBox.h-childBox.h;
    else if(vpos=="after")
      result.y += parentBox.y+parentBox.h;
  }
  return result;
}
function kc_bringToFront(control,bottom)
{
  if(control!=null)
  {
    var parent = bottom;
    var zIndex = control.style.zIndex;
    while(parent!=null)
    {
      if(parent.style.zIndex && parent.style.zIndex+1>zIndex)
        zIndex = parent.style.zIndex+1;
      parent = parent.offsetParent;
    }
    control.style.zIndex = zIndex;
  }
}
function kc_parentDisplay(control)
{
  var parent = control.parentNode;
  while(parent!=null)
  {
    if(parent.style && (parent.style.display=="none" || parent.style.visibility=="hidden"))
      return false;
    parent = parent.parentNode;
  }
  return true;
}
/*---------------------------*/
function KCDisposable()
{
  this.items = new Array();
}
KCDisposable.prototype.add = function(obj)
{
  var result = this.items.length;
  this.items[result]=obj;
  return result;
}
KCDisposable.prototype.remove = function(id)
{
  if(id<this.items.length && this.items[id]!=null)
    delete this.items[id];
}
KCDisposable.prototype.fire = function(id)
{
  if(id<this.items.length && this.items[id]!=null && typeof(this.items[id].dispose)!="undefined")
    this.items[id].dispose();
}
KCDisposable.prototype.dispose = function()
{
  for(var i=0;i<this.items.length;i++)
  {
    this.fire(i);
    this.remove(i);
  }
  this.items.length=0;
}
var kc_disposable = new KCDisposable();
/*---------------------------*/
function KCSpecObjs()
{
  this.items = new Array();
  kc_disposable.add(this);
}
KCSpecObjs.prototype.add = function(obj)
{
  this.items[this.items.length] = obj;
}
KCSpecObjs.prototype.fire = function(methodName)
{
  for(var i=0;i<this.items.length;i++)
//    eval("if(typeof(this.items[i]."+method+")=='function') this.items[i]."+method+"();");
    if(typeof(this.items[i][methodName])=="function")
      this.items[i][methodName]();
}
KCSpecObjs.prototype.dispose = function()
{
  kc_disposeArray(this.items);
  this.items = null;
}
var kc_specObjs = new KCSpecObjs();
function kc_setBackground(objInst,backgroundImageUrl,backgroundRepeat)
{
  var backgroundImage = backgroundImageUrl=="" ? "" : "url("+backgroundImageUrl+")";
  if(objInst.style.backgroundImage!=backgroundImage)
    objInst.style.backgroundImage=backgroundImage;
  if(objInst.style.backgroundRepeat!=backgroundRepeat)
    objInst.style.backgroundRepeat=backgroundRepeat;
}
function kc_setBackgroundCell(cell,background,repeat)
{
//  if(ie55)
//  {
//    if(cell.background!=background)
//      cell.background=background;
//  }
//  else
    kc_setBackground(cell,background,repeat);
}
function kc_setImage(img,src)
{
  if(img!=null && img.src!=src)
    img.src = src;
}
function kc_setDisplay(objInst,display)
{
  if(objInst.style.display!=display)
    objInst.style.display = display;
}
function kc_repos(childName,parentName,left,top,right,bottom)
{
  var parent = kc_findObj(parentName);
  var child = kc_findObj(childName);
  if(parent!=null && child!=null)
  {
    var parentPos = kc_absolutePos(parent);
    var childPos = kc_absolutePos(child);
    if(left!=null)
      child.style.left = parentPos.x+left;
    if(top!=null)
      child.style.top = parentPos.y+top;
    if(right!=null)
      child.style.left = parentPos.x+parentPos.w-childPos.w+right;
    if(bottom!=null)
      child.style.top = parentPos.y+parentPos.h-childPos.h+top;
  }
}
/*------------------------*/
function kc_newImage(arg) {
	if (document.images) {
		var rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function KCImages(path)
{
  this.disposed = false;
  this.path = path;
  if(this.isValid() && this.path.length>0 && this.path.charAt(this.path.length-1)!="/")
    this.path+="/";
  kc_disposable.add(this);
}
KCImages.prototype.dispose = function()
{
  if(!this.disposed)
  {
    for(var i=0;i<this.length;i++)
      if(typeof(this[i])=="object")
        delete this[i];
  }
  this.disposed = true;
}
KCImages.prototype.load = function(property,filename)
{
  if(this.isValid())
    this[property] = kc_newImage(this.path+filename);
}
KCImages.prototype.isValid = function()
{
  return this.path!=null && typeof(this.path)=="string";
}
KCImages.prototype.assignToBackground = function(obj,imagename,repeat,position_,attachment)
{
  if(obj!=null && obj.style!=null && this.isValid() && this[imagename]!=null && this[imagename].src!=null)
    with(obj.style)
    {
      backgroundImage = "url("+this[imagename].src+")";
      backgroundRepeat = repeat;
      backgroundPosition = position_;
      backgroundAttachment = attachment;
    }
}
var KCButtonStates = new Array("normal","hover","down","disabled","selected","selectedHover","selectedDown");
KCImages.prototype.loadArray = function(names,states)
{
  if(this.isValid() && names!=null)
    for(var i=0;i<names.length;i++)
    {
      var name = "_"+i.toString();
      if(states!=null && i<states.length && states[i]!=null && states[i].length>0)
        name = states[i];
      if(names[i]!=null && names[i].length>0)
        this.load(name,names[i]);
    }
  return this;
}
var KCEmptyImages = new KCImages(KCPath)
kc_disposable.add(KCEmptyImages);
with(KCEmptyImages)
{
  var ea = new Array(KCButtonStates.length);
  for(var i=0;i<ea.length;i++)
    ea[i]="empty.gif";
  loadArray(ea,KCButtonStates);
}
var KCDefaultIconNames = new Array("normal.gif","hover.gif","down.gif","disabled.gif","selected.gif","selectedHover.gif","selectedDown.gif");
/*------------------------*/
function concatClasses(className,sufix,only)
{
  var array = className.split(" ");
  var result="";
  var first=true;
  for(var i=0; i<array.length; i++)
  {
    if(!first)
      result+=" ";
    if(array[i].length>0)
    {
      if(only)
        result += array[i]+sufix;
      else
        result += array[i]+" "+array[i]+sufix;
      first=false;
    }
  }
  return result;
}
function KCStyleClass(name,states)
{
  if(name!=null && states!=null)
    for(var i=0;i<states.length;i++)
      if(states[i]!=null && states[i].length>0)
        this[states[i]]=concatClasses(name,"-"+states[i]);
}
KCStyleClass.prototype.dispose = function()
{
  for(var i=0;i<this.length;i++)
    if(typeof(this[i])!="function")
      delete this[i];
}
/*------------------------*/
function KCMouseCapture(srcObj,target,status,cancelBubble)
{
  this.disposed       = false;
  this.down           = false;
  this.over           = false;
  this.srcObj         = srcObj;
  this.target         = target;
  this.status         = status;
  this.cancelBubble   = cancelBubble==null?false:cancelBubble;
  this.addEventSource(srcObj);
}
KCMouseCapture.prototype.dispose = function()
{
  if(!this.disposed)
  {
    if(this.listernerClick!=null)
    {
      kc_events.removeListener(this.listernerClick);
      this.listernerClick = null;
    }
    if(this.listernerUp!=null)
    {
      kc_events.removeListener(this.listernerUp);
      this.listernerUp = null;
    }
    if(this.listernerDown!=null)
    {
      kc_events.removeListener(this.listernerDown);
      this.listernerDown = null;
    }
    if(this.listernerOut!=null)
    {
      kc_events.removeListener(this.listernerOut);
      this.listernerOut = null;
    }
    if(this.listernerOver!=null)
    {
      kc_events.removeListener(this.listernerOver);
      this.listernerOver = null;
    }
    if(this.listernerLoseCapture!=null)
    {
      kc_events.removeListener(this.listernerLoseCapture);
      this.listernerLoseCapture = null;
    }
    this.srcObj = null;
    this.target = null;
  }
  this.disposed=true;
}
KCMouseCapture.prototype.typeOf = function()
{
  return "KCMouseCapture";
}
KCMouseCapture.prototype.addEventSource = function(srcObj,over,out,down,up,click,loseCapture)
{
  if(srcObj!=null)
  {
    if(over==null || over)
    {
      if(this.listenerOver==null)
      {
        this.listenerOver = new KCEventListener(this,this.onMouseOver);
        kc_events.addListener(this.listenerOver);
      }
      if(typeof(srcObj.onmouseenter)!="undefined")
        this.listenerOver.addEvent(srcObj,"mouseenter");
      else
        this.listenerOver.addEvent(srcObj,"mouseover");
    }
    if(out==null || out)
    {
      if(this.listenerOut==null)
      {
        this.listenerOut = new KCEventListener(this,this.onMouseOut);
        kc_events.addListener(this.listenerOut);
      }
      if(typeof(srcObj.onmouseleave)!="undefined")
        this.listenerOut.addEvent(srcObj,"mouseleave");
      else
        this.listenerOut.addEvent(srcObj,"mouseout");
    }
    if(down==null || down)
    {
      if(this.listenerDown==null)
      {
        this.listenerDown = new KCEventListener(this,this.onMouseDown);
        kc_events.addListener(this.listenerDown);
      }
      this.listenerDown.addEvent(srcObj,"mousedown");
    }
    if(up==null || up)
    {
      if(this.listenerUp==null)
      {
        this.listenerUp = new KCEventListener(this,this.onMouseUp);
        kc_events.addListener(this.listenerUp);
      }
      this.listenerUp.addEvent(srcObj,"mouseup");
    }
    if(click==null || click)
    {
      if(this.listenerClick==null)
      {
        this.listenerClick = new KCEventListener(this,this.onMouseClick);
        kc_events.addListener(this.listenerClick);
      }
      this.listenerClick.addEvent(srcObj,"click");
    }
    if(loseCapture==null || loseCapture)
    {
      if(this.listenerLoseCapture==null)
      {
        this.listenerLoseCapture = new KCEventListener(this,this.onLoseCapture);
        kc_events.addListener(this.listenerLoseCapture);
      }
      this.listenerClick.addEvent(srcObj,"losecapture");
    }
  }
}
KCMouseCapture.prototype.update = function()
{
  if(typeof(this.target.update)!="undefined")
    this.target.update();
}
KCMouseCapture.prototype.click = function()
{
  if(typeof(this.target.click)!="undefined")
    this.target.click();
}
KCMouseCapture.prototype.onMouseOver = function(listener,eventObject)
{
  this.eventObject = eventObject;
  if(this.status)
    window.status = this.status;
  if(!this.over)
  {
    this.over = true;
    this.update();
  }
  if(typeof(this.target.mouseOver)!="undefined")
    this.target.mouseOver();
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.onMouseOut = function(listener,eventObject)
{
  this.eventObject = eventObject;
  if(this.status)
    window.status = "";
  if(this.over)
  {
    this.over = false;
    this.down = false;
    this.update();
  }
  if(typeof(this.target.mouseOut)!="undefined")
    this.target.mouseOut();
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.onMouseDown = function(listener,eventObject)
{
  this.eventObject = eventObject;
  if(!this.down)
  {
    this.down = true;
    this.update();
  }
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.onMouseUp = function(listener,eventObject)
{
  this.eventObject = eventObject;
  if(this.down)
  {
    this.down = false;
    this.update();
  }
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.onMouseClick = function(listener,eventObject)
{
  this.eventObject = eventObject;
  this.click();
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.onLoseCapture = function(listener,eventObject)
{
  this.eventObject = eventObject;
  if(typeof(this.target.loseCapture)!="undefined")
    this.target.loseCapture();
  if(typeof(window.event)!="undefined" && typeof(window.event.cancelBubble)!="undefined")
    window.event.cancelBubble = this.cancelBubble;
}
KCMouseCapture.prototype.setStatus =
function(status)
{
  this.status = status;
  if(this.over)
    window.status = this.status;
}
/*------------------------*/
function KCConfirm(causesValidation,confirm,message,result,type,promptValue)
{
  this.causesValidation = causesValidation==null ? true :causesValidation;
  this.confirm = confirm==null ? false : confirm;
  this.message = message==null ? "" : message;
  this.result = result==null ? true : result;
  this.type = type==null ? "confirm" : type;
  this.promptValue = promptValue==null ? "" : promptValue;
}
KCConfirm.prototype.check = function()
{
  if(this.causesValidation && typeof(Page_ClientValidate)=='function')
  {
    Page_ClientValidate();
    if(!Page_IsValid)
      return false;
  }
  this.confirmResult = true;
  this.promptResult = "";
  if(this.confirm)
  {
    if(this.type=="confirm")
      this.confirmResult  = this.result==window.confirm(this.message);
    else if(this.type=="alert")      
      window.alert(this.message);
    else if(this.type=="prompt")
      this.promptResult = window.prompt(this.message,this.promptValue);
  }
  if(this.confirmResult && this.promptResult!=null)
    return true;
  return false;
}
var kc_defaultConfirm = new KCConfirm(null,null,null,null,null,null);
var kc_defaultConfirm2 = new KCConfirm(true,false,"",true,"confirm","");
/*------------------------*/
function KCTarget(name,features,replace)
{
  this.name = name==null?"_self":name;
  this.features = features;
  this.replace = replace;
}
KCTarget.prototype.open=function(url)
{
  return window.open(url,this.name,this.features,this.replace);
}
var kc_defaultTarget = new KCTarget(null,null,null);
/*------------------------*/
function KCVisibility()
{
}
KCVisibility.prototype.setVisible =function(control,visible)
{
  if(control!=null && control.style!=null)
    control.style.visibility = (visible==null || !visible)?"hidden":""
}
var kc_visibility = new KCVisibility();
/*------------------------*/
function KCDisplay()
{
}
KCDisplay.prototype.setVisible=function(control,visible)
{
  if(control!=null && control.style!=null)
    control.style.display = (visible==null || !visible)?"none":""
}
var kc_display = new KCDisplay();
/*------------------------*/
function KCSlave(master,id)
{
  if(typeof(master)=="string")
    master = kc_findObj(master);
  this.div=null;
  if(master!=null)
  {
    this.div = document.createElement("div");
    this.div.id = id;
    this.div.style.zIndex = (master.style.zIndex==0?10000:master.style.zIndex)+2;
    this.div.style.position = "absolute";
    this.div.style.left = "0px";
    this.div.style.top = "0px"
    this.div.style.visibility = "hidden";
    if(document.forms.length>0)
      document.forms[0].appendChild(div);
    else
      document.body.appendChild(div);
  }
}
KCSlave.prototype.dispose = function()
{
  this.div = null;
}
/*---------------------------*/
function KCStaticBehavior(instance,className,imagesPath,imageNames,states,destination,status,text)
{
  this.instance = instance;
  this.lastState = "";
  this.status = status;
  this.text = text;
  this.lastText = null;
  this.lastClassName = null;
  if(this.instance)
  {
    this.instance.setAttribute("UNSELECTABLE","on",0);
    this.instance.setText = __kcg_setNonClippedText;
    this.instance.getText = __kcg_getNonClippedText;
    var c = this.instance.getElementsByTagName("img");
    if(c.length>0)
    {
      this.img = c[0];
      this.img.setAttribute("UNSELECTABLE","on",0);
      if(imagesPath && imageNames && states)
        this.icons = new KCImages(imagesPath).loadArray(imageNames,states);
    }
    if(className && states)
      this.classes = new KCStyleClass(className,states);
    if(kc_checkType(destination,"KCMouseCapture"))
    {
      this.capture = destination;
      this.capture.addEventSource(this.instance);
    }
    else if(destination!=null)
    {
      this.capture = new KCMouseCapture(this.instance,destination,"",true);
      this.disposeCapture = true;
    }
  }
}
KCStaticBehavior.prototype.dispose =
function()
{
  if(this.instance)
  {
    this.instance.setText = null;
    this.instance.getText = null;
    this.img = null;
    if(this.icons!=null)
    {
      this.icons.dispose();
      this.icons = null;
    }
    if(this.classes!=null)
    {
      this.classes.dispose();
      this.dispose = null;
    }
    if(this.capture!=null && this.disposeCapture)
    {
      this.capture.dispose();
      this.capture=null;
    }
  }
  this.instace = null;
}
KCStaticBehavior.prototype.setState =
function(state)
{
  if(state!=this.lastState)
  {
    this.lastState = state;
    if(this.instance)
    {
      if(this.classes && this.lastClassName!=this.classes[this.lastState])
      {
        this.lastClassName=this.classes[this.lastState];
        this.instance.className = this.lastClassName;
      }
      if(this.img && this.icons)
      {
        if(this.img.src!=this.icons[this.lastState].src)
          this.img.src = this.icons[this.lastState].src;
      }
      if(this.text && this.text!=this.lastText)
      {
        this.lastText = this.text[this.lastState];
        this.instance.setText(this.lastText);
      }
      if(this.status && this.capture)
        this.capture.setStatus(this.status[this.lastState]);
    }
  }
}
KCStaticBehavior.prototype.over =
function()
{
  return this.capture && this.capture.over;
}
KCStaticBehavior.prototype.down =
function()
{
  return this.capture && this.capture.down;
}
/*------------------------*/
function KCStaticBehaviors()
{
  this.items = new Array();
  this.lastState = "";
}
KCStaticBehaviors.prototype.dispose =
function()
{
  for(var i=0;i<this.items.length;i++)
    if(this.items[i]!=null)
      this.items[i].dispose();
  kc_disposeArray(this.items);
}
KCStaticBehaviors.prototype.add =
function(behavior)
{
  this.items[this.items.length] = behavior;
}
KCStaticBehaviors.prototype.setStatus =
function(text)
{
  for(var i in this.items)
    this.items[i].setStatus(text);
  return this;
}
KCStaticBehaviors.prototype.setState =
function(state)
{
  if(state!=this.lastState)
  {
    this.lastState = state;
    for(var i in this.items)
      this.items[i].setState(this.lastState);
  }
  return this;
}
KCStaticBehaviors.prototype.over =
function()
{
  for(var i in this.items)
    if(this.items[i].over())
      return true;
  return false;
}
KCStaticBehaviors.prototype.down =
function()
{
  for(var i in this.items)
    if(this.items[i].down())
      return true;
  return false;
}
function kc_disposeWrappers()
{
  for(var i=0;i<kc_wrapped.length;i++)
    if(kc_wrapped[i]!=null)
    {
      if(kc_wrapped[i].wrapper)
        kc_wrapped[i].wrapper=null;
      delete kc_wrapped[i];
    }
  kc_wrapped.length = 0;
}
var kc_wrapped = new Array();
kc_wrapped.add = function(obj,wrapper)
{
 this[this.length] = obj; 
 obj.wrapper = wrapper;
 kc_disposable.add(wrapper);
}
//kc_attachEventEx(window,"unload",window,"kc_disposeWrappers");
function KCWrapper(instance,parent)
{
  this.instance = typeof(instance)=="string" ? kc_findObj(instance) : instance;
  this.disposed = false;
  this.setDisplay = KCWrapper_setDisplay;
  this.getDisplay = KCWrapper_getDisplay;
  this.setVisibility = KCWrapper_setVisibility;
  this.getVisibility = KCWrapper_getVisibility;
  if(this.instance!=null)
  {
//    this.instance.wrapper = instance;
    kc_wrapped.add(this.instance,this);
    this.parent = parent;
  }
}
  function KCWrapper_dispose()
  {
    if(!this.disposed)
    {
      this.instance = null;
    }
    this.disposed = true;
  }
  function KCWrapper_setDisplay(text)
    {
      if(this.instance!=null)
        this.instance.style.display = text;
    }
  function KCWrapper_getDisplay ()
    {
      if(this.instance!=null)
        return this.instance.style.display;
      else
        return "";
    }
  function KCWrapper_setVisibility (text)
    {
      if(this.instance!=null)
        this.instance.style.visibility = text;
    }
  function KCWrapper_getVisibility ()
    {
      if(this.instance!=null)
        return this.instance.style.visibility;
      else
        return "";
    }
function KCInitialization()
{
  this.items = new Array();
  kc_disposable.add(this);
}
KCInitialization.prototype.dispose = function()
{
  kc_disposeArray(this.items);
  this.items = null;
}
KCInitialization.prototype.add =
function(obj)
{
  this.items[this.items.length] = obj;
}
KCInitialization.prototype.initialize =
function()
{
  for(var i in this.items)
    this.items[i].initialize();
}
var kc_initialization = new KCInitialization();
/*--------------------*/
function KCSelectControl(control)
{
  this.oldVisibility = null;
  this.control = control;
}
KCSelectControl.prototype.hide = function()
{
  if(this.control && this.oldVisibility==null)
  {
    this.oldVisibility = this.control.style.visibility;
    this.control.style.visibility = "hidden";
  }
}
KCSelectControl.prototype.show = function()
{
  if(this.control && this.oldVisibility!=null)
  {
    this.control.style.visibility = this.oldVisibility;
    this.oldVisibility=null;
  }
}
function KCSelectControls()
{
  if(!ie)
    return;
  this.timer = new KCTimer(this,this.delayShow,false);
  kc_disposable.add(this);
  this.selects = null;
  this.counter = 0;
}
KCSelectControls.prototype.initialize = function()
{
  if(!ie)
    return;
  var selects = document.getElementsByTagName("SELECT");
  this.selects = new Array(selects.length);
  for(var i=0; i<selects.length; i++)
    this.selects[i] = new KCSelectControl(selects[i]);
}
KCSelectControls.prototype.dispose = function()
{
  if(!ie)
    return;
  if(this.timer!=null)
  {
    this.timer.dispose();
    this.timer = null;
  }
  if(this.selects!=null)
  {
    kc_disposeArray(this.selects);
    this.selects=null;
  }
}
KCSelectControls.prototype.hide = function()
{
  if(!ie)
    return;
  this.timer.stop();  
  if(this.counter==0 && this.selects!=null)
    for(var i=0;i<this.selects.length;i++)
      this.selects[i].hide();
  this.counter++;
}
KCSelectControls.prototype.show = function()
{
  if(!ie)
    return;
  this.counter--;
  if(this.counter==0 && !this.timer.isRunning())
    this.timer.start(200);
}
KCSelectControls.prototype.delayShow = function()
{
  if(!ie)
    return;
  if(this.selects!=null)
    for(var i=0;i<this.selects.length;i++)
      this.selects[i].show();
}
1
kc_selectControls = new KCSelectControls();
/*--------------------*/
document.getAbsolutePath =
function(file)
{
  if (file==null || file.length==0 || new RegExp("^(\\w+://|/).*").test(file))
    return file;
  var base = document.URL;
  var index = base.lastIndexOf("/");
  if(index>0)
    base = base.substring(0,index);
  return base+"/"+file;
}
function setClassName(obj,className)
{
//  if(obj && obj.className!=className)
  if(obj!=null && className!=null)
    obj.className = className;
}
kc_setClassName = setClassName;
function setImageSrc(img,src)
{
  if(img!=null && img.src!=src)
    img.src = src;
}
kc_setImageSrc = setImageSrc;
function kc_setCursor(obj,cursor)
{
  if(obj!=null && obj.style!=null && obj.style.cursor!=null)
    obj.style.cursor = cursor;
}
function kc_fireDownMethod(control,startObject,startMethod,stopObject,stopMethod,exceptions)
{
  if(control!=null && !stopMethod.call(stopObject,control))
  {
    startMethod.call(startObject,control,exceptions);
    if(control.hasChildNodes())
      for(var i=0;i<control.childNodes.length;i++)
        kc_fireDownMethod(control.childNodes[i],startObject,startMethod,stopObject,stopMethod,exceptions);
  }
}
function kc_fireUpMethod(control,startObject,startMethod,stopObject,stopMethod)
{
  if(control!=null && !stopMethod.call(stopObject,control))
  {
    startMethod.call(startObject,control);
    kc_fireUpMethod(control.parentNode,startObject,startMethod,stopObject,stopMethod);
  }
}
function kc_trueMethod(control)
{
  return true;
}
function kc_falseMethod(control)
{
  return false;
}
function kc_disableMethod(control,exceptions)
{
  if(exceptions!=null && exceptions.length>0 && typeof(control.tagName)!="undefined")
  {
    for(var i=0;i<exceptions.length;i++)
      if(control.tagName==exceptions[i])
        return;
  }
  if( control!=null && typeof(control.disabled)!="undefined" && !control.notDisabled )
    control.disabled = true;
}
function kc_notDisabledMethod(control)
{
  if(control!=null)
    control.notDisabled = true;
}
function __kcg_getClippedText()
{
  return this.clipDiv.innerHtml
}
function __kcg_setClippedText(text)
{
  with(this.clipDiv)
  {
    while(hasChildNodes())
      removeChild(firstChild);
    appendChild(this.ownerDocument.createTextNode(text));
  }
}
function __kcg_appendClippedControl(control)
{
  with(this.clipDiv)
  {
    while(hasChildNodes())
      removeChild(firstChild);
    appendChild(control);
  }
}
function kc_getText(obj)
{
  return obj==null?"":obj.innerHtml;
}
function __kcg_getNonClippedText()
{
  return this.innerHtml
}
function kc_setText(obj,text)
{
  if(obj==null)
    return;
  with(obj)
  {
    while(hasChildNodes())
      removeChild(firstChild);
    appendChild(document.createTextNode(text));
  }
}
function __kcg_setNonClippedText(text)
{
  with(this)
  {
    while(hasChildNodes())
      removeChild(firstChild);
    appendChild(this.ownerDocument.createTextNode(text));
  }
}
function __kcg_appendNonClippedControl(control)
{
  with(this)
  {
    while(hasChildNodes())
      removeChild(firstChild);
    appendChild(control);
  }
}
/*-----------------------------*/
function KCDebug()
{
  this._window = null;
}
KCDebug.prototype.getWindow = function()
{
  if(this._window==null)
    this._window = open(null,"debug");
  return this._window;
}
KCDebug.prototype.write = function(text)
{
  this.getWindow().document.write(text);
}
KCDebug.prototype.writeln = function(text)
{
  this.getWindow().document.write(text+"<br>");
}
var kc_debug = new KCDebug();
/*-----------------------------*/
var p_ = "";
var P_ = "";
var pn_ = null;
var p2_ = KCDefaultIconNames;
var p3_ = kc_defaultConfirm;
var p4_ = kc_defaultConfirm2;
var p5_ = KCPath;
var p6_ = KCButtonStates;
var p7_ = kc_defaultTarget;
var p8_ = kc_defaultTarget;
function kc_load()
{
  kc_submited = false;
  kc_pureSubmit = false;
  kc_selectControls.initialize();
  kc_specObjs.fire("update");
  return true;
}
function kc_stop()
{
  kc_submited = false;
  kc_pureSubmit = false;
  return true;
}
function kc_unload()
{
  kc_disposeWrappers();
  kc_disposable.dispose();
  kc_events.dispose();
  kc_disposeArray(kc_tds);
  kc_submited = false;
  kc_pureSubmit = false;
  document.getAbsolutePath=null;
  return true;
}
var mousePos = new KCPos();
function kc_mouseMove(listener,eventObject)
{
  mousePos = eventObject.mousePos;
}
kc_events.addListener(window,"stop",window,kc_stop);
kc_events.addListener(window,"load",window,kc_load);
kc_events.addListener(window,"unload",window,kc_unload);
//kc_events.addListener(document,"mousemove",window,kc_mouseMove);


