/*************************************************************************************
Description of File:  Common JavaScript functions used in the portal application.
*************************************************************************************/

//
// Define the browsers
//
var ces_ieBr = document.all;
var ces_ns6Br = document.getElementById && !document.all;
var ces_ns4Br = document.layers;
var ces_macbr = navigator.appVersion.indexOf("Mac") != -1;
var ces_supportedBrowser = ces_ieBr || ces_ns6Br || ces_ns4Br;

var ces_tkHeights = new Array();
function ces_tkHeight(id, height) {
  this.id = id;
  this.height = height;
}

var offsetxpoint=0;
var offsetypoint=0;
	
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}	

//
// Define global variables
//
function ces_change_src(iframe, src)
{
	try
	{
		if(iframe && src)
			iframe.src = src;	
	} catch(exception)
	{
	}			
}

function ces_mapObj(id, type) {
  this.id=id;
  this.type=type;
}

var ces_maxRowSelect = -1;

// Variable used to determine whether to highlight a row and show the task list.
// If it is true, then the row will not be "selected" and the task list won't
// appear.  All items with the "tasklink" prefix set this var to true.
var ces_linkClick = false;
var ces_activeToolkit = ""; // an int flag that equals the active toolkit
var ces_isThumbnailView = false;
var ces_lastRowObj;
var ces_lastSrcId;
var ces_selectedThumbnail;
var ces_selectedKey;
var ces_ENTER_KEY = 13;
var ces_SHIFT_KEY = 16;
var ces_CTRL_KEY = 17;
var ces_ARROW_LEFT = 37;
var ces_ARROW_UP = 38;
var ces_ARROW_RIGHT = 39;
var ces_ARROW_DOWN = 40;
var ces_DELETE_KEY = 46;
var ces_X_KEY = 88;
var ces_C_KEY = 67;
var ces_V_KEY = 86;
var ces_selectedList = new Array();
var ces_pivot; // The row object ces_pivot that is used for multi select
var ces_activeComponentId = -1;
var ces_pointedId = -1;
var ces_pointerId = -1;
var ces_pointedRow = -1;
var ces_currCompId = -1;
var ces_activeCompManageList = -1;
var ces_activeCompSurroundTable = -1;
var ces_currentPageUrl = '';
var _ces__EVENTTARGET = '';
var _ces__EVENTARGUMENT = '';
var _ces__ButtonX = '';
var _ces__ButtonY = '';
var _ces__VIEWSTATE = '';

var _syndicated__EVENTARGUMENT = '';
var _syndicated__EVENTTARGET = '';
var _syndicated__VIEWSTATE = '';

var _ces_clientId = '';
var _ces_nsbr_xcoord = 0;
var _ces_nsbr_ycoord = 0;

// TODO: desc of this array and obj below
var ces_componentArray = new Array();

function ces_syncomp(comp_id, scheme, host, path, portal)
{
	var url;
		
	if(scheme && host && path && portal)
	{
		url = scheme + '://' + host + path + '/portalcontent.aspx?galleryComponentId=' + comp_id + '&outputFormat=text/html&encoded=true&_synHost=' + host + '&_synPath=' + path + '&portalName=' + portal;
	}
	else
	{
		url = 'portalcontent.aspx?galleryComponentId=' + comp_id + '&outputFormat=text/html&encoded=true';
	}
	ces_staticLoadScript(url);
}

function ces_staticLoadScript(url)
{
	var qs = document.location.search;
	
	var ramp = /&/gi;
	qs=qs.replace(ramp, '&amp;');
	url=url.replace(ramp, '&amp;');
	
	if(qs.length > 0 && qs.substring(0,1) == '?')
		qs = qs.substring(1);
	qs += '&amp;_synRawUrl=' + escape(document.location.pathname + document.location.search);
	
	if(_ces__EVENTTARGET != '')
	{
		alert(_ces__EVENTTARGET);
		qs += '&amp;__EVENTTARGET=' + _ces__EVENTTARGET;
	}	
	if(_ces__EVENTARGUMENT != '')
	{
		alert(_ces__EVENTARGUMENT);
		qs += '&amp;__EVENTARGUMENT=' + _ces__EVENTARGUMENT;
	}
	
	if(_ces__VIEWSTATE != '')
	{
		alert(escape(_ces__VIEWSTATE).replace(/\+/g,'%2b'));	
		qs += '&amp;__VIEWSTATE=' + escape(_ces__VIEWSTATE).replace(/\+/g,'%2b');
	}

	document.write('<script src="', url + '&amp;' + qs, '" type="text/JavaScript"></script>');
}

function ces_portalComponent(id, name) 
{
  this.id = id;
  this.name = name;
}

/*************************************************************************************
Function:     ces_execServerPull
Parameters:   (String)url - the url to be loaded
Description:  This function is called to cause a server url to load with no effect on
			  the current page.
*************************************************************************************/
var ces_serverPullIFrame = null;
function ces_execServerPull(e, url, callback)
{
	if(!ces_serverPullIFrame)
	{
		try
		{
			ces_serverPullIFrame = document.createElement('iframe');
			ces_serverPullIFrame.setAttribute('id','spIFrame');
			ces_serverPullIFrame.style.display = 'none';
			ces_serverPullIFrame.style.width = '0px';
			ces_serverPullIFrame.style.height = '0px';
			ces_serverPullIFrame.style.border = '0px';
			document.body.appendChild(ces_serverPullIFrame);
		
		} catch(exception)
		{
			var iframeHTML='\<iframe id="spIFrame" style="';
			iframeHTML+='display:none;';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			ces_serverPullIFrame = new Object();
			ces_serverPullIFrame.document = new Object();
			ces_serverPullIFrame.document.location = new Object();
			ces_serverPullIFrame.document.location.iframe = document.getElementById('spIFrame');
			ces_serverPullIFrame.document.location.replace = function(location) {
				this.iframe.src = location; }		
		}
	}
	var IFrameDoc;
	if(ces_serverPullIFrame.contentDocument) 
	{
		// For NS6
		IFrameDoc = ces_serverPullIFrame.contentDocument; 
	} else if (ces_serverPullIFrame.contentWindow) 
	{
		// For IE5.5 and IE6
		IFrameDoc = ces_serverPullIFrame.contentWindow.document;
	} else if (ces_serverPullIFrame.document) 
	{
		// For IE5
		IFrameDoc = ces_serverPullIFrame.document;
	} else 
	{
		return true;
	}
  
    if(callback)
    {
		var funcPtr = new Function(callback);
		if(funcPtr)
			ces_serverPullIFrame.attachEvent('onload', funcPtr );
	}			

    IFrameDoc.location.replace(url);
    return false;
}

