function removeEngineer(){
	return confirm('Are you sure you want to remove this engineer?');
}

function removeClient(){
	return confirm('Are you sure you want to remove this client?');
}

function removeContact(){
	return confirm('Are you sure you want to remove this contact?');
}

function removeEnquiry(){
	return confirm('Are you sure you want to remove this enquiry?');
}

function removeJob(){
	return confirm('Are you sure you want to remove this job?');
}

function convertEnquiry(){
	return confirm('Are you sure you want to convert this enquiry?');
}

function confirmInvoiceSend(){
	return confirm('Are you sure you want to send this invoice?');
}

function removeReport(){
	return confirm('Are you sure you want to remove this report?');
}

function markJobFinished(){
	return confirm('Are you sure you want to mark this job as finished?  This cannot be un-done.');
}

function generalValidate() {
	var d = document.getElementById('frmOnline');
	if (d['Data[title]'].options[d['Data[title]'].selectedIndex].value=="") {
		alert("You must choose a title.");
		d['Data[title]'].focus();
		return false;
	}
	if (!d['Data[firstname]'].value) {
		alert("You must enter a first name.");
		d['Data[firstname]'].focus();
		return false;
	}
	if (!d['Data[lastname]'].value) {
		alert("You must enter a last name.");
		return false;
	}
	if (d['Data[country]'].options[d['Data[country]'].selectedIndex].value=="") {
			alert("You must choose a country of residence.");
			return false;
	}
	if (!d['Data[telephone]'].value) {
		alert("You must enter a telephone number.");
		return false;
	}
	if (!d['Data[email]'].value) {
		alert("You must enter an email address.");
		return false;
	}
	if (d['Data[how]'].options[d['Data[how]'].selectedIndex].value=="") {
		alert("You must tell us how you found us.");
		return false;
	}
	if (!d['Data[enquiry]'].value) {
		alert("Please input an enquiry.");
		return false;
	}

	return true;
}

function reqQuoteValidate() {
	var d = document.getElementById('frmOnline');
	if (d['Data[title]'].options[d['Data[title]'].selectedIndex].value=="") {
		alert("You must choose a title.");
		d['Data[title]'].focus();
		return false;
	}
	if (!d['Data[firstname]'].value) {
		alert("You must enter a first name.");
		d['Data[firstname]'].focus();
		return false;
	}
	if (!d['Data[lastname]'].value) {
		alert("You must enter a last name.");
		return false;
	}
	if (d['Data[country]'].options[d['Data[country]'].selectedIndex].value=="") {
			alert("You must choose a country of residence.");
			return false;
	}
	if (!d['Data[telephone]'].value) {
		alert("You must enter a telephone number.");
		return false;
	}
	if (!d['Data[email]'].value) {
		alert("You must enter an email address.");
		return false;
	}
	if (d['Data[how]'].options[d['Data[how]'].selectedIndex].value=="") {
		alert("You must tell us how you found us.");
		return false;
	}
	if (!d['Data[enquiry]'].value) {
		alert("Please input an enquiry.");
		return false;
	}

	return true;

}

function reqRingbackValidate() {
	var d = document.getElementById('frmOnline');
	if (d['Data[title]'].options[d['Data[title]'].selectedIndex].value=="") {
		alert("You must choose a title.");
		d['Data[title]'].focus();
		return false;
	}
	if (!d['Data[firstname]'].value) {
		alert("You must enter a first name.");
		d['Data[firstname]'].focus();
		return false;
	}
	if (!d['Data[lastname]'].value) {
		alert("You must enter a last name.");
		return false;
	}
	if (!d['Data[telephone]'].value) {
		alert("You must enter a telephone number.");
		return false;
	}
	if (!d['Data[email]'].value) {
		alert("You must enter an email address.");
		return false;
	}
	if (d['Data[how]'].options[d['Data[how]'].selectedIndex].value=="") {
		alert("You must tell us how you found us.");
		return false;
	}

	return true;
}

