/* ---- Beta Label and Link Insertion ---- */

function beta() {
//var beta = true; // set to "false" to disable Beta elements in header & footer
var beta = false; // set to "false" to disable Beta elements in header & footer

if (beta) {
	var is_QA = true; // set to "false" when site is moved to production

        //var betaUrl = (is_QA) ? "http://beta-dev.bbt1.cistest.att.net:9090/home.action?program=webmail" : "http://beta.comcast.net/home.action?program=webmail";
        var betaUrl = "http://beta.comcast.net/home.action?program=webmail";

        // Footer link
        var f = document.getElementById("footer");
        if (f == null) return false;

        var width;
        if (window.innerWidth) {
            width = window.innerWidth;
        } else if (document.documentElement && document.documentElement.clientWidth) {
            width = document.documentElement.clientWidth;
        } else {
            width = document.body.clientWidth;
        }

        if (width > 570) {
          var fu = f.getElementsByTagName("ul")[1];
		  if (fu == null) {
          	fu = f.getElementsByTagName("ul")[0];
		  }

          // create footer link
          var fl = document.createElement("li");
          fl.setAttribute("id","help-beta");
          fu.appendChild(fl);

        if (is_ie && is_mac) {
            fl.innerHTML="<a href='" + betaUrl + "' title='Learn about this Comcast Beta product' target='_blank'>News about this Beta</a>";
          } else {
            var fa = document.createElement("a");
            fa.setAttribute("href",betaUrl);
            fa.setAttribute("title","Learn about this Comcast Beta product");
            fa.setAttribute("target","_blank");

            var ft = document.createTextNode("News about this Beta ");

            // append link into footer link list
            fa.appendChild(ft);
            fl.appendChild(fa);
	  }
	}
	 
	// find H1 tag in header
	var h = document.getElementById("header");
	if (h == null) return false;
	var h1 = h.getElementsByTagName("h1")[0];
	if (h1 == null) return false;
	
  if (is_ie && is_mac && !is_ie5) {
    h1.innerHTML += "<a href='" + betaUrl + "' title='Learn about this Comcast Beta product' id='beta' target='_blank'> Beta</a>";

    var l = document.createElement("span");
    l.innerHTML = "<a href='http://www.comcastsupport.com/betachat/' title='Chat with a customer service representative about this Beta product' id='livechat' target='_blank'>Live Chat Support</a>";
  } else {
	// create Beta graphic label
	var b = document.createElement("a");
	b.setAttribute("href",betaUrl);
	b.setAttribute("title","Learn about this Comcast Beta product");
	b.setAttribute("id","beta");
	b.setAttribute("target","_blank");
	var bt = document.createTextNode(" Beta");
	b.appendChild(bt);

        // insert Beta link into header H1
        h1.appendChild(b);
	
	// create live chat support link
	var l = document.createElement("a");
	l.setAttribute("href","http://www.comcastsupport.com/betachat/");
	l.setAttribute("title","Chat with a customer service representative about this Beta product");
	l.setAttribute("id","livechat");
	l.setAttribute("target","_blank");
	var lt = document.createTextNode("Live Chat Support");
	l.appendChild(lt);
  }	
	
  // insert Live Chat link after header H1
  var sk = document.getElementById("skipnav");
  if (sk == null) return false;
  h.insertBefore(l, sk);
}
}

function removeBeta() {
        var a1 = document.getElementById("beta");
        var a2 = document.getElementById("livechat");
        if (a1 == null || a2 == null) return false;

        a1.parentNode.removeChild(a1);
        a2.parentNode.removeChild(a2);
}



/* ---- User Agent Detection ---- */

var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_safari = (navigator.appVersion.indexOf("Safari") > -1);
var is_firefox = (agt.indexOf("firefox") != -1);
var safari_agtnum = navigator.userAgent.lastIndexOf("/") + 1;
var safari_version = parseInt(navigator.userAgent.substring(safari_agtnum));
var is_safari12up = (safari_version >= 125);
var is_win = ((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1));
var is_mac = (agt.indexOf("mac")!=-1);
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie5up =(is_ie && !is_ie3 && !is_ie4);
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

/* ---- Upgrade Message for old User Agents ---- */

