//
// RootsWeb header/footer script version 0.5
// also add an image tag to drop a session cookie named rws
// if it is missing
//
// written 09-16-2005 by rkw
//

var proto=(window.location.protocol == "https:") ? "https:" : "http:";
if (proto=="http:") {
  document.write('<link rel="stylesheet" title="Default Style" href="'+proto+'//img.rootsweb.com/css/rkw.css" type="text/css">');
} else {
  document.write('<link rel="stylesheet" title="Default Style" href="'+proto+'//img.rootsweb.com/css/rkw_s.css" type="text/css">');
}
document.write('<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="'+proto+'//img.rootsweb.com/favicon.ico">\n');

function getSubCookie(dc,name) {
	var prefix=name+"=";
	var begin=dc.indexOf("&"+prefix);
	if (begin==-1) {
		begin=dc.indexOf(prefix);
		if (begin!=0) return "";
	} else {
		begin+=1;
	}
	var end=dc.indexOf("&",begin);
	if (end==-1) end=dc.length;
	return unescape(dc.substring(begin+prefix.length,end));
}

function getCookie(name) {
	var dc=document.cookie;
	var prefix=name+"=";
	var begin=dc.indexOf("; "+prefix);
	if (begin==-1) {
		begin=dc.indexOf(prefix);
		if (begin!=0) return "";
	} else {
		begin+=2;
	}
	var end=dc.indexOf(";",begin);
	if (end==-1) end=dc.length;
	return unescape(dc.substring(begin+prefix.length,end));
}

function addHeaderTab(text,url,sel,border) {
	document.write('<a href="'+url+'"');
	if (border=="left")
		document.write(' style="border-left: 0"');
	else if (border=="right")
		document.write(' style="border-right: 0"');
	if (text==sel) document.write(' class="active"');
	document.write('title="'+text+'" onmouseover="window.status=\''+text+'\'; return true" onmouseout="window.status=\'\'; return true">'+text+'</a>');
}

function addArea(parent,coords,url,title) {
	var area=document.createElement('area');
	area.shape='rect';
	area.coords=coords;
	area.href=url;
	area.alt=title;
	area.title=title;
	parent.appendChild(area);
}

function writeLink(text,url,sel,border) {
	document.write('<a href="'+url+'"');
	document.write('>'+text+'</a>');
	if (border!='right') document.write(' | ');
}

function writeHeader(dWidth,selTab)
{ //for backwards compatability
	writeHeaderTabsLogin(dWidth,selTab,true,true, "");
}

function urlEncode(url)
{
	url = url.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < url.length; n++) {

	    var c = url.charCodeAt(n);

	    if (c < 128) {
		utftext += String.fromCharCode(c);
	    }
	    else if((c > 127) && (c < 2048)) {
		utftext += String.fromCharCode((c >> 6) | 192);
		utftext += String.fromCharCode((c & 63) | 128);
	    }
	    else {
		utftext += String.fromCharCode((c >> 12) | 224);
		utftext += String.fromCharCode(((c >> 6) & 63) | 128);
		utftext += String.fromCharCode((c & 63) | 128);
	    }

	}
	return escape(utftext)
}
    
