var checkout_tos_required = false;
var checkout_validation_required = false;

function getBillingInfoForm(success_target_arg,err_target_arg,cancel_target_arg) {

	document.getElementById("reg_billing_info_form").innerHTML = "Loading billing info form...";
	
	contentString = "";
	
	contentString += "<form name=\"submit_billing_form\" action=\"/registration2/process_checkout.php\" method=\"post\" onsubmit=\"return validateBillingInfoForm()\">\n";
	contentString += "<div id=\"reg_billing_info_fields\" style=\"display: none;\">\n";
	contentString += "<strong>Billing Information:</strong><br><br>Please complete all fields below:<br><br>";
	contentString += "<table width=100% cellpadding=2>\n";
	contentString += "<tr>\n";
	contentString += "<td>Cardholder First Name:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_first_name\" name=\"reg_billing_first_name\"><\/td>\n";
	contentString += "<td>Cardholder Last Name:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_last_name\" name=\"reg_billing_last_name\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Cardholder Address:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_address\" name=\"reg_billing_address\"><\/td>\n";
	contentString += "<td>City:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_city\" name=\"reg_billing_city\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Country:<\/td>\n";
	contentString += "<td><select id=\"reg_billing_country\"><option value=\"United States\">United States<\/option><option value=\"\">Other<\/option><\/select><\/td>\n";
	contentString += "<td>State/Province:<\/td>\n";
	contentString += "<td><select id=\"reg_billing_state\" name=\"reg_billing_state\">";
	
	stateList = "Select...,Alabama,Alaska,Alberta,Arizona,Arkansas,British Columbia,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Manitoba,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Bruswick,New Hampshire,New Jersey,New Mexico,New York,Newfoundland,North Carolina,North Dakota,Northwest Territories,Nova Scotia,Nunavut,Ohio,Oklahoma,Ontario,Oregon,Pennsylvania,Prince Edward Island,Puerto Rico,Quebec,Rhode Island,Saskatchewan,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Virgin Islands,Washington,West Virginia,Wisconsin,Wyoming,Yukon";
	stateArray = stateList.split(",");
	for (x = 0; x < stateArray.length; x++) {
		contentString += "<option value=\""+stateArray[x]+"\">"+stateArray[x]+"<\/option>\n";
	}	
	contentString += "<option value=\"\">Other/None</option>\n";
	contentString += "<\/select>";
	
	contentString += "<\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Zip Code:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_zip_code\" name=\"reg_billing_zip_code\"><\/td>\n";
	contentString += "<td><\/td>";
	contentString += "<td><\/td>";
	contentString += "<\/tr>\n";
	contentString += "<tr><td colspan=4>&nbsp;<\/td><\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Card Number:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_card_number\" name=\"reg_billing_card_number\"><\/td>\n";
	contentString += "<td>CVV2 Code: (from back of card)<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_cvv2_code\" name=\"reg_billing_cvv2_code\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Expiration Date:<\/td>\n";
	contentString += "<td colspan=3><select id=\"reg_billing_exp_month\" name=\"reg_billing_exp_month\">";
	contentString += "<option value=\"1\">1<\/option>";
	contentString += "<option value=\"2\">2<\/option>";
	contentString += "<option value=\"3\">3<\/option>";
	contentString += "<option value=\"4\">4<\/option>";
	contentString += "<option value=\"5\">5<\/option>";
	contentString += "<option value=\"6\">6<\/option>";
	contentString += "<option value=\"7\">7<\/option>";
	contentString += "<option value=\"8\">8<\/option>";
	contentString += "<option value=\"9\">9<\/option>";
	contentString += "<option value=\"10\">10<\/option>";
	contentString += "<option value=\"11\">11<\/option>";
	contentString += "<option value=\"12\">12<\/option>";
	contentString += "<\/select><select id=\"reg_billing_exp_year\" name=\"reg_billing_exp_year\">";
	
	var todaysDate = new Date();
	currentYear = todaysDate.getFullYear();
	for (x = 0; x < 10; x++) {
		contentString += "<option value=\""+(currentYear+x)+"\">"+(currentYear+x)+"<\/option>";
	}
	
	contentString += "<\/select>";
	
	contentString += "<\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<\/table>";

	contentString += "<br>By clicking \"Submit My Order\", you agree that your credit card will be charged the total listed above.  The charge on your credit card will appear as \"SDI Camps and Races\".\n";
	
	contentString += "<\/div>\n";
	
	contentString += "<div align=right id=\"reg_order_submit_buttons\"><br><input type=button value=\"Cancel\" onclick=\"document.location.href='"+cancel_target_arg+"'\"><input id=\"reg_form_submit_button\" type=button value=\"Submit My Order!\" onclick=\"this.disabled=true;validateBillingInfoForm();\"><\/div>\n";

	contentString += "<input type=hidden name=\"success_target\" value=\""+success_target_arg+"\">\n";
	contentString += "<input type=hidden name=\"err_target\" value=\""+err_target_arg+"\">\n";
	
	contentString += "<input type=hidden id=\"reg_accept_partial\" name=\"reg_accept_partial\" value=\"no\">\n";
	contentString += "<input type=hidden id=\"reg_min_payment\" name=\"reg_min_payment\" value=\"\">\n";
	contentString += "<input type=hidden id=\"reg_payment_amount\" name=\"reg_payment_amount\" value=\"\">\n";
	
	contentString += "<\/form>";
	
	document.getElementById("reg_billing_info_form").innerHTML = contentString;

}

