
function updateReqFields(fieldname,modify) {
	var reqfieldlist = $('required');
	var reqfields = reqfieldlist.value.split(",");
	if (modify=='remove') {
		var newreqfieldlist = new Array();
		for (var i=0;i<reqfields.length;i++) {			
			if (fieldname==reqfields[i]) continue;
			newreqfieldlist.push(reqfields[i]);
		}
		reqfieldlist.value=newreqfieldlist.toString();
	}	
	if (modify=='add') {
		reqfields.push(fieldname);	
		reqfieldlist.value=reqfields.toString();
	}
}



function turn(elmAction) {
	switch (elmAction) {
		case 'city-on':
			$('cityRow').removeClassName('hide');
			$('city').addClassName('required');
			updateReqFields('city','add');
		break;
		case 'city-off':
			$('cityRow').addClassName('hide');
			$('city').removeClassName('required');
			updateReqFields('city','remove');
			$('city').value = "";
		break;
		case 'state-on':
			$('stateRow').removeClassName('hide');
			$('state').addClassName('required validate-selection');
			updateReqFields('state','add');		
		break;
		case 'state-off':
			$('stateRow').addClassName('hide');
			$('state').removeClassName('required validate-selection');
			updateReqFields('state','remove');
			$('state').selectedIndex = 0;
		break;
		case 'zipcode-on':
			$('ZIPcodeRow').removeClassName('hide');
			$('ZIPcode').addClassName('required validate-zipcode');
			updateReqFields('ZIPcode','add');		
		break;
		case 'zipcode-off':
			$('ZIPcodeRow').addClassName('hide');
			$('ZIPcode').removeClassName('required validate-zipcode');
			updateReqFields('ZIPcode','remove');
			$('ZIPcode').value = "";
		break;
		case 'provence-on':
			$('canadaProvence').addClassName('required validate-selection');
			$('canadaProvenceRow').removeClassName('hide');
			updateReqFields('canadaProvence','add');
		break;
		case 'provence-off':
			$('canadaProvence').removeClassName('required validate-selection');
			$('canadaProvenceRow').addClassName('hide');
			updateReqFields('canadaProvence','remove');
			$('canadaProvence').selectedIndex = 0;
		break;
		case 'postcode-on':
			$('postcode').addClassName('required validate-canadapostalcode');
			$('canadaPostalCode').removeClassName('hide');
			updateReqFields('postcode','add');
		break;
		case 'postcode-off':
			$('postcode').removeClassName('required validate-canadapostalcode');
			$('canadaPostalCode').addClassName('hide');
			updateReqFields('postcode','remove');
			$('postcode').value = "";
		break;
		case 'parkingspots-off':
			$('parking_spots').removeClassName('required validate-selection');
			$('parkingRow').addClassName('hide');
			updateReqFields('parking_spots','remove');
			$('parking_spots').value = "";
		break;
		case 'parkingspots-on':
			$('parking_spots').addClassName('required validate-selection');
			$('parkingRow').removeClassName('hide');
			updateReqFields('parking_spots','add');
		break;
		case 'others-off':
			$('others').removeClassName('required');
			$('othersRow').addClassName('hide');
			updateReqFields('others','remove');
			$('others').value = "";
		break;
		case 'others-on':
			$('others').addClassName('required');
			$('othersRow').removeClassName('hide');
			updateReqFields('others','add');
		break;
	}
}


function countryChangeFunction() {

	updateReqFields('city','remove');
	
	switch ($F('country')) {				
		case 'United States of America':
			turn('city-on');
			turn('state-on');
			turn('zipcode-on');
			turn('provence-off');
			turn('postcode-off');
			break;
		case 'Canada':
			turn('city-on');
			turn('state-off');
			turn('zipcode-off');
			turn('provence-on');
			turn('postcode-on');
			break;
		default:
			turn('city-on');
			turn('state-off');
			turn('zipcode-off');
			turn('provence-off');
			turn('postcode-off');
			break;
	}
 } 
 
 function parkingChangeFunction() {
	
	switch ($F('parking')) {				
		case 'no':
			turn('parkingspots-off');
			break;
		case 'yes':
			turn('parkingspots-on');
			break;
		default:
			turn('parkingspots-off');
			break;
	}
 }
 
function transportationChangeFunction() {
	
	switch ($F('transportation')) {				
		case 'yes':
			turn('parkingspots-on');
			break;
		default:
			turn('parkingspots-off');
			break;
	}
}

function dancersChangeFunction() {
	
	switch ($F('dancers')) {				
		case '':
			turn('others-off');
			break;
		case '1':
			turn('others-off');
			break;
		default:
			turn('others-on');
			break;
	}
}
 
 /*
 to strip out commas
 	if (elm.hasClassName('stripcommas')) {
			var tmpValue = elm.value;
			elm.value = tmpValue.replace(/,/g,';');
			alert(elm.value);
		};
 */