function reqPresentationValidate() {
	var d = document.getElementById('frmOnline');
	if (d['Data[title]'].options[d['Data[title]'].selectedIndex].value=="") {
		alert("You must choose a title.");
		d['Data[title]'].focus();
		return false;
	}
	if (!d['Data[firstname]'].value) {
		alert("You must enter a first name.");
		d['Data[firstname]'].focus();
		return false;
	}
	if (!d['Data[lastname]'].value) {
		alert("You must enter a last name.");
		d['Data[lastname]'].focus();
		return false;
	}
	if (d['Data[country]'].options[d['Data[country]'].selectedIndex].value=="") {
			alert("You must choose a country of residence.");
			return false;
	}
	if (!d['Data[telephone]'].value) {
		alert("You must enter a telephone number.");
		return false;
	}
	if (!d['Data[email]'].value) {
		alert("You must enter an email address.");
		return false;
	}
	if (d['Data[how]'].options[d['Data[how]'].selectedIndex].value=="") {
		alert("You must tell us how you found us.");
		return false;
	}

	return true;

}

function classVerify() {
	var d = document.getElementById('classified');
	if(!d['Data[title]'].value) {
		alert("You must input a title");
		d['Data[title]'].focus();
		return false;
	}

	if (isNaN(d['Data[price]'].value) || (d['Data[price]'].value < 0)) {
		alert("You must enter a price greater than zero.");
		d['Data[price]'].focus();
		return false;
	}



	return true;
}

function clientVerify() {
	var d = document.getElementById('client');
	if(!d['Data[clientname]'].value) {
		alert("You must enter a client name");
		d['Data[clientname]'].focus();
		return false;
	}
	if (!d['Data[email]'].value) {
		alert("You must enter a username");
		d['Data[email]'].focus();
		return false;
	}
	if (!d['Data[passwd]'].value) {
		alert("You must enter a password");
		d['Data[passwd]'].focus();
		return false;
	}
	return true;
}

function enquiryVerify() {
	var d=document.getElementById('enquiryFrm');
	if(!d['Data[clientname]'].value) {
		alert("You must enter a client name");
		d['Data[clientname]'].focus();
		return false;
	}
	if(!d['Data[contactname]'].value) {
		alert("You must enter a contact name");
		d['Data[contactname]'].focus();
		return false;
	}
	if(!d['Data[telephone]'].value) {
		alert("You must enter a contact telephone number");
		d['Data[telephone]'].focus();
		return false;
	}
	if(!d['Data[emailaddress]'].value) {
		alert("You must enter a contact email address");
		d['Data[emailaddress]'].focus();
		return false;
	}
	if(!d['Data[enquiry]'].value) {
		alert("You must enter an enquiry");
		d['Data[enquiry]'].focus();
		return false;
	}


if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d['Data[emailaddress]'].value)){

} else {
	alert("Invalid E-mail Address! Please re-enter.")
	d['Data[emailaddress]'].focus();
	return false;
}



	return true;
}

function jobVerify() {
	var cd = document.getElementById('clientDropDown');
	var sel = cd[cd.selectedIndex].value;
	var d=document.getElementById('jobFrm');

	if(sel == -1){

		if (!d['NClient[newClient]'].value) {
			alert("Please enter a client name");
			d['NClient[newClient]'].focus();
			return false;
		}

		if (!d['NClient[newContact]'].value) {
			alert("Please enter a contact name");
			d['NClient[newContact]'].focus();
			return false;
		}

		if (!d['NClient[newEmail]'].value) {
			alert("Please enter an email address for the client");
			d['NClient[newEmail]'].focus();
			return false;
		}

		if (!d['NClient[newTelephone]'].value) {
			alert("Please enter a telephone number for the client");
			d['NClient[newTelephone]'].focus();
			return false;
		}


		if(d['Data[deliveryCost]'].value && isNaN(d['Data[deliveryCost]'].value)) {
			alert("You must enter a numeric value for delivery cost");
			d['Data[deliveryCost]'].focus();
			return false;
		}

		if(d['Data[collectionCost]'].value && isNaN(d['Data[collectionCost]'].value)) {
			alert("You must enter a numeric value for collection cost");
			d['Data[collectionCost]'].focus();
			return false;
		}

		if(!d['Data[jobDescription]'].value) {
			alert("You must enter a Job Description");
			d['Data[jobDescription]'].focus();
			return false;
		}


		var sDate = mkDate(d['Data[start_date]']);
		var eDate = mkDate(d['Data[end_date]']);

		if (eDate != false && sDate > eDate) {
			alert("The Job End Date is before the Job Start Date");
		}

	}
	return true;
}