function getCorduroBillingForm(total_amount) {

	document.getElementById("reg_billing_info_form").innerHTML = "Loading billing info form...";
	
	contentString = "";
	pathArray = document.location.href.split( '/' );
	
	contentString += "<iframe allowTransparency=\"true\" name=\"corduropay\" ";
	contentString += "src=\"https://payment.corduro.com/corduro.payment/Content/authenticate.aspx?";
	contentString += "ClientNumber=1438bbc6a5fee7f";
	contentString += "&ProcessType=card";
	contentString += "&MID=F732158522E92C9F";
	contentString += "&RegKey=65b4b7fe83106319";
	contentString += "&GatewayKey=CO";
	contentString += "&amount="+total_amount;
	contentString += "&amountshown=false";
	contentString += "&HTTP_REFERRER="+document.location.href;
	contentString += "&ClientURL="+document.location.href;
	contentString += "&postbackurl="+pathArray[0]+"//"+pathArray[2]+"/registration2/process_corduro_wait.php\"";
	contentString += " frameborder=\"0\" style=\"BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; WIDTH: 500px; margin-left:15px; HEIGHT: 885px; BORDER-TOP: medium none; BORDER-RIGHT: medium none\" id=\"corduropay\" >";
	contentString += "</iframe>";
	
	document.getElementById("reg_billing_info_form").innerHTML = contentString;


}

function validateBillingInfoForm() {

	if (checkout_validation_required) {

		first_name_val = document.getElementById("reg_billing_first_name").value;
		last_name_val = document.getElementById("reg_billing_last_name").value;
		address_val = document.getElementById("reg_billing_address").value;
		city_val = document.getElementById("reg_billing_city").value;
		zip_val = document.getElementById("reg_billing_zip_code").value;
		card_number_val = document.getElementById("reg_billing_card_number").value;
		cvv2_val = document.getElementById("reg_billing_cvv2_code").value;
		
		err_msg_object = document.getElementById("err_msg");
				
		allow_partial = document.getElementById("reg_accept_partial").value;
		if (allow_partial == "yes") {
			min_payment = parseFloat(document.getElementById("reg_min_payment").value);
			payment_amount = parseFloat(document.getElementById("reg_partial_payment_entry").value);
			if (payment_amount < min_payment) {
				err_msg_object.innerHTML = "You must pay at least the required minimum amount.";
				document.getElementById("reg_form_submit_button").disabled = false;
				return false;
			} else {
				document.getElementById("reg_payment_amount").value = payment_amount;
				
				if (min_payment == 0) {
					document.forms['submit_billing_form'].submit();
					return true;				
				}
				
			}
		
		}
		
		if (first_name_val == "") {
			err_msg_object.innerHTML = "You must enter the cardholder first name.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (last_name_val == "") {
			err_msg_object.innerHTML = "You must enter the cardholder last name.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (address_val == "") {
			err_msg_object.innerHTML = "You must enter the cardholder address.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (city_val == "") {
			err_msg_object.innerHTML = "You must enter the cardholder city.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (zip_val == "") {
			err_msg_object.innerHTML = "You must enter the cardholder zip code.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (card_number_val == "") {
			err_msg_object.innerHTML = "You must enter a credit card number.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		if (cvv2_val == "") {
			err_msg_object.innerHTML = "You must enter the cvv2 code from the back of your card.";
			document.getElementById("reg_form_submit_button").disabled = false;
			return false;
		}
		
		if (checkout_tos_required) {
		
			if (document.getElementById("reg_billing_tos_checkbox").checked == false) {
				err_msg_object.innerHTML = "You must agree to the terms.";
				document.getElementById("reg_form_submit_button").disabled = false;
				return false;	
			}
		
		}

	}
	
	document.forms['submit_billing_form'].submit();
	return true;

}

