function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function IsDate(iYear,iMonth,iDay) {

	if ((iYear != '') && (iMonth != '') && (iDay != '')) {

		iMonth = iMonth - 1;
		var Months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

		var isLeap = (iYear % 4 == 0) 
		if (iYear % 100 == 0) { isLeap = isLeap && (iYear % 400 == 0); }
		if (isLeap) { Months[1] = 29; }

		return (iDay <= Months[iMonth]);

	} else { 

		return (false);

	}
}

function IsEmail(strEmail) {

	return (strEmail.search(/^\w+((-\w+)|((\.|-)\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);

}

function OpenWindow(sURL, oWindow, sWindow, sOpt) {

	if (oWindow == null) {
		oWindow = window.open(sURL, sWindow, sOpt)
		oWindow.focus();
	} else {
		if (!oWindow.closed) {
			oWindow.location = sURL;
			oWindow.focus();
		} else {
			oWindow = window.open(sURL, sWindow, sOpt)
			oWindow.focus();
		}
	}
}

function CheckContactForm(theForm) {

	var sMessage = '';

	var aFields = new Array ( 
		{name:"realname",message:"- Name"}, 
		{name:"email",message:"- E-Mail Address"}
	);

	for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
		var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
		if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
	}

	if (sMessage != '') {
		alert('Please ensure that the following fields are completed\n\n' + sMessage);
		for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
			var oTemp = eval('theForm.' + aFields[iLoop].name);
			if (oTemp.value == '') { oTemp.focus(); }
		}
		return (false);
	}

	if (!IsEmail(theForm.email.value)) {
		alert('The E-Mail Address is invalid.');
		theForm.email.focus();
		return (false);
	}


	return (true);

}

function CheckRegisterForm(theForm) {

	var sMessage = '';

	var aFields = new Array ( 
		{name:"Prefix",message:"- Prefix"}, 
		{name:"Surname",message:"- Surname"}, 
		{name:"Telephone",message:"- Telephone"},
		{name:"Password",message:"- Password"},
		{name:"Confirm",message:"- Confirm your Password"}
	);

	for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
		var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
		if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
	}

	if (sMessage != '') {
		alert('Please ensure that the following fields are completed\n\n' + sMessage);
		for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
			var oTemp = eval('theForm.' + aFields[iLoop].name);
			if (oTemp.value == '') { oTemp.focus(); }
		}
		return (false);
	}

	if (theForm.EmailAddress.value != '') {
		if (!IsEmail(theForm.EmailAddress.value)) {
			alert('The E-Mail Address is invalid.');
			theForm.EmailAddress.focus();
			return (false);
		}
	}

	if (theForm.Password.value != theForm.Confirm.value) {
		alert('The passwords do not match.');
		theForm.Password.value = '';
		theForm.Confirm.value = '';
		theForm.Password.focus();
		return (false);
	}

	return (true);

}

function CheckLogonForm(theForm) {

	var sMessage = '';

	var aFields = new Array ( 
		{name:"Key",message:"- Registration Key"},
		{name:"Password",message:"- Password"}
	);

	for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
		var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
		if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
	}

	if (sMessage != '') {
		alert('Please ensure that the following fields are completed\n\n' + sMessage);
		for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
			var oTemp = eval('theForm.' + aFields[iLoop].name);
			if (oTemp.value == '') { oTemp.focus(); }
		}
		return (false);
	}

	return (true);

}

function CheckAdminRegisterForm(theForm) {

	var sMessage = '';

	var aFields = new Array ( 
		{name:"Prefix",message:"- Prefix"}, 
		{name:"Surname",message:"- Surname"}, 
		{name:"Telephone",message:"- Telephone"},
		{name:"Password",message:"- Password"}
	);

	for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
		var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
		if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
	}

	if (sMessage != '') {
		alert('Please ensure that the following fields are completed\n\n' + sMessage);
		for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
			var oTemp = eval('theForm.' + aFields[iLoop].name);
			if (oTemp.value == '') { oTemp.focus(); }
		}
		return (false);
	}

	if (theForm.EmailAddress.value != '') {
		if (!IsEmail(theForm.EmailAddress.value)) {
			alert('The E-Mail Address is invalid.');
			theForm.EmailAddress.focus();
			return (false);
		}
	}

	return (true);

}

function CheckAdminNewsflashForm(theForm) {

	var sMessage = '';

	if ((theForm.Heading.value != '') || (theForm.Message.value != '')) {

		var aFields = new Array ( 
			{name:"Message",message:"- Message"}
		);

		for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
			var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
			if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
		}

		if (sMessage != '') {
			alert('Please ensure that the following fields are completed\n\n' + sMessage);
			for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
				var oTemp = eval('theForm.' + aFields[iLoop].name);
				if (oTemp.value == '') { oTemp.focus(); }
			}
			return (false);
		}

	}


}

function CheckDigits(theField) {

	for (var iCount = 0; iCount < theField.value.length; iCount++) {
		var iTest = parseInt(theField.value.substring(iCount,iCount+1));
		if (isNaN(iTest)) {
			alert('This field can only accept numeric digits as input.');
			var sTemp = '';
			for (var iCount = 0; iCount < theField.value.length; iCount++) {
				var iTest = parseInt(theField.value.substring(iCount,iCount+1));
				if (!isNaN(iTest)) {
					sTemp += theField.value.substring(iCount,iCount+1);
				}
			}
			theField.value = sTemp;
			theField.focus();
			return (false);
		}
	}

	return (true);

}

function CheckBasketForm(theForm) {

	for (var iCount = 0; iCount < theForm.length; iCount++) {
		if (theForm.elements[iCount].name.substring(0,3) == "txt") {
			if ((theForm.elements[iCount].value == '') || (theForm.elements[iCount].value == '0')) {
				alert('Order Quantities cannot be blank or zero.');
				theForm.elements[iCount].focus();
				return (false);
			}
		}
	}	

	return (true);

}

function CheckOrderForm(theForm) {

	var sMessage = '';

	var aFields = new Array ( 
		{name:"Contact",message:"- Contact Name"}, 
		{name:"Telephone",message:"- Telephone"}
	);

	for (var iLoop = 0; iLoop < aFields.length; iLoop++) {
		var sTemp = eval('theForm.' + aFields[iLoop].name + '.value');
		if (sTemp == '') { sMessage += aFields[iLoop].message + '\n'; }
	}

	if (sMessage != '') {
		alert('The following fields are missing from the order form:\n\n' + sMessage + '\nPlease complete them and then submit your order again.');
		for (var iLoop = aFields.length-1; iLoop >= 0; iLoop--) {
			var oTemp = eval('theForm.' + aFields[iLoop].name);
			if (oTemp.value == '') { oTemp.focus(); }
		}
		return (false);
	}

	if (!theForm.elements[4].checked && !theForm.elements[5].checked && !theForm.elements[6].checked && !theForm.elements[7].checked) {
		alert("Please select a value for the \"Payment Method\" field and then submit your order again.");
		return (false);
	}

	if (!theForm.elements[8].checked && !theForm.elements[9].checked) {
		alert("Please select a value for the \"Delivery Method\" field and then submit your order again.");
		return (false);
	}

	if (theForm.elements[8].checked && (theForm.elements[10].value=='')) {
		alert("Please enter a value for the \"Delivery Address\" field and then submit your order again.");
		return (false);
	}

	return (confirm('You have read and agree to the Terms and Conditions\nand you wish to place your order now.'));

}