function OpenRatingsPopup()
{	
	jQuery("#ratingsPopup").show();
	
	return false;
}

function CloseRatingsPopup()
{
	jQuery("#ratingsPopup").hide();
	
	return false;
}

function OpenLoginBox()
{
	CloseRegistrationBox(); // just in case
	
	jQuery('[id$="loginBox"]').show(500);
	
	return false;
}

function CloseLoginBox()
{
	jQuery('[id$="loginBox"]').hide(500);
	
	return false;
}

function Login()
{
	jQuery('[id$="loginLinkPanel"]').hide();
	jQuery('[id$="favoritesLinkPanel"]').show();
	jQuery('[id$="addToFavoritesPanel"]').show();			
}

function Logout()
{	
	// call a handler to logout
	jQuery.ajax({
	   type: "GET",
	   timeout: 30000,
	   url: "/SubaruDrive0/controls/LogoutHandler.ashx",
	   beforeSend: function(){
		},
	   success: function (response) {
			jQuery('[id$="loginLinkPanel"]').show();
			jQuery('[id$="favoritesLinkPanel"]').hide();
			
			HideAddToFavoritesPanel();
			
			if(currentDocumentName == 'My Favorites')
			{
				window.location.href = "/Home.aspx";
			}
		},
		failure: function (msg) {
		}
	});
}

function OpenRegistrationBox()
{
	CloseLoginBox(); // just in case
	
	jQuery('[id$="registrationBox"]').show(500);
	
	return false;
}

function CloseRegistrationBox()
{
	jQuery('[id$="registrationBox"]').hide(500);
	
	return false;
}

function ShowFavArticles()
{
	jQuery('[id$="favImagesPanel"]').hide();
	jQuery('[id$="favArticlesPanel"]').show();
	jQuery('[id$="favArticlesSelector"]').css("background-color", "#232323");
	jQuery('[id$="favImagesSelector"]').css("background-color", "black");
	
	return false;
}

function ShowFavImages()
{
	jQuery('[id$="favArticlesPanel"]').hide();
	jQuery('[id$="favImagesPanel"]').show();
	jQuery('[id$="favImagesSelector"]').css("background-color", "#232323");
	jQuery('[id$="favArticlesSelector"]').css("background-color", "black");
	
	return false;
}

function ShowAddToFavoritesPanel()
{
	var addToFavoritesPanel = jQuery('[id$="addToFavoritesPanel"]');
	if (addToFavoritesPanel != null) addToFavoritesPanel.show();
	
	var ratingsPanel = jQuery('[id$="ratingsPanel"]');
	var ratingsDisplay = jQuery('[id$="ratingsDisplay"]');
	if (ratingsPanel != null) ratingsPanel.css("left", "165px");
	if (ratingsDisplay != null) ratingsDisplay.css("left", "300px");
}

function HideAddToFavoritesPanel()
{
	var addToFavoritesPanel = jQuery('[id$="addToFavoritesPanel"]');
	if (addToFavoritesPanel != null) addToFavoritesPanel.hide();
	
	var ratingsPanel = jQuery('[id$="ratingsPanel"]');
	var ratingsDisplay = jQuery('[id$="ratingsDisplay"]');
	if (ratingsPanel != null) ratingsPanel.css("left", "30px");
	if (ratingsDisplay != null) ratingsDisplay.css("left", "440px");			
}

function AddToFavorites(nodeAliasPath, isArticle)
{
	if(null === nodeAliasPath || typeof nodeAliasPath == 'undefined' || nodeAliasPath == '')
	{
		return;
	}

	if(null === isArticle || typeof isArticle == 'undefined' || isArticle != 'true')
	{
		isArticle = 'false';
	}
	
	// call a handler to add to favorites
	jQuery.ajax({
	   async: false,
	   type: "GET",
	   timeout: 30000,
	   url: "../SubaruDrive0/controls/AddToFavoritesHandler.ashx",
	   data: "NodeAliasPath=" + nodeAliasPath + "&IsArticle=" + isArticle,
	   beforeSend: function(){
		},
	   success: function (response) {
			DisplayAddToFavoritesConfirmation();
		},
		failure: function (msg) {
		}
	});
}

function DisplayAddToFavoritesConfirmation()
{
	var addToFavoritesConfirmation = jQuery('[id$="addToFavoritesConfirmation"]')
	
	if(addToFavoritesConfirmation != null) addToFavoritesConfirmation.show();
	
	return false;
}

function CloseAddToFavoritesConfirmation()
{
	jQuery('[id$="addToFavoritesConfirmation"]').hide(500);
	
	HideAddToFavoritesPanel();
	
	return false;
}


function RemoveFromFavorites(siteID, nodeAliasPath, isArticle, whichTab)
{
	if(null === nodeAliasPath || typeof nodeAliasPath == 'undefined' || nodeAliasPath == '')
	{
		return;
	}
	
	if(null === isArticle || typeof isArticle == 'undefined' || isArticle != 'true')
	{
		isArticle = 'false';
	}
	
	if(null === whichTab || typeof whichTab == 'undefined' || whichTab == '')
	{
		whichTab = "";
	}
	
	// call a handler to add to favorites
	jQuery.ajax({
	   async: false,
	   type: "GET",
	   timeout: 30000,
	   url: "../SubaruDrive0/controls/RemoveFromFavoritesHandler.ashx",
	   data: "SiteID=" + siteID + "&NodeAliasPath=" + nodeAliasPath + "&IsArticle=" + isArticle,
	   beforeSend: function(){
		},
	   success: function (response) {
		window.location.href = "/My-Favorites.aspx?Tab=" + whichTab;
		},
		failure: function (msg) {
		}
	});
}

function IsFavorite(nodeAliasPath, isArticle)
{
	var result = '';
	
	if(null === nodeAliasPath || typeof nodeAliasPath == 'undefined' || nodeAliasPath == '')
	{
		return;
	}
	
	if(null === isArticle || typeof isArticle == 'undefined' || isArticle != 'true')
	{
		isArticle = 'false';
	}
	
	// call a handler to determine if favorite
	jQuery.ajax({
	   async: false,
	   type: "GET",
	   timeout: 30000,
	   url: "../SubaruDrive0/controls/IsFavoriteHandler.ashx",
	   data: "NodeAliasPath=" + nodeAliasPath + "&IsArticle=" + isArticle,
	   beforeSend: function(){
		},
	   success: function (response) {
		result = response;
		return result;
		},
		failure: function (msg) {
		}
	});
	
	return result;
}


function IsAuthenticated()
{	
	var result = '';
	
	// call a handler to determine if user is authenticated
	jQuery.ajax({
	   async: false,
	   type: "GET",
	   timeout: 30000,
	   url: "../SubaruDrive0/controls/IsAuthenticatedHandler.ashx",
	   beforeSend: function(){
		},
	   success: function (response) {
		result = response;
		return result;
		},
		failure: function (msg) {
		}
	});
	
	return result;
}

function GoToFavorites()
{
	if(IsAuthenticated() == 'true')
	{
		window.location.href = "/My-Favorites.aspx";
	}
	else
	{
		jQuery('[id$="redirectToFavorites"]').val('true');
		OpenLoginBox();
	}
}

function RedirectToFavorites()
{
	window.location.href = "/My-Favorites.aspx";
}