function getSimpleBillingInfoForm(container_obj_id) {

	document.getElementById(container_obj_id).innerHTML = "Loading billing info form...";
	
	contentString = "";
		
	contentString += "<strong>Billing Information:</strong><br><br>Please complete all fields below:<br><br>";
	contentString += "<table width=100% cellpadding=2>\n";
	contentString += "<tr>\n";
	contentString += "<td>Cardholder First Name:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_first_name\" name=\"reg_billing_first_name\"><\/td>\n";
	contentString += "<td>Cardholder Last Name:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_last_name\" name=\"reg_billing_last_name\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Cardholder Address:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_address\" name=\"reg_billing_address\"><\/td>\n";
	contentString += "<td>City:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_city\" name=\"reg_billing_city\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Country:<\/td>\n";
	contentString += "<td><select id=\"reg_billing_country\"><option value=\"United States\">United States<\/option><option value=\"\">Other<\/option><\/select><\/td>\n";
	contentString += "<td>State/Province:<\/td>\n";
	contentString += "<td><select id=\"reg_billing_state\" name=\"reg_billing_state\">";
	
	stateList = "Select...,Alabama,Alaska,Alberta,Arizona,Arkansas,British Columbia,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Manitoba,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Bruswick,New Hampshire,New Jersey,New Mexico,New York,Newfoundland,North Carolina,North Dakota,Northwest Territories,Nova Scotia,Nunavut,Ohio,Oklahoma,Ontario,Oregon,Pennsylvania,Prince Edward Island,Puerto Rico,Quebec,Rhode Island,Saskatchewan,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Virgin Islands,Washington,West Virginia,Wisconsin,Wyoming,Yukon";
	stateArray = stateList.split(",");
	for (x = 0; x < stateArray.length; x++) {
		contentString += "<option value=\""+stateArray[x]+"\">"+stateArray[x]+"<\/option>\n";
	}	
	contentString += "<option value=\"\">Other/None</option>\n";
	contentString += "<\/select>";
	
	contentString += "<\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Zip Code:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_zip_code\" name=\"reg_billing_zip_code\"><\/td>\n";
	contentString += "<td><\/td>";
	contentString += "<td><\/td>";
	contentString += "<\/tr>\n";
	contentString += "<tr><td colspan=4>&nbsp;<\/td><\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Card Number:<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_card_number\" name=\"reg_billing_card_number\"><\/td>\n";
	contentString += "<td>CVV2 Code: (from back of card)<\/td>\n";
	contentString += "<td><input type=text id=\"reg_billing_cvv2_code\" name=\"reg_billing_cvv2_code\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Expiration Date:<\/td>\n";
	contentString += "<td colspan=3><select id=\"reg_billing_exp_month\" name=\"reg_billing_exp_month\">";
	contentString += "<option value=\"1\">1<\/option>";
	contentString += "<option value=\"2\">2<\/option>";
	contentString += "<option value=\"3\">3<\/option>";
	contentString += "<option value=\"4\">4<\/option>";
	contentString += "<option value=\"5\">5<\/option>";
	contentString += "<option value=\"6\">6<\/option>";
	contentString += "<option value=\"7\">7<\/option>";
	contentString += "<option value=\"8\">8<\/option>";
	contentString += "<option value=\"9\">9<\/option>";
	contentString += "<option value=\"10\">10<\/option>";
	contentString += "<option value=\"11\">11<\/option>";
	contentString += "<option value=\"12\">12<\/option>";
	contentString += "<\/select><select id=\"reg_billing_exp_year\" name=\"reg_billing_exp_year\">";
	
	var todaysDate = new Date();
	currentYear = todaysDate.getFullYear();
	for (x = 0; x < 10; x++) {
		contentString += "<option value=\""+(currentYear+x)+"\">"+(currentYear+x)+"<\/option>";
	}
	
	contentString += "<\/select>";
	
	contentString += "<\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<\/table>";

	//contentString += "<br>By clicking \"Submit My Order\", you agree that the credit card will be charged the amount entered below.  The charge on your credit card will appear as \"SDI Corporate Group\".\n";
	
	contentString += "<br>\n";
	contentString += "<div align=right style=\"padding-bottom: 5px;\">";
	contentString += "Amount: $<input type=text style=\"width: 100px;\" id=\"payment_amount\" name=\"payment_amount\">";
	contentString += "<\/div>\n";
	
	document.getElementById(container_obj_id).innerHTML = contentString;


}

