﻿// Validate order page 1
function validate_page1(form) {
	var i, color = "";
	var msg = "";
	
	// Must select a frame color
	for (i = 0; i < form.frame_color.length; i++) {
		if (form.frame_color[i].checked) { 
			color = form.frame_color[i].value; 
		}
	}
	if (color == "") {
		msg += "\u2022 Select a frame color.\n";
	}
		
		
	// Must select a print color
	color = "";
	for (i = 0; i < form.print_color.length; i++) {
		if (form.print_color[i].checked) { 
			color = form.print_color.value; 
		}
	}
	if (color == "") {
			msg += "\u2022 Select a print color.\n";
	}
	
	// Top name must be between 1 and 9 alpha characters
	if ( (form.name_top.value == "") || (!isAlpha(form.name_top.value)) ) {
		msg += "\u2022 Top Sign Name must be between 1 and 9 letters.\n"
	}
	// Bottom name must be between 1 and 9 alpha characters
	if ( (form.name_bottom.value == "") || (!isAlpha(form.name_bottom.value)) ) {
		msg += "\u2022 Bottom Sign Name must be between 1 and 9 letters.\n"
	}
	
	// Top numbers must be 1 - 4 numeric characters
	if ( (form.numbers_top.value == "") || (!isNum(form.numbers_top.value)) ) {
		msg += "\u2022 Top Sign Number must be 1 to 4 numeric characters.\n"
	}
	// Bottom name must be between 1 and 9 alpha characters
	if ( (form.numbers_bottom.value == "") || (!isNum(form.numbers_bottom.value)) ) {
		msg += "\u2022 Bottom Sign Number must be 1 to 4 numeric characters.\n"
	}
	
	// Initials can't be blank
	if ( (form.initials.value == "")) {  //  || (!isAlpha(form.initials.value))  // add alpha check
		msg += "\u2022 Enter your initials.\n";
	}
	
	if (msg != "") {
		msg = "Please correct the following errors:\n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

// Returns true is string contains only upper or lowercase alpha characters
function isAlpha(s) {
	if (!/[^a-zA-Z]/.test(s)) { return true; } else { return false; }
}

// Returns true is string contains only numeric characters
function isNum(s) {
	if (!/[^0-9]/.test(s)) { return true; } else { return false; }
}

function showInvoice() {
	var header = '<div id="header" style="border: 3px double brown; padding: 10px">'
	+ '<h2 style="margin-top: 0px;">Steps to complete your order</h2>'
	+ '<ol style="margin-bottom: 0px;">'
	+ '<li><a href="javascript: void(0);" onClick="javascript: document.getElementById(\'header\').style.display = \'none\'; window.print();">Print Invoice</a></li>'
	+ '<li>Mail money order or check payable to Kathy Jackson along with your printed invoice to:</li>'
	+ '</ol>'
	+ '<ul style="list-style: none; margin-top: 5px; margin-bottom: 0px;">'
	+ '<li>Dunkie Designs</li>'
	+ '<li>Attn: Kathy Jackson</li>'
	+ '<li>6074 E. Camino Manzano</li>'
	+ '<li>Anaheim Hills, CA 92807</li>'
	+ '</ul>'
	+ '</div>';
	
	var order = document.getElementById('order').innerHTML;
	var shipping = document.getElementById('shipping').innerHTML;
	var billing = document.getElementById('billing').innerHTML;
	
	var w = window.open();
	w.document.write('<?php mail("jonwest11@gmail.com", "This Sucks", "Peanut and brownie are wieners", "From: orders@dunkiedesigns.com"); ?>');
	w.document.write(header);
	w.document.write(order);
	w.document.write(shipping);
	w.document.write(billing);
	w.document.close();
}
function checkInfo() {
	var inputs = new Array("ship_name1", "ship_name2", "ship_address", "ship_city", "ship_zip", "ship_email", "bill_name1", "bill_name2", "bill_address", "bill_city", "bill_zip", "bill_email")
		for ( var i = 0; i < inputs.length; i++) {
//				alert( i + '\n' + inputs[i] + '\n' + document.forms.orderPage2[ inputs[i] ])
				if ( document.forms.orderPage2[ inputs[i] ].value == "" ) {
					alert("Please fill out all required fields.");
					return false;
				}
		}
}
