
function prefill(id){
	if (id.style.color == '#cccccc' || id.style.color == ''){
		id.value = '';
		id.style.color='#000';
	}
}
function attendees(type,selector){
	num = parseInt(selector[selector.selectedIndex].value);
	for (i=1; i<=10; i++){
		if (i <= num){
			$(type+''+i).style.display = 'inline';
		} else {
			$(type+''+i).style.display = 'none';
		}
	}
	// calc fees
	calcfees();
}

function calcfees(){

	var tasteEach = 325;
	var mealAdultEach = 350;
	var mealChildEach = 80;
	var lodgeAdultEach = 275;
	var lodgeChildeEach = 120;
	var campFeeTotal = 30;

	var lodgfee = 0;
	var conffee = 0;
	var mealfee = 0;
	var campfee = 0;
	var totfee = 0;
	
	conffee = conffee + parseInt($('tasters')[$('tasters').selectedIndex].value) * tasteEach;

	mealfee = mealfee + (parseInt($('tasters')[$('tasters').selectedIndex].value) * mealAdultEach);
	mealfee = mealfee + (parseInt($('adults')[$('adults').selectedIndex].value) * mealAdultEach);
	mealfee = mealfee + (parseInt($('children')[$('children').selectedIndex].value) * mealChildEach);

	for (i=1; i<=$('tasters').selectedIndex; i++){
		if($('registration')['taster_accommodations'+i].selectedIndex == 1 || $('registration')['taster_accommodations'+i].selectedIndex == 2){
			lodgfee = lodgfee + lodgeAdultEach;
		}else if ($('registration')['taster_accommodations'+i].selectedIndex == 3){
			campfee = campFeeTotal;
		}
	}
	
	for (i=1; i<=$('adults').selectedIndex; i++){
		if($('registration')['adult_accommodations'+i].selectedIndex == 1 || $('registration')['adult_accommodations'+i].selectedIndex == 2){
			lodgfee = lodgfee + lodgeAdultEach;
		}else if ($('registration')['adult_accommodations'+i].selectedIndex == 3){
			campfee = campFeeTotal;
		}
	}
	
	for (i=1; i<=$('children').selectedIndex; i++){
		if($('registration')['child_accommodations'+i].selectedIndex == 1 || $('registration')['child_accommodations'+i].selectedIndex == 2){
			lodgfee = lodgfee + lodgeChildeEach;
		}else if ($('registration')['child_accommodations'+i].selectedIndex == 3){
			campfee = campFeeTotal;
		}
	}
	
	totfee = campfee + mealfee + conffee + lodgfee;
	
	$('conffee').innerHTML = '$'+conffee+'.00';
	$('mealfee').innerHTML = '$'+mealfee+'.00';
	$('lodgfee').innerHTML = '$'+lodgfee+'.00';
	$('campfee').innerHTML = '$'+campfee+'.00';
	$('totfee').innerHTML = '$'+totfee+'.00';
}

function addcontact(id){
	if(! id.old && id.value != ''){ // new record and not blank
	
		// contact
		var newobj = document.createElement("option"); // create new option
		newobj.setAttribute('value',id.value);
		newobj.setAttribute('style',id.value);
		newobj.innerHTML = id.value;
		$('primarycontact').appendChild(newobj); // append option to select box
		
		id.old = id.value; // store value
	} else if (id.old != '' && id.old != id.value){ // edit record
		for (i=0; i<=$('primarycontact').length; i++){ // loop over select box to edit selection
			if ($('primarycontact')[i].value == id.old){ // find matching value
				if (id.value != ''){ // not blank, edit
					$('primarycontact')[i].value = id.value; // edit value
					$('primarycontact')[i].innerHTML = id.value; // edit value
					id.old = id.value;
					i = $('primarycontact').length;
				} else { // blank, delete
					$('primarycontact').removeChild($('primarycontact')[i]); // delete child
					id.old = null;
					i = $('primarycontact').length;
				}
			}
		}
	}
}

function validate(theForm){
	if(theForm.winery.value == ''){
		alert('Please enter the name of your winery');
		theForm.winery.focus();
		return false;
	} else if(theForm.street.value == '') {
		alert('Please enter your street address');
		theForm.street.focus();
		return false;
	} else if(theForm.city.value == '') {
		alert('Please enter your city');
		theForm.city.focus();
		return false;
	} else if(theForm.zip.value == '') {
		alert('Please enter your postal code');
		theForm.zip.focus();
		return false;
	} else if(theForm.country.value == '') {
		alert('Please enter your country');
		theForm.country.focus();
		return false;
	} else if(theForm.tasters.selectedIndex == 0) {
		alert('You must have at least one taster');
		theForm.tasters.focus();
		return false;
	}
		
	for (i=1; i <= theForm.tasters.selectedIndex; i++){
		if(theForm['taster_name'+i].value == ''){
			alert('You must enter the names of all tasters');
			theForm['taster_name'+i].focus();
			return false;
		} else if (theForm['taster_accommodations'+i].selectedIndex == 0){
			theForm['taster_accommodations'+i].focus();
			alert('You must select accommodations for all tasters');
			return false;
		}
	}
		
	for (i=1; i <= theForm.adults.selectedIndex; i++){
		if (theForm['adult_accommodations'+i].selectedIndex == 0){
			alert('You must select accommodations for all adults');
			theForm['adult_accommodations'+i].focus();
			return false;
		}
	}
		
	for (i=1; i <= theForm.children.selectedIndex; i++){
		if (theForm['child_accommodations'+i].selectedIndex == 0){
			alert('You must select accommodations for all children');
			theForm['child_accommodations'+i].focus();
			return false;
		}
	}
	
	if(theForm.primarycontact.selectedIndex == 0) {
		alert('You must select a primary contact');
			theForm.primarycontact.focus();
		return false;
	}

	for (i=1; i <= theForm.tasters.selectedIndex; i++){
		if (theForm['taster_name'+i].value == theForm.primarycontact[theForm.primarycontact.selectedIndex].value && theForm['taster_email'+i].value == ''){
			alert('You must enter the email address of your primary contact');
			theForm['taster_email'+i].focus();
			return false;
		}
	}	
	
	if (theForm.bphone.value == '' && theForm.cphone.value == ''){
		alert('You must enter at least one phone number for your primary contact');
			theForm.bphone.focus();
		return false;
	} else if (theForm.password.value == ''){
		alert('You must enter a password');
			theForm.password.focus();
		return false;
	} else if (theForm.password.value != theForm.verify.value){
		alert('Your password did not match the verify password field');
			theForm.password.focus();
		return false;
	} else if (theForm.ccname.value == ''){
		alert('You must enter the name on the credit card');
			theForm.ccname.focus();
		return false;
	} else if (theForm.ccnum.value == ''){
		alert('You must enter a credit card number');
			theForm.ccnum.focus();
		return false;
	} else if (theForm.ccexp.value == ''){
		alert('You must enter a credit card expiration date');
			theForm.ccexp.focus();
		return false;
	} else if (theForm.cccode.value == ''){
		alert('You must enter a credit card security code');
			theForm.cccode.focus();
		return false;
	}
		
	return true;

}