function upgrade() {
	var old_ua = false;
	
	var ua, os, ua1, ua2;
	if ((is_mac && is_ie) || (is_safari && !is_safari12up) || (is_win && !is_ie5_5up)) { old_ua = true; }
	
	if (is_ie) { ua = "Internet Explorer"; }
	else if (is_safari) { ua = "Apple Safari"; }
	else if (is_firefox) { ua = "Mozilla Firefox"; }
	
	if (is_win) { os = "Windows"; }
	else if (is_mac) { os = "Mac OSX"; }
	
	if (is_win) { ua1 = '<a href="http://www.microsoft.com/windows/ie/downloads/default.mspx" target="_blank">Internet Explorer 7.0<\/a>'; }
	else if (is_mac) { ua1 = '<a href="http://www.apple.com/safari" target="_blank">Apple Safari<\/a>'; }
	
	ua2 = '<a href="http://www.mozilla.com/firefox/" target="_blank">Mozilla Firefox<\/a>';
	var close = '<a href="#" title="Hide this message. You will be reminded in 30 days." id="close" onclick="storeUpgradePref(); return false;">close<\/a>';
	var new_ua = 'a newer web browser like ' + ua1 + ' or ' + ua2;
	var latest = 'the latest version';
	var msg = '<p>You are currently using an older version of <b>' + ua + '<\/b> for <b>' + os + '<\/b>. To get the most out of Comcast Webmail, we recommend that you upgrade to ' + new_ua + '.<\/p>';
	
	
	var ui = getCookie("upgrademsg");
	var show_msg = (ui == null || ui == "") ? true : false;
	
	if (old_ua && show_msg && !opener) {
		document.write('<div id="upgrade"><div>' + close + msg + '<\/div><\/div>');
	}
}

function storeUpgradePref() {
	var u = document.getElementById("upgrade");
	if (u == null || !document.getElementById) return false;
	if (u.removeChild) {
		u.parentNode.removeChild(u);
	}
	else {
		u.style.display = "none";
	}
	//setInCookie("commcenterUI", "upgrademsg", "0");
	setCookie("upgrademsg", "0", "30", "/");
}




/* ---- Global Variables ---- */

var num_attachments = "0";
var currentTemplate = "msglist";



/* ---- DOM Page Load Utility Functions ---- */

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function addClass(element, value) {
	if (!element.className) {
		element.className = value;
	}
	else {
  	var allClasses = element.className.split(' ');
  	for (var i=0; i<allClasses.length; i++) {
  	  if (allClasses[i] == value) {
  	    return; /* If the class is already there, we're done */
	    }
    }
		element.className += " " + value;
	}
}

function removeClass(element, value) {
	if (!element.className) return false;
	var oldClasses = element.className.split(' ');
	var newClasses = [];
	for (var i=0; i<oldClasses.length; i++) {
	  if (oldClasses[i] != value) {
	    newClasses[i] = oldClasses[i];
    }
	}
	element.className = newClasses.join(' ');
	return true;
}

function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

// Adds suppport for the push method for IE 5 */
Array.prototype.push = ArrayPush;
function ArrayPush(value){
    this[this.length] = value;
}

// Pass in a container object
// Counts the number of checked checkboxes in the container
// Returns -1 if passed in parameter is null
function countChecks(container) {
	if (container == null) return -1;
    var totalChecks = 0;
    
    var inputs = container.getElementsByTagName('input');
    for (var i=0; i<inputs.length; i++) {
        if ((inputs[i].type == 'checkbox') && (inputs[i].checked == true)) {
            totalChecks++;
        }
    }
    return totalChecks;
}

// Will check/uncheck all checkboxes in a container
// Pass in type ("check" to check, anthing else to uncheck and string name of container
function checkClear(type, container) {
	var msgtable = document.getElementById(container);
	if (msgtable == null) return false;
	var checks = msgtable.getElementsByTagName("input");
	for(var i=0; i<checks.length; i++) {
		if (checks[i].type == "checkbox") {
            checks[i].checked = (type == "check");
		}
	}
}

// Transfers an 'option' from one 'select' box to another
// Pass in the two 'select' elements and the correct 'option' element
function transferOption(fromSelect, toSelect, transOption) {
    if (fromSelect == null || toSelect == null || transOption == null) return false;
    
    // Move via DOM
    //var newOption = transOption.cloneNode(true);
    //fromSelect.removeChild(transOption);
    //toSelect.appendChild(newOption);
    
    // The even more "hacky" approach... works in MAC IE:
    var newOption = new Option(transOption.innerHTML, transOption.value);
    for (var i=0; i<fromSelect.length; i++) {
        if (fromSelect.options[i] == transOption) {
            fromSelect.options[i] = null;
            break;
        }
    }
    toSelect.options[toSelect.length] = newOption;

    return;
}



