Event.observe(window, "load", initPage)



function initPage()
{
	hookupPhoneNumber();
}


//
function openWindow()
{
	var newWin = window.open 
	('../Global/credit_card_security_codes.html','newwindow',config='height=425,width=650,toolbar=no,scrollbars=no,menubar=no,location=no,directories=no,status=no,resizable=yes');

}


//
function calculateName(o_form)
{
	var rtn = "";
	var first_name		= o_form.first_name.value;
	var middle_initial	= o_form.middle_initial.value;
	var last_name		= o_form.last_name.value;
	rtn += first_name;
	if(middle_initial.length > 0)
		rtn += " "+ middle_initial;
	rtn += " "+ last_name;

	o_form.card_name.value = rtn;
}


//
function validateForm(o_form)
{
	var have_error = false;
	var str = "The following fields are required: \n";

	with(o_form)
	{
		// First Name
		if(first_name.value.length == 0)
		{
			have_error = true;
			str += "\n- First Name"
		}

		// Last Name
		if(last_name.value.length == 0)
		{
			have_error = true;
			str += "\n- Last Name"
		}

		// Email
		if(email.value.length == 0)
		{
			have_error = true;
			str += "\n- Email "
		}

		// Home Phone Number
		if(home_phone_number.value.length == 0 ||
			home_phone_area.value.length == 0 )
		{
			have_error = true;
			str += "\n- Home Phone Numbe"
		}

		// Street Address 
		if(street_address.value.length == 0)
		{
			have_error = true;
			str += "\n- Street Address"
		}

		// City
		if(city.value.length == 0)
		{
			have_error = true;
			str += "\n- City "
		}

		// State
		if(state.value.length == 0)
		{
			have_error = true;
			str += "\n- State "
		}

		// Zip Code
		if(zip_code.value.length == 0)
		{
			have_error = true;
			str += "\n- Zip Code"
		}
	}

	if(have_error)
	{
		str += "\n\n\n";
		alert(str);
		return false;
	}

	return true;
}

//
function moveToPhonePrefix(src, textbox)
{
	if(src.value.length == 3)
		textbox.focus();
}








//
function hookupPhoneNumber()
{
	var phone_number_boxes = Element.getElementsBySelector(document, 'input[class="phone-number"]');
	phone_number_boxes.each(function(box) {
		Event.observe(box, "blur", addDash)
	});
}


//
function addDash()
{
	var forth_char = this.value.substring(3, 4);
	if(forth_char.length == 0) { return; }
	
	if(CommonJS.isMatch(forth_char, "0123456789"))
	{
		this.value = this.value.substring(0,3) +"-"+ this.value.substring(3, this.value.length);
	}
}

