﻿/*
 * nothing in this files should be used in strict places.
 * needs auditing to make sure.
 */

var m_wndPickList = null;
var m_strCurrentPickListControlName= null;
var m_strWndName = null;
var isVSCurrentPageAvailable = false;

// next two functions are to prevent delay execution until the proper functions have been declared in overrides.js
if (typeof(declareClass) == 'undefined') 
{
	var declareClass = function()
	{
		declareClass.curry(arguments[0], arguments.length > 1 ? arguments[1] : null).defer();
	};
}
if (typeof(initFramework) == 'undefined') 
{
	var initFramework = function()
	{
		if (typeof(initFramework.defer) == 'undefined') 
		{
			return;
		}
		initFramework.defer();
		
	};
}

function maximizeWindow(objWnd)
{
	objWnd.moveTo(0,0);
	objWnd.resizeTo(screen.width,screen.height);
}

function wndPickListClose(strCurrentControlName)
{
	if (m_wndPickList != null) 
	{	
		if (m_strCurrentPickListControlName != strCurrentControlName)
		{	
			if (m_wndPickList.closed == false) 
			{
				if (m_wndPickList.frames.length==0 || m_wndPickList.frames['framePickListNav'].document==null || m_wndPickList.frames['framePickListNav'].document.forms.length==0 || m_wndPickList.frames['framePickListNav'].document.forms[0].elements['hidFieldForNames'].value != strCurrentControlName)
				{		
					m_wndPickList.close();
					m_wndPickList = null;
					m_strCurrentPickListControlName = '';
  	      if (typeof(_pickListWindow) != "undefined")
  	      {
            _pickListWindow = null;
            _currentPickListControlName = '';
          }
				}
			}
			else
			{
				m_wndPickList = null;
				m_strCurrentPickListControlName = '';
	      if (typeof(_pickListWindow) != "undefined")
	      {
          _pickListWindow = null;
          _currentPickListControlName = '';
        }
			}
		}
	}
};

function setIFrameSource(frameid, url, delay)
{
	if (delay != 'YES')
	{
		setTimeout(setIFrameSource.bind(this, frameid, url, 'YES'),0);
		return;
	}
	if (url != '') 
	{
		document.getElementById(frameid).contentWindow.location.replace(url);
	}
};

function LinkClick(ev)
{
    // this function is registered in PageBase as a document.click
    // it's purpose is to hide the mainDiv before proceeding with anchor click
    
    var el = Event.element(ev);
    
    if (el.tagName.toLowerCase() == "a")
    {
        var clearScreen = true;
        
        if (el.onClick != null)
        {
            var onClick = el.onClick.toString();
            
            if (onClick.toLowerCase().indexOf("javascript") != -1)
                clearScreen = false;
        }
        
        if (el.href != null)
        {
            var href = el.href;
            
            if (href.toLowerCase().indexOf("javascript") != -1)
                clearScreen = false;
        }

        if (el.target != null)
        {
            var target = el.target;
            
            if (target != "")
                clearScreen = false;
        }

        if (clearScreen)
			ClearScreen();
    }
};
function UpdatePrices(openPrice, highPrice, lowPrice, closePrice, volume, impact)
{
    var openPriceSpan = $('openPriceSpan');
    var highPriceSpan = $('highPriceSpan');
    var lowPriceSpan = $('lowPriceSpan');
    var closePriceSpan = $('closePriceSpan');
    var volumeSpan = $('volumeSpan');
    var impactSpan = $('impactSpan');
    
    if (openPriceSpan != null)    
        openPriceSpan.innerHTML = openPrice;
    if (highPriceSpan != null)    
        highPriceSpan.innerHTML = highPrice;
    if (lowPriceSpan != null)    
        lowPriceSpan.innerHTML = lowPrice;
    if (closePriceSpan != null)    
        closePriceSpan.innerHTML = closePrice;
    if (volumeSpan != null)    
        volumeSpan.innerHTML = volume;
    if (impactSpan != null)    
        impactSpan.innerHTML = impact;

    var pricesDiv = $('pricesDiv');
    
    if (pricesDiv != null)
        pricesDiv.style.display = 'block';
}
function ClosePrices()
{
//    var pricesDiv = $('pricesDiv');
//    
//    if (pricesDiv != null)
//        pricesDiv.style.display = 'none';
}
function IsDate(date, isUS)
{
    var datePattern = /^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/;
    var matchArray = date.match(datePattern);

    if (matchArray == null)
        return false;

    if (isUS)
    {
        month = matchArray[1];
        day = matchArray[3];
    }
    else
    {
        month = matchArray[3];
        day = matchArray[1];
    }

    year = matchArray[5];

    if (month < 1 || month > 12)
        return false;

    if (day < 1 || day > 31)
        return false;

    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31)
        return false;

    if (month == 2)
    {
        var isLeap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        
        if (day > 29 || (day == 29 && !isLeap))
            return false;
    }
    
    // date is valid
    return true;
}

var _isToolbarCollapsed = true;
var toolbarMenuIFrame = null;
function setToolbarIframe(div)
{
	if (!document.all)
		return;
	
  if (!toolbarMenuIFrame)
  {
  	toolbarMenuIFrame = document.createElement('iframe');
  	toolbarMenuIFrame.src = 'javascript:false;';
  	toolbarMenuIFrame.style.display = 'none';
  	toolbarMenuIFrame.style.position = 'absolute';
  	toolbarMenuIFrame.style.border = 'none';
  	document.body.appendChild(toolbarMenuIFrame);
  }
  if (div)
  {
  	if (div.style.display == 'block')
  	{
	  	var pos = getPosition(div);
		  toolbarMenuIFrame.style.top = pos[1];
		  toolbarMenuIFrame.style.left = pos[0];
		  toolbarMenuIFrame.style.width = div.offsetWidth;
		  toolbarMenuIFrame.style.height = div.offsetHeight;
	  	toolbarMenuIFrame.style.display = 'block';
  	}
		else
	  {
	  	toolbarMenuIFrame.style.display = 'none';
	  }
	}	  
	else if (toolbarMenuIFrame.style.display == 'block')
  {
  	toolbarMenuIFrame.style.display = 'none';
  }
}
function getPosition(oNode,pNode)
{
  if(!pNode)
  	var pNode = document.body
  var oCurrentNode=oNode;
  var iLeft=0;
  var iTop=0;
  while ((oCurrentNode)&&(oCurrentNode!=pNode))
	{
		iLeft+=oCurrentNode.offsetLeft;
		iTop+=oCurrentNode.offsetTop;
	  oCurrentNode=oCurrentNode.offsetParent;
  }
  return new Array(iLeft,iTop);
};
var subToolbarDisplayDiv = null;
function ExpandToolbar(subToolbar)
{
    CollapseToolbar();
    
    
    var divName = subToolbar + "_ToolbarDiv";
    var div = $(divName);
    var anchorName = subToolbar + "_ToolbarAnchor";
    var anchor = $(anchorName);
    
    var toolbarContentCell = $("toolbarContentCell");
    var toolbarTr = $("toolbarTr");
    var toolbarTable = $("toolbarTable");
    var toolbarDiv = $("toolbarDiv");
    
    if (!subToolbarDisplayDiv)
    {
	  	subToolbarDisplayDiv = document.createElement('div');
	  	subToolbarDisplayDiv.style.display = 'none';
	  	subToolbarDisplayDiv.style.position = 'absolute';
	  	document.body.appendChild(subToolbarDisplayDiv);
    }
    
  	subToolbarDisplayDiv.className = div.className;
  	subToolbarDisplayDiv.style.cssText = div.style.cssText;
  	subToolbarDisplayDiv.innerHTML = div.innerHTML;
    
    subToolbarDisplayDiv.style.display = "block";
    subToolbarDisplayDiv.style.top = anchor.offsetTop + toolbarDiv.offsetTop + toolbarTable.offsetTop + toolbarTr.offsetTop + toolbarContentCell.offsetTop + 15;
    subToolbarDisplayDiv.style.left = anchor.offsetLeft + toolbarDiv.offsetLeft + toolbarTable.offsetLeft + toolbarTr.offsetLeft + toolbarContentCell.offsetLeft;

    setToolbarIframe(subToolbarDisplayDiv);
    _isToolbarCollapsed = false;
};
function CollapseToolbar()
{
    if (!_isToolbarCollapsed)
    {
        var div = subToolbarDisplayDiv;
        if (div != null)
        {
          div.style.display = "none";
                    
        	setToolbarIframe(div);
        }
    }
};