/*************************************************************************************
Function:     ces_taskSelected
Parameters:   (string)path - the path to set the current location.  This is the custom handler.
              (string)task - the CES task id (see CES task documentation)
              (bool)isPopup - should the task be opened in a new window
              (int)rowNum - the row in the component's table that the user clicked on
              (int)elementId - the component id being acted on
              (int)width - the initial width of popup
              (int)height - the initial height of popup
              (bool)async - specifies if call should use ces_execServerPull
              (string)callback - defines a callback function to exec after the server pull
Description:  This function is called when a task is selected from a dynamically
              drawn toolkit in the components.
*************************************************************************************/
function ces_taskSelected(path, task, isPopup, rowNum, 
						elementId, width, height, async, callback, isModal, onExecute) 
{

  try {
    if (onExecute == 'return false;')
      return;
  } catch (exception) {
  
  }
  
  if(ces_pointerId > -1) {
    path = path.replace(ces_pointedId, ces_pointerId);
  }

  var bContinue = true;
  if (task.indexOf("alert_delete") > -1) {
    if (task.indexOf("multi") > -1) {
      if (!confirm('Are you sure you want to PERMANENTLY delete these Alerts?')) {
        bContinue = false;
      }
    } else {
      if (!confirm('Are you sure you want to PERMANENTLY delete this Alert?')) {
        bContinue = false;
      }
    }
  } else if (task.indexOf("_delete") > -1) {
    if (task.indexOf("multi") > -1) {
      if (!confirm('Are you sure you want to PERMANENTLY delete these items?')) {
        bContinue = false;
      }
    } else {
      if (!confirm('Are you sure you want to PERMANENTLY delete this item?')) {
        bContinue = false;
      }
    }
  }  else if (task.indexOf("remove") > -1) {
    if (!confirm('Are you sure you want to remove this item?')) {
      bContinue = false;
    }
  } else if (task.indexOf("_publish") > -1) {
    if (!confirm('Are you sure you want to publish this item?')) {
      bContinue = false;
    }
  } else if (task.indexOf("_unpublish") > -1) {
    if (!confirm('Are you sure you want to un-publish this item?')) {
      bContinue = false;
    }
  } else if (task == "recycle_bin_clear") {
    if (!confirm('Are you sure you want to PERMANENTLY clear the recycle bin?')) {
      bContinue = false;
    }
  }

  if (bContinue) 
  {
    var ProcessArea = document.getElementById('ProcessAlert');

    // If no custom handler, submit back to the current page and use the ces form fields
    if (path == '') {    
		
      if (ProcessArea) 
        ces_showProcessArea();
      		
		  if(document.getElementById('ces_task'))
			  document.getElementById('ces_task').value = task;
  			
		  if(document.getElementById('ces_component'))
			  document.getElementById('ces_component').value = elementId;
  			
		  if(document.getElementById('selected_toolkit_row'))
			  document.getElementById('selected_toolkit_row').value = rowNum;
        
      if(onExecute) {
        var funcPtr = new Function(onExecute);
        if(funcPtr)
          funcPtr();
		  } else {
			  //__doPostBack("","");
			  document.forms[0].submit();
		  }
		
    // else a custom handler is defined
    } else {
    
      if (async && async == 1) {
		    ces_execServerPull(null, path, callback);
        ces_hideToolkit(ces_activeToolkit);
		    return;
		    
	    } else if (isPopup == 'true' || isPopup == 'True') {
	    
		    if(isModal || isModal == 'true') 
			    ces_openModalWin(path, width, height);
		    else
			    ces_openWin(path, width, height);
			
        if (ProcessArea)
          ces_hideProcessArea();
 
        ces_hideToolkit(ces_activeToolkit);
      } else {   
        var ProcessArea = document.getElementById('ProcessAlert');
        if (ProcessArea && path.toLowerCase().indexOf("documentviewer.aspx") == -1 && path.toLowerCase().indexOf("export") == -1 && path.toLowerCase().indexOf("movecontent.aspx") == -1) {
          ces_showProcessArea();
        }
        document.location=path;
      }
    }
  }
}

/*************************************************************************************
Function:     ces_openDocument
Parameters:   (string)path - the path of the document viewer web form
              (int)rowNum - the row containing the document
Description:  Opens a document by calling the DocumentViewer.aspx web form.  Also
              hides the toolkit because clicking the document will fire the show
              toolkit.
*************************************************************************************/
function ces_openDocument(componentId, path, rowNum) {
  ces_hideToolkit(componentId + "-" + rowNum);
  document.location = path;
}