function getSimpleCheckForm(container_obj_id) {

	document.getElementById(container_obj_id).innerHTML = "Loading billing info form...";
	
	contentString = "";
		
	contentString += "<strong>Billing Information:</strong><br><br>Please complete all fields below:<br><br>";
	contentString += "<table width=100% cellpadding=2>\n";
	contentString += "<tr>\n";
	contentString += "<td>Check Writer First Name:<\/td>\n";
	contentString += "<td><input type=text id=\"check_first_name\" name=\"check_first_name\"><\/td>\n";
	contentString += "<td>Check Writer Last Name:<\/td>\n";
	contentString += "<td><input type=text id=\"check_last_name\" name=\"check_last_name\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Check Number:<\/td>\n";
	contentString += "<td><input type=text id=\"check_number\" name=\"check_number\"><\/td>\n";
	contentString += "<td><\/td>\n";
	contentString += "<td><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<\/table>";
	contentString += "<br>\n";
	contentString += "<div align=right style=\"padding-bottom: 5px;\">";
	contentString += "Check Amount: $<input type=text style=\"width: 100px;\" id=\"payment_amount\" name=\"payment_amount\">";
	contentString += "<\/div>\n";

	document.getElementById(container_obj_id).innerHTML = contentString;

}

function getSimpleMoneyOrderForm(container_obj_id) {

	document.getElementById(container_obj_id).innerHTML = "Loading billing info form...";
	
	contentString = "";
		
	contentString += "<strong>Billing Information:</strong><br><br>Please complete all fields below:<br><br>";
	contentString += "<table width=100% cellpadding=2>\n";
	contentString += "<tr>\n";
	contentString += "<td>Payer First Name:<\/td>\n";
	contentString += "<td><input type=text id=\"mo_first_name\" name=\"mo_first_name\"><\/td>\n";
	contentString += "<td>Payer Last Name:<\/td>\n";
	contentString += "<td><input type=text id=\"mo_last_name\" name=\"mo_last_name\"><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<tr>\n";
	contentString += "<td>Money Order Number:<\/td>\n";
	contentString += "<td><input type=text id=\"mo_number\" name=\"mo_number\"><\/td>\n";
	contentString += "<td><\/td>\n";
	contentString += "<td><\/td>\n";
	contentString += "<\/tr>\n";
	contentString += "<\/table>";
	contentString += "<br>\n";
	contentString += "<div align=right style=\"padding-bottom: 5px;\">";
	contentString += "Money Order Amount: $<input type=text style=\"width: 100px;\" id=\"payment_amount\" name=\"payment_amount\">";
	contentString += "<\/div>\n";

	document.getElementById(container_obj_id).innerHTML = contentString;

}

function getSimpleCashForm(container_obj_id) {

	document.getElementById(container_obj_id).innerHTML = "Loading billing info form...";
	
	contentString = "";
		
	contentString += "<strong>Billing Information:</strong><br><br>Please complete all fields below:<br><br>";
	contentString += "<br>\n";
	contentString += "<div align=right style=\"padding-bottom: 5px;\">";
	contentString += "Cash Amount: $<input type=text style=\"width: 100px;\" id=\"payment_amount\" name=\"payment_amount\">";
	contentString += "<\/div>\n";

	document.getElementById(container_obj_id).innerHTML = contentString;

}

function setTosRequired() {
	checkout_tos_required = true;
}