function ShowToolbar()
{
    var toolbarTable = $('toolbarTable');

    if (toolbarTable != null)
        toolbarTable.style.visibility = 'visible';
};
function HideToolbar()
{
    var toolbarTable = $('toolbarTable');
    
    if (toolbarTable != null)
        toolbarTable.style.visibility = 'hidden';
};

var htmlTextAreas = new Array();

function customEval(expr)
{
	return eval(expr);
};

function IncludeEmptyDatesHandler(includeEmptyDatesPanelId)
{
	var form = document.forms[0];
	var elements = form.elements;
	var isDateValueFound = false;
	var includeEmptyDatesPanel = document.getElementById(includeEmptyDatesPanelId);
	
	if (includeEmptyDatesPanel != null)
	{	
		for (i=0; i<elements.length; i++)
		{
			var element = elements[i];
			var elementClass = "";
			
			if (document.all)
				elementClass = element.attributes['class'].value;
			else
				elementClass = element.getAttribute('class');
			
			if (elementClass == 'dateBox')
			{
				if (element.value != '')
				{
					isDateValueFound = true;
				}
			}
		}

		if (isDateValueFound)
		{
			includeEmptyDatesPanel.style.display = 'block';
		}
		else
		{
			includeEmptyDatesPanel.style.display = 'none';
		}
	}
};
function ToggleTextAreas(n)
{
	try
	{
	  if (window.eval('typeof('+n.id+'HtmlTextArrays)') != 'undefined')
	  {
	    var tmpArrayName = n.getAttribute('htmlareas');
	    if (tmpArrayName != null)
	    {
	      window.eval('htmlTextAreas='+n.id+'HtmlTextArrays.copy();');
	    }
	    else
	    {
	      htmlTextAreas.length = 0;
	      findTextAreas(n);
	      window.eval(n.id+'HtmlTextArrays=htmlTextAreas.copy();');
	      n.setAttribute('htmlareas',n.id+'HtmlTextArrays');
	    }
	    for (var i=0; i<htmlTextAreas.length; i++)
	    {
	      toggleEditor(htmlTextAreas[i]);
	    }   
	  }
	}
	catch (e)
	{
	}
};

Array.prototype.copy = function()
{
     var copy = new Array();
     for (var i = 0; i < this.length; i++) {
        copy[i] = this[i];
     }
     return copy;
};

var vocusSelects = new Array();

function ToggleVocusSelects(n)
{
  if (window.eval('typeof('+n.id+'vocusSelects)') != 'undefined')
  {
    var tmpArrayName = n.getAttribute('vocusSelects');
    if (tmpArrayName != null)
    {
      window.eval('vocusSelects='+n.id+'vocusSelects.copy();');
    }
    else
    {
      vocusSelects.length = 0;
      findVocusSelects(n);
      window.eval(n.id+'vocusSelects=vocusSelects.copy();');
      n.setAttribute('vocusSelects',n.id+'vocusSelects');
    }
    for (var i=0; i<vocusSelects.length; i++)
    {
      try 
      {
        vocusSelects[i].onchange();
      }
      catch (e)
      {
      }
    } 
  }  
};

function findVocusSelects(n)
{
  if ((typeof(n.tagName) != 'undefined') && (n.tagName.toUpperCase() == 'SELECT'))
    vocusSelects[vocusSelects.length] = n;
  
  var children = n.childNodes;
  
  for (var i=0; i<children.length; i++)
  {
    findVocusSelects(children[i]);
  }
};
if (typeof(gSafeOnload) == 'undefined') 
{
	var gSafeOnload = new Array();
}
if (typeof(vsOrigOnload) == 'undefined') 
{
	var vsOrigOnload = null;
}
function SafeAddOnload(f)
{
	if  (window.onload)
	{
		if ((String(window.onload).replace(/\n/g,'').replace(/\s/g,'') != 'function(){oldonload();SafeOnload();}') &&
		    (String(window.onload).replace(/\n/g,'').replace(/\s/g,'') != 'function(){SafeOnload();}') &&
			(String(window.onload).replace(/\n/g,'').replace(/\s/g,'') != 'function(){}'))
		{
		  var oldonload = window.onload;
		  vsOrigOnload = window.onload.toString();
		  window.onload = function(){};
		}		
		VsLoadFunctions.push(f);
	}
	else
	{
		VsLoadFunctions.push(f);
		window.onload = function(){};
	}
};
function SafeOnload(fromPopup)
{
	if (typeof(fromPopup) == 'undefined')
		fromPopup = false;
  if ((window.location.href.toUpperCase().indexOf("VOCUSPOPUP") != -1 && !fromPopup) || typeof(vs) != 'undefined')
  	return;
	for (var i=0;i<gSafeOnload.length;i++)
		eval(gSafeOnload[i]);
};

var gSafeOnclick = new Array();
function SafeAddOnclick(f)
{
	try
	{
	    if  (document.onclick)
	    {
		    if (document.onclick != SafeOnclick)
		    {
			    gSafeOnclick[0] = document.onclick;
			    document.onclick = SafeOnclick;
			    var iframelist = document.getElementsByTagName('iframe');
	        for (var i=0;i<iframelist.length;i++)
	        {
	            try
	            {
	                if ((iframelist[i].id.toUpperCase() != 'PICKLISTHIDDENFRAME') && (iframelist[i].id.toUpperCase().indexOf('TMPIFRAME') == -1) && (iframelist[i].name != 'picklist'))
	                    iframelist[i].contentWindow.SafeAddOnclick(SafeOnclick);
	                    //iframelist[i].contentWindow.document.onclick = SafeOnclick;
	            }
	            catch (e) {}
	        }
		    }		
		    gSafeOnclick[gSafeOnclick.length] = f;
	    }
	    else
	    {
		    gSafeOnclick[0] = f;
		    document.onclick = SafeOnclick;
  	    var iframelist = document.getElementsByTagName('iframe');
	      for (var i=0;i<iframelist.length;i++)
	      {
	            try
	            {
                    if ((iframelist[i].id.toUpperCase() != 'PICKLISTHIDDENFRAME') && (iframelist[i].id.toUpperCase().indexOf('TMPIFRAME') == -1) && (iframelist[i].name != 'picklist'))
	                    iframelist[i].contentWindow.document.onclick = SafeOnclick;
	            }
	            catch (e) {}
	      }
	    }
	}
	catch (e)
	{
	    if (typeof(vsExceptions) != 'undefined')
	        vsExceptions.handleError(e);
	}
};
function SafeOnclick()
{
	for (var i=0;i<gSafeOnclick.length;i++)
		gSafeOnclick[i]();
};

