var validation = null;
var validatedThisPage = false;
validation = retrieveValidationArray();
if (validation == null)
{
	validation = new Array();
	validation[0] = new ValidateObject("commentSubject", "Subject", true, false, "isNotEmpty", "So we can expedite your question or comment as quickly as possible, a subject for the question or comment must be specified");
	validation[1] = new ValidateObject("name", "Your name", true, false, "isNotEmpty", "Your name must be entered");
	validation[2] = new ValidateObject("emailAddress", "E-mail address", true, false, "isEmail", "Your e-mail address must be entered and must be a valid e-mail address");
	validation[3] = new ValidateObject("oldEmailAddress", "Old e-mail address", true, false, "isEmail", "Your old e-mail address must be entered and must be a valid e-mail address");
	validation[4] = new ValidateObject("newEmailAddress", "New e-mail address", true, false, "isEmail", "Your new e-mail address must be entered and must be a valid e-mail address");
	validation[5] = new ValidateObject("comment", "Question or comment", true, false, "isNotEmpty", "In order to resolve your problem or react to your remarks, a question or comment must be entered");
	validation[6] = new ValidateObject("addToMailingList", "Add me to the MylesPinkney.com mailing list", false, false, null, null, "yes");
	validation[7] = new ValidateObject("permissionToPublish", "I give MylesPinkney.com permission to publish my comments", false, false, null, null, "yes");
}

function onLoadEvent()
{
	document.getElementById("username").value = getCustomerServiceEmailAddress();
	document.getElementById("sender").value = getCustomerServiceEmailAddress();
	document.getElementById("recipient").value = getCustomerServiceEmailAddress();
	
	findValidateObject(validation, "name").validate = true;
	findValidateObject(validation, "emailAddress").validate = true;
	findValidateObject(validation, "oldEmailAddress").validate = false;
	findValidateObject(validation, "newEmailAddress").validate = false;
	findValidateObject(validation, "commentSubject").validate = true;
	findValidateObject(validation, "comment").validate = true;
	findValidateObject(validation, "permissionToPublish").validate = false;
	findValidateObject(validation, "addToMailingList").validate = false;

	document.getElementById("comment").onfocus = new Function('commentFocus(this)');

	var commentSubject = document.getElementById("commentSubject");
	commentSubject.onchange = new Function('commentSubjectChanged(this)');
	commentSubjectChanged(commentSubject);
}

function commentSubjectChanged(list)
{	
	var value = list.options[list.selectedIndex].value;
	if (value == "COMMENT")
	{
		document.getElementById("permissionToPublishContainer").style.display = "inline";
		document.getElementById("addToMailingList1").style.visibility = "visible";
		findValidateObject(validation, "emailAddress").validate = true;
		findValidateObject(validation, "oldEmailAddress").validate = false;
		findValidateObject(validation, "newEmailAddress").validate = false;
		findValidateObject(validation, "comment").validate = true;
		for (var i = 1; i <= 3; i++)
		{
			document.getElementById("emailAddress" + i).style.display = "";
			document.getElementById("oldEmailAddress" + i).style.display = "none";
			document.getElementById("newEmailAddress" + i).style.display = "none";
			document.getElementById("comment" + i).style.display = "";
		}
	}
	else if (value == "CHANGE_MY_SUBSCRIPTION_EMAIL_ADDRESS")
	{
		document.getElementById("permissionToPublishContainer").style.display = "none";
		document.getElementById("addToMailingList1").style.visibility = "hidden";
		findValidateObject(validation, "emailAddress").validate = false;
		findValidateObject(validation, "oldEmailAddress").validate = true;
		findValidateObject(validation, "newEmailAddress").validate = true;
		findValidateObject(validation, "comment").validate = false;
		for (var i = 1; i <= 3; i++)
		{
			document.getElementById("emailAddress" + i).style.display = "none";
			document.getElementById("oldEmailAddress" + i).style.display = "";
			document.getElementById("newEmailAddress" + i).style.display = "";
			document.getElementById("comment" + i).style.display = "none";
		}
	}
	else if (value == "UNSUBSCRIBE_ME_FROM_MAILING_LIST")
	{
		document.getElementById("permissionToPublishContainer").style.display = "none";
		document.getElementById("addToMailingList1").style.visibility = "hidden";
		findValidateObject(validation, "emailAddress").validate = true;
		findValidateObject(validation, "oldEmailAddress").validate = false;
		findValidateObject(validation, "newEmailAddress").validate = false;
		findValidateObject(validation, "comment").validate = false;
		for (var i = 1; i <= 3; i++)
		{
			document.getElementById("emailAddress" + i).style.display = "";
			document.getElementById("oldEmailAddress" + i).style.display = "none";
			document.getElementById("newEmailAddress" + i).style.display = "none";
			document.getElementById("comment" + i).style.display = "none";
		}
	}
	else
	{
		document.getElementById("permissionToPublishContainer").style.display = "none";
		document.getElementById("addToMailingList1").style.visibility = "visible";
		findValidateObject(validation, "emailAddress").validate = true;
		findValidateObject(validation, "oldEmailAddress").validate = false;
		findValidateObject(validation, "newEmailAddress").validate = false;
		findValidateObject(validation, "comment").validate = true;
		for (var i = 1; i <= 3; i++)
		{
			document.getElementById("emailAddress" + i).style.display = "";
			document.getElementById("oldEmailAddress" + i).style.display = "none";
			document.getElementById("newEmailAddress" + i).style.display = "none";
			document.getElementById("comment" + i).style.display = "";
		}
	}
}

