

var iutils = function()
{
	var fn = {
		ua:navigator.userAgent.toLowerCase(),isIe:false,isIe6:false,backSet:false,backDocSet:false,cursor:'pointer',
		head_tag:document.getElementsByTagName("head")[0],rdf:[],
		ax:false,ax_replace:true,
		init:function ()
		{
			iutils.isIe = iutils.ua.indexOf("msie")>-1;
			iutils.isIe6 = iutils.ua.indexOf("msie 6")>-1;
			iutils.cursor = (iutils.isIe) ? 'hand' : 'pointer';
			var xhDoc = iutils.getDoc();
			iutils.backDocSet = (iutils.isIe && iutils.isIe && xhDoc.xhtml == 'HTML' && parseInt(xhDoc.version) == 4);
			iutils.backSet = (iutils.isIe6 || iutils.backDocSet);
			iutils.treeholder = iutils.get(iutils.holderId);
		},
		center:function (e, a, s)
		{
			var _w = iutils.getWDim();
			var _s = iutils.getWScr();
			var _e = iutils.getEDim(e);
			var _o = iutils.getPos(e);
			
//			_e.height+=(iutils.wrapadBWidth*2);
			var corH = ( iutils.qaState ) ? (iutils.ad.qaCount * 26) + 25 : 0; // count + pad
			
			var setX = ( _w.width - _e.width  ) / 2 + (a ? _s.scrollX : 0 );
			var setY = ( _w.height - (_e.height + corH) ) / 2 + (a ? _s.scrollY : 0 );
			
			// if object bigger than win h
			if (_w.height < (_e.height + corH)) setY = _w.height + (iutils.backSet?_s.scrollY:0) - (_e.height + corH); 
			
			e.style.left = setX + "px";
			if (s) iutils.fx(e, 'top', setY, 0.35 )
			else e.style.top  = setY + "px";
		},
		getEDim:function(e)
		{
			var display = e.style.display;
			if (display != 'none' && display != null) return { width: e.offsetWidth, height: e.offsetHeight};
			return {width: e.clientWidth, height: e.clientHeight};
		},
		getWScr:function()
		{
			var sX = 0, sY = 0, d=document,w=window;
			if( typeof( w.pageYOffset ) == 'number' ) { sY = w.pageYOffset;sX = w.pageXOffset;}
			else if( d.body && ( d.body.scrollLeft || d.body.scrollTop ) ) { sY = d.body.scrollTop; sX = d.body.scrollLeft;}
			else if( d.documentElement && ( d.documentElement.scrollLeft || d.documentElement.scrollTop ) ) { sY = d.documentElement.scrollTop; sX = d.documentElement.scrollLeft;}
			return {scrollX: sX, scrollY: sY};
		},
		getWDim:function()
		{
			var x = 0, y = 0,d=document,w=window;
			if (w.innerWidth && w.innerWidth != 0) x = w.innerWidth;
			else if (d.documentElement.clientWidth && d.documentElement.clientWidth != 0) x = d.documentElement.clientWidth;
			else if (d.body.clientWidth && d.body.clientWidth != 0) x = d.body.clientWidth;
			
			if (w.innerHeight && w.innerHeight != 0) y = w.innerHeight;
			else if (d.documentElement.clientHeight && d.documentElement.clientHeight != 0) y = d.documentElement.clientHeight;
			else if (d.body.clientHeight && d.body.clientHeight != 0) y = d.body.clientHeight;
			
			return {width:x, height:y};
		},
		getPos:function (e)
		{
			var obj = e;
			var curleft = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curleft += obj.offsetLeft;
					obj = obj.offsetParent;
				}
			}
			else if (obj.x) curleft += obj.x;
			
			var obj = e;
			var curtop = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curtop += obj.offsetTop;
					obj = obj.offsetParent;
				}
			}
			else if (obj.y) curtop += obj.y;

			curtop += e.offsetHeight;
			return {left:curleft, top:curtop};
		},
		getStyle:function(h,g){
			var a=document.defaultView;
			if (a&&a.getComputedStyle) 
			{
				var e,f;
				if(g=="float"){g="cssFloat"}
				if(e=h.style[g]){return e}
				if(f=a.getComputedStyle(h,"")){return f[g]}
				return null
			}
			var t;
			if(g=="opacity")
			{
				if(typeof h.style.filter=="string")
				{
					var e=h.style.filter.match(/alpha\(opacity=(.+)\)/i);
					if(e){var j=parseFloat(e[1]);
						if(!isNaN(j)){return(j?j/100:0)}
					}
				}
				return 1
			}
			if(g=="float"){g="styleFloat"}
			if(t=h.style[g]){return t}
			if(t=h.currentStyle){return t[g]}
			return null
		},
		getDoc:function()
		{
			var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
			var v={xhtml:'HTML',version:4,importance:'Transitional'};
			if(typeof document.namespaces != "undefined")
			{
				if(document.all[0].nodeType==8) re.exec(document.all[0].nodeValue);
				else return v;
			}
			else
			{
				if(document.doctype != null) re.exec(document.doctype.publicId);
				else return v;
			}
			return {xhtml:RegExp.$1,version:parseInt(RegExp.$2),importance:RegExp.$3}
		},
		get:function (e){return document.getElementById(e);},
		css:function (e,s) { for (var i in s) e.style[i] = s[i]; },
		attach:function(o,e,f){if(o.addEventListener)o.addEventListener(e,f,false);else if(o.attachEvent)o.attachEvent("on"+e,f);},
		ready:function(f){ iutils.attach(window,'load', f); },
		trim:function(v){v=v.replace(/^\s+/, '');return v.replace(/\s+$/, '');},
		loadScript:function(s,f) { var b=document.createElement("script");b.charset="UTF-8";b.src=s; iutils.head_tag.appendChild(b); if (f) f();},
		bgmessage:function(id,cl)
		{
			var f = function()
			{
				iutils.css(iutils.get('ioverlay'),{display:'none'});
				iutils.css(iutils.get(id),{display:'none'});
				if (null != cl.onClick)
					cl.onClick();
				return false;
			}
			
			var o = iutils.get('ioverlay');
			if (!o)
			{
				var d = iutils.getWDim(), b = document.getElementsByTagName("body").item(0), o = document.createElement("div");
				o.setAttribute('id', 'ioverlay');
				b.insertBefore(o, b.firstChild);
			}
			iutils.css(o,{position:'absolute',display:'block',background:'#'+cl.color,opacity:cl.opacity,height:d.height+'px',width:'100%',zIndex:50});
			
			o.onclick = f;
			if (null != cl.eventObj)
				iutils.get(cl.eventObj).onclick = f;
			
			iutils.css(iutils.get(id),{display:'block',zIndex:99});
		},
		axcall:function(a,r,c,t,cb)
		{
			if (iutils.ax)
			{
				var b = '\'' + a + '\', \'' + r + '\', \'' + c + '\', \'' + t + '\', \'' + cb + '\'';
				setTimeout("AjaxRequestCall("+b+")", 100);
				return;
			}
			
			iutils.ax = true;
			setTimeout(function() { iutils.ax = false; }, 10000);
			
			if (t=='get') iutils.axget(a,r,c,cb);
			else iutils.axpost(a,r,c,cb);
		},
		axget:function(a,r,c,cb)
		{
			a = a.replace(/^https?\:\/\/[^\/]+/, '');
			if (a != '') r = a + '?' + r;
			
			var pc = false;
			if (window.XMLHttpRequest)
				pc = new XMLHttpRequest()
			else if (window.ActiveXObject)
			{ 
				try { pc = new ActiveXObject("Msxml2.XMLHTTP") } 
				catch (e){
					try { pc = new ActiveXObject("Microsoft.XMLHTTP") }
					catch (e){}
				}
			}
			else return false;
			
			pc.onreadystatechange=function() { iutils.axcb(pc,c,cb); }
			pc.open('GET', r, true);
			pc.send(null);
		},
		axpost:function(a,r,c,cb)
		{
			a = a.replace(/^https?\:\/\/[^\/]+/, '');
			var pc = false;
			if (window.XMLHttpRequest)
				pc = new XMLHttpRequest()
			else if (window.ActiveXObject)
			{
				try { pc = new ActiveXObject("Msxml2.XMLHTTP") } 
				catch (e){
					try { page_request = new ActiveXObject("Microsoft.XMLHTTP") }
					catch (e){}
				}
			}
			else return false;

			pc.onreadystatechange=function() { iutils.axcb(pc,c,cb); }
			pc.open('POST', (a), true);
			pc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			pc.send(r);
			
		},
		axcb:function(pc,c,cb)
		{
			cb = (!cb || cb == '') ? null : cb;
			if (pc.readyState == 4 && (pc.status==200 || window.location.href.indexOf("http")==-1))
			{
				var b = pc.responseText;
				
				if (c != 'null' && !iutils.get(c))
					iutils.axel(c);

				if (iutils.ax_replace)
				{
					if (c == 'alert') 
						alert(b);
					else if (c != 'null')
						iutils.get(c).innerHTML = b;
				}
				else
					iutils.get(c).innerHTML = iutils.get(c).innerHTML + b;
				
				if (cb != null)
				{
					var _tc = (c != 'null') ? "'" + c + "'" : "null";
					if (typeof(cb) == 'function') cb(_tc.replace(/\'/g,''))
					else window.setTimeout(cb + "("+_tc+")", 50);
			
				}
				iutils.ax = false;
			}
		},
		axel:function(id)
		{
			var b = document.getElementsByTagName("body").item(0);
			var e = document.createElement("div");
			e.setAttribute('id', id);
			e.style.position = 'absolute';
			e.style.display = 'none';
			b.insertBefore(e, b.firstChild);
		},
		axdata:function(id)
		{
			var c = iutils.get(id);
			if (!c) return '';
			var d = c.innerHTML;
			c.innerHTML = '';
			return d;
		}
	};
	for (var o in fn) this[o] = fn[o];
	
	var iutils = this;
	iutils.init();
	return iutils;
};


var iutils = new iutils();