var pickListClickList = new Array();
function addPickListToList(f)
{
	pickListClickList[pickListClickList.length] = f;
};

function hidePickLists()
{
	for(i = 0; i <= pickListClickList.length-1; i++)
	{
		if (document.getElementById('iframe'+pickListClickList[i]))
		{
		  if (document.getElementById('iframe'+pickListClickList[i]).style.display != 'none')
		  {
		    BlurPickListIframe(pickListClickList[i]);
		  }
		}
	}
};

function showPopUpBlockerMessage()
{
  var message = 'Your web browser\'s pop-up blocking feature is preventing application windows from opening.  Please refer to your browser\'s help section for information on how to add "{0}" to the list of sites that should not be blocked.';
  if (typeof(vs) != 'undefined' && vs)
  {
      return vs.getUiPhrase(message).replace('{0}', window.location.hostname);
  }
  switch (languageId)
  {
        case '1036': 
            message='Le dispositif de blocage instantan\u00E9 de votre browser\u0027s d\u0027encha\u00EEnement emp\u00EAche des fen\u00EAtres d\u0027application de l\u0027ouverture.  Veuillez se r\u00E9f\u00E9rer \u00E0 la section de l\u0027aide de votre browser\u0027s pour l\u0027information sur la fa\u00E7on dont s\u0027ajouter \u0022'+window.location.hostname+'\u0022 \u00E0 la liste d\u0027emplacements qui ne devraient pas \u00EAtre bloqu\u00E9s.';
            break;
        // Spanish
        case '1034': 
            message='La caracter\u00EDstica de bloqueo pop-up de su navegador web est\u00E1 previniendo la abertura de ventanas.  Refiera por favor a la secci\u00F3n de ayuda de su navegador para la informaci\u00F3n sobre c\u00F3mo agregar \u0022'+window.location.hostname+'\u0022 a la lista de los sitios que no deben ser bloqueados.';
            break;
        // German
        case '1031': 
            message='Pop-up blockierende Eigenschaft Ihrer Netzdatenbanksuchroutine verhindert Anwendungsfenster an der \u00D6ffnung.  Beziehen Sie bitte sich auf Hilfenabschnitt Ihrer Datenbanksuchroutine zu Information \u00FCber, wie man hinzuf\u00FCgt \u0022'+window.location.hostname+'\u0022 zur Liste der Aufstellungsorte, die nicht blockiert werden sollten.';
            break;
	    case '1040': 
            message='Le impostazioni di blocco popup del browser impedisce l\'apertura qualche finestre dell\'applicazione.  Consultare la Guida del browser per informazioni su come agiungere "'+window.location.hostname+'" all\'elenco di siti da non bloccare.';
            break;
        case '2052':
            message = 'Web浏览器的弹出窗口拦截功能是无法打开应用程序窗口。请参考您的浏览器的帮助部分信息如何添加“' + window.location.hostname + '”不应该被封锁的网站清单';
            break;
  }
  alert(message);
};

function pickListClose()
{	
	if (top.opener != null)
	{
		if (!top.opener.closed)
		{
		    if (top.opener.top.frames['framePickListNav'] != null)
		    {
			    top.opener.top.frames['framePickListNav'].document.forms['frmPickListNav'].submit();
			    top.opener.top.focus();
		    }
		    else if (top.opener.document.forms.length > 0)
		    {
			    if (top.opener.document.forms[0].name == "PickListForm")
			    {
            if (top.opener.document.forms[0].submitButtonButton) {
              top.opener.document.forms[0].submitButtonButton.click();
            }
				    top.opener.focus();
			    }
		    }
		}
	}
	top.window.close();
};

function refreshHeader()
{
	if (parent.frames['frameHeader']) 
	{
		var href = parent.frames['frameHeader'].document.location.href;
		parent.frames['frameHeader'].document.location.href = href;
	}
};

function publishBooleanAdditional_OnClick(publishBoolean)
{
	if (!document.all)
	{
		var lastDiv = document.getElementById("lastDiv");

		if (lastDiv != null)
		{
			if (lastDiv.style.display == 'block')
				changePublishType();
		}
	}
};

function GetBooleanValue(radioButton)
{
	return (document.getElementsByName(radioButton.id)[0].checked == true);
};

function rollIn()
{
	if (document.getElementById('menuDiv') != null)
	{
		if (document.getElementById('menuDiv').style.visibility != 'hidden')
		{
			rollInMenu();
		}
	}
	
	showSelects();
};

function ClosePickList(controlName)
{
  try
  {
  	if (_pickListWindow != null) 
	  {	
		  if (_currentPickListControlName != controlName)
  		{	
	  		if (_pickListWindow.closed == false) 
		  	{
			  	_pickListWindow.close();
  				_pickListWindow = null;
	  			_currentPickListControlName = '';
	        if (m_wndPickList)
	        {
            m_wndPickList = null;
            m_strCurrentPickListControlName = '';
          }
		  	}
			  else
  			{
	  			_pickListWindow = null;
		  		_currentPickListControlName = '';
	        if (typeof(m_wndPickList) != "undefined")
	        {
            m_wndPickList = null;
            m_strCurrentPickListControlName = '';
          }
			  }
  		}
	  }
	} catch(e)
	{
  }
};

function getRadioButtonValue(radioButton)
{
	var num = radioButton.length;
	
	for (var i=0; i<num; i++)
	{
		if (radioButton[i].checked)
		{
			return radioButton[i].value;
		}
	}
};

function disableOkButton(val)
{
	var form = document.forms[0];
	var elements = form.elements;
	
	for (var i=0; i<elements.length; i++)
	{
		var name = elements[i].name;
		var length = name.length;
		if (name.substring(length-2, length).toUpperCase() == 'OK')
		{
			elements[i].disabled = val;
		}
	}
};

function elementExists(elements, strName)
{
	var blnFound = false;
	var intI;
	
	if (typeof(elements) != 'undefined')
	{		
		for (intI=0; intI<=elements.length-1; intI++)
		{	
			if (elements[intI].name == strName)
			{					
				blnFound = true;
				intI = elements.length;
			}
		}
	}
	
	return blnFound;
};

function formExists(forms, strName)
{
	var blnFound = false;
	var intI;
		
	if (typeof(forms) != 'undefined')
	{		
		for (intI=0; intI<=forms.length-1; intI++)
		{	
			if (forms[intI].name == strName)
			{					
				blnFound = true;
				intI = forms.length;
			}
		}
	}
	
	return blnFound;
};
	
