/*
	JavaScript file for suecrockettphotography.com
*/


		function validate() {
			
			var queue = new Array();
			
			var showname = document.getElementById('fp-showname').value;
			
			var datesst = document.getElementById('fp-datesst').value;
			
			var datesnd = document.getElementById('fp-datesnd').value;
			
			var keywords = document.getElementById('fp-keywords').value;
			
			if((showname == "" || showname == "0") && datesst == "" && datesnd == "" && keywords == "") {
				
				// alert
				
				alert("Please fill in at least one of the fields");
				
				return false;
				
			} else {
				
				if((datesst != "" && datesnd == "") || (datesst == "" && datesnd != "")) {
					
					queue.push("If you are going to specify dates, make sure you fill in BOTH fields");
					
				}
				
				
				
				if(datesst != "" && datesnd != "") {
					
					if(!validateDate(datesst)) {
						
						queue.push("Please make sure the FIRST DATE is in the format: dd/mm/yyyy");
						
					}
					
					
					
					if(!validateDate(datesnd)) {
						
						queue.push("Please make sure the LAST DATE is in the format: dd/mm/yyyy");
						
					}
					
					
				}
				
				
				
				// check to see if there is anything in the queue
				
				if(queue.length > 0) {
					
					alert("You have not completed the form correctly. The errors we found were:\n\n " + queue.join("\n") + "");
					
					return false;
					
				} else {
					
					return true;
					
				}
				
			}
			
		}
		
		
		
		function validateDate(thedate) {
			
			// validates a date in these formats: dd/mm/yyyy or dd-mm-yyyy or dd.mm.yyyy
			
			var testdate = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
			
			return testdate.test(thedate);
			
		}
		
		
		
