//STEP 1 CHECKS
function Check_Step1(){
	var eventname = document.forms.Step1of3.eventname.value;
	var racerfirstname = String(document.forms.Step1of3.racerfirstname.value);
	var racerlastname = String(document.forms.Step1of3.racerlastname.value);
	var qwty = document.getElementsByName('qwty');
	var pok = 0;

	var respace = /\s/g;
	
	if ( eventname == "0" ){
		alert( "You have not selected an event!" );
		return;
	}

	if (!(String(document.forms.Step1of3.racerbib.value) > 0))
	{
		if ( racerfirstname.replace(respace, "") == "" ){
			alert( "Please fill in your First Name or Bib# ! ");
			return;
		}


		var rx_first='^[A-Za-z0-9\'-]*$';
		xx = new RegExp(rx_first);
		if (!xx.test(racerfirstname.replace(respace, ""))){
			alert("First Name contains not permit symbols!");
			return;
		}	
		if ( racerlastname.replace(respace, "") == "" ){
			alert( "Please fill in your Last Name!");
			return;
		}
		var rx_last='^[A-Za-z0-9\'-]*$';
		xx = new RegExp(rx_last);
		if (!xx.test(racerlastname.replace(respace, ""))){
			alert("Last Name contains not permit symbols!");
			return;
		}	
	}

	if (qwty[0].value == "no"){
		alert("This event has't products for order!");
		return;
	}else{
		for (var i=0;i<qwty.length;i++){
			if (qwty[i].value>0){pok = 1;}
		}	
		if (pok == 0){alert("Please change product for order!");return;}
	}

	document.forms.Step1of3.submit();
}


function Check_Step1_2(){
	document.getElementById("Step1_2of3").submit();
}

//STEP 2 CHECKS
function Check_Step2(){
	var firstname = document.forms.Step2of3.firstname.value;
	var lastname = document.forms.Step2of3.lastname.value;
	var addressline1 = document.forms.Step2of3.addressline1.value;
	var city = document.forms.Step2of3.city.value;
	var state = document.forms.Step2of3.state.value;
	var zipcode = document.forms.Step2of3.zipcode.value;
	var country = document.forms.Step2of3.country.value;
	var phonenumber = document.forms.Step2of3.phonenumber.value;
	var emailaddress = document.forms.Step2of3.emailaddress.value;
	var creditcardtype = document.forms.Step2of3.creditcardtype.value;
	var cardnumber = document.forms.Step2of3.cardnumber.value;
	var expiremonth = document.forms.Step2of3.expiremonth.value;
	var expireyear = document.forms.Step2of3.expireyear.value;
//	var securitycode = Step2of3.securitycode.value;
	var racerfirstname = document.forms.Step2of3.racerfirstname.value;
	var racerlastname = document.forms.Step2of3.racerlastname.value;
	var shippingfirstname = document.forms.Step2of3.firstname.value;
	var shippinglastname = document.forms.Step2of3.shippinglastname.value;
	var shippingaddressline1 = document.forms.Step2of3.shippingaddressline1.value;
	var shippingcity = document.forms.Step2of3.shippingcity.value;
	var shippingstate = document.forms.Step2of3.shippingstate.value;
	var shippingzipcode = document.forms.Step2of3.shippingzipcode.value;
	var shippingcountry = document.forms.Step2of3.shippingcountry.value;
	var shippingphonenumber = document.forms.Step2of3.shippingphonenumber.value;
	
	if ( firstname == "" ){
		alert( "Please fill in your First Name!");
		return;
	}	
	if ( lastname == "" ){
		alert( "Please fill in your Last Name!");
		return;
	}
	if ( addressline1 == "" ){
		alert( "Please fill in your Address!");
		return;
	}
	if ( city == "" ){
		alert( "Please fill in your City!");
		return;
	}

	// Super Hard Code commented
	/*if ( state == "" ){
		alert( "Please fill in your State!");
		return;
	}*/

	// Super Hard Code commented
	/*if ( zipcode == "" ){
		alert( "Please fill in your Zip Code!");
		return;
	}*/
	if ( country == "" ){
		alert( "Please fill in your Country!");
		return;
	}

	// Super Hard Code commented
	/*if ( phonenumber == "" ){
		alert( "Please fill in your Phone Number!");
		return;
	}*/

	if ( emailaddress == "" ){
		alert( "Please fill in your Email Address!");
		return;
	}
	var rx_email='^([\\w-~_]+\\.)*[\\w-~_]+@([\\w-_]+\\.){1,3}\\w+$';
		xx = new RegExp(rx_email);
		if (!xx.test(emailaddress)){
		    alert("email you've specified is invalid!");
			return;
		}
	if ( creditcardtype == "0" ){
		alert( "Please fill in your Credit Card Type!");
		return;
	}
	if ( cardnumber == "" ){
		alert( "Please fill in your Card Number!");
		return;
	}
	if ( expiremonth == "0" ){
		alert( "Please fill in your Expire Month!");
		return;
	}
	if ( expireyear == "0" ){
		alert( "Please fill in your Expire Year!");
		return;
	}
//	if ( securitycode == "" ){
//		alert( "Please fill in your Security Code!");
//		return;
//	}
	if ( racerfirstname == "" ){
		alert( "Please fill in your Racer First Name!");
		return;
	}
	if ( racerlastname == "" ){
		alert( "Please fill in your Racer Last Name!");
		return;
	}
	if ( shippingfirstname == "" ){
		alert( "Please fill in your Shipping First Name!");
		return;
	}	
	if ( shippinglastname == "" ){
		alert( "Please fill in your Shipping Last Name!");
		return;
	}
	if ( shippingaddressline1 == "" ){
		alert( "Please fill in your Shipping Address!");
		return;
	}
	if ( shippingcity == "" ){
		alert( "Please fill in your Shipping City!");
		return;
	}

	// Super Hard Code commented
	/*if ( shippingstate == "" ){
		alert( "Please fill in your Shipping State!");
		return;
	}*/

	// Super Hard Code commented
	/*if ( shippingzipcode == "" ){
		alert( "Please fill in your Shipping Zip Code!");
		return;
	}*/
	if ( shippingcountry == "" ){
		alert( "Please fill in your Shipping Country!");
		return;
	}

	// Super Hard Code commented
	/*if ( shippingphonenumber == "" ){
		alert( "Please fill in your Shipping Phone Number!");
		return;
	}*/
	document.forms.Step2of3.submit();
}
//SET SHIPPING INFO
function SetShippingInfo( state ){
	if ( state ){
		document.forms.Step2of3.shippingfirstname.value = document.forms.Step2of3.firstname.value;
		document.forms.Step2of3.shippinglastname.value = document.forms.Step2of3.lastname.value;
		document.forms.Step2of3.shippingaddressline1.value = document.forms.Step2of3.addressline1.value;
		document.forms.Step2of3.shippingaddressline2.value = document.forms.Step2of3.addressline2.value;
		document.forms.Step2of3.shippingcity.value = document.forms.Step2of3.city.value;
		document.forms.Step2of3.shippingstate.value = document.forms.Step2of3.state.value;
		document.forms.Step2of3.shippingzipcode.value = document.forms.Step2of3.zipcode.value;
		document.forms.Step2of3.shippingcountry.value = document.forms.Step2of3.country.value;
		document.forms.Step2of3.shippingphonenumber.value = document.forms.Step2of3.phonenumber.value;
	}
}
