﻿_spBodyOnLoadFunctionNames.push("changeWelcomeText");
_spBodyOnLoadFunctionNames.push("addTodayDate");

function changeWelcomeText(){
	//find a reference...
	var node = document.getElementById("todayDate");
	
	//find welcome node from a reference...
	while(node && (node.nodeType != "1" || node.className != "welcomeUser")){
		node = node.previousSibling;
	}
	
	//if welcome node was found...
	if(node){
		
		//find the weolcome link...
		var links = node.getElementsByTagName("A");
		
		//if weolcome link was found...
		if(links.length > 0){
		
			//get the user name from the hidden...
			var input = document.getElementById("txtuser");
			if(input != null)
			{
				var text = removeWrongPrefix(input.value);
			
			//set the right welcome message. You can test it works by changing the "Welcome" word.
				links[0].innerHTML = "Welcome " + text;
			}
		}
	}
}

function navigateMailToLink(strBody)
{
	 var strEncoded="";  
    for (ix=0; ix < strBody.length; ix++)  
    {  
        var curChar=strBody.charAt(ix);  
        var strHexCode;  
        var strHexCodeL;  
        if (curChar=='%')  
        {  
            strHexCode=strBody.charAt(ix+1);  
            strHexCode+=strBody.charAt(ix+2);  
            strHexCodeL=strHexCode.toLowerCase();  
            if (strHexCodeL=="3a" || strHexCodeL=="2f" ||  
                strHexCodeL=="2e" || strHexCodeL=="2d" ||  
                strHexCodeL=="3d")  
            {  
                strEncoded+=curChar;  
            }  
            else 
            {  
                strEncoded+=curChar;  
                strEncoded+="25";  
            }  
        }  
        else 
        {  
            strEncoded+=curChar;  
        }  
    }  
    strEncoded = unescape(strEncoded);  
    window.location=strEncoded; 
 }


function removeWrongPrefix(text){
	var searched = "osbamembershipprovider:";
	var index = text.toLowerCase().indexOf(searched);
	
	if(index > -1){
		var replaced = text.substr(index, searched.length);
		text = text.replace(replaced, "");
	}
	
	return text;
}

