var DISPLAY_FRAME 	= 'displayFrame';
var NAVBAR_FRAME 	= 'navBarFrame';
var MENU_FRAME 	= 'menuFrame';
var MENU_TOP_FRAME 	= 'menuTop';
var NAVBAR_FORM		= 'NavbarFRM';


// Determine browser.
if (typeof(Is)=='undefined') {
        function Is() {
            agent  = navigator.userAgent.toLowerCase();
            this.major = parseInt(navigator.appVersion);
            this.minor = parseFloat(navigator.appVersion);
            this.ns    = ((agent.indexOf('mozilla')   !=   -1) &&
                         ((agent.indexOf('spoofer')   ==   -1) &&
                         (agent.indexOf('compatible') ==   -1)));
            this.ns2   = (this.ns && (this.major      ==    3));
            this.ns3   = (this.ns && (this.major      ==    3));
            this.ns4b  = (this.ns && (this.major      ==    4) &&
                         (this.minor                  <= 4.03));
            this.ns4   = (this.ns && (this.major      <    5));
            this.ns6    = (this.ns && (this.major     >=    5));
            this.ie    = (agent.indexOf("msie")       !=   -1);
            this.ie3   = (this.ie && (this.major      <     4));
            this.ie4   = (this.ie && (this.major      ==    4) &&
                         (agent.indexOf("msie 5.0")   ==   -1));
            this.ie5   = (this.ie && (this.major      ==    4) &&
                         (agent.indexOf("msie 5.0")   !=   -1));
            this.ie55  = (this.ie && (this.major      ==    4) &&
                         (agent.indexOf("msie 5.5")   !=   -1));
        }
}

if (typeof(is)=='undefined'){
        var is = new Is();
}
/**
     * return true if this array contains this value
     */
    function contain(array,value) {
        for(var i = 0;i<array.length;i++) {
            if(array[i] == value) {
                return true;
            }
        }
        return false;
    }
    function SelectAll(type) {
        var oSelected = document.getElementsByName(type);
        if(oSelected.length){
           for(var i=0; i<oSelected.length; i++){
             oSelected[i].checked = true;
           }
        }else{
          oSelected.checked = true;
        }
        return false;
      }

    function SelectNone(type){
        var oSelected = document.getElementsByName(type);
        if(oSelected.length){
           for(var i=0; i<oSelected.length; i++){
             oSelected[i].checked = false;
           }
        }else{
          oSelected.checked = false;
        }
      }

    function InvertSelection(type){
        var oSelected = document.getElementsByName(type);
        if(oSelected.length){
           for(var i=0; i<oSelected.length; i++){
             oSelected[i].checked = !oSelected[i].checked;
           }
        }else{
          oSelected.checked = !oSelected.checked;
        }
      }

      function ValidateFilter(filter) {
        //var st = new String(filter);
        return true;
      }


/*******************************************************************************
 * this function signals the auto refresh mechanism that it can start counting
 * the refresh time.
 * this should avoid a situation where a refresh happens when user drills down
 ******************************************************************************/
function allowAutoRefresh(allow){
    var navBar = getNavBarFrame();
    if(!navBar){
        return false;
    }
    navBar.bRefreshAllowed = allow;
}

 // The function will check that all the characters in strToCheck variable
 // defined in the strLegalCharSet string.
 // In case of full match the function returns true else false.
    function MatchCharacters(strToCheck, strLegalCharSet){
     // not allow null as parameters.
     if( strToCheck == null || strToCheck == "" ||
   strLegalCharSet == null || strLegalCharSet == "" ){
   return false;
  }

     var strName = new String(strToCheck);
     for(var i=0;i<strName.length;i++){
   var ch = strName.charAt(i);
   if(strLegalCharSet.indexOf(ch) == -1){
    // Case of illegal character
             return false;
    }//if
  }//for
     return true;
 }


 // The function trims a given string aka  string.trim() since javascript doesn't have that method
function trimString(str){
    var i;
    var iPrefix = null
    var iSuffix ;
    if (str){
    for (i=0;i<str.length;i++){
            if (str.charAt(i) != ' ' ){
                if (iPrefix == null) iPrefix = i // mark the first occurrence of letter
                iSuffix = i+1
      }//if
    }//for
        str = str.substring(iPrefix,iSuffix)
    }
    else{
        str = '';
    }
    return str;
}


// This function is suppose to be empty !!
// Please do not delete ! This is used as a general data structure
// (In JavaScript anything is possible)
function ReportEvent()
{

}

