		this.image = new Array();
		this.span = new Array();
		this.span2 = new Array();
		
		//this function adds input boxes
		function addFields()	{
			//change variable names to something more 
			var current_id = document.getElementById("nextID");
			var next_id = current_id.value;
			current_id.value++;
			
			if (image.length <= 3) {
				var target = document.getElementById("inputs");
			    //create the form elements
				var input = document.createElement("input");
			    var spans = document.createElement("span");
			    var spans2 = document.createElement("span");
			    //define the attributes
			    spans.setAttribute('id', 'images'+next_id);
			    spans.innerHTML = "";
			    
			    input.setAttribute("name", "item_upload"+next_id);
			    input.setAttribute("id", "item_upload"+next_id);
			    input.setAttribute("type", "file");
			    input.setAttribute("size", "22")
			    
			    spans2.innerHTML = "<br/>";
			    //add elements to form (parent div)
			    target.appendChild(spans);
			    target.appendChild(input);
			    target.appendChild(spans2);
			       
			    /**
			    * add them to an array 
			    * makes it easier and cleaner 
			    * to remove the elements 
			    */
			    image[image.length] = input;
			    span[span.length] = spans;
			    span2[span2.length] = spans2;
			    
			} else {
				alert ('You can only attach a maximum of 5 images');
			}
		}
		
		//this function removes the input boxes starting last added
		function removeField() {

			//set the target div
			var target = document.getElementById("inputs");
			if (image.length>0) {
				//removes the child node from the parent div				
				target.removeChild(image[image.length-1]); //target.lastChild
				//remove from image array
				image = image.splice(0,image.length-1); 
				//remove span tag with text from form and the array
				target.removeChild(span[span.length-1]);
				span = span.splice(0,span.length-1);
				//remove the span tag with the <br/> from the form and the array
				target.removeChild(span2[span2.length-1]);
				span2 = span2.splice(0,span2.length-1);
			}
		}
		
		/**
		* validates the input(file) boxes to check
		* for valid and allowed file types
		*/
function mark_error(id)
{
	document.getElementById(id).style.backgroundColor = '#f7f7ff';
	document.getElementById(id).style.borderWidth = '1px';
	document.getElementById(id).style.borderStyle = 'solid';
	document.getElementById(id).style.borderColor = '#FF0000';
}
function unmark_error(id)
{
	document.getElementById(id).style.backgroundColor = '';
	document.getElementById(id).style.borderWidth = '';
	document.getElementById(id).style.borderStyle = '';
	document.getElementById(id).style.borderColor = '';
}
		
		function validate() {
			
			//check email
			if(document.getElementById('fname').value == ''){
			mark_error('fname');
			alert ("Please enter your name.");
			document.getElementById('fname').focus();
			return false;
		} else {
			unmark_error('fname');
		}
			if (document.getElementById('lname').value == "") {
			mark_error('lname');
			alert ("Please enter your surname.");
			document.getElementById('lname').focus();
			return false;
			} else {
			unmark_error('lname');				
			}
			if (document.getElementById('email_12').value == "") {
			mark_error('email_12');
			alert ("Please enter an email address.");
			document.getElementById('email_12').focus();
			return false;				
			} else {
			unmark_error('email_12');				
			}
			
			if (document.getElementById('email_12').value != document.getElementById('confirm_email').value) {
			alert ("Email addresses don't match.");
			document.getElementById('confirm_email').focus();
			return false;
			}
			if (document.getElementById('telephone').value == "") {
			mark_error('telephone');
			alert ("Please enter a contact number.");
			document.getElementById('telephone').focus();
			return false;				
			} else {
			unmark_error('telephone');				
			}
			
			if (document.getElementById('item_details').value == "") {
			mark_error('item_details');
			alert ("Please enter your enquiry details.");
			document.getElementById('item_details').focus();
			return false;				
			} else {
			unmark_error('item_details');				
			}
			
			if (document.getElementById('where-from').value == "none") {
			mark_error('where-from');
			alert ("Please enter your Location.");
			document.getElementById('where-from').focus();
			return false;				
			} else {
			unmark_error('where-from');				
			}
			
			

			//REMOVE VALIDATION OF UPLOAD FIELD, UNCOMMENT TO UNDO..
			//if (document.getElementById('item_upload').value == "") {
			//mark_error('item_upload');
			//alert ("Please select a picture to upload.");
			//document.getElementById('item_upload').focus();
			//return false;				
			//} else {
			//unmark_error('item_upload');				
			//}			

			//first check if there is a file selected
			if (document.getElementById('item_upload').value !="") {	
				//then check file extension for validity
				if( (document.getElementById('item_upload').value.lastIndexOf(".jpeg")==-1) && (document.getElementById('item_upload').value.lastIndexOf(".jpg")==-1) && (document.getElementById('item_upload').value.lastIndexOf(".bmp")==-1) ) {
					//if it fails display appropriate message
				  	alert("Please upload only .jpg, .jpeg or .bmp extention file");
					return false;
				} 
			}
			//if any other boxes where added check each of them
			// not the neatest way - a loop would be better: something to look at
			
			
			var length = image.length;
			for ( var i = 1; i<=length; i++){
				if ((document.getElementById('item_upload'+i).value.lastIndexOf(".jpeg")==-1) && (document.getElementById('item_upload'+i).value.lastIndexOf(".jpg")==-1) && (document.getElementById('item_upload'+i).value.lastIndexOf(".bmp")==-1) ) {
					alert("Please upload only .jpg, .jpeg or .bmp extention file");
					return false;
				}
			}
			//if everythig is ok then submit the form
			document.getElementById('form').submit();
			
		}