/* ---- Popup Window Functions ---- */

// Opens a pop-up window
var newwindow;
function pop(url, width, height, name) {
    if ((url == '') || (url == null)) {
        return true; // follow the default link instead
    } else {
	// Trim the window name to the html file name (i.e. 'compose.html' becomes 'compose'
	if (name == null) {
		var windowName = url.split('/');
		windowName = windowName[windowName.length-1];
		windowName = windowName.split('=');
		windowName = windowName[windowName.length-1];
		windowName = windowName.substring(0,windowName.indexOf('.'));
	}
	else if (name == "_blank")	{
  		var today = new Date();
  		windowName = today.getMilliseconds();
	}
	else	{
		windowName = name;
	}

        // open the new window
        newwindow = window.open(url, windowName, 'height='+height+',width='+width+',resizable=1,menubar=1,scrollbars=1');
        if (window.focus) {newwindow.focus()}
        return false;
    }
}

// WM87 popup function
function doPopup(obj, cmd, height, width) {
	if (!height) {
		var height = 614;
		var width = 780;
	}
    w2 = popwindow("/wmv/blank.html", height, width);
    if (cmd != 'spam' && document.execCommand && is_ie5_5up && !is_mac && useHTML != "n")	{
		obj.templ.value = cmd+"2.html";
    }
    if (!is_safari || (is_safari && is_safari12up)) {
		obj.target = w2.name;
	}
    else {
  		obj.target = w2.myname;
  	}
	obj.popup.value = "yes";
    return true;
}

function popwindow(cmd, width, height) {
  var today = new Date();
  var millis = today.getMilliseconds();

  if (!is_safari || (is_safari && is_safari12up)) {
     url = "/wmv/blank.html";
  } else {
	url = "";
  }
  var winHeight;
  if (screen.height <= height) { winHeight = eval(parseInt(screen.height * 0.88)); }
  else { winHeight = height; }
  var winLeft = eval((screen.width - width)/2);
  var winTop = eval((screen.height - winHeight)/4);
  var w2 = window.open(url, millis, 'width='+width+',height=' + winHeight + ',top=' + winTop+ ',left=' + winLeft + ',scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,status=no,location=no,address=no');
  w2.opener = self;
  w2.focus();
  w2.myname = millis;
  return w2;
}

function noPopup(obj)	{
	obj.target = "_self";
	obj.popup.value = "no";
	obj.templ.value = "";
}



/* ---- Form Submission Functions ---- */

function imageSubmit(formobj, fieldname) {
  if ((is_ie5up && is_mac) || (is_safari && !is_safari12up)) {
    // max 10 HTML forms per page
    for(i = 1; i < 10; i++) {
        var hdnVar = document.getElementById("HIDDEN_VAR" + i);
        if (hdnVar == null) {
            break;
        }
        hdnVar.name = fieldname;
    }
    // use document.getElementById to set hidden field's name = fieldname
  } else {
    var newField = document.createElement("input");
    newField.setAttribute("type","hidden");
    newField.setAttribute("name", fieldname);
    formobj.appendChild(newField);
  }
  formobj.submit();
}



/* ---- Nav, Submenus ---- */

