var windowWidth = 0;
var windowHeight = 0;
var contentScrollTop = 0;
var windowSizeChanged = false;

function getSettings()
{
	getBrowser();
	getDOMType();
	getWindowSize();
}

function getWindowSize()
{
	var newWidth;
	var newHeight;
	var newScroll;

	if (document.getElementById('page'))
		newScroll = document.getElementById('page').scrollTop;
	else
		newScroll = 0;
		
	if (self.innerHeight) // all except Explorer
	{
		newWidth = self.innerWidth;
		newHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		newWidth = document.documentElement.clientWidth;
		newHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		newWidth = document.body.clientWidth;
		newHeight = document.body.clientHeight;
	}

	windowSizeChanged = false;
	if ((newWidth!=windowWidth) || (newHeight!=windowHeight) || (newScroll!=contentScrollTop))
	{
		windowWidth = newWidth;
		windowHeight = newHeight;
		contentScrollTop = newScroll;
		windowSizeChanged = true;
	}
	
}

function createDiv(id,className)
{
	var dv = document.createElement('div');
	dv.setAttribute('id',id);
	dv.className = className;
	
	return dv;
}


var popupLabel=null;
var popupLabelShadow;
var popupContent;
var popupContentShadowRight;
var popupContentShadowBottom;
var popupContentShadowBottomRight;
var popupTabs;
var popupClose;
var popupHelp;

function initiatePopupVariables()
{
	if (popupLabel==null)
	{
		popupLabel = document.getElementById('popupLabel');
		popupLabelShadow = document.getElementById('popupLabelShadow');
		popupContent = document.getElementById('popupContent');
		popupContentShadowRight = document.getElementById('popupContentShadowRight');
		popupContentShadowBottom = document.getElementById('popupContentShadowBottom');
		popupContentShadowBottomRight = document.getElementById('popupContentShadowBottomRight');
		popupTabs = document.getElementById('popupTabs');
		popupClose = document.getElementById('popupClose');
		popupHelp = document.getElementById('popupHelp');
	}
}
function showPopup(x,y,w,h,helpFunction,closeFunction)
{
	return fn.popup.show(x,y,w,h,helpFunction,closeFunction);
	
	/*
	initiatePopupVariables();

	x = parseInt(x);
	y = parseInt(y);
	w = parseInt(w);
	h = parseInt(h);
	
	pageTrans.style.display = 'block';

	objMoveTo('popupContent',x,y,w,h);
	objMoveTo('popupContentShadowBottom',x+8,y+h+4,w-4,3);
	objMoveTo('popupContentShadowRight',x+w+4,y+8,3,h-4);
	objMoveTo('popupContentShadowBottomRight',x+w+4,y+h+4,3,3);
	
	objMoveTo('popupClose',x+w-43,y+8);
	objMoveTo('popupHelp',x+w-81,y+8);
	
	popupContent.innerHTML = '';
	
	popupContent.style.display = 'block';
	//popupContentShadowBottom.style.display = 'block';
	//popupContentShadowRight.style.display = 'block';
	//popupContentShadowBottomRight.style.display = 'block';
	if (closeFunction)
		popupClose.onclick = closeFunction;
	popupClose.style.display = 'block';
	if (helpFunction)
		popupHelp.onclick = helpFunction;
	popupHelp.style.display = 'block';
*/	
}

