/* Start Header ------------------------------------------------------------

    Kodak Graphic Communications Canada Company
    Burnaby B.C. Canada
    V5G 4M1

    Copyright (C) 2008 Kodak Graphic Communications Canada Company
    
    Reproduction or disclosure of this file or its contents without the
    prior written consent of Kodak Graphic Communications Canada Company
    is prohibited.

 * End Header --------------------------------------------------------------
 */
 
// =========================================== script block
// Catch the backspace key and suppress
// it unless the key press is insite an INPUT
// field or TEXTAREA field.
// ===========================================
document.onkeydown=SupressBackspaceKeyPress;

sm_CentreFromLeft = 0; // when left side bar visible: 220

function SupressBackspaceKeyPress( evt ) 
{
    var kKeyCode_Backspace = 8;
    if ( window.event )
    {
        //ie & safari
        var strElementTagName = window.event.srcElement.tagName;
        if ( window.event.keyCode == kKeyCode_Backspace && strElementTagName != "INPUT" && strElementTagName != "TEXTAREA") 
        {
            window.event.cancelBubble = true;
            window.event.returnValue = false;
        }
    } 
    else
    {
        //firefox
        var elementId = document.getElementById( evt.target.getAttribute( "id" ) );
        var keyPressed = evt.which? evt.which: evt.keyCode;
        if ( typeof elementId != 'undefined' && elementId != null)
        {
            var strElementTagName = elementId.tagName;
        
            if (keyPressed == kKeyCode_Backspace && strElementTagName != "INPUT" && strElementTagName != "TEXTAREA") 
            {
                evt.cancelBubble = true;
                evt.preventDefault();
            }
        }
    }

}

function WebForm_FireDefaultButton(event, target) 
{
    //overrides ASP-derived method 
    // for FF compatibility
    var element = event.target || event.srcElement;
    
    if (event.keyCode == 13 &&
        !(element &&
        element.tagName.toLowerCase() == "textarea")) 
        {
        var defaultButton;
        if (__nonMSDOMBrowser) 
        {
            defaultButton = document.getElementById(target);
        } 
        else 
        {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof defaultButton.click != "undefined") 
        {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) 
            {
                event.stopPropagation();
            }
            return false;
        }
    }
    return true;
}



// =========================================== CSWFunctions_HandleError
// displays error if there is a fault string 
// returns true if no errors, false if error found
// ===========================================
//function CSWFunctions_HandleError( objResults ) 
//{
//    CSWFunctions_HandleErrorImplementation( objResults, false )
//}

var gCSWFunctions_StatusCallbackErrorShowing = false;

//-------------------------------------------- CSWFunctions_HandleErrorStatusCallback
//--------------------------------------------
function CSWFunctions_HandleErrorStatusCallback( objResults )
{
    CSWFunctions_HandleError( objResults, true );
}

//-------------------------------------------- CSWFunctions_HandleError
// blnStatusCallback flag is optional
//--------------------------------------------
function CSWFunctions_HandleError( objResults, blnStatusCallback )
{
    var blnHasErrors = false; // i.e. no errors found
    var strFaultString = "";
    var strFaultCode = "";
    
    for ( var strProperty in objResults )
    {
        if ( strProperty == 'faultString' )
        {
            strFaultString = unescape( objResults['faultString'] );
            blnHasErrors = true;
        }
        if ( strProperty == 'faultCode' )
        {
            strFaultCode = unescape( objResults['faultCode'] );
        }
    }
    
    // if result is negative i.e. we have found and error and we are in need of displaying it
    // or if not no errors then show it
    if ( blnHasErrors )
    {
        var strErrorCodeString = '';
        if ( strFaultCode != "" )
        {
            strErrorCodeString = '&nbsp;&nbsp;&nbsp;Error Code: ' + strFaultCode;
        }
        CSWBase_ShowError( strFaultString + strErrorCodeString );
        if ( blnStatusCallback )
        {
            gCSWFunctions_StatusCallbackErrorShowing = true;
        }
    }
    else
    {
        if ( blnStatusCallback )
        {
            if ( gCSWFunctions_StatusCallbackErrorShowing )
            {
                gCSWFunctions_StatusCallbackErrorShowing = false;
                CSWBase_HideError();
            }
        }
        else
        {
            CSWBase_HideError();
        }
    }
        
    return blnHasErrors;
}

