// Checks whether any fields which are required are missing and alerts the user
function checkSubmit(){

var name = document.getElementById('fullname').value;
var company = document.getElementById('company').value;
var email = document.getElementById('email').value;
var tel = document.getElementById('telephone').value;
var address = document.getElementById('address').value;
var county = document.getElementById('county').value;
var postcode = document.getElementById('postcode').value;
var title = document.getElementById('ptitle').value;
var description = document.getElementById('pdescription').value;

var check = 0;
var missing='';

if ((name==null)||(name=="")){
check = 1;	
missing = missing + 'Name, ';
}

if ((company==null)||(company=="")){
check = 1;	
missing = missing + 'Company, ';
}

if ((email==null)||(email=="")){
check = 1;	
missing = missing + 'E-Mail, ';
}

if ((tel==null)||(tel=="")){
check = 1;	
missing = missing + 'Telephone, ';
}

if ((address==null)||(address=="")){
check = 1;	
missing = missing + 'Address, ';
}

if ((county==null)||(county=="")){
check = 1;
missing = missing + 'County, ';
}

if ((postcode==null)||(postcode=="")){
check = 1;
missing = missing + 'Postcode, ';
}

if ((title==null)||(title=="")){
check = 1;	
missing = missing + 'Project Title, ';
}

if ((description==null)||(description=="")){
check = 1;	
missing = missing + 'Project Description, ';
}

if (check == 1){
	alert('The following fields are missing: ' + missing);
}else{
	if (emailcheck(email)==true){
		document.requestform.submit()
	}
	
}
	

}

// Checks whether a given string has a valid email format i.e. someone@somewhere.com
function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email addresss.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email addresss.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email addresss.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email addresss.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email addresss.D")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email addresss.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email addresss.")
		    return false
		 }

 		 return true					
	}
	/*
var attachmentCount = 0;	

function addAttachment(){
	
	if (attachmentCount!=10){
	
	var file = document.getElementById('attachment').value;
	var i = file.length;
	var j = file.lastIndexOf("\\") + 1;
	var filename = file.substring(i,j);
	var type = (file.substring(i, i-3)).toLowerCase();
	if ((type=='jpg') || (type=='gif') || (type=='doc') || (type=='txt') || (type=='pdf')){
	
	
	
	
	
	var div = document.getElementById('attachments');
	div.innerHTML += filename + "<br>";
	attachmentCount = attachmentCount + 1;
	var hidden = 'attach' + attachmentCount;
	document.getElementById(hidden).value=file;
	
	}else{
	
	alert('Invalid file type only jpeg, gif, Text, MS Word, PDF file types are permitted.	');
	
	}
	
	} else{
		alert('Cannot attach more than 5 files');
	}
}
*/ 