function frameExists(frames, strName)
{
	var blnFound = false;
	var intI;
	
	if (typeof(frames) != 'undefined')
	{		
		for (intI=0; intI<=frames.length-1; intI++)
		{	
			if (frames[intI].name == strName)
			{					
				blnFound = true;
				intI = frames.length;
			}
		}
	}
		
	return blnFound;
};
	
function windowExists(wnd)
{
	if (typeof(wnd) == 'object')
	{
		if (wnd.closed == false)
		{
			return true;
		}
	}
	else
	{
		return false;
	}
};

var m_awndAddEdit = new Array(0);

function windowOpen(strURL, strWindowName, blnIncludeToolbars, intWindowType, intWindowAlign, openMaximized)
{
  if (typeof(vsParams) != 'undefined' && vsParams.strictDocType)
  {
    var er = new Error("'windowOpen' has been depreciated.  Please use 'vs._dialogs.openWindow'.  Also, check to see if you can use 'vs._dialogs.showPopup' instead.");
    vsExceptions.handleError(er);
  }
	var intWINDOWTYPE_SMALL = 0;
	var intWINDOWTYPE_MEDIUM = 1;
	var intWINDOWTYPE_LARGE = 2;

	var intWINDOWALIGN_LEFT = 0;
	var intWINDOWALIGN_CENTER = 1;
	var intWINDOWALIGN_RIGHT = 2;

	var dblDivFactor;
	var lngLeft;
	var lngHeight;
	var lngTop;	
	var lngWidth;
	var strFeatures;
	var objWnd;
	
	if (strWindowName == null || strWindowName == '') 
	{
		strWindowName = 'wnd' + Math.floor(30000*Math.random() + 1);
	}

	if (intWindowType == intWINDOWTYPE_SMALL)
	{				
		dblDivFactor = 2;					
	}
	else if (intWindowType == intWINDOWTYPE_MEDIUM)
	{
		dblDivFactor = 1.6;					
	}	
	else
	{
		dblDivFactor = 1.05;
	}

	lngWidth = Math.floor(screen.availWidth/dblDivFactor);
	lngHeight = Math.floor(screen.availHeight/dblDivFactor);

	if ((screen.availHeight - lngHeight) < 170)
	{
		lngHeight = screen.availHeight - 170;
	}

	// CALCULATE TOP
	if (intWindowType == intWINDOWTYPE_SMALL)
	{		
		lngTop = Math.floor((screen.availHeight - (lngHeight - 15))/2) - 100;	
	}
	else if (intWindowType == intWINDOWTYPE_MEDIUM)
	{
		lngTop =  Math.floor((screen.availHeight - (lngHeight - 15))/2) - 100;				
	}	
	else
	{
		lngTop =  0;
	}
	
	// CALCULATE LEFT
	if (intWindowAlign==intWINDOWALIGN_RIGHT)
	{
		lngLeft = screen.availWidth - lngWidth - 15;
	}	
	else if (intWindowAlign==intWINDOWALIGN_CENTER)
	{
		lngLeft = Math.floor((screen.availWidth - (lngWidth - 15))/2)
	}
	else
	{
		lngLeft = 0;	
	}	
	
	if (lngTop < 0)
	{
		lngTop = 0;	
	}

	if (blnIncludeToolbars == true)	
	{
		strFeatures = 'toolbar=yes,location=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes';		
	}
	else
	{
		strFeatures = 'toolbar=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes';		
	}			
		
	strFeatures = strFeatures + ',left='+ lngLeft + ',width=' + lngWidth + ',top=' + lngTop + ',height=' + lngHeight;	
	
	if (typeof(obj) != "undefined") // Added for dropdown picklist so that the new window can reference the parent of the picklist.  (iframes can not be referenced from new windows through the opener property)
	{
	  objWnd = parent.open(strURL, strWindowName, strFeatures, false);
	}
	else
	{
	  objWnd = window.open(strURL, strWindowName, strFeatures, false);
	}
	
	try
	{
	    if (objWnd)
	    {
		    if (openMaximized != null)
		    {
			    if (openMaximized)
				    maximizeWindow(objWnd);
		    }
	    }
	    else
	    {
		    try 
		    { 
		      showPopUpBlockerMessage(); 
		      return;
		    }
		    catch (e) {}     
	    }
    	
	    objWnd.focus();
	}
	catch (e)
	{
	    objWnd = null;
	}
	return objWnd;
};

function childWindowNotifyOfClose()
{
	var intI;
	
	for (intI = 0; intI <= m_awndAddEdit.length-1; intI++)
	{
		if (m_awndAddEdit[intI] != null && m_awndAddEdit[intI].closed != true) 
		{
			m_awndAddEdit[intI].opener = null;	
		}		
	}
	m_awndAddEdit.length = 0;
};

function childWindowAdd(wndChild)
{
	m_awndAddEdit.length++;
	m_awndAddEdit[m_awndAddEdit.length-1] = wndChild;
};

function TrimFormPost(form)
{ 
  var elem = form.elements;
  for (i=0; i<=elem.length-1; i++)
  { 
    if (elem[i].value == '')     
    { 
       elem[i].name = ''; 
       elem[i].value = ''; 
    } 
  } 
};

function ValidateText()
{
	var elm;
	var elmHid;
	var intI;
	var intJ;
	var intCharCode;
	var frm;
	var strValue;
	var strNewValue;
	
	frm =  document.forms[0];

	// Need to only set focus if client OS is NOT macintosh
	// since the Macintosh raises an error
	if (navigator.appVersion.indexOf('Macintosh')==-1)
	{		
		for (intI=0; intI<=frm.elements.length - 1; intI++)
		{
			elm = frm.elements[intI];
			
			if (elm.type == 'textarea' ) 
			{
				if (typeof(frm.elements['hid' + elm.name]) != 'undefined')
				{
					elmHid = frm.elements['hid' + elm.name];
					
					if (elm.value != elmHid.value) 
					{
						strNewValue = '';
			
						for (intJ=0; intJ<=elm.value.length-1; intJ++)
						{
							intCharCode	= elm.value.charCodeAt(intJ, 1);
			
							// if(intCharCode==9 || intCharCode==10 || intCharCode==13 || (intCharCode>31 && intCharCode<127  ) )
							if (intCharCode>0 && intCharCode<255)
							{
								strNewValue = strNewValue + elm.value.charAt(intJ, 1);
							}
							else
							{
								if (intCharCode == 8230 || intCharCode == 8221) 
								{
									strNewValue = strNewValue + '\"';									
								}
								else if (intCharCode == 8216 || intCharCode == 8217) 
								{
									strNewValue = strNewValue + '\'';									
								}
								else if (intCharCode == 61623 || intCharCode == 8212) 
								{
									strNewValue = strNewValue + '-';									
								}
								else
								{							
									//alert(elm.value.charAt(intJ, 1) + ' - ' + elm.value.charCodeAt(intJ, 1));
									//alert(strNewValue);
								}
							}
						}
						
						elm.value = strNewValue;
					}				
				}		
			}
		}
	}	
};

