// Initialised in alladminpages_inc.asp
var gsRootURL = '/EMRRoot/';
var gsBaseURL = '../';
var gsPageID;
var gbDisplayPageHelp=true;
var gbSupportLogon = false;
// Case 104047 - base url for documentation hosting - this is set on the page as the value is dynamicly generated from a reg setting and the current version
var gsDocumentationURL = '***NOT SET***';

/*Utility function; Goes up the DOM from the element oElement, till
a parent element with the tag that matches sTag
is found. Returns that parent element.*/
function EMR_GetParent(oElement,sTag) 
{
    
  while (oElement != null && oElement.tagName.toLowerCase() != sTag.toLowerCase()){
    oElement = oElement.parentElement || oElement.parentNode;
  }
  // When get parent objects, IE gives us an outer wrapper object which has refs to the document object
  // and to what we want - termed "element".
  if ( oElement && oElement.element )
  {
  	oElement = oElement.element;
  }
  return oElement;
}

function EMR_OpenBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function EMR_GetStyleObj(id) {
    if (document.getElementById || // DOM-compliant browsers (MSIE5, NSN6, O5)
        document.all) {            // or MSIE 4
        return EMR.getElement(id).style;
    } else return EMR.getElement(id); // NSN4
}


function EMR_GetObj(id) {
   return EMR.getElement(id);
   /*
   RD 6/3/2009. Case 94670. Replace uses of EMR_getObj with EMR.getElement
   
   if (document.getElementById) { // DOM-compliant browsers (MSIE5, NSN6, O5)
   return document.getElementById(id);
   } else if (document.all) { // MSIE4
   return document.all[id];
   } else if (document.layers) { // NSN4
   return document.layers[id];
   } else { // Trap DHTML-impaired browsers
   return false;
   }
   */
}

function EMR_SetClass(id, classname) {
    if(document.all)
        id.className = classname;
    else
        id.setAttribute("class", classname);
    
    return true;
}

/*
* Returns the next-highest element in the hierarchy of the specified element that
* isn't a text-based node (nodeType == ELEMENT_NODE)
*/
function EMR_GetNonTextNode(node)
{
    try
    {
        while (node && node.nodeType != 1)
            node = node.parentNode;
    }

    catch (ex) { node = null;}

    return node;
}

/**
* Returns the absolute location of the specified element
* Useful when used with EMR_GetNonTextNode as Firefox replacement
* for the IE-only offsetX attribute.
*/
function EMR_GetLocation(el)
{
      var c = { x : 0, y : 0 };

      while (el)
      {
            c.x += el.offsetLeft;
            c.y += el.offsetTop;
            el = el.offsetParent;
      }

      return c;
}