function setFilters(dimensionStr)
{
   var topazState = getNavBarForm();
   topazState.all.ActiveFilters.value = dimensionStr;
}

function clearFilters()
{
   var topazState = getNavBarForm();
   topazState.clearFilters.value = "true";
   topazState.submit();
}

//if true new window will be open
function showReport(isNewWindow)
{
    var topazState = getNavBarForm();
    if(isNewWindow)
        topazState.target="newWindow";
    else
        topazState.target="displayFrame";
}
function setReport(reportName)
{
    var topazState = getNavBarForm();
    topazState.reportName.value= reportName;
}
function setStartTime(startTime)
{
    var topazState = getNavBarForm();
    topazState.startTime.value= startTime;
}
function setEndTime(endTime)
{
    var topazState = getNavBarForm();
    topazState.endTime.value= endTime;
}
function setStepUnit(stepUnit)
{
    var topazState = getNavBarForm();
    if (topazState != null){
        topazState.stepUnit.value= stepUnit;
    }
}
function setStepValue(stepValue)
{
    var topazState = getNavBarForm();
    if (topazState != null && topazState.stepValue != null){
        topazState.stepValue.value= stepValue;
    }
}
function setTimeFrameUnit(timeFrameUnit)
{
    var topazState = getNavBarForm();
    topazState.timeFrameUnit.value= timeFrameUnit;
}
function setTimeFrameValue(timeFrameValue)
{
    var topazState = getNavBarForm();
    topazState.timeFrameValue.value= timeFrameValue;
}
function setTimeFrame(timeFrame) {
    var topazState = getNavBarForm();
    topazState.timeFrame.value= timeFrame;
}
function setDimention(dim)
{
    var topazState = getNavBarForm();
    topazState.ActiveFilters.value = dim;
}

function setMultiProfileFilters(dim)
{
    var topazState = getNavBarForm();
    topazState.MultiActiveFilters.value = dim;
}

function setTarget(target)
{
    var topazState = getNavBarForm();
    topazState.target= target;
}

function replaceDelim(stringToReplace,oldDelim,newDelim)
{
        var str=new String(stringToReplace);
        // create regular expresion with "\\" at start to prevent confusion
        // with special characters (*,#, etc) and
        // add "g" flag to replace all appearances of the oldDelim
        var regExpresion = new RegExp("\\"+oldDelim, "g");
        var newString=str.replace(regExpresion,newDelim);
        return newString;
}

/**
 * this function will update event according to received
 * dimension and start time and call to drill down function
 */
function sendEvent(dimension,startTime,event) {

    if(typeof(dimension) != 'undefined' && dimension != null && dimension.length > 0) {
        event.dimension = dimension;
        var profile = getProfileId(dimension);
        if(profile != null) {
            event.profile = profile;
        }
    }
    if(typeof(startTime) != 'undefined' && startTime != null && startTime.length > 0) {
        event.startTime = startTime;
    }
    drilldown(event);
}


/**
 * this function supposes that dimension string is in following format
 * <profileId>_<dimType>_<dimValue>,<profileId>_<dimType>_<dimValue>,...
 * and <profileId> is same for all dimensions
 *
 * @param dimension string in format <profileId>_<dimType>_<dimValue>,<profileId>_<dimType>_<dimValue>,...
 * @return profile id for this dimension string
 */
function getProfileId(dimension) {
    var profileIndex = dimension.indexOf("_");
    if(profileIndex == -1) {
        //error
        return null;
    }
    return dimension.substring(0,profileIndex);
}