// =========================================== CSWFunctions_SubmitFormToIFrame
// ===========================================
function CSWFunctions_SubmitFormToIFrame( objForm, strAction, strTarget )
{
    var oldAction = objForm.action;
    var oldTarget = objForm.target;
    objForm.action = strAction;
    objForm.target = strTarget; // comment out this line to open as its own page
    objForm.submit();
    objForm.action = oldAction;
    objForm.target = oldTarget;
}

// =========================================== CSWFunctions_SubmitToNewWindow
// ===========================================
function CSWFunctions_SubmitToNewWindow( strUrl, strTitle, intWidth, intHeight )
{
    var dteNow = new Date();
    var strWindowProperties = "status=no, scrollbars=yes, resizable=yes, toolbar=no, width=" + intWidth + ", height=" + intHeight;
    var strWindowName = strTitle + dteNow.getHours() + dteNow.getMinutes() + dteNow.getSeconds();
    
    var objNewWindow = window.open( "", strWindowName, strWindowProperties );
    
    try
    {
        objNewWindow.moveTo( GetCenteredScreenXPos( intWidth ), GetCenteredScreenYPos( intHeight ) );
    }
    catch ( objException )
    {
        // non-fatal error, so continue
    }
    
    var objOldAction = document.forms[0].action;
    var objOldTarget = document.forms[0].target;
    
    if ( strUrl == "" )
    {
        strUrl = objOldAction;
    }
    
    document.forms[0].action = strUrl;
    document.forms[0].target = strWindowName;
    document.forms[0].submit();
    document.forms[0].action = objOldAction;
    document.forms[0].target = objOldTarget;
    
    return false;
}

// =========================================== CSWFunctions_AddLoadEvent
// add a page load event without disturbing
// any of the previously registered load events
// ===========================================
function CSWFunctions_AddLoadEvent( objFunction ) 
{
    var objOldOnloadFunction = window.onload;
    if ( typeof window.onload != 'function' ) 
    {
        window.onload = objFunction;
    } 
    else 
    {
        window.onload = function() 
        {
            objOldOnloadFunction();
            objFunction();
        }
    }
}

// =========================================== CSWFunctions_AddResizeEvent
// add a page load event without disturbing
// any of the previously registered load events
// ===========================================
function CSWFunctions_AddResizeEvent( objFunction ) 
{
    var objOldOnResizeFunction = window.onresize;
    if ( typeof window.onresize != 'function' ) 
    {
        window.onresize = objFunction;
    } 
    else 
    {
        window.onresize = function() 
        {
            objOldOnResizeFunction();
            objFunction();
        }
    }
}

// =========================================== CSWFunctions_EnsureTopWindow
// make the current window the top one
// =========================================== 
function CSWFunctions_EnsureTopWindow()
{
    if ( window != window.top )
    {
        window.top.location = window.location;
    }
}

// ===========================================
// ===========================================
function CSWFunctions_ShowAndHideArrays
(
    aryDivToShow,
    aryDivToHide
)
{
    for (index in aryDivToHide)
    {
        var sectionToHide = document.getElementById( aryDivToHide[index] )
        if ( sectionToHide )
        {
            sectionToHide.style.display='none';
        }
    }

    for (index in aryDivToShow)
    {
        var objSectionToShow = document.getElementById( aryDivToShow[index]);
        if ( objSectionToShow )
        {
            objSectionToShow.style.display='block';
        } 
    }
}

// ===========================================
// ===========================================
function CSWFunctions_ShowAndHideList
(
    strDivToShow,
    aryDivToHide
)
{
    for (index in aryDivToHide)
    {
        var sectionToHide = document.getElementById( aryDivToHide[index] )
        if ( sectionToHide )
        {
            sectionToHide.style.display='none';
        }
    }

    var objSectionToShow = document.getElementById( strDivToShow );
    if ( objSectionToShow )
    {
        objSectionToShow.style.display='block';
    } 
}


// ===========================================
// ===========================================
function CSWFunctions_SetAllCheckboxStates( strCheckboxName, blnChecked )
{
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if((objCurrentElement.type == "checkbox") &&
            (objCurrentElement.name.indexOf(strCheckboxName) != -1))
        {
            objCurrentElement.checked = blnChecked;
        }//if
    }//for
    //return false;
}

