//-----------------------------------------------------------------------------------------------------------------------------------------------
// settings
//-----------------------------------------------------------------------------------------------------------------------------------------------
var enableNoRightClick = false; // enable no right-clicking


//-----------------------------------------------------------------------------------------------------------------------------------------------
// limits text in a text box
//-----------------------------------------------------------------------------------------------------------------------------------------------
function setClassName(objItem, newName)
{
	try
	{
		objItem.className = newName;
	}
	catch (e) {}
}


//-----------------------------------------------------------------------------------------------------------------------------------------------
// limits text in a text box
//-----------------------------------------------------------------------------------------------------------------------------------------------
function limitText(textBox, divName, maxLength, isLoad)
{
	if (textBox.value.length > maxLength)
		textBox.value = textBox.value.substring(0, maxLength);
	
	try
	{
		var objDiv = MM_findObj(divName);
		var charsLeft = maxLength - textBox.value.length;
		objDiv.innerHTML = charsLeft.toString() + " characters left";
		try
		{
			if (charsLeft == maxLength) {
				objDiv.style.display = "none";
			} else if (objDiv.style.display != "block") {
				objDiv.style.display = "block";
			}
		}
		catch (e2) {}
	}
	catch (e) {}			
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
// maximises a window
//-----------------------------------------------------------------------------------------------------------------------------------------------
function maximiseWindow(winRef) {
  if (window.screen) {
    winRef.moveTo(0,0);
    winRef.outerHeight = screen.availHeight;
    winRef.outerWidth = screen.availWidth;
  }
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
// alters a window
//-----------------------------------------------------------------------------------------------------------------------------------------------
function alterWindow(winRef) {
  maximiseWindow(winRef);
  winRef.focus();
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
// set dropdown value
//-----------------------------------------------------------------------------------------------------------------------------------------------
function setDropDownValue(objDropdownList, strValue)
{
	for (var i = 0; i < objDropdownList.options.length; i++)
		if (objDropdownList.options[i].selected)
			objDropdownList.options[i].selected = false;
	for (var i = 0; i < objDropdownList.options.length; i++)
		if (objDropdownList.options[i].value.toLowerCase().trim() == strValue.toLowerCase().trim())
			objDropdownList.options[i].selected = true;
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
// standard MM functions
//-----------------------------------------------------------------------------------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
// handles no right-click functionality
//-----------------------------------------------------------------------------------------------------------------------------------------------
function clickIE4(){
	if (event.button==2){
		return false;
	}
}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			return false;
		}
	}
}

// check if must enable no right click
if (enableNoRightClick)
{
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	document.oncontextmenu=new Function("return false");
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// validates an integer
//-----------------------------------------------------------------------------------------------------------------------------------------------
function isValidInt(txtValue, requiresG0, canBe0)
{
	try
	{
		var testExp = /\d/g
		if (!requiresG0)
			testExp = /^-|\d/g
		var matchArray = txtValue.trim().match(testExp);
		if (matchArray == null)
			return false;
		if (matchArray.length != txtValue.trim().length)
			return false;
		if (canBe0 && requiresG0)
		{
			if (parseInt(txtValue.trim()) < 0)
				return false;
		}
		else if (requiresG0)
		{
			if (parseInt(txtValue.trim()) <= 0)
				return false;
		}
		if (isFinite(txtValue.trim()))
			return true;
	}
	catch (e) {}
	return false;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// validates a decimal
//-----------------------------------------------------------------------------------------------------------------------------------------------
function isValidDecimal(txtValue, requiresG0, canBe0)
{
	try
	{
		var testExp = /\d|./g
		var matchArray = txtValue.trim().match(testExp);
		if (matchArray == null)
			return false;
		if (matchArray.length != txtValue.trim().length)
			return false;
		if (canBe0 && requiresG0)
		{
			if (parseFloat(txtValue.trim()) < 0)
				return false;
		}
		else if (requiresG0)
		{
			if (parseFloat(txtValue.trim()) <= 0)
				return false;
		}
		if (isFinite(txtValue.trim()))
			return true;
	}
	catch (e) {}
	return false;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// expands / collapses multiple object
//-----------------------------------------------------------------------------------------------------------------------------------------------
function multipleExpandCollapse(objNamePrefix, imgNamePrefix, itemCount, imgSrcExtension)
{
	for (var i = 0; i < itemCount; i++)
	{
		expandCollapse(objNamePrefix + i.toString(), imgNamePrefix + i.toString(), imgSrcExtension);
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// expands / collapses object
//-----------------------------------------------------------------------------------------------------------------------------------------------
function expandCollapse(objName, imgName, imgSrcExtension)
{
	// check if visible
	if (objectVisible(objName))
	{
		if (imgName != "" && collapsePlus != undefined && collapsePlus != "")
		{
			var imageSrc = collapsePlus;
			if (imgSrcExtension == undefined || imgSrcExtension == null)
				imgSrcExtension = "";
			imageSrc = imageSrc.replace("##X", imgSrcExtension);
			changeImage(imgName, imageSrc);
		}
		showHideObject(objName, false);
	}
	else
	{
		if (imgName != "" && collapseMinus != undefined && collapseMinus != "")
		{
			var imageSrc = collapseMinus;
			if (imgSrcExtension == undefined || imgSrcExtension == null)
				imgSrcExtension = "";
			imageSrc = imageSrc.replace("##X", imgSrcExtension);
			changeImage(imgName, imageSrc);
		}
		showHideObject(objName, true);
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// changes image source
//-----------------------------------------------------------------------------------------------------------------------------------------------
function changeImage(objName, imageSource)
{
	try
	{
		if (document.images[objName].src != imageSource)
			document.images[objName].src = imageSource;
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// changes object text
//-----------------------------------------------------------------------------------------------------------------------------------------------
function changeText(objName, objText)
{
	try { MM_findObj(objName).innerText = objText; }
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// object visible
//-----------------------------------------------------------------------------------------------------------------------------------------------
function objectVisible(objectName)
{
	try { return (MM_findObj(objectName).style.display == "block"); }
	catch (e) {}
	try { return (MM_findObj(objectName).style.visibility == "visible"); }
	catch (e) {}
	return false;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// show / hide object text
//-----------------------------------------------------------------------------------------------------------------------------------------------
function showHideObject(objectName, showItem)
{
	try { MM_findObj(objectName).style.visibility = (showItem) ? "visible" : "hidden"; }
	catch (e) {}
	try { MM_findObj(objectName).style.display = (showItem) ? "block" : "none"; }
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// opens the processing window
//-----------------------------------------------------------------------------------------------------------------------------------------------
function OpenProcessingWindow(sUrl)
{
	try { document.body.style.cursor = 'wait'; }
	catch (e) {}
	try
	{
		var windowW = 202;
		var windowH = 101;
		var windowX = parseInt(screen.width / 2.0) - (202 / 2.0);
		var windowY = parseInt(screen.height / 2.0) - (101 / 2.0);
		var processingWindow = window.open(sUrl, "saProcessingWindow", "top=" + windowY + ",left=" + windowX + ",y=" + windowY + ",x=" + windowX + "," +
			"scrollbars=no,dialog=no,minimizable=no,modal=no,width=" + windowW + ",height=" + windowH + ",resizable=no");
		processingWindow.moveTo(windowX, windowY);
		processingWindow.focus();
		SetProcessingCookie();
	}
	catch (e) {}
	try
	{
		for (var i=0;i<document.anchors.length;i++)
		{
			try { document.anchors[i].style.cursor = "wait"; }
			catch (e2) {}
		}
		for (var i=0;i<document.links.length;i++)
		{
			try { document.links[i].style.cursor = "wait"; }
			catch (e2) {}
		}
		for (var i=0;i<document.forms.length;i++)
			for (var k=0; k < document.forms[i].elements.length; k++)
			{
				try { document.forms[i].elements[k].style.cursor="wait"; }
				catch (e2) {}
				try { document.forms[i].elements[k].readOnly = true; }
				catch (e2) {}
			}
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// closes the processing window
//-----------------------------------------------------------------------------------------------------------------------------------------------
function CloseProcessingWindow()
{
	try
	{
		if (getCookie("sa_RequestInProgress") == "1")
		{
			try
			{
				var processingWindow = window.open('','saProcessingWindow');
				processingWindow.close();
			}
			catch (e2) {}
			ResetProcessingCookie();
			try { window.focus(); }
			catch (e2) {}
		}
	}
	catch (e) {}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// sets / resets the processing cookie
//-----------------------------------------------------------------------------------------------------------------------------------------------
function SetProcessingCookie()
{
	document.cookie='sa_RequestInProgress=1;path=/';
}
function ResetProcessingCookie()
{
	document.cookie='sa_RequestInProgress=0;path=/';
}
function getCookie(name)
{
	try
	{
		var start = document.cookie.indexOf(name + "=");
		var len=start + name.length + 1;
		if ((!start)&&(name != document.cookie.substring(0,name.length)))
			return null;
		if (start == -1)
			return null;
		var end=document.cookie.indexOf(";",len);
		if (end==-1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}
	catch (e) { return e.Message; }
}
function delCookie(name)
{
	var expireNow = new Date();
	document.cookie=name + "=" + "; expires=" + expireNow.toLocaleTimeString() + "; path=/";
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// extends string object
//-----------------------------------------------------------------------------------------------------------------------------------------------
String.prototype.trim = function() {
	// trim values
	var returnString = this;
	returnString = returnString.replace(/^\s*(.*)/gim, "$1");
	returnString = returnString.replace(/(.*?)\s*$/gim, "$1");
	return returnString;
}
