<!--


// email

function checkEmail (strng, name) {
	var error="";
	if (strng == "") {
		error = "Please enter an email address.\n";
	}else {
		var normal = /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/;
		var validButRare = /^[a-z0-9,!#\$%&'\*\+\/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+\/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$/;
		if (normal.test(strng)) {
		}
		else if (validButRare.test(strng)) {
			//javascript to alert for questionable email
		}
		else {
			error = "Please enter a valid email address.\n";
		} 
	}
return error;
}  


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng, name) {
var error = "";
if (strng == "") {
   error = "Please complete " + name + ".\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = name + " contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = name + " is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng, name) {
var error = "";
if (strng == "") {
   error = "Please complete " + name + ".\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = name + " is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = name + " contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = name + " must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng, name) {
var error = "";
if (strng == "") {
   error = "Please complete " + name + ".\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = name + " is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = name + " contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng, name) {
var error = "";
  if (strng.length == 0) {
     error = "Please complete " + name + ".\n";
  }
return error;	  
}

// was textbox altered

function isDifferent(strng, name) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "Please do not alter " + name + ".\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(radioID, name) {
for (i=0; i<radioID.length; i++) {
   if (radioID[i].checked) {
      var checkvalue = radioID[i].value;
      break;
   }
}
var error = "";
   if (!(checkvalue)) {
       error = "Please select a " + name + ".\n";
    }
return error;    
}

// valid selector from dropdown list

function checkDropdown(choice, name) {
var error = "";
    if (choice == 0) {
    error = "Please choose an option from " + name + ".\n";
    }    
return error;
}    




// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.

function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}

function switchDiv(this_div, next_div){
  if (getStyleObject(this_div) && getStyleObject(next_div)) {
    changeObjectVisibility(this_div, "hidden");
    changeObjectVisibility(next_div, "visible");
  }
}

function nextpart1(this_div, next_div){
var why = "";
why += isEmpty(document.enroll.FirstName.value, "First Name");
why += isEmpty(document.enroll.LastName.value, "Last Name");
why += checkDropdown(document.enroll.Month.selectedIndex, "Month");
why += checkDropdown(document.enroll.Day.selectedIndex, "Day");
why += checkDropdown(document.enroll.Year.selectedIndex, "Year");
why += checkRadio(document.enroll.Gender, "Gender");
why += checkPhone(document.enroll.Phone.value, "Phone");
why += checkEmail(document.enroll.Email.value, "Email");
why += isEmpty(document.enroll.Street.value, "Street");
why += isEmpty(document.enroll.City.value, "City");
why += checkDropdown(document.enroll.State.selectedIndex, "State");
why += isEmpty(document.enroll.ZipCode.value, "Zip Code");

if (why == "") 
  {
    switchDiv(this_div, next_div);
  } else {
    alert(why);
  }
}

function nextpart2(this_div, next_div){
var why = "";
why += checkRadio(document.enroll.PlanType, "Plan Type");

if (why == "") 
  {
    switchDiv(this_div, next_div);
  } else {
    alert(why);
  }
}

function nextfamily(this_div, next_div){
var why = "";
why += isEmpty(document.enroll.Mem2.value, "at least one household memeber");

if (why == "") 
  {
    switchDiv(this_div, next_div);
  } else {
    alert(why);
  }
}

function nextpart3(this_div, next_div){
var why = "";
why += checkRadio(document.enroll.Rate, "Rate");

if (why == "") 
  {
    switchDiv(this_div, next_div);
  } else {
    alert(why);
  }
}

function nextpart4(this_div, next_div){
var why = "";
why += checkRadio(document.enroll.Frequency, "Frequency");

if (why == "") 
  {
    switchDiv(this_div, next_div);
  } else {
    alert(why);
  }
}

function nextpart5(this_div, next_div){
var why = "";
why += checkRadio(document.enroll.MethodOfPayment, "Method Of Payment");

if (why == "") 
  {
	var radioID = document.enroll.MethodOfPayment;
	for (i=0; i<radioID.length; i++) {
   if (radioID[i].checked) {
      var checkvalue = radioID[i].value;
      break;
   }
}
    changeObjectVisibility(this_div,"hidden");
	summary(checkvalue);
  } else {
    alert(why);
  }
}

function summary(selection){
	
	var name = document.getElementById(selection + "_name");
	name.innerHTML = document.enroll.FirstName.value + " " + document.enroll.Initial.value + " " + document.enroll.LastName.value;
	
	var birth = document.getElementById(selection + "_birth");
	birth.innerHTML = document.enroll.Month.value + " " + document.enroll.Day.value + ", " + document.enroll.Year.value;
	
	var phone = document.getElementById(selection + "_phone");
	phone.innerHTML = document.enroll.Phone.value;
	
	var altPhone = document.getElementById(selection + "_alt_phone");
	altPhone.innerHTML = document.enroll.AltPhone.value;
	
	var email = document.getElementById(selection + "_email");
	email.innerHTML = document.enroll.Email.value;
	
	var address = document.getElementById(selection + "_address");
	address.innerHTML = document.enroll.Street.value + "<br />" + document.enroll.City.value + ", " + document.enroll.State.value + " " + document.enroll.ZipCode.value;

	var quantityName = document.getElementsByName("PlanType");
	for(var k=0;k<quantityName.length;k++) {
          if(quantityName[k].checked){
            var quantity = quantityName[k].value;
			break;
          }
		}
	
	var frequencyName = document.getElementsByName("Frequency");
	for(var k=0;k<frequencyName.length;k++) {
          if(frequencyName[k].checked){
            var frequency = frequencyName[k].value;
			break;
          }
		  else {
			var frequency = "monthly";
		}
	}
		
	var rateName = document.getElementsByName("Rate");
	for(var k=0;k<rateName.length;k++) {
          if(rateName[k].checked){
            var rate = rateName[k].value;
			break;
          }
		}
	
	var rateArray = calculateRate(quantity, rate, frequency);
	var memberFee = rateArray[0];
	var total = rateArray[1];
	
	var memberFeeForm = document.getElementById(selection + "_member_fee");
	memberFeeForm.innerHTML = memberFee;
	
	if(selection == "mCC" || selection == "B") {
	var memberFeeForm2 = document.getElementById(selection + "_member_fee2");
	memberFeeForm2.innerHTML = memberFee;
	}
	
	var totalForm = document.getElementById(selection + "_total");
	totalForm.innerHTML = total;
	
  changeObjectVisibility(selection,"visible");
  
}


function changeSwitch(this_div, elementID, changeTo) {
                document.getElementById(elementID).onclick = new Function("next" + this_div + "('" + this_div + "', '" + changeTo + "');");
		}

function calculateRate(quantity, rate, frequency){
	if (quantity == "single"){
		if (rate == "none"){
			if (frequency == "monthly"){
				return["$9.95","$39.90"]
			}
			else {
				return["$119.40","$139.40"]
			}
		}
		else if (rate == "senior"){
			if (frequency == "monthly"){
				return["$8.95","$37.90"]
			}
			else {
				return["$107.40","$127.40"]
			}
		}
		else if (rate == "group"){
			return["$7.95","$27.95"]
		}
		else /*LCC Rate*/{
			if (frequency == "monthly"){
				return["$6.95","$33.90"]
			}
			else {
				return["$83.40","$103.40"]
			}
		}
	}
	else{
		if (rate == "none"){
			if (frequency == "monthly"){
				return["$16.95","$53.90"]
			}
			else {
				return["$203.40","$223.40"]
			}
		}
		else if (rate == "senior"){
			if (frequency == "monthly"){
				return["$15.95","$51.90"]
			}
			else {
				return["$191.40","$211.40"]
			}
		}
		else if (rate == "group"){
			return["$11.95","$31.95"]
		}
		else /*LCC Rate*/{
			if (frequency == "monthly"){
				return["$10.95","$41.90"]
			}
			else {
				return["$131.40","$151.40"]
			}
		}
	}
}
		
// -->