// ===========================================
// ===========================================
function CSWFunctions_SetAllCheckboxStatesByValue( strValue, blnChecked )
{
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if((objCurrentElement.type == "checkbox") &&
            (objCurrentElement.value.indexOf( strValue ) != -1))
        {
            objCurrentElement.checked = blnChecked;
        }//if
    }//for
    //return false;
}

// ===========================================
// ===========================================
function CSWFunctions_SetAllCheckboxStatesByScriptName( strCheckBoxScriptName, blnChecked )
{
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if ( objCurrentElement.type == "checkbox" ) 
        {
            var objAttr = objCurrentElement.attributes;
            var objScriptName = objAttr.getNamedItem( 'scriptname' );
            if ( objScriptName != null )
            {
                if ( objScriptName.value.indexOf( strCheckBoxScriptName ) != -1 )
                {
                    objCurrentElement.checked = blnChecked;
                }
            }
        }
    }
}

// ===========================================
// ===========================================
function CSWFunctions_GetAllCheckboxesByScriptName( strCheckBoxScriptName )
{
    var aryElements = new Array();
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    var arrayIndex = 0;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if ( objCurrentElement.type == "checkbox" ) 
        {
            var objAttr = objCurrentElement.attributes;
            var objScriptName = objAttr.getNamedItem( 'scriptname' );
            if ( objScriptName != null )
            {
                if ( objScriptName.value.indexOf( strCheckBoxScriptName ) != -1 )
                {
                    aryElements[ arrayIndex ] = objCurrentElement;
                    arrayIndex++;
                }
            }
        }
    }
    return aryElements
}

// ===========================================
// ===========================================
function CSWFunctions_GetAllCheckedCheckboxesByScriptName( strCheckBoxScriptName )
{
    var aryElements = new Array();
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    var arrayIndex = 0;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if ( objCurrentElement.type == "checkbox" ) 
        {
            var objAttr = objCurrentElement.attributes;
            var objScriptName = objAttr.getNamedItem( 'scriptname' );
            if ( objScriptName != null )
            {
                if ( objScriptName.value.indexOf( strCheckBoxScriptName ) != -1 )
                {
                    if ( objCurrentElement.checked == true )
                    {
                        aryElements[ arrayIndex ] = objCurrentElement.value;
                        arrayIndex++;
                    }
                }
            }
        }
    }
    return aryElements
}

// ===========================================
// ===========================================
function CSWFunctions_SetAllCheckboxStatesByTitle( strTitle, strCheckBoxScriptName, blnChecked )
{
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    for(intIndex = 0; intIndex < objElements.length; intIndex++)
    {
        objCurrentElement = objElements[intIndex];
        if ( ( objCurrentElement.type == "checkbox" ) && !objCurrentElement.disabled )
        {
            var objAttr = objCurrentElement.attributes;
            var objScriptName = objAttr.getNamedItem( strTitle );
            if ( objScriptName != null )
            {
                if ( objScriptName.value == strCheckBoxScriptName )
                {
                    objCurrentElement.checked = blnChecked;
                }
            }
        }
    }
}

// ===========================================CSWFunctions_SetAllEnableStates
// ===========================================
function CSWFunctions_SetAllEnableStates( blnEnabled, strIdsToEnable )
{
    CSWFunctions_SetAllEnableStates( blnEnabled, strIdsToEnable, true );
}

// ========================================================= CSWFunctions_SetAllEnableStates
// ========================================================= 
function CSWFunctions_SetAllEnableStates( blnEnabled, strIdsToEnable, blnIncludeHiddenFields )
{
    var objElements;
    var intIndex;
    var objCurrentElement;
    objElements = document.forms['aspnetForm'].elements;
    for ( var intIndex = 0; intIndex < objElements.length; intIndex++ )
    {
        objCurrentElement = objElements[intIndex];
        if ( objCurrentElement.name.indexOf( strIdsToEnable ) != -1 )
        {
            var blnToggle = true;
            if ( ! blnIncludeHiddenFields )
            {
                if ( ! blnEnabled && ( objCurrentElement.type == "hidden" ) )
                {
                    // Don't ever disable a hidden field
                    blnToggle = false;
                }
            }
            
            if ( blnToggle )
            {
                objCurrentElement.enabled = blnEnabled;
                objCurrentElement.disabled = !blnEnabled;
            }
        }
    }
}


