// JavaScript Document
function attemptPrint() {
	if( validateSideForm() ) {
		/*var inf = document.getElementById('content1').innerHTML;
		win = window.open("", 'popup', 'toolbar = yes, menubar = yes, status = no, scrollbars = 1');
		win.document.write('<style type="text/css">* {font-size:10pt;} h1 {font-size:12pt;}</style>'+inf);
		win.stop();*/
		window.print(); 
	}
}

function validateSideForm() {
	var why = "";
	var elem;
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	
	elem = document.theForm.membershipNumber;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your membership number.\n";
		}
	}
	
	elem = document.theForm.firstName;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your first name.\n";
		}
	}
	
	elem = document.theForm.lastName;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your last name.\n";
		}
	}
	
	elem = document.theForm.homephone;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your home phone number.\n";
		}
	}
	
	elem = document.theForm.workphone;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your work phone number.\n";
		}
	}
	
	elem = document.theForm.address;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your address.\n";
		}
	}
	
	elem = document.theForm.city;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your city.\n";
		}
	}
	
	elem = document.theForm.state;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your state.\n";
		}
	}
	
	elem = document.theForm.zip;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your zip code.\n";
		}
	}
	
	elem = document.theForm.previousaddress;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your previous address.\n";
		}
	}
	
	elem = document.theForm.previouscity;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your previous city.\n";
		}
	}
	
	elem = document.theForm.previousstate;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your previous state.\n";
		}
	}
	
	elem = document.theForm.previouszip;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your previous zip code.\n";
		}
	}
	
	elem = document.theForm.clubLocation;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your club location.\n";
		}
	}
	
	elem = document.theForm.dateOfIllnessInjury;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your date of illness/injury.\n";
		}
	}
	
	elem = document.theForm.illnessImpedesAbility;
	if (elem) {
		if (elem.value=='') {
			why += "Please describe how illness or injury impedes your ability to use the health club.\n";
		}
	}
	
	elem = document.theForm.estimatedDurationConvalescence;
	if (elem) {
		var one_checked = false;
		for(var i = 0; i < elem.length; i++) {
			if(elem[i].checked) {
				one_checked = true;
				break;
			}
		}
		if( !one_checked ) {
			why += "Please enter your estimated duration of convalescence.\n";
		}
	}

	elem = document.theForm.accountType;
	if (elem) {
		var one_checked = false;
		for(var i = 0; i < elem.length; i++) {
			if(elem[i].checked) {
				one_checked = true;
				break;
			}
		}
		if( !one_checked ) {
			why += "Please enter your account type.\n";
		}
		else {
			if(elem[0].checked) {
				elem = document.theForm.creditCard;
				var one_checked = false;
				for(var i = 0; i < elem.length; i++) {
					if(elem[i].checked) {
						one_checked = true;
						break;
					}
				}
				if (!one_checked) {
					why += "Please select your credit card type.\n";
				}
				elem = document.theForm.creditCardAccountNumber;
				if (elem) {
					if (elem.value=='') {
						why += "Please enter your credit card account number.\n";
					}
				}
				elem = document.theForm.creditCardExpDate;
				if (elem) {
					if (elem.value=='') {
						why += "Please enter your expiration date.\n";
					}
				}
			}
			else {
				elem = document.theForm.achNumber;
				if (elem) {
					if (elem.value=='') {
						why += "Please enter your account number.\n";
					}
				}
				elem = document.theForm.routingNumber;
				if (elem) {
					if (elem.value=='') {
						why += "Please enter your routing number.\n";
					}
				}				
			}
		}
	}
	
	elem = document.theForm.authorization;
	if (elem) {
		if (elem.value=='') {
			why += "Please enter your name in the authorization field.\n";
		}
	}
	
	
	if (why != "") {
		alert('There are problems with your request:\n\n'+why);
		return false;
	}
	else {
		return true;
	}	
}