/*
	Javascript source file for http://lavitaallegra.com
	Created and maintained by Russell McEntyre
	http://rmcentyre.com or rmcentyre@gmail.com
*/


// ------------------------------------------------------------------- Store Managment -------------

function Create_Rows() {
	var num_rows = parseInt(document.getElementById("customize_row_count").value);
	document.getElementById("customize_rows").innerHTML = "";
	
	if (num_rows != 0) {
		var customizeDiv = document.getElementById("customize_rows");
		
		var customizeTable = document.createElement("table");
		customizeDiv.appendChild(customizeTable);
		
		var customizeBody = document.createElement("tbody");
		customizeTable.appendChild(customizeBody);
		customizeBody.insertRow(-1).innerHTML = "<td>Line</td><td>Limit</td><td>Description</td>";
		
		for (var i=1;i<=num_rows;i++) {
			var iRow = customizeBody.insertRow(-1);
			iRow.insertCell(-1).innerHTML = i;
			iRow.insertCell(-1).innerHTML = "<input type=\"text\" name=\"char_limit[" + i + "]\" size=\"3\" maxlength=\"3\" value=\"" + char_limit[i] + "\" />";
			iRow.insertCell(-1).innerHTML = "<input type=\"text\" name=\"char_desc[" + i + "]\" size=\"20\" maxlength=\"20\" value=\"" + char_desc[i] + "\" />";
		}
	}

}

function Div_Form_Reset() {
	document.getElementById("error_msg").innerHTML = "";
	document.getElementById("customize_rows").innerHTML = "";
}


// ------------------------------------------------------------------- Mailing List ----------------

function Join_Mailing_List(boxchecked)
	{
		if(boxchecked)
			{
				document.getElementById("additional_info").style.display = "block";
			}
			
			else
			
			{
				document.getElementById("additional_info").style.display = "none";
			}
	}

function Validate_Data()
	{
		// set up some variables
		var first_name = document.contact_us.First_Name;
		var last_name = document.contact_us.Last_Name;
		var email = document.contact_us.Email;
		var confirm_email = document.contact_us.Confirm_Email;
		var message = document.contact_us.Message;
		var submit = document.contact_us.Submit;
		
		// check to make sure neither email blank is null
		if(email.value != "" && confirm_email.value != "")
			{
				// check if emails are equal
				if(email.value != confirm_email.value)
					{
						// if they're not equal, make border of confirm turn red
						confirm_email.style.borderColor = "#CC3333";
					}
					else
					{
						// if they are equal, set borders to match
						confirm_email.style.borderColor = first_name.style.borderColor;
					}
			}
			else
			{
				confirm_email.style.borderColor = email.style.borderColor;
			}
		
		if(email.value != "")
			{	
				// check for valid email address
				if ((email.value.indexOf('@') < 0) || ((email.value.charAt(email.value.length-4) != '.') && (email.value.charAt(email.value.length-3) != '.')))
					{
						email.style.borderColor = "#CC3333";
					}
					else
					{
						email.style.borderColor = first_name.style.borderColor;
					}
			}
			
		if(confirm_email.value != "")
			{	
				// check for valid email address
				if ((confirm_email.value.indexOf('@') < 0) || ((confirm_email.value.charAt(confirm_email.value.length-4) != '.') && (confirm_email.value.charAt(confirm_email.value.length-3) != '.')))
					{
						confirm_email.style.borderColor = "#CC3333";
					}
					else
					{
						if(email.value != confirm_email.value)
						{
							confirm_email.style.borderColor = "#CC3333";
						}
						else
						{
							confirm_email.style.borderColor = first_name.style.borderColor;
						}
					}
			}

					
		// check that all are not null and that emails are equal
		if(first_name.value != "" && last_name.value != "" && email.value != "" && message.value != "" && email.value == confirm_email.value && !((email.value.indexOf('@') < 0) || ((email.value.charAt(email.value.length-4) != '.') && (email.value.charAt(email.value.length-3) != '.'))) && !((confirm_email.value.indexOf('@') < 0) || ((confirm_email.value.charAt(confirm_email.value.length-4) != '.') && (confirm_email.value.charAt(confirm_email.value.length-3) != '.'))))
			{
				// if true, enable submit button
				submit.disabled=false;
			}
			else
			{
				submit.disabled=true;
			}
	}

function Clear_Red()
	{
		var first_name = document.contact_us.First_Name;
		var last_name = document.contact_us.Last_Name;
		var email = document.contact_us.Email;
		var confirm_email = document.contact_us.Confirm_Email;
		var submit = document.contact_us.Submit;
		
		email.style.borderColor = first_name.style.borderColor;
		confirm_email.style.borderColor = first_name.style.borderColor;
		submit.disabled=true;
	}