
var report = true;
var clickUpdate = false;
var clickDelete = false;
var clickSend = false;
var clickSearch = false;

function newFunction()
{
	try
	{
		return (true);
	}
	catch (e)
	{
		reportError("newFunction()",e);
		
		return (false);
	}
}

function nothing()
{
}
	
function reportError(fn,e)
{
	if (report)
	{
		alert ("Sorry - an error has occured...\n\n" + fn + ": >> " + e.description);	
	}
}

function checkAddUpdateUser()
{
	var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	
	try
	{
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this User ?"));
		}
		else
		{
			if (document.addUpdate.txtUsername.value == "")
			{
				alert ("Sorry - you need to enter the user name.");
				document.addUpdate.txtUsername.focus();
				return(false);
			}
			
			if (document.addUpdate.txtPassword.value == "")
			{
				alert ("Sorry - you need to enter the password.");
				document.addUpdate.txtPassword.focus();
				return(false);
			}
			
			if (document.addUpdate.txtBusinessName.value == "")
			{
				alert ("Sorry - you need to enter the business name.");
				document.addUpdate.txtBusinessName.focus();
				return(false);
			}
			
			if (!emailFilter.test(document.addUpdate.txtEMail.value))
			{
				alert ("Sorry - you need to enter the email address.");
				document.addUpdate.txtEMail.focus();
				return(false);
			}
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddUpdateUser()",e);
		
		return (false);
	}
}