function showCalloutPopup(objID,offsetY,w,h,hasTitle)
{
	initiatePopupVariables();

	pageTrans.style.display = 'block';
	
	objMoveRelTo('popupLabel',objID,-5,-5,false);
	objMoveRelTo('popupLabelShadow',objID,4,31,false);

	objMoveRelTo('popupContent',objID,136,offsetY,false,w,h);
	objMoveRelTo('popupContentShadowBottom',objID,146,offsetY+h+4,false,w-6,3);
	objMoveRelTo('popupContentShadowRight',objID,136+w+4,offsetY+8,false,3,h-4);
	objMoveRelTo('popupContentShadowBottomRight',objID,136+w+4,offsetY+h+4,false,3,3);
	objMoveRelTo('popupTabs',objID,136+w-293,offsetY+h+2,false);
	objMoveRelTo('popupClose',objID,136+w-43,offsetY+10,false);
	objMoveRelTo('popupHelp',objID,136+w-81,offsetY+10,false);
	
	popupLabel.innerHTML = document.getElementById(objID).innerHTML;
	popupContent.innerHTML = '';
	
	popupLabel.style.display = 'block';
	popupLabelShadow.style.display = 'block';
	popupContent.style.display = 'block';
	popupContentShadowBottom.style.display = 'block';
	popupContentShadowRight.style.display = 'block';
	popupContentShadowBottomRight.style.display = 'block';
	popupClose.style.display = 'block';
	popupHelp.style.display = 'block';
}
function hidePopup()
{
	popupClose.onclick = function(){};
	popupHelp.onclick = function(){};
	
	popupContent.innerHTML = '&nbsp;';
	popupClose.style.display = 'none';
	popupHelp.style.display = 'none';
	popupContentShadowBottomRight.style.display = 'none';
	popupContentShadowRight.style.display = 'none';
	popupContentShadowBottom.style.display = 'none';
	popupContent.style.display = 'none';
	popupLabelShadow.style.display = 'none';
	popupLabel.style.display = 'none';
	pageTrans.style.display = 'none';
	displayTabContent('#F1F1C7');
	fn.resize.remove('popup');
}

function setPopupBackgroundColor(color)
{
	popupContent.style.backgroundColor = color;
	popupLabel.style.backgroundColor = color;
}

//AJAX called functions on each page
function displayPopupContent(defaultField)
{
	document.getElementById('popupContent').innerHTML = aRecord[1];
	if (defaultField)
		setTimeout('document.getElementById(\''+defaultField+'\').select();document.getElementById(\''+defaultField+'\').focus()',100);
}
//Functions to deal with popup tabs
function displayTabContent(color)
{
	setPopupBackgroundColor(color);
	if (aRecord)
	{
		document.getElementById('popupContent').innerHTML = aRecord[1];
		document.getElementById('popupTabs').innerHTML = aRecord[2];
	}
}
var helpButtonsDark = new Array();
var helpInfoDark = new Array();
var helpButtonsLight = new Array();
var helpInfoLight = new Array();
var bShowingButtons = false;
function fadeInHelpButtons(rootName)
{
	if (bShowingButtons)
	{
		for (var i=1;i<helpButtonsDark.length;i++)
		{
			helpButtonsDark[i].innerHTML = '<img src="images/helpfade_dark.gif" width="26" height="26" />';
			setTimeout('helpButtonsDark['+i+'].style.display="none"',1500);
		}
		for (var i=1;i<helpButtonsLight.length;i++)
		{
			helpButtonsLight[i].innerHTML = '<img src="images/helpfade_light.gif" width="26" height="26" />';
			setTimeout('helpButtonsLight['+i+'].style.display="none"',1500);
		}
		bShowingButtons = false;
	}
	else
	{
		helpButtons = new Array();
		var i = 1;
		currentOpacity = 0;
		
		while (document.getElementById(rootName+'Dark'+i)!=null)
		{
			helpButtonsDark[i]= document.getElementById(rootName+'Dark'+i);
			helpInfoDark[i] = document.getElementById(rootName+'DarkInfo'+i).innerHTML;
			helpButtonsDark[i].style.display = 'block';
			helpButtonsDark[i].innerHTML = '<img src="images/helppulse_dark.gif" width="26" height="26" />';
			i++;
		}
		i = 1;
		while (document.getElementById(rootName+'Light'+i)!=null)
		{
			helpButtonsLight[i]= document.getElementById(rootName+'Light'+i);
			helpInfoLight[i] = document.getElementById(rootName+'LightInfo'+i).innerHTML;
			helpButtonsLight[i].style.display = 'block';
			helpButtonsLight[i].innerHTML = '<img src="images/helppulse_light.gif" width="26" height="26" />';
			i++;
		}		
		if (i>1)
		{
			bShowingButtons = true;
			setTimeout('replaceHelpButtons()',1300);
		}
	}
}
function replaceHelpButtons()
{
	var hlp;
	for (var i=1;i<helpButtonsDark.length;i++)
	{
		hlp = helpInfoDark[i].split('|');
		helpButtonsDark[i].innerHTML = '<a href="#" class="helppulse_dark" onmouseover="showHelp(\''+hlp[0]+'\','+hlp[9]+','+hlp[1]+','+hlp[2]+','+hlp[3]+','+hlp[4]+','+hlp[5]+','+hlp[6]+','+hlp[7]+','+hlp[8]+')">&nbsp;</a>';
	}
	for (var i=1;i<helpButtonsLight.length;i++)
	{
		hlp = helpInfoLight[i].split('|');	
		helpButtonsLight[i].innerHTML = '<a href="#" class="helppulse_light" onmouseover="showHelp(\''+hlp[0]+'\','+hlp[9]+','+hlp[1]+','+hlp[2]+','+hlp[3]+','+hlp[4]+','+hlp[5]+','+hlp[6]+','+hlp[7]+','+hlp[8]+')">&nbsp;</a>';
	}
}