var c_domain;
// searches for nested UL tags in navmenu and assigns appropriate event handlers for opening/closing submenus
function toggleMenu() {
	var nav = document.getElementById("nav");
	if (nav == null) return false;
	var body = document.getElementsByTagName("body")[0];
	var navListItems, toggleButton, c_name;
	var beta = false;

        if (document.domain.indexOf("beta") != -1) {
                c_domain = document.domain.substr(5);
              	//deleteCookie("commcenterUI", null, document.domain);
		setInCookie("commcenterUI", c_name, "0", "" );
         }


  navListItems = nav.getElementsByTagName('li');
  for (var i=0; i<navListItems.length; i++) {
	if (navListItems[i].getElementsByTagName('ul').length) {
		toggleButton = navListItems[i].getElementsByTagName('a').item(0);
		var toggleID = toggleButton.parentNode.getAttribute("id");

		if (toggleID == "n-folders") {
                        c_name = "folderMenuOpenStatus";
                } else if ( toggleID == "n-myboxes") {
                        c_name = "mboxMgrMenuOpenStatus";
                }

	
		// retrieve "commcenterUI" cookie and add "open" status to current nav button
		var ui = getCookie("commcenterUI");

		if (ui != null) {
			var s1 = getCookie2(c_name, ui);
			if (s1 == "1") {
				addClass(toggleButton, "open");
				toggleButton.parentNode.getElementsByTagName('ul').item(0).style.display = "block";
			}
			
		}

    // make sure My Folders displays as open on the edit page
    if (toggleID == "n-folders" && document.body.className.indexOf("myfolders") != -1) {
      addClass(toggleButton, "open");
      toggleButton.parentNode.getElementsByTagName('ul').item(0).style.display = "block";
    }
    if (toggleID == "n-myboxes" && document.body.className.indexOf("mailbox") != -1) {
      addClass(toggleButton, "open");
    }
 
  	  toggleButton.onclick = function() {
  	    var toggleThis = this.parentNode.getElementsByTagName('ul').item(0);
  	    var toggleID = this.parentNode.getAttribute("id");
  	   
		if (toggleID == "n-folders") {
                        c_name = "folderMenuOpenStatus";
            	} else if ( toggleID == "n-myboxes") {
                        c_name = "mboxMgrMenuOpenStatus";
            	}

    		toggleThis.style.display = toggleThis.style.display == "block" ? "none" : "block";
    		
    		if (this.className.indexOf("open") != -1) {
    			removeClass(this, "open");
    			//setInCookie("commcenterUI", toggleID, "0");
    			setInCookie("commcenterUI", c_name, "0", "1826", null, c_domain);
    		}
    		else {
    			addClass(this, "open");
    			//setInCookie("commcenterUI", toggleID, "1");
    			setInCookie("commcenterUI", c_name, "1", "1826", null, c_domain);
    		}
            
            // reposition corners, this fixes IE but not safari
            var nav = document.getElementById("nav");
            if (nav != null) {
                var corners = nav.getElementsByTagName('b');
                for (var j=0; j<corners.length; j++) {
                    if (corners[j].className.indexOf('ll') != -1 || corners[j].className.indexOf('lr') != -1 ) {
                        corners[j].style.bottom = '0px';
                    }
                }
            }
    		return false;
    	}
	}
	}
}

// assigns "empty this folder" function to all links with a class of "empty" in navmenu
function emptyLink(obj) {
	var nav = document.getElementById("nav");
	if (nav == null) return false;
	
	var a = nav.getElementsByTagName("a");
	for (i=0; i<a.length; i++) {
		if (a[i].className == "empty") {
			a[i].onclick = function() {
				var aa = this.parentNode.getElementsByTagName("a")[0];
				var myfolder = aa.firstChild.nodeValue;
				if (confirm("Delete all messages in "+myfolder+"?"))	{
					this.href += "&confirmed=1";
					return true; 
				}
				else {
					return false;
				}
			}
		}
	}
}



/* ---- Visual Style Functions ---- */

// Adds background color to odd rows in message list tables
function stripeTables(elem) {
	if (!document.getElementsByTagName) return false;
	var tables = document.getElementsByTagName("table");
	for (var i=0; i<tables.length; i++) {
		if (tables[i].className == elem) continue;
		var odd = false;
		var rows = tables[i].getElementsByTagName("tr");
		for (var j=0; j<rows.length; j++) {
			if (rows[j].getAttribute("class") == "nomsg") return false;
				if (odd == true) {
					addClass(rows[j], "alt");
					odd = false;	
				}
				else {
					odd = true;
				}
			}
	}
}

// Adds rounded corner graphics to selected corners of reference element
function roundCorners(elem, top, bot) {
    if (elem == null) return;
	if (is_mac && is_ie) return;
    if (top) {
        var ul = document.createElement("b");
        ul.className = "ul";
        var ur = document.createElement("b");
        ur.className = "ur";
        elem.appendChild(ul);
        elem.appendChild(ur);
    }
    if (bot) {
        var ll = document.createElement("b");
        ll.className = "ll"
        var lr = document.createElement("b");
        lr.className = "lr";
        elem.appendChild(ll);
        elem.appendChild(lr);
    }
}

// Adds rounded corners graphics to selected corners of reference tabs
function decorateTabs() {
    var tabLists = getElementsByClassName(document, "ul", "ul-toolbar-tabs");
    var tabs, j; 
    for (var i=0; i<tabLists.length; i++) {
        tabs = tabLists[i].getElementsByTagName('li');
        for (j=0; j<tabs.length; j++) {
            roundCorners(tabs[j], true, true);
        }
    }
}