// ===========================================
// ===========================================
function CSWFunctions_FindAbsolutePosY( objElement )
{
	var curtop = 0;
	if ( objElement.offsetParent )
	{
		while ( objElement.offsetParent )
		{
			curtop += objElement.offsetTop;
			objElement = objElement.offsetParent;
		}
	}
	else if ( objElement.y )
	{
		curtop += objElement.y;
	}
	return curtop;
}


// ===========================================
// ===========================================
function CSWFunctions_FindAbsolutePosX( objElement )
{
	var curleft = 0;
	if ( objElement.offsetParent )
	{
		while ( objElement.offsetParent )
		{
			curleft += objElement.offsetLeft;
			objElement = objElement.offsetParent;
		}
	}
	else if ( objElement.x )
	{
		curleft += objElement.x;
	}
	return curleft;
}

// =========================================== CSWFunctions_SetSelection
// ===========================================
/*&function CSWFunctions_SetSelection( strSelectedDivId, strHighlightDivId )
{
    var intSelectedYPos;
    var intHighlightedYPos;
    var objSelectedDivElement;
    var objHighlightDivElement;
   
    objSelectedDivElement = document.getElementById( strSelectedDivId );
    objHighlightDivElement = document.getElementById( strHighlightDivId );
    intSelectedYPos = CSWFunctions_FindAbsolutePosY( objSelectedDivElement );
    intHighlightedYPos = CSWFunctions_FindAbsolutePosY( objHighlightDivElement );
    objSelectedDivElement.style.top = intHighlightedYPos - intSelectedYPos;
    objSelectedDivElement.style.visibility = "visible";
}*/

// ===========================================
// ===========================================
function CSWFunctions_UpdateListBasedOnSelections( strSourceListId, strDestinationListId )
{
    var i, intNextIndexInDestinationList;
    var objSourceList = document.getElementById( strSourceListId );
    var objDestinationList = document.getElementById( strDestinationListId );
    for ( i = objSourceList.length - 1; i >= 0 ; i-- )
    {
        if ( objSourceList.options[i].selected == true )
        {
            intNextIndexInDestinationList = objDestinationList.length;
            objDestinationList.options.length = intNextIndexInDestinationList + 1;
            objDestinationList.options[ intNextIndexInDestinationList ].value 
                = objSourceList.options[i].value;
            objDestinationList.options[ intNextIndexInDestinationList ].text 
                = objSourceList.options[i].text;
        }
    }
    return false;
}


// ===========================================
// ===========================================
function CSWFunctions_ClearSelectedItems( strListId )
{
    var i;
    var objList = document.getElementById( strListId );
    for ( i = objList.length - 1; i >= 0 ; i-- )
    {
        if ( objList.options[i].selected == true )
        {
            objList.options[i] = null;
        }
    }
    
    return false;
}

// ===========================================
// ===========================================
function CSWFunctions_ChangeStyle( objElement, strNewStyle )
{
   objElement.className = strNewStyle;
}

// ===========================================
// ===========================================
// Note: the width and height specify the inner window size
function OpenSecondaryWindow
(
  strURL,
  intDesiredWidth,
  intDesiredHeight,
  strResizable,
  intDesiredXPos,                 // optional
  intDesiredYPos,                 // optional
  strAdditionalWindowFeatures,    // optional
  strDesiredTarget                // optional
)
{

  var intXPos, intYPos, intWidth, intHeight;
  var strWindowFeatures, strTarget, objNewWindow;

  // the desired X, Y positions are optional
  if ( intDesiredXPos || intDesiredYPos )
  {
      intXPos = intDesiredXPos;
      intYPos = intDesiredYPos;
  }
  else
  {
      intXPos = 0;
      intYPos = 0;
  }

  // adjust window dimensions based on client platform
  // (the following adjustments were discovered empirically)
  intWidth = intDesiredWidth;
  intHeight = intDesiredHeight;

  strWindowFeatures =
      "resizable=" + strResizable +
      ",width=" + intWidth +
      ",height=" + intHeight +
      ",left=" + intXPos +
      ",top=" + intYPos;

  // the additional window features are optional
  if ( ( strAdditionalWindowFeatures ) && ( strAdditionalWindowFeatures != "" ) )
  {
      strWindowFeatures += "," + strAdditionalWindowFeatures;
  }

  // the target is optional
  if ( ( strDesiredTarget ) && ( strDesiredTarget != "" ) )
  {
      strTarget = strDesiredTarget;
  }
  else
  {
      // open in a new window
      strTarget = "_blank";
  }

  objNewWindow = window.open( strURL, strTarget, strWindowFeatures );

  try
  {
      // for some browsers the left\top in the above line does nothing,
      // so move the window explicitly
      objNewWindow.moveTo( intXPos, intYPos );
  }
  catch ( objException )
  {
      // non-fatal error, so continue
  }
} //OpenSecondaryWindow