var maskVisible = false;
function showHelp(objID, helpID, incLeft, incTop, incRight, incBottom,textOffsetLeft,textOffsetTop,textWidth, textHeight)
{
	var xywh = getXYWH(document.getElementById(objID));
	var x = xywh.x-7-incLeft;
	var y = xywh.y-7-incTop;
	var w = xywh.w+14+incRight;
	var h = xywh.h+14+incBottom;

	if (x<0) x=1;
	if (x+w>=windowWidth) w=(windowWidth-x)-2;
	if (y<0) y=1;
	if (y+h>=windowHeight) h=(windowHeight-y)-2;

	objMoveTo('maskTop',0,0,windowWidth,y);
	objMoveTo('maskRight',x+w,y,windowWidth-(x+w),h);
	objMoveTo('maskBottom',0,y+h,windowWidth,windowHeight-(y+h));
	objMoveTo('maskLeft',0,y,x,h);
	objMoveTo('maskHole',x-2,y-2,w,h);
	objMoveTo('maskEdge',x-2,y-2,w,h);
	
	if ((x+textOffsetLeft+textWidth)>windowWidth)
		textOffsetLeft -= ((x+textOffsetLeft+textWidth)-windowWidth+10);
	if ((y+textOffsetTop+textHeight)>windowHeight)
		textOffsetTop -= ((y+textOffsetTop+textHeight)-windowHeight+10);
	if (x+textOffsetLeft<0)
		textOffsetLeft = -x;
	if (y+textOffsetTop<0)
		textOffsetTop = -y;

	objMoveTo('helpText',x+textOffsetLeft,y+textOffsetTop,textWidth,textHeight);

	document.getElementById('maskTop').style.display = 'block';
	document.getElementById('maskRight').style.display = 'block';
	document.getElementById('maskBottom').style.display = 'block';
	document.getElementById('maskLeft').style.display = 'block';
	document.getElementById('maskEdge').style.display = 'block';
	document.getElementById('maskHole').style.display = 'block';
	document.getElementById('helpText').style.display = 'block';

	document.getElementById('helpText').innerHTML = 'Loading ...';
	ajaxRequest('ajax/general/HelpText.asp?id='+helpID);
	animateOpacity('helpText',0,100,50,5);
	
	maskVisible = true;
}
function displayHelpText()
{
	document.getElementById('helpText').innerHTML = aRecord[1];
}
function hideHelp()
{
	document.getElementById('maskTop').style.display = 'none';
	document.getElementById('maskRight').style.display = 'none';
	document.getElementById('maskBottom').style.display = 'none';
	document.getElementById('maskLeft').style.display = 'none';
	document.getElementById('maskEdge').style.display = 'none';
	document.getElementById('maskHole').style.display = 'none';
	document.getElementById('helpText').style.display = 'none';
	document.getElementById('helpText').innerHTML = '';
	setOpacity('helpText',0);
	maskVisible = false;
}
function setOpacity(objID,value) 
{
	document.getElementById(objID).style.opacity = value/100;
	document.getElementById(objID).style.filter = 'alpha(opacity=' + value + ')';
}