/* ---- Search Functions ---- */

function initSearch() {
    var webSearchButton = document.getElementById('search-web');
    var webSearchForm = document.getElementById('searchform');
    var webSearchField = document.getElementById('search-field');
    if (webSearchButton != null && webSearchForm != null) {
        webSearchButton.onclick = webSearch;
		//if (webSearchField != null && !is_ie)
		//	webSearchField.onkeypress = noenterifEmpty;
    }
    
    var emailSearchButton = document.getElementById('search-email');
    if (emailSearchButton != null) {
        emailSearchButton.onclick = function() {
                    return emailSearch(this.form);
	}
    }
}

function webSearch() {
    var webSearchForm = document.getElementById('searchform');
    if (webSearchForm == null) return false;
    var searchField = document.getElementById('search-field');
    if (searchField == null) return false;
    var webSearchField = document.getElementById('web-search-query');
    if (webSearchField == null) return false;

	if (currentTemplate == "message_center")	{
    	var webSearchName = document.getElementById('web-search-name');
    	if (webSearchName != null) webSearchName.value = "msgctr";
	}
    
    webSearchField.value = searchField.value;
    webSearchForm.submit();
    return false;
}

function emailSearch(formobj) {
  var tempPage = document.body.className.split(" ");
  if (tempPage[0] && tempPage[0] == "msglist")  {

  if ((is_ie5up && is_mac) || (is_safari && !is_safari12up)) {
    // max 10 HTML forms per page
    for(i = 1; i < 10; i++) {
        var hdnVar = document.getElementById("HIDDEN_VAR" + i);
        if (hdnVar == null) {
            break;
        }
        if (( hdnVar.type == "hidden" ) && (hdnVar.name.search(/^e_/) != -1))
                hdnVar.name = "HIDDEN_VAR" + i + "name";
    }
  } else {
        var x=document.getElementById("Webmail");
        for(i=0; i<x.length; i++) {
                if ((x.elements[i].type == "hidden") && (x.elements[i].name.search(/^e_/) != -1)) {
        //alert(x.elements[i].name);
                        x.elements[i].parentNode.removeChild(x.elements[i]);
                        i = i - 1;
                }
        }
   }

        noPopup(formobj);
        formobj.submit();
        return true;
  }
  else  {

	var content = document.getElementById("n-INBOX");
	if (content == null) return false;
	var links = content.getElementsByTagName("a");
	if (links.length > 0)	{
            var url = links[0].href + "&search=" +
		escape(formobj.search_field.value);
	    window.location = url;
        }
  }
  return false;
}

/* is this function needed? yes.  It addresses a Firefox problem with 
  automatically executing a search when enter is hit.  There has got to be a
  better way to fix the problem, but this works (at least on the message list)
  until we have something better. */
function noenterifEmpty(event) {
     if (!is_ie) {
	 if (event && event.which == 13) 
       {
		 if (document.forms['Webmail'] && document.forms['Webmail'].fake_blank_ns_hdr_search_btn)
         	document.forms['Webmail'].fake_blank_ns_hdr_search_btn.click();
         return false;
       }
       return true;

     }
      return true;
}



/* ---- Utility Bar Save/Cancel Buttons ---- */

// Assigns action to "cancel" buttons in bottom utility bar; used on preferences and edit screens
function cancel() {
	/*var content = document.getElementById("content");
	if (content == null) return false;*/
	
	var inputs = document.getElementsByTagName("input");
	for(var i=0; i<inputs.length; i++) {
		if (inputs[i].className == "cancelbutton") {
                   if (currentTemplate == "add_mb" || currentTemplate == "edit_mb" || currentTemplate == "login_advanced") {
                         inputs[i].onclick = function() {
                         location.href = mb_listURL;
                         }
                   }
                   else if (opener) {
                      inputs[i].onclick = function() {
                      self.close();
                      }
                   } else {
                         inputs[i].onclick = function() {
                         history.go(-1);
                         }
                   }
                } //cancelbutton

                if (inputs[i].className == "backbutton") {
                         inputs[i].onclick = function() {
                         history.go(-1);
                         }
                }
        } // for

}