function writeHeaderTabsLogin(dWidth,selTab,showTabs,showLogin,cacheDomain) {

        if (cacheDomain == "")
      	{
      		cacheDomain = "http://c.ancestry.com/";
        }
        var isLoggedIn=(((location.href.indexOf("rootsweb.ancestry.") > 0)?getCookie("RATT"):getCookie("ATT")).length>1);
	document.write('<center>');
        document.write('<table width="760" border=0 cellpadding=0 cellspacing=0><tr><td width=440 align=left>');
	document.write('<a href="http://www.rootsweb.ancestry.com/"><img src="'+proto+'//img.rootsweb.com/hdr/rw.gif" border=0 height=69 width=314></a></td><td align=right>');
        document.write('<table width="100%" cellspacing=0 cellpadding=0><tr><td colspan=2 align=right>');
        document.write('<div id="rw_sn">');
        if (showLogin)
        {
                if (isLoggedIn) {
                        var vs=(location.href.indexOf("rootsweb.ancestry.") > 0)?getCookie("RVARSESSION"):getCookie("VARSESSION");
                        var user=getSubCookie(vs,'LOGINNAME');
                        if (location.href.indexOf("rootswebstage") > 0)
                        { //it's stage, go to myaccount on stage
                                document.write('Welcome <strong>'+user+'</strong>&nbsp;&nbsp;<a href="https://myaccount.rootswebstage.com/signout">Sign out</a>&nbsp;&nbsp;');
                                document.write('<a href="https://myaccount.rootswebstage.com/">My Account</a>');
                        }
                        else
                        { //it's not stage, go to live
                                document.write('Welcome <strong>'+user+'</strong>&nbsp;&nbsp;<a href="https://myaccount.rootsweb.com/signout">Sign out</a>&nbsp;&nbsp;');
                                document.write('<a href="https://myaccount.rootsweb.com/">My Account</a>');
                        }
                } else {
                        if (location.href.indexOf("rootswebstage") > 0)
                        { //it's stage, go to myaccount on stage
                                document.write('Welcome to RootsWeb.com <a href="https://myaccount.rootswebstage.com/signin">Sign in</a>');
                        }
                        else
                        { //it's not stage, go to live
                                document.write('Welcome to RootsWeb.com <a href="https://myaccount.rootsweb.com/signin">Sign in</a>');
                        }
                }
        }

	document.write('&nbsp;</div></td></tr><tr><td colspan=2><img src="'+proto+'//img.rootsweb.com/wc/pixel.gif" style="height:4px;width:1px;border-width:0px;" /></td></tr>');
	document.write('</td></tr><tr><td width="195">');
	document.write('<a href="http://www.ancestry.com/s33216/t10989/grid1000/rd.ashx"><img src="'+proto+'//img.rootsweb.com/hdr/anc.gif" border=0 height=42 width=183></a></td><td valign=bottom align=right>');
	document.write('<table border=0 cellpadding=0 cellspacing=0><tr><td align=right width="125"><div id="rw_dm">');
	document.write('<a href="http://www.ancestry.com/s33216/t11016/grid1001/rd.ashx">DISCOVER MORE ></a></div></td></tr>');
	document.write('<tr><td><img src="'+proto+'//img.rootsweb.com/wc/pixel.gif" style="height:8px;width:1px;border-width:0px;" /></td></tr></table>');
        document.write('</td></tr></table></td></tr><tr><td colspan=2>');
	document.write('<img src="'+proto+'//img.rootsweb.com/wc/pixel.gif" style="height:4px;width:1px;border-width:0px;" /></td></tr><tr><td colspan=2>');
	if (showTabs)
	{
		// Modern or not ?
		var isMacIE=((navigator.userAgent.indexOf("IE")>-1) && (navigator.userAgent.indexOf("Mac")>-1));
		if (!isMacIE && document.createElement && document.appendChild) {
			document.write('<div id="nav">');
			addHeaderTab('Home','http://www.rootsweb.ancestry.com/',selTab,'left');
			addHeaderTab('Searches','http://searches.rootsweb.ancestry.com/',selTab,'');
			addHeaderTab('Family Trees','http://wc.rootsweb.ancestry.com/',selTab,'');
			addHeaderTab('Mailing Lists','http://lists.rootsweb.ancestry.com/',selTab,'');
			if (location.href.indexOf("rootswebstage") > 0)
			{
				addHeaderTab('Message Boards','http://boards.rootswebstage.com/',selTab,'');
			}
			else
			{
				addHeaderTab('Message Boards','http://www.ancestry.com/s33216/t11581/grid1016/rd.ashx',selTab,'');
			}			
			addHeaderTab('Web Sites','http://www.rootsweb.ancestry.com/~websites/',selTab,'');
			addHeaderTab('Passwords','http://passwordcentral.rootsweb.ancestry.com/',selTab,'');
			addHeaderTab('Help','http://rootsweb.custhelp.com/',selTab,'right');
		} else {
			document.write('<div>');		
			writeLink('Home','http://www.rootsweb.ancestry.com/',selTab,'left');
			writeLink('Searches','http://searches.rootsweb.ancestry.com/',selTab,'');
			writeLink('Family Trees','http://wc.rootsweb.ancestry.com/',selTab,'');
			writeLink('Mailing Lists','http://lists.rootsweb.ancestry.com/',selTab,'');
			if (location.href.indexOf("rootswebstage") > 0)
			{
				writeLink('Message Boards','http://boards.rootswebstage.com/',selTab,'');
			}
			else
			{
				writeLink('Message Boards','http://www.ancestry.com/s33216/t11581/grid1016/rd.ashx',selTab,'');
			}			
			writeLink('Web Sites','http://www.rootsweb.ancestry.com/~websites/',selTab,'');
			writeLink('Passwords','http://passwordcentral.rootsweb.ancestry.com/',selTab,'');
			writeLink('Help','http://rootsweb.custhelp.com/',selTab,'right');
		}
		document.write('</div>');
	}
	document.write('</td></tr></table>');
	document.write('</center>');
	if (showTabs)
	{ //don't put extra space at the bottom unless the tabs are there
		document.write('<div id="content"></div>');
	}
		
	if (showTabs && (selTab == 'Message Boards')) 
	{
		document.write('<link rel="stylesheet" type="text/css" href="'+cacheDomain+'s/3/css/boards.css" />');
		if (isLoggedIn)
		{
			document.write('<div style="color: #49679E; margin: 0px 0px 12px 0px; font-size: 10px; 	color: #666666; float: right; margin-left: 10px;">');
			if (location.href.indexOf("rootswebstage") > 0)
			{ //it's stage, go to myaccount on stage
				//document.write('<a href="http://resources.rootswebstage.com/cgi-bin/boards/favorites?stage=1">My Favorites</a>');
				//document.write('<a href="http://resources.rootswebstage.com/cgi-bin/boards/favorites?stage=1&a=1" style="padding-left: 6px;">My Alerts</a>'); 
				document.write('<a href="http://anc.rootswebstage.com/myancestry/communityfavorites.aspx?backurl='+escape(document.location)+'">My Favorites</a>');
				document.write('<a href="http://anc.rootswebstage.com/myancestry/messageboardalerts.aspx?backurl='+escape(document.location)+'" style="padding-left: 6px;">My Alerts</a>'); 
				document.write('<a href="https://myaccount.rootswebstage.com/publicprofile?op=edit&kurl='+urlEncode(location.href)+'" style="padding-left: 6px;">My Public Profile</a></div>');
			}	
			else
			{ //it's not stage, go to live
				//document.write('<a href="http://resources.rootsweb.ancestry.com/cgi-bin/boards/favorites">My Favorites</a>'); 
				//document.write('<a href="http://resources.rootsweb.ancestry.com/cgi-bin/boards/favorites?a=1" style="padding-left: 6px;">My Alerts</a>'); 
				document.write('<a href="http://anc.rootsweb.com/myancestry/communityfavorites.aspx?backurl='+escape(document.location)+'">My Favorites</a>');
				document.write('<a href="http://anc.rootsweb.com/myancestry/messageboardalerts.aspx?backurl='+escape(document.location)+'" style="padding-left: 6px;">My Alerts</a>'); 
				document.write('<a href="https://myaccount.rootsweb.com/publicprofile?op=edit&kurl='+urlEncode(location.href)+'" style="padding-left: 6px;">My Public Profile</a></div>');
			} 		
		}
	 }
}

