//------------------------------------------------------------------------------
// Class:  TellAFriend
//------------------------------------------------------------------------------
// Author:  CL
// Date:  2008/01/30
// Description:  This class defines the functions used by the Manage Group section.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function AddressBook()
{
	// Variables:
	var sortOrder = "";
	var sortColumnID = "";
	var groupID = "";
	var addressBookType = "";
	var albumID = "";
	var selectedFriendOnThisPage = "";
	
	//--------------------------------------------------------------------------

	// Methods:
	this.init = init;
	this.getPaginationURLLocation = getPaginationURLLocation;
	this.addressBookLoadResult = addressBookLoadResult;
	this.updateAddressBookPaginValues = updateAddressBookPaginValues;
	this.saveSelectedFriend = saveSelectedFriend;
	this.selectAllCheckBoxes = selectAllCheckBoxes;
	this.deletePhotosConfirm = deletePhotosConfirm;
	this.addSelectedFriendsToInvitation = addSelectedFriendsToInvitation;
	this.deleteSelectedFriends = deleteSelectedFriends;
	this.updateMoreInfo = updateMoreInfo;

	//--------------------------------------------------------------------------
	
	function init(strSortOrder,intColumnID,intGroupID,intAddressBookType,intAlbumID)
	{
		sortOrder = strSortOrder;
		sortColumnID = intColumnID;
		groupID = intGroupID;
		addressBookType = intAddressBookType;
		albumID = intAlbumID;
		selectedFriendOnThisPage = "";
	}

	//--------------------------------------------------------------------------
	
	function getPaginationURLLocation(sOtherValues)
	{
		var thePaginationURLLocation =  "/gallery/_var/inc_friendInfoList.cfm?gid=" + groupID + "&colID=" + sortColumnID + "&sortOrd=" + sortOrder;
		if(addressBookType > 0)
		{
			thePaginationURLLocation += "&abt=" + addressBookType + "&a=" + albumID;
		}
		thePaginationURLLocation += sOtherValues;
		return thePaginationURLLocation;
	}
	
	//--------------------------------------------------------------------------
	
	function addressBookLoadResult(gID)
	{
		var theURLLocation = "index.cfm?gid=" + gID + "&colID=" + sortColumnID + "&sortOrd=" + sortOrder ;
		if(addressBookType > 0)
		{
			theURLLocation += "&abt=" + addressBookType + "&a=" + albumID;
		}
		window.location = theURLLocation;
	}
	
	//--------------------------------------------------------------------------
	
	function updateAddressBookPaginValues(grpID,sortColID,sortOrd)
	{
		groupID = grpID;
		sortColumnID = sortColID;
		sortOrder = sortOrd;
	}
	
	//--------------------------------------------------------------------------
	
	function saveSelectedFriend(theFriendSelect, intValue)
	{
		if(theFriendSelect.checked == 1)
		{
			$.ajax({
				type: "GET",
				url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=1&sID=" + intValue,
				dataType: "html"
			});
		}
		else
		{
			$.ajax({
				type: "GET",
				url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=2&sID=" + intValue,
				dataType: "html"
			});	
		}
		
	}
	
	//--------------------------------------------------------------------------
	
	function selectAllCheckBoxes(formName, fieldName, checkValue)
	{
		var sValueSelected = "";
		var sValueDeSelected = "";
		if(!document.forms[formName])
			return;
		
		var objCheckBoxes = document.forms[formName].elements[fieldName];
		if(!objCheckBoxes)
			return;
		
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes)
		{
			objCheckBoxes.checked = checkValue;
			intValue = objCheckBoxes.value;
			if(objCheckBoxes.checked == 1)
			{
				if(sValueSelected.length == 0)
				{
					sValueSelected = intValue;
				}
				else
				{
					sValueSelected = sValueSelected + "," + intValue;
				}
			}
			else
			{
				if(sValueDeSelected.length == 0)
				{
					sValueDeSelected = intValue;
				}
				else
				{
					sValueDeSelected = sValueDeSelected + "," + intValue;
				}
			}
		}
		else
		{
			for(var i=0; i < countCheckBoxes; i++)
			{
				objCheckBoxes[i].checked = checkValue;
				intValue = objCheckBoxes[i].value;
				if(objCheckBoxes[i].checked == 1)
				{
					/*$.ajax({
						type: "GET",
						url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=1&sID=" + intValue,
						dataType: "html"
					});*/
					if(sValueSelected.length == 0)
					{
						sValueSelected = intValue;
					}
					else
					{
						sValueSelected = sValueSelected + "," + intValue;
					}
				}
				else
				{
					/*$.ajax({
						type: "GET",
						url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=2&sID=" + intValue,
						dataType: "html"
					});	
					*/
					if(sValueDeSelected.length == 0)
					{
						sValueDeSelected = intValue;
					}
					else
					{
						sValueDeSelected = sValueDeSelected + "," + intValue;
					}
				}
			}
		}

		$.ajax({
				type: "GET",
				url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=1&sID=" + sValueSelected,
				dataType: "html"
			});
		
		$.ajax({
				type: "GET",
				url: "/gallery/_var/inc_setManageAddressBookSession.cfm?sectionID=1&tID=2&sID=" + sValueDeSelected,
				dataType: "html"
			});
		
	}
	
	//--------------------------------------------------------------------------
	
	function deletePhotosConfirm(idString)
	{
		document.getElementById('sSelectedFriendsListings').style.display = "none";
		$.ajax({
			type: "GET",
			url: "/gallery/_var/inc_getAllSelectedFriendInfo.cfm",
			dataType: "html",
			success: function(html){
				if(html.length > 0)
				{
					document.getElementById('bdsection').style.height = "250px";
					document.getElementById('sSelectedFriendsListings').innerHTML = html;
					document.getElementById('sSelectedFriendsListings').style.display = "block";
				}
			},
			error: function(){
				document.getElementById('sSelectedFriendsListings').innerHTML = "";
			 }
		});
		
		theElement = document.getElementById(idString);
		if (theElement.style.display == "none")
		{
			theElement.style.display = "block";
		}
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
			
		YAHOO.deleteFriend.container.deleteFriend = new YAHOO.widget.Panel('deleteFriend', { width:'350px', close:false, draggable:false, fixedcenter:true, visible:true, constraintoviewport:false, zIndex:100 } );
		YAHOO.deleteFriend.container.deleteFriend.render();
		
		function hideDeleteFriend()
		{
			document.getElementById("overlay").style.display ="none";
			YAHOO.deleteFriend.container.deleteFriend.hide();
		}
		YAHOO.util.Event.addListener("closeDeleteFriends", "click", hideDeleteFriend, YAHOO.deleteFriend.container.deleteFriend, true);
	}
	
	//--------------------------------------------------------------------------
	
	function addSelectedFriendsToInvitation()
	{
		var sCurrentEmails = window.opener.document.frmTellAFriend.recipientEmails.value;
		$.ajax({
			type: "POST",
			url: "/gallery/_var/inc_getAllSelectedFriendInfo.cfm?sType=2",
			data: "sCurrentRecipients=" + sCurrentEmails,
			dataType: "text",
			success: function(text){
				if(text.length > 0)
				{
					if(oTellAFriend.getEmailRecipientCount(text) <= 25)
					{
						window.opener.document.frmTellAFriend.recipientEmails.value = text;
						window.close();
					}
					else
					{
						alert(
							'* You have entered more than 25 emails for the invitation email.\n'
							+ '  Please delselect some of the emails in the address book or \n  remove some the emails from your invitation email "Recipient Emails" field.'
						);
					}					
				}
			},
			error: function(){
				window.close();
			 }
		});
	}
	
	//--------------------------------------------------------------------------
	
	function deleteSelectedFriends()
	{
		document.frmAddressBook.isDeleteFriends.value = "1";
		document.frmAddressBook.submit();
	}
	
	//--------------------------------------------------------------------------
	
	function updateMoreInfo(fID,strEmail)
	{
		document.getElementById('moreInfoEmail').innerHTML = strEmail;
		document.getElementById('TipMoreInfo').innerHTML = "<img src='/gallery/img/loading.gif'>";
		if (document.getElementById('moreFriendInfo').style.display == "none")
		{
			document.getElementById('moreFriendInfo').style.display = "block";
		}
		YAHOO.moreFriendInfo.container.moreFriendInfo.show();
		
		$.ajax({
				type: "GET",
				url: "/gallery/_var/inc_getMoreDetails.cfm",
				data: "fID="+ fID,
				dataType: "html",
				success: function(html){
					if(html.length > 0)
					{
						document.getElementById('TipMoreInfo').innerHTML = html;
					}
					else
					{
						document.getElementById('TipMoreInfo').innerHTML = 
						   "<img src='/gallery/img/skin/admin_addressBookMoreDetails_bullet.gif' border='0' style='vertical-align:middle'>&nbsp;&nbsp;No groups are found for this friend.<br/>";
					}
				},
				error: function(){
					document.getElementById('TipMoreInfo').innerHTML = 
					"<img src='/gallery/img/skin/admin_addressBookMoreDetails_bullet.gif' border='0' style='vertical-align:middle'>&nbsp;&nbsp;Unable to retrieve the group information for this friend.<br/>";
				}
		});	
	}		

}

// Create Object
oAddressBook = new AddressBook();
//--------------------------------------------------------------------------