function confirmEmpty(obj) {
    var myfolder='';
    tmparray = obj.search.split('&');
    for (var i = 0; i <= tmparray.length - 1; i++) {
            left = tmparray[i].substring(0, tmparray[i].indexOf("="));
            if (left == "folder")   {
                    myfolder = tmparray[i].substring(tmparray[i].indexOf("=") + 1, tmparray[i].length);
                    myfolder = unescape(myfolder);
                    break;
            }
    }
    if (confirm("Delete all messages in "+myfolder+"?"))	{
        obj.href += "&confirmed=1";
        return true; 
    }
    else {return false;}
}



/* ---- Footer Functions ---- */

function addCopyright() {
	var copyright = document.getElementById("copyright");
	if (copyright == null) return false;
    
    var now = new Date;
    
    var theSpans = copyright.getElementsByTagName('span');
    for (var i=0; i<theSpans.length; i++) {
        theSpans[i].innerHTML += " "+now.getFullYear();
    }
}

function askComcastLink() {
    var askLink = document.getElementById("help-ask");
    if (askLink == null) return false;
    
    var allAskLinks = askLink.getElementsByTagName('a');
    for (var i=0; i<allAskLinks.length; i++) {
        allAskLinks[i].onclick = function() {
            window.open(this.href,"askcomcast","scrollbars=no,status=no,location=no,toolbar=no,favorites=no,address=no,menubar=no,resizable=yes,width=520,height=482");
            return false;
        }
    }
}

// Makes header and footer links pop in a new window if launched from a popup window
function headerFooterLinks() {
	if (opener != null) {
	
		// webmail logo
		var wh = document.getElementsByTagName("h1")[0];
                if (wh != null) {
      			var wa = wh.getElementsByTagName("a")[0];
      			wa.setAttribute("target","_blank");
    		}

    // Links that should open in a new window, link 'help' and 'comcast.net'
    	var blankIds = Array("opt-help", "opt-comcastnet");
    	for (var i=0; i<blankIds.length; i++) {
      		var container = document.getElementById(blankIds[i]);
      		if (container == null) continue;

      		var anchor = container.getElementsByTagName("a")[0];
      	 	  anchor.setAttribute("target","_blank");
    	}

		// footer links
		var f = document.getElementById("footer");
		if (f != null) {
			var a = f.getElementsByTagName("a");
			for (i=0; i<a.length; i++) {
					a[i].setAttribute("target","_blank");
			}
		}
	}
	
	// signout button
	var sl = document.getElementById("opt-signout");
	if (sl == null) return false;
	var sa = sl.getElementsByTagName("a")[0];
	sa.onclick = function() {
		var h = this.getAttribute("href");
		var nextUrl = "http://mailcenter.comcast.net/";
		//var fixUrl = h + "&url=" + escape(escape(nextUrl));
		var fixUrl = h + "&url=";
		this.setAttribute("href", fixUrl);
		
		/*
		if (opener != null) {
			opener.location.href = fixUrl;
			self.close();
		}
		*/
	}
}



/* ---- Folder / Mailbox screen functions ---- */

/* Turn buttons on/off for two screen:
    folders.html
    mb-list.html */
function initMbListButton() {
	if ((document.body.className.indexOf("preferences-email-del") != -1) || (document.body.className == "myfolders")) {
        // We're on one of the right pages
        var container = document.getElementById("core");
        if (container == null) return false;
        
        var radioBoxes = container.getElementsByTagName('input');
        for (var i=0; i<radioBoxes.length; i++) {
            if (radioBoxes[i].type == 'radio') {
                radioBoxes[i].onclick = function() {
			mbListButton();
			if (this.form && this.form.f_del_name)	{
				this.form.f_del_name.value = this.value;
			}
		}
            }
        }
        
	mbListButton();

        var temp;
        // Assign functions for the buttons
        temp = document.getElementById('folders-rename');
        if (temp !=null) { temp.onclick = callRenameFolder; }
        temp = document.getElementById('folders-add');
        if (temp !=null) { temp.onclick = callAddFolder; }
        temp = document.getElementById('folders-delete');
        if (temp !=null) { temp.onclick = deleteFolder; }
        temp = document.getElementById('mblist-edit');
        if (temp !=null) { temp.onclick = modifyAccess; }
        temp = document.getElementById('mblist-remove');
        if (temp !=null) { temp.onclick = deleteAccess; }
        temp = document.getElementById('mblist-add');
        if (temp !=null) { temp.onclick = callAddMailbox; }
    } else { return false;}
}


/* Turn buttons on/off for two screen:
    folders.html
    mb-list.html */
