/*V7.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;						
	}
}




