/* dynlite input/output operations management
 * based on	dynlite dhtml dom api
 * peter assenov- aip solutions ltd.' 2001-2008
 * 2.3.0.1/2009-01-26
 */
/** simultaneous http request manager **/
/* compatibility settings if used standalone */
if(!window.dl) dl={w:window,log:['-- http connection log --']}
/* http request object */
function http(id,url)
{	this.id=id;
	try{this.req=(dl.w.XMLHttpRequest)? new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")}
	catch(e){this.req=null};
	if(url) this.open(url);
return this;
}
_http=http.prototype;
_http.open=function(url)
{	this.url=url;
	if(this.req!=null&&this.url)
	{	this.fire('onrequest');
		this.req.open("GET",this.url,true);
		this.req.onreadystatechange=this.evt(this,'onstatechange');
		this.req.send(null);
	}
	else this.fire('onerror');
return this;
}
_http.evt=function(_this,evt){if(_this[evt]) return (function(){return _this[evt](this);});} /* closure */
_http.fire=function(evt,par){if(this[evt]) this[evt](par); return this;}
_http.onstatechange=function()
{	this.fire('onprogress');
	if(this.req.readyState==4)/* transfer completed */
  	{ 	this.fire('onresult');
  		this.fire((this.req.status==200)?'ondata':'onerror');
  	}
}
/* default event handlers */
_http.onrequest=function(){dl.log.push('#http request '+this.id+': openining '+this.url+' ...');}
_http.onprogress=function(){dl.log.push('#http['+this.id+']: state changed to '+this.req.readyState);};
_http.onresult=function(){dl.log.push('#http['+this.id+']: transfer from '+this.url+' completed.');};
_http.ondata=function(){dl.log.push('#http['+this.id+']: data received from '+this.url);};
_http.onerror=function()
{	if(!this.req) dl.log.push('!http '+this.id+': cannot create XttpRequest object');
	else if(!this.url) dl.log.push('!http '+this.id+': url not specified');
	else dl.log.push('#http['+this.id+']: error loading '+this.url+'-'+this.req.status);
};
/** cookies management **/
/* compatibility settings if used standalone */
if(!window.dl) dl={w:window,d:document,log:['-- cookies log --']}
/* cookie object */
dl.cookie=function(key,val,attrs)
{	var pars=attrs||{};
	if(!val) /* get */
	{	var re=new RegExp(key+"=([^;]+)");
		return re.test(dl.d.cookie)? unescape(RegExp.$1) : false;
	}
	else /* set */
	{	/* parameters setup */
		pars[key]=escape(val);
		if(!pars.expires) /* expiration*/
		{	var ttl=pars.ttl||30;
			if(ttl)
			{	var exp=new Date();
				exp.setDate(exp.getDate()+ttl);
				pars.expires=exp.toGMTString();
			}
		}
		if(!pars.domain)/* domain */
			pars.domain=dl.w.location.hostname;
		if(!pars.path) /* path */
			pars.path='/';
		if(pars.ttl) /* removing ttl custom attribute */
			delete pars.ttl;
		/* string build-up */
		var str='';
		for(i in pars)
			str+=i+'='+pars[i]+'; ';
		dl.d.cookie=str;
		dl.log.push('# cookie saved: '+unescape(str));
//		trace(dl.log);
	}
}
/** popup management **/
dl.popup={active:0,fader:'over',blank:'popupBlank.php'}
dl.popup.open=function(id,w,h,src)
{	this.close();
	this.active=id;
	this.el=dl.el(this.active);
	this.fel=dl.el(this.fader);
	this.css=this.el.style;
	this.d=dl.d.documentElement;
	if(src)
		this.el.src=src;
	this.place(w,h);
	this.el.on();
	this.fel.on();
	dl.w.scroll(0,0);
}
dl.popup.close=function()
{	if(!this.active) return false;
	this.el.src=this.blank;
	this.el.off();
	this.fel.off();
	this.active=0;
}
dl.popup.place=function(w,h)
{	if(w)
	{	var ww = this.d.offsetWidth;
		this.w=w||this.el.clientWidth||440;
		this.css.width=this.w+'px';
		this.css.marginLeft=(this.h>ww)? -parseInt(ww/2)+'px':-parseInt(this.w/2)+'px';
	}
	if(h)
	{	var wh = this.d.offsetHeight;
		this.h=h||this.el.clientHeight||204;
		this.css.height=this.h+'px';
		this.css.marginTop=(this.h>wh)? -parseInt(wh/2)+'px':-parseInt(this.h/2)+'px';
	}
	dl.w.scroll(0,0);
}
/* end of code. enjoy... */