// ===========================================
// ===========================================
function OpenHelpWindow( strURL )
{
    var intWidth, intHeight;
  
    intWidth = 790;
    intHeight = 500;
  
    OpenSecondaryWindow(
        strURL,
        intWidth,
        intHeight,
        "YES",
        GetCenteredScreenXPos( intWidth ),
        GetCenteredScreenYPos( intHeight ),
        "toolbar=yes,scrollbars=yes,location=yes",
        "_blank" );

} //OpenHelpWindow

// ===========================================
// ===========================================
function OpenTroubleshootingWindow( strURL, strGUID )
{
    var intWidth, intHeight;

    intWidth = 600;
    intHeight = 590;

    // Append to the URL whether or not cookies and java are enabled
    strURL = strURL  
      + "&Cookies=" + CookiesAreEnabled() 
      + "&Java=" + JavaIsEnabled();

    // Add the param file parameter to the URL.
    strURL += "&" + GetUniqueAppletParamFileNameParameter( strGUID );

    OpenSecondaryWindow(
        strURL,
        intWidth,
        intHeight,
        "YES",
        GetCenteredScreenXPos( intWidth ),
        GetCenteredScreenYPos( intHeight ),
        "scrollbars=yes",
        "InSite_Troubleshooting_Window" );

} //_OpenTroubleshootingWindow
                

// =========================================== CSWFunctions_OpenUploadWindow
// ===========================================
function CSWFunctions_OpenUploadWindow
(
    strURL,
    intWidth,
    intHeight
)
{
    OpenSecondaryWindow(
        strURL,
        intWidth,
        intHeight,
        "YES",
        GetCenteredScreenXPos( intWidth ),
        GetCenteredScreenYPos( intHeight ),
        "",
        "_blank" );
}

// =========================================== LaunchSmartReview
// ===========================================
function LaunchSmartReview( strUrl, strGUID )
{
    // Add the param file parameter to the URL.
    strUrl += "&" + GetUniqueAppletParamFileNameParameter( strGUID );

    var dteNow = new Date();
    
    var objOldAction = document.forms[0].action;
    var objOldTarget = document.forms[0].target;
    document.forms[0].action = strUrl;
    document.forms[0].target = "_self";
    document.forms[0].submit();
    document.forms[0].action = objOldAction;
    document.forms[0].target = objOldTarget;
    
    return false;
}
                
// =========================================== CSWFunctions_LaunchSmartReviewInSpreadMode
// ===========================================
function CSWFunctions_LaunchSmartReviewInSpreadMode
( 
    strUrl,
    strGUID 
)
{
    // Add the param file parameter to the URL.
    strUrl += "&" + GetUniqueAppletParamFileNameParameter( strGUID );

    var dteNow = new Date();
    
    var objOldAction = document.forms[0].action;
    var objOldTarget = document.forms[0].target;
    document.forms[0].action = strUrl;
    document.forms[0].target = "_self";
    document.forms[0].submit();
    document.forms[0].action = objOldAction;
    document.forms[0].target = objOldTarget;
    
    return false;
}
                               
// =========================================== GetCenteredScreenXPos
// ===========================================
function GetCenteredScreenXPos(intWindowWidth) 
{

    var intXPos;
  
    intXPos = (screen.width - intWindowWidth) / 2;
  
    return intXPos;

}//GetCenteredScreenXPos
    
    
// =========================================== GetCenteredScreenYPos
// ===========================================
function GetCenteredScreenYPos(intWindowHeight) 
{
    var intYPos;

    intYPos = (screen.height - intWindowHeight) / 2;

    return intYPos;

}//GetCenteredScreenYPos

