function jdelay(targetId) {
  this.initialized=false;
  
  this.targetId=targetId;
  this.target=null;
  
  var ret=this.createInstanceID();
  this.createEvent('load',window,this.jstart);
  return true;
}


jdelay.prototype.jstart = function() {
window.jdelay_instance[0][0].getInstanceID();
}

jdelay.prototype.createEvent=function(evt,target,handler) {
if(this.createEvent.arguments.length!=3) {return false;}
  try {if(window.addEventListener){target.addEventListener(evt, handler, false);} else {target.attachEvent('on'+evt,handler);}} catch(e) 
  {if(document.all) {alert("Cannot create event '"+evt+"':"+e.number+":"+e.description);} else {alert("Cannot create event '"+evt+"'\n"+e);}}
}


jdelay.prototype.createInstanceID=function () {
var s=(this.constructor.toString());i=s.indexOf(" ");j=s.indexOf("(");
var base=s.substring(i+1,j);
base+="_instance";var wbase="window."+base;
if(eval(wbase)==null) {eval(wbase+"=Array()");}
//instantiate
var arr=[this,0];
var warray=eval(wbase);
warray[warray.length]=arr;
return warray.length;
}

jdelay.prototype.getInstanceID=function() {
 var s=(this.constructor.toString());i=s.indexOf(" ");j=s.indexOf("(");
 var base=s.substring(i+1,j);
 base+="_instance";var wbase="window."+base;
 var warray=eval(wbase);var retval={target:'0', key: '-1'};
 for(key=0;key<warray.length;key++) {
 if(warray[key][1]==0) {
 warray[key][1]=1;
 retval.target=warray[key][0]; retval.key=key;
 var wb=(wbase+"["+key+"][0]");
 retval.target.instance=retval;
 retval.target.wbase=wb;
 eval(wb+".init()")
 }
 }
 return retval;
}

jdelay.prototype.init=function() {
//create screen
  this.initialized=true;
  var element=document.createElement('div')
  document.body.appendChild(element);
  this.screen=element;	  

  var element=document.createElement('div')
  document.body.appendChild(element);
  this.screen2=element;	  
  
  if(this.targetId!="") {
   if(!this.select(this.targetId)) {alert(this.err);return false;} 
  }
  
  this.runEvent('onload'); 
}

jdelay.prototype.runEvent=function(handler) {
var e=eval("this."+handler);
if(typeof(e)=="function") {
try {setTimeout(e,1);} catch(e) {void(0);return false;}
}
return true;
}

jdelay.prototype.select=function(targetId) {
if(!this.initialized) {this.targetId="";this.init();}

this.err="#"+targetId+" is not valid";
//clear prev object
this.target=null;

//level 1 catch id
if(this.target==null) {
try {this.target=document.getElementById(targetId);} catch(err) {void(0);}
}

//try by name
if(this.target==null) {
try {this.target=document.getElementByName(targetId);} catch(err) {void(0);}
}

//try by name
if(this.target==null) {
try {this.target=document.getElementByName(targetId);} catch(err) {void(0);}
}

//try by evaluation
if(this.target==null) {
try {this.target=eval(targetId);} catch(err) {void(0);}
}

//try by evaluation level2
if(this.target==null) {
 try {this.target=eval("window."+targetId);} catch(err) {void(0);}
}

//try to get tag reference
if(this.target==null) {
 try {this.target=document.getElementsByTagName(targetId)[0];} catch(err) {void(0);}
}


//give up
if(this.target==null) {return false;}
this.err="";


//once an object is selected
this.cssText=this.target.style.cssText;
this.initialized=true;

return true;
}

jdelay.prototype.getElementLeftPosition = function(e){
var x=0;
while(e){
x+=e.offsetLeft+e.clientLeft;
e=e.offsetParent;
}
return x;
}

jdelay.prototype.getElementTopPosition = function(e){
var y=0;
while(e){
y+=e.offsetTop+e.clientTop;
e=e.offsetParent;
}
return y;
}


jdelay.prototype.disable = function() {
 var element=this.screen;

  element.style.cssText=";position:absolute;background:#000000;text-align:center;";  
  element.style.cssText+=";filter:alpha(opacity=50);-moz-opacity:.50;opacity:.50;";

  element.style.left=this.getElementLeftPosition(this.target);
  element.style.top=this.getElementTopPosition(this.target);
  element.style.width=this.target.offsetWidth+"px";
  element.style.height=this.target.offsetHeight+"px";  
  
  element.style.paddingTop=(parseInt(element.style.height)*(10/100));  
  
  coll = this.target.getElementsByTagName("SELECT");
  
  for(i=0;i<coll.length;i++) {
   coll[i].style.visibility="hidden";
  }
  element.style.display="block";
}

jdelay.prototype.enable = function() {
  this.screen.style.display="none";
  coll = this.target.getElementsByTagName("SELECT");  

  for(i=0;i<coll.length;i++) {
   coll[i].style.visibility="visible";
  }
return;
}


jdelay.prototype.showMessage = function(innerHTML) {
 var element=this.screen2;

  element.style.cssText=";position:absolute;text-align:center;";  

  element.style.left=this.getElementLeftPosition(this.target);
  element.style.top=this.getElementTopPosition(this.target);
  element.style.width=this.target.offsetWidth+"px";
  element.style.height=this.target.offsetHeight+"px";  
  element.innerHTML=innerHTML;
  this.target.style.visibility="hidden";
  element.style.display="block";
}

jdelay.prototype.closeMessage = function() {
  this.screen2.style.display="none";
  this.target.style.visibility="visible";
return;
}


jdelay.prototype.addStyle = function(cssText) {
try {
this.target.style.cssText=cssText;
} catch(e) {return false;}
return true;
}

jdelay.prototype.resetStyle = function() {
this.target.style.cssText=this.cssText;
}

jdelay.prototype.show = function() {
this.target.style.visibility="visible";
}


jdelay.prototype.hide = function() {
this.target.style.visibility="hidden";
}