function animateOpacity(objID,value,target,stepSize,delay)
{
	var diff = Math.abs(value-target);
	if (diff<Math.abs(stepSize))
		value = target;
	else
		value += stepSize;
	setOpacity(objID,value);
	
	if (value!=target)
		setTimeout('animateOpacity(\''+objID+'\','+value+','+target+','+stepSize+')',delay);
}
function copyToClipboard(text)
{
	document.getElementById('holdtext').innerText = text;
	var Copied = document.getElementById('holdtext').createTextRange();
	Copied.execCommand("Copy");
}
function getDivsByClassName(className) 
{
	var obj = Array();
	var divs = document.getElementsByTagName('div');
	
	for (i=0;i<divs.length; i++) {
		if (divs[i].className == className)
			obj[obj.length] = divs[i];
	}
	return obj;
}
// Show the debug window
function showDebug() {
  window.top.debugWindow =
      window.open("",
                  "Debug",
                  "left=0,top=0,width=400,height=600,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  window.top.debugWindow.opener = self;
  // open the document for writing
  window.top.debugWindow.document.open();
  window.top.debugWindow.document.write(
      "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");
}
// If the debug window exists, then write to it
function debug(text) {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.document.write(new Date().toString()+': '+text+"\n");
  }
}
// If the debug window exists, then close it
function hideDebug() {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.close();
    window.top.debugWindow = null;
  }
}

function updateUserDetailsSettings()
{
	fetchPage('','ajax/users/userCheck.asp','noChange=yes');
				alert('Details Confirmed!');
	fn.popup.hide();
}

function checkPasswordValid(what,who)
{
	var returnValue = 'yes';
	var errorText = '';
	if (document.getElementById('oldPass').value=='')
	{
		errorText+='Please enter an old password\n';
		returnValue = 'no';
	}
	if (document.getElementById('oldPass').value==document.getElementById('newPass1').value)
	{
		errorText+='Your old password and new password cannot be the same\n';
		returnValue = 'no';
	}
	if (document.getElementById('newPass1').value=='')
	{
		errorText+='Please enter a new password\n';
		returnValue = 'no';
	}
	if (document.getElementById('newPass2').value=='')
	{
		errorText+='Please retype your new password\n';
		returnValue = 'no';
	}
	if (document.getElementById('newPass2').value!=document.getElementById('newPass1').value)
	{
		errorText+='Your new passwords must match\n';
		returnValue = 'no';	
	}
	if ((document.getElementById('newPass1').value.length)<5)
	{
		errorText += 'Your password must be at least 5 characters long.\n';
		returnValue = 'no';
	}
	re = /[0-9]/;
	if(!re.test(document.getElementById('newPass1').value))
	{
		errorText += 'Your password must contain at least one number.\n';
		returnValue = 'no';
	}
	re = /[a-z]/;
	if(!re.test(document.getElementById('newPass1').value))
	{
		errorText += 'Your password must contain at least one character.\n';
		returnValue = 'no';
	}
	if (document.getElementById('secQuestion'))
	{
		if (document.getElementById('secQuestion').value=='0')
		{
			errorText+='Please choose a security question\n';
			returnValue = 'no';	
		}
		if (document.getElementById('secAnswer').value=='')
		{
			errorText+='Please enter a security answer\n';
			returnValue = 'no';	
		}		
	}
	
	fetchPage('','ajax/users/checkCurrentPassword.asp',null,function(password){
		if (password!=document.getElementById('oldPass').value)
		{
			errorText+='The old password you entered is not correct\n';
			returnValue = 'no';	
		}
		if (returnValue=='yes')
		{
			if (what=='True')
			{
				fetchPage('','ajax/users/changePassword.asp','old='+document.getElementById('oldPass').value+'&newPass1='+document.getElementById('newPass1').value+'&newPass2='+document.getElementById('newPass2').value);
				alert('Password changed!');
			} else {
				fetchPage('','ajax/users/changePassword.asp','old='+document.getElementById('oldPass').value+'&newPass1='+document.getElementById('newPass1').value+'&newPass2='+document.getElementById('newPass2').value+'&secQuestion='+document.getElementById('secQuestion').value+'&secAnswer='+document.getElementById('secAnswer').value+'&secAdded=yes');
				alert('Password and security details changed!');
			}
			fn.popup.hide();
		} else {
		alert(errorText);
		}
					
	});						
}