/*************************************************************************************
Function:     ces_openWin
Parameters:   (String)url - the url the popup window will render
Parameters:   (int)width - the width of the popup (OPTIONAL)
Parameters:   (int)height - the height of the popup (OPTIONAL)
Description:  Opens the passed in url in a new common sized window.  (Common)
*************************************************************************************/
function ces_openWin(url, width, height) {
  var leftPos = 100;
  var topPos = 5;
  if (width == null) {
    width = 650;
  }
  if (height == null) {
    height = 550;
  }     
  var openWin = window.open(url, '_blank', 'resizable=yes,titlebar=no,scrollbars=yes,width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos);
  if(!openWin)
  {
	alert("You must disable your pop-up blocker for this site.");
  }
}

/*************************************************************************************
Function:     ces_openModalWin
Parameters:   (String)url
Description:  Opens the passed in url in a new common sized modal window.  (Common)
TODO: not yet implemented.  Do later.  For now, opens smaller win.
*************************************************************************************/
function ces_openModalWin(url, width, height) {

  var ProcessArea = document.getElementById('ProcessAlert');
  if (ProcessArea)
    ces_hideProcessArea();

  //var openWin = window.open(url, '_blank', 'resizable=yes,scrollbars=yes,width=650,height=400,left=100,top=50');
  if (width == null)
    width = 500;
  if (height == null)
    height = 400;
  if (document.body.onclick == null) {
    document.body.onclick=ces_checkModal;
  }
  if (document.body.onfocus == null) {
    document.body.onfocus=ces_checkModal;
  }
  ces_openDGDialog(url, width, height, '');
  return false;
}

function ces_openDocBrowserWin(url) {
  ces_openModalWin(url, 700, 400);
}

/*************************************************************************************
Function:     ces_closeOpenWin
Parameters:   (String)locationStr - OPTIONAL
Description:  closes a popup window after setting the opener's location (if applicable)
*************************************************************************************/
function ces_closeOpenWin(locationStr) {
  if (locationStr != null) {
    opener.document.location = locationStr;
  }
  window.close();
}

function ces_GetToolkitDiv(rowNum, componentId) {
  var toolkitDiv;

  //temp - not using
  _ces_clientId = '';

  if (rowNum == "multi")
    toolkitDiv = document.getElementById(_ces_clientId + componentId + "_toolkit-MULTI");
  else
    toolkitDiv = document.getElementById(_ces_clientId + componentId + "_toolkit-" + rowNum);
    
  return toolkitDiv;
}

/*************************************************************************************
Function:     ces_showToolkit
Parameters:   (int)rowNum
Description:  Displays a toolkit (a list of tasks in a table).
*************************************************************************************/
function ces_showToolkit(componentId, rowNum, evt, x, y) {

  ces_currCompId = componentId;
//alert(componentId);
  var toolkitDiv = ces_GetToolkitDiv(rowNum, componentId);

  if (toolkitDiv != null) 
  { 
    var toolkitTable = document.getElementById(componentId + 'DynToolkitTable-' + rowNum);
//alert('table ' + toolkitTable);
    var tempTk = toolkitDiv.innerHTML;

    // Clear all pointers
    ces_pointedId = -1;
    ces_pointedRow = -1;
    ces_pointerId = -1;

    toolkitDiv.style.visibility = 'visible';

		var curX=0;
		var curY=0;

		if (x != null)
		  curX = x;
		else
		  curX = (ces_ns6Br)?evt.pageX : event.clientX+ietruebody().scrollLeft;
		  
		if (y != null)
		  curY = y;
		else
		  curY = (ces_ns6Br)?evt.pageY : event.clientY+ietruebody().scrollTop;

		//Find out how close the mouse is to the corner of the window
		var rightedge=ces_ieBr&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-evt.clientX-offsetxpoint-20;
		var bottomedge=ces_ieBr&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-evt.clientY-offsetypoint-20;

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<toolkitDiv.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			toolkitDiv.style.left=ces_ieBr? ietruebody().scrollLeft+event.clientX-toolkitDiv.offsetWidth+"px" : window.pageXOffset+evt.clientX-toolkitDiv.offsetWidth+"px";
		else if (curX<leftedge)
			toolkitDiv.style.left="5px";
		else
			//position the horizontal position of the menu where the mouse is positioned
			toolkitDiv.style.left=curX+offsetxpoint+"px";

		if (curY < toolkitDiv.offsetHeight) {
		  if (bottomedge<toolkitDiv.offsetHeight)
		    toolkitDiv.style.top=curY-100+"px";
		  else
        toolkitDiv.style.top=curY+offsetypoint+"px";
    }
		else if (bottomedge<toolkitDiv.offsetHeight)
			toolkitDiv.style.top=ces_ieBr? ietruebody().scrollTop+event.clientY-toolkitDiv.offsetHeight-offsetypoint+"px" : window.pageYOffset+evt.clientY-toolkitDiv.offsetHeight-offsetypoint+"px";
		else
			toolkitDiv.style.top=curY+offsetypoint+"px";

    if (rowNum == "multi") {
  
      //11/9/04
      var multiTable = document.getElementById(componentId + "DynToolkitTable-MULTI");

      for (var i=multiTable.rows.length - 1; i >= 1; i--) {
        multiTable.deleteRow(i);
      }

      // This jscript function is build in DocumentUtil.cs
      // or in any file that needs to utilize multi select.
      try {
      //mcummings
        eval('buildTaskList_' + componentId + '()');
      } catch (exception) {

      }
    }
  } else if (rowNum == 'multi') {

  } else { // Toolkit Div is null

    var sourceId = '';
    var sourceObj = ces_getRightClickSourceObj(evt);
    if (sourceObj != null)
      sourceId = sourceObj.id;

    var itemType = ces_getRowItemBySource('itemtype', sourceId);

    var itemId = ces_getRowItemBySource('itemid', sourceId);

    if (itemType == 'folder' || itemType == 'CES.NET.ContentCategory')
      itemType = 'c';
    else if (itemType == 'element' || itemType == 'CES.NET.ContentElement')
      itemType = 'e';
    else if (itemType == 'package' || itemType == 'CES.NET.ContentPackage')
      itemType = 'p';
    else if (itemType.indexOf('calendarEntry') > -1)
      itemType = 'calentry';
    else if (itemType.indexOf('calendarDay') > -1)
      itemType = 'calday';
    else if (itemType.indexOf('cesxmlcomp') > -1)
      itemType = 'cesxmlcomp';
    else if (itemType.indexOf('portalbox') > -1)
      itemType = 'portalbox';
    else if (itemType.indexOf('breadcrumb') > -1) {
      var breadIndex = itemType.indexOf('breadcrumb');
      var code = itemType.substring(breadIndex + 10, breadIndex + 11);
      itemType = 'breadcrumb' + code;
    }
    else if (itemType.indexOf('rbc') > -1)
      itemType = 'rbc';   
    else if (itemType.indexOf('rbe') > -1)
      itemType = 'rbe';     
    //else if (itemType.indexOf('TeamSpaceTemplate') > -1)
    //  itemType = 'TeamSpaceTemplate';         

//alert(itemType);   
//alert(itemId);  
    if (ces_ns6Br) {

			if (x != null)
				_ces_nsbr_xcoord = x;
			else
				_ces_nsbr_xcoord = evt.clientX;
			  
			if (y != null)
				_ces_nsbr_ycoord = y;
			else
				_ces_nsbr_ycoord = evt.clientY;  

      //_ces_nsbr_xcoord = evt.clientX;
      //_ces_nsbr_ycoord = evt.clientY;
    }
    var bComplete = false;
	  try {

		  var customPostBack = eval('__ces_postbackftn_' + componentId);
		  //var urlHost = eval('url_' + componentId);
		  var urlHost = eval('url_rclk');
		  var tReturnUrl = '';
  
		  try 
			{
				tReturnUrl = eval('returnUrl_rclk');
			} catch(Exception){}		  

		  ces_generateRightClickPostBackMenu(tReturnUrl, customPostBack, urlHost, componentId, rowNum, itemId, itemType, "ces_toolkitCallback");
		  bComplete = true;
			  
	  } catch(Exception){}

    if (!bComplete) {

      var rtPkgId = 0;
	    var rtDocId = 0;
	    try 
	    {
		    rtPkgId = eval('rootPkgId_' + componentId);
	    } catch(Exception){}
	    try 
	    {
		    rtDocId = eval('rootDocId_' + componentId);
	    } catch(Exception){}
	    
      // If this is an element in a package, set the type to package element
      if (rtPkgId > 0 && itemType == 'e')
      {
        itemType = 'pe';
        itemId = rtPkgId + '-' + itemId;
      }
      if (rtPkgId > 0 && itemType == 'package_package')
      {
        itemType = 'pp';
        itemId = rtPkgId + '-' + itemId;
      }

      if (rtDocId > 0 && itemType == 'document_package')
      {
        itemType = 'ep';
        itemId = rtDocId + '-' + itemId;     
      }
      if (rtPkgId > 0 && itemType == 'package_element')
      {     
        itemId = rtPkgId + '-' + itemId;
      }

			var returnUrl = '';
			
	    try 
	    {
		    //var urlHost = eval('url_' + componentId);
		    var urlHost = eval('url_rclk');
		    try 
				{
					//returnUrl = eval('returnUrl_' + componentId);
					returnUrl = eval('returnUrl_rclk');
						
				} catch(Exception){}

				//052606
				/*
				if (itemType == null || itemType == '')
				{
				  componentId = '0';
				  rowNum = '0';
				  itemId = '0';
					itemType = 'cespage';
				}
				*/
				//********
		    ces_generateItemToolkit(urlHost, returnUrl, componentId, rowNum, itemId, itemType, "ces_toolkitCallback", evt);			    
	    } catch(Exception){}
	  }
  }
}

function ces_toolkitCallback(data, componentId, row)
{
  if (data == null || data == '')
    return;

  var divObj = document.createElement('div');

  document.body.appendChild(divObj);
  
  divObj.innerHTML = data;
  ces_showToolkit(componentId, row);
}

function ces_toolkitCallback_ns(e, data, componentId, row, x, y)
{

  if (data == null || data == '') {
  //alert('here');
    if (ces_ns6Br) {
      data = document.getElementById('spIFrame').contentDocument.body.innerHTML;
    } else {
      return;
    }
  }
//alert(data);
  var divObj = document.createElement('div');

  document.body.appendChild(divObj);
  
  divObj.innerHTML = data;

  ces_showToolkit(componentId, row, e, x, y);
}

/*************************************************************************************
Function:     ces_hideToolkit
Parameters:   (string)tk - toolkit = componentId + "-" + rowNum;
Description:  Hides a document toolkit.
*************************************************************************************/
function ces_hideToolkit(tk) {

  var dash = tk.indexOf("-");
  var rowNum = tk.substring(dash + 1, tk.length);
  var componentId = tk.substring(0, dash);

  var cid = '';
  
  try {
    cid = ces_getRowItemBySource('componentid', ces_lastRowObj.id);
  } catch (exception) {}

  if (componentId == '')
    componentId = cid;

  var toolkitDiv;
  if (ces_pointedRow > -1)
    toolkitDiv = ces_GetToolkitDiv(ces_pointedRow, componentId);
  else
    toolkitDiv = ces_GetToolkitDiv(rowNum, componentId);

  if (toolkitDiv != null) {
    //toolkitDiv.style.display="none";
    toolkitDiv.style.visibility = 'hidden';
  }
}

/*************************************************************************************
Function:     ces_highlightToolkitRow
Parameters:   (int)num - the toolkit number
              (Object)row - the <tr> to highlight
              (int)size - number of rows in the toolkit
Description:  Highlights a particluar row of the toolkit.
NOTE: FOR MULTI TOOLKIT ONLY
*************************************************************************************/
function ces_highlightToolkitRow(compId, num, row, size) { 

  // TODO: size should be determined by numrows of table all the time
  if (num == 'MULTI') {
    var multiTable = document.getElementById(compId + "DynToolkitTable-MULTI");
    if (multiTable != null) {
      size = multiTable.rows.length - 1;
    }
  }

  //document.body.style.cursor = 'hand';
  var thisRow = -1;
  if (row != null) {
    thisRow = row.id;
  }

  for (var n=0; n < size; n++) {
  	
    row = document.getElementById(compId + "toolkit-" + num + "-row-" + n);

    for (var i=0; i < row.cells.length; i++) {    
      if (thisRow == row.id) {
        row.cells[i].className="selected";
      } else {
        row.cells[i].className="";
      }
    }
  }
}

/*************************************************************************************
Function:     ces_highlightRow
Parameters:   (Object)rowObj - the <tr> to highlight
              (int)rowNum - the row number
Description:  Highlights a particluar row of a table when a user clicks on it.
*************************************************************************************/
function ces_highlightRow(rowObj, rowNum) {

  tempLastRow = rowObj;

  // Loop through each cell in the row and change the className
  for (var i=0; i < rowObj.cells.length; i++) {    
    rowObj.cells[i].className="selected";
  }

  if (ces_lastRowObj != null) {
    if (ces_lastRowObj.id != rowObj.id) {
      for (var i=0; i < ces_lastRowObj.cells.length; i++) {    
        ces_lastRowObj.cells[i].className="";
      }
    }
  }  
  
  ces_lastRowObj = rowObj;
}

var tempLastRow = null;

/*************************************************************************************
Function:     ces_highlightTempRow
Parameters:   (Object)rowObj - the <tr> to highlight
              (int)num - the row number
Description:  Highlights a particluar row of a table when a user mouses over 
              the row.
*************************************************************************************/
function ces_highlightTempRow(rowObj, rowNum) {

  for (var i=0; i < rowObj.cells.length; i++) {
    if (ces_lastRowObj.id == rowObj.id) {
      rowObj.cells[i].className="selected";
    }
    else {
      rowObj.cells[i].className="selected-temp";
    }
    
    if (tempLastRow.id != ces_lastRowObj.id) {
      tempLastRow.cells[i].className="";
    }
  }
  tempLastRow = rowObj;
  document.body.style.cursor = 'hand';
}

/*************************************************************************************
Function:     ces_mouseOutOfRow
Parameters:   (Object)rowObj - the <tr> to unselect
              (int)num - the row number
Description:  Sets the row that is moused out of to a non-selected state unless
              the row is the selected row (the row clicked).
*************************************************************************************/
function ces_mouseOutOfRow(rowObj, rowNum) {

  for (var i=0; i < rowObj.cells.length; i++) {
    if (ces_lastRowObj.id == rowObj.id) {
      rowObj.cells[i].className="selected";
    }
    else {
      rowObj.cells[i].className="";
    }
  }
  document.body.style.cursor = 'auto';  
}

function ces_getParentSourceObj(strId, sourceObj) {

  //var parentSourceObj = sourceObj.parentElement;
  //082205 - fix for Firefox
  var parentSourceObj = ces_ns6Br ? sourceObj.parentNode : sourceObj.parentElement;

  while (parentSourceObj != null) {
    if (parentSourceObj.id.indexOf(strId) > -1)
      break;
    else
      //parentSourceObj = parentSourceObj.parentElement;
      parentSourceObj = ces_ns6Br ? parentSourceObj.parentNode : parentSourceObj.parentElement;
  }
  return parentSourceObj;
}

//TODO: DESC
function ces_getRightClickSourceObj(evt) {

  var parentSourceObj = null;
  var sourceObj = ces_ns6Br ? evt.target : event.srcElement;
  var sourceId = null;

  if (sourceObj != null)
    sourceId = sourceObj.id;
  else
    return null;

  try {
    if (sourceId.indexOf("link") > -1) {
      sourceObj = ces_ns6Br ? sourceObj.parentNode : sourceObj.parentElement;//sourceObj.parentElement;      
      sourceId = sourceObj.id;
    }
  } catch (exception) {
  }

  // desc
  if (sourceId.indexOf("r_clk") != -1 
    || sourceId.indexOf("breadcrumb") != -1) {
    return sourceObj;
  
  } else {
    parentSourceObj = ces_getParentSourceObj('r_clk', sourceObj);
  }

  // If still no valid object, see if there is a portal box right click menu
  if (parentSourceObj == null || parentSourceObj.id.indexOf("r_clk") == -1) {
    parentSourceObj = ces_getParentSourceObj('cesportalbox', sourceObj);
  }
  
  return parentSourceObj;
}

/*************************************************************************************
Function:     ces_showRightClickToolkit
Parameters:   (Object)evt - the DOM event object (netscape only)
Description:  Displays a toolkit (a list of tasks in a table) when the user right
              clicks the right area of the document.  Declared for oncontextmenu
*************************************************************************************/
function ces_showRightClickToolkit(evt){

  var componentId = null;
  var sourceId = null;

  var sourceObj = ces_getRightClickSourceObj(evt);
  if (sourceObj != null) {
    sourceId = sourceObj.id;
    ces_lastSrcId = sourceId;
    componentId = ces_getComponentIdBySource(sourceObj);
  }

  if (componentId != null 
    && componentId > -1 
    && sourceId != null 
    && sourceId != '') {

    if (ces_isThumbnailView) {
      if(sourceId.indexOf("r_clk") > -1) {    
        var thumbnailPanel = document.getElementById(sourceId.replace('r_clk', 'thumbnail'));
        if (thumbnailPanel != null) {
          if (ces_selectedThumbnail != null)
            ces_selectedThumbnail.className = "ces-thumbnail-panel";
          ces_selectedThumbnail = thumbnailPanel;
          thumbnailPanel.className="ces-thumbnail-panel-selected";
        }
      }
    }

    var rowNum = ces_getRowItemBySource('rownum', sourceId);
//alert(sourceId);
    var rowObj = getRowObjectByNum(rowNum, componentId);
    if (ces_selectedList.length > 1) {
      var doesContain = false;
      for (var i=0; i < ces_selectedList.length; i++) {
        if (ces_selectedList[i] != null) {
          if (getRowNum(ces_selectedList[i]) == rowNum) {
            doesContain = true; 
            break;
          }
        }
      }
      if (!doesContain) {
        unHighlightAllRows();
        ces_selectedList = new Array();
        ces_selectedList[0] = rowObj;     
      }
    }

    // If multi select
    if (ces_selectedList.length > 1) {
      ces_hideRightClickToolkit(evt);
      ces_activeToolkit = 'MULTI';
      ces_showToolkit(componentId, 'multi', evt);
      return false;
      
    // else single select
    } else {
      ces_hideRightClickToolkit(evt);
      ces_showToolkit(componentId,rowNum,evt);
      ces_activeToolkit = componentId + "-" + rowNum;

      if (rowObj != null) {
        ces_selectedList[0] = rowObj;
        ces_highlightRow(rowObj, rowNum);
      }
      return false;
    }
  } else {
    _ces_clientId = '';
    ces_showToolkit(componentId,rowNum,evt);    
  }
}


// Takes a source id ex: component45...r_clk1-3 
//-> new component45...r_clk1-3-0-0
//-> or  component45...r_clk1-3-category-3275
//-> or  component45...r_clk1-3-category-3275_blah blah blah

function ces_getRowItemBySource(type, sourceId) {

  var dash = sourceId.indexOf("-");
  var dash2 = sourceId.indexOf('-', dash + 1);
  var dash3 = sourceId.indexOf('-', dash2 + 1);
  var finalDelim = sourceId.indexOf('_', dash3 + 1);//doesn't work for date because 8:30 is represented as 8_30 or what item items with "_" in their name?
  var elip = sourceId.indexOf("...");
  var len = sourceId.length;

  if (type == 'rownum') {
    if (dash2 == -1)
      return sourceId.substring(dash + 1, len);
    else
      return sourceId.substring(dash + 1, dash2);
  } else if (type == 'componentid') {
    var compStr = 'component';
    var componentStrIndex = sourceId.indexOf(compStr);
    return sourceId.substring(componentStrIndex + compStr.length, elip);  
  } else if (type == 'itemtype') {
    return sourceId.substring(dash2 + 1, dash3);
  } else if (type == 'itemid') {
    if (sourceId.indexOf("tv.") > -1)
      len = finalDelim;
    return sourceId.substring(dash3 + 1, len);
  } else if (type == 'clientid') {
    var componentStrIndex = sourceId.indexOf('component');
    return sourceId.substring(0, componentStrIndex);  
  } else {
    return '';
  }
}

function ces_getComponentInfo(id) {
  for (var i=0; i < ces_componentArray.length; i++) {
    if (ces_componentArray[i].id == id)
      return ces_componentArray[i].name;
  }
  return "";
}

/*************************************************************************************
Function:     ces_hideRightClickToolkit
Parameters:   (Object)evt - the DOM event object (netscape only)
Description:  Hides a portal toolkit.
*************************************************************************************/
function ces_hideRightClickToolkit(evt) {

try
{
	if(ces_activeMenuItems)
	{
		for (var i=ces_activeMenuItems.length-1; i>-1;i--) 
		{
			document.getElementById(ces_activeMenuItems[i]).style.visibility = 'hidden';	
			c_sif(false, ces_activeMenuItems[i]);
		}
		ces_activeMenuItems = new Array();
	}
} catch(exception)
{
}

  var sourceId = ces_ns6Br ? evt.target.id : event.srcElement.id;
  if (sourceId.indexOf("DynToolkit") == -1) {
    if (ces_activeToolkit == 'MULTI' || ces_activeToolkit != '') {
      ces_hideToolkit(ces_activeToolkit);
    }
  }
}

//111504
function ces_checkClick(evt) {
  var sourceId = ces_ns6Br ? evt.target.id : event.srcElement.id;
  if (sourceId.indexOf('dyntoolkitcell') == -1
      && sourceId.indexOf('ElementTaskButton') == -1) {
    ces_hideToolkit(ces_activeHtmlToolkit);
  }
}

//111504
var ces_activeHtmlToolkit = '';

function ces_showHtmlPlaceholderToolkit(compId, rowNum) {
  ces_activeHtmlToolkit = compId + '-' + rowNum;
  ces_showToolkit(compId, rowNum);
}

function ces_checkHtmlPlaceholderToolkit(evt) {
  var sourceId = ces_ns6Br ? evt.target.id : event.srcElement.id;
  if (sourceId.indexOf('ElementTaskButton') == -1)
    ces_hideToolkit(ces_activeHtmlToolkit);
}

/*************************************************************************************
Function:     ces_docClick
Parameters:   (Object)evt - the DOM event object (netscape only)
Description:  Hides a portal toolkit.
*************************************************************************************/
function ces_docClick(evt) {

  ces_checkHtmlPlaceholderToolkit(evt);
  
  var sourceId = '';
  var sourceObj = ces_getRightClickSourceObj(evt);
  if (sourceObj != null)
    sourceId = sourceObj.id;  

  if (ces_activeToolkit == 'MULTI' || ces_activeToolkit != "") {
    ces_hideToolkit(ces_activeToolkit);
  }
  if (sourceId.indexOf("r_clk") == -1) {
    unHighlightAllRows();
    ces_selectedList = new Array();  
    ces_activeComponentId = -1;
    ces_lastSrcId = null;
  } else {
    ces_activeComponentId = ces_getRowItemBySource('componentid', sourceId);
    ces_lastSrcId = sourceId;
  }

  // Begin Thumbnails
  if (sourceId != '' && ces_isThumbnailView) {
    if(sourceId.indexOf("r_clk") > -1) {
      var thumbnailPanel = document.getElementById(sourceId.replace('r_clk', 'thumbnail'));
      if (thumbnailPanel != null) {
        if (ces_selectedThumbnail != null)
          ces_selectedThumbnail.className = "ces-thumbnail-panel";
        ces_selectedThumbnail = thumbnailPanel;
        thumbnailPanel.className="ces-thumbnail-panel-selected";
      }
    }
  }
  // End thumbnails
  
  // hide any active toolbar items
  var editModeTB =  document.getElementById('ces_editmode_tb');
  if (editModeTB)
    ces_hideMenuDropDowns(event, editModeTB, '');
}

/*************************************************************************************
Function:     ces_disableRightClick
Parameters:   (Object)evt - the DOM event object (netscape only)
Description:  Hides the browser's default context menu when a user right clicks.
              An example to use this would be to add in your page: 
              document.oncontextmenu=ces_disableRightClick;
*************************************************************************************/
function ces_disableRightClick(evt) {
  return false;
}

/*************************************************************************************
Function:     ces_selectRow
Parameters:   (Object)rowObj - the <tr> row selected
Description:  Handle clicking a row or multiple rows based on what key is pressed.
*************************************************************************************/
function ces_selectRow(rowObj) {
//alert(ces_selectedKey);
  if (ces_selectedKey == ces_CTRL_KEY) {

    // if selected list has 0 items, this is ces_pivot
    if (ces_selectedList.length == 0)
      ces_pivot = rowObj;
      
    // if already selected, unselect!
    if (alreadySelected(rowObj)) {

      ces_removeFromSelected(rowObj);
      
      //unselect
      for (var i=0; i < rowObj.cells.length; i++) {    
        rowObj.cells[i].className="";
      }    
    } else {

      // Add to selected list
      ces_addSelectedRow(rowObj);
      
      //select
      for (var i=0; i < rowObj.cells.length; i++) {    
        rowObj.cells[i].className="selected";
      }
      ces_lastRowObj = rowObj;
    }

  } else if (ces_selectedKey == ces_SHIFT_KEY) {

    var rowNum = getRowNum(rowObj);
 
    // if selected list has 0 items, this is ces_pivot
    if (ces_selectedList.length == 0)
      ces_pivot = rowObj;
      
    if (rowNum > getRowNum(ces_pivot)) {
      shift('down', rowObj);
    } else {
      shift('up', rowObj);
    }
    ces_lastRowObj = rowObj;
  
  } else {
    ces_selectRowObject(rowObj);  
  }
}

/*************************************************************************************
Function:     ces_selectRowObject
Parameters:   (Object)rowObj - the <tr> row selected
Description:  TODO: add desc.
*************************************************************************************/
function ces_selectRowObject(rowObj) {
  
  unHighlightAllRows();
  ces_selectedList = new Array();
  ces_selectedList[0] = rowObj;
  
  // if selected list has 0 or 1 item(s), this is ces_pivot
  if (ces_selectedList.length == 0 || ces_selectedList.length == 1)
    ces_pivot = rowObj;

  if (rowObj != null) {
    for (var i=0; i < rowObj.cells.length; i++) { 

      rowObj.cells[i].className="selected";
      if (ces_lastRowObj != null) {
        if (ces_lastRowObj.id != rowObj.id) {
          if (ces_lastRowObj.cells[i] != null)
            ces_lastRowObj.cells[i].className="";
        }
      }
    }
  }
  ces_lastRowObj = rowObj;
}

/*************************************************************************************
Function:     shift
Parameters:   (string)type - whether to shift up or down
              (Object)rowObj - the <tr> row selected
Description:  TODO: add desc.
*************************************************************************************/
function shift(type, rowObj) {
  var first;
  var last;

  if (type == 'down') {
    last = getRowNum(rowObj);
    first = getRowNum(ces_pivot);
  } else {
    last = getRowNum(ces_pivot);
    first = getRowNum(rowObj);  
  }

  unHighlightAllRows();
  ces_selectedList = new Array();
  
  for (var i=0; i < rowObj.cells.length; i++) {    
    rowObj.cells[i].className="selected";
    if (ces_lastRowObj != null) {
      if (ces_lastRowObj != rowObj) {
        ces_lastRowObj.cells[i].className="";
      }
    }
  }  
  
  // If we were shifting one way and then switched while still holding shift then swap the indexes.
  if ((last - 0) < (first - 0)) {
    var iTemp = first;
    first = last;
    last = iTemp;
  }
  
  var cid = ces_getRowItemBySource('componentid', rowObj.id);

  for (var i=(first - 0); i <= (last - 0); i++) {

    var obj2 = getRowObjectByNum(i, cid);

    if (obj2 != null) {
    
      ces_addSelectedRow(obj2);
      
      //select
      for (var k=0; k < obj2.cells.length; k++) {
        obj2.cells[k].className="selected";
      }
    }
  }  
}

/*************************************************************************************
Function:     getRowObjectByNum
Parameters:   (int)iNum - The row number
              (int)iCompId - the componentId (OPTIONAL)
Description:  Gets a row object from the row number.
*************************************************************************************/
function getRowObjectByNum(iNum, iCompId) {

  if (iCompId == null) {
    if (ces_activeComponentId > -1) {
      iCompId = ces_activeComponentId;
    } else {
      try {
        iCompId = ces_getRowItemBySource('componentid', ces_lastRowObj.id);
      } catch (exception) {
      
      }
    }
  }
  
  var rowObj = document.getElementById("component" + iCompId + "...document-" + iNum);

  return rowObj;
}

function getRowNum(tempObj) {
  var dash = tempObj.id.indexOf("-");
  var len = tempObj.id.length;
  return tempObj.id.substring(dash + 1, len);
}

function unHighlightAllRows() {
  for (var i=0; i < ces_selectedList.length; i++) {
    if (ces_selectedList[i] != null) {
      var tempRowObj = ces_selectedList[i];
      for (var k=0; k < tempRowObj.cells.length; k++) {    
        tempRowObj.cells[k].className="";
      }
    }    
  }
}

function ces_addSelectedRow(rowObj) {

  var iLen = ces_selectedList.length;
  if (ces_maxRowSelect != -1 && iLen >= ces_maxRowSelect) {
    var tRowObj = ces_selectedList[0];
    ces_removeFromSelected(tRowObj);
    for (var i=0; i < tRowObj.cells.length; i++) {    
      tRowObj.cells[i].className="";
    }      
  }
  ces_selectedList[iLen] = rowObj;
}

function alreadySelected(rowObj) {
  for (var i=0; i < ces_selectedList.length; i++) {
    if (ces_selectedList[i] != null) {
      if (ces_selectedList[i].id == rowObj.id) {
        return true;
      }
    }
  }
  return false;
}

/*************************************************************************************
Function:     ces_removeFromSelected
Parameters:   (object)rowObj - The row object whos id that maps to a row object we want removed
Description:  Removes an object from the list of selected rows where the passed
              in row object's id matches the id of the rowmap obj in the array.
*************************************************************************************/
function ces_removeFromSelected(rowObj) {
  for (var i=0; i < ces_selectedList.length; i++) {
    if (ces_selectedList[i] != null) {
      if (ces_selectedList[i].id == rowObj.id) {
        
        delete ces_selectedList[i]; 
        
        //create new array
        var temp = new Array();
        var x = 0;
       
        for (var n=0; n < ces_selectedList.length; n++) {
          if (ces_selectedList[n] != null) {
            temp[x] = ces_selectedList[n];          
            x++;
          }
        }
        // set to new array
        ces_selectedList = temp;
      }
    }
  } 
}

function ces_getComponentIdBySource(sourceObj) {
  var componentId = -1;
  
  var sourceId = sourceObj.id;

  if (sourceId != null) {

    // NOTE: links do not have to adhere because of parentElement
    if (sourceId.indexOf("link") > -1) {
      sourceId = sourceObj.parentElement.id;
    }   

    var featuredDocArea = sourceId.indexOf("document") > -1;
    var docPkgArea = sourceId.indexOf("tasklink") > -1 || sourceId.indexOf("r_clk") > -1;
    var breadCrumbLink = sourceId.indexOf("breadcrumb") > -1

    if (sourceId != '') {
      componentId = ces_getRowItemBySource('componentid', sourceId);
    }
  }
  return componentId;
}

function ces_trackKey(evt) {
  var keyCode = '';
  if (ces_ns6Br) {
    keyCode = evt.keyCode;
  } else {
    keyCode = event.keyCode
  }
  
  if (ces_DELETE_KEY == keyCode) {
    try {
      // Try to execute registered delete task
      if (ces_lastSrcId != null && ces_selectedList.length == 1) {
        eval('_ces_deleteTask_' + ces_activeComponentId + '()');
      }
    } catch (exception) {
    }
  }

  if (keyCode == ces_SHIFT_KEY || keyCode == ces_CTRL_KEY) {
    if (ces_maxRowSelect > 0 && keyCode == ces_SHIFT_KEY) {
      // do nothing
    } else {
      ces_selectedKey = keyCode;
    }
  }
  
  // Begin cut/copy/paste
  try {
    if (ces_selectedList.length == 1) {
			if (keyCode == ces_X_KEY && ces_lastSrcId != null) {
				//window.status = 'cut ' + ces_lastSrcId;
				eval('_ces_cutTask_' + ces_activeComponentId + '()');
			} else if (keyCode == ces_C_KEY && ces_lastSrcId != null) {
				//window.status = 'copy ' + ces_lastSrcId;
				eval('_ces_copyTask_' + ces_activeComponentId + '()');
			} else if (keyCode == ces_V_KEY) {
				//window.status = 'paste ' + ces_lastSrcId;
				eval('_ces_pasteTask_' + ces_activeComponentId + '()');
			}
		}
  } catch (exception) {
  
  } 
  
  /********************************************************
  * UP ARROW CLICKED
  ********************************************************/  
  if (keyCode == ces_ARROW_UP ) {
    ces_lastSrcId = null;
    if (ces_pivot != null) {
      
      if (ces_selectedKey == ces_SHIFT_KEY) {
        
        var oneUp;
        if (ces_selectedList && ces_selectedList.length <= 1) {
          oneUp = getRowNum(ces_pivot) - 1;
        } else {
          oneUp = getRowNum(ces_lastRowObj) - 1;
        }
        if (oneUp > -1) {
          shift('up', getRowObjectByNum(oneUp));
          ces_lastRowObj = getRowObjectByNum(oneUp);
        }
      } else {     
        var oneUp = getRowNum(ces_pivot) - 1;
        
        if (oneUp > -1)
          ces_selectRowObject(getRowObjectByNum(oneUp));
      }
    }
  /********************************************************
  * DOWN ARROW CLICKED
  ********************************************************/ 
  } else if (keyCode == ces_ARROW_DOWN ) {
  
    ces_lastSrcId = null;
  
    if (ces_pivot != null) {
      
      if (ces_selectedKey == ces_SHIFT_KEY) {
        
        var oneDown;
        if (ces_selectedList.length <= 1) {
          oneDown = ((getRowNum(ces_pivot)) - 0) + 1;
        } else {
          oneDown = ((getRowNum(ces_lastRowObj)) - 0) + 1;
        }
        if (getRowObjectByNum(oneDown) != null) {
          shift('down', getRowObjectByNum(oneDown));
          ces_lastRowObj = getRowObjectByNum(oneDown);
        }
      } else {
        var oneDown = ((getRowNum(ces_pivot)) - 0) + 1;
        if (getRowObjectByNum(oneDown) != null)
          ces_selectRowObject(getRowObjectByNum(oneDown));
      }
    }
  /********************************************************
  * RIGHT ARROW CLICKED
  ********************************************************/ 
  } else if (keyCode == ces_ARROW_RIGHT ) {
    //ces_showRightClickToolkit;
  }
  
}

function ces_unces_trackKey(evt) {

  var keyCode = '';
  if (ces_ns6Br) {
    keyCode = evt.keyCode;
  } else {
    keyCode = event.keyCode
  }

  if ((keyCode == ces_ARROW_UP || keyCode == ces_ARROW_DOWN) 
    && (ces_selectedKey == ces_SHIFT_KEY)) {
    //do nothing
  } else {
    ces_pivot = ces_lastRowObj;
    ces_selectedKey = null;
  }
}

/*************************************************************************************
Function:     ces_adjustIFrameSize 
Parameters:   (Object) The calling window
Description:  Sizes an Iframe to its contents
*************************************************************************************/
function ces_adjustIFrameSize (iframeWindow) 
{
  if (iframeWindow.document.height) 
  {
    var iframeElement = parent.document.getElementById(iframeWindow.name);
    iframeElement.style.height = iframeWindow.document.height + 'px';
    iframeElement.style.width = iframeWindow.document.width + 'px';
  }
  else if (document.all) 
  {
    var iframeElement = parent.document.all[iframeWindow.name];
    if (iframeWindow.document.compatMode &&
        iframeWindow.document.compatMode != 'BackCompat') 
    {
      iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
      iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
    }
    else 
    {
      iframeElement.style.height = iframeWindow.document.body.scrollHeight + 5 + 'px';
      iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
    }
  }
}

//******************************************************************************
//  BEGIN MODAL DIALOG CODE
//******************************************************************************

// Global for brower version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4));

// One object tracks the current modal dialog opened from this window.
var ces_dialogWin = new Object();

function ces_openDGDialog(url, width, height, returnFunc, args) {
	if (!ces_dialogWin.win || (ces_dialogWin.win && ces_dialogWin.win.closed)) {
		ces_dialogWin.returnFunc = returnFunc;
		ces_dialogWin.returnedValue = "";
		ces_dialogWin.args = args;
		ces_dialogWin.url = url;
		ces_dialogWin.width = width;
		ces_dialogWin.height = height;
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		ces_dialogWin.name = (new Date()).getSeconds().toString();
		// Assemble window attributes and try to center the dialog.
		if (Nav4) {
			// Center on the main window.
			ces_dialogWin.left = window.screenX + 
			   ((window.outerWidth - ces_dialogWin.width) / 2);
			ces_dialogWin.top = window.screenY + 
			   ((window.outerHeight - ces_dialogWin.height) / 2);
			var attr = "screenX=" + ces_dialogWin.left + 
			   ",screenY=" + ces_dialogWin.top + ",scrollbars=yes,resizable=yes,width=" + 
			   ces_dialogWin.width + ",height=" + ces_dialogWin.height;
		} else {
			// The best we can do is center in screen.
			ces_dialogWin.left = (screen.width - ces_dialogWin.width) / 2;
			ces_dialogWin.top = (screen.height - ces_dialogWin.height) / 2;
			var attr = "left=" + ces_dialogWin.left + ",top=" + 
			   ces_dialogWin.top + ",scrollbars=yes,resizable=yes,width=" + ces_dialogWin.width + 
			   ",height=" + ces_dialogWin.height;
		}
		
		// Generate the dialog and make sure it has focus.
		ces_dialogWin.win=window.open(ces_dialogWin.url, ces_dialogWin.name, attr);
		if(!ces_dialogWin.win)
		{
			alert("You must disable your pop-up blocker for this site.");
			return;
		}
		ces_dialogWin.win.focus();
	} else 
	{
		if(!ces_dialogWin.win)
		{
			alert("You must disable your pop-up blocker for this site.");
			return;
		}
		ces_dialogWin.win.focus();
	}
}

function ces_deadend() {
	if (ces_dialogWin.win && !ces_dialogWin.win.closed) {
		ces_dialogWin.win.focus();
		return false
	}
}

// Since links in IE4 cannot be disabled, preserve 
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var ces_IELinkClicks;

// Disable form elements and links in all frames for IE.
function ces_disableForms() {
	ces_IELinkClicks = new Array();
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = true;
			}
		}
		ces_IELinkClicks[h] = new Array();
		for (i = 0; i < frames[h].document.links.length; i++) {
			ces_IELinkClicks[h][i] = frames[h].document.links[i].onclick;
			frames[h].document.links[i].onclick = ces_deadend;
		}
		frames[h].window.onfocus = ces_checkModal;
    	frames[h].document.onclick = ces_checkModal;
	}
}

