var prnwindow;
var strHead = "";
function popWin(page,w,h) {
prnwindow=window.open(page,'prnwindow','width=' + w + ',height=' + h + ',left=300,top=150,location=no,resizable=yes,menubar=no,status=no,toolbar=yes,scrollbars=yes');
prnwindow.opener=self;
prnwindow.focus();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function doWelcome () {
// displays welcome message for IFF login cookie
var ckTID = "MJ";
if (!(thisTopicId==undefined)) ckTID = thisTopicId.substring(0,5);

var fn = readCookie("fn");
var uname = readCookie("uname");
var txt = "&nbsp;";
var mytry=0;
if  (!(thisTopicId==undefined) )
//if  (!(thisTopicId=='MJ.KL') )

//if ('x'=='y') // dont redirect anymore
    if ( (ckTID == 'MJ.KL') && (fn == null) ) {
        var url = window.location.href;
        //alert(readCookie("fn"));
        //alert(url.indexOf('login.phtml'));
        //alert(window.location);
        if (url.indexOf('login.phtml')==-1 && mytry==0) {
         //alert("You must be logged in to view this section of the site.");
         ++mytry;
          window.location ="/key_leader/login.phtml?url=" + url;
        }
        return;
    }


if (fn != null) {
    fn = fn.replace("+"," ");
    txt = 'Hi, ' + fn + ' - ';
    txt +='<a class="header" href="javascript:logout();">Logout</a>';
}
else {
    //txt +='<a class="header" href="/key_leader/login.phtml">Login</a>';
    txt = 'Hi! ';
    txt +='<a class="header" href="javascript:logout();">Logout</a>';
}
txt = "<span class=\"header\">" + txt + "</span>" + "&nbsp;|";
//txt = '&nbsp;'; // remove this live when it goes live
//document.write('<p class="gap">' + txt + '</p>');
document.write(txt);
//alert(txt);
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function logout () {
    eraseCookie('uname');
    eraseCookie('fn');
    eraseCookie('tenor');
    eraseCookie('__utma');
    eraseCookie('__utmb');
    eraseCookie('utmcsr');
    window.location ="/";
    return;

}


function writeHeadLinks() {
    strHead += '<a class="header" href="/">&nbsp;Home</a>&nbsp;|&nbsp;';
    strHead += '<a class="header" href="/about.shtml">About Us</a>&nbsp;|&nbsp;';
    strHead += '<a class="header" href="/Contact_Us.phtml">Contact Us</a>&nbsp;|&nbsp;';
    strHead += '<a class="header" href="/sample_link.shtml">Site Map</a>&nbsp;&nbsp;';
    document.write(strHead);
}