///handle all drilldown events
function drilldown(ev)
{
  // special check for j2ee license
  if (ev && ev.reportName && (ev.reportName=='J2EE_drilldown_summary' || ev.reportName=='J2EE_drilldown_trend')) {
    if (typeof(checkJ2EELicense)=='undefined' || !checkJ2EELicense()) {
      return; // don't drilldown
    }
  }

  // when drilling down - must reset the user's changes on the navbar
  getNavBarForm().reset();
  // No more refreshes after drill down
  allowAutoRefresh(false);

  if((ev && ev.newWindow && ev.displayFrame) ||  (typeof(window.giveFocusToParent) != "undefined" && !window.giveFocusToParent))
    //setting to false if event is new window and if giveFocusToParent was not already set as false
    //needed for noc so focus will go to new window and not main window,
    // must be before getNavBarForm() because noc report overrides this function
    window.giveFocusToParent = false;
  else
    //set to true if not a new window, meaning going to displayFrame (main window)
    //must set back to true if drill down from noc first to new window --> giveFocusToParent=false
    //and now drill down to main display frame we need --> giveFocusToParent = true
    window.giveFocusToParent = true;

  var topazState = getNavBarForm();
  var target = topazState.target;
  var len=topazState.elements.length;
  var formValues=new Array();
  for(var i=0;i<len;i++)
  {
      formValues[i] = topazState.elements[i].value;
  }

  if(ev.simulateTableFirstCellEvent)
    topazState.simulateTableFirstCellEvent.value = ev.simulateTableFirstCellEvent;
  if(ev.destName)
      topazState.destName.value = ev.destName;
  if(ev.measurementName)
      topazState.measurementName.value = ev.measurementName;
  if(ev.groupName)
      topazState.groupName.value = ev.groupName;
  if(ev.groupId)
      topazState.groupId.value = ev.groupId;
  if(ev.locationName)
      topazState.locationName.value = ev.locationName;
  if(ev.currentIndex)
      topazState.currentIndex.value = ev.currentIndex;
  if(ev.maxAggregationType)
      topazState.maxAggregationType.value = ev.maxAggregationType;
  if(ev.timeFrame)
      setTimeFrame(ev.timeFrame);

  if(ev.clearFilters)
      topazState.clearFilters.value = ev.clearFilters;
  if(ev.trackIndex)
      topazState.trackIndex.value = ev.trackIndex;
  if(ev.startTime)
      setStartTime(ev.startTime);
  if(ev.endTime)
      setEndTime(ev.endTime);
  if(ev.stepUnit)
      setStepUnit(ev.stepUnit);
  if(ev.stepValue)
      setStepValue(ev.stepValue);
  if(ev.timeFrameUnit)
      setTimeFrameUnit(ev.timeFrameUnit);
  if(ev.timeFrameValue)
      setTimeFrameValue(ev.timeFrameValue);
  if(ev.dimension)//can be no change in dimentions
  {
      if(ev.specialDelim)//special delim was used to delim fields
              ev.dimension=replaceDelim(ev.dimension,ev.specialDelim,",");
      setDimention(ev.dimension);
  }
  if(ev.multiProfileFilters)
    setMultiProfileFilters(ev.multiProfileFilters);


  //J2ee component report sort
  if(ev.j2eeSortBy)
    topazState.j2eeSortBy.value = ev.j2eeSortBy;
  if(ev.j2eeSortDirection)
    topazState.j2eeSortDirection.value = ev.j2eeSortDirection;
  if(ev.j2eeResourceType)
    topazState.j2eeResourceType.value = ev.j2eeResourceType;

  topazState.clearClonnable.value = true;
  if(ev.displayFrame)
    setTarget(ev.displayFrame);

  if(ev.newWindow)
  {
      if(ev.displayFrame)
      {
              if(ev.windowParams)
              {
                      if(ev.specialDelim)//special delim was used to delim fields
                              ev.windowParams=replaceDelim(ev.windowParams,ev.specialDelim,",");
                      window.open("",ev.displayFrame,ev.windowParams);
              }
              else
                      window.open("",ev.displayFrame);
              setTarget(ev.displayFrame);

      }
  }
  if(ev.profile)
      topazState.filterProfileId.value=ev.profile;
  if(ev.breakdown)
      topazState.breakdown.value=ev.breakdown;

  //if this is another report
  if(ev.reportName) {
      //alert("ev.reportName = "+ev.reportName + " topazState.reportName.value = "+topazState.reportName.value);
      if(ev.reportName != topazState.reportName.value) {
        setReport(ev.reportName);
      }
  }

  if(typeof(ev.displayFrame) == 'undefined' || ev.displayFrame == null || ev.displayFrame.length == 0 || ev.displayFrame == DISPLAY_FRAME) {
    if (typeof(ev.appendCrumb) == 'undefined' || ev.appendCrumb)
      topazState.BreadCrumbAction.value = "append"; // the drill down should be tracked in Bread Crumb
    else
      topazState.BreadCrumbAction.value = "leave"; // next/prev - not a "real" drilldown - does not append
    submitNavBarForm();
  } else {
    // the drill down should not be tracked in Bread Crumb, since it is opened in a separate window/frame
    topazState.BreadCrumbAction.value = "leave";
    topazState.submit();
  }

  if(ev.restore){
    for(var i=0;i<len;i++){
              if(topazState.elements[i].name!="destName"&&topazState.elements[i].name!="locationName" && topazState.elements[i].name!="groupName")
                      topazState.elements[i].value=formValues[i];
    }//for
      topazState.target = target;
  }

}
/***********************************************************************
  IBMReport:this method builds a report drilldown Event from the given params
  this function is used only from IBMRawDataHelper.java
***********************************************************************/
function drillIntoError(bNewWindow,displayFrame,dimensionDesc,startTime){
    var ev=new ReportEvent();
    ev.reportName	= 's_failed_transactions';
    ev.displayFrame = displayFrame;
    ev.restore   	= true;
    ev.dimension 	= dimensionDesc;
    ev.startTime 	= startTime;
    //ev.timeFrame 	= '5Minutes'; // not in use anymore since the move to time units
    ev.timeFrameUnit='minute';
    ev.timeFrameValue='15';
    ev.newWindow 	= bNewWindow;
    ev.windowParams = "height=300,width=800,location=0,toolbar=0,resizable=1"
    drilldown(ev);

}

