
//Form Validation for Registration


//First check for all required fields

function validate_me(){



form_name = "special_rates"
v = eval("document." + form_name);

var alert_msg = "";var readable_name, field_name;

//Validate Fields filled out
for (loop=0;loop<=v.elements.length-1;loop++)
{
if (v.elements[loop].type == "text")
{
if (v.elements[loop].value == "")
{
field_name = v.elements[loop].name;
readable_name = (field_name).toUpperCase();
readable_name = readable_name.replace(/_/g,' ');
alert_msg = alert_msg + readable_name + "\n"
}
}
//next squiggle end loop
}

//Verify Card Data
warning="";
if (v.which_card_type.selectedIndex == 0)
{warning = warning + "You must select the card type.\n"}
if (v.card_num.value.length <= 12)
{warning = warning + "You must enter a valid credit card number.\n"}
if (v.month.selectedIndex == 0)
{warning = warning + "You must select an expiry month.\n"}
if (v.year.selectedIndex == 0)
{warning = warning + "You must select an expiry year.\n"}
if (v.billing_zip.value.length < 5)
{warning = warning + "You must enter a 5 digit zip code.\n"}

var first_digit = (v.card_num.value).substring(0,1);

if (first_digit == "4"){v.which_card_type.selectedIndex = 1;}
if (first_digit == "5"){v.which_card_type.selectedIndex = 2;}
if (first_digit == "3"){v.which_card_type.selectedIndex = 3;}



var card_month = v.month.selectedIndex;
if (card_month < 10){card_month = "0" + card_month;}
v.card_exp.value = card_month + "-" + v.year[v.year.selectedIndex].text;
v.card_type.value = v.which_card_type[v.which_card_type.selectedIndex].text;

//Verify Quantity
if (v.quantity.selectedIndex == 0)
{warning = warning + "\nYou must select a quantity.\n"}

//Set Quantity and Price
var pricing = new Array(0,400,165,85);
v.quantity_line.value = v.quantity[v.quantity.selectedIndex].text;
v.price.value = pricing[v.quantity.selectedIndex];

alert_msg = alert_msg + warning;

if (alert_msg.length != 0)
{
alert_msg = "You need to provide the following\ninformation to register:\n\n" + alert_msg;
//alert(alert_msg);
}

//Set Card Expiry date

//Set Quantity and dollar value

//Uppercase License Number
v.license.value = (v.license.value).toUpperCase();

//alert("CARD TYPE=" + v.card_type.value);

 
//Message if address state is different from course approval state?
// - do as redline in confirm_page
 
//Create username in PHP

if (alert_msg.length == 0)
{
v.submit()
}
else
{
alert(alert_msg);
}

//next squiigle end function
}








