//most people forget to pass in the callback/handler
function GetXmlHttpObject(handler) { 
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("MSIE")>=0) { 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP";
		} 
		try { 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		} catch(e) { 
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	} else {
//	if (navigator.userAgent.indexOf("Mozilla")>=0) {
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 

//stores the id we're ajaxing
var lastDIV="";

//fill an id with a url, any object that supports innerHTML
function ajax(nurl,ndiv) {
	lastDIV = ndiv; 
	var url="" + nurl + "";
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

//ajax callback function
function stateChanged() {
	var divname=""+lastDIV;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete" || xmlHttp.status == 200) {
        	document.getElementById(divname).innerHTML=xmlHttp.responseText;		
	}
}

//fill an id with a url, any object that supports innerHTML
function ajax_loadScroll(nurl,ndiv) {
	lastDIV = ndiv; 
	var url="" + nurl + "";
	xmlHttp=GetXmlHttpObject(stateChanged_loadScroll);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

//ajax callback function
function stateChanged_loadScroll() {
	var divname=""+lastDIV;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete" || xmlHttp.status == 200) {
        	document.getElementById(divname).innerHTML=xmlHttp.responseText;


//directions:
//http://13thparallel.com/archive/dhtml-scrollbars/
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

//We wrap all the code in an object so that it doesn't interfere with any other code
var scroller = {

  init:   function() {

    var container="info_container";
    var content="info";

    //collect the variables
    scroller.docH = document.getElementById(content).offsetHeight;
    scroller.contH = document.getElementById(container).offsetHeight;
    scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight;
      
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)

    scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
    //scroller.scrollH = 15;

    //if(scroller.scrollH < 15) scroller.scrollH = 15;
    document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";
    
    //what is the effective scroll distance once the scoller's height has been taken into account
    scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
    //scroller.scrollDist = 400;
    //window.alert(scroller.scrollDist);
    
    //make the scroller div draggable
    Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist);
    
    //add ondrag function
    document.getElementById("scroller").onDrag = function (x,y) {
      var scrollY = parseInt(document.getElementById("scroller").style.top);
      var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
      document.getElementById(content).style.top = docY + "px";
    }//end onDrag

  }//end init

};


		scroller.init();
	}
}


//fill an id with a url, any object that supports innerHTML
function ajax_loadScrollRight(nurl,ndiv) {
	lastDIV = ndiv; 
	var url="" + nurl + "";
	xmlHttp=GetXmlHttpObject(stateChanged_loadScrollRight);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

//ajax callback function
function stateChanged_loadScrollRight() {
	var divname=""+lastDIV;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        	document.getElementById(divname).innerHTML=xmlHttp.responseText;

//directions:
//http://13thparallel.com/archive/dhtml-scrollbars/
var DragRight = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= DragRight.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = DragRight.obj = this;
		e = DragRight.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= DragRight.drag;
		document.onmouseup		= DragRight.end;

		return false;
	},

	drag : function(e)
	{
		e = DragRight.fixE(e);
		var o = DragRight.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		DragRight.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		DragRight.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		DragRight.obj.lastMouseX	= ex;
		DragRight.obj.lastMouseY	= ey;

		DragRight.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		DragRight.obj.root.onDragEnd(	parseInt(DragRight.obj.root.style[DragRight.obj.hmode ? "left" : "right"]), 
									parseInt(DragRight.obj.root.style[DragRight.obj.vmode ? "top" : "bottom"]));
		DragRight.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

//We wrap all the code in an object so that it doesn't interfere with any other code
var scrollerRight = {

  init:   function() {

    var container="info_containerRight";
    var content="infoRight";

    //collect the variables
    scrollerRight.docH = document.getElementById(content).offsetHeight;
    scrollerRight.contH = document.getElementById(container).offsetHeight;
    scrollerRight.scrollAreaH = document.getElementById("scrollAreaRight").offsetHeight;
      
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)

    scrollerRight.scrollH = (scrollerRight.contH * scrollerRight.scrollAreaH) / scrollerRight.docH;
    //scroller.scrollH = 15;

    //if(scroller.scrollH < 15) scroller.scrollH = 15;
    document.getElementById("scrollerRight").style.height = Math.round(scrollerRight.scrollH) + "px";
    
    //what is the effective scroll distance once the scoller's height has been taken into account
    scrollerRight.scrollDist = Math.round(scrollerRight.scrollAreaH-scrollerRight.scrollH);
    //scroller.scrollDist = 400;
    //window.alert(scroller.scrollDist);
    
    //make the scroller div draggable
    DragRight.init(document.getElementById("scrollerRight"),null,0,0,-1,scrollerRight.scrollDist);
    
    //add ondrag function
    document.getElementById("scrollerRight").onDrag = function (x,y) {
      var scrollY = parseInt(document.getElementById("scrollerRight").style.top);
      var docY = 0 - (scrollY * (scrollerRight.docH - scrollerRight.contH) / scrollerRight.scrollDist);
      document.getElementById(content).style.top = docY + "px";
    }//end onDrag

  }//end init

};



		scrollerRight.init();
	}
}


