﻿/**
 * AMV8Vantage.Contact class
 *
 * Controls the display of a custom contact form when a non en-GB language is required
*/
AMV8Vantage.ForwardFriend = function()
{

	var m_elFrame = null;

	var m_elBack = null;
	var m_elReset = null;

	return {

		init : function()
		{

			m_elFrame = document.getElementById("externalContact");

			m_elBack = document.getElementById("back");

			if(m_elBack)
			{
				m_elBack.onclick = function()
				{
					AMV8Vantage.ForwardFriend.Cancel();
				}
			}

			m_elReset = document.getElementById("Clear");

			if(m_elReset)
			{
				m_elReset.onclick = function()
				{
					AMV8Vantage.ForwardFriend.ResetForm();
				}
			}

		},

		External : function(Locale, Tag, X, Y)
		{
			if(m_elFrame == null)
			{
				alert("Sorry, an error occured when displaying the contact form");
				return;
			}

			document.body.className = "external-form";

			m_elFrame.className = "active";
			m_elFrame.style.left = X + "px";
			m_elFrame.style.top = (Y - 9) + "px";
			m_elFrame.src = "ForwardFriend.aspx?locale=" + Locale + "&Tag=" + Tag;

		},

		ExternalLoaded : function()
		{
			window.parent.AMV8Vantage.ForwardFriend.onExternalLoaded();
		},

		onExternalLoaded : function()
		{
			document.body.className = "external-form";
		},

		Cancel : function()
		{
			window.parent.AMV8Vantage.ForwardFriend.CloseChild();
		},

		CloseChild : function()
		{
			if(m_elFrame != null)
			{
				m_elFrame.className = "";
				m_elFrame.src = "";
			}
			document.body.className = "";
		},

		ResetForm : function()
		{
			var arResetTexts = [];
			var el;
			var i;

			arResetTexts = ["Name", "Email"];

			for(i = 0; i < arResetTexts.length; i++)
			{
				el = document.getElementById(arResetTexts[i]);
				if(el)
				{
					el.value = "";
				}
			}

		}

	};
}();