function mbListButton() {
        // We're on one of the right pages
        var container = document.getElementById("core");
        if (container == null) return false;
        
        var isSelected = false;
        var radioBoxes = container.getElementsByTagName('input');
        for (var i=0; i<radioBoxes.length; i++) {
            if (radioBoxes[i].type == 'radio') {
                if (radioBoxes[i].checked == true) {
                    isSelected = true;
                }
            }
        }
        
        var temp;
        // Turn the buttons on & off
        if (isSelected) {
            temp = document.getElementById('mblist-edit');
            if (temp !=null) { temp.disabled = false; }
            temp = document.getElementById('mblist-remove');
            if (temp !=null) { temp.disabled = false; }
            temp = document.getElementById('folders-rename');
            if (temp !=null) { temp.disabled = false; }
            temp = document.getElementById('folders-delete');
            if (temp !=null) { temp.disabled = false; }
        } else {
            temp = document.getElementById('mblist-edit');
            if (temp !=null) { temp.disabled = 'disabled'; }
            temp = document.getElementById('mblist-remove');
            if (temp !=null) { temp.disabled = 'disabled'; }
            temp = document.getElementById('folders-rename');
            if (temp !=null) { temp.disabled = 'disabled'; }
            temp = document.getElementById('folders-delete');
            if (temp !=null) { temp.disabled = 'disabled'; }
        }


}

function rm_name(str) {
        var email = '';
        pattern1 = /,/;
        pattern2 = /(^.*) (\(.*\))/;
        list = str.split(pattern1);
        if ( list.length == 1 ) {
                email = list[0].replace(pattern2, "$1");
        } else {
          for ( i=0; i<list.length; i++ ) {
                //alert("list" + i + "=" + list[i]);
                if (i < list.length -1 ) {
                  email += list[i].replace(pattern2, "$1,");
                } else {
                  email += list[i].replace(pattern2, "$1");
                }

          }
        }
        return email;
}



/* ------ Cookie Functions ------ */

function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) {
            break;
        }
    }
    return '';
}

function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

function getCookie2(name, cookie) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (cookie.substring(i, j) == arg) {
          var endstr = cookie.indexOf ("&", j);
          if (endstr == -1) {
            endstr = cookie.length;
          }
          return unescape(cookie.substring(j, endstr));
          // return getCookieVal(j);
        }
        i = cookie.indexOf("&", i) + 1;
        if (i == 0) {
            break;
        }
    }
    return '';
}

function setCookieEZ(name, value) {
   //alert("namae=" + name + "\nvalue=" + value );
   document.cookie = name + "=" + escape(value);
}


function setInCookie (bigname, name, value) {
	var argv = setInCookie.arguments;
	var argc = setInCookie.arguments.length;
	var days = (argc > 3) ? argv[3] : 1826;
	var path = (argc > 4) ? argv[4] : null;
	var domain = (argc > 5) ? argv[5] : null;
	var secure = (argc > 6) ? argv[6] : false;
	var bigvalue= getCookie(bigname);

	if (!bigvalue)  {
	//alert("setInCookie, new cookie");
			setCookie(bigname, name+'='+value, days, path, domain, secure);
			return;
	}
	var oldvalue = getCookie2(name, bigvalue);
	if (!oldvalue)  {
	  if (bigvalue && bigvalue != "")       {
			bigvalue += "&";
	  }
	  bigvalue += name + "=" + value;
	}
	else    {
	var reg = new RegExp(name+"="+oldvalue);
	bigvalue = bigvalue.replace(reg, name+"="+value);
	}
	setCookie(bigname, bigvalue, days, path, domain, secure);
}

function setCookie(name, value, days, path, domain, secure) {
    if (isNaN(days)) {
        days = 1;
    }
    var offset = days * 24 * 60 * 60 * 1000;
    var now = new Date();
    var d;
    if (!isNaN(now.valueOf())) {
        var then = now.valueOf() + offset;
        d = new Date(then);
    } else {
        d = now;
    }
    var curCookie = name + "=" + escape(value) + "; expires=" + d.toGMTString() +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    document.cookie = curCookie;
}