function jobVerifyEdit() {

	var d=document.getElementById('jobFrm');

		if (!d['Data[contactname]'].value) {
			alert("Please enter a contact name");
			d['Data[contactname]'].focus();
			return false;
		}

		if (!d['Data[emailaddress]'].value) {
			alert("Please enter an email address for the enquiry");
			d['Data[emailaddress]'].focus();
			return false;
		}

		if (!d['Data[telephone]'].value) {
			alert("Please enter a telephone number for the client");
			d['Data[telephone]'].focus();
			return false;
		}

		if(d['Data[deliveryCost]'].value && isNaN(d['Data[deliveryCost]'].value)) {
			alert("You must enter a numeric value for delivery cost");
			d['Data[deliveryCost]'].focus();
			return false;
		}

		if(d['Data[collectionCost]'].value && isNaN(d['Data[collectionCost]'].value)) {
			alert("You must enter a numeric value for collection cost");
			d['Data[collectionCost]'].focus();
			return false;
		}

		if(!d['Data[jobDescription]'].value) {
			alert("You must enter a Job Description");
			d['Data[jobDescription]'].focus();
			return false;
		}


		var sDate = mkDate(d['Data[start_date]']);
		var eDate = mkDate(d['Data[end_date]']);

		if (eDate != false && sDate > eDate) {
			alert("The Job End Date is before the Job Start Date");
		}

	return true;
}

function newJobVerify() {
	var d=document.getElementById('newJobForm');

	if(parseInt(d['Data[clientID]'].value) == -1){
		if(!d['NClient[newClient]'].value) {
			alert("You must enter a client name if you are selecting to make a new client");
			d['NClient[newClient]'].focus();
			return false;
		}
	}

	if(!d['Data[contactname]'].value) {
		alert("You must enter a contact name");
		d['Data[contactname]'].focus();
		return false;
	}
	if(!d['Data[telephone]'].value) {
		alert("You must enter a contact telephone number");
		d['Data[telephone]'].focus();
		return false;
	}
	if(!d['Data[emailaddress]'].value) {
		alert("You must enter a contact email address");
		d['Data[emailaddress]'].focus();
		return false;
	}

	if(d['Data[deliveryCost]'].value && isNaN(d['Data[deliveryCost]'].value)) {
		alert("You must enter a numeric value for delivery cost");
		d['Data[deliveryCost]'].focus();
		return false;
	}

	if(d['Data[collectionCost]'].value && isNaN(d['Data[collectionCost]'].value)) {
		alert("You must enter a numeric value for collection cost");
		d['Data[collectionCost]'].focus();
		return false;
	}

	/*if(!d['Data[jobDescription]'].value) {
		alert("You must enter a Job Description");
		d['Data[jobDescription]'].focus();
		return false;
	}*/


	var sDate = mkDate(d['Data[start_date]']);
	var eDate = mkDate(d['Data[end_date]']);

	if (eDate != false && sDate > eDate) {
		alert("The Job End Date is before the Job Start Date");
	}


	return true;
}


function mkDate(el) {

	if (el.value) {

		start_date = el.value.split("/")


		// Access each element in the array.
		year = start_date[2];
		month = start_date[1];
		day = start_date[0];

		if (year.length == 2) {
		    year = '20' + year;
		}

		return new Date(year,month-1,day);
	} else {
		return false;
	}
}
