/**
*
* 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;
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 arrayContains( 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 ( sPropertyValue.indexOf( 'function ' ) == -1 )
{
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 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 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';
}
}