function getNavBarForm() {
        var navbarForm = null;
        var navbarFrame = getNavBarFrame()
        if (navbarFrame)
                navbarForm = eval('navbarFrame.document.' + NAVBAR_FORM);
        if (!navbarForm )
                window.status = 'could not get navBar form';
        return navbarForm
}

function getNavBarFrame(){
        //alert("getNavBarFrame="+window.name);
        if(window.name == NAVBAR_FRAME) {
            return window;
        }

        var dispFrame = getDispFrame();
        var navbarFrame = null;

        //alert("dispFrame="+dispFrame);
        if (dispFrame){
          navbarFrame = dispFrame.frames[NAVBAR_FRAME];
        }

        if (!navbarFrame && typeof(getCustomNavBarFrame) != "undefined") {
          navbarFrame = getCustomNavBarFrame();
        }

        if (!navbarFrame)
          window.status = "navbar frame could not be found";
        return navbarFrame;
}

/**
*  Search for current active frame or for "targetFrame" if defined in active report RDL
*/
function getDispFrame() {

  //no menu found in this frame, so this is standle alone frame, so return the parent
        if(typeof(top.applicationsFramework) == 'undefined')
        {
            return window.parent;
        }

        var appFrame = top.applicationsFramework.getApplicationFrame();

		var menu = appFrame.menu;

		//a change to support display frame (in use when working with VT component)
		if (typeof(menu) == 'undefined')
		{
			//if the app frame doesn't have the menu - take it from
			//the app display frame
			var appDisplayFrame = top.applicationsFramework.getApplicationDisplayFrame();
			return appDisplayFrame.menu.getActiveFrame();
		}

        return appFrame.menu.getActiveFrame();

     }

// Submits NavBar form in case of filters change: time frame, active profile, active filters
function submitNavBarFormFiltered() {
    getNavBarForm().BreadCrumbAction.value = "reset";
    submitNavBarForm();
  }
/**
* Search for current active frame, change target for nav bar from to this frame and submit nav bar
*/
function submitNavBarForm() {

    if(typeof(top.applicationsFramework) != 'undefined') {
      top.applicationsFramework.showClock();
    }

    var disFrame = getDispFrame();
    var navBarForm = getNavBarForm();
    var navBarFrame = getNavBarFrame();
    if(navBarFrame.targetFrame == null) {
        navBarForm.target = disFrame.name;
    } else {
       navBarForm.target = navBarFrame.targetFrame;
    }

    navBarForm.submit();
}


// The function trim all spaces from the beggining and the end of the given name
function TrimSpaces(name){
    var tmpName 	= "";
    var retValue 	= "";
    var bCharacterFound = false;

    // Drop spaces from the start.
    for(var i=0;i<name.length;i++){
        if(name.charAt(i)!=" "){
            bCharacterFound = true;
        }

        if(bCharacterFound){
           tmpName += name.charAt(i)
        }
    }

    // Drop spaces from the end.
    bCharacterFound = false;
    for(var i=tmpName.length-1;i>=0;i--){
        if(tmpName.charAt(i)!=" "){
            bCharacterFound = true;
        }

        if(bCharacterFound){
           retValue = tmpName.charAt(i) + retValue;
        }
    }

    return retValue;
}

