

	function valid(ca) {
		
		for (var j=0; j<document.forms[0].length -1; j++) {
			
			if (document.forms[0][j].style.backgroundColor == '#ffffaa'){
				
				var field_name = document.forms[0].elements[j].name;
				
				switch (field_name) {
					
					case "region" :
						
						if (ca.indexOf("g") != -1) {
							
							if (document.forms[0].elements[j].value == '') {
								alert('You need to enter a region.');
								document.forms[0].region.focus();
								return false;
							}							
							
						} else {
							
							if (document.forms[0].region.options[document.forms[0].region.selectedIndex].text=='<--- Select a region --->') {
								alert('You need to select a region.');
								document.forms[0].region.focus();
								return false;							
								
							}
							
						}
						
					break
					
					case "country_area" :
						
						if (ca.indexOf("c") != -1) {
							
							var c_val = document.forms[0].country_area.options.value;
							
							if (c_val.indexOf("A") != -1) {
								
								alert('You need to select a country, not an area.');
								document.forms[0].country_area.focus();
								return false;
								
							} else if (c_val =='') {
								
								alert('You need to select a country.');
								document.forms[0].country_area.focus();
								return false;
								
							}
							
						} else if (ca.indexOf("a") != -1) {
							
							var c_val = document.forms[0].country_area.options.value;
							
							if (c_val.indexOf("C") != -1) {
								
								alert('You need to select an area, not a country.');
								document.forms[0].country_area.focus();
								return false;
								
							} else if ( c_val =='') {
								
								alert('You need to select a area.');
								document.forms[0].country_area.focus();
								return false
							}
							
						} else {
							
							if (document.forms[0].elements[j].value == '') {
								alert('You need to select a country/area.');
								document.forms[0].country_area.focus();
								return false
							}
							
						}
						
					break
					
					case "country" :
						
						if (document.forms[0].elements[j].value == '') {
							alert("You need to enter a country.");
							document.forms[0].country.focus();
							return false;
						}
						
					break
					
					case "area" :
						
						if (document.forms[0].elements[j].value == '') {
							alert("You need to enter an area.");
							document.forms[0].area.focus();
							return false;
						}
						
					break
					
					case "resort" :
						
						if (document.forms[0].elements[j].value == '') {
							alert("You need to enter a resort.");
							document.forms[0].resort.focus();
							return false;
						}
						
					break
					
					case "accommodation_name" :
						
						if (document.forms[0].elements[j].value == '') {
							alert("You need to enter an accommodation name.");
							document.forms[0].accommodation_name.focus();
							return false;
						}
						
						if (document.forms[0].elements[j].value.length < 3) {
							alert("You need to enter a minimum of three letters for the accommodation name.");
							document.forms[0].accommodation_name.focus();
							return false;
						}
						
					break
					
					default:
						
					break
					
				}
				
			}
		}
		
		return true;
		
	}

	function mandatory() {
		
		for (var i=0; i<document.forms[0].length -1; i++) {
			if (document.forms[0][i].style.backgroundColor == '#ffffaa'){
				
				if (document.forms[0].elements[i].value == '') {
					
					alert('Please complete mandatory field ('+document.forms[0].elements[i].name+')');
					document.forms[0].elements[i].focus();
					return false;
					
				}
				
				if (document.forms[0].elements[i].name == 'accommodation_name' && document.forms[0].elements[i].value.length < 3) {
					alert('You need to enter at least 3 letters of the accommodation name.');
					return false;
				}				
				
				
				
			}
		}
		
		return true;
		
	}

	function SelectCheckbox() {
		
		var val_selected = 'false';
		
		for (var i=0; i<document.forms[0].elements.length -1; i++) {
			
			if (document.forms[0].elements[i].type == 'checkbox') {
				
				if (document.forms[0].elements[i].checked) {
					val_selected = 'true';
					
				}
				
			}
			
		}
		
		if (val_selected == 'false') {
			
			alert('You need to select at least one holiday type.');
			return false;
			
		}
		
	}

