
//  THE CONTAINER PARENT THAT SHRINKS AND EXPAND
var homePersonalization = new Array('tdPeopleSearch','tdExperienceSearch','tdPersonalization');

// THE CHILDREN ELEMENT THAT GET DISPLAYED AND HIDDEN
// ZERO IS THE SHRINK STATE
// ONE IS THE THE SELECTED STATE
var homePersonalizationChildren = new Array ('divSearchPeople','divSearchExperience','divPersonalization');

function resizeArea(item,itemParent)
{
    // THE HIGHLIGHTED AREA SHOULD BE 501PX
    // THE DEHIGHLIGHTED AREA SHOULD BE 247PX
    var dom0 = null;
    var dom1 = null;
    var dom2 = null;
    var dom3 = document.getElementById( "personalizationRegister" );
    for (i=0;i<homePersonalization.length;i++)
    {

        dom0 = document.getElementById( homePersonalizationChildren[i] + "0" );
        dom1 = document.getElementById( homePersonalizationChildren[i] + "1" );
        dom2 = document.getElementById( "tdArrow" + i );

        if ( itemParent == homePersonalization[i] )
        {
            // THE PARENT ELEMENT THAT NEEDS TO EXPAND
            document.getElementById( itemParent ).style.width = 501;

            // THE CHILD ELEMENTS THAT NEED TO BE DISLAYED AND HIDDEN
            dom1.style.display = "block";
            dom0.style.display = "none";

            // HIDE THE ARROW
            dom2.style.display = "none";

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // DISPLAY THE REGISTER SECTION
            if ( itemParent == "tdPersonalization" )
            {
              dom3.style.display = "block";
            }
        }
        else
        {
            // THE PARENT ELEMENTS THAT NEED TO SHRINK
            document.getElementById( homePersonalization[i] ).style.width = 247;

            // THE CHILD ELEMENTS THAT NEED TO BE DISPLAYED AND HIDDEN
            dom0.style.display= "block";
            dom1.style.display= "none";

            // SHOW THE ARROW
            dom2.style.display = "block";

            // HIDE THE REGISTER SECTION
            dom3.style.display = "none";
        }
        /////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////
    }
}

function initForFailedLogin()   {
  var divArea = getTag( "divPersonalization0" );
  if( divArea )
    {
    resizeArea(divArea ,'tdPersonalization');
    divArea.style.display = "none";
    var elem = getTag( "divPersonalization1" );
    if( elem )
      elem.style.display = "block";
    elem = getTag( "personalizationRegister" );
    if( elem )
      elem.style.display = "block";

    elem = getTag( "divPersonalizationLoginFailed" )
    if( elem )
      elem.style.display = "block";
   }
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

var DWTPersonalization = {
 cookie: null,
 userName: null,


 init: function( cookieName ) {
  this.cookie = getCookie( cookieName );
  if( this.cookie )
    this.userName = this.cookie.substring( 0, this.cookie.indexOf( "|" ) );
  },

 initForFailedLogin: function() {
  if( this.cookie == null || this.userName.length == 0 )
    initForFailedLogin();
  },

 updateTemplateVisibility: function( welcomeDiv, loginDiv, logincheck ) {
    if( this.cookie && this.userName.length > 0 )
      div = getTag( welcomeDiv );                   
    else
      div = getTag( loginDiv );
    if( div )
      div.style.display = "block";

    if( logincheck == "1" )
      initForFailedLogin();
  },

 removeCookie: function( cookieName ) {
   var exdate=new Date();
   exdate.setTime ( exdate.getTime() - 1 );
   document.cookie=cookieName + "=;path=/;expires=" + exdate.toGMTString();

   },

 logout: function( cookieName ) {
   this.removeCookie( cookieName );
   //alert( "what is the cookie now?: " + getCookie( cookieName ) );
   window.location.href = ve_getUrlPrefix();
   }
}
