/*--------------------------------------------------------*\
	Script:  includes/js/common.js
	Purpose: Provide all common functions
\*--------------------------------------------------------*/

/*--------------------------------------------------------*\
	Global Variables
\*--------------------------------------------------------*/

var Standard_Popup_Container = "wrapper";

/*--------------------------------------------------------*\
	Utility Functions
\*--------------------------------------------------------*/

function check_javascript_enabled()
{
	var Javascript_Enabled = document.getElementById("Javascript_Enabled");
	Javascript_Enabled.value = 1;

	return(true);
}

/*--------------------------------------------------------*\
	DOM Functions
\*--------------------------------------------------------*/

function clear_child_nodes(Element)
{
	if(Element != null)
	{
		if(Element.childNodes)
		{
			var Number_Children = Element.childNodes.length;
			var Child;

			for(var Counter = 0; Counter < Number_Children; Counter++)
			{
				Child = Element.childNodes[0];
				Element.removeChild(Child);
			}
		}
	}
}

/*--------------------------------------------------------*\
	Popup Functions
\*--------------------------------------------------------*/

function create_popup(Container_ID, Popup_ID, Title, Class, Style)
{
	var Container = document.getElementById(Container_ID);

	var Title_Output = "",
		Class_Output = "",
		Style_Output = "";

	if(Title != null)
	{
		Title_Output = "<div class=\"popup_title\">" + Title + "</div>";
	}
	if(Class != null)
	{
		Class_Output = " class=\"" + Class + "\"";
	}
	if(Style != null)
	{
		Style_Output = " style=\"" + Style + "\"";
	}

	Container.innerHTML +=
		'<table cellspacing="0" cellpadding="0" id="' + Popup_ID + '"' + Class_Output + Style_Output + '>' +
		'<tr>' +
		'<td class="popup_top_left"></td>' +
		'<td class="popup_top_middle"> </td>' +
		'<td class="popup_top_right"></td>' +
		'</tr>' +
		'<tr>' +
		'<td class="popup_middle_left"> </td>' +
		'<td align="left" valign="top" class="popup_middle" id="' + Popup_ID + '_middle">' +
		'<div class="close_popup"><a href="javascript:close_popup(\'' + Container_ID + '\',\'' + Popup_ID + '\');" title="Close"><img src="/images/actions/close.gif" width="8" height="8" alt="Close" title="Close" /></a></div>' +
		Title_Output +
		'</td>' +
		'<td class="popup_middle_right"> </td>' +
		'</tr>' +
		'<tr>' +
		'<td class="popup_bottom_left"></td>' +
		'<td class="popup_bottom_middle"> </td>' +
		'<td class="popup_bottom_right"></td>' +
		'</tr>' +
		'</table>';

	var Content = document.getElementById(Popup_ID + "_middle");

	return(Content);
}

//----------------------------------------------------------

function close_popup(Container_ID, Popup_ID)
{
	Container = document.getElementById(Container_ID);
	Popup = document.getElementById(Popup_ID);

	Container.removeChild(Popup);
}

//----------------------------------------------------------

function center_popup(Popup_ID)
{
	var Popup = document.getElementById(Popup_ID);
	Popup.style["left"] = ((document.documentElement.offsetWidth - Popup.offsetWidth) / 2) + "px";
	Popup.style["top"] = (((document.documentElement.clientHeight - Popup.offsetHeight) / 2) + document.documentElement.scrollTop) + "px";
	Popup.style["visibility"] = "visible";
}

/*--------------------------------------------------------*\
	Delete Functions
\*--------------------------------------------------------*/

function delete_wish_list(ID, Title)
{
	var Popup_ID = "delete_wish_list";
	var Container = document.getElementById(Popup_ID);

	if(Container == null)
	{
		var Container = create_popup(Standard_Popup_Container, Popup_ID, "Delete Wish List", "standard_popup");

		Container.innerHTML += 
			'Are you sure you want to delete your wish list <a href="/wish_list.php?ID=' + ID + '" title="' + Title + '">' + Title + '</a>?<br /><br />' +
			'<a href="/delete_wish_list.php?ID=' + ID + '&amp;Confirm=1" title="Yes, Delete">Yes</a> or <a href="javascript:close_popup(\'' + Standard_Popup_Container + '\',\'' + Popup_ID + '\');" title="No, Don\'t Delete">No</a>';

		center_popup(Popup_ID);
	}
}

//----------------------------------------------------------

function delete_wish_list_item(Item_ID, Item_Title, Wish_List_ID, Wish_List_Title)
{
	var Popup_ID = "delete_wish_list_item";
	var Container = document.getElementById(Popup_ID);

	if(Container == null)
	{
		var Container = create_popup(Standard_Popup_Container, Popup_ID, "Delete Wish List Item", "standard_popup");

		Container.innerHTML += 
			'Are you sure you want to delete your wish list item <a href="/wish_list_item.php?ID=' + Item_ID + '" title="' + Item_Title + '">' + Item_Title + '</a> from <a href="/wish_list.php?ID=' + Wish_List_ID + '" title="' + Wish_List_Title + '">' + Wish_List_Title + '</a>?<br /><br />' +
			'<a href="/delete_wish_list_item.php?ID=' + Item_ID + '&amp;Confirm=1" title="Yes, Delete">Yes</a> or <a href="javascript:close_popup(\'' + Standard_Popup_Container + '\',\'' + Popup_ID + '\');" title="No, Don\'t Delete">No</a><br /><br />' +
			'If anybody has a claim on this item and the wish list is open, they will be notified that the item has been removed.';

		center_popup(Popup_ID);
	}
}

//----------------------------------------------------------

function delete_wish_list_invitation(Invitation_ID, Invitee_Email, Invitee_Name, Wish_List_ID, Wish_List_Title)
{
	var Popup_ID = "delete_wish_list_invitation";
	var Container = document.getElementById(Popup_ID);

	if(Container == null)
	{
		var Container = create_popup(Standard_Popup_Container, Popup_ID, "Delete Wish List Invitation", "standard_popup");

		Container.innerHTML += 
			'Are you sure you want to delete your wish list invitation for <a href="mailto:' + Invitee_Email + '" title="Email ' + Invitee_Name + '">' + Invitee_Name + '</a> in <a href="/wish_list.php?ID=' + Wish_List_ID + '" title="' + Wish_List_Title + '">' + Wish_List_Title + '</a>?<br /><br />' +
			'<a href="/delete_wish_list_invitation.php?ID=' + Invitation_ID + '&amp;Confirm=1" title="Yes, Delete">Yes</a> or <a href="javascript:close_popup(\'' + Standard_Popup_Container + '\',\'' + Popup_ID + '\');" title="No, Don\'t Delete">No</a>'; 
			'If anybody has a claim on this item and the wish list is open, they will be notified that the item has been removed.';

		center_popup(Popup_ID);
	}
}