// Restore IE form elements and links to normal behavior.
function ces_enableForms() {
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = false;
			}
		}
		for (i = 0; i < frames[h].document.links.length; i++) {
			frames[h].document.links[i].onclick = ces_IELinkClicks[h][i];
		}
	}
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function ces_blockEvents() {
	if (Nav4) {
		window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.onclick = ces_deadend;
	} else {
		ces_disableForms();
	}
	window.onfocus = ces_checkModal;
}
// As dialog closes, restore the main window's original
// event mechanisms.
function ces_unblockEvents() {
	if (Nav4) {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.onclick = null;
		window.onfocus = null;
	} else {
		ces_enableForms();
	}
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function ces_checkModal() {
	setTimeout("ces_finishChecking()", 50);
	return true;
}

function ces_finishChecking() {
	if (ces_dialogWin.win && !ces_dialogWin.win.closed) {
		ces_dialogWin.win.focus();
	}
}
//******************************************************************************
//  END MODAL DIALOG CODE
//******************************************************************************

/*************************************************************************************
Function:     xname
Parameters:   (xtype) xxx
Description:  xdesc.
NOTE:         Component manager list - called from Portal Page
*************************************************************************************/
function ces_comp_list_menuRowOn(ctrl)
{
	ctrl.style.borderColor = '#0000FF';
	ctrl.style.cursor = 'hand';
	ctrl.style.backgroundColor = '#99CCCC';	
}

/*************************************************************************************
Function:     xname
Parameters:   (xtype) xxx
Description:  xdesc.
*************************************************************************************/
function ces_comp_list_menuRowOff(ctrl)
{
	ctrl.style.borderColor = '#FFFFFF';
	ctrl.style.cursor = '';
	ctrl.style.backgroundColor = '#FFFFFF';
}


/*************************************************************************************
Function:     xname
Parameters:   (xtype) xxx
Description:  xdesc.
*************************************************************************************/
function ces_toolkit_row_mouseover(ctrl) {
	ctrl.className = 'active';
}

/*************************************************************************************
Function:     xname
Parameters:   (xtype) xxx
Description:  xdesc.
*************************************************************************************/
function ces_toolkit_row_mouseout(ctrl)
{
	ctrl.className = 'inactive';
}

//====================================================
function ces_appendToFunction(func,script) 
{
	try
	{
		var currScript = eval(func) ? eval(func).toString() : "";
		eval(func + " = new Function( (currScript.length ? currScript.slice(currScript.indexOf(\"{\")+1, currScript.length-2) : \"\") + script);");
	}
	catch(exception)
	{	
	}
}	

function ces_generateRightClickPostBackMenu(returnUrl, ftn, url, componentId, row, entityId, entityType, callback)
{
	url += "&returnUrl=" + returnUrl + "&compId=" + componentId + "&row=" + row + "&entityId=" + entityId + "&entityType=" + entityType + "&ftn=" + ftn;
	var data = ces_getServerData(null, url, callback, componentId, row);
}

function ces_generateItemToolkit(url, returnUrl, componentId, row, entityId, entityType, callback, evt)
{
  entityId = entityId.replace('&', ';amp');
	url += '&returnUrl=' + escape(returnUrl) + '&compId=' + componentId + '&row=' + row + '&entityId=' + entityId + '&entityType=' + entityType;
	var data = ces_getServerData(null, url, callback, componentId, row, evt);
}

/*************************************************************************************
Function:     ces_getServerData
Parameters:   (String)url - the url to be loaded
Description:  This function is called to retrieve data from the server via a url
*************************************************************************************/
var ces_serverDataIFrame = null;
var ces_serverData = null;
function ces_getServerData(e, url, callback, parm1, parm2, evt)
{
	ces_serverDataIFrame = null;
	if(!ces_serverDataIFrame)
	{
		try
		{
			ces_serverDataIFrame = document.createElement('iframe');
			ces_serverDataIFrame.setAttribute('id','spIFrame');
			ces_serverDataIFrame.style.display = 'none';
			ces_serverDataIFrame.style.width = '0px';
			ces_serverDataIFrame.style.height = '0px';
			ces_serverDataIFrame.style.border = '0px';
			document.body.appendChild(ces_serverDataIFrame);
		
		} catch(exception)
		{
			var iframeHTML='\<iframe id="spIFrame" style="';
			iframeHTML+='display:none;';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
		
			ces_serverDataIFrame = new Object();
			ces_serverDataIFrame.document = new Object();
			ces_serverDataIFrame.document.location = new Object();
			ces_serverDataIFrame.document.location.iframe = document.getElementById('spIFrame');
			ces_serverDataIFrame.document.location.replace = function(location) {
		  this.iframe.src = location; }		
		}
		
	}
	var IFrameDoc;
	var funcStr = '';
	
	if(ces_serverDataIFrame.contentDocument) 
	{
		// For NS6/FireFox
		IFrameDoc = ces_serverDataIFrame.contentDocument; 
		//funcStr = "null,(document.getElementById('spIFrame').contentDocument.body.innerHTML)";
		funcStr = "null,null";
  } else if (ces_serverDataIFrame.contentWindow) 
  {
  
		// For IE5.5 and IE6
		IFrameDoc = ces_serverDataIFrame.Document;

	} else if (ces_serverDataIFrame.document) 
	{
		// For IE5
		IFrameDoc = ces_serverDataIFrame.document;
	} else 
	{
	
		return true;
	}

  if (funcStr == '') {
    funcStr = "(document.getElementById('" + ces_serverDataIFrame.uniqueID + "').contentWindow.document.body.innerHTML)";
  }

	  funcStr += "," + parm1;

  //if(parm2)
	funcStr += "," + parm2;

  var funcPtr = new Function(callback + "(" + funcStr + ")");

  try {
    if (ces_ns6Br) {
      //ces_serverDataIFrame.addEventListener("load",function(e) {ces_toolkitCallback_ns(e, null, parm1, parm2)},true);
      var x = evt.pageX;
      var y = evt.pageY;
      ces_serverDataIFrame.addEventListener("load",function(e) {ces_toolkitCallback_ns(e, null, parm1, parm2, x, y)},true);
      //ces_serverDataIFrame.addEventListener('load',funcPtr, true);
    } else {
	    ces_serverDataIFrame.attachEvent('onload', funcPtr);
	    
	  }
	} catch (exception) {

	}

	ces_serverData = null;
  IFrameDoc.location.replace(url);

  return false;
}

function ces_showflash(contentVersion, cabVersion, source, width, height, alt_img, alt_width, alt_height)
{

	var flashCanPlay = true;

	var plugin = (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash']) ?
			navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin : 0;

	if (plugin) 
	{
		var words = navigator.plugins['Shockwave Flash'].description.split(' ');
		for (var i = 0; i < words.length; ++i)
		{
			if (isNaN(parseInt(words[i])))
				continue;
			var pluginVersion = words[i];
		}
		flashCanPlay = pluginVersion >= contentVersion;
	}

	if (flashCanPlay) 
	{
		var flashStr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + cabVersion + '" ' +
			'width="' + width + '" height="' + height + '">' + //align="left">' +
			'<param name=movie value="' + source + '">' +
			'<param name=quality value=high>' +
			'<param name="wmode" value="transparent">' +
			'<embed src="' + source + '" menu=false quality=high bgcolor=#FFFFFF ' +
			'swLiveConnect=false width="' + width + '" height="' + height + '" align="right" ' +
			'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">' +
			'</embed>' +
			'</object>';
//alert(flashStr);
		document.write(flashStr);
	} else
	{
		if(alt_img != '')
		{
			document.write('<a href="http://www.macromedia.com/go/getflashplayer" target="_blank">');
			document.write('<img src="' + alt_img + '" width="' + alt_width + '" height="' + alt_height + '" border="0" alt="Get Macromedia Flash Player">');
			document.write('</a>');
		}
	}
}


function ces_findPosY(obj)
{
	if(obj == null)
		return 0;
	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 ces_getAbsTop(control)
{
	return ces_findPosY(control);
	var current=control;
	var i=0;
	while(current.tagName!="BODY")
	{
		i+=current.offsetTop;
		current=current.offsetParent;
	}
	return i; 
}

function ces_resize_full(control, offset, container)
{
	if(control == null)
		return;
	
    if(!offset)
		offset = 0;
	var winheight;
	var winwidth;
	if(container == null)
	{
		winheight = (ces_ieBr?document.body.clientHeight:window.innerHeight);
		winwidth = (ces_ieBr?document.body.clientWidth:window.innerWidth);
	}
	else
	{
		winheight = container.offsetHeight;
		winwidth = container.offsetWidth;
	}
		
	var winTop = ces_getAbsTop(control);
	
	try
	{	
		control.style.height=winheight - winTop - offset;
	}catch(exception)
	{
	}	
}

function ces_scrollTo(scrollcontrol, positioncontrol)
{
	if(scrollcontrol == null || positioncontrol == null)
		return;
	scrollcontrol.scrollTop = positioncontrol.offsetTop;
}

function ces_showProcessArea() 
{
  var areaWidth = 250;
  var areaHeight = 300;
  var winl = (document.body.offsetWidth-20 - areaWidth) / 2;
  var wint = (document.body.offsetHeight - areaHeight) / 2;
  var divObj = document.getElementById('ProcessAlert');
  if (divObj) {
    divObj.style.top = wint;
    divObj.style.left = winl;
    divObj.style.display = '';
  }
}
function ces_hideProcessArea() 
{
  var divObj = document.getElementById('ProcessAlert');
  if (divObj) {
    divObj.style.display = 'none';
  }
}

function noop()
{
}

function ces_firstSibling(control)
{
	var sibling = control.previousSibling;
	while(sibling.previousSibling != null)
	{
		sibling = sibling.previousSibling;
	}
	return sibling;
}

function ces_gridedit_status(control)
{
	window.status = ces_firstSibling(control).innerHTML;
}
