//ALL JAVASCRIPT HERE IS INCLUDED IN BOTH GLOBAL AND ADMIN SIDES


//Cool little onload Manager
//Allows you to create multiple onload events
//Just use addOnload([function name]);
var	olm			= new Array();
function addOnload(func){olm[olm.length] = func;}
function onloadManager(){for(var i = 0;i < olm.length;i++) {eval(olm[i]);}}
window.onload	= onloadManager;


//Tick All checkboxes
function checkBoxes(obj,formname,fieldname){
	//obj		= Set to equal  "this" without quotes
	//formname	= id name of the form the checkboxes are inside
	//fieldname = name of the checkboxes
	if(document.forms[formname].elements[fieldname+"[]"].length){
		for (i = 0; i < document.forms[formname].elements[fieldname+"[]"].length; i++){
			document.forms[formname].elements[fieldname+"[]"][i].checked = obj.checked;
		}
	}else{
		document.forms[formname].elements[fieldname+"[]"].checked = obj.checked;
	}
}

//Get Body Size
function getBodyDimensions(){
	var x = new Array();
	x[0] = 630;
	x[1] = 460;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			x[0] = window.innerWidth-16;
			x[1] = window.innerHeight-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			x[0] = document.body.offsetWidth-20;
			x[1] = document.body.offsetHeight-20;
		}
	}
	return x;
}

//Get Window Size
function getWindowSize(){
  var d = new Array();
  if(typeof(window.innerWidth) == 'number'){
    d[0] = window.innerWidth;
    d[1] = window.innerHeight;
  }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
    d[0] = document.documentElement.clientWidth;
    d[1] = document.documentElement.clientHeight;
  }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
    d[0] = document.body.clientWidth;
    d[1] = document.body.clientHeight;
  }
  return d;
}

//Get Scroll Offsets
function getScrollOffsets(){
	var s = new Array();
	if(typeof(window.pageYOffset) == 'number'){
		s[0] = window.pageXOffset;
		s[1] = window.pageYOffset;
	} else if(document.body && ( document.body.scrollLeft || document.body.scrollTop)){
		s[0] = document.body.scrollLeft;
		s[1] = document.body.scrollTop;		
	} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		s[0] = document.documentElement.scrollLeft;
		s[1] = document.documentElement.scrollTop;		
	} else {
		s[0] = 0;
		s[1] = 0;
	}
	return s;
}

//Returns the top and left values to know where the center of the window is at the
//point you have stopped moving the scrollbar.
function getWindowCenter(){
	var c			= new Array();
	var winDim		= getWindowSize();
	var winOffset	= getScrollOffsets();
	c[0]			= winOffset[1]+(winDim[1]/2);
	c[1]			= winOffset[0]+(winDim[0]/2);
	return c;
}

//Keep Centered
//Lets you keep a floating element centered on page when scrolling
function centerObject(id,objW,objH){
	obj=document.getElementById(id);
	var winCenter	=	getWindowCenter();	

	obj.style.top	=	(winCenter[0]-(objH/2))+"px";
	obj.style.left	=	(winCenter[1]-(objW/2))+"px";		
}

//Get Mouse Position
function getMousePosition(evt) {
	var mc = new Array();

	if (evt.pageX) {
		mc[0] = evt.pageX;
		mc[1] = evt.pageY;
	}else
	if (evt.clientX){
		mc[0] = evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		
		mc[1] = evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	} else {
		mc[0] = 0;
		mc[1] = 0;
	}
	return mc;
}

//Expand Div
function expandDiv(id,width,height,width_inc,height_inc,init) {
	if(init == null){
		var winc = width / 10;
		var hinc = height / 10;
		setTimeout("expandDiv('"+id+"',"+width+","+height+","+winc+","+hinc+",1)",10);
	} else {
		var time = 0;
		b = document.getElementById(id);
		w = parseInt(b.style.width);
		h = parseInt(b.style.height);

		if(w < width){
			b.style.width = (w + width_inc) + "px";
			time = 1;
		}
		if(h < height){
			b.style.height = (h + height_inc) + "px";
			time = 1;
		}
		if(time == 1){
			setTimeout("expandDiv('"+id+"',"+width+","+height+","+width_inc+","+height_inc+",1)",10);
		}
	}
}