// the function will check the validity of the sub-report name in terms of
// special characters like ", ', &, @ ...
// the following characters are allow: ()-_+=[]{}|:;<>.,
// In case the function gets null or string with spaces only as parameter it returns true.
function isContainSpecialCharacter(name){
    // not allow null as parameter.
    if(name==null) return true;

    // Not allow empty/space only strings
    if(TrimSpaces(name)=="") return true;

    var strName = new String(name);
    for(var i=0;i<strName.length;i++){
        if( strName.charAt(i)=="\'" ||
            strName.charAt(i)=='\"' ||
            strName.charAt(i)=="*" ||
            strName.charAt(i)=="&" ||
            strName.charAt(i)=="^" ||
            strName.charAt(i)=="%" ||
            strName.charAt(i)=="$" ||
            strName.charAt(i)=="#" ||
            strName.charAt(i)=="@" ||
            strName.charAt(i)=="!" ||
            strName.charAt(i)=="~" ||
            strName.charAt(i)=="`" ||
            strName.charAt(i)=="?" ||
            strName.charAt(i)=="/" ||
            strName.charAt(i)=="\\"||
            strName.charAt(i)=="<" ||
            strName.charAt(i)==">"
            )
            return true;
    }
    return false;
}

// the function will check the validity of the sub-report name in terms of
// special numeric characters only.
// the function will return true in case of all numeric else false.
function IsNumeric(name){
        return !isNaN(Number(name));
}
//------------------------------- the following functions handle the menu selection --------------
function selectMenu(id) {
  /****** deprectead and unsupported anymore, we do not want drilldowns to change menu selection ******/
    /*var MenuPage;
    MenuPage = getTreeMenu()
    if (MenuPage) {
        MenuPage.colorItemId(id)
    } */
    return false;
}

function getTreeMenu(){
    var appFWObj = top.getApplicationsFramework();
    var menuFrame = appFWObj.getApplicationFrame();
    return menuFrame;
                }


function OpenHelp(nsURL,ieURL){
        var sWinOptions = "toolbar=no,resizable=yes,height=650,top=10,left=10,width=860,scrollbars=yes";
        var sWinName = "UserGuidePdf";
        // By default this is explorer
        var currURL = ieURL;
        if (is.ns) {
            currURL = nsURL;
        }

        window.open(currURL, sWinName, sWinOptions);
}

//------------------------------------- Cookies --------------------------------



function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}



// computes string length, in bytes, according to DB character encoding
// str - the input string
// encoding - the DB character encoding
// encoding can get one of three values:
// ANSI - native code page, could be multi-byte.
// UCS2 - Unicode wide chars (2 bytes per character).
// UTF-8 - a varying-length variation on Unicode.
// the assumption is that all browsers handle strings internally as Unicode.
//return the number of the bytes in the string,according to the specified encoding
//return -1 for un recognized encoding

function getByteLength(str,encoding)
{
// There are four possible ranges of Unicode values, by which we can
// know the character's size (in bytes). In actuality, only UTF-8
// is effected by the third and fourth ranges
    var first, second, third, fourth;
    var length=0;
    switch(encoding){
        case "ANSI" :
            first=second=1;
            third=fourth=2;
            break;

        case "UCS2" :
            length = (str.length)*2;
            return length;

        case "UTF-8" :
            first=1;
            second=2;
            third=3;
            fourth=4;
            break;

        default:
            return -1;

    }
    for (i=0;i<str.length;i++)
    {
        var val=str.charCodeAt(i);//returns the character`s UNICODE decimal value
        if(val<=127)
            length+=first;
        else if(val<=2047)
            length+=second;
        else if(val<=65535)
            length+=third;
        else length+=fourth;
    }
    return length;
}

/*******************************************************************************
 *                              Filters                                        *
 *******************************************************************************/

 // Represents a PairObject structure
function PairObject(key, value){
  this.key = key;
  this.value = value;
}

/**
 * The function will filter the given array according to the pattern
 * and return a filtered array sorted according to the given compare function.
 * Note:
 *      The compare function is optional.
 *      The filters will ignore case.
 *      The function supports the following filters:
 *      - <*> Will filter nothing.
 *      - <*Text> Will filter all the names ends with the "Text".
 *      - <Text*> Will filter all the names starts with the "Text".
 *      - <*Text*> Will filter all the names contains the "Text".
 *      - <Text> Will filter all the names with the exact "Text" name.
 *
 * @param arrToFilter - an array of PairObject objects to be filter.
 *                      The filters will be on the PairObject,value string.
 * @param pattern     - The pattern to be filtered.
 * @param compareFunc - An optional compare function, to order the return value.
 * @return Array      - Contain a filtered PairObject objects.
 * @auther <a href="mailto:yossia@mercury.co.il">Yossi Admon</a>
 */
