//Radio Button Code
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function
//End Radio Code

var intWrong,strAlert;
function checkForm(myForm) {
	strAlert = "The following field(s) are required:\n";
	intWrong=0;
//Check Radio Button
//var radioButtonArr = getSelectedRadio(document.myForm.bln_packagetype);
//if (radioButtonArr.length == 0) {
//		intWrong++;
//		strAlert=strAlert+"\n * Select a Membership Plan";
 //alert("No check boxes selected");
// }
//End Check Radio Button
	if (myForm.user_name.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Username (5-20 characters)";
	} else {
		if (myForm.user_name.value.length<5) {
			intWrong++;
			strAlert=strAlert+"\n * Username must be 5+ characters";
		}
		if (myForm.user_name.value.length>20) {
			intWrong++;
			strAlert=strAlert+"\n * Username must be <20 characters";
		}
		intSpecChar=0;
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
		for (var i = 0; i < myForm.user_name.value.length; i++) {
			if (iChars.indexOf(myForm.user_name.value.charAt(i)) != -1) {
				intWrong++;
				intSpecChar=1;
			}
		}
		if (intSpecChar==1) {
			strAlert=strAlert+"\n * Username must be letters or numbers\n  * No spaces or special characters in username";
		}
		myForm.user_name.value = myForm.user_name.value.toLowerCase();
	}
	if (myForm.user_password.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Password (5-15 characters)";
	} else {
		if (myForm.user_password.value.length<5) {
			intWrong++;
			strAlert=strAlert+"\n * Password must be 5+ characters";
		}
		if (myForm.user_password.value.length>15) {
			intWrong++;
			strAlert=strAlert+"\n * Password must be <15 characters";
		}
		if (myForm.user_password.value!=myForm.user_password2.value) {
			intWrong++;
			strAlert=strAlert+"\n * Passwords Must Match";
		}
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.user_email.value)){
		//nothing
	} else {
		strAlert = strAlert + "\n * Valid Email Address";
		intWrong++;
	}
	if (myForm.user_fname.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * First Name";
	} else {
		intSpecChar=0;
		var iChars = "!@#$%^*=-\\\;/|\0123456789:?";
		for (var i = 0; i < myForm.user_fname.value.length; i++) {
			if (iChars.indexOf(myForm.user_fname.value.charAt(i)) != -1) {
				intWrong++;
				intSpecChar=1;
			}
		}
		if (intSpecChar==1) {
			strAlert=strAlert+"\n * No special characters in first name";
		}
	}
	if (myForm.user_lname.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Last Name";
	} else {
		intSpecChar=0;
		var iChars = "!@#$%^*=-\\\;/|\0123456789:?";
		for (var i = 0; i < myForm.user_lname.value.length; i++) {
			if (iChars.indexOf(myForm.user_lname.value.charAt(i)) != -1) {
				intWrong++;
				intSpecChar=1;
			}
		}
		if (intSpecChar==1) {
			strAlert=strAlert+"\n * No special characters in last name";
		}
	}
	if (myForm.user_addr1.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Address, Line 1";
	}
	if (myForm.user_city.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * City";
	}
    if (myForm.state_uid.selectedIndex == "" )
    {
		intWrong++;
		strAlert=strAlert+"\n * Select A State";
    }
	if (myForm.user_zip.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Postal Code";
	}
    //if (myForm.country_uid.selectedIndex == "" )
    //{
	//	intWrong++;
	//	strAlert=strAlert+"\n * Select A Country";
    //}
	if (myForm.user_phone.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Telephone Number";
	}
	if (myForm.user_age.value=="") {
		intWrong++;
		strAlert=strAlert+"\n * Age";
	}
 if (!myForm.IAGREE.checked)
 {
	intWrong++;
	strAlert=strAlert+"\n * You must agree to the terms of use before you can continue.";
   //alert("You must agree to the terms of use before you can continue.");
//theForm.IAGREE.focus();
   //return (false);
 }
  if (!myForm.OVER18.checked)
 {
	intWrong++;
	strAlert=strAlert+"\n * You must certify that you are over the age of 18 before you can continue.";
   //alert("You must agree to the terms of use before you can continue.");
//theForm.IAGREE.focus();
   //return (false);
 }
	if (intWrong>0) {
		alert(strAlert);
		return false;
	} else {
		return true;
	}
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}