function hideDiv(id, imageId) {
	var obj = document.getElementById(id);
	var img = document.getElementById(imageId);
	if (obj.style.display == "none")
	{
		obj.style.display = "";
		if (img)
			img.setAttribute("src", "/jobitcommon/images/minus.gif");
	}
	else
	{
		obj.style.display = "none";
		if (img)
			img.setAttribute("src", "/jobitcommon/images/plus.gif");
	}
}

function fnTrapKD(btn, event){
	if (document.all) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancel = true;
			btn.click();
			return false;
		}
	}
	else if (document.getElementById) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancel = true;
			btn.click();
			return false;
		}
	}
}
function fnTrapKDLB(btn, event){
	if (document.all) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancel = true;
			__doPostBack(btn, '');
			return true;
		}
	}
	else if (document.getElementById) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancel = true;
			__doPostBack(btn, '');
			return true;
		}
	}
}

function enableRow(checkbox, userDataList)
{
	userDataList.disabled = !checkbox.checked;
}

//Pop up class

// object constructor
function Popup() {
	// define object's properties
	this.name = "";
	//this.init();
	
	this.eventObj = null;
	this.offset = 0;
	this.x = 0;
	this.y = 0;
	this.below = false;
	this.allowClose = false; // enables esc and document click to close
			
	// attach object's methods
	this.findPosX = _findPosX;
	this.findPosY = _findPosY;
}

function Popup(name) {
	// define object's properties
	this.name = name;
	//this.init();
	
	this.eventObj = null;
	this.offset = 0;
	this.x = 0;
	this.y = 0;
	this.below = false;
	this.allowClose = false; // enables esc and document click to close
			
	// attach object's methods
	this.findPosX = _findPosX;
	this.findPosY = _findPosY;
}

