/**
*
* DESCRIPTION
*
* This file is expected to be included in almost every page as it contains
* global variables and javascript expected to be used by lots of different
* pages
*
*/
var sPrefix             = '';
var iModalOffsetX       = 2;
var iModalOffsetY       = 2;
var iSP2HeightModifier  = 25;
var 	sInputFocusColor		= "black";
function doNothing()
{
}
function foo()
{
alert( 'bar' );
}
function returnFalse()
{
return false;
}
function setCookie( sName, sValue )
{
document.cookie = sName + '=' + escape(sValue) + '; path=/';
}
function getCookie( sName )
{
var cookieVar       = document.cookie;
var cookieName      = sName + '=';
var cookieLength    = cookieVar.length;
var cookieBegin     = 0;
while ( cookieBegin < cookieLength )
{
var valueLength = cookieBegin + cookieName.length;
if ( cookieVar.substring(cookieBegin, valueLength) == cookieName )
{
var valueEnd    = cookieVar.indexOf( ';', valueLength );
if ( valueEnd == -1 )
valueEnd = cookieLength;
return unescape( cookieVar.substring(valueLength, valueEnd) );
}
cookieBegin = cookieVar.indexOf( ' ', cookieBegin ) + 1;
if (cookieBegin == 0)
break;
}
return null;
}
function deleteCookie( sName )
{
document.cookie = sName + '=; path=/; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
}
function trim( sData )
{
while ( sData.substr(0,1) == ' ' )
{
sData   = sData.substr( 1 );
}
while ( sData.substr(sData.length-1) == ' ' )
{
sData   = sData.substring( 0, sData.length-1 );
}
return sData;
}
function getValueFromParamString( sParamString, sKey )
{
var aArguments    = new Array();
var aValuePairs   = sParamString.split( ',' );
var sReturnValue  = '';
var bValueFound   = false;
for ( var iPair = 0; iPair < aValuePairs.length; iPair++ )
{
var sPair           = aValuePairs[iPair]
var iFirstEquals    = sPair.indexOf( '=' );
aArguments[aArguments.length]   = sPair.substring( 0, iFirstEquals );
aArguments[aArguments.length]   = sPair.substr( iFirstEquals+1 );
}
for (var iArg = 0; iArg < aArguments.length; iArg++)
{
if ( aArguments[iArg++] == sKey && !bValueFound ) // Only get first instance
{
sReturnValue  = aArguments[iArg];
bValueFound   = true;
}
}
return sReturnValue; // Returns '' if not found
}
function indexOfArrayElement( oArray, oElement )
{
var iReturnIndex    = -1;
for ( iItem = 0; iItem < oArray.length; iItem++ )
{
if ( oArray[iItem] == oElement )
{
iReturnIndex    = iItem;
break;
}
}
return iReturnIndex;
}
function copyObjectInfoToClipboard( oSource, sLabel )
{
var sProperties = '';
for ( sPropertyName in oSource )
{
var sPropertyValue  = '' + eval( 'oSource.' + sPropertyName );
if ( typeof sPropertyValue != 'object' )
{
sProperties += sPropertyName + ' = ' + sPropertyValue + '\n';
}
}
copyToClipboard( sProperties + '\n\n' );
if ( arguments.length > 1 )
{
alert( 'Copied "' + sLabel + '" properties to clipboard' );
}
}
function copyToClipboard( sText )
{
window.clipboardData.setData( 'Text', sText );
}
function penceToPounds( iPence )
{
var sPounds         = ( iPence / 100 ).toFixed( 2 );
var aPoundBits      = sPounds.split( '.' );
var sWholePounds    = aPoundBits[0];
var sNewWholePounds = '';
if ( sWholePounds.length > 3 )
{
sNewWholePounds += sWholePounds.substr( 0, sWholePounds.length % 3 );
for ( var i = sWholePounds.length % 3; i < sWholePounds.length; i+=3 )
{
if ( sNewWholePounds != '' )
{
sNewWholePounds += ',';
}
sNewWholePounds += sWholePounds.substr( i, 3 );
}
}
else
{
sNewWholePounds = sWholePounds;
}
var sNewAmountInPounds  = sNewWholePounds + '.' + aPoundBits[1];
return sNewAmountInPounds;
}
function DoModelessWindow( sUrl, aParams )
{
var oWindow     = aParams[0];
var sParams     = aParams[1];
var sParamString  = 'frameurl=' +sUrl;
var sArgs     = 'help: no;';
var sStatusBar    = getValueFromParamString( sParams, 'statusbar' );
var sNoResize   = getValueFromParamString( sParams, 'noresize' );
var sBackground   = getValueFromParamString( sParams, 'background' );
var iHeight     = getValueFromParamString( sParams, 'height' );
var iWidth      = getValueFromParamString( sParams, 'width' );
var sScroll     = getValueFromParamString( sParams, 'scroll' );
var oMainContentCell    = document.getElementById( 'maincontentcell' );
var iDialogTop          = window.screenTop + getTop( oMainContentCell );
var iDialogLeft         = window.screenLeft + getLeft( oMainContentCell );
sArgs   += 'dialogTop: ' + ( parseInt(iDialogTop)+parseInt(iModalOffsetY) ) + 'px;';
sArgs   += 'dialogLeft: ' + ( parseInt(iDialogLeft)+parseInt(iModalOffsetX) ) + 'px;';
sArgs += (sScroll == 'true') ? 'scroll: yes;' : 'scroll: no;';                                              // scroll=true      [default yes]
sArgs += (sNoResize == 'true') ? 'resizable: no;' : 'resizable: yes;';                                      // resizable=true   [default yes]
sArgs += (sStatusBar == 'true') ? 'status: yes;' : 'status: no;';                                           // statusbar=true   [default yes (untrusted) or no (trusted)]
sArgs += (iHeight > 100) ? 'dialogHeight: ' +(parseInt(iHeight)+parseInt(iSP2HeightModifier))+ 'px;' : '';  // height=x         [no default]
sArgs += (iWidth > 100) ? 'dialogWidth: ' +iWidth+ 'px;' : '';                                              // width=x          [no default]
sParamString  += (sBackground != '') ? ',bgcolor=' +sBackground : sBackground;  // background = (#rrggbb || colorName)
window.showModelessDialog( 'modelessdialog.htm', [oWindow,sParamString], sArgs );
}
function DoModalWindow( sUrl, sParams, sOtherParams )
{
var sParamString    = 'frameurl=' +sUrl;
var sArgs           = 'help: no;';
var sStatusBar      = getValueFromParamString( sParams, 'statusbar' );
var sNoResize       = getValueFromParamString( sParams, 'noresize' );
var sBackground     = getValueFromParamString( sParams, 'background' );
var iHeight         = getValueFromParamString( sParams, 'height' );
var iWidth          = getValueFromParamString( sParams, 'width' );
var sScroll         = getValueFromParamString( sParams, 'scroll' );
var iDefinedTop     = getValueFromParamString( sParams, 'top' );
var iDefinedLeft    = getValueFromParamString( sParams, 'left' );
if ( iDefinedTop == '' || iDefinedLeft == '' )
{
var oMainContentCell    = document.getElementById( 'maincontentcell' );
var iDialogTop          = window.screenTop + getTop( oMainContentCell );
var iDialogLeft         = window.screenLeft + getLeft( oMainContentCell );
sArgs   += 'dialogTop: ' + ( parseInt(iDialogTop)+parseInt(iModalOffsetY) ) + 'px;';
sArgs   += 'dialogLeft: ' + ( parseInt(iDialogLeft)+parseInt(iModalOffsetX) ) + 'px;';
}
else
{
sArgs   += 'dialogTop: ' + iDefinedTop + 'px;';
sArgs   += 'dialogLeft: ' + iDefinedLeft + 'px;';
}
sArgs += ( sScroll == 'false' ) ? 'scroll: yes;' : 'scroll: no;';                                               // scroll=false     [defaults to no if not specified]
sArgs += ( sNoResize == 'false' ) ? 'resizable: yes;' : 'resizable: no;';                                       // noresize=false   [defaults to no if not specified]
sArgs += ( sStatusBar == 'true' ) ? 'status: yes;' : 'status: no;';                                             // statusbar=true   [defaults to no if not specified]
sArgs += ( iHeight > 100 ) ? 'dialogHeight: ' +(parseInt(iHeight)+parseInt(iSP2HeightModifier))+ 'px;' : '';    // height=x         [is no default]
sArgs += ( iWidth > 100 ) ? 'dialogWidth: ' +iWidth+ 'px;' : '';                                                // width=x          [is no default]
sParamString  += ( sBackground != '' ) ? ',bgcolor=' +sBackground : sBackground;                                // background=#nnnnnn
sParamString  += ( sOtherParams != null ) ? ',' +sOtherParams : '';
var modalReturnValue  = window.showModalDialog( 'dialog.htm', sParamString, sArgs );
return modalReturnValue;
}
function showHide( sElem, bInline )
{
var oElem       = document.getElementById( sElem );
var bHide       = oElem.style.display != 'none';
var sVisible    = ( bInline ) ? 'inline' : 'block';
oElem.style.display = ( bHide ) ? 'none' : sVisible;
}
function getLeft( objSourceElement )
{
var intReturnCoordinate = 0;
while ( objSourceElement != null )
{
intReturnCoordinate += objSourceElement.offsetLeft;
objSourceElement    = objSourceElement.offsetParent;
}
return intReturnCoordinate;
}
function getTop( objSourceElement )
{
var intReturnCoordinate = 0;
while ( objSourceElement != null )
{
intReturnCoordinate += objSourceElement.offsetTop;
objSourceElement    = objSourceElement.offsetParent;
}
return intReturnCoordinate;
}
function getAbsX(obj)
{
var leftOffset = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
leftOffset += obj.offsetLeft;
obj = obj.offsetParent;
}
}
else if (obj.x) //for NN4
{
leftOffset = obj.x;
}
return leftOffset;
}
function getAbsY(obj, exclueObj)
{
var topOffset = 0;
var padding	= 0;
if (obj.offsetParent)
{
while (obj.offsetParent && obj.id != exclueObj)
{
topOffset += obj.offsetTop;
obj = obj.offsetParent;
}
}
else if (obj.y) // for NN4
{
topOffset = obj.y;
}
return topOffset;
}
function getY( oElement )
{
var iY =  oElement.offsetTop + document.body.scrollTop + document.documentElement.scrollTop;
alert(oElement.offsetTop + " "  + document.body.scrollTop + " "  + document.documentElement.scrollTop)
return iY;
}
function createHelpDiv()
{
var oNewDiv = document.createElement( 'DIV' );
oNewDiv.style.display       = 'none';
oNewDiv.style.position      = 'absolute';
oNewDiv.style.left          = '0px';
oNewDiv.style.top           = '0px';
oNewDiv.style.padding       = '4px';
oNewDiv.style.background    = '#EDF4FC';
oNewDiv.style.fontSize      = '11px';
oNewDiv.style.border        = '1px solid #0C5DD2';
oNewDiv.id                  = 'helpdiv';
var oTitle  = document.createElement( 'B' );
oTitle.appendChild( document.createTextNode("") );
oNewDiv.appendChild( oTitle );
oNewDiv.appendChild( document.createElement('BR') );
oNewDiv.appendChild( document.createTextNode("") );
document.body.appendChild( oNewDiv );
}
function showHelp( sTitle, sMessage, iWidth, iOffsetX, iOffsetY, bAlign )
{
var oHelpDiv                                    = document.getElementById( 'helpdiv' );
if ( oHelpDiv != null )
{
oHelpDiv.childNodes[0].childNodes[0].nodeValue  = sTitle;
oHelpDiv.childNodes[2].nodeValue                = sMessage;
oHelpDiv.style.width                            = iWidth + 'px';
oHelpDiv.style.display                          = 'block';
oHelpDiv.style.left                             = ( window.event.clientX + iOffsetX ) + 'px';
oHelpDiv.style.top                              = ( window.event.clientY + iOffsetY ) + 'px';
if ( arguments.length == 6 && bAlign == 'right' )
{
oHelpDiv.style.left = ( window.event.clientX + iOffsetX - iWidth ) + 'px';
}
}
}
function hideHelp()
{
var oHelpDiv            = document.getElementById( 'helpdiv' );
if ( oHelpDiv != null )
{
oHelpDiv.style.display  = 'none';
}
}
function $( sId )
{
if ( typeof sId == 'string' )
{
return document.getElementById( sId );
}
else
{
return sId;
}
}
function getPropertyFromParamString( sProperty, sCommaDelimitedParams )
{
var sPropValue  = '';
var aParams     = sCommaDelimitedParams.split( ',' );
for ( var i = 0; i < aParams.length; i++ )
{
var aParam  = aParams[i].split( '=' );
if ( aParam.length > 1 && aParam[0] == sProperty )
{
sPropValue  = aParam[1];
break;
}
}
return sPropValue;
}
function showAboveControl( sObjectId )
{
var oObjectToBeShown    = document.getElementById( sObjectId );
if ( oObjectToBeShown != null )
{
var sHidingId       = 'iframe_hiding_' + sObjectId;
if ( document.getElementById( sHidingId ) == null )
{
var oTempIframe = document.createElement( 'IFRAME' );
with ( oTempIframe )
{
id          = sHidingId;
scrolling   = 'no';
with ( style )
{
display     = 'none';
position    = 'absolute';
zIndex      = '999';
border      = 'none';
margin      = '0px';
padding     = '0px';
}
}
document.body.appendChild( oTempIframe );
}
var oHidingFrame    = document.getElementById( sHidingId );
var iNewLeft    = getLeft( oObjectToBeShown );
var iNewTop     = getTop( oObjectToBeShown );
var iNewWidth   = ( oObjectToBeShown.offsetWidth + 0 );
var iNewHeight  = ( oObjectToBeShown.offsetHeight + 0 );
/*
iNewLeft    -= 5;
iNewTop     -= 5;
iNewWidth   += 10;
iNewHeight  += 10;
*/
oHidingFrame.style.left     = iNewLeft + 'px';
oHidingFrame.style.top      = iNewTop + 'px';
oHidingFrame.style.width    = iNewWidth + 'px';
oHidingFrame.style.height   = iNewHeight + 'px';
oHidingFrame.style.display  = 'block';
/*
oHidingFrame.focus();
oObjectToBeShown.focus();
*/
}
}
function disableControlHiding( sObjectId )
{
var oObjectToBeShown    = document.getElementById( sObjectId );
if ( oObjectToBeShown != null )
{
var sHidingId       = 'iframe_hiding_' + sObjectId;
var oHidingFrame    = document.getElementById( sHidingId );
if ( oHidingFrame != null )
{
oHidingFrame.style.display  = 'none';
}
}
}
function getSelectedIndexFromValue( oSelect, sValue )
{
var iSelectedIndex  = -1;
for ( var i = 0; i < oSelect.options.length; i++ )
{
if ( oSelect.options[i].value == sValue )
{
iSelectedIndex  = i;
break;
}
}
return iSelectedIndex;
}
function escapeXml( sRaw )
{
var sEscaped    = ( sRaw == null || sRaw.length == 0 ) ? '' : sRaw;
sEscaped        += '';
sEscaped        = sEscaped.replace( /\&/g, '&amp;'  );
sEscaped        = sEscaped.replace( /"/g,  '&quot;' );
sEscaped        = sEscaped.replace( /</g,  '&lt;'   );
sEscaped        = sEscaped.replace( />/g,  '&gt;'   );
sEscaped        = sEscaped.replace( /%/g,  '&#37;'  );
return sEscaped;
}
function unescapeXml( sEscaped )
{
var sRaw    = ( sEscaped == null || sEscaped.length == 0 ) ? '' : sEscaped;
sRaw        += '';
sRaw        = sRaw.replace( /\&amp;/g,  '&' );
sRaw        = sRaw.replace( /\&quot;/g, '"' );
sRaw        = sRaw.replace( /\&lt;/g,   '<' );
sRaw        = sRaw.replace( /\&gt;/g,   '>' );
sRaw        = sRaw.replace( /\&#37;/g,  '%' );
return sRaw;
}
function encodeForGetRequest( sSource )
{
var sEscaped    = ( sSource == null || sSource.length == 0 ) ? '' : sSource;
sEscaped        += '';
sEscaped        = sEscaped.replace( /%/g,  '%25' );
sEscaped        = sEscaped.replace( /\&/g, '%26' );
sEscaped        = sEscaped.replace( /\?/g, '%3F' );
return sEscaped;
}
function enterField( oField )
{
if ( oField.value == oField.egtext )
{
oField.style.color      = 'black';
oField.style.fontStyle  = 'normal';
oField.value            = '';
}
}
function leaveField( oField, prePopulated )
{
if ( oField.value == '' && prePopulated == null )
{
oField.style.color      = '#666666';
oField.style.fontStyle  = 'italic';
}
}