function show(id,clear)
{
	if (clear)
		document.getElementById(id).innerHTML = '';
	document.getElementById(id).style.display='block';
}
function hide(id,clear)
{
	document.getElementById(id).style.display='none';
	if (clear)
		document.getElementById(id).innerHTML = '';
}
function expandCollapse(divID)
{
	var obj = document.getElementById(sCurrentDataArea+nCurrentTab+divID+'EC');
	obj.className = (obj.className=='collapseItem'?'expandItem':'collapseItem');
	document.getElementById(sCurrentDataArea+nCurrentTab+divID).style.display = (obj.className=='collapseItem'?'block':'none');
}
/*
function copyToClipboard(value)
{
	clipboardData.setData("Text",value);
}

function dragBrowser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new dragBrowser();

// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else 
  {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }
  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;
  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;
  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}
 
function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
    // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left =
    (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  =
    (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();

}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;	
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
    event.preventDefault();	
  }
}

*/
function setFocusTo(id)
{
	var obj = document.getElementById(id);
	obj.focus();
}

/*
	fn.el
			get
			insertAfter
			
	fn.text
			clear
			add
			concat
			
	fn.timing
			clear
			startTiming
			stopTiming
			report
			
	fn.resize
			add
			remove
			doResize
			
	fn.script
			isLoaded
			loadScript
			
	fn.style
			isLoaded
			loadStyle
			
*/
var fn = {
	style: {
		set: function(id,style,value) {
			fn.el.get(id).style[style] = value;
		}
	},
	el: {
		get: function(id) {
			return document.getElementById(id);
		},
		value: function(id) {
			var o = fn.el.get(id);
			if (o.nodeName=='SELECT')
				return o.options[o.selectedIndex].value;
			else
				return '';
		},
		xywh: function(id) {
			return getXYWH(fn.el.get(id));
		},
		insertAfter: function(newNode, oldNode) {
			oldNode.parentNode.insertBefore(newNode, oldNode.nextSibling);
		},
		setFocus: function(id) {
			fn.el.get(id).focus();
		},
		create: function(type,defaultClass,defaultStyle,defaultID) {
			var obj = document.createElement(type);
			if (defaultClass)
				obj.className = defaultClass;
			if (defaultStyle)
				obj.style.cssText = defaultStyle;
			if (defaultID)
				obj.id = defaultID;
			return obj;
		}
	},
	popup: {
		zIndex: 5000,
		transLayers: new Array(),
		getID: function() {
			return 'container'+this.zIndex;
		},
		getContentID: function(contentID) {
			var parentID = contentID.substr(9,20);
			return fn.el.get('popupContent'+parentID);
		},
		show: function(x,y,w,h,helpFunction,closeFunction,hideHelpButton,hideCloseButton) {
			this.zIndex += 5;
			
			document.body.appendChild(fn.el.create('iframe','hiddenIFrame','width:100%;height:'+windowHeight+'px;','iframe'+this.zIndex));
			document.body.appendChild(fn.el.create('div','trans3','z-index:'+this.zIndex+';width:100%;height:'+windowHeight+'px;position:absolute;left:0px;top:0px;right:0px;bottom:0px;background:#777;','trans'+this.zIndex));
			this.transLayers['trans'+this.zIndex] = this.zIndex; // = fn.el.get('trans'+this.zIndex);
			
			fn.resize.add('trans', function() {
				var obj;
				for (var transID in fn.popup.transLayers) {
					obj = fn.el.get(transID);
					obj.style.height = windowHeight+'px';
				}
			});
			
			var container = fn.el.create('div','','position:absolute;z-index:'+(this.zIndex+1)+';left:'+x+'px;top:'+y+'px;width:'+(w+4)+'px;height:'+(h+7)+'px;','container'+this.zIndex);
			
			var shadowRight = fn.el.create('div','popupShadowRight');
			shadowRight.appendChild(fn.el.create('div','shadowRight trans4'));
			shadowRight.appendChild(fn.el.create('div','shadowRight trans6'));
			shadowRight.appendChild(fn.el.create('div','shadowRight trans8'));
			container.appendChild(shadowRight);

			var shadowBottom = fn.el.create('div','popupShadowBottom');
			shadowBottom.appendChild(fn.el.create('div','shadowBottom trans4'));
			shadowBottom.appendChild(fn.el.create('div','shadowBottom trans6'));
			shadowBottom.appendChild(fn.el.create('div','shadowBottom trans8'));
			container.appendChild(shadowBottom);

			container.appendChild(fn.el.create('div','popupShadowBottomRight'));
			container.appendChild(fn.el.create('div','popupContent','height:'+h+'px;width:'+(w-3)+'px','popupContent'+this.zIndex));
			
			if (!hideCloseButton) {
				var closeButton = fn.el.create('a','popupClose','','popupClose'+this.zIndex);
				closeButton.setAttribute('href','#');
				closeButton.setAttribute('title','Close this popup');
				container.appendChild(closeButton);
			}

			if (!hideHelpButton) {
				var helpButton = fn.el.create('a','popupHelp','','popupHelp'+this.zIndex);
				helpButton.setAttribute('href','#');
				helpButton.setAttribute('title','Show help for this popup');
				container.appendChild(helpButton);
			}
			
			document.body.appendChild(container);

			if (!hideCloseButton) {
				fn.el.get('popupClose'+this.zIndex).onclick = function() {
					if (closeFunction) {
						closeFunction();
					}
					fn.popup.hide();
					return false;
				};				
			}
			
			if (!hideHelpButton) {
				fn.el.get('popupHelp'+this.zIndex).onclick = function() {
					fn.help.show();
					if (helpFunction)
						helpFunction();
					return false;
				};				
			}
			//fn.el.get('popupContent'+this.zIndex).innerHTML = '<a href="#" onclick="showPopup('+(x+20)+','+(y+20)+',650,200,null,function(){alert(1);});return false">do another popup</a><br/><br/><a href="#" onclick="fn.popup.hide();return false">hide popup</a>';
			
			return {id:'container'+this.zIndex,contentID:'popupContent'+this.zIndex};
		},
		hide: function() {
			if (this.zIndex>5000) {
				delete this.transLayers['trans'+this.zIndex];
				document.body.removeChild(fn.el.get('container'+this.zIndex));
				document.body.removeChild(fn.el.get('trans'+this.zIndex));
				document.body.removeChild(fn.el.get('iframe'+this.zIndex));
				this.zIndex -= 5;
			}
		}
	},
	help: {
		contextID: 0,
		backup: {
			IDs: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
			position: -1
		},
		helpPopup: null,
		setContextID: function(id) {
			if (this.contextID!=0) {
				this.backup.position++;
				this.backup.IDs[this.backup.position] = this.contextID;
			}
			this.contextID = id;
		},
		show: function(id) {
			var helpID = this.contextID;
			
			if (id!==undefined)
				helpID = id;
				
			if (helpID!=0) {
				if (this.helpPopup==null) {
					this.helpPopup = fn.popup.show((windowWidth-600)/2,(windowHeight-550)/2,600,608,null,
						function() {
							fn.help.closeHelp();
						},
						true
					);
				}
				fetchPage(this.helpPopup.contentID,'ajax/help/getHelp.asp','id='+helpID);	
				fn.resize.add('help', function() {
					fn.el.get(fn.help.helpPopup).style.left = ((windowWidth-600)/2)+'px';
					fn.el.get(fn.help.helpPopup).style.top = ((windowHeight-550)/2)+'px';
				});				
			}
		},
		closeHelp: function() {
			//this.contextID = this.backup.IDs[this.backup.position];
			//this.backup.position--;
			fn.resize.remove('help');
			fn.help.helpPopup = null;
		},
		jumpTo: function(id) {
		}
	},
	text: {
		aText: new Array(),
		clear: function() {
			this.aText = new Array();
		},
		add: function(txt) {
			this.aText.push(txt);
		},
		concat: function(sep) {
			return this.aText.join(sep);
		}
	},
	clipboard: {
		copy: function(value) {
			clipboardData.setData("Text",value);
		}
	},
	timing: {
		aTimers: new Object(),
		clear: function() {
			this.aTimers = new Object();
			this.aTimers['__Report__'] = 'Timing Report .....\n';
		},
		startTiming: function(name) {
			this.aTimers[name] = {
				startTime:new Date(),
				stopTime:null,
				difference:null
			}
		},
		stopTiming: function(name) {
			this.aTimers[name].stopTime = new Date();
			this.aTimers[name].difference = (this.aTimers[name].stopTime - this.aTimers[name].startTime);
			if (!this.aTimers['__Report__'])
				this.aTimers['__Report__'] = 'Timing Report .....\n';
			
			this.aTimers['__Report__'] += '\n'+name+': '+this.aTimers[name].difference+'ms';
		},
		insert: function(title,value) {
			this.aTimers['__Report__'] += '\n'+title+': '+value;
		},
		report: function() {
			return this.aTimers['__Report__'];
		}
	},
	resize: {
		aBits: new Array(),
		add: function(id,fn) {
			this.aBits[id] = fn;
		},
		remove: function(id) {
			delete this.aBits[id];
		},
		doResize: function() {
			for (var fn in this.aBits)
				if (this.aBits[fn])
					this.aBits[fn]();
		}
	},
	tmp: {
		aVars: new Array(),
		set: function(key,value) {
			fn.tmp.aVars[key] = value;
		},
		get: function(key) {
			return fn.tmp.aVars[key];
		}
	},
	flash: {
		show: function(url,width,height) {
			var newDiv = document.createElement('div');
			newDiv.id = 'helpContainer';
			newDiv.style.width = width+'px';
			newDiv.style.height = height+'px';
			fn.el.insertAfter(newDiv,fn.el.get('percentageBar'));
			
			var s1 = new SWFObject('includes/jw_media_player/mediaplayer.swf','single',width,height,'7');
//			s1.addParam("allowfullscreen","true");
			s1.addVariable('file',url);
			s1.addVariable('width',width);
			s1.addVariable('height',height);
			s1.write('helpContainer');			
		}
	},
	script: {
		isLoaded: function(filePath)
		{
			var oScriptObjs = document.getElementsByTagName('script');
			for (var i = 0;i < oScriptObjs.length;i++)
			{
				if (oScriptObjs[i].src)
				{
					if (oScriptObjs[i].src.indexOf(filePath) != -1)
						return oScriptObjs[i];
				}
			}
			
			return false;
		},
		loadScript: function(filePath,onScriptLoad)
		{
			if (!this.isLoaded(filePath))
			{
				var oNewScript = document.createElement('script');
				oNewScript.type = 'text/javascript';
				if (typeof(onScriptLoad)=='function')
				{
					oNewScript.onload = onScriptLoad;
					
					//this next part is needed for IE
					oNewScript.onreadystatechange = function() {
						if (this.readyState == 'loaded') {
							onScriptLoad();			 
						}
					}					
				}
				oNewScript.src = filePath;
				document.getElementsByTagName('head')[0].appendChild(oNewScript);
			}
			else
			{
				if (typeof(onScriptLoad)=='function')
					onScriptLoad();
			}			
		}		
	},
	style: {
		isLoaded: function(filePath)
		{
			var oCSSObjs = document.getElementsByTagName('link');
			for (var i = 0;i < oCSSObjs.length;i++)
			{
				if (oCSSObjs[i].href)
				{
					if (oCSSObjs[i].href.indexOf(filePath) != -1)
						return oCSSObjs[i];
				}
			}
			
			return false;
		},
		loadStyle: function(filePath,onCSSLoad)
		{
			if (!this.isLoaded(filePath))
			{
				var oNewCSS = document.createElement('link')
				oNewCSS.type = 'text/css';
				oNewCSS.rel = 'stylesheet';
				oNewCSS.href = filePath;
				
				if (typeof(onCSSLoad)=='function') {
					oNewCSS.onload = onCSSLoad;
					
					//this next part is needed for IE
					oNewCSS.onreadystatechange = function() {
						if (this.readyState == 'loaded') {					 
							onScriptLoad();			 
						}
					}					
				}
				
				document.getElementsByTagName('head')[0].appendChild(oNewCSS);
			}
			else
			{
				if (typeof(onCSSLoad)=='function')
					onCSSLoad();
			}
		}		
	}
	
};