function toggleObjectDisplay(obj, isDisplayed)
{
	if (typeof(obj) == 'undefined')
		return;
	if (isDisplayed)
	{
		obj.style.display="block";
		ToggleTextAreas(obj);
		ToggleVocusSelects(obj);
	}
	else
	{
		obj.style.display="none";
	}
};

function clearSelect(select)
{
	var options = select.options;
	var length = options.length;
	
	for (i=0; i<length; i++)
	{
		options.remove(0);
	}
};

function inputTextEnable(src)
{
	if (typeof(src) != 'undefined' && src != null)
	{
		src.readOnly = false;
		src.style.backgroundColor = 'white';
		src.tabIndex = 0;
	}
};

function inputTextDisable(src)
{
	if (typeof(src) != 'undefined' && src != null)
	{
		src.readOnly = true;
		src.style.backgroundColor = 'LIGHTGREY';
		src.tabIndex = -1;	

	}
};

function toggleTextBoxEnabled(textBox, isEnabled)
{
	var backgroundColor;
	var tabIndex;
	
	if (isEnabled)
	{
		backgroundColor = 'white';
		tabIndex = 0;
	}
	else
	{
		backgroundColor = 'lightgrey';
		tabIndex = -1;
	}
		
	if (typeof(textBox) != 'undefined' && textBox != null)
	{
		textBox.style.backgroundColor=backgroundColor;
		
		if (!isEnabled)
    		textBox.style.border = '1 solid #7F9DB9';
    	else
        {
            textBox.style.borderWidth = '';
            textBox.style.borderStyle = '';
            textBox.style.borderColor = '';
        }
            
		textBox.readOnly=!isEnabled;
		textBox.tabIndex = tabIndex;
	}
};

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	{
		num = "0";
	}
		
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+',' + num.substring(num.length-(4*i+3));
	}
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
};


function submitOnReturn(e, submitButtonId)
{
	if (typeof(vocusSubmitControlPresent) == 'undefined')
	{
		var intKEYCODE_ENTER = 13;
		
		if (submitButtonId == null || submitButtonId == "")
		{
			submitButtonId = "defaultSubmitHidden";
		}
		else
		{
			if (document.getElementById(submitButtonId + "Button") != null)
				submitButtonId = submitButtonId + "Button";
			else if (document.getElementById(submitButtonId + "OK") != null)
				submitButtonId = submitButtonId + "OK";
			else if (document.getElementById(submitButtonId) == null)
				submitButtonId = "defaultSubmitHidden";
		}
		
		if (submitButtonId == "defaultSubmitHidden")
		{
			if (document.getElementById(submitButtonId) != null)
				submitButtonId = document.getElementById(submitButtonId).value;
			else
				submitButtonId = "";
		}
		
		if (submitButtonId != "")
		{
			if (document.all)
			{
				if (window.event.keyCode == intKEYCODE_ENTER)
				{
					if (document.getElementById(submitButtonId) != null)
					{
						document.getElementById(submitButtonId).click();
						window.event.returnValue = false;
					}
				}
			}
			else
			{
				if (e.which == intKEYCODE_ENTER)
				{
					if (document.getElementById(submitButtonId) != null)
					{
						document.getElementById(submitButtonId).click();
						e.preventDefault();
					}
				}
			}
		}
	}
};

function formOnSubmit()
{
	if (document.forms[0].elements['defaultSubmitHidden'] == null && document.all)
	{
		window.event.returnValue = false;
	}
};

var formSubmitted = false;
var isDocumentLoaded = false;
var oldPostBackFunction;
var picklistValidateOnReturn = false;

function overridePostBack()
{
	if (typeof(__doPostBack) != 'undefined')
	{
		try
		{
			oldPostBackFunction = __doPostBack;
			try
			{
				__doPostBack = newPostBackFunction;
			}
			catch (e)
			{
				__doPostBack = oldPostBackFunction;
			}
		}	
		catch (e)
		{
			alert('Should not be here (overridePostBack)!');
		}
	}
};

function newPostBackFunction(eventTarget, eventArgument) 
{
	try
	{
	  vocusPostBack = true;
	  var theform = document.forms[0];
		VocusEventTargetValue = eventTarget;
		VocusEventArgumentValue = eventArgument;
		theform.__EVENTTARGET.value = eventTarget.replace(/\$/g, ":");
		theform.__EVENTARGUMENT.value = eventArgument;
		if (document.getElementById('btnHiddenSubmit'))
		{
		  document.getElementById('btnHiddenSubmit').click();
		}
		else
		{
		  theform.submit();
		}
	}
	catch (e)
	{
		try
		{
			oldPostBackFunction(eventTarget, eventArgument);
		}
		catch (e)
		{
			alert('Should not be here (newPostBackFunction)!');
		}
	}
};

var VocusEventTargetValue = '';
var VocusEventArgumentValue = '';

function VocusSetEventArgs(eventTarget, eventArgument)
{
	VocusEventTargetValue = eventTarget;
	VocusEventArgumentValue = eventArgument;
}

function VocusClearEventArgs()
{
	VocusEventTargetValue = '';
	VocusEventArgumentValue = '';
}

function VocusOnSubmit(eventTarget, eventArgument)
{
	if (typeof(VocusOnSubmitExecute) != 'undefined' && !vocusPostBack)
		VocusOnSubmitExecute(eventTarget, eventArgument);
	vocusPostBack = false;

}

var vocusPostBack = false;
function __doPostBackEx(eventTarget, eventArgument)
{
	if (typeof(objvocusAjaxGrid) != 'undefined' && objvocusAjaxGrid != null)  // Stupid IE returns type as object even though it's null
	{
		$('ajaxGridStartIndex').value = objvocusAjaxGrid.startIndex;
		if ($('showListSave') && $('saveDiv'))
		{
			if ($('saveDiv').style.display == 'inline')
			{
				$('showListSave').value = 'true';
			}
			else
			{
				$('showListSave').value = 'false';
			}
		}
		objvocusAjaxGrid.events.sendCheckedOnUnload(null, 'YES');
	}
	vocusPostBack = true;
	VocusEventTargetValue = eventTarget;
	VocusEventArgumentValue = eventArgument;
	if (formSubmitted == false && isDocumentLoaded)
	{
		var onSubmitResult = true;
		if (document.forms[0].onsubmit != null)
		{
			var result;
			
			result = document.forms[0].onsubmit();
						
			if (result != null)
				onSubmitResult = result;
				
		}

		if (onSubmitResult)
		{		
			formSubmitted = true;
			
			__doPostBack(eventTarget, eventArgument);

			if (checkHideMessageType(eventTarget))
			{
				hideSelects(document.forms[0]);
				HideToolbar();
			
				showWaitMessage();
			}
			
		}
	}
	//else
	//{
	//	alert("Form has already been submitted.");
	//}
};
function checkHideMessageType(eventTarget)
{
	return (typeof(vs) === 'undefined' || vs._pageEvents.checkTransitionMessageShow(eventTarget));
};
function isElementSelect(element)
{
	try
	{
		return (element.type.toUpperCase().indexOf("SELECT") != -1);
	}
	catch(e)
	{
		return false;
	}
};

