/* dynlite dhtml dom api  
 * peter assenov- AIP Solutions Ltd.' 2003
 * version: 2.1.3/04.10.2003
 */

/* version history 
	2.1.3- added xml support in debug object.

 */	
	      
/* dynlite initialisation */
dom=(document.getElementById)?1:0;
ns6=(dom&&!document.all)?1:0;
if(!dom)
{	alert('This site is not compatible with your browser!');
	self.location.href='browser.html';
} 
window.develop=1;
onerror=function(msg,url,lno){if(window.develop&&window.debug) debug.error(msg,url,lno); return true}; 
/* dynlite debug */
debug=new Object();
debug.log=['--- dynlite log activated. ---'];
debug.add=function(msg){this.log[this.log.length]=msg}
debug.show=function(){alert(this.log.join('\n'))} 
debug.error=function(msg,url,lno)
{	var err=[' <msg> '+msg,' <line> '+lno,' <url>   '+url.replace(/^.*(\/|\\)/,'')];
	this.add('!Error: '+err.join(''));
	alert('Error!\n------------------------------------------------\ndynlite detected the following error: \n\n'+err.join('\n'));
	if(confirm('show dynlite activity log?')) this.show();
}
debug.info=function(el,vis)
{	if(typeof(el)=='object')
	{	var code=[],j=0;
		if(el.xml) code[0]=el.xml;
		else for(var i in el){code[j++]=i+' -> '+el[i]}
		(vis)?document.write(code.join('<br>')):alert(code.join('\n'));
	}
	else alert(el);
}
debug.status=function(val){window.status=val}
window.log=window.debug;
log.add((window.develop)?'#dynlite initialised in developping mode.':'#dynlite initialised successfully.');

/* dynlite doc  */
function dyncss(type)
{	this.type=type||'link';													
	this.arr=(document.styleSheets&&document.styleSheets.length)?(this.type=='import')?(ns6)?document.styleSheets.item(0).cssRules.item(0).styleSheet.cssRules:document.styleSheets[0].imports[0].rules:(this.type=='link')?(ns6)?document.styleSheets.item(0).cssRules:document.styleSheets[0].rules:0:0;
	this.el=null;
log.add((this.arr)?'- stylesheet object of type '+this.type+' created.':'! could not find stylesheet definition of type '+this.type);
}
dyncss.prototype.attr=function(el,prop,val)
{	for (var i=this.arr.length-1; i>=0; i--)									
	{	this.el=this.arr[i];													
		if(this.el.selectorText.toLowerCase()==el.toLowerCase())				
		{	if(val==null) return(this.el.style[prop]);						
			else this.el.style[prop]=val;							
		return 0;
		}
	}
}
evt=new Object()						
evt.add=function(elm,evt,obj,met)
{	if(/^on/.test(evt))
	{	cel = window[elm].el||window[elm];
		cel[evt]=function(e){(met)?window[obj][met](e):obj(e)};
	}
	else (ns6)?elm.addEventListener(evt,obj,false):elm.attachEvent('on'+evt,obj);
log.add('- '+evt+' event listener to object '+elm+' added.');
}
evt.evoke=function(elm,cevt,pars)
{	var cel=window[elm].el||window[elm];
	var cpars=(pars)?pars.toString():'';									
return (cel&&cel[cevt])?cel[cevt](cpars):null;							
}
page=new Object();
page.css=new dyncss();
page.init=[];/*load handling*/
page.add=function(func,method){page.init[page.init.length]=(method)?'window["'+func+'"].'+method:func;}
page.onload=function()
{	eval(this.init.join(";"));
	if (window.init) window.init();
log.add('#onload code executed.');
}
onload=function(){page.onload()}
page.clean=[];/*unload handling*/
page.remove=function(func){page.clean[page.clean.length]=func;}
page.onunload=function(){eval(this.clean.join(";"));}
onunload=function(){page.onunload()}
log.add('#dynlite doc initialised.');

/* dynlite layer */ 
function dynobj(name)
{	this.name=name;
	this.el=document.getElementById(this.name+'Div');
	if(this.el)
	{	this.css=this.el.style;
		this.el.obj=this;
		window[this.name]=this;
	}
log.add((this.el)?'- object: '+this.name+' created.':'! could not create object: '+this.name);
}
dynobj.prototype.show=function(nest){this.css.visibility=(nest)?'inherit':'visible';}
dynobj.prototype.hide=function(){this.css.visibility='hidden';}
log.add('#dynlite layer loaded.');
//positioning...
page.pos='center';															
page.setPos=function(cont)
{	this.w=parseInt(this.css.attr('#'+cont,'width',null));					
	this.h=parseInt(this.css.attr('#'+cont,'height',null));
	this.winw=(ns6)? window.innerWidth-15:document.body.offsetWidth-15;			
	this.winh=(ns6)? window.innerHeight:document.body.offsetHeight;
	this.x=parseInt((this.winw-this.w)/2);									
	this.y=(this.pos=="center")? parseInt((this.winh-this.h)/2) : 0;			
	if(!ns6) this.x-=8;
	this.css.attr('#'+cont,'left',(this.x>0)?this.x:0);							
	this.css.attr('#'+cont,'top',(this.y>0)?this.y:0);
log.add((this.x)?'- page positioned to: x->'+this.x+' y->'+this.y:'! fail to calculate page position');
}
/* popup window managing */
page.popupWin=0;
page.popupOpen=function(file,w,h) 
{	this.popupW=w||350;
	this.popupH=h||500;
	this.popupX=parseInt(((ns6)? window.innerWidth:document.body.offsetWidth)/2-this.popupW/2)||100;			
	this.popupY=parseInt(((ns6)? window.innerHeight:document.body.offsetHeight)/2-this.popupH/2)||50;
	if(this.popupWin)
	{	this.popupWin.close();
		this.popupWin=0;
	} 
	this.popupWin=window.open(file,'popupWindow','left='+this.popupX+',top='+this.popupY+',width='+this.popupW+',height='+this.popupH+',scrollbars=1');
	this.popupWin.focus();
};
//enjoy...