function checkAddProduct()
{
	
	try
	{
		if (clickDelete)
		{
			if (document.addUpdate.txtProductName.value == "")
			{
				alert ("Sorry - you need to enter the product name.");
				document.addUpdate.txtProductName.focus();
				return(false);
			}
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddProduct()",e);
		
		return (false);
	}
}

function checkDeleteProduct()
{
	
	try
	{
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this Product ?"));
		}
		else
		{
			if (document.addUpdate.txtProductOrderingEmailAddress.value == "")
			{
				alert ("Sorry - you need to enter the email address that orders will be emailed to.");
				document.addUpdate.txtProductOrderingEmailAddress.focus();
				return(false);
			}
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkDeleteProduct()",e);
		
		return (false);
	}
}

function checkDeleteAgChemProduct()
{
	
	try
	{
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this Product ?"));
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkDeleteAdChemProduct()",e);
		
		return (false);
	}
}

function checkDeleteCroppingProduct()
{
	
	try
	{
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this Product ?"));
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkDeleteCroppingProduct()",e);
		
		return (false);
	}
}

function checkAddFertilizerOrder()
{
	
	try
	{
		if (document.addForm.txtInvAddress1.value == "")
		{
			alert ("Sorry - you need to enter the 1st line of your invoice address");
			document.addForm.txtInvAddress1.focus();
			return(false);
		}
		
		if (document.addForm.txtDelAddress1.value == "")
		{
			alert ("Sorry - you need to enter the 1st line of your delivery address");
			document.addForm.txtDelAddress1.focus();
			return(false);
		}
		
		if (document.addForm.txtInvTownCity.value == "")
		{
			alert ("Sorry - you need to enter the town / city of your invoice address");
			document.addForm.txtInvTownCity.focus();
			return(false);
		}
		
		if (document.addForm.txtDelTownCity.value == "")
		{
			alert ("Sorry - you need to enter the town / city of your delivery address");
			document.addForm.txtDelTownCity.focus();
			return(false);
		}
		
		if (document.addForm.txtInvCounty.value == "")
		{
			alert ("Sorry - you need to enter the county of your invoice address");
			document.addForm.txtInvCounty.focus();
			return(false);
		}
		
		if (document.addForm.txtDelCounty.value == "")
		{
			alert ("Sorry - you need to enter the county of your delivery address");
			document.addForm.txtDelCounty.focus();
			return(false);
		}
		
		if (document.addForm.txtInvPostCode.value == "")
		{
			alert ("Sorry - you need to enter the postcode of your invoice address");
			document.addForm.txtInvPostCode.focus();
			return(false);
		}
		
		if (document.addForm.txtDelPostCode.value == "")
		{
			alert ("Sorry - you need to enter the postcode of your delivery address");
			document.addForm.txtDelPostCode.focus();
			return(false);
		}
		
		if (document.addForm.txtInvTelephone.value == "")
		{
			alert ("Sorry - you need to enter the telephone number of your invoice address");
			document.addForm.txtInvTelephone.focus();
			return(false);
		}
		
		if (document.addForm.txtDelTelephone.value == "")
		{
			alert ("Sorry - you need to enter the telephone number of your delivery address");
			document.addForm.txtDelTelephone.focus();
			return(false);
		}
		
		if (!checkInputsForDecimals())
			return(false);
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddFertilizerOrder()",e);
		
		return (false);
	}
}

function checkAddAgChemOrder()
{
	
	try
	{
		if (document.addForm.txtInvAddress1.value == "")
		{
			alert ("Sorry - you need to enter the 1st line of your invoice address");
			document.addForm.txtInvAddress1.focus();
			return(false);
		}
		
		if (document.addForm.txtDelAddress1.value == "")
		{
			alert ("Sorry - you need to enter the 1st line of your delivery address");
			document.addForm.txtDelAddress1.focus();
			return(false);
		}
		
		if (document.addForm.txtInvTownCity.value == "")
		{
			alert ("Sorry - you need to enter the town / city of your invoice address");
			document.addForm.txtInvTownCity.focus();
			return(false);
		}
		
		if (document.addForm.txtDelTownCity.value == "")
		{
			alert ("Sorry - you need to enter the town / city of your delivery address");
			document.addForm.txtDelTownCity.focus();
			return(false);
		}
		
		if (document.addForm.txtInvCounty.value == "")
		{
			alert ("Sorry - you need to enter the county of your invoice address");
			document.addForm.txtInvCounty.focus();
			return(false);
		}
		
		if (document.addForm.txtDelCounty.value == "")
		{
			alert ("Sorry - you need to enter the county of your delivery address");
			document.addForm.txtDelCounty.focus();
			return(false);
		}
		
		if (document.addForm.txtInvPostCode.value == "")
		{
			alert ("Sorry - you need to enter the postcode of your invoice address");
			document.addForm.txtInvPostCode.focus();
			return(false);
		}
		
		if (document.addForm.txtDelPostCode.value == "")
		{
			alert ("Sorry - you need to enter the postcode of your delivery address");
			document.addForm.txtDelPostCode.focus();
			return(false);
		}
		
		if (document.addForm.txtInvTelephone.value == "")
		{
			alert ("Sorry - you need to enter the telephone number of your invoice address");
			document.addForm.txtInvTelephone.focus();
			return(false);
		}
		
		if (document.addForm.txtDelTelephone.value == "")
		{
			alert ("Sorry - you need to enter the telephone number of your delivery address");
			document.addForm.txtDelTelephone.focus();
			return(false);
		}
		
		if (document.addForm.radioDepotId[0].checked == false && document.addForm.radioDepotId[1].checked == false && document.addForm.radioDepotId[2].checked == false)
		{
			alert ("Sorry - you need to enter your supplier depot");
			document.addForm.radioDepotId[0].focus();
			return(false);
		}
		
		if (!checkInputsForDecimals())
			return(false);
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddAgChemOrder()",e);
		
		return (false);
	}
}

function checkContactUs()
{
	try
	{
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	
		return(true);
	}
	catch (e)
	{
		reportError("checkContactUs()",e);
	}
}

function checkSure(msg)
{
	try
	{
		var ok;
		
		ok = confirm (msg);
	
		if (ok)
		{
			return (true);
		}
		else
		{
			return (false);
		}
	}
	catch (e)
	{
		reportError("checkSure()",e);
	}
}

function displayIFrame(iFrame,url)
{
	try
	{
		window.parent[iFrame].document.location.href = url;
	}
	catch (e)
	{
		reportError("displayIFrame(iFrame,url)",e);
	}
}

function displayPage(url)
{
	try
	{
		document.location.href = url;
	}
	catch (e)
	{
		reportError("displayPage(url)",e);
	}
}

function bringWindowForward()
{
	try
	{
		window.focus();
	}
	catch (e)
	{
		reportError("bringWindowForward()",e);
	}
}
	
function addBookmark()
{
	window.external.addFavorite (window.location,document.title);
}

function checkInputsForDecimals()
{
	try
	{
		var inputs = document.getElementsByTagName("input");
		
		for (var i=0;i < inputs.length;i++)
		{
			//links[i].className = 'unHighlighted';
			
			if (inputs[i].name.indexOf("quantity_") != -1)
			{
				if (inputs[i].value.indexOf(".") != -1)
				{
					alert("Sorry - one of your input values contains a decimal point");
					return(false);
				}
			}
		}
		
		return(true);
	}
	catch (e)
	{
		reportError("checkInputsForDecimals()",e);
		
		return (false);
	}
}

function checkReset()
{
	
	try
	{
		if (document.form.txtNewEndDate.value == "")
		{
			alert ("Sorry - you need to enter the new end date.");
			document.form.txtNewEndDate.focus();
			return(false);
		}
	
		return (true);
	}
	catch (e)
	{
		reportError("checkReset()",e);
		
		return (false);
	}
}

function checkExtend()
{
	
	try
	{
		if (document.form2.txtExtendEndDate.value == "")
		{
			alert ("Sorry - you need to enter the extended end date.");
			document.form2.txtExtendEndDate.focus();
			return(false);
		}
	
		return (true);
	}
	catch (e)
	{
		reportError("checkExtend()",e);
		
		return (false);
	}
}

function checkAddUpdateNewsArticle()
{
	try
	{
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this Article ?"));
		}
		else
		{
			if (document.addUpdate.txtNewsHeadline.value == "")
			{
				alert ("Sorry - you need to enter the article headline.");
				document.addUpdate.txtNewsHeadline.focus();
				return(false);
			}
		
			if (document.addUpdate.txtNewsArticle.value == "")
			{
				alert ("Sorry - you need to enter the article text.");
				document.addUpdate.txtNewsArticle.focus();
				return(false);
			}
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddUpdateNewsArticle()",e);
	}
}

function checkAddUpdateDownload()
{
	try
	{
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		
		if (clickDelete)
		{
			clickDelete = false;
			
			return (checkSure("Are you sure you want to DELETE this Download ?"));
		}
		else if (clickUpdate)
		{
			if (document.addUpdate.txtDownloadName.value == "")
			{
				alert ("Sorry - you need to enter the download name.");
				document.addUpdate.txtDownloadName.focus();
				return(false);
			}
		
			if (document.addUpdate.txtDownloadDescription.value == "")
			{
				alert ("Sorry - you need to enter the download description.");
				document.addUpdate.txtDownloadDescription.focus();
				return(false);
			}
		}
		else
		{
			if (document.addUpdate.txtDownloadName.value == "")
			{
				alert ("Sorry - you need to enter the download name.");
				document.addUpdate.txtDownloadName.focus();
				return(false);
			}
		
			if (document.addUpdate.txtDownloadDescription.value == "")
			{
				alert ("Sorry - you need to enter the download description.");
				document.addUpdate.txtDownloadDescription.focus();
				return(false);
			}
			
			if (document.addUpdate.downloadUploadedResource.value == "")
			{
				alert ("Sorry - you need to enter the file to be uploaded.");
				document.addUpdate.downloadUploadedResource.focus();
				return(false);
			}
		}
		
		return (true);
	}
	catch (e)
	{
		reportError("checkAddUpdateDownload()",e);
	}
}