/*************************************************************************************************************************
// File:	Registration.js
// Author: 	Matthew Hammond Mah, CondeNet
// Date: 	4/2/2007
// Summary: This javascript library is intended for the generic registration process that is used across all of CondeNet's
// 			desitnation sites (Style.com,Mens.Style.com,Concierge.com,Epicurious.com)
//
*************************************************************************************************************************/

var agt=navigator.userAgent.toLowerCase();
var is_safari = true;

function ReadCookie(cookieName) {
 	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return "";
 	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

var currEntryId;

function UserInfo () {
}

UserInfo.USERNAME_COOKIE = 'amg_user_info';

UserInfo.prototype.getUserName =
	function () {
		var cookieVal = ReadCookie(UserInfo.USERNAME_COOKIE);
		if (cookieVal == '') {
			return null;
		}

		return cookieVal;
        };

UserInfo.prototype.isLoggedIn =
	function () {
		return this.getUserName() != null;
	};



function showMouseOverPointer(e) {
	$(this.id).style.cursor = 'pointer';
}

function showUserStatusInNav() {
	if (new UserInfo().isLoggedIn()) {
		doShowSignedInNavbar();
	} else {
		doShowSignedOutNavbar();
	}
}

function doShowSignedOutNavbar() {
	if ($('signedOutMod') != null) {
		$('signedOutMod').style.display = 'block';
	}
	$('signedInMod').style.display = 'none';
	$('userId').innerHTML = '';
}

function doShowSignedInNavbar() {
	$('signedInMod').style.display = 'block';
	if ($('signedOutMod') != null) {
		$('signedOutMod').style.display = 'none';
	}
	$('userId').innerHTML = new UserInfo().getUserName();
}

function appendReturnto() {
        window.location = '/user/login/retrieve?returnto=' + escape(window.location.pathname + window.location.search);
    }

function doLogoutPost() {
        var opt = {
            method: 'post',
            onSuccess:
                function(response) {
                    window.location = window.location;
                }
        }
//        if (confirm("Are you sure that you want to log out?")) {
            new Ajax.Request('/user/logout', opt);
//        }
    }

YAHOO.util.Event.addListener(window, 'load', showUserStatusInNav);
YAHOO.util.Event.addListener('signOutLink1', 'click', doLogoutPost);