function commentFocus(textArea)
{
	if (textArea.value == "Enter your new e-mail address here." || textArea.value == "Enter the e-mail address to unsubscribe here.")
	{
		textArea.value = "";
	}
}

function createSubjectList()
{
	var keyValue = document.location.href.split("=");
	var subject = "";
	if (keyValue != null && keyValue.length >= 2)
	{
		subject = keyValue[1];
	}

	var selected = false;
	var opts = new Array();
	var count = 0;
	
	if (subject == null || subject.length == 0)
	{
		opts[count++] = new Option("Please select", "");
	}
	
	if (subject == "QUESTION_ABOUT_MY_ORDER")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Question about my order", "QUESTION_ABOUT_MY_ORDER", selected);
	
	if (subject == "QUESTION_ABOUT_PURCHASING")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Question about purchasing from MylesPinkney.com", "QUESTION_ABOUT_PURCHASING", selected);
	
	if (subject == "GENERAL_QUESTION")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("General question", "GENERAL_QUESTION", selected);
	
	if (subject == "ERROR")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Error encountered on the website", "ERROR", selected);
	
	if (subject == "COMMENT")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Comment about the MylesPinkney.com Web site, the artist or the artwork", "COMMENT", selected);
	
	if (subject == "CHANGE_MY_SUBSCRIPTION_EMAIL_ADDRESS")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Change my subscription e-mail address", "CHANGE_MY_SUBSCRIPTION_EMAIL_ADDRESS", selected);
	
	if (subject == "UNSUBSCRIBE_ME_FROM_MAILING_LIST")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Unsubscribe me from the mailing list", "UNSUBSCRIBE_ME_FROM_MAILING_LIST", selected);
	
	if (subject == "OTHER")
	{
		selected = true;
	}
	else
	{
		selected = false;
	}
	opts[count++] = new Option("Other", "OTHER", selected);
	
	findValidateObject(validation, "commentSubject").createList(opts);
}

function onUnloadEvent()
{
	if (validatedThisPage == false)
	{
		deleteValidationCookie();
	}
}

function submitForm()
{
	validatedThisPage = true;
	
	var obj = findValidateObject(validation, "name");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "emailAddress");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "oldEmailAddress");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "newEmailAddress");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "commentSubject");
	obj.value = document.getElementById(obj.id).options[document.getElementById(obj.id).selectedIndex].value;
	obj = findValidateObject(validation, "comment");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "permissionToPublish");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "addToMailingList");
	obj.value = document.getElementById(obj.id).value;
	
	if (validateArray(validation))
	{
		deleteValidationCookie();
		document.forms[0].action = getFormMailAction();
		document.forms[0].submit();
	}
	else
	{
		persistValidationArray(validation);
		document.location = "contactUs.html";
	}
}
