function highlight(myself)
{
	myself.style.border = "solid 2px #00BFFF";
	return true;
}

function unhighlight(myself)
{
	myself.style.border = "inset 2px #FFFFFF";
	return true;
}


function check_account_form()
{
	var accountForm = document.getElementById("account_form");

	try
	{
		var length = accountForm.length;
		var focus_flag = -1; //because the element_index start at 0 we start at -1
		var error_color = "#FFCC00";
		var noerror_color = "";

		for(var element_index=0; element_index < length; element_index++)
		{
			formElement = accountForm[element_index];

			if(formElement.value == "" && formElement.getAttribute("required") == "true")
			{
				formElement.style.background = error_color;
				if(focus_flag < 0)
				{
					focus_flag = element_index;
					formElement.focus();
				}
			}
			else
			{
				formElement.style.background = noerror_color;
			}

		}

		//the .value == "" test is all that is needed (i.e. we dont need required==true) because we know these are required.
		if((document.getElementById("password").value != document.getElementById("password_confirm").value) || (document.getElementById("password").value == "" || document.getElementById("password_confirm").value == ""))
		{
			focus_flag = 2;
			document.getElementById("password").focus();
			document.getElementById("password").style.background = error_color;
			document.getElementById("password_confirm").style.background = error_color;
		}
		else
		{
			document.getElementById("password").style.background = noerror_color;
			document.getElementById("password_confirm").style.background = noerror_color;
		}

		if((document.getElementById("address_email").value != document.getElementById("address_email_confirm").value) || (document.getElementById("address_email").value.indexOf("@") < 1) || (document.getElementById("address_email").value.indexOf(".") < 1) || (document.getElementById("address_email").value == "" || document.getElementById("address_email_confirm").value == ""))
		{
			focus_flag = 1;
			document.getElementById("address_email").focus();
			document.getElementById("address_email").style.background = error_color;
			document.getElementById("address_email_confirm").style.background = error_color;
		}
		else
		{
			document.getElementById("address_email").style.background = noerror_color;
			document.getElementById("address_email_confirm").style.background = noerror_color;
		}
                
		//if( (document.getElementById("billing_address_email").value == "") || (document.getElementById("billing_address_email").value.match(new RegExp('^.+?\@.+?\....?$')) == null) )
		if( (document.getElementById("billing_address_email").value == "") || (document.getElementById("billing_address_email").value.indexOf("@") < 1) || (document.getElementById("billing_address_email").value.indexOf(".") < 1) )
		{
			focus_flag = 10;
			document.getElementById("billing_address_email").focus();
			document.getElementById("billing_address_email").style.background = error_color;
		}
		else
		{
			document.getElementById("billing_address_email").style.background = noerror_color;
		}
                
		//if( (document.getElementById("shipping_address_email").value == "") || (document.getElementById("shipping_address_email").value.match(new RegExp('^.+?\@.+?\....?$')) == null) )
		if( (document.getElementById("shipping_address_email").value == "") || (document.getElementById("shipping_address_email").value.indexOf("@") < 1) || (document.getElementById("shipping_address_email").value.indexOf(".") < 1) )
		{
			focus_flag = 11;
			document.getElementById("shipping_address_email").focus();
			document.getElementById("shipping_address_email").style.background = error_color;
		}
		else
		{
			document.getElementById("shipping_address_email").style.background = noerror_color;
		}
                
		if(focus_flag < 0)
		{
			accountForm.submit();
			//return true;
		}
		else
		{
			return false;
		}
	}
	catch(er)
	{
		alert(er);
		return false;
	}
}

function check_account_edit_form()
{
	var accountForm = document.getElementById("account_edit_form");

	try
	{
		var length = accountForm.length;
		var focus_flag = -1; //because the element_index start at 0 we start at -1
		var error_color = "#FFCC00";
		var noerror_color = "";

		for(var element_index=0; element_index < length; element_index++)
		{
			formElement = accountForm[element_index];

			if(formElement.value == "" && formElement.getAttribute("required") == "true")
			{
				formElement.style.background = error_color;
				if(focus_flag < 0)
				{
					focus_flag = element_index;
					formElement.focus();
				}
			}
			else
			{
				formElement.style.background = noerror_color;
			}

		}

		if(focus_flag < 0)
		{
			accountForm.submit();
			//return true;
		}
		else
		{
			return false;
		}
	}
	catch(er)
	{
		alert(er);
		return false;
	}
}

function account_form_shipbill(toggle)
{
	if(toggle.checked)
	{
		document.getElementById("shipping_name_first").value = document.getElementById("billing_name_first").value;
		document.getElementById("shipping_name_last").value = document.getElementById("billing_name_last").value;
		document.getElementById("shipping_name_company").value = document.getElementById("billing_name_company").value;
		document.getElementById("shipping_rescom").value = document.getElementById("billing_rescom").value;
		document.getElementById("shipping_address_street_line1").value = document.getElementById("billing_address_street_line1").value;
		document.getElementById("shipping_address_street_line2").value = document.getElementById("billing_address_street_line2").value;
		document.getElementById("shipping_address_city").value = document.getElementById("billing_address_city").value;
		document.getElementById("shipping_address_state").value = document.getElementById("billing_address_state").value;
		document.getElementById("shipping_address_zip").value = document.getElementById("billing_address_zip").value;
		//document.getElementById("shipping_address_country").value = document.getElementById("billing_address_country").value;
		document.getElementById("shipping_number_phone").value = document.getElementById("billing_number_phone").value;
		document.getElementById("shipping_number_fax").value = document.getElementById("billing_number_fax").value;
		document.getElementById("shipping_address_email").value = document.getElementById("billing_address_email").value;
	}
	else
	{
		document.getElementById("shipping_name_first").value = "";
		document.getElementById("shipping_name_last").value = "";
		document.getElementById("shipping_name_company").value = "";
		document.getElementById("shipping_rescom").value = "0";
		document.getElementById("shipping_address_street_line1").value = "";
		document.getElementById("shipping_address_street_line2").value = "";
		document.getElementById("shipping_address_city").value = "";
		document.getElementById("shipping_address_state").value = "";
		document.getElementById("shipping_address_zip").value = "";
		//document.getElementById("shipping_address_country").value = "";
		document.getElementById("shipping_number_phone").value = "";
		document.getElementById("shipping_number_fax").value = "";
		document.getElementById("shipping_address_email").value = "";
	}


	/*var accountForm = document.getElementById("account_form");

	try
	{
		var length = accountForm.length;

		for(var element_index=0; element_index < length; element_index++)
		{
			formElement = accountForm[element_index];

			if(formElement.name == "")
			{
			}

		}

		return true;
	}
	catch(er)
	{
		alert(er);
		return false;
	}*/
}

function copy_email(type)
{
	document.getElementById(type+"_address_email").value = document.getElementById("address_email").value;
	return false;
}