var hiddenSelectArray = new Array();
var hiddenSelectVisibilityArray = new Array();
var selectsHidden = false;
var restrictPopupShow = false;
function hideSelects(canShow)
{
	if (!document.all)
		return;
  if (!selectsHidden)
  {
  	var iframes = document.getElementsByTagName('IFRAME');
	 	var iframe;
  	for (var i=0; i<=iframes.length-1; i++)
  	{
  		iframe = iframes[i];
  		if (iframe.contentWindow.hideSelects)
  		{
  			if (restrictPopupShow)
  				iframe.contentWindow.eval('restrictPopupShow=true;');
  			else
   				iframe.contentWindow.eval('restrictPopupShow=false;');
 			iframe.contentWindow.eval('hideSelects("NO");');
  		}
  	}
  	var elements = document.getElementsByTagName('SELECT');
  	var element;
  	var counter = 0;
  	
  	for (var i=0; i<=elements.length-1; i++)
  	{
  		element = elements[i];
  		
  		if (isElementSelect(element))
  		{
  			if (element.style.visibility != 'hidden' && element.size <= 1)
  			{
  				hiddenSelectArray[counter] = element;
  				hiddenSelectVisibilityArray[counter] = element.style.visibility;
  				element.style.visibility = 'hidden';
  				counter++;
  			}
  		}
  	}
  	selectsHidden = true;
  }
  else
  {
  	if (canShow != 'NO')
    	showSelects();
  }
};

function showSelects()
{
	if (!document.all)
		return;
	if (!restrictPopupShow)
	{
		for (var i=0; i<=hiddenSelectArray.length-1; i++)
		{
			var element = hiddenSelectArray[i];
			element.style.visibility = hiddenSelectVisibilityArray[i];
		}
		var iframes = document.getElementsByTagName('IFRAME');
		var iframe;
	
		for (var i=0; i<=iframes.length-1; i++)
		{
			iframe = iframes[i];
			if (iframe.contentWindow.showSelects)
			{
  			if (restrictPopupShow)
  				iframe.contentWindow.eval('restrictPopupShow=true;');
  			else
   				iframe.contentWindow.eval('restrictPopupShow=false;');
				iframe.contentWindow.eval('showSelects();');
			}
		}
		selectsHidden = false;
	}
};

function isElementDateTimeButton(element)
{
	try 
	{
	  if ((element.id.toUpperCase().indexOf("TIMEBOX_") != -1) || (element.id.toUpperCase().indexOf("DATEBOX_") != -1))
	  {
	    return true;
	  }
	  else
	  {
	    return false; 
	  }
	}
	catch(e)
	{
		return false;
	}
};

var hiddenDateTimeButtonArray = new Array();
var hiddenDateTimeButtonVisibilityArray = new Array();
var dateTimeButtonsHidden = false;

var divArray = new Array();
var divZIndexArray = new Array();
var divPositionArray = new Array();

function hideDateTimeButtons(form)
{
  if (!dateTimeButtonsHidden)
  {
    divArray[0] = document.getElementById('mainDiv');
//    divArray[1] = document.getElementById('quickSearch_otherPanel');
  	for (var i=0; i<=divArray.length-1; i++)
  	{
  	 // alert(divArray[i].owner);
  		divZIndexArray[i] = divArray[i].style.zIndex;
  		divPositionArray[i] = divArray[i].style.position;
			divArray[i].style.zIndex = -1;
			divArray[i].style.position = 'relative';			
    }
  	var elements = form.elements;
  	var element;
  	var counter = 0;
  	if (document.getElementById('divMergeSubmit'))
  	{
  		hiddenDateTimeButtonArray[counter] = document.getElementById('divMergeSubmit');
  		document.getElementById('divMergeSubmit').style.visibility = 'inherit';
  		hiddenDateTimeButtonVisibilityArray[counter] = document.getElementById('divMergeSubmit').style.visibility;
  		document.getElementById('divMergeSubmit').style.visibility = 'hidden';
  		counter++;	  
  	}
  
  	if (document.getElementById('divIMailEditor'))
  	{
  		hiddenDateTimeButtonArray[counter] = document.getElementById('divIMailEditor');
  		document.getElementById('divIMailEditor').style.visibility = 'inherit';
  		hiddenDateTimeButtonVisibilityArray[counter] = document.getElementById('divIMailEditor').style.visibility;
  		document.getElementById('divIMailEditor').style.visibility = 'hidden';
  		counter++;	  
  	}
  
  	for (var i=1; i<=6; i++)
  	{
    	if (document.getElementById('divPublishMemo'+i))
    	{
    		hiddenDateTimeButtonArray[counter] = document.getElementById('divPublishMemo'+i);
    		document.getElementById('divPublishMemo'+i).style.visibility = 'inherit';
    		hiddenDateTimeButtonVisibilityArray[counter] = document.getElementById('divPublishMemo'+i).style.visibility;
    		document.getElementById('divPublishMemo'+i).style.visibility = 'hidden';
    		counter++;	  
    	}
  	}
  
  	for (var i=0; i<=elements.length-1; i++)
  	{
  		element = elements[i];
  		
  		if (isElementDateTimeButton(element))
  		{
  			if (element.style.visibility != 'hidden')
  			{
  				hiddenDateTimeButtonArray[counter] = element;
  				hiddenDateTimeButtonVisibilityArray[counter] = element.style.visibility;
  				element.style.visibility = 'hidden';
  				counter++;
  			}
  		  element = document.getElementById(element.id.substring(0,7)+'Image'+element.id.substring(7));
  			if (element.style.visibility != 'hidden')
  			{
  				hiddenDateTimeButtonArray[counter] = element;
  				hiddenDateTimeButtonVisibilityArray[counter] = element.style.visibility;
  				element.style.visibility = 'hidden';
  				counter++;
  			}
  		}
      else if (isElementSelect(element))
  		{
  			if (element.style.visibility != 'hidden')
  			{
  				hiddenDateTimeButtonArray[counter] = element;
  				hiddenDateTimeButtonVisibilityArray[counter] = element.style.visibility;
  				element.style.visibility = 'hidden';
  				counter++;
  			}
  		}
  	}
  	dateTimeButtonsHidden = true;
  }
  else
  {
    showDateTimeButtons();
  }
};

function showDateTimeButtons()
{
	var form = document.forms[0];
	for (var i=0; i<=divArray.length-1; i++)
 	{
		divArray[i].style.zIndex = divZIndexArray[i];
		divArray[i].style.position = divPositionArray[i];			
  }
	var elements = form.elements;

	for (var i=0; i<=hiddenDateTimeButtonArray.length-1; i++)
	{
		var element = hiddenDateTimeButtonArray[i];
		element.style.visibility = hiddenDateTimeButtonVisibilityArray[i];
	}
	dateTimeButtonsHidden = false;
};

function UseWorkingMessage()
{
	var messageModeHidden = document.getElementById('messageModeHidden');
	
	if (messageModeHidden != null)
		messageModeHidden.value = 'wait';
};

function UseSearchingMessage()
{
	if (top && top.vs && top.vs.StrictHeader) 
	{
		return;
	}
	var messageModeHidden = document.getElementById('messageModeHidden');
	
	if (messageModeHidden != null)
		messageModeHidden.value = 'search';
};