function deleteCookie( name, path, domain ) {
        if ( getCookie( name ) ) document.cookie = name + "=" +
                ( ( path ) ? ";path=" + path : "") +
                ( ( domain ) ? ";domain=" + domain : "" ) +
                ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


/* ---- Select Menu (Move To) Functions ---- */

// checks which messages (if any) have been selected and allows them to be moved to other folders
function moveToFolderFromList(form, pagename) {
	var movetop = document.getElementById("movelist-top");
	var movebot = document.getElementById("movelist-bot");
	var msglist = document.getElementById("msgtable");
	var form = document.getElementById("Webmail");
	//if (movetop == null || msglist == null || form == null) return false;
	if (movetop == null || form == null) return false;
	
	var option = movetop.options[movetop.selectedIndex].value;
	if (option == null) return false;
  
	if (pagename == "message_list") {
		if (msglist == null) return false;
		var checkCounter = 0;
		var checks = msglist.getElementsByTagName("input");
		
		for (i=0; i<checks.length; i++) {
			if (checks[i].type == "checkbox" && checks[i].checked == true) {
				checkCounter += 1;
			}
		}
		
		if (checkCounter == 0) {
			alert("Please select a message to move.");
			movetop.selectedIndex = "0";
			movebot.selectedIndex = "0";
		}
		else {
			noPopup(form);
			imageSubmit(form,"e_move_marked");
		}
	}
	
	else if ((pagename == "readmail") || (pagename == "compose")) {
		noPopup(form);
		imageSubmit(form,"e_move_marked");
    	//alert(pagename);
	}
}

// Syncs top and bottom Move To select menus, runs "moveToFolderFromList" function
function msglistSyncMove(pagename) {
	var movetop = document.getElementById("movelist-top");
	var movebot = document.getElementById("movelist-bot");
	var form = document.getElementById("Webmail");
	if (movetop == null || movebot == null) return false;
	
	movetop.onchange = function() {
		movebot.selectedIndex = movetop.selectedIndex;
		moveToFolderFromList(form, pagename);
	}
	movebot.onchange = function() {
		movetop.selectedIndex = movebot.selectedIndex;
		moveToFolderFromList(form, pagename);
	}

}



/* ---- WM87 Functions ---- */

function loadFolderSettings()
{
}

function submitButtonOff()        {
  if ((is_ie5up && is_mac) || (is_safari && !is_safari12up)) {
    // max 10 HTML forms per page
    for(i = 1; i < 10; i++) {
        var hdnVar = document.getElementById("HIDDEN_VAR" + i);
        if (hdnVar == null) {
            break;
        }
        hdnVar.name = "HIDDEN_VAR" + i + "name";
    }
    // use document.getElementById to set hidden field's name = fieldname
  } else {
    var fieldToRemove = document.getElementById("tmp-submit-field");
    if (fieldToRemove != null)
    	fieldToRemove.parentNode.removeChild(fieldToRemove);
  }
}


function submitButton(formobj, fieldname)        {
  if ((is_ie5up && is_mac) || (is_safari && !is_safari12up)) {
    // max 10 HTML forms per page
    for(i = 1; i < 10; i++) {
        var hdnVar = document.getElementById("HIDDEN_VAR" + i);
        if (hdnVar == null) {
            break;
        }
        hdnVar.name = fieldname;
    }
    // use document.getElementById to set hidden field's name = fieldname
  } else {
    var newField = document.createElement("input");
    newField.setAttribute("type","hidden");
    newField.setAttribute("name", fieldname);
    newField.setAttribute("value", "yes");
    newField.setAttribute("id", "tmp-submit-field");
    formobj.appendChild(newField);
  }
  formobj.submit();
}



function setOppositeValue(visible, hiding)      {
	if (visible.checked) { hiding.value = 'n'; }
	else { hiding.value = 'y'; }
}

function SearchEnter (field, event) {
                var keyCode = event.keyCode ? event.keyCode : event.which ? event. which : event.charCode;
                if (keyCode == 13) {
                        field.form.hdrsearch.click();
                        return false;
                }
                else
                return true;
}

function adjustComposeURL(obj) {
        if(obj.href.indexOf('js=yes') == -1)
                obj.href += "&js=yes";
        if (document.execCommand && is_ie5_5up && !is_mac && useHTML != "n") {
                obj.href += "&templ=compose2.html";
        }
        return true;
}



/* ---- Global Onload Events ---- */
if (window.onload != null) window.onload = null;
addLoadEvent(function() {
    if (document.getElementById) {
        initSearch();
        toggleMenu();
	cancel();
        initMbListButton();
        askComcastLink();
        addCopyright();
        headerFooterLinks();
        emptyLink();
	beta();
        
        roundCorners(document.getElementById("toolbar"), true, false);
        roundCorners(document.getElementById("navmenu"), true, true);
        roundCorners(document.getElementById("footer"), false, true);
    }
    
});