//stores the form data we're submitting
var formData="";

//send form via post with output directed to an id, usually div
function sendFormPost(nurl,ndiv) {
	lastDIV = ndiv;
	var url=""+nurl;
	var mode=true;
	var data=""+formData;
	var method="post";
	var header="Content-Type:application/x-www-form-urlencoded; charset=UTF-8";
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open(method,url,mode);
	xmlHttp.setRequestHeader(header.split(':')[0],header.split(':')[1]);
	xmlHttp.send(data);
}

//send form via get
function sendFormGet(nurl,ndiv) {
	lastDIV = ndiv;
	var url=""+nurl;
	var mode=true;
	var data=""+formData;
	var method="get";
	var header="Content-Type:application/x-www-form-urlencoded; charset=UTF-8";
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open(method,url+'?'+formData,mode);
	xmlHttp.setRequestHeader(header.split(':')[0],header.split(':')[1]);
	xmlHttp.send(data);
}

//no validation function yet
function getFormValues(fobj) {
	var str = "";
	for(var i = 0;i < fobj.elements.length;i++) {		

		if (fobj.elements[i].type == "checkbox") {
			if (fobj.elements[i].checked) {
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			} else {
				str += fobj.elements[i].name + "=&";
			}
		} else {
			str += fobj.elements[i].name +"=" + escape(fobj.elements[i].value) + "&";
		}
	}
	str = str.substr(0,(str.length - 1));
	formData=""+str;
	return str;
}

//2 forms at a time
function getFormValues2(fobj1,fobj2) {
	var str = "";
	for(var i = 0;i < fobj1.elements.length;i++) {		

		if (fobj1.elements[i].type == "checkbox") {
			if (fobj1.elements[i].checked) {
				str += fobj1.elements[i].name + "=" + escape(fobj1.elements[i].value) + "&";
			} else {
				str += fobj1.elements[i].name + "=&";
			}
		} else {
			str += fobj1.elements[i].name +"=" + escape(fobj1.elements[i].value) + "&";
		}
	}
	for(var i = 0;i < fobj2.elements.length;i++) {		

		if (fobj2.elements[i].type == "checkbox") {
			if (fobj2.elements[i].checked) {
				str += fobj2.elements[i].name + "=" + escape(fobj2.elements[i].value) + "&";
			} else {
				str += fobj2.elements[i].name + "=&";
			}
		} else {
			str += fobj2.elements[i].name +"=" + escape(fobj2.elements[i].value) + "&";
		}
	}

	str = str.substr(0,(str.length - 1));
	formData=""+str;
	return str;
}

//blocks old-school form submission via enter key
function noenter(event) {
	
	if (event.keyCode==13 || event.keyCode==3) {
		return false;
	} else {
		return true;
	}
}

//works with block, inline, and the the others, try shToggle(ntype,ndiv)
function shToggle(content) {
	if (document.getElementById(content).style.display == "none") {
		document.getElementById(content).style.display = "block";
	} else {
		document.getElementById(content).style.display = "none";
	}
}

//inverse all checkboxes in a form object
function check_all_inverse(fobj) {
	for(i=0;i<fobj.elements.length;i++) {
		if (fobj.elements[i].type=="checkbox") {
			if (fobj.elements[i].checked==true) {
				fobj.elements[i].checked=false;
			} else {
				fobj.elements[i].checked=true;
			}
		}
	}
}

//check all checkboxes in a form object
function check_all(fobj) {
        for(i=0;i<fobj.elements.length;i++) {
                if (fobj.elements[i].type=="checkbox") {
                        fobj.elements[i].checked=true;
                }
        }
}