function WaitAndRedirect(messageMode, url, noUnloadTransition) {
    if (noUnloadTransition)
        vsParams._pageParameters.noUnloadTransition = true;

    var messageModeHidden = document.getElementById('messageModeHidden');

    if (messageModeHidden != null)
    {
        messageModeHidden.value = messageMode;
    }

	showWaitMessage();

	if (parent &&
		parent.vs &&
		parent.vs.StrictHeader) 
	{
		parent.vs.currentPage.changeBody(vs._entity, url, undefined, noUnloadTransition);
	}
	else 
	{
		location.href = url;
	}
};

function ClearScreen()
{
	if (top && top.vs && top.vs.StrictHeader) 
	{
		return;
	}
    var mainDiv = null;
    var toolbarDiv = null;
    var footerDiv = null;
    var doc = null;
    var navMainSectionDiv = null;
    
    if (top.frames["frameBody"] == null)
    {
        mainDiv = $("mainDiv");
        navMainSectionDiv = $("navMainSectionDiv");
        toolbarDiv = $("toolbarDiv");
	    footerDiv = $("footerDiv");
	    doc = document;
    }
    else
    {
        mainDiv = top.frames["frameBody"].document.getElementById('mainDiv');
        navMainSectionDiv = top.frames["frameBody"].document.getElementById('navMainSectionDiv');
        toolbarDiv = top.frames["frameBody"].document.getElementById('toolbarDiv');
        footerDiv = top.frames["frameBody"].document.getElementById('footerDiv');
        doc = top.frames["frameBody"].document;
    }
    
    if (navMainSectionDiv != null)
        mainDiv = navMainSectionDiv;

    // IE has an issue where if IFRAMES are in the process of loading it does not switch to cancel the request but waits until they have loaded to switch to the new page (this causes the app to seem slow when you switch from Analytics to another tab
    try
    {
        if (IsBrowserIE() && top.frames["frameBody"] != null && top.frames["frameBody"].frames.length > 0)
        {
            for (i=0; i<top.frames["frameBody"].frames.length; i++)
            {       
            		if (top.frames["frameBody"].frames[i].location.href.indexOf('fckeditor') == -1)
            		{
						try
						{
		                	top.frames["frameBody"].frames[i].location.replace(vsParams && vsParams.urls ? vsParams.urls.blank : 'javascript: document.write("<html><body></body></html>");document.close();'); 
						}
						catch (e)
						{
						}
                }
            }
        }
    }
    catch (e) {}

    if (mainDiv != null && mainDiv.style.display != 'none')
    {
        var h = mainDiv.offsetHeight;
        
        if (toolbarDiv != null)
        {
            h += toolbarDiv.offsetHeight;
        }

        if (footerDiv != null)
        {
            h += footerDiv.offsetHeight;
        }

	    var clearDiv = doc.createElement('div');
	    clearDiv.style.position = 'absolute';
	    clearDiv.style.left = mainDiv.offsetLeft+1;
	    clearDiv.style.width = mainDiv.offsetWidth-2;
	    clearDiv.style.backgroundColor = 'white';
	    clearDiv.style.border = 'none';
	    clearDiv.style.top = '0px';
	    clearDiv.style.height = (h-1) + 'px';
	    clearDiv.style.zIndex = 254;
	    doc.body.appendChild(clearDiv);

	    var clearIFrame = doc.createElement('iframe');
	    clearIFrame.style.position = 'absolute';
	    clearIFrame.style.left = mainDiv.offsetLeft+1;
	    clearIFrame.style.width = mainDiv.offsetWidth-2;
	    clearIFrame.style.backgroundColor = 'white';
	    clearIFrame.style.border = 'none';
	    if (document.all)
	    {
	    	clearIFrame.src = vsParams && vsParams.urls ? vsParams.urls.blank : 'javascript: document.write("<html><body></body></html>");document.close();';
	    }
	    clearIFrame.style.top = '0px';
	    clearIFrame.style.height = (h-1) + 'px';
	    clearIFrame.style.zIndex = 253;
	    doc.body.appendChild(clearIFrame);
    }
    CollapseToolbar();
};

function showWaitMessage()
{
	if (top && top.vs && top.vs.StrictHeader) 
	{
		return;
	}
    if (window.location.href.toUpperCase().indexOf("VOCUSPOPUP") == -1)
    {
	    var mainDiv = document.getElementById('mainDiv');
	    var waitMessageDiv = document.getElementById('waitMessageDiv');
	    var toolbarDiv = document.getElementById('toolbarDiv');
	    var settingsDiv = document.getElementById('settingsDiv');
	    var navDiv = document.getElementById('navDiv');
	    var searchMessageDiv = document.getElementById('searchMessageDiv');
	    var messageModeHidden = document.getElementById('messageModeHidden');
	    var isSearchMessage = false;
	    var isWaitMessage = false;
    	
	    if (messageModeHidden != null)
	    {
		    isSearchMessage = messageModeHidden.value == 'search';
		    isWaitMessage = messageModeHidden.value == 'wait';
	    }
    	
	    if (isSearchMessage)
	    {
		    if (searchMessageDiv != null)
		    {
			    var messageDivHeight = Number(searchMessageDiv.style.height.replace('px',''));
			    var messageDivWidth = Number(searchMessageDiv.style.width.replace('px',''));
    			
			    searchMessageDiv.style.left = (GetWindowWidth() - messageDivWidth) / 2;
			    searchMessageDiv.style.top = (GetWindowHeight() - messageDivHeight) / 2;			
			    searchMessageDiv.style.display = "block";
			    
			    ClearScreen();
			    
			    searchMessageDiv.style.zIndex = 255;
    			
			    if (settingsDiv != null)
				    settingsDiv.disabled = true;
			    if (navDiv != null)
				    navDiv.disabled = true;
		    }
	    }
	    else if (isWaitMessage)
	    {
		    if (waitMessageDiv != null)
		    {
			    var messageDivHeight = Number(waitMessageDiv.style.height.replace('px',''));
			    var messageDivWidth = Number(waitMessageDiv.style.width.replace('px',''));
    			
			    waitMessageDiv.style.left = (GetWindowWidth() - messageDivWidth) / 2;
			    waitMessageDiv.style.top = (GetWindowHeight() - messageDivHeight) / 2;			
			    waitMessageDiv.style.display = "block";
    			
			    ClearScreen();

			    waitMessageDiv.style.zIndex = 255;

			    if (settingsDiv != null)
				    settingsDiv.disabled = true;
			    if (navDiv != null)
				    navDiv.disabled = true;
		    }
	    }
	    else
	    {
		    ClearScreen();

		    if (settingsDiv != null)
			    settingsDiv.disabled = true;
		    if (navDiv != null)
			    navDiv.disabled = true;
	    }
    }
};

