/*V8.0*/
function confirmBox(messageStr,string,mode,submitValue, extraParams)
{
    if(confirm(messageStr))
    {
        if(mode == "link")
        {
          location.href = eval('"'+string+'"');
        }
        else if(mode == "submit")
        {
            DoPostBack(submitValue, extraParams, false);
        }
    }
};


function RemoveReportElement(ElementName)
{
    var ReportName = document.forms[0].hdnReportName.value;
    var AvailableElements = document.forms[0].hdnAvailableElements.value;
    var DefaultElements = document.forms[0].hdnDefaultElements.value;
    var originalLocation = escape(document.location.href);
    var NewLocation = "Report-Customization.aspx?ReportName=" + ReportName + 
                      "&Elements=" + AvailableElements + 
                      "&DefaultElements=" + DefaultElements + 
                      "&Location=" + originalLocation + 
                      "&Action=remove&ElementName=" + ElementName;
 

    confirmBox("Are you sure you wish to remove this element?",NewLocation,"link");
    
}

function ZoomItem(CrcidArray, OverrideDate, ExtraCGI)
{
    var originalLocation = escape(document.location.href);
     
    var newLocation = document.location.href;
    
    if( newLocation.indexOf("?") < 0 )
    {
        newLocation += "?";
    }
 
    newLocation = newLocation.replace(/#$/, '');
    
    var OverrideDateParam = "";
    
    if ( OverrideDate > 0 )
    {
      OverrideDateParam = "&OverrideDate=" + OverrideDate;
    }
    
    var nURL = newLocation + OverrideDateParam + "&action=zoom&crcids=" + CrcidArray.join("~") + "&back=" + originalLocation;
    
    
    //if( ! ( ExtraCGI == undefined ) )
    if( ExtraCGI )
    {
      nURL += "&" + ExtraCGI;
    }
    
        DMLoad(nURL);

    //document.location.href = nURL;
}


function CheckCount( myCheckBox, TotalPossibleItems )
{ 
    varItems = document.forms[0].hdnSelectedItemCount.value;
    if( myCheckBox.checked == true )
    {
      varItems++;
    }
    else
    {
      varItems--;
    }
    
    if( varItems > TotalPossibleItems )
    {
        alert("You may only select 10 items to filter.");
        myCheckBox.checked = false;
        varItems--;
    }
    document.forms[0].hdnSelectedItemCount.value = varItems;
}
function ValidateDataMiningItemForm(MaxItems)
{
  if( CheckSelectedItemsCount(MaxItems) ) 
   {
      DoPostBack('Save','',true);
   }
}

function CheckSelectedItemsCount(MaxItems)
{
  if( document.forms[0].hdnSelectedItemCount.value == 0 )
  {
    alert("You must select at least 1 item to be added to the filter.");
    return false;
  }
  else if( document.forms[0].hdnSelectedItemCount.value > MaxItems )
  {
    alert("You may only select " + MaxItems + " items to filter.");
    return false;
  }
  return true;
}

function UpdateList( myCheckBox, Section, ItemCRCID, ItemName, IsExclude )
{      
    
    myCheckBox = eval("document.forms[0]." + myCheckBox);

    if( myCheckBox.checked )
    {
        AddToList(myCheckBox, Section,ItemCRCID, ItemName, IsExclude);
    }
    else
    {   
        RemoveFromList(myCheckBox, Section,ItemCRCID, ItemName, IsExclude);
    }
}

function AddToList(myCheckBox, Section, ItemCRCID, ItemName, IsExclude )
{
    var myHdnTxt;
    if(!IsExclude)
      {
        myHdnTxt = eval("document.forms[0].hdnSelected" + Section);
      }
    else
      {   
        myHdnTxt = eval("document.forms[0].hdnExcluded" + Section);    
      }

    if(myHdnTxt.value == "" )
    {
        myHdnTxt.value = ItemCRCID;
    }
    else
    {
        var tempVar  = myHdnTxt.value;
        tempVar = tempVar.replace(/[^~]*/g, '');
        var NumberOfItems = tempVar.length;
        
        if( NumberOfItems == 9 )
        {
            alert("You may only select 10 items");
            myCheckBox.checked = false;
            return;
        }

        myHdnTxt.value += "~" + ItemCRCID;
        
    }
    
    if( ! IsExclude )
    {
        myHdnTxt = eval("document.forms[0].hdnSelected" + Section + "Names");
    }
    else
    {
        myHdnTxt = eval("document.forms[0].hdnExcluded" + Section + "Names");
    }

    
    if( myHdnTxt.value == "" )
    {
        myHdnTxt.value = ItemName;
    }
    else
    {
        myHdnTxt.value += "~" + ItemName;
    }

}

function RemoveFromList(myCheckBox, Section, ItemCRCID, ItemName, IsExclude)
{
    var myHdnTxt 
    if( ! IsExclude )
    {
        myHdnTxt = eval("document.forms[0].hdnSelected" + Section);
    }
    else
    {
        myHdnTxt = eval("document.forms[0].hdnExcluded" + Section);    
    }

    if( myHdnTxt.value != "" )
    {
        var newString;
        newString = myHdnTxt.value.replace(eval("/" + ItemCRCID + "/"),"");
        newString = newString.replace(/~~/,"");
        newString = newString.replace(/~$/,"");
        newString = newString.replace(/^~/,"");
        
        myHdnTxt.value = newString;
        
        if( ! IsExclude )
        {
            myHdnTxt = eval("document.forms[0].hdnSelected" + Section + "Names");
        }
        else
        {
            myHdnTxt = eval("document.forms[0].hdnExcluded" + Section + "Names");
        }


        ItemName = ItemName.replace(/\//g,"\\/");       
        newString = myHdnTxt.value.replace(eval("/" + ItemName + "/"),"");
        newString = newString.replace(/~~/g,"");
        newString = newString.replace(/~$/,"");
        newString = newString.replace(/^~/,"");
        
        myHdnTxt.value = newString;
    }
}

function ClearList( Section )
{
    var myHdnTxt = eval("document.forms[0].hdnSelected" + Section);
    myHdnTxt.value = "";

    myHdnTxt = eval("document.forms[0].hdnSelected" + Section + "Names");
    myHdnTxt.value = "";
}

function ClearExcludeList( Section )
{
    var myHdnTxt = eval("document.forms[0].hdnExcluded" + Section);
    myHdnTxt.value = "";

    myHdnTxt = eval("document.forms[0].hdnExcluded" + Section + "Names");
    myHdnTxt.value = "";
}


function CheckUncheckAll( CheckBoxLikeName, CheckItems )
{
  
  var arrLen = document.forms[0].elements.length;
  
  var r = new RegExp('^'+CheckBoxLikeName);
  
  for(var c=0; c<arrLen; c++)
    {
      if(document.forms[0].elements[c].name.match(r))
        {
          document.forms[0].elements[c].checked = CheckItems;
        }
    }

}

function ChangeImage(iName, iSrc)
{
  eval('document.'+iName+'.src = "'+iSrc+'";');
}

var preloaded = new Array();

function PreloadImage( iSource)
{
  var arrLen = preloaded.length;
  preloaded[arrLen] = new Image();
  preloaded[arrLen].src = iSource;

}

function FilterList(ListID)
{
   var FilterValue = eval("document.forms[0].txt" + ListID + "Filter.value");

    Location = document.location.href;

    var rgx = eval("/" + ListID + "Offset\=[^\?\&]*/g");
    Location = Location.replace(rgx, '');
    
    rgx = eval("/" + ListID + "Filter\=[^\?\&]*/g");
    Location = Location.replace(rgx, '');
    
    Location = Location.replace(/\&\&/g, '&');
    Location = Location.replace(/\?\&/g, '?');
    
    if ( Location.indexOf("?") < 1 )
      Location += "?";

    Location += "&" + ListID + "Filter=" + FilterValue;
    CustomPost(Location);
}


//Added Javaless calendar functions
function DoPostBackWithXY(action, extraparams, cleanURL, scroll)
{
  if ( cleanURL )
    cleanURL = true
  
  var FormAction;
  if( document.forms[0].action.indexOf( '#' ) != -1 )
    FormAction = document.forms[0].action.substr(0, document.forms[0].action.indexOf('#'));
  else
    FormAction = document.forms[0].action;
    
  if ( cleanURL == true )
  {
    if( FormAction.indexOf('?') != -1 )
      FormAction = document.forms[0].action.substr(0, document.forms[0].action.indexOf('?'));
  }
  
  if ( FormAction.indexOf("?") < 0 )
    FormAction += "?";
  
  if (FormAction.lastIndexOf("&") != ( FormAction.length - 1 ) )
    FormAction += "&";
  
  
  FormAction = RemoveParam( FormAction, "Action" );
  FormAction += "&Action=" + action;
  FormAction = FormAction.replace( /&+/g, "&" );

  if ( extraparams && extraparams != '')
  { 
    var ExtraParamsArr = extraparams.split( '&' );
    
      var arrLen = ExtraParamsArr.length;
    
      for( var i = 0; i < arrLen; i++ )
      {
        if ( ExtraParamsArr[i] != '' )
        {
          FormAction   = RemoveParam( FormAction, ExtraParamsArr[i].split( '=' )[0] );
        }
          
      }
    FormAction  +=  "&" + extraparams;
  }
  
  if ( scroll == "1" )
  {
    FormAction    = RemoveParam( FormAction, "yp" );
    FormAction    = RemoveParam( FormAction, "xp" );
  
    var top  = GetScrollY()
    var left = GetScrollX();
    
    FormAction   += "&yp=" + top + "&xp=" + left;
  }
    
  document.forms[0].action = FormAction;
  document.forms[0].submit();
  document.body.style.cursor = "wait"; 
  //ShowPleaseWait();
  return false;

}
function RemoveParam( URL, Param )
{
    var rgx = eval("/" + Param + "\=[^\?\&]*/g");
    URL = URL.replace(rgx, '');
    URL = URL.replace(/\&\&/g, '&');
    URL = URL.replace(/\?\&/g, '?');
    
    return URL;
}

function GetScrollX()
{
    var left = document.body.scrollLeft;
    
    if ( left == 0 )
    {
      left = window.document.documentElement.scrollLeft;
    }
    
    if ( left == 'undefined' || left == '' )
    {
      left = 0;
    }
    
    return left;
}

function GetScrollY()
{
    var top  = document.body.scrollTop;
    
    if ( top == 0 )
    {
      top = window.document.documentElement.scrollTop;
    }
    
    if ( top == 'undefined' || top == '' )
    {
      top  = 0;
    }
    
    return top;
}

function Show_Stuff(MenuName,item,yshift,params)
{
	Show_StuffXY(MenuName,item,0,yshift,params)
}

var MenuOpenedClass = 'SliceMenuItemOpen';
var MenuClosedClass = 'SliceMenuItem';
function Show_StuffXY(MenuName,item,xshift,yshift,params)
{
  OnClickParams     = params;
  
  var Click_Menu    = document.getElementById( MenuName );
  if ( ! Click_Menu )
  return;
  
  var object        = document.getElementById( item );
  var BlankDiv      = document.getElementById( 'BlankDiv' );
  
  parent.top.HideAllFrames();
  
  if ((parent.top.LastClosedItem != null) && (parent.top.LastClosedItem == object))
  {
    parent.top.LastClosedItem = null;
    return;
  }
  if (Click_Menu.style.display == "none")
    {     
      Click_Menu.style.display = "";
      Click_Menu.style.top = GetRealTopByObject( object ) + yshift - 1;
      
      var Left        = GetRealLeftByObject( object ) + 1 + xshift;
      var Right       = Left + Click_Menu.offsetWidth;
      var WindowWidth = BlankDiv.offsetWidth;

      if ( WindowWidth == 0 )
      {
        if ( window.innerWidth )
          WindowWidth = window.innerWidth - 17;
      }

      if ( WindowWidth > 0 && Right > WindowWidth )
      {
          Left -= ( Right - WindowWidth ) + 2;
      }

      Click_Menu.style.left = Left;              
      Click_Menu.style.zIndex = 900;
                    
      object.className = MenuOpenedClass;
        
      parent.top.LastMenu      = Click_Menu;
      parent.top.LastItem      = object;
      parent.top.HighlightItem = true;
    }
}

function ShowDateInfo( InfoText, SourceObj )
{
	document.getElementById( 'DateInfoText' ).innerHTML = "<font class=\"mini\" color=\"#000000\">"+InfoText+"</font>";
}

var TDArray = new Array('','', '', '','','','');
function HighLightWeek(HighLightWeekID,CssClass)
{
	var CalObj = document.getElementById( "NavCalendar" );
	var Rows = CalObj.getElementsByTagName( "tr" );
	var Columns = Rows[ HighLightWeekID ].getElementsByTagName( "td" );	
	
	
	for(var x=0;x<7;x++)
	{	
		//window.alert(CssClass);
		if(CssClass == '')
		{
			//window.alert(TDArray[x]);
			Columns[x].className = TDArray[x];
			//window.alert(Columns[x].className);
		}
		else
		{
			TDArray[x] = Columns[x].className;
			if(Columns[x].className == "CalTable" || Columns[x].className == "CalHighlight")
			{
				Columns[x].className = CssClass;
			}
			//window.alert(TDArray);			
		}				
	}
}

var OldCalendarRows = new Array('','','','','','','');
var OldCalendarColumns = new Array(7);
function HighLightMonth(CssClass)
{
	var CalObj = document.getElementById( "NavCalendar" );
	var Rows = CalObj.getElementsByTagName( "tr" );
	var Columns;
	var Fonts;
	
	for(var x=1;x<Rows.length;x++)
	{
		Columns = Rows[x].getElementsByTagName( "td" );
		OldCalendarColumns= OldCalendarRows[x];
		if( OldCalendarColumns.length < 1 )
		{
			OldCalendarColumns = new Array(7);
		}			
		for(var y=0;y<Columns.length;y++)
		{
			if(CssClass == '')
			{
			  
				Columns[y].className = OldCalendarColumns[y];	
					
			}
			else
			{
				if(Columns[y].className == "CalTable" || Columns[y].className == "CalHighlight")
				{
					OldCalendarColumns[y] = Columns[y].className
					
				
					Fonts = Columns[y].getElementsByTagName( "font" );
					if(Fonts.length < 2)
					{
						Columns[y].className = "TableHover";
					}
					else
					{
						Columns[y].className = "CalDisabled";
					}						
				}
				else
				{
					OldCalendarColumns[y] = Columns[y].className;
					Columns[y].className = "CalDisabled";
				}								
			}				
		}
		OldCalendarRows[x] = OldCalendarColumns;						
	}
}

function MN(value)
{
  value = value.replace(/\$|\,|\%|[^0-9]/gi,'');

  if ( ! value || value == "-" || value == "" )
  {
    return "";
  }
  return parseFloat(value);
}


var OnClickParams  = null
var LastMenu       = null;
var LastItem       = null;
var LastItemObj    = null;
var HighlightItem  = null;
var LastClosedItem = null;

function Show_PopUpMenu(MenuName, CallingFrame, item, xshift, yshift,params, HighlightItem)
{
  var MenuFrame    = parent.top.document.getElementById( 'Menus' );
  var Menu         = parent.top.Menus.document.getElementById( MenuName );
  var DisplayFrame = parent.top.document.getElementById( CallingFrame );
  var ItemObj      = document.getElementById( item );
  var BlankDiv     = document.getElementById( 'BlankDiv' );

  if ( parent.top.LastItem != null )
      Hide_PopUpMenu();
      
  parent.top.HideAllFrames();
  parent.top.LastItem    = item;
  parent.top.LastItemObj = ItemObj;
  parent.top.LastMenu    = MenuName;
  
  Menu.style.display      = '';
  MenuFrame.style.display = '';    
  
  parent.top.Menus.SetOpenMenuItem( LastItem );
  parent.top.Menus.SetOpenMenuName( LastMenu );
  parent.top.Menus.SetOnClickParams( params );
  MenuFrame.style.height  = Menu.offsetHeight;
  MenuFrame.style.width   = Menu.style.width;
  //MenuFrame.style.top     = parent.top.GetRealTopByObject( DisplayFrame ) + MouseY + yshift - 1;
  //MenuFrame.style.left    = ( parent.top.GetRealLeftByObject( DisplayFrame ) + MouseX ) - MN( MenuFrame.style.width );
  
  MenuFrame.style.display = "";
  MenuFrame.style.top     = ( parent.top.GetRealTopByObject( DisplayFrame ) + GetRealTopByObject( ItemObj ) + yshift - 1 ) - GetScrollY();
  
    
  var Left        = GetRealLeftByObject( DisplayFrame )  + GetRealLeftByObject( ItemObj ) + 1 + xshift;
  Left           -= GetScrollX();

  var Right       = GetRealLeftByObject( ItemObj ) + 1 + xshift + Menu.offsetWidth;
  Right          -= GetScrollX();
  var WindowWidth = BlankDiv.offsetWidth;
    
  if ( WindowWidth == 0 )
  {
    if ( window.innerWidth )
      WindowWidth = window.innerWidth - 17;
  }

  if ( WindowWidth > 0 && Right > WindowWidth )
  {
      Left -= ( Right - WindowWidth ) + 2;
  }
    
  MenuFrame.style.left    = Left;
  MenuFrame.style.zIndex  = 900;

  if ( HighlightItem )
  {
      ItemObj.className            = MenuOpenedClass;
      parent.top.HighlightItem     = true;
      parent.top.Menus.SetHighlight( true );
  }      
  else
  {
      parent.top.HighlightItem     = null;
      parent.top.Menus.SetHighlight( null );
  }
}
function Hide_PopUpMenus()
{
  var Divs = parent.top.Menus.document.getElementsByTagName( "div" );
  
  for( var i = 0; i < Divs.length; i++ )
  {
      Divs[ i ].style.top     = 0;
      Divs[ i ].style.left    = 0;
      Divs[ i ].style.display = 'none';
  }
  
  if ( parent.top.LastItemObj )
    parent.top.LastItemObj.className = MenuClosedClass;
  
  parent.top.LastItem     = null;
  parent.top.LastItemObj  = null;
  parent.top.LastMenu     = null;
  
}
function Hide_PopUpMenu()
{
    if ( parent.top.LastItemObj != null )
    {
      var MenuFrame    = parent.top.document.getElementById( 'Menus' );
      var Menu         = parent.top.Menus.document.getElementById( parent.top.LastMenu );

      Menu.style.top     = 0;
      Menu.style.left    = 0;
      MenuFrame.style.display = 'none';
      Menu.style.display      = 'none';
      
      parent.top.Menus.SetHighlight( null );

      if ( parent.top.HighlightItem )
      {
        parent.top.LastItemObj.className = MenuClosedClass;
      }  
      
      parent.top.LastItem     = null;
      parent.top.LastItemObj  = null;
      parent.top.LastMenu     = null;
  }   
}


function GetRealTop(zName)
{
  var obj   = document.getElementById(zName);
  return GetRealTopByObject( obj );
};


function GetRealLeft(zName)
{
  var obj   = document.getElementById(zName);
  return GetRealLeftByObject( obj );
};


function GetRealLeftByObject(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function GetRealTopByObject(obj )
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
		
	return curtop;
}



function GetHeightByObject( obj )
{
  return obj.offsetHeight;
}

function GetHeight(ele)
{
  var obj   = document.getElementById(ele);
  return GetHeightByObject( obj );
}


function GetBestTextColor( Color )
{
  var R = parseInt('0x' + Color.substring( 1, 3 ) );
  var G = parseInt('0x' + Color.substring( 3, 5 ) );
  var B = parseInt('0x' + Color.substring( 5, 7 ) );
  var Luminosity = (R * 0.299) + (G * 0.587 ) + (B * 0.114);

  if(Luminosity > 150)
  {
    return "#000000";
  }
	  
	return "#FFFFFF";
}

function getProperties( obj )
{
    var Buffer = ""

    for (var property in obj)
    {
        Buffer += property + " = " + obj[ property ] + "<Br>";
    }
    
    return Buffer;
}

function GetPageHeight()
{
    var Height = document.body.offsetHeight;
        
    if ( parent.top.IsMSIE )
      Height -= 4;
      
    return Height;
}

function GetParent( Obj )
{
  if ( Obj.parentNode )
    return Obj.parentNode;
  
  if ( Obj.parentElement )
    return Obj.parentElement
    
  return null;
}

function ShowHideAlt( Object, FrameName, Text, OffsetX, OffsetY )
{
  var AltFrame = parent.top.document.getElementById( "AltFrame" );

  if ( parent.top.AltFrame.OpenAltFrame == Object )
  {
    HideAltFrame();
    return;
  }

  ShowAltFrame( Object, "AltFrame", FrameName, Text, OffsetX, OffsetY );
  parent.top.AltFrame.OpenAltFrame = Object;
}

function HideAltFrame()
{
  parent.top.AltFrame.OpenAltFrame = null;
  var AltFrameObj = parent.top.document.getElementById( "AltFrame" );
  AltFrameObj.style.left = -500;
  AltFrameObj.style.top  = -500;
}

function ShowAltFrame( Object, FrameName, ParentFrameName, Text, OffsetX, OffsetY )
{
  ShowFrame( Object, "AltFrame", ParentFrameName, Text, OffsetX, OffsetY, true )
}

function ShowFrame( Object, FrameName, ParentFrameName, Text, OffsetX, OffsetY, ExcludeScrollPos )
{
  parent.top.HideAllFrames();
  var FrameObj    = parent.top.document.getElementById( FrameName ); 
  var ParentFrame = parent.top.document.getElementById( ParentFrameName ); 
  
  var left = GetRealLeftByObject( ParentFrame ) + GetRealLeftByObject( Object );
  var top  = GetRealTopByObject( ParentFrame ) + GetRealTopByObject( Object );
  
  
  if ( ExcludeScrollPos )
  {
    var ScrollOffset = eval( "parent.top." + ParentFrameName + ".GetScrollY();" );
    top -= ScrollOffset;
  }
    
    
  if ( OffsetX )
    left += OffsetX;
  
  if ( OffsetY )
    top += OffsetY;

  eval( 'parent.top.' + FrameName + '.WriteContent( Text )' );

  var FrameRight  = left + MN( FrameObj.style.width );
  var BlankDiv    = parent.top.document.getElementById( "BlankDiv" ); 
  var WindowWidth = BlankDiv.offsetWidth;

  if ( WindowWidth == 0 )
  {
    if ( parent.top.window.innerWidth )
    WindowWidth = parent.top.window.innerWidth;
  }
  
  if ( WindowWidth > 0 && FrameRight > WindowWidth )
  {
    left -= ( FrameRight - WindowWidth ) + 16;
  }

  FrameObj.style.left = left + "px";
  FrameObj.style.top  = top + "px";

  parent.top.OpenFrame = FrameName;
}

function HideDropDownLists()
{
    var Inputs = document.getElementsByTagName( "select" );
    
    for ( var i = 0; i < Inputs.length; i++ )
    {
      Inputs[ i ].style.visibility = 'hidden';
    }
}


function ShowDropDownLists()
{
    var Inputs = document.getElementsByTagName( "select" );
    
    for ( var i = 0; i < Inputs.length; i++ )
    {
      Inputs[ i ].style.visibility = 'visible';
    }
}