function Filter(arrToFilter, pattern, compareFunc){
    var retVal = new Array();
    // We compare to lower case.
    var innerPattern = pattern.toLowerCase();
    var iPatternType = -1;
    if(pattern == "*"){ // Case <*>
        retVal = arrToFilter;
    } else {
        if(pattern.indexOf("*") == 0 && (pattern.length-1) == pattern.lastIndexOf("*")){
            // Case <*Text*>
            iPatternType = 2;
            innerPattern = innerPattern.substr(1, innerPattern.length - 2);
        } else if(pattern.indexOf("*") == 0 && pattern.length != pattern.lastIndexOf("*")){
            // Case <*Text>
            iPatternType = 0;
            innerPattern = innerPattern.substr(1);
        } else if((pattern.length-1) == pattern.lastIndexOf("*")){
            // Case <Text*>
            iPatternType = 1;
            innerPattern = innerPattern.substr(0, innerPattern.length -1);
        } else {
            // Case <Text>
            iPatternType = 3;
        }

        // Iterate the array
        for(var i=0; i<arrToFilter.length; i++){
            var name = arrToFilter[i].value.toLowerCase();
            switch (iPatternType){
                case 0 : {     // <*Text>
                    if(name.length >= innerPattern.length && name.substr(name.length - innerPattern.length) == innerPattern){
                        retVal[retVal.length] = arrToFilter[i];
                    }
                    break;
                }
                case 1 : {     // <Text*>
                    if(name.indexOf(innerPattern) == 0){
                        retVal[retVal.length] = arrToFilter[i];
                    }
                    break;
                }
                case 2 : {     // <*Text*>
                    if(name.indexOf(innerPattern) > -1){
                        retVal[retVal.length] = arrToFilter[i];
                    }
                    break;
                }
                case 3 : {     // <Text>
                    if(name == innerPattern){
                        retVal[retVal.length] = arrToFilter[i];
                    }
                    break;
                }
            }
        }
    }

    // If there is compare function, filter according.
    if(typeof(compareFunc) == 'function'){
        retVal.sort(compareFunc);
    }
    return retVal;
}

/**
 * The function compair PairObject object String values.
 * It ignore case.
 * @param a - the first PairObject to be compair.
 * @param b - the second PairObject to be compair to.
 * @return Number 0 - if both (a and b) are euqals, 1 if a is bigger than b else -1.
 * @auther <a href="mailto:yossia@mercury.co.il">Yossi Admon</a>
 */
function CompPairObjectStringValuesIgnoreCase(a, b){
    var aName = a.value.toLowerCase();
    var bName = b.value.toLowerCase();
    if(aName == bName){
        return 0;
    }
    if(aName > bName){
        return 1;
    }

    return -1
}

/**
 * The function compair PairObject object values.
 * It ignore case.
 * @param a - the first PairObject to be compair.
 * @param b - the second PairObject to be compair to.
 * @return Number 0 - if both (a and b) are euqals, \
 *                positive number if a is bigger than b,
 *                negative number if b is bigger than a.
 * @auther <a href="mailto:yossia@mercury.co.il">Yossi Admon</a>
 */
function CompPairObjectNumberValuesIgnoreCase(a, b){
    return parseInt(a.value) - parseInt(b.value);
}

//return the number of the bytes in the string encoded in UTF-8

function getUTF8ByteLength(str){
    return getByteLength(str,"UTF-8");
}

/**
 * Used in analysis bottom reports, in order to set the 'excel' div in the top frame.
 * The 'excel' div in the top analysis reports is used when the "download to excel"
 * is selected.
 * @return void
 */
function changeExcelDynamicLinkInAnotherFrame(frameName, newExcelLink) {
    var excelLink = frameName.origExcelKeys;
    if (excelLink != ""){
        excelLink = excelLink + '_'+ newExcelLink;
    }
    else {
            excelLink = newExcelLink;
    }
    frameName.excelKeys = excelLink;
}

function generateReport(){
  var navBarFrame = getNavBarFrame();
  navBarFrame.submitAll();
}

function Parameter(name,value) {
  this.name = name;
  this.value = value;
}

function drillToDiagnostics(drillFrom,url,from,to)
{
 	params = "drill_from=" + drillFrom + "&page_url=" + url + "&time_from=" + from + "&time_to=" + to;
	opener.top.openDifferentContextWindow(
            'MercuryDiagnostics',
            '/opal/uibridge/action/controller.do?type=app&action=initial&'+params);
}