// =========================================== GetCenteredWindowXPos
// ===========================================
function GetCenteredWindowXPos( intDialogWidth ) 
{

    var intWindowWidth;
    var intXPos;

    if ( window.innerWidth && window.pageXOffset )
    {
        intWindowWidth = window.innerWidth +
                         window.pageXOffset;
    }
    else
    {
        intWindowWidth = document.body.clientWidth +
                         document.body.scrollLeft;
    }

    intXPos = ( intWindowWidth - intDialogWidth ) / 2;
    return intXPos;

}//_GetCenteredWindowXPos
    
    
// =========================================== GetCenteredWindowYPos
// ===========================================
function GetCenteredWindowYPos( intDialogHeight ) 
{
    var intWindowHeight;
    var intYPos;

    if ( window.innerHeight && window.pageYOffset )
    {
        intWindowHeight = window.innerHeight +
                          window.pageYOffset;
    }
    else
    { 
        intWindowHeight = document.body.clientHeight +
                          document.body.scrollTop;
    }
    
    intYPos = ( intWindowHeight - intDialogHeight ) / 2;
    return intYPos;
    
}//_GetCenteredWindowYPos


// =========================================== CSWFunctions_CentreInWindow
// ===========================================
function CSWFunctions_CentreInWindow( strElementId, intElementWidth, intElementHeight, strListOfSelectBoxesToExclude )
{
    var objElement = document.getElementById( strElementId );
    
    if ( objElement != null )
    {
        CSWFunctions_HideSelectBoxes( strListOfSelectBoxesToExclude );    
        
        var newTop = GetCenteredWindowYPos( intElementHeight );
        var newLeft = GetCenteredWindowXPos( intElementWidth );
        objElement.style.top = newTop - 100;
        objElement.style.left = newLeft - sm_CentreFromLeft;
    }    
}


// =========================================== CSWFunctions_HideSelectBoxes
// Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
// IE has a problem with wanted select form tags to always be the topmost z-index or layer
// ===========================================
function CSWFunctions_HideSelectBoxes( strListOfSelectBoxesToExclude ) 
{
  // check to see if this is IE version 6 or lower. if so, hide select boxes.
  var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
  if ( brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1 ) 
  {
      for( var i = 0; i < document.forms.length; i++ ) 
      {
          for( var e = 0; e < document.forms[i].length; e++ )
          {
              var objElement = document.forms[i].elements[e];
              if ( objElement.tagName == "SELECT" ) 
              {
                  if ( ( objElement.id == "" ) || ( strListOfSelectBoxesToExclude.match( objElement.id ) == null ) )
                  {
                        objElement.style.visibility="hidden";
                  }
              }
          }
      }
  }
}