function hideWaitMessage()
{
	var mainDiv = document.getElementById('mainDiv');
	var waitMessageDiv = document.getElementById('waitMessageDiv');
	var toolbarDiv = document.getElementById('toolbarDiv');
	var settingsDiv = document.getElementById('settingsDiv');
	var navDiv = document.getElementById('navDiv');
	var searchMessageDiv = document.getElementById('searchMessageDiv');
	var messageModeHidden = document.getElementById('messageModeHidden');
	var isSearchMessage = false;
	var isWaitMessage = false;
	
	if (messageModeHidden != null)
	{
		isSearchMessage = messageModeHidden.value == 'search';
		isWaitMessage = messageModeHidden.value == 'wait';
	}

	if (isSearchMessage)
	{
		// Do nothing
	}
	else if (isWaitMessage)
	{
		if (waitMessageDiv != null)
		{					
			waitMessageDiv.style.display = "none";
			
			if (mainDiv != null)
				mainDiv.style.visibility = 'visible';
			if (toolbarDiv != null)
				toolbarDiv.disabled = false;
			if (settingsDiv != null)
				settingsDiv.disabled = false;
			if (navDiv != null)
				navDiv.disabled = false;
		}
	}
	else
	{
		if (mainDiv != null)
			mainDiv.style.visibility = 'visible';
		if (toolbarDiv != null)
			toolbarDiv.disabled = false;
		if (settingsDiv != null)
			settingsDiv.disabled = false;
		if (navDiv != null)
			navDiv.disabled = false;
	}
};

function GetWindowHeight()
{
	// The Height of a window is determined differently in Mozilla vs. IE
	
	if (IsBrowserIE())
	{
		// IE
    		return document.body.clientHeight;		
	} 
	else 
	{		
		// Mozilla
    		return window.innerHeight - 20;
	} 
};

function GetWindowWidth()
{
	if (IsBrowserIE())
	{
		// IE
    		return document.body.clientWidth;		
	} 
	else 
	{		
		// Mozilla
    		return window.innerWidth - 20;
	} 
};

function IsBrowserIE()
{
	if (document.all)
	{
		return true;
	}
	else
	{
		return false;
	}
	
};
function IsOsMac()
{
	if (navigator.appVersion.indexOf('Macintosh')!=-1)
	{
		return true;
	}
	else
	{
		return false;
	}

};
function SetCursorMozilla(cursorObject,cursorStyle)
{
	if (((IsBrowserIE()) && (GetIEVersion() >= 6)) || (!(IsBrowserIE())))
	{
	  cursorObject.style.cursor=cursorStyle;	
	}
};

function GetIEVersion()
{
	var a = navigator.userAgent;
	var ie = a.indexOf("MSIE");
	return ie+1 ? parseFloat(a.substring(ie+5,a.indexOf(";",ie+5))) : 0;
};

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
};

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
};

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
};
function vocusLog(msg, noTrace)
{
	if (msg === null)
	{
		msg = 'null';
	}
	if (location.hostname.toLowerCase() == 'localhost' || location.hostname.indexOf('10.1.1.') == 0 || location.hostname.indexOf('.') == -1)
	{
		if (typeof(top.console) != 'undefined' && top.console.debug)
		{
			if (typeof(msg) == 'object')
				top.console.debug("Object - " + msg.toString() + ": %o", msg);
			else
				top.console.debug(msg);
			if (typeof(noTrace) == 'undefined' || !noTrace)
				top.console.trace();
		}
		else if (location.hostname.toLowerCase() == 'localhost' || $('fblIFrame')) 
	    {
	        if (typeof(msg) == 'object')
			    console.debug("Object - " + msg.toString() + ": %o", msg);
		    else
			    console.debug(msg);
		    if (typeof(noTrace) == 'undefined' || !noTrace)
			    console.trace();
	    }
		else
		{
			if (!$('vocusLog'))
			{
				createLog();
			}
			if ($('vocusLog').style.display == 'none')
			{
				$('vocusLog').style.display = 'block';
			}
			$('vocusLogText').value = msg + '\n' + $('vocusLogText').value;
		}
	}
};
var vocusLogObj = null;
function createLog()
{
	var logDiv = document.createElement('div');
	var logText = document.createElement('textarea');
	var logClear = document.createElement('input');
	var logHide = document.createElement('input');
	logDiv.id = 'vocusLog';
	logDiv.onmousedown = startLogMove.bindAsEventListener(logDiv);
	logDiv.style.display = 'none';
	logDiv.style.position = 'absolute';
	logDiv.style.zIndex = 255;
	logDiv.style.width = '50%';
	logDiv.style.height = 'auto';
	logDiv.style.backgroundColor = 'white';
	logDiv.style.cursor = 'move';

	logDiv.style.border = 'thick red solid';

	logText.id = 'vocusLogText';
	logText.name = 'vocusLogText';
	logText.rows = 6;
	logClear.type = 'button';
	logClear.value = 'Clear Log';
	logClear.onclick = function () { $('vocusLogText').value = ''; };
	logHide.type = 'button';
	logHide.value = 'Hide Log';
	logHide.onclick = function () { $('vocusLog').style.display='none';  };
	logDiv.appendChild(logText);
	logDiv.appendChild(logClear);
	logDiv.appendChild(logHide);
	vocusLogObj = logDiv;
	//if ($('mainDiv'))
	//	$('mainDiv').insertBefore(logDiv, $('mainDiv').childNodes[0]);
	//else
		document.body.insertBefore(logDiv, document.body.childNodes[0]);
		
};
function returnFalse(ev)
{
	Event.stop(ev);
	return false;
};
function startLogMove(ev)
{		
	var el = Event.element(ev);
	if (el.style.cursor != 'move')
		return;
	Event.stop(ev);
	
	Event.observe(document.body, 'mousemove', moveLog);
	Event.observe(document.body, 'mouseup', stopLogMove);
	Event.observe(document.body, 'drag', returnFalse);
	Event.observe(document.body, 'selectstart', returnFalse);
};
function moveLog(ev)
{
	Event.stop(ev);
	var x = Event.pointerX(ev);
	var y = Event.pointerY(ev);
	x -= parseInt(parseInt(vocusLogObj.offsetWidth)/2);
	//y -= 20;
	vocusLogObj.style.left = x+'px';
	vocusLogObj.style.top = y+'px';	
};
function stopLogMove(ev)
{
	Event.stopObserving(document.body, 'mousemove', moveLog);
	Event.stopObserving(document.body, 'mouseup', stopLogMove);	
	Event.stopObserving(document.body, 'drag', returnFalse);
	Event.stopObserving(document.body, 'selectstart', returnFalse);
};

function currentAttachmentHide(hide)
{
	if (hide == '1')
	{
		document.getElementById('divCurrentAttachmentFile').style.display='none';
		document.getElementById('deleteAttachment').value='1';
	}
	else
	{
		document.getElementById('divCurrentAttachmentFile').style.display='block';
		document.getElementById('deleteAttachment').value='0';
	}
};

function logFunc(objRef, funcName, logText, beforeCallBack, afterCallBack)
{
	objRef[funcName] = objRef[funcName].wrap(function(proceed)
	{
        var params = $A(arguments).slice(1);
        console.log(logText, params);
        
        if (beforeCallBack) 
        {
            beforeCallBack();
        }
        var retVal = proceed.apply(this, params);
        if (afterCallBack) 
        {
            afterCallBack();
        }
        return retVal;
    });
};