function not_used() {

		for (var m=0; m<document.forms[0].length -1; m++) {
			
			alert(document.forms[0].length);
			
			var field_name = document.forms[0].elements[m].name;
			alert(field_name);
			
		}

	var mandatory = new Array('month', 'drop', 'month', 'year', 'drop', 'year', 'general_sun', 'textarea', 'general comments for sun holiday');
	
	for (var k=0; k < mandatory.length; k=k+3) {
		
		if (eval("document.forms[0]." + mandatory[k])) {
			
			if (mandatory[k+1] == 'drop') {
				
				if (eval("document.forms[0]." + mandatory[k] + ".value") == '') {
					alert('You need to enter a ' + mandatory[k+2] + '');
					eval("document.forms[0]."+mandatory[k]+".focus()");
					return false;
				}
				
			} else if (mandatory[k+1] == 'textarea') {
				
				if (eval("document.forms[0]." + mandatory[k] + ".value") == '') {
					alert('You need to enter ' + mandatory[k+2] + '');
					eval("document.forms[0]."+mandatory[k]+".focus()");
					return false;
				}				
				
			}
			
		}
		
	}
}

	function change_mandatory() {
		
		if (document.forms[0].field_type.value == '') {
			document.forms[0].table_control.style.backgroundColor = '#ffffff';
			document.forms[0].disable.style.backgroundColor = '#ffffaa';
			document.forms[0].holiday_type.style.backgroundColor = '#ffffaa';
			document.forms[0].pre_field_label.style.backgroundColor = '#ffffff';
			document.forms[0].field_label.style.backgroundColor = '#ffffff';
			document.forms[0].form_name.style.backgroundColor = '#ffffff';
			document.forms[0].col_type.style.backgroundColor = '#ffffff';
			document.forms[0].col_num.style.backgroundColor = '#ffffff';
			document.forms[0].dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].post_field_label.style.backgroundColor = '#ffffff';
			document.forms[0].list_order.style.backgroundColor = '#ffffaa';
			document.forms[0]._mandatory.style.backgroundColor = '#ffffaa';
			document.forms[0].quote_field.style.backgroundColor = '#ffffaa';
			document.forms[0].rating.style.backgroundColor = '#ffffaa';
			
		} else if (document.forms[0].field_type.value == 'label') {
			document.forms[0].table_control.style.backgroundColor = '#ffffff';
			document.forms[0].holiday_type.style.backgroundColor = '#ffffaa';
			document.forms[0].pre_field_label.style.backgroundColor = '#ffffff';
			document.forms[0].field_label.style.backgroundColor = '#ffffff';
			document.forms[0].form_name.style.backgroundColor = '#ffffaa';
			document.forms[0].col_type.style.backgroundColor = '#ffffff';
			document.forms[0].col_num.style.backgroundColor = '#ffffff';
			document.forms[0].dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].post_field_label.style.backgroundColor = '#ffffff';		
			
		} else if (document.forms[0].field_type.value == 'drop') {
			document.forms[0].table_control.style.backgroundColor = '#ffffff';
			document.forms[0].holiday_type.style.backgroundColor = '#ffffaa';
			document.forms[0].pre_field_label.style.backgroundColor = '#ffffff';
			document.forms[0].field_label.style.backgroundColor = '#ffffff';
			document.forms[0].form_name.style.backgroundColor = '#ffffaa';
			document.forms[0].col_type.style.backgroundColor = '#ffffaa';
			document.forms[0].col_num.style.backgroundColor = '#ffffff';
			document.forms[0].dropdown_name.style.backgroundColor = '#ffffaa';
			document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffaa';
			document.forms[0].post_field_label.style.backgroundColor = '#ffffff';
			
		} else if (document.forms[0].field_type.value == 'textarea') {
			document.forms[0].table_control.style.backgroundColor = '#ffffff';
			document.forms[0].holiday_type.style.backgroundColor = '#ffffaa';
			document.forms[0].pre_field_label.style.backgroundColor = '#ffffff';
			document.forms[0].field_label.style.backgroundColor = '#ffffff';
			document.forms[0].form_name.style.backgroundColor = '#ffffaa';
			document.forms[0].col_type.style.backgroundColor = '#ffffaa';
			document.forms[0].col_num.style.backgroundColor = '#ffffff';
			document.forms[0].dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffff';
			document.forms[0].post_field_label.style.backgroundColor = '#ffffff';
			
		}
		
	}
	
	function toggle_name_newname() {
		
		if (document.forms[0].field_type.value == 'drop') {
			
			if (document.forms[0].dropdown_name.options[document.forms[0].dropdown_name.selectedIndex].text == '' && document.forms[0].new_dropdown_name.value == '') {
				
				document.forms[0].dropdown_name.style.backgroundColor = '#ffffaa';
				document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffaa';
				
			} else if (document.forms[0].dropdown_name.options[document.forms[0].dropdown_name.selectedIndex].text != '' && document.forms[0].new_dropdown_name.value != '') {
				
				document.forms[0].dropdown_name.style.backgroundColor = '#ffffff';
				document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffff';
				
			} else if (document.forms[0].dropdown_name.options[document.forms[0].dropdown_name.selectedIndex].text != '') {
				document.forms[0].dropdown_name.style.backgroundColor = '#ffffaa';
				document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffff';
				
				
			} else if (document.forms[0].new_dropdown_name.value != '') {
				document.forms[0].dropdown_name.style.backgroundColor = '#ffffff';
				document.forms[0].new_dropdown_name.style.backgroundColor = '#ffffaa';
				
				
			}
			
			
		}
		
	}
	
	function no_chars() {
		
		if (document.forms[0].field_type.value == 'drop') {
			
			if (document.forms[0].col_type.options[document.forms[0].col_type.selectedIndex].text == 'Character' ||document.forms[0].col_type.options[document.forms[0].col_type.selectedIndex].text == 'Varchar') {
				
				document.forms[0].col_num.style.backgroundColor = '#ffffaa';
				
			} else {
				
				document.forms[0].col_num.style.backgroundColor = '#ffffff';
				
			}
			
		}
		
	}
