/*
	File: laureate.js
	Description:  This file houses all of the custom client-side javascript functions needed for Laureate's Online malls.
	Author: Ping Lay
	Date: 3/31/2007
*/


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;
}

/* 
	The cookie is in the following format:
	mn = urlencode("fname=UserName&uid=UserId");
 */
function getFirstName() { 
    var cookieString = ""; 
    try { 
            cookieString = readCookie("mn").replace("%3D", "%3d"); 
    } catch(err) { 
            return (null); 
    } 
    var cookieArray; 
    
    if (cookieString) 
            cookieArray = cookieString.split('%26'); // Split at the '&' 
        else 
                return(null); 
                
        if (cookieArray) { 
                fname = cookieArray[0].split('%3d'); 
                if (fname) { 
                        return (fname[1]); 
                } 
                else 
                        return (null); 
        } 
        else 
                return (null); 
                
}


function writeWelcome() {
	
    var firstName = getFirstName();
    	
    if ((firstName != null))
    {
        if (document.getElementById)
        {
            x = document.getElementById('welcomeBar');
            if (x != null)
            	x.innerHTML = "Welcome, " + firstName + ". If you're not " + firstName + ", <a href=\""+logout+"\">click here.</a>";
        }
        else if (document.all)
        {
            x = document.all[id];
            if (x != null)
            	x.innerHTML = "Welcome, " + firstName + ". <br/> If you're not " + firstName + ", <a href=\""+logout+"\">click here.</a>";
        }
    }
    
}

function outword(word) {
  if (word != null && word != '')
  {
	  lower = word.toLowerCase();
	  upper = word.toUpperCase();
	  normal = upper.substring(0,1) + lower.substring(1,lower.length);
	  return normal;
  }
  else
  	return null;
} 
