
	var g_iTicketHeight = 650
	var g_iTicketWidth = 790
	var nScaleFactor = (screen.deviceXDPI / 96);
	var sDefaultStyleSheet = "common.css";
	var sBigDPIStyleSheet = "commonBigDPI.css";

	String.prototype.trim = doTrim;
	String.prototype.lTrim = doLTrim;
	String.prototype.rTrim = doRTrim;
	String.prototype.replaceAll = doReplaceAll;
	function doLTrim()	{ return this.replace(/^\s*/, ''); }
	function doRTrim()	{ return this.replace(/\s*$/, ''); }
	function doTrim()	{ return this.lTrim().rTrim(); }
	function doReplaceAll(sToBeReplaced, sReplaceValue) { return this.split(sToBeReplaced).join(sReplaceValue); }


	function resizeDisplayTable(sTableID) {
		var oTable = document.all(sTableID);
		var iTableWidth = oTable.width.replace(/%/g, '');
		iTableWidth = parseInt(iTableWidth) * nScaleFactor;
		var sTableWidth = formatNumberForDisplay(iTableWidth.toString(), 0) + '%';
		oTable.width = sTableWidth;
	}

	function checkDPI(sRelativePath) {
		if(nScaleFactor != 1)
		{
			sDefaultStyleSheet = sRelativePath + sDefaultStyleSheet;
			sBigDPIStyleSheet = sRelativePath + sBigDPIStyleSheet;
//			alert(sDefaultStyleSheet);
//			alert(sBigDPIStyleSheet);
			var i;
			for(i = 0; i < document.styleSheets.length; i++)
			{
//				alert(document.styleSheets(i).href);
				if(document.styleSheets(i).href == sDefaultStyleSheet) {break;}
			}
			
			if(nScaleFactor > 1)
			{
				document.styleSheets(i).href = sBigDPIStyleSheet;
			}
		}
	}

	function parseValue( sValue ) {
		// this function attempts to parse a numeric value from the supplied string
		// if an error occurs or no number is present, it returns 0
		try {
			sValue = sValue.toString().replace( /\$|\,/g, "" );
			var dTemp = parseFloat( sValue );
			if ( isNaN( dTemp ) ) {
				return 0;
			} else {
				return dTemp;
			}
		} catch( e ) {
			return 0;
		}
	}
	
	function formatCurrency( num ) {
		// this function formats the supplied number as currency
		num = num.toString().replace( /\$|\,/g, "" );
		if( isNaN( num ) ) {
			num = "0";
		}
		sign = ( num == ( num = Math.abs( num ) ) );
		num = Math.floor( num * 100 + 0.50000000001 );
		cents = num % 100;
		num = Math.floor( num / 100 ).toString();
		if ( cents < 10 )
			cents = "0" + cents;
		for ( var i = 0; i < Math.floor( ( num.length - ( 1 + i ) ) / 3 ); i++ )
		num = num.substring( 0, num.length - ( 4 * i + 3 ) ) + "," + num.substring( num.length - ( 4 * i + 3 ) );
		return ( ( ( sign ) ? '' : '-' ) + num + '.' + cents );
	}
	
	function expandRow( oTD ) {
		var oImg = oTD.firstChild;
		var sDisplay;
		var sSectionId = "";
		var oTRs = null;
		if ( oTD.sectionid ) {
			sSectionId = oTD.sectionid;
			oTRs = document.all( sSectionId );
		}
		if ( oImg.tagName == "IMG" ) {
			var sImg = oImg.src;
			if ( sImg.indexOf( "expanded" ) == -1 ) {
				oTD.expanded = "true";
				oImg.src = "images/icon_expanded.gif";
				sDisplay = "";
			} else {
				oTD.expanded = "false";
				oImg.src = "images/icon_contracted.gif";
				sDisplay = "none";
			}
		}
		if ( oTRs && oTRs.length ) {
			for ( var iTR = 0; iTR < oTRs.length; iTR++ ) {
				var oTR = oTRs[ iTR ];
				oTR.style.display = sDisplay;
			}
		} else if ( oTRs ) {
			oTRs.style.display = sDisplay;
		}
		event.cancelBubble = true;
	}
				
	function sortXML( xmlData, xslStyle, sColumnName, divContent, sDataType, iSortToChange ) {
		var aExpandedTDs = new Array();
		var iExpandedTDs = 0;
		var oExpandedTDs = divContent.getElementsByTagName( "TD" );
		if ( oExpandedTDs ) {
			for ( var iTD = 0; iTD < oExpandedTDs.length; iTD++ ) {
				var oTD = oExpandedTDs.item( iTD );
				if ( oTD.expanded && oTD.expanded == "true" ) {
					aExpandedTDs[ iExpandedTDs ] = oTD.id;
					iExpandedTDs++;
				}
			}
		}
		
		var xmlSorts = xslStyle.selectNodes( "//xsl:sort" );
		var xmlSort = null;
		var sSort;
		if ( xmlSorts ) {
			xmlSort = xmlSorts.item(iSortToChange);
		}
		if ( xmlSort ) {
			var sOrder = xmlSort.getAttribute( "order" );
			if ( sOrder == "descending" ) {
				sSort = "ascending";
			} else {
				sSort = "descending";
			}
			if ( sDataType == "number" ) {
				xmlSort.setAttribute( "select", "number(translate(" + sColumnName + ", '/-: T', ''))" );
			} else {
				xmlSort.setAttribute( "select", sColumnName );
			}
			xmlSort.setAttribute( "order", sSort );
			xmlSort.setAttribute( "data-type", sDataType );
			divContent.innerHTML = xmlData.transformNode( xslStyle ).replace(/&lt;br&gt;/g,"<br>");
		}
		if ( aExpandedTDs.length > 0 ) {
			for ( iTD = 0; iTD < aExpandedTDs.length; iTD++ ) {
				var oTD = divContent.all( aExpandedTDs[ iTD ] );
				if ( oTD ) {
					oTD.click();
				}
			}
		}
		return sSort;
	}
	
	function getNumberFromDateString( sDate ) {
		var oDate = new Date( sDate );
		var sDateNumber = oDate.getFullYear().toString();
		sDateNumber += padLeft( ( oDate.getMonth() + 1 ).toString(), "0", 2 )
		sDateNumber += padLeft( oDate.getDate().toString(), "0", 2 )
		sDateNumber += padLeft( ( oDate.getHours() ).toString(), "0", 2 )
		sDateNumber += padLeft( ( oDate.getMinutes() ).toString(), "0", 2 )
		sDateNumber += padLeft( ( oDate.getSeconds() ).toString(), "0", 2 )
		return sDateNumber
	}
	
	function padLeft( sToPad, sPadding, iEndLength ) {
		while ( sToPad.length < iEndLength ) {
			sToPad = sPadding + sToPad;
		}
		return sToPad;
	}
	
	var m_oDisplayedTab;
	
	function displayTab( oTab ) {
		if ( m_oDisplayedTab != oTab ) {
			var oTabDiv = document.all( oTab.tabid )
			if ( oTabDiv && oTabDiv.tagName == "DIV" ) {
				if ( m_oDisplayedTab != null ) {
					document.all( m_oDisplayedTab.tabid ).style.display = "none";
					m_oDisplayedTab.className = "tab-off";
				}
				oTabDiv.style.display = "";
				oTab.className = "tab-on";
				m_oDisplayedTab = oTab;
				return true;
			} else {
				return false;
			}
		}
	}
	
	function getQueryString( sKey ) {
		var sQueryString = document.location.search;
		var aQueries = sQueryString.split( "&" );
		var sValue = "";
		for ( var iQuery = 0; iQuery< aQueries.length; iQuery++ ) {
			var sQuery = aQueries[ iQuery ];
			var aQuery = sQuery.split( "=" );
			if ( aQuery[ 0 ].toLowerCase() == sKey.toLowerCase() || aQuery[ 0 ].toLowerCase() == "?" + sKey.toLowerCase() ) {
				sValue = aQuery[ 1 ];
				sValue = unescape( sValue );
				sValue = sValue.replaceAll( "+", " " ); 
				break;
			}
		}
		return sValue;
	}
	
    function getZuluDate(dDate) {
        var sMonth = (dDate.getMonth() + 1).toString();
        var sDay = dDate.getDate().toString();
        var sYear = dDate.getFullYear().toString();
        var sHours = dDate.getHours().toString()
        var sMinutes = dDate.getMinutes().toString();
        var sSeconds = dDate.getSeconds().toString();
        if (sMonth.length == 1) {
            sMonth = "0" + sMonth;
        }
        if (sDay.length == 1) {
            sDay = "0" + sDay;
        }
        return sYear + "-" + padLeft( sMonth, "0", 2 ) + "-" + padLeft( sDay, "0", 2 ) + "T" + padLeft( sHours, "0", 2 ) + ":" + padLeft( sMinutes, "0", 2 ) + ":" + padLeft( sSeconds, "0", 2 );
    }
	
	function showControl(sControl)
		{
			var oControl = document.getElementById(sControl);
			oControl.style.display = "inline";
		}
		
	function hideControl(sControl)
		{
			var oControl = document.getElementById(sControl);
			oControl.style.display = "none";
			try
			{
				oControl.selectedIndex = 0;
			}
			catch (e) {}
		}
		
	function enableControl(sControl)
		{
			var oControl = document.getElementById(sControl);
			//alert(oControl.disabled + " " + sControl);
			if(oControl.disabled) {
				oControl.disabled = false;
			}
			if(! oControl.enabled) {
				oControl.enabled = true;
			}
		}
		
	function disableValidator(sControl)
		{
			var oControl = document.getElementById(sControl);
			//alert(oControl.disabled + " " + sControl);
			
			oControl.setAttribute('enabled', false);
		}
		
	function disableControl(sControl)
		{
			var oControl = document.getElementById(sControl);
			//alert(oControl.disabled + " " + sControl);
			
			if( oControl.getAttribute('enabled') == null ) {
				//alert("oControl.getAttribute('enabled')" + " " + sControl + " disable");
				oControl.setAttribute('enabled', false);
				return;
			}
			if(! oControl.disabled ) {
				//alert("! oControl.disabled" + " " + sControl + " disable");
				oControl.disabled = true;
				return;
			}
			if(oControl.enabled) {
				//alert("oControl.enabled" + " " + sControl + " enable");
				oControl.enabled = false;
				return;
			}
			//alert(oControl.enabled + " " + sControl + " setAttribute");
		}
		
	function emptyList(oControl) {
		while (oControl.options.length) oControl.options[0] = null;
	}
	
	function fillList(oControl, aValues, iDefault) {
		for (i=0; i < aValues.length; i++) {
			aOption = aValues[i].split("!");
			option = new Option (aOption[1], aOption[0]);
			oControl.options[oControl.length] = option;
		}
		if(iDefault == null) {iDefault = 0;}
		oControl.selectedIndex = iDefault;
	}
		
	function setDropDown(oDropDown, sValue)
		{
			setDropDownListBoxControl(oDropDown, sValue, 0)
		}
			
	function setListBox(oDropDown, sValue)
		{
			setDropDownListBoxControl(oDropDown, sValue, -1)
		}
			
	function setDropDownListBoxControl(oDropDown, sValue, iDefault)
		{
			//alert("setDropDown " + oDropDown + " " + sValue);
			oDropDown.selectedIndex = 0;
			for(i=0;i<oDropDown.length;i++)
			{
				//alert(oDropDown.selectedIndex);
				oDropDown.selectedIndex = i;
				aValue = oDropDown.value.split('|');
				if(aValue[0] == sValue)
				{
					break;
				}
				else
				{
					oDropDown.selectedIndex = iDefault;
				}
			}
		}
			
	function setListBoxSelections(oDropDown, sSelections, iDefault)
		{
			if(sSelections.length == 0) {
				if(iDefault == null) {iDefault = 0;}
				oDropDown.selectedIndex = iDefault;
			}
			var aSelections = sSelections.split('|');
			for(n=0;n<aSelections.length;n++)
			{
				for(i=0;i<oDropDown.length;i++)
				{
					aValue = oDropDown.options[i].value.split('|');
					if(aValue[0] == aSelections[n])
					{
						//alert(aSelections[n]);
						oDropDown.options[i].selected = true;
					}
				}
			}
		}
			
	function setDropDownByText(oDropDown, sValue)
		{
			//alert("setDropDown " + oDropDown + " " + sValue);
			oDropDown.selectedIndex = 0;
			for(i=0;i<oDropDown.length;i++)
			{
				//alert(oDropDown.selectedIndex);
				oDropDown.selectedIndex = i;
				if(oDropDown.options[i].text == sValue)
				{
					break;
				}
				else
				{
					oDropDown.selectedIndex = 0;
				}
			}
		}
			
	function getValuesFromList(oListBox)
		{
			//alert("setDropDown " + oDropDown + " " + sValue);
			var aOptions = oListBox.options;
			var sValues = "";
			var aValue;
			for(i=0;i<aOptions.length;i++)
			{
				//alert(oDropDown.selectedIndex);
				if(i>0){sValues += "|";}
				aValue = aOptions[i].value.split('|');
				sValues += aValue[0];
			}
			return sValues;
		}

	function getSelectedValuesFromList(oListBox)
		{
			var sValues = "";
			var aValue;
			for(i=0;i<oListBox.options.length;i++)
			{
				//alert(oDropDown.selectedIndex);
				if(oListBox.options[i].selected)
				{
					if(sValues.length > 0){sValues += "|";}
					aValue = oListBox.options[i].value.split('|');
					sValues += aValue[0];
				}
			}
			return sValues;
		}

	function getDopdownValue(oDropdown)
		{
			var sValues = oDropdown.value;
			var aValue = sValues.split('|');
			return aValue[0];
		}

	function getValueArrayFromList(oListBox)
		{
			//alert("setDropDown " + oDropDown + " " + sValue);
			var aOptions = oListBox.options;
			var sValues = "";
			var aValue;
			for(i=0;i<aOptions.length;i++)
			{
				//alert(oDropDown.selectedIndex);
				if(i>0){sValues += "$";}
				sValues += aOptions[i].value + "!" + aOptions[i].text;
			}
			return sValues;
		}
		
	function storeCheckBox(oCheckBox, sHiddenText) {
		if(oCheckBox.checked)
		{
			document.all(sHiddenText).value = 'true';
		}
		else
		{
			document.all(sHiddenText).value = 'false';
		}
		//alert(document.all(sHiddenText).value);
	}
	
	function storeSelections(oDropDown, sHiddenText) {
		document.all(sHiddenText).value = getSelectedValuesFromList(oDropDown);
		//alert(document.all(sHiddenText).value);
	}
	
	function fillFilter(sDropDown, sValues, sSelections) {
		var oDropDown = document.all(sDropDown);
		var aValues = sValues.split("$");
		emptyList(oDropDown);
		fillList(oDropDown, aValues, -1);
		oDropDown.size = aValues.count;
		setListBoxSelections(oDropDown, sSelections, -1)
	}
	
	function fillCheckBox(sCheckBox, sHiddenText) {
		var oCheckBox = document.all(sCheckBox);
		var sChecked = document.all(sHiddenText).value;
		if(sChecked == 'true')
		{
			oCheckBox.checked = true;
		}
		else
		{
			oCheckBox.checked = false;
		}
		//alert(document.all(sHiddenText).value);
	}
	