function footerAddLink(parent,text,url,addSep) {
	var a=document.createElement('a');
	a.href=url;
	a.appendChild(document.createTextNode(text));
	parent.appendChild(a);
	if (addSep) parent.appendChild(document.createTextNode(' | '));
}

function writeFooter(hrWidth) {
	document.write('<div id="footer_div">');
	var rws=getCookie('rws');
	document.write('<center>');

	var pattern = /http:\/\/wc.rootsweb.ancestry.com\/cgi-bin\/igm.cgi?op=GET/;
	if (document.URL != 'http://www.rootsweb.ancestry.com'
         && pattern.exec(document.URL) == null)
	{
		document.write('<SCR' + 'IPT type="text/javascript">OAS_AD(\'Bottom\');</SCR' + 'IPT>');
	}

	if (null==hrWidth || hrWidth.length==0) hrWidth='90%';
	if (hrWidth!='0')
		document.write('<hr width="'+hrWidth+'" size="1" noshade align="center">');
	document.write('<p><font face="Verdana, Arial, Helvetica, sans-serif" size="-2">RootsWeb is funded ');
	document.write('and supported by <a href="http://www.ancestry.com/s33216/t10989/grid1005/rd.ashx">Ancestry.com</a> ');
	document.write('and our loyal RootsWeb community. <a href="http://www.rootsweb.ancestry.com/rootsweb/support.html">Learn ');
	document.write('more.</a><br><br>');
	document.write('<a href="http://corporate.ancestry.com/">About Us</a> | ');
	document.write('<a href="http://rootsweb.custhelp.com/cgi-bin/rootsweb.cfg/php/enduser/ask.php">Contact Us</a> | ');
	document.write('<a href="http://www.rootsweb.ancestry.com/rootsweb/aup.html">Acceptable Use Policy</a> | ');
	document.write('<a href="http://www.rootsweb.ancestry.com/rootsweb/privacy.html">PRIVACY STATEMENT</a> | ');
	document.write('<a href="http://corporate.ancestry.com/about-ancestry/legal/"> Copyright</a><br>');
	document.write('&copy; 2010 Ancestry.com</font></p></center>');
	if (null==rws || rws.length==0)
		document.write('<img src="'+proto+'//images.rootsweb.com/cgi-bin/session" height=1 width=1>');
	document.write('</div>');
}