// =========================================== CSWFunctions_DisplaySelectBoxes
// Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
// IE has a problem with wanted select form tags to always be the topmost z-index or layer
// ===========================================
function CSWFunctions_DisplaySelectBoxes() 
{
	for( var i = 0; i < document.forms.length; i++ ) 
	{
		for( var e = 0; e < document.forms[i].length; e++)
		{
			if( document.forms[i].elements[e].tagName == "SELECT" ) 
			{
    			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

// ===========================================CookiesAreEnabled()
//
// Returns true if the user's browser has
// cookies enabled. Returns false otherwise.
//
// ===========================================
function CookiesAreEnabled() 
{
    var blnCookiesEnabled;
  
    document.cookie = "cookie_test=yes";
  
    if ( document.cookie.indexOf("cookie_test=") != -1 ) 
    {
  
      blnCookiesEnabled = true;
  
    } 
    else 
    {
  
      blnCookiesEnabled = false;
  
    }//if
  
    return blnCookiesEnabled;
}//CookiesAreEnabled


// =========================================== JavaIsEnabled()
//
// Returns true if the user has enabled Java
// capabilities. Returns false otherwise.
//
// ===========================================
function JavaIsEnabled() 
{
    return navigator.javaEnabled();
}//JavaIsEnabled

// =========================================== GetUniqueAppletParamFileNameParameter()
//
// Returns a name/value pair for the applet param
// file query string parameter.  The value will
// be unique to avoid race conditions.
//
// ===========================================
function GetUniqueAppletParamFileNameParameter( strGUID )
{
    var timestamp;
    var date = new Date();
  
    // Returns the number of milliseconds since January 1, 1970.
    timestamp = date.getTime();
      
    return "paramFile=" + strGUID + timestamp;
    
} //GetUniqueAppletParamFileNameParameter


// =========================================== LogDebug
// ===========================================
function CSWFunctions_LogDebug( strDebugString )
{
    LogDebug( strDebugString );
}

// =========================================== LogDebug
// ===========================================
function LogDebug( strDebugString )
{
    var objDebugWindow = document.getElementById( 'DebugWindow' );
    var objDebugText = document.getElementById( 'DebugText' );
    objDebugWindow.style.display = 'block';
    var strCurrentHtml = objDebugText.innerHTML;
    objDebugText.innerHTML = strCurrentHtml + '<BR>' + strDebugString;
}

// =========================================== CSWFunctions_AdjustPanelHeight
// ===========================================
function CSWFunctions_AdjustPanelHeight( strPanelId )
{
    var objPanel = document.getElementById( strPanelId );
    if ( objPanel != null )
    {
        var intWindowHeight;
        if ( window.innerHeight && window.pageYOffset )
        {
            intWindowHeight = window.innerHeight + window.pageYOffset;
        }
        else
        {
            intWindowHeight = document.body.clientHeight + document.body.scrollTop;
        }
        
        objPanel.style.height = intWindowHeight * .65;
    }
}

// =========================================== CSWFunctions_CallbackHandler
// =========================================== 
function CSWFunctions_CallbackHandler( result, context )
{
    var objResults;
    objResults = result.parseJSON();
    
    if ( !CSWFunctions_HandleError( objResults ) )
    {
        for( key in objResults )
        {
            var strElementId = key;
            var strElementValue = objResults[ strElementId ];
            var strDecodedElementValue = unescape( strElementValue );
            var objElement = document.getElementById( strElementId );
            if( objElement != null ) 
            {
                objElement.innerHTML = strDecodedElementValue;
            }
        }
        
        // select the first row of the list when it exists
        if ( self.AWEC_SelectableList )
        {
            AWEC_SelectableList.SelectFirstRow();
        }
    }
    CSWFunctions_EndLoading();
}

// =========================================== CSWFunctions_CallbackErrorHandler
// =========================================== 
function CSWFunctions_CallbackErrorHandler( result, context )
{
    if ( result == 'SessionTimeout' )
    {
        window.location = kLoginUrlWithSessionTimeout;
    }
    var intIndex = result.indexOf( 'SystemError' );
    if ( intIndex == 0 )
    {
        var strExtraInfo = result.substring( result.indexOf( '|' ) + 1 );
        // url is incomplete, ends with ExtraInfo
        window.location = kUserErrorUrl + strExtraInfo;
    }
    else
    {
        CSWBase_ShowError( result );
    }
}


// =========================================== CSWFunctions_StartLoading
// ===========================================
function CSWFunctions_StartLoading()
{
    document.getElementById( 'LoadingIndicatorPanel' ).style.display = 'block';
}

// =========================================== CSWFunctions_EndLoading
// ===========================================
function CSWFunctions_EndLoading()
{
    document.getElementById( 'LoadingIndicatorPanel' ).style.display = 'none';
}

// =========================================== CSWFunctions_UpdatePostData
// <hack> this gets .Net callback framework to post the current state of the form controls.
// Otherwise, it will post the state of the controls after form_load.
// Search for WebForm_InitCallback in http://msdn.microsoft.com/msdnmag/issues/05/01/CuttingEdge/
// ===========================================
function CSWFunctions_UpdatePostData()
{
    __theFormPostData = '';
    __theFormPostCollection = new Array();
    WebForm_InitCallback();
}

// =========================================== CSWFunctions_SetTopPosition
// ===========================================
function CSWFunctions_SetTopPosition( objReferenceElement, objElementToMove )
{
    // reset this so we get the real position
    objElementToMove.style.top = 0; 
    var intReferenceDivAbsY = CSWFunctions_FindAbsolutePosY( objReferenceElement );
    var intMovingDivAbsY = CSWFunctions_FindAbsolutePosY( objElementToMove );

    if ( intReferenceDivAbsY != intMovingDivAbsY )
    {
        var intDiff = intReferenceDivAbsY - intMovingDivAbsY;
    
        // set the element to move to be located on top of the reference element;
        // this position is relative to the parent at some negative interval
        // that is the difference between the reference and the moving divs from 
        // the root of the page.
        objElementToMove.style.top = intDiff; 
    }
}

// =========================================== CSWFunctions_ShowPleaseWaitPanel
// ===========================================
function CSWFunctions_ShowPleaseWaitPanel( strPleaseWaitPanelId, intWidth, intHeight )
{
    var objPanel = document.getElementById( strPleaseWaitPanelId );
    if ( objPanel )
    {
        objPanel.style.width = intWidth;
        objPanel.style.height = intHeight;
        CSWFunctions_CentreInWindow( strPleaseWaitPanelId, intWidth, intHeight, "" );
        objPanel.style.display = 'block';
    }
}

// =========================================== CSWFunctions_HidePleaseWaitPanel
// ===========================================
function CSWFunctions_HidePleaseWaitPanel( strPleaseWaitPanelId )
{
    var objPanel = document.getElementById( strPleaseWaitPanelId );
    if ( objPanel )
    {
        CSWFunctions_DisplaySelectBoxes();
        objPanel.style.display = 'none';
    }
}

// =========================================== CSWFunctions_SetCookie
// ===========================================
function CSWFunctions_SetCookie( cookieName , cookieValue )
{
    document.cookie=cookieName+ "=" +escape(cookieValue);
}

// =========================================== trim() method for String class
// ===========================================
String.prototype.trim = function() 
{
    var tempString = this.replace(/^\s+/, '');
    return tempString.replace(/\s+$/, '');
};


// ========================================================= CSWFunctions_CloseWindowAndOptionallyRefreshParent
// ========================================================= 
function CSWFunctions_CloseWindowAndOptionallyRefreshParent( blnRefreshParent, noParentRedirect ) 
{
    if ( blnRefreshParent )
    {
        var objParentWindow = window.opener;

        if ( objParentWindow == null )
        {
            if ( typeof noParentRedirect != 'undefined' )
            {
                window.resizeTo(1024, 768);
                window.moveTo( GetCenteredScreenXPos( 1024 ), GetCenteredScreenYPos( 768 ) );
                window.location = noParentRedirect;
            }
        }
        else
        {
            //Make sure the parent window is still
            //open before refreshing its contents.
            //The control statement is a cheap hack
            //to get around the fact that IE says the
            //'closed' property is always false, even
            //if the window no longer exists
            if( typeof( objParentWindow.document ) == 'object' ) 
            {
                objParentWindow.location.reload( true );
            }
        }
    }
    
    window.close();
}

// ========================================================= CSWFunctions_CloseWindowAndRedirectParent
// ========================================================= 
function CSWFunctions_CloseWindowAndRedirectParent( url, noParentRedirect  ) 
{
    var objParentWindow = window.opener;

    if ( objParentWindow == null )
    {
        if ( typeof noParentRedirect == 'undefined' )
        {
            window.location = url;
        }
        else
        {
            window.resizeTo(1024, 768);
            window.moveTo( GetCenteredScreenXPos( 1024 ), GetCenteredScreenYPos( 768 ) );
            window.location = noParentRedirect;
        }
    }
    else
    {
        //Make sure the parent window is still
        //open before refreshing its contents.
        //The control statement is a cheap hack
        //to get around the fact that IE says the
        //'closed' property is always false, even
        //if the window no longer exists
        if( typeof( objParentWindow.document ) == 'object' ) 
        {
            objParentWindow.location = url;
        }
        window.close();
    }
}

// =========================================== CSWFunctions_FilterChanged
// ===========================================
function CSWFunctions_FilterChanged( dropdown, previousValue, defaultIndex )
{
    for( var i = 0; i < dropdown.options.length; i++)
    {
        if ( ( i != defaultIndex || defaultIndex != -1 ) && dropdown.options[i].selected == true )
        {
            dropdown.options[i].className = "CSWStyle_DefaultChanged";
        }
        
        if ( dropdown.options[i].value == previousValue )
        {
            //clear preview selected
            dropdown.options[i].className = "";
        }
    } 
}

// ========================================================= CSWFunctions_CancelBubble
// ========================================================= 
function CSWFunctions_CancelBubble( evt )
{
    evt = (evt) ? evt : window.event;
    evt.cancelBubble = true;
}

// ========================================================= CSWFunctions_DisableSelect
// ========================================================= 
function CSWFunctions_DisableSelect( elementId )
{ 
    var element = document.getElementById(elementId);
    element.onselectstart = function () { return false; } // ie
    element.onmousedown = function () { return false; } // mozilla
}

// ========================================================= CSWFunctions_DisableSelect
// ========================================================= 
function CSWFunctions_OnCalendarClose( calendar )
{ 
    calendar.params.inputField.blur();     
}