// Sets cookie values. Expiration date is optional - if not supplied, cookie will be session-only
//
function EMR_SetCookie(name, value, expire)
{
	document.cookie = name + "=" + escape(value)   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function EMR_GetCookie(Name)
{
	var search = Name + "="
	if (document.cookie.length > 0)
	{
		// if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1)
		{
			// if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

// Replace all instances of a string with another.
// Do not use if the replacement string includes the original as it will Iloop.
function EMR_ReplaceChars( str, sFind, sReplace  )
{
	if ( str )
	{
		while ( str.indexOf( sFind ) >= 0 )
		{
			str = str.replace(sFind, sReplace);
		}
	}
	else
	{
		str = '';
	}
	return str;

}

// Do simple mailmerge of markup (client-side) e.g. for help text that's stored in divs
function EMR_MergeMarkup(str)
{
	str = EMR_ReplaceChars(str, '{i}', '<img src="' + gsRootURL + 'images/icons/info_small.gif" class="emr_img_inline_2">');
	str = EMR_ReplaceChars(str, '{?}', '<img src="' + gsRootURL + 'images/icons/help_small.gif" class="emr_img_inline_2">');
	str = EMR_ReplaceChars(str, '{m}', '<img src="' + gsRootURL + 'images/icons/quick_guides_small.gif" class="emr_img_inline_2">');
	str = EMR_ReplaceChars(str, '{v}', '<img src="' + gsRootURL + 'images/icons/video_small2.gif" class="emr_img_inline_2">');
	// Case 104047 - documents are now hosted at thier own URL - replace {docs} with the root url used for documentation
	str = EMR_ReplaceChars(str, '{docs}', gsDocumentationURL);
	str = EMR_ReplaceChars(str, '%7Bdocs%7D', gsDocumentationURL); // Cope with where the curly brackets have been escaped in URLs

	return str;
}

// Case 119588. AMH.
// Gets the sessInstallerVersionForQuery key session value. Safe for use within standard EMR pages/floatup dialogs and 
// old-style popup windows.
function EMR_GetVersion() {
    if (typeof(top.session) != 'undefined' && typeof(top.session.getValue) != 'undefined')
        return top.session.getValue('sessInstallerVersionForQuery');
    else
    {
        if (window.opener && typeof(window.opener.top.session) != 'undefined' && typeof(window.opener.top.session.getValue) != 'undefined')
            return window.opener.top.session.getValue('sessInstallerVersionForQuery');
        else
            return '';    
    }
}

function EMR_LoadCommonHelpResource() {
	/* build the url to the document based on the language code and page id (there is 1 help text document per page 
	 * per language stored in directories by language)	*/ 
	// Case 119588 - use EMR_GetVersion() to get version.
    var resourceUrl = gsRootURL + 'text/HelpResource.asp?language=' + EMR_gsHelpTextLanguageCode + '&pageId=common&version=' + EMR_GetVersion();
    var iframe = document.getElementById("EMR_CommonHelpResource");
    
	// don't bother re-navigating if we are already on the right page!
	if(resourceUrl != iframe.src) {
/************************************************************************************************************
* TODO - this is always firing becuase the location.href is made absolute before the comparison meaning the
* value do not match even when they should.
************************************************************************************************************/
		setTimeout(function() { iframe.src = resourceUrl; }, 1);
	}	
}

function EMR_LoadHelpResource(pageID) {

	/* build the url to the document based on the language code and page id (there is 1 help text document per page 
	 * per language stored in directories by language)	*/
	// Case 119588 - use EMR_GetVersion() to get version.
    var resourceUrl = gsRootURL + 'text/HelpResource.asp?language=' + EMR_gsHelpTextLanguageCode + '&pageId=' + pageID + '&version=' + EMR_GetVersion();
    var iframe = document.getElementById("EMR_HelpResource");
    
	// don't bother re-navigating if we are already on the right page!
	if(resourceUrl != iframe.src) {
/************************************************************************************************************
* TODO - this is always firing becuase the location.href is made absolute before the comparison meaning the
* value do not match even when they should.
************************************************************************************************************/
		setTimeout(function() { iframe.src = resourceUrl; }, 1);
	}	
}



// DH 11/08/08 Given a DOM element oElement, find an appropriate helptext ID and update the helptext. Case 67237
// Moved from emr_controlwithhelp.htc

function EMR_UpdateHelpTextFromElement(oElement){

try
    {
        // DH 08/08/08 Use the helptextid attribute if it is available, if not, use the element's ID
        // see case 67222

        var sID;
        if(oElement.getAttribute('emr_helptextid')){
            sID = oElement.getAttribute('emr_helptextid');
        }else{
            sID = oElement.id;
        }

        if ( sID )
        {
            if ( parent )
            {
            
                // TODO - Debug New window pop-ups & help text working in IE not FF
                if(EMR_IsDialog()){
                    EMR_SetControlHelpTextFromID(sID);  // This may or may not help the pop-up window problem
                }else{
                    EMR_TopFrame().EMR_SetControlHelpTextFromID(sID);
                }
                
            }
        }
     }
     catch (e)
     {
        // Ignore - should never happen
     }
     finally
     {
     }
}


// Get the text for id "sID". First look in the hidden text defined for each admin page in separate spans.
// If not found there, look in the help window for text that's common to all pages. 
function EMR_GetHelpTextForID(oAdminPage, sID, oHelpText)
{
	// Look first in the admin page.
	var oControlHelp ;
	if ( oAdminPage && EMR.getElement )
	{
	    oControlHelp = oAdminPage.EMR.getElement(sID);
		if ( oControlHelp )
		{
			oHelpText.text = oControlHelp.innerHTML;
			if ( EMR_ExtractHelp(oHelpText) )
			{
				return true; // got it
			}
		}
	}

	try
	{
	    if (EMR.getElement('EMRHelpFrame'))
		{
			// Didn't find in the admin page - now look in the help window for global text.
			oControlHelp = EMRHelpFrame.EMR_GetObj(sID);
			if ( oControlHelp )
			{
				oHelpText.text = oControlHelp.innerHTML;
				if ( EMR_ExtractHelp(oHelpText) )
				{
					return true; // got it
				}
			}
		}
	}
	catch(e)
	{
		// do nothing
		/*25955*/ Log(e, 'Could not get help text for ID' + sID, logVerbosity.Information);
	}
	
	return false; // not found
}


// Extract help from a div - first line is heading, rest is body. Go from oHelp.text to oHelp.heading and oHelp.body
function EMR_ExtractHelp(oHelp) 
{
	var sHelpText = oHelp.text;
	var arrHelp = (sHelpText.split('{emr_'));
	var iCount = arrHelp.length;
	var iPos;
	for ( iPos = 1 ; iPos < iCount ; iPos ++ )
	{
		var sEntry = arrHelp[iPos];
		var iEndType = sEntry.indexOf('}');
		if ( iEndType > 0 )
		{
			var sType = sEntry.slice(0,iEndType).toLowerCase();
			var sText = sEntry.slice(iEndType + 1);
			// If there's a trailing BR, remove it as this is put in for ease of editing.
			if ( sText.slice(sText.length-4).toLowerCase() == '<br>' )
			{
				sText = sText.slice(0,sText.length-4);
			}
			// Now put the text into the oHelp object
			switch(sType)
			{
				case 'head':
					oHelp.heading = sText;
					break;
				case 'more':
					oHelp.moreURL = sText;
					break;
				case 'video':
					oHelp.videoID = sText;
					break;
				case 'faq':
					oHelp.faqID = sText;
					break;
				case 'body':
					oHelp.body = sText;
					break;
				default:
					break;
			}
		}
		else
		{
			/*25955*/ Log('Malformed help text entry for: ' + oHelp.text, logVerbosity.Warning); 
		}
	}

	// TODO Remove
	// extract the heading and body
	//var iBody = sHelpText.toLowerCase().indexOf('<br>');
	//if ( iBody )
	//{
	//	oHelp.heading = sHelpText.slice(0, iBody);
	//	oHelp.body = sHelpText.slice(iBody+4);
	//	return true;
	//}
	if ( iCount > 1 )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function EMR_GetDialogWidth(sOuterFrameDiv)
{
	var varWidth;
	var frame = document.getElementById(sOuterFrameDiv)
	if ( frame )
	{
	
	if (window.XMLHttpRequest && !document.all) {
        //  mozilla, safari, opera 9
		varWidth = frame.clientWidth + 25;
    } else {
        // IE6, older browsers, IE7
        varWidth = frame.offsetWidth + 15;
    }
		
		

		varWidth = varWidth + "px";
	}
	return varWidth;
}

function EMR_GetDialogHeight(sOuterFrameDiv)
{
	var varHeight ;
	var frame = document.getElementById(sOuterFrameDiv)
	if ( frame )
	{
	    if (window.XMLHttpRequest && !document.all) {
            // IE 7, mozilla, safari, opera 9
            varHeight = frame.clientHeight + frame.offsetTop + 90;
        } else {
            // IE6, older browsers
            varHeight = frame.offsetHeight + frame.offsetTop + 90;
        }

		
		if (varHeight > 760) varHeight = 760;
		varHeight = varHeight + "px";
	}
	return varHeight;
}

// Resize a dialog to fit the content which is within an outermost div called 'sOuterFrameDiv'
// If this is null, use a default name.

// A change in IE7 means that offsetWidth - and apparently all other similar calls - now return the maximum of:
// * The width of the object
// * The width of the window (or dialog).
// 
// therefore they only option is to increase the window size to e.g. 110em width so that the dialog starts off really large, and then the resize call can make it smaller.

function EMR_ResizeDialog( sOuterFrameDiv )
{
    // call resizeToContent if it exists
    if(window.resizeToContent) 
    {
        window.resizeToContent();
        return;
    }
    
	if (!sOuterFrameDiv ) sOuterFrameDiv = 'OuterFrame';
	
	var varWidth = EMR_GetDialogWidth( sOuterFrameDiv );
	var varHeight = EMR_GetDialogHeight( sOuterFrameDiv );
	
	if (!varWidth || !varHeight )
	{
		return false; // no div present so can't resize.
	}
	
	try
	{

	    // MJA 24Sep09 case 123729 no longer using IE dialogs, so external.dialogWidth retired.
		window.resizeTo(varWidth.replace('px', ''), varHeight.replace('px', ''));
		
	}
	catch (e)
	{
		// MJA case6771. No idea why we reported this. It doesn't seem helpful. alert('Not called from a dialog'); %>
		/*25955*/ //Log(e, 'Not called from a dialog - EMR_ResizeDialog', logVerbosity.Warning);
	}


	// display the pagehelp text
	try
	{
		EMR_SetControlHelpTextFromID('emr_pagehelp');
	}
	catch (e)
	{
		// ignore - probably no help for this dlg
		/*25955*/ //Log(e, 'Probably no help for this dialog - EMR_ResizeDialog', logVerbosity.Warning); 
	}
	return true; // ok
}

function EMR_GetWindowWidth(sOuterFrameDiv)
{
	var varWidth = document.getElementById('OuterFrame').offsetWidth + 30;
	return varWidth;
}

function EMR_GetWindowHeight(sOuterFrameDiv)
{
	var varHeight = document.getElementById('OuterFrame').offsetHeight + document.getElementById('OuterFrame').offsetTop + 150;
	if (varHeight > 600) varHeight = 600;
	return varHeight;
}

// Resize a window to fit the content which is within an outermost div called 'sOuterFrameDiv'
// If this is null, use a default name.
function EMR_ResizeWindow( sOuterFrameDiv )
{
    // FF has a sizeToContent function that does everything for us
    if(window.sizeToContent)
    {
        window.sizeToContent();
        return;
    }
    
	if (!sOuterFrameDiv ) sOuterFrameDiv = 'OuterFrame';
	
	var varWidth = EMR_GetWindowWidth( sOuterFrameDiv );
	var varHeight = EMR_GetWindowHeight( sOuterFrameDiv );
	
	try
	{
		window.resizeTo( varWidth, varHeight ) ;
	}
	catch (e)
	{
		/*25955*/ Log(e, 'Not called from a window - EMR_ResizeWindow', logVerbosity.Warning);
	}
	finally
	{
	}
}


// Set the class name of all keyword links on the help page to the style which navigates through the help content.
function EMR_ChangeClassOfAllLinks()
{
	var arrLinks = document.getElementsByTagName('a');
	var iCountLinks = arrLinks.length;
	var iLink = 0;
	for ( iLink = 0 ; iLink < iCountLinks; iLink ++ )
	{
		var sHref = arrLinks[iLink].href;
		if ( sHref )
		{
			// MJA 15Aug07 case 11325. Get page name only.
			try
			{
				var iLastQuestion=sHref.lastIndexOf('?');
				var iLastSlash=sHref.lastIndexOf('/');
				if ( (iLastSlash > 0) && (iLastQuestion <= 0) )
				{
					sHref = sHref.slice(iLastSlash + 1);
				}
			}
			catch(e)
			{
				// leave href alone
				/*25955*/ Log(e, 'EMR_ChangeClassOfAllLinks', logVerbosity.Warning); 
			}
			
			if ( sHref.indexOf('.') <= 0 )
			{
			    // Case 83611 - use JQuery to add the class so the behaviour is hooked up correctly
			    //arrLinks[iLink].className = 'emr_a_helplink';
			    $(arrLinks[iLink]).addClass('emr_a_helplink');
			}
		}
	}
}

function EMR_GetPageID()
{
	return gsPageID;
}

function EMR_TopFrame()
{
//	return top;

	var oFrame = this;
	while(true){
		if(oFrame.EMR_SetPageID || oFrame.parent == oFrame)
			break;
		else
			oFrame = oFrame.parent;
	}
	return oFrame;
}

// true if current window is a dlg
function EMR_IsDialog()
{
	try
	{
		if ( top == this )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	catch(e)
	{
		/*25955*/ Log(e, 'exception from emr_isdialog', logVerbosity.Serious);
		return false;
	}
}


// Called when this page has loaded 
function EMR_doOnLoadAdmin()
{
	// MJA 05Jan06 case 8029 - fix "permission denied" error when using SSL for frame and not for editor.
    try
	{
		var oHelp = new Object();
		var oTopFrame = EMR_TopFrame();
		if ( parent )
		{
			if ( oTopFrame && oTopFrame.EMR_SetPageID && gbDisplayPageHelp)
			{
				oTopFrame.EMR_SetPageID(gsPageID);
				oTopFrame.EMR_SetHelpTextLanguageCode(gsHelpTextLanguageCode);
				
				// Set the page help for this page.
				oTopFrame.EMR_SetPageHelpTextFromID('emr_pagehelp');
			}
		}

		// MJA 11nov04 set the framest to be the large one for all admin pages except the editor.
		if ( gsPageID != '0106' && oTopFrame && oTopFrame.EMR_SetTopNavNormal )
		{
			oTopFrame.EMR_SetTopNavNormal();
		}
	}
	catch(e)
	{
		// ignore error.
	}
}


function doPageKitCancel()
{
   window.returnValue=null;
   window.close();
   return false
}

function convertToEMRLink(url, userProperties, logonKey) {
    if(!url)
        return url;

    /* check for query string and append the standard EMR parameters as required. */
    if(!userProperties)
        userProperties = top.session.getValue('sessUserProperties', false);
    if(!logonKey)
        logonKey = top.session.getValue('sessLgnK', false);
    
    // check if the url already has a querystring (i.e. ? in the url)
    var containsQS = false;
    if(url.indexOf('?') >= 0)
        containsQS = true;
    
    if(userProperties) {
        url += (containsQS ? '&' : '?') + userProperties
        containsQS = true;
    }
    if(logonKey)
        url += (containsQS ? '&' : '?') + 'sess=' + logonKey
    
    return url;
}

function convertAllLinksForEMR() {
    try {
        var links = document.getElementsByTagName('a');
        var root = document.location.href.substring(0,
            document.location.href.length - (document.location.pathname.length + document.location.search.length)).toLowerCase();

        try {
            var userProperties = top.session.getValue('sessUserProperties', false);
            var logonKey = top.session.getValue('sessLgnK', false);
        }
        catch(e) {};

        for(var i = 0; i < links.length; i++) {
            /* links to be converted must either be local links (i.e. have an href with the same scheme and host as the current page) and 
                either have no emrlink attribute (assumed to be "true") or have a emrlink attribute = "true" or have an emrlink attribute = true.  
                In all cases the href attribute must have a non zero length value. */
            if(links[i].href && links[i].href.indexOf(window.location.href) < 0 && ((links[i].href.substring(0, root.length).toLowerCase() == root && (links[i].emrlink == null || links[i].emrlink.toLowerCase() == "true")) || (links[i].emrlink != null && links[i].emrlink.toLowerCase() == "true")))
                links[i].href = convertToEMRLink(links[i].href, userProperties, logonKey);
        }
    }
    catch(ex) {
        /*25955*/ Log(ex, logVerbosity.Serious);
    }
}



/* Rollover Bindings - split from emr_img_rollover.htc case 68325 DH 18/08/08 */

// Swap in the rollover version of the image (indicated by _f2) 
function emr_img_rollover_onmouseover(oElement)	
{

	try
	{
		// If the filename does not have '_f2", add "_f2" onto the end for the rollover version
		if (oElement && oElement.src )
		{
			var sSrc = oElement.src;	
			if ( sSrc.indexOf('_f2') <= 0 )
			{
				sSrc = sSrc.slice(0, sSrc.length - 4) + '_f2.gif';
			}

			oElement.src=sSrc;
		}
	}
	catch (e)
	{
		// Ignore - should never happen
	}
	finally
	{
	}
	return true;
}

// Swap back the standard version of the image, assuming the follover version is currently there.
function emr_img_rollover_onmouseout(oElement)
{
	try
	{
		// If the filename has '_f2", work out the filename without "_f2" on the end
		if (oElement && oElement.src )
		{
			var sSrc = oElement.src;
			if ( sSrc.indexOf('_f2') > 0 )
			{
				sSrc = sSrc.slice(0, sSrc.length - 7) + '.gif';
			}

			oElement.src=sSrc;
		}
	}
	catch (e)
	{
		// Ignore - should never happen
	}
	finally
	{
	}
	return true;
}




/* Parse a helplink click. Split from emr_helplink.htc Case 68672 DH 18/08/08 */

function emr_helplink_onclick(oElement)
{
	try
	{
		var sHref = oElement.href;
		
		if ( sHref )
		{
		
			// Remove the abs URL that IE ads to the ID in the href
			// Note that we can't check the full URL as this has dots in e.g. www.emailreaction.com
			var iLastSlash = sHref.lastIndexOf('/');
			var sID = sHref.slice(iLastSlash + 1);
			if ( sID.indexOf('.') > 0 )
			{
				// a web page
				var args=new Array();
				var arr = window.open(sHref, '_blank', 'width=650,height=500,resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes');
			}
			else
			{
				// An EMR Help text id
				if ( parent )
				{
					// MJA 05apr05. Help in dialogs works slightly differently. In a dialog, there's no parent to 
					// refer to, so we pass in a pointer to oElement page. 
					// In a framed admin page, the dialog window is in a separate frame, so we need to call our parent, 
					// which will pull the help text from the main admin page, not from us.
					
					try
					{
						if ( EMR_IsDialog() )
						{
							EMR_SetPageHelpTextFromID(top,sID);
						}
						else
						{
							EMR_TopFrame().EMR_SetPageHelpTextFromID(sID);
						}
					}
					catch(e)
					{
						// no handler - must be an admin page. 
						EMR_TopFrame().EMR_SetPageHelpTextFromID(sID);
					}
				}
				else
				{
					alert('no parent');
				}
			}
		}
	}
	catch (e)
	{
		// Ignore - should never happen
	}
	finally
	{
	}

	return false;
}

/* Case 16361 - Start
 * DP - 12-May-09
 * Custom row filters for targer, seed & exclusion lists
 *   Types - bit mask value:
 *     1 = Target
 *     2 = Seed
 *     4 = Exclusion
 *     16 = MailingList
 *     32 = DynamicList */
// DP 26Apr2010 Case 159981 - New filter methods to include all target types that can be used for mailings
function AllMailableLists_ItemFilter(sender, row) {
    return (TargetList_ItemFilter(sender, row) || MailingList_ItemFilter(sender, row) || DynamicList_ItemFilter(sender, row));
}

function AllMailableLists_FolderFilter(sender, folder) {
    return (TargetList_FolderFilter(sender, folder) || MailingList_FolderFilter(sender, folder) || DynamicList_FolderFilter(sender, folder));
}

function TargetList_ItemFilter(sender, row) {
    return isListType(row, 1);
}

function TargetList_FolderFilter(sender, folder) {
    return containsListType(folder, 1);
}

// DP 26Apr2010 Case 159981 - New filter methods for new list types
function MailingList_ItemFilter(sender, row) {
    return isListType(row, 16);
}

function MailingList_FolderFilter(sender, folder) {
    return containsListType(folder, 16);
}

function DynamicList_ItemFilter(sender, row) {
    return isListType(row, 32);
}

function DynamicList_FolderFilter(sender, folder) {
    return containsListType(folder, 32);
}

function SeedList_ItemFilter(sender, row) {
    return isListType(row, 2);
}

function SeedList_FolderFilter(sender, folder) {
    return containsListType(folder, 2);
}

function ExclusionList_ItemFilter(sender, row) {
    return isListType(row, 4);
}

function ExclusionList_FolderFilter(sender, folder) {
    return containsListType(folder, 4);
}

function isListType(row, checkType) {
    // Check if the intType bit mask includes the type specified.
    var type = row.getFieldValue('intType');
    if(type)
        return ((type & checkType) == checkType);
    
    return false;
}

// recursive method to check if this folder or any of it's children contain a list of the specified type
function containsListType(folder, checkType) {
    // check the cached value
    if(folder.containsListType && (folder.containsListType['Type_' + checkType] != null))
        return folder.containsListType['Type_' + checkType];

    var matchFound = false;
    // check this folder first, if that has one we don't need to check any further
    var index;
    for(index in folder.items) {
        if(isListType(folder.items[index], checkType)) {
            matchFound = true;
            break;
        }
    }
    
    if(!matchFound) { // don't bother checking further if we already have a match
        // check the sub folders next
        for(index in folder.folders) {
            if(containsListType(folder.folders[index], checkType)) {
                matchFound = true;
                break;
            }
        }
    }
    
    // cache the result for next time
    if(!folder.containsListType)
        folder.containsListType = new Object();
    folder.containsListType['Type_' + checkType] = matchFound;
        
    return matchFound;
}

function ListTree_OnGetIconPath(row)
{
    var iconName = 'list'

    if(row) {
        // add -sync for syncronised lists
        if (row.getFieldValue('intTargetType') != 0)
            iconName += "-sync";
            
        // add -excl for exclusions lists and -seed for seed lists
        if (isListType(row, 2))
            iconName += '-seed';
        else if (isListType(row, 4))
            iconName += '-excl';
        else if (isListType(row, 8))
            iconName += '-locked';
        else if (isListType(row, 48))
            iconName += '-dynamic';
        else if (isListType(row, 16))
            iconName += '-flash';
            
        // DP 06Jan2010 Case 141226 - if the list has been deleted but is being shown because of filter options, use the deleted list icon - this overrides any other icons selected based on the time / sync options
        if (row.getFieldValue('intStatus') < 100)
            iconName += '-deleted';
    }

    iconName += '.gif'

    return iconName;
}

//  MJA 24Jun10 case 167410 - get the appropriate icon for an emailing - used from e.g. C:\Dev\EMR Web Files\EMR Web 4\ERInclude\popups\QueryBuilderInputSelection.aspx
function ClickMailingTree_OnGetIconPath(row) {
	var iconName = 'email-1.gif';
	return iconName;
}




function AssetTree_OnGetIconPath(row){
       return "email-1.gif";
}
/*  Case 16361 - End */


//==============================================================================================================================
//==================== JAVASCRIPT USED BY emr_isPopupBlocked_js.asp ============================================================================
//==============================================================================================================================


function emr_IsPopupBlocker() {
    var bBlocked = false;
    var strNewURL = "Dummy.htm"
    var Strfeature = "height=10,width=10,status=yes,scrollbars=no,status=no,titlebar=no,toolbar=no; ";
    var WindowOpen = window.open(strNewURL, "MainWindow", Strfeature);
    try {
        var obj = WindowOpen.name;
        WindowOpen.close();
        // If get to here without any exception being thrown, popup blocker is not active.
    }
    catch (e) {
        // POP-UP Blocker is active. 
        bBlocked = true
    }
    return bBlocked;
}

