/*
	File: Gsc.js
	Description:  This file houses all of the custom client-side javascript functions needed for the Goodsamclub Online mall.
	Author: Ping Lay
	Date: 9/14/2006
*/

function loadLeftNav() {
	//alert('loadHeader');
	if (isGoodSamClubMember()){
		showGoodSamClubMember_left_nav();
	}
}

function showGoodSamClubMember_left_nav() {
	//alert('call showGoodSamClubMember_left_nav()');
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById('mn_visitor_left_nav').style;
		style2.display = "none";
		var style2 = document.getElementById('mn_member_left_nav').style;
		style2.display = "block";
		//alert("document.getElementById");
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all['mn_visitor_left_nav'].style;
		style2.display = "none";
		var style2 = document.all['mn_member_left_nav'].style;
		style2.display = "block";
		//alert("document.all");
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers['mn_visitor_left_nav'].style;
		style2.display = "none";
		var style2 = document.layers['mn_member_left_nav'].style;
		style2.display = "block";
		//alert("document.layers");
	}
}

function checkMANav() {
	if (isGoodSamClubMember()){
		showMA_nav();
	}
}
function showMA_nav() {
	//alert('call showGoodSamClubMember_left_nav()');
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById('mn_topnav_ma_tab').style;
		style2.display = "block";
		//alert("document.getElementById");
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all['mn_topnav_ma_tab'].style;
		style2.display = "block";
		//alert("document.all");
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers['mn_topnav_ma_tab'].style;
		style2.display = "block";
		//alert("document.layers");
	}
}

function isGoodSamClubMember(){
	var memberFirstName = getMNCookieFirstName();
	var UID = getGSCCookie();
	//alert(UID);
	
	//if (memberFirstName && UID)
	if (UID)
		return true;
	else
		return false;
}

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 getGSCCookie() {
    var cookieString = readCookie("SMILEANDSAVE");
    var cookieArray;
    
    if (cookieString)
    	cookieArray = cookieString.split('%7C');
	else
		return(null);
		
 	if (cookieArray)
   		return cookieArray[0];
	else
		return(null);
}

function getMN_GSC_Cookie() {
    var cookieString = readCookie("U");
    var cookieArray;
     
    if (cookieString)
    	cookieArray = cookieString.split('%7C');
	else
		return(null);
		
 	if (cookieArray)
   		return cookieArray[0];
	else
		return(null);
}


function getMNCookieFirstName() {
    var cookieString = readCookie("U");
    var cookieArray;
    
    if (cookieString)
    	cookieArray = cookieString.split('%7C');
	else
		return(null);
		
    if (cookieArray)
    	return outword(cookieArray[1]);
	else
		return (null);
}

function writeWelcome() {
	
    //var firstName = getMNCookieFirstName();
	var firstName = "Good Sam Member";
	
    if ((firstName != null))
    {
        if (document.getElementById)
        {
            x = document.getElementById('welcomeBar');
            x.innerHTML = "Welcome, " + firstName + ". If you're not Good Sam Member, <a href=\""+logout+"\">click here.</a>";
        }
        else if (document.all)
        {
            x = document.all[id];
            x.innerHTML = "Welcome, " + firstName + ". If you're not Good Sam Member, <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;
} 
