/***********************************************************
* Author Chris Hobden <chris@impera.co.uk>                *
* Copyright (c) Oshun Ltd, 2003-2008. All rights reserved.*
* See http://www.imperal.co.uk/licence/                   *
***********************************************************/
var isis={
'loadclass': function(name){
	var client=isis.getClient();
	var date = new Date();
	var timestamp = date.getTime();
	var url='/isisjslib/'+name.toLowerCase().substr(4)+'.js?time='+timestamp;
	client.open('GET', url, false);
	client.send(null);
	eval(client.responseText);
	window[name] = eval(name);
},
'ajax': function(props){
	if(typeof isisAjax == 'undefined')isis.loadclass('isisAjax');
	return new isisAjax(props);
},
'graph': function(props){
	if(typeof isisGraph == 'undefined')isis.loadclass('isisGraph');
	return new isisGraph(props);
},
'slider': function(props){
	if(typeof isisSlider == 'undefined')isis.loadclass('isisSlider');
	return new isisSlider(props);
},
'datePicker': function(fid, date_format, inc_time){
	if(typeof isisDatePicker == 'undefined')isis.loadclass('isisDatePicker');
	return new isisDatePicker(fid, date_format, inc_time);
},
'xmltable': function(props){
	if(typeof isisXMLTable == 'undefined')isis.loadclass('isisXMLTable');
	return new isisXMLTable(props);
},
'menu': function(props){
	if(typeof isisMenu == 'undefined')isis.loadclass('isisMenu');
	return new isisMenu(props);
},
'progress': function(props){
	if(typeof isisProgress == 'undefined')isis.loadclass('isisProgress');
	return new isisProgress(props);
},
'dialog': function(props){
	if(typeof isisDialog == 'undefined')isis.loadclass('isisDialog');
	return new isisDialog(props);
},
'titlebar': function(props){
	if(typeof isisTitleBar == 'undefined')isis.loadclass('isisTitleBar');
	return new isisTitleBar(props);
},
'widget': function(title, url, containerid, props){
	if(typeof isisWidget == 'undefined')isis.loadclass('isisWidget');
	return new isisWidget(title, url, containerid, props);
},
'fx': function(obj, props){
	if(typeof isisFX == 'undefined')isis.loadclass('isisFX');
	return new isisFX(obj, props);
},
'addEventHandler': function(target,eventname,func, capture){
	capture=capture?capture:false;
	if ( target.addEventListener ) {
		target.addEventListener(eventname, func, capture);
	} else {
		target.attachEvent("on" + eventname, func);
	}
},
'toggleDisplay':function(fid){
	var field=document.getElementById(fid);
	if(field)field.style.display=field.style.display==""?"none":"";
},
'getClient': function(){
	if(typeof XMLHttpRequest !='undefined')return new XMLHttpRequest();
	var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
	for(var i=0;i<axO.length;i++){
		try{
			return new ActiveXObject(axO[i]);
		}catch(e){}
	}
	return false;
},
'readCookie': function(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
},
'createCookie': function(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
},
'err': function(err){
	this.dialog({'message':err});
},
'getScrollTop': function(){
	if (document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop;
	}else if (document.body){
		return document.body.scrollTop;
	}else 0;
},
'getScrollLeft': function(){
	if (document.documentElement && document.documentElement.scrollLeft){
		return document.documentElement.scrollLeft;
	}else if (document.body){
		return document.body.scrollLeft;
	}else 0;
},
'getClientWidth': function(){
	if (self.innerWidth){
		return self.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth){
		return document.documentElement.clientWidth;
	}else if (document.body){
		return document.body.clientWidth;
	}else 0;
},
'getClientHeight': function(){
	if (self.innerHeight){
		return self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight){
		return document.documentElement.clientHeight;
	}else if (document.body){
		return document.body.clientHeight;
	}else 0;
},
'getMouseCoords': function(e){
	if(e.pageX || e.pageY){
		return {x:e.pageX, y:e.pageY};
	}
	return {
		x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:e.clientY + document.body.scrollTop  - document.body.clientTop
	};
},
'getPosition': function(obj){
	var left = 0;
	var top  = 0;
	while (obj.offsetParent){
		if(!obj.currentStyle||obj.currentStyle.hasLayout==true)left += obj.offsetLeft; //IE fix, not 100% tested
		top  += obj.offsetTop;
		obj     = obj.offsetParent;
	}
	left += obj.offsetLeft;
	top  += obj.offsetTop;

	return {x:left, y:top};
},
'hexdig':'0123456789ABCDEF',
'hueShift':function(h,s){
	h+=s;
	while (h>=360.0) h-=360.0;
	while (h<0.0) h+=360.0;
	return h;
},
'dec2Hex':function (d){
	return this.hexdig.charAt((d-(d%16))/16)+this.hexdig.charAt(d%16);
},
'Hex2dec':function (h){
	h=h.toUpperCase();
	d=0;
	for (i=0;i<h.length;i++) {
		d=d*16;
		d+=this.hexdig.indexOf(h.charAt(i));
	}
	return d;
},
'RGB2Hex':function(rgb){
	return '#'+this.dec2Hex(rgb.r)+this.dec2Hex(rgb.g)+this.dec2Hex(rgb.b);
},
'putInRange':function(n,l,h){
	return (n<l)?l:((n>h)?h:n);
},
'hex2RGB':function (hex){
	if(hex.charAt(0)=="#")hex=hex.substring(1,7);
	var rgb=new Object();
	rgb.r=parseInt(hex.substring(0,2), 16);
	rgb.g=parseInt(hex.substring(2,4), 16);
	rgb.b=parseInt(hex.substring(4,6), 16);
	return rgb;
},
'HSV2RGB':function(hsv){
	var rgb=new Object();
	if (hsv.saturation==0) {
		rgb.r=rgb.g=rgb.b=Math.round(hsv.value*2.55);
	} else {
		hsv.hue/=60;
		hsv.saturation/=100;
		hsv.value/=100;
		i=Math.floor(hsv.hue);
		f=hsv.hue-i;
		p=hsv.value*(1-hsv.saturation);
		q=hsv.value*(1-hsv.saturation*f);
		t=hsv.value*(1-hsv.saturation*(1-f));
		switch(i) {
			case 0: rgb.r=hsv.value; rgb.g=t; rgb.b=p; break;
			case 1: rgb.r=q; rgb.g=hsv.value; rgb.b=p; break;
			case 2: rgb.r=p; rgb.g=hsv.value; rgb.b=t; break;
			case 3: rgb.r=p; rgb.g=q; rgb.b=hsv.value; break;
			case 4: rgb.r=t; rgb.g=p; rgb.b=hsv.value; break;
			default: rgb.r=hsv.value; rgb.g=p; rgb.b=q;
		}
		rgb.r=Math.round(rgb.r*255);
		rgb.g=Math.round(rgb.g*255);
		rgb.b=Math.round(rgb.b*255);
	}
	return rgb;
},
'RGB2HSV':function(rgb){
	hsv = new Object();
	max=this.max3(rgb.r,rgb.g,rgb.b);
	dif=max-this.min3(rgb.r,rgb.g,rgb.b);
	hsv.saturation=(max==0.0)?0:(100*dif/max);
	if (hsv.saturation==0) hsv.hue=0;
	else if (rgb.r==max) hsv.hue=60.0*(rgb.g-rgb.b)/dif;
	else if (rgb.g==max) hsv.hue=120.0+60.0*(rgb.b-rgb.r)/dif;
	else if (rgb.b==max) hsv.hue=240.0+60.0*(rgb.r-rgb.g)/dif;
	if (hsv.hue<0.0) hsv.hue+=360.0;
	hsv.value=Math.round(max*100/255);
	hsv.hue=Math.round(hsv.hue);
	hsv.saturation=Math.round(hsv.saturation);
	return hsv;
},
'min3':function(a,b,c){
	return (a<b)?((a<c)?a:c):((b<c)?b:c);
},
'max3':function(a,b,c){
	return (a>b)?((a>c)?a:c):((b>c)?b:c);
},
'showSelect':function(x,y,w,h){
	var selx,sely,selw,selh,i
	var sel=document.getElementsByTagName("SELECT")
	for(i=0;i<sel.length;i++){
		selx=0; sely=0; var selp;
		if(sel[i].offsetParent){
			selp=sel[i];
			while(selp.offsetParent){
				selp=selp.offsetParent;
				selx+=selp.offsetLeft;
				sely+=selp.offsetTop;
			}
		}
		selx+=sel[i].offsetLeft;
		sely+=sel[i].offsetTop;
		selw=sel[i].offsetWidth;
		selh=sel[i].offsetHeight;
		if(selx+selw>x && selx<x+w && sely+selh>y && sely<y+h)
		sel[i].style.visibility="visible";
	}
},
'hideSelect':function(x,y,w,h){
	var selx,sely,selw,selh,i
	var sel=document.getElementsByTagName("SELECT")
	for(i=0;i<sel.length;i++){
		selx=0; sely=0; var selp;
		if(sel[i].offsetParent){
			selp=sel[i];
			while(selp.offsetParent){
				selp=selp.offsetParent;
				selx+=selp.offsetLeft;
				sely+=selp.offsetTop;
			}
		}
		selx+=sel[i].offsetLeft;
		sely+=sel[i].offsetTop;
		selw=sel[i].offsetWidth;
		selh=sel[i].offsetHeight;
		if(selx+selw>x && selx<x+w && sely+selh>y && sely<y+h)
		sel[i].style.visibility="hidden";
	}
}
};