var lastWin

function PopupScreenCentre(url,name,width,height,scrollbars) 
{
	var titleBarHeight, windowBorderWidth
	titleBarHeight = 24
	windowBorderWidth = 4

	var screenWidth, screenHeight
	screenWidth = 800
	screenHeight = 600

	if (window.screen) 
	{
		if (window.screen.availWidth) 
		{
			// ok browser has the appropriate properties we need to centre it
			screenWidth = window.screen.availWidth
			screenHeight = window.screen.availHeight
		}
	}

	var windowWidth = windowBorderWidth + width + windowBorderWidth
	var windowHeight = titleBarHeight + height + windowBorderWidth

	var left = (screenWidth - windowWidth) / 2
	var top = (screenHeight - windowHeight) / 2

	if(lastWin&&!lastWin.closed)
	{
		lastWin.close()
	}
	lastWin = window.open(url,name,'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+height+',scrollbars=1,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0')
}

function ImagePopup(filename) 
{
	PopupScreenCentre("attachments/" + filename, "_blank", 780, 550, 0)
}

function changePage(selectObj) 
{
  if(selectObj.selectedIndex!=-1&&selectObj.selectedIndex!=0)
  {
    document.location="page.asp?id="+selectObj.options[selectObj.selectedIndex].value
  }
}

// check that the tooltip shown is visible
function showTip(linkObj)
{
//	var tipObj = document.getElementById(toolTipID);
	var tipObj = linkObj.lastChild;
	jsdebug("show")
	if(tipObj)
	{
		jsdebug("obj")
		
		//debugger
		tipObj.style.display='block';
		//var width = $(toolTipID).getDimensions().width 
		var width = 232;
		var left = cumulativeOffset(tipObj)[0];  //array is [left,top]
		var right = left + width //width of tip box
		jsdebug("left["+tipObj.style.left+"]")
		
		var windowWidth = (window.innerWidth)?window.innerWidth:document.documentElement.clientWidth
		jsdebug("windowWidth["+windowWidth+"]")
		if(right > windowWidth)
		{
			//$$(toolTipID).makePositioned(); 
			//tipObj.left=-400;
			jsdebug("right["+right+"]")
			tipObj.style.left="-"+((right - windowWidth)+70)+"px"
			jsdebug("left["+tipObj.style.left+"]")
		}
		//alert(tipObj.style.left)
	}else
	{
		jsdebug("no obj")
	
	}
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function jsdebug(messageText)
{
  var s = " ";                     // Declare variables.
  var d = new Date();              // Create Date object with today's date.
  s += d.getYear() + "/";          // Get year.
  text = ''+(d.getMonth() + 1)     // Get month
  s += ((text.length==1)?'0'+text:text) + "/";   
  text = ''+(d.getDate())
  s += ((text.length==1)?'0'+text:text) + " ";          // Get day
  var c = ":";
  text = ''+d.getHours()
  s += ((text.length==1)?'0'+text:text) + c;        
  text = ''+d.getMinutes() ;         // Get Minutes
  s += ((text.length==1)?'0'+text:text) +  c;        
  text = ''+d.getSeconds() ;       // Get Seconds
  s += ((text.length==1)?'0'+text:text) +  c;        
  text = ''+d.getMilliseconds();        // Get Milliseconds
  s += ((text.length==2)?'0'+text:text) +  '.';        

  document.getElementById("debugarea").innerHTML = s+': '+messageText +'<br>'+ document.getElementById("debugarea").innerHTML
}


function cumulativeOffset(element) {
  var valueT = 0, valueL = 0;
  do {
    valueT += element.offsetTop  || 0;
    valueL += element.offsetLeft || 0;
    element = element.offsetParent;
  } while (element);
  return [valueL, valueT];
}


// hide the tooltip 
function hideTip(linkObj)  //toolTipID)
{
	var tipObj = linkObj.lastChild;
	//var tipObj = document.getElementById(toolTipID);
	if(tipObj)
	{
		tipObj.style.display='none';
		tipObj.style.left="0px"
	}
}

function makeRequest(url) {
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = function() { alertContents(http_request); };
    http_request.open('GET', url, true);
    http_request.send(null);

}

function alertContents(http_request) {

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            alert(http_request.responseText);
        } else {
            alert('There was a problem with the request.');
        }
    }

}

function PopWindow(url,w,h) {
var windowtop = ((screen.height - h) / 2) - 39;
var windowleft = (screen.width - w) / 2;
win = window.open(url,'newwindow','height='+h+',width='+w+',top='+windowtop+',left='+windowleft+'toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no')
win.focus();
}