// Global Variables for the login form
var resizeTimer;     // timer object for updating the dim background width.
var dbl_IE_Version;  // IE version detected by ASP.NET

// Sets the IE Version of the browser (-1 = not IE)
function setIEVersion(dblIEVersion) {
   dbl_IE_Version = dblIEVersion;
}

function setLoginStatus()
{
	if (booLoggedIn)
	{
		hideNotLoggedInElements();
	}
	else
	{
		hideLoggedInElements();
	}
}

// Hides elements marked to display when not logged in
// and displays those hidden elements that are marked to be displayed
// only when logged in.
function toggleLoggedInLoggedOut ()
{
	// Toggle all elements of the class 'LoggedIn'
	$(".LoggedIn").toggle();
	// Toggle all elements of the class 'NotLoggedIn'
	$(".NotLoggedIn").toggle();
}

function hideNotLoggedInElements ()
{
	$(".NotLoggedIn").css("display","none");
	$("area.NotLoggedIn").attr("coords","0,0,0,0");
}

function hideLoggedInElements ()
{
	$(".LoggedIn").css("display","none");
	$("area.LoggedIn").attr("coords","0,0,0,0");
}

// Resize the dim background so it fits the width of the page
function resizeDimBackground() {
   var strTargetId = $(".LoginTeaserLogin").attr("id");
   var objBG = document.getElementById(strTargetId + "_BG");
   if (objBG) {
      objBG.style.width = $(document).width();
   }
}

// Hides or shows the div containing the Login control
function toggleLoginDisplay () {
   var strTargetId;
   var objBG;

	if ($(".LoginTeaserLogin").css("display") == "none") {
	   strTargetId = $(".LoginTeaserLogin").attr("id");
		$(".LoginTeaserLogin").css("width","0").css("height","0");

      // Only show the darkened background on Non-IE browsers
		if (dbl_IE_Version == -1) {
		   objBG = document.getElementById(strTargetId + "_BG");
		   if (!objBG) {
		      objBG = document.createElement('DIV');
		      objBG.id = strTargetId + "_BG";
		      objBG.style.height = $(document).height();
		      objBG.style.width = $(document).width();
		      document.body.appendChild(objBG);
		      $('#' + strTargetId + "_BG").toggleClass('alrtBG');
		   } else {
		      objBG.style.height = $(document).height();
		      objBG.style.width = $(document).width();
		   }
		   objBG.style.visibility = 'visible';
		   objBG.style.display = 'block';
		}

		// if you make the window a child IE will work but the postback will not.   
		//objBG.appendChild(document.getElementById(strTargetId));
		$(".LoginTeaserLogin").fadeIn("slow").animate({ height: "400px", width: "392px" }, { queue: false });

		$(window).bind("resize", function () {
		   if (!resizeTimer) {
		      clearTimeout(resizeTimer);
		   }
		   resizeTimer = setTimeout(resizeDimBackground, 100);
		});
		$("[id$='txtCN']").focus();
	}
	else
	{
		//$(".LoginTeaserLogin").fadeOut();
	   $(".LoginTeaserLogin").fadeOut().animate({ height: 0, width: 0 }, { queue: false, complete: function () { $(".LoginTeaserLogin").hide(); } });

      // clear the error messages
	   $(".textredsmall").css("display","none").css("visible","hidden");
	   // clear the input boxes
	   $(".fmInpt", $("#LoginTeaserLoginControls")).val("");

       strTargetId = $(".LoginTeaserLogin").attr("id");
       objBG = document.getElementById(strTargetId + "_BG");
       if (objBG) {
          objBG.style.visibility = 'hidden';
          objBG.style.display = 'none';
       }
	   //$(".LoginTeaserLogin").css("display","none");
	   $(window).unbind("resize");
	}
}

function setFailureDimensions ()
{
	$(".LoginTeaserLogin").css("height", $(".LoginTeaser").height());
	$(".LoginTeaserLogin").css("width",  $(".LoginTeaser").width());
}

// Hides or shows the div containing the UserInfo line
function toggleUserInfoDisplay ()
{
	$("#divHiddenUserInfo").toggle();
}

// When the "Don't Show Me This" link is clicked, this function is called.
// It places a cookie that stops the teaser from being shown.
function placeTeaserNoShowCookie ()
{
	var intNumberOfDaysToExpire = 1;
	var expDate = new Date();
	
	// Create real expiration date
	expDate.setDate(expDate.getDate() + intNumberOfDaysToExpire);
	// Hide the teaser
	$(".LoginTeaser").slideToggle();
	// Show the UserInfo line
	$("#divHiddenUserInfo").toggle();
	// Show "Show Teaser"
	$("#spnUnhideLoginTeaser").toggle();
	// Place the cookie
	document.cookie = "TeaserNoShow = True; expires=" + expDate.toUTCString();
}

function unhideTeaserNoShow()
{
	// Show the teaser
	$(".LoginTeaser").slideToggle();
	// Remove "Show Teaser"
	$("#spnUnhideLoginTeaser").toggle();
	// Hide the UserInfo line
	$("#divHiddenUserInfo").toggle();
	// Place the cookie
	expireTeaserNoShowCookie();
}

function expireTeaserNoShowCookie ()
{
	var intNumberOfDaysToExpire = 1;
	var expDate = new Date();
	
	// Create real expiration date
	expDate.setDate(expDate.getDate() - intNumberOfDaysToExpire);
	// Place the cookie
	document.cookie = "TeaserNoShow = False; expires=" + expDate.toUTCString();
}

function addCurrentLocation ()
{
	var strOriginalURL;
	
	// Checks if there is a query string
	if (location.search == '')
	{
		strOriginalURL = location.pathname + "?";
	}
	else
	{
		strOriginalURL = location.pathname + location.search.replace(/&/g,"URLAMP") + "URLAMP";
	}

	$(".OptIn.NotLoggedIn").each( function () { $(this).attr("href", $(this).attr("href") + "?banmanproredirect=" +  encodeURIComponent("http://" + location.host + "/index.aspx?sec=log&URL=" + strOriginalURL + "optin=" + intEMemberID).replace(/%26/g,"BMPAMPSAND"));});
	$(".OptOut.NotLoggedIn").each( function () { $(this).attr("href", $(this).attr("href") + "?banmanproredirect=" +  encodeURIComponent("http://" + location.host + "/index.aspx?sec=log&URL=" + strOriginalURL + "optout=" + intEMemberID).replace(/%26/g,"BMPAMPSAND"));});
	$(".OptIn.LoggedIn").each( function () { $(this).attr("href", $(this).attr("href") + "?banmanproredirect=" +  encodeURIComponent(location.href.replace(/&opt(in|out)=[0-9]+/gi,"").replace(/&/g,"BMPAMPSAND") + "BMPAMPSANDoptin=" + intEMemberID));});
	$(".OptOut.LoggedIn").each( function () { $(this).attr("href", $(this).attr("href") + "?banmanproredirect=" +  encodeURIComponent(location.href.replace(/&opt(in|out)=[0-9]+/gi,"").replace(/&/g,"BMPAMPSAND") + "BMPAMPSANDoptout=" + intEMemberID));});
}


