//General functions to control form fields

function groupControl(targetFieldId, sourceFieldId){
	//get the text field element - passed as targetFieldId
	var textElement = document.getElementById(targetFieldId);
	//get the source field element
	var selectElement = document.getElementById(sourceFieldId);
	
	if(selectElement.selectedIndex >= 1){
		textElement.readOnly = false;
	}else{
		textElement.readOnly = true;
		//textElement.value = '';
	}
}

function checkFields(){
	//setup valid marker
	var valid = true;
	//setup message to be returned
	var msg = "Please correct the following form errors. \r\n\r\n";
	//make sure all the date drop downs have been selected
	if(document.reservation.month.value =='' || 
		document.reservation.day.value=='' || 
		document.reservation.year.value==''){
		msg += "A reservation date is required.\r\n";
		valid = false;
	}else{
		var reqDate = new Date(document.reservation.year.value, document.reservation.month.value - 1, document.reservation.day.value);
		var curDate = new Date();
		if(reqDate < curDate){
			msg += 'Date Error: Please select a future date \r\n';
			valid = false;
		}
	}
	if(document.reservation.numDays.value==''){
		msg += "Indicate the number of days this reservation is for.\r\n";
		valid = false;
	}
	
	var radioGroup = document.getElementsByName('pickupTime');
	if(!radioGroup[0].checked && !radioGroup[1].checked){
		msg += "Indicate the time you will be picking up your reservation.\r\n";
		valid = false;
	}
	
	if(document.reservation.numPeople.value > 1 && document.reservation.groupName.value == ''){
		msg += "Reservations for more than one person require a 'Group Name'.\r\n";
		valid = false;
	}
	if(!valid){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function checkPaymentInfo(){
	//setup valid marker
	var valid = true;
	//setup message to be returned
	var msg = "Please correct the following form erros. \r\n\r\n";
	//name on card cannot be blank
	if(document.cardInfo.nameOnCard.value == ''){
		msg += "Please input name as it appears on card.\r\n";
		valid = false;
	}
	//cc number must be 16 digits no spaces
	if(document.cardInfo.cardNumber.value == ''){
		msg += "Please input your card number.\r\n";
		valid = false;
	}
	//cvv number must not be blank
	if(document.cardInfo.cvvNum.value == ''){
		msg += "Please enter the CVV number from your card.\r\n";
		valid = false;	
	}
	//exp. data must not be blank
	if(document.cardInfo.expDate.value == ''){
		msg += "Please enter the expiration date on your card.\r\n";
		valid = false;
	}
	
	if(!valid){
		alert(msg);
		return false;
	}else{
		return true;
	}
	
	
	
	
	
}