AddSafeLoaderCallback(Template_Init);

function Template_Init()
{
}

var MailingList = {};

MailingList.ClosePopupForm = function()
{
	document.getElementById("popup_content_new").style.display = "none";
	JSFeature.HideWhiteOut();
	JSFeature.StopCenterOnScreen();
}

MailingList.ShowPopupForm = function()
{
	JSFeature.ShowWhiteOut(.6, "black", 1000);
	document.getElementById("popup_content_new").style.display = "";
	
	JSFeature.CenterOnScreen(document.getElementById("popup_content_new"));
	
	document.getElementById("mailing_list_name").value = "";
	document.getElementById("mailing_list_company").value = "";
	document.getElementById("mailing_list_email_address").value = "";
	
	document.getElementById("mailing_list_name").select();
}

MailingList.Submit_Click = function()
{
	var mailing_list_name 			= document.getElementById("mailing_list_name").value.trim();
	var mailing_list_company 		= document.getElementById("mailing_list_company").value.trim();
	var mailing_list_email_address 	= document.getElementById("mailing_list_email_address").value.trim();

	if(mailing_list_name == "")
	{
		document.getElementById("mailing_list_name").style.backgroundColor = "red";
		alert('"Name" is a required field!');
		document.getElementById("mailing_list_name").style.backgroundColor = "";
		document.getElementById("mailing_list_name").select();
		return;
	}
	
	//	if(mailing_list_company == "")
	//	{
	//		document.getElementById("mailing_list_company").style.backgroundColor = "red";
	//		alert('"Company" is a required field!');
	//		document.getElementById("mailing_list_company").style.backgroundColor = "";
	//		document.getElementById("mailing_list_company").select();
	//		return;
	//	}

	if(mailing_list_email_address == "")
	{
		document.getElementById("mailing_list_email_address").style.backgroundColor = "red";
		alert('"Email Address" is a required field!');
		document.getElementById("mailing_list_email_address").style.backgroundColor = "";
		document.getElementById("mailing_list_email_address").select();
		return;
	}
	
	document.getElementById("mailing_list_submit_button").style.disabled = "disabled";
	
	// Call the PHP function
	SignupForMailingList(SignupForMailingList_Callback, mailing_list_name, mailing_list_company, mailing_list_email_address);
}

MailingList.EmailAddress_KeyPress = function(e)
{
	var characterCode;
	
	if(e.which)
		characterCode = e.which;
	else if(typeof(event) == 'object')
		characterCode = event.keyCode;
	else
		characterCode = 'unknown';// escape, F1, F2, etc...

	if(characterCode == 13)//enter
	{
		MailingList.Submit_Click();
		return false;
	}
	else if(characterCode == 'unknown')// escape, F1, F2, etc...
	{
		return true;
	}
	else
	{
		return true;
	}
}

function SignupForMailingList_Callback(data)
{	
	if(data.status == 'success')
	{
		alert("Thank You! You have successfully signed up for the mailing list.");
		MailingList.ClosePopupForm();
	}
	else if(data.status == 'invalid_input')
	{
		if(data.error_message)
			alert(data.error_message);
		else
			alert("An error has occurred.");
	}
}