// $Id: functions.js,v 1.15 2006/08/29 01:07:58 lina Exp $

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG()
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.width && img.height)
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
	var inputs = document.getElementsByTagName("input")
	var re = new RegExp("(.*\/)[^\/]+$")
	for(i=0; i<inputs.length; i++)
	{
		img = inputs[i]
		imgName = img.type == "image" ? img.src.toUpperCase() : "dummy.jpg"
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.width && img.height)
		{
			imgStyle = img.style.cssText
			imgStyle = "width:" + img.width + "px; height:" + img.height + "px;"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');" + imgStyle
			img.style.cssText = imgStyle
			var m = re.exec(img.src)
			img.src = m[1] + "spacer.gif"
		}
	}
}

function openPopUp (url, width, height, windowName, scrollable, resizable, centred, toolbar) {
	if (width == null) width = 400;
	if (height == null) height = 400;
	if (windowName == null) windowName = '_blank';
	if (scrollable == null) scrollable = true;
	if (resizable == null) resizable = true;
	if (centred == null) centred = true;
	if (toolbar == null) toolbar = false;
	var extra = '';
	if (centred) {
		var left = Math.round(screen.width / 2 - width / 2);
		var top = Math.round(screen.height / 2 - height / 2);
		extra = ',left=' + left + ',top=' + top;
	}
	var popUp = window.open(url, windowName, 'width=' + width + ',height=' + height + (scrollable ? ',scrollbars' : '') + (resizable ? ',resizable' : '') + (toolbar ? ',toolbar' : '') + extra);
	popUp.focus();
}

function getElem (id) {
	if (isIE) {
		return eval('document.all.' + id);
	} else {
		return document.getElementById(id);
	}
}

function showElem (id, displayValue) {
	if (displayValue == null) {
		displayValue = 'block';
	}
	getElem(id).style.display = displayValue;
	var visible = getElem(id + '_visible');
	if (visible) {
		visible.value = -1;
	}
}

function hideElem (id) {
	getElem(id).style.display = 'none';
	var visible = getElem(id + '_visible');
	if (visible) {
		visible.value = 0;
	}
}

function ovrElem (elem) {
	var cssClass = elem.className;
	if (cssClass.substr(0, 4) != 'ovr_') {
		elem.className = 'ovr_' + cssClass;
	}
}

function outElem (elem) {
	var cssClass = elem.className;
	if (cssClass.substr(0, 4) == 'ovr_') {
		elem.className = cssClass.substr(4);
	}
}

function ovrRow (row) {
	ovrElem(row);
}

function outRow (row) {
	outElem(row);
}

function addElemEvent (elem, event, code) {
	var e;
	eval('e = elem.' + event + ';');
	if (typeof(e) == 'function') {
		e = e.toString();
		e = ' ' + e.substring(e.indexOf('{') + 1, e.lastIndexOf('}'));
	} else {
		e = '';
	}
	var f = new Function('event', code + e);
	eval('elem.' + event + ' = f;')
}

function showTab (tid, tabIndex) {
	if (tabIndex >= arrTabs[tid].length) {
		tabIndex = 0;
	}
	for (var i = 0; i < arrTabs[tid].length; i++) {
		var id = arrTabs[tid][i][0];
		var selectorId = arrTabs[tid][i][1];
		if (tabIndex == i) {
			showElem(id, 'block');
			getElem(selectorId).className = 'activeTab';
		} else {
			hideElem(id);
			getElem(selectorId).className = 'inactiveTab';
		}
	}
	getElem('tabsSelectedIndex' + tid).value = tabIndex;
	if (isIE && !isOpera) {
		correctPNG();
	}
}


/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

document.write('<div id="dhtmltooltip"></div>')

var offsetxpoint=12 //Customize x offset of tooltip
var offsetypoint=15 //Customize y offset of tooltip
var ie=document.all ? true : false
var ns6=document.getElementById && !document.all ? true : false
var enabletip=false
var tipobj

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
	if (ns6||ie){
		tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
		tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip

/***
* End of Cool DHTML tooltip script
***/


var isIE = document.all ? true : false;
var isOpera = window.opera ? true : false;
var arrTabs = new Array();

if (isIE && !isOpera) {
	window.attachEvent("onload", correctPNG);
}