Popup.prototype = {
	init: function ()
	{
		this.eventObj = null;
		this.offset = 0;
		this.x = 0;
		this.y = 0;
		this.below = false;
		this.allowClose = false; // enables esc and document click to close
				
		// attach object's methods
		this.findPosX = _findPosX;
		this.findPosY = _findPosY;
	},
	
	setCenter: function (cen)
	{
		this.center = cen;
	},

	setOffset: function(os)
	{
		this.offset = os;
	},

	getEventObj: function()
	{
		return this.eventObj;
	},

	setEventObj: function(eventObj)
	{
		this.eventObj = eventObj;
	},

	setContent: function(content)
	{
		this.content = content;
		var div = document.getElementById(this.name + '_popupDiv_');
		if (div != null) {
			this.show();
		}
	},

	setX: function(x)
	{
		this.x = x;
	},

	setY: function(y)
	{
		this.y = y;
	},

	setBelow: function(b)
	{
		this.below = b;
	},

	show: function()
	{
		var pageBody = document.getElementsByTagName("body").item(0); // body of page

		//var iframe = document.createElement('iframe'); // create iframe
		/*if (browser('msie')) {
			pageBody.appendChild(iframe); // add to the page body

			iframe.id = this.name + '_popupFrame_';
			iframe.src = 'javascript:false;';
			iframe.frameBorder = 0;
			iframe.style.position = 'absolute';
			iframe.style.display = 'none';
		}*/

		var div = document.getElementById(this.name + '_popupDiv_');
		if (div == null) {
			div = document.createElement('div'); // create iframe
		}
		
		div.style.position = 'absolute';
		div.style.display = "none";

		div.id = this.name + '_popupDiv_';
		pageBody.appendChild(div); // add to the page body

		// show the popup
		//eventObj = document.getElementById(objId); // used to position the tooltip

		if ((this.content != null) && (this.content != "")) { // position and show tooltip
			div.innerHTML = this.content;
			
			if (browser('msie')) {
				g = window.document.body.scrollTop;
			}
			else {
				g = window.pageYOffset;
			}
		
			// weird hack to stop the start at left move to position
			div.style.visibility = "hidden";
			div.style.display = "block";

			if (this.center) {
				var top = ((pageBody.clientHeight / 2) + g) - (div.offsetHeight / 2);
				div.style.top  = top;
				div.style.left = (pageBody.clientWidth / 2) - (div.offsetWidth  / 2);
			}
			else {
				if (this.below) {
					div.style.top  = this.findPosY(this.eventObj) + (this.eventObj.offsetHeight + this.y);
					div.style.left = this.findPosX(this.eventObj) + this.x + this.offset;
				}
				else {
					var top = this.findPosY(this.eventObj) - (div.offsetHeight + this.x)
					if (top < 0)
						top = 0;
					div.style.top  = top;
					div.style.left = this.findPosX(this.eventObj) - ((div.offsetWidth - this.eventObj.offsetWidth) + this.y) + this.offset;
				}
			}

			/*if (browser('msie')) {
				iframe.style.width = div.offsetWidth;
				iframe.style.height = div.offsetHeight;
				iframe.style.left = div.style.left;
				iframe.style.top = div.style.top;
			}*/

			// weird hack to stop the popup from start at left the moving
			if (! this.center)
			{
				var l = parseInt(div.style.left);
				div.style.left = 10;
				var w = div.offsetWidth;
				div.style.left = l;
				if (l + w >= pageBody.clientWidth)
				{
					div.style.left = pageBody.clientWidth - (parseInt(div.style.left) + div.offsetWidth);
				}
			}
			div.style.display = "none";
			div.style.visibility = "visible";
			
			div.style.display = "block";
			//iframe.style.display = 'block';
			
			this.element = div;
			
	       	if (this.allowClose)
	       	{
	       		// our events
				this.onKeyHandler = new EventHandler(document, "keypress", "escPressed", this, false);
				this.onMouseOutHandler = new EventHandler(this.element, "mouseout", "onMouseOut", this, false);
				this.onMouseOverHandler = new EventHandler(this.element, "mouseover", "onMouseOver", this, false);
				this.onClickHandler = new EventHandler(document, "click", "onDocClick", this, false);
				
				EventManager.add(this.onKeyHandler);
				EventManager.add(this.onClickHandler);
				EventManager.add(this.onMouseOutHandler);
				EventManager.add(this.onMouseOverHandler);
			}
		}
		else {
			this.hide();
		}
	},

	hide: function()
	{
		//var iframe = document.getElementById(this.name + '_popupFrame_');
		var div = document.getElementById(this.name + '_popupDiv_');

		var mybody = document.getElementsByTagName("body").item(0);

		/*if (iframe != null) {
			mybody.removeChild(iframe);
		}*/
		if (div != null) {
			mybody.removeChild(div);
		}
		
        if (this.allowClose)
        {
			EventManager.remove(this.onKeyHandler);
			EventManager.remove(this.onMouseOutHandler);
			EventManager.remove(this.onMouseOverHandler);
			EventManager.remove(this.onClickHandler);
		}
	},
	
	// event handlers
	onMouseOut: function(e)
    {
        EventManager.add(this.onClickHandler);
        //this.autoHiding = setTimeout('this.close()', 2000);
    },

    onMouseOver: function(e)
    {
        //clearInterval(this.autoHiding);
        EventManager.remove(this.onClickHandler);
    },
    
    onDocClick: function(e)
    {
        this.hide();
    },

    escPressed: function(e) 
    {
	    var code;
	    if (e.keyCode) code = e.keyCode;
	    else if (e.which) code = e.which;
    	
	    if (code == 27)
	    {
            this.hide();
	    }
    }
}



/* helpers */

function _findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function _findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

//
function browser(string)
{
	place = navigator.userAgent.toLowerCase().indexOf(string) + 1;
	thestring = string;
	return place;
}

function switchTabs(idToShow, idToHide)
{
	var show = document.getElementById(idToShow);
	var hide = document.getElementById(idToHide);
	
	hide.style.display = 'none';
	show.style.display = '';
}

function calculateInc(value, boxId)
{
	var box = document.getElementById(boxId);
	var result;
	value = value.replace(",", "");
	value = value.replace("$", "");
	result = value * 1.1;

	box.innerHTML = "$" + result.toFixed(2);
}