//Contains JS to print the proper login icon, and welcome message
function createWelcome(){
	//creates welcome message and logout link
	var name = getCookie("name");
	var pageDepth = calcPageDepth(location.pathname);
	var urlPrefix = "";
	
	for(var i=0; i<pageDepth;i++){
		urlPrefix += '../';	
	}
	
	if(name != null && name != "" && name != "null"){
		document.write(" <tr><td class=\"text\">&nbsp;</td><td colspan=\"5\" valign=\"top\" class=\"text\" height=\"16\"><div align=\"right\">Welcome, " + name + " | <a href=\"" + urlPrefix + "/secure/logoutRedirect.php\">Logout</a><br /></td></tr>");
	}else{
	}
}
//Contains JS to print the proper login icon, and welcome message
function drawLoginButton(){
	//creates welcome message and logout link if logged in, or a login button if not
	var name = getCookie("name");
	var pageDepth = calcPageDepth(location.pathname);
	var urlPrefix = "";
	
	for(var i=0; i<pageDepth;i++){
		urlPrefix += '../';	
	}
	if(name != null && name != "" && name != "null"){
		document.write("<div align=\"right\"><span class=\"medium_text\">Welcome, " + name + " | <a href=\"" + urlPrefix + "login/logout.php\">Logout</a></span></div>");
	}else{
		document.write("<div align=\"right\"><a href=\"" + urlPrefix + "product/trial.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('ImageSignup','','" + urlPrefix + "images/index/free-trial-over.jpg',1)\"><img src=\"" + urlPrefix + "images/index/free-trial.jpg\" name=\"ImageSignup\" width=\"85\" height=\"37\" border=\"0\" id=\"ImageSignup\" /></a> <img src=\"" + urlPrefix + "images/index/00_index_08.gif\" name=\"ImageBar\" width=\"17\" height=\"37\" border=\"0\" id=\"ImageBar\" />  <a href=\"" + urlPrefix + "login/\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('ImageLogin','','" + urlPrefix + "images/index/00_index_09-over.gif',1)\"><img src=\"" + urlPrefix + "images/index/00_index_09.gif\" name=\"ImageLogin\" width=\"62\" height=\"37\" border=\"0\" id=\"ImageLogin\" /></a></div>");
	}
}

function drawMyAccountButton(){
	//creates a link around the my account button. when user is logged in, link is to their respective control panels. if not, link to login page
    var ad2d = getCookie("uli");
	var pageDepth = calcPageDepth(location.pathname);
	var urlPrefix = "";
	
	for(var i=0; i<pageDepth;i++){
		urlPrefix += '../';	
	}
	
	var homepoint = "";
	if(ad2d == "TRIAL_SCHOOL" || ad2d == "SCHOOL"){
		homepoint = urlPrefix + "teacher-cp/";
	}else if(ad2d == "TRIAL_HOME" || ad2d == "HOME"){
		homepoint = urlPrefix + "parent-cp/";
	}else if(ad2d == "STUDENT"){
		homepoint = urlPrefix + "student-cp/";
	}else{
		homepoint = urlPrefix + "login/";
	}
	
	//if the user is in a control panel section
	if(location.pathname.match("-cp") != null){
		document.write("<a href=\"" + homepoint + "\"><img src=\"" + urlPrefix + "images/my-account.jpg\" name=\"ImageMyAccount\" width=\"120\" height=\"33\" border=\"0\" id=\"ImageMyAccount\" /></a>");
	}else{
		document.write("<a href=\"" + homepoint + "\" onmouseout=\"MM_swapImgRestore()\"  onmouseover=\"MM_swapImage('ImageMyAccount','','" + urlPrefix + "/images/my-account-over.jpg',1)\"><img src=\"" + urlPrefix + "images/my-account-off.jpg\" name=\"ImageMyAccount\" width=\"120\" height=\"33\" border=\"0\" id=\"ImageMyAccount\" /></a>");
	}
	
}

function calcPageDepth(pathname)
{
	//the number of levels down a document is can be calculated by counting the number of forward slashes in the pathname and subtracting one
	var patt1=/\//gi;
	var matches = pathname.match(patt1);
	if(matches == null )
	{
		return 0;
	}else
	{
		return matches.length-1;
	}

}
