var errorboxid = -1;
			 function filterString(str) {
				  re = /\$|\_|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\s|\?|\||\\|\!|\$|\./g;
				  // remove special characters like "$" and "," etc...
				  return str.replace(re, "");
			 }

			function suggestURL()
			{
				var title1 = document.getElementById('title1').value;
				var url = document.getElementById('url_title').value;
				
				if(title1 != "" && url == "" && title1 != "Home")
				{
					string = filterString(title1);
					document.getElementById('url_title').value = string.toLowerCase();
				}
			}

			function validatePage()
			{
				var status = true;
				var msg = '';
				var id = '';
				var section = 0;

				var title1 = document.getElementById('title1').value;
				var url_title = document.getElementById('url_title').value;

				if(isEmpty(title1))
				{
					msg = 'Please enter in a title for this page.';
					id = 'title1';
					section = 1;

					status = false;
				}
				else if(isEmpty(url_title))
				{
					msg = 'Please enter in a URL for this page.';
					id = 'url_title';
					section = 1;

					status = false;
				}
				else if(!isAlphaNumeric(url_title))
				{
					msg = 'The page URL must contain only alpha numerical data.';
					id = 'url_title';
					section = 1;

					status = false;
				}

				if(!status)
				{
					toggleJavascriptError(msg, id, section);
				}

				return status;
			}
			
			function validatePanel()
			{
				var title = document.getElementById('title').value;
				
				var status = true;
				var msg = '';
				var id = '';
				var section = 0;

				if(isEmpty(title))
				{
					msg = 'Please enter in a title for this panel.';
					id = 'title';
					section = 1;

					status = false;
				}
				else if(!isAlphaNumeric(title))
				{
					msg = 'The panel title must contain only alpha numerical data.';
					id = 'title';
					section = 1;

					status = false;
				}

				if(!status)
				{			
					toggleJavascriptError(msg, id, section);
				}

				return status;
			}
			
			function toggleJavascriptError(msg, id, section, setfocus)
			{
					/*
					Clear other messages
					*/
					var flag = true;
					var i=0;
					while(flag)
					{
						if(document.getElementById('msg'+i))
							document.getElementById('msg'+i).style.display = 'none';
						else
							flag = false;

						i++;
					}

					if(document.getElementById(id+'box'))
						document.getElementById(id+'box').style.border = '1px solid #ca5d5d';
					
					if(document.getElementById('msg'+section))
					{
						document.getElementById('msg'+section).style.display = 'block';
						document.getElementById('msg'+section).innerHTML = msg;
					}

					if(document.getElementById('msg'))
					{
						document.getElementById('msg').style.display = 'block';
						document.getElementById('msg').innerHTML = msg;
					}

					if(section != null)
						tabs.showSection(section);

					if(errorboxid != -1 && errorboxid != id)
					{
						if(document.getElementById(errorboxid+'box'))
							document.getElementById(errorboxid+'box').style.border = '1px solid #cccccc';
					}

					if(setfocus == true)
						document.getElementById(id).focus();

					errorboxid = id;
			}
			
			function isEmpty(str)
			{
				return (str == null) || (str.length == 0);
			}
			
			function isEmail(str)
			{
				if(isEmpty(str)) return false;
			
				var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
			
				return re.test(str);
			}

			function isAlphaNumeric(str)
			{
				var re = /[^a-zA-Z0-9]/g
				
				
				if (re.test(str))
				{			
					return false;
				}
				else
				{
					return true;
				}
			}
			
			function isNumeric(str)
			{
				var re = /[^\. 0-9]/g
				
				if (re.test(str)) return false;
				
				return true;
			}

			function isPrice(str)
			{
				var re = /[^\. \$ 0-9]/g
				
				if (re.test(str)) return false;
				
				return true;
			}

			function isAlpha(str)
			{
				var re = /[^a-zA-Z]/g
				
				if (re.test(str)) return false;
			
				return true;
			}
			
			function isImage(str)
			{
				if (!/(\.(jpg|jpeg|png))$/i.test(str)) return false;
				
				return true;
			}

			function validateDVCMSUser(usesTabs)
			{
				if(usesTabs == "" || usesTabs == null)
					usesTabs = "true";

				var username = document.getElementById('username').value;
				var password = document.getElementById('password').value;
				var thename = document.getElementById('name').value;
				var email = document.getElementById('email').value;

				var anyPrivileges = false;
				var pCount = 0;
				
				var ins = document.getElementsByTagName('input')
				var i;
				for(i=0;i<ins.length;i++)
				{
					if(ins[i].type=="checkbox")
					{
						if(ins[i].checked == true)
							anyPrivileges = true;
						
						pCount++;
					}
				}
				
				if(pCount == 0) anyPrivileges = true;

				var status = true;
				var msg = '';
				var id = '';
				var section = 0;
				var setFocus = true;

				if(isEmpty(username))
				{
					msg = 'You must enter in a username.';
					id = 'username';
					section = 0;
					status = false;
				}
				else if(!isAlpha(username))
				{
					msg = 'Username must contain only alphabetical characters.';
					id = 'username';
					section = 0;
					status = false;
				}
				else if(isEmpty(password) && usesTabs != "false")
				{
					msg = 'You must enter in a password.';
					id = 'password';
					section = 0;
					status = false;
				}
				else if(!isAlpha(password) && usesTabs != "false")
				{
					msg = 'Password must contain only alphabetical characters.';
					id = 'password';
					section = 0;
					status = false;
				}
				else if(isEmpty(thename))
				{
					msg = 'You must enter in a name.';
					id = 'name';
					section = 0;
					status = false;
				}
				else if(isEmpty(email))
				{
					msg = 'You must enter in an email address.';
					id = 'email';
					section = 0;
					status = false;
				}
				else if(!isEmail(email))
				{
					msg = 'Your email address seems invalid.';
					id = 'email';
					section = 0;
					status = false;
				}
				else if(isEmpty(email))
				{
					msg = 'You must enter in an email address.';
					id = 'email';
					section = 0;
					status = false;
				}				
				else if(!anyPrivileges)
				{
					msg = 'You must select at least one privilege for the user.';
					id = '';
					section = 1;
					status = false;
					setFocus = false;
				}
				else
				{
					status = true;
				}

				if(!status)
				{
					if(usesTabs == "false")
						section = null;

					toggleJavascriptError(msg, id, section, setFocus);
				}

				return status;
			}
			
			function validateCustomer(form)
			{
				username = document.getElementById('username').value;
				password = document.getElementById('password').value;
				school = document.getElementById('school').value;
				email = document.getElementById('email').value;
				phone = document.getElementById('phone').value;
				firstname = document.getElementById('firstname').value;
				lastname = document.getElementById('lastname').value;
				address = document.getElementById('address').value;
				suburb = document.getElementById('suburb').value;
				city = document.getElementById('city').value;
				postcode = document.getElementById('postcode').value;
				country = document.getElementById('country').value;
				state_specific = document.getElementById('state_specific').value;
				
				var status = true;

				var setFocus = true;

				if(isEmpty(username))
				{
					msg = 'You must enter in a username.';
					id = 'username';
					section = 0;
					status = false;
				}
				else if(username.length < 3)
				{
					msg = 'The username must be at least 3 characters long.';
					id = 'username';
					section = 0;
					status = false;
				}
				else if(!isAlphaNumeric(username))
				{
					msg = 'The username must contain only alphabetical characters.';
					id = 'username';
					section = 0;
					status = false;
				}
				else if(isEmpty(password))
				{
					msg = 'You must enter in a password.';
					id = 'password';
					section = 0;
					status = false;
				}
				else if(password.length < 3)
				{
					msg = 'The password must be at least 3 characters long.';
					id = 'password';
					section = 0;
					status = false;
				}
				else if(isEmpty(firstname))
				{
					msg = 'You must enter in a first name.';
					id = 'firstname';
					section = 0;
					status = false;
				}
				else if(isEmpty(lastname))
				{
					msg = 'You must enter in a last name.';
					id = 'lastname';
					section = 0;
					status = false;
				}
				else if(!isEmpty(phone) && !isNumeric(phone))
				{
					msg = 'Your phone number must contain only numerical data.';
					id = 'firstname';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(isEmpty(email))
				{
					msg = 'You must enter in a email address.';
					id = 'email';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(!isEmail(email))
				{
					msg = 'Please check that the email address is a valid one.';
					id = 'email';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(isEmpty(address))
				{
					msg = 'You must enter in an address.';
					id = 'address';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(isEmpty(suburb))
				{
					msg = 'You must enter in a suburb.';
					id = 'suburb';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(isEmpty(postcode))
				{
					msg = 'You must enter in a postcode.';
					id = 'postcode';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(!isNumeric(postcode))
				{
					msg = 'The postcode must contain only numerical data.';
					id = 'postcode';
					section = 1;
					status = false;
					setFocus = false;
				}
				else if(isEmpty(city))
				{
					msg = 'You must enter in a city.';
					id = 'city';
					section = 1;
					status = false;
					setFocus = false;
				}				
				else if(country != "Australia" && isEmpty(state_specific))
				{
					msg = 'You must enter in a state.';
					id = 'state';
					section = 1;
					status = false;
					setFocus = false;
				}
				else
				{
					status = true;
				}
				
				if(!status)
				{			
					toggleJavascriptError(msg, id, section, setFocus);
				}

				return status;
			}
			
			function validateCategory()
			{
				category = document.getElementById('category').value;
				image = document.getElementById('image').value
				
				var status = true;
				var msg = '';
				var id = '';
				var section = 0;
				var setFocus = true;

				if(isEmpty(category))
				{
					msg = 'You must enter in a category name.';
					id = 'category';
					section = null;
					status = false;
				}
				else if(!isEmpty(image) && !isImage(image))
				{
					msg = 'The image must be either a JPG or PNG file.';
					id = 'image';
					section = null;
					status = false;					
				}
				else
				{
					status = true;
				}
				
				if(!status)
				{			
					toggleJavascriptError(msg, id, section, setFocus);
				}

				return status;
			}

			function returnSelectedMultiple(field)
			{
				len = field.length
				i = 0
				chosen = new Array();
				j = 0;

				for (i = 0; i < len; i++)
				{
					if (field[i].selected)
					{
						chosen[j] = field[i].value;
						j++;
					}
				}

				return chosen
			}

			
			function returnCheckboxValues(field)
			{
				len = field.length
				i = 0
				chosen = new Array();
				j = 0;

				for (i = 0; i < len; i++)
				{
					if (field[i].checked)
					{
						chosen[j] = field[i].value;
						j++;
					}
				}

				return chosen
			} 

			function validateProduct()
			{
				var status = true;
				var msg = '';
				var id = '';
				var section = 0;
				var setFocus = true;

				if(document.getElementById('code'))
					code = document.getElementById('code').value;
					
				if(document.getElementById('name'))
					pname = document.getElementById('name').value;

				if(document.getElementById('price'))
				{
					price = document.getElementById('price').value;
					price = price.replace("$","");
				}
				
				if(document.getElementById('specialPrice'))
				{
					specialPrice = document.getElementById('specialPrice').value;
					specialPrice = specialPrice.replace("$","");
				}
				
				if(document.getElementById('stockLevel'))
					stockLevel = document.getElementById('stockLevel').value;
				
				if(document.getElementById('weight'))
					weight = document.getElementById('weight').value;
				
				if(document.getElementById('images'))
					images = document.getElementById('images').value;
				
				if(document.getElementById('colours'))
				{
					colours = document.getElementById('colours');
					colourArr = returnSelectedMultiple(colours);
				}
				else
				{
					colourArr = "";
				}

				if(document.getElementById('specificColours'))
					specificColours = document.getElementById('specificColours').value;
				else
					specificColours = "";

				sizeFlag = false;

				if(document.getElementById('sizes'))
				{			
					for(i=0;i<document.getElementsByTagName("input").length;i++)
					{
						if(document.getElementsByTagName("input")[i].type == "checkbox")
						{
							if(document.getElementsByTagName("input")[i].checked == true)
							{
								if(document.getElementsByTagName("input")[i].name == "sizes[]")
									sizeFlag = true;
							}
						}
					}
				}

				if(document.getElementById('categories'))
				{
					var categories = document.getElementById('categories');
					catArr = returnSelectedMultiple(categories);
				}
				else
				{
					catArr = ""
				}

				imgFlag = true;
				imgMsg = '';
				imgId = '';
				imgSection = '';
				for(i=0;i<10;i++)
				{
					if(document.getElementById('image'+i))
					{
						theimage = document.getElementById('image'+i).value;
						if(!isEmpty(theimage) && !isImage(theimage))
						{
							imgFlag = false;
							imgMsg = 'The image must be of the format JPG or PNG.';
							imgId = 'image'+i;
							imgSection = 5;

							break;
						}
					}
				}

				if(isEmpty(code))
				{
					msg = 'Please enter in a product code.';
					id = 'code';
					section = 0;

					status = false;
				}		
				else if(isEmpty(pname))
				{
					msg = 'Please enter in a name for this product.';
					id = 'name';
					section = 0;

					status = false;
				}
				else if(isEmpty(price))
				{
					msg = 'Please enter in a price.';
					id = 'price';
					section = 0;

					status = false;
				}
				else if(!isPrice(price))
				{
					msg = 'Product price must contain only numerical values.';
					id = 'price';
					section = 0;

					status = false;
				}
				else if((!isEmpty(specialPrice) && !isPrice(specialPrice)) && document.getElementById('specialPrice'))
				{
					msg = 'Special Price must contain only numerical values.';
					id = 'specialPrice';
					section = 0;

					status = false;
				}
				else if(catArr.length == 0)
				{
					msg = 'You must select at least one category for this product.';
					id = 'categories';
					section = 1;
					setFocus = false;

					status = false;
				}
				else if(imgFlag == false)
				{
					msg = imgMsg;
					id = imgId;
					section = imgSection;
					setFocus = false;
					status = false;
				}
				else
				{
					status = true;
				}
				
				if(!status)
				{			
					toggleJavascriptError(msg, id, section, setFocus);
				}

				return status;

				/*
				else if((isEmpty(specificColours) && colourArr.length == 0) && document.getElementById('colours'))
				{
					msg = 'You must select or enter in one colour for this product.';
					id = 'specificColours';
					section = 2;
					setFocus = false;

					status = false;
				}
				else if((sizeFlag == false) && document.getElementById('sizes'))
				{
					msg = 'You must select at least one size for this product';
					id = 'sizes';
					section = 3;
					setFocus = false;

					status = false;
				}
				*/
			
			}

			function checkExternalLink()
			{
				var elink = document.addeditbanner.externalurl.value;
				var ilink = document.addeditbanner.internalurl.value;

				if(ilink == "")
				{
					document.addeditbanner.externalurl.disabled = false;
				}
				else
				{
					document.addeditbanner.externalurl.disabled = true;
					document.addeditbanner.externalurl.value = "http://";
				}
			}
			
			function checkInternalExternalLinks()
			{
				var nolink = document.addeditbanner.nolink.checked;
				
				if(nolink)
				{
					document.addeditbanner.internalurl.value = "";
					document.addeditbanner.externalurl.value = "http://";
					
					document.addeditbanner.externalurl.disabled = true;
					document.addeditbanner.internalurl.disabled = true;
				}
				else
				{
					document.addeditbanner.externalurl.disabled = false;
					document.addeditbanner.internalurl.disabled = false;				
				}
			}
			
			function validateBanner()
			{
				var image = document.getElementById('image').value;

				var status = true;
				var msg = '';
				var id = '';
				var section = 0;
				var setFocus = true;
				
				if(isEmpty(image))
				{
					msg = 'You must select an image for this banner';
					id = 'image';
					section = null;
					setFocus = false;
					status = false;
				}
				else if(!isImage(image))
				{
					msg = 'The image must be either a JPG or PNG file';
					id = 'image';
					section = null;
					setFocus = false;
					status = false;
				}
				else
				{
					status = true;
				}
				
				if(!status)
				{			
					toggleJavascriptError(msg, id, section, setFocus);
				}

				return status;
			}

	function confirmDel()
	{
		return confirm("Are you sure you want to delete this item?");
	}

	function confirmUserDelete()
	{
		return confirm("Are you sure you want to delete this user?");
	}

	function confirmNewsletterDelete()
	{
		return confirm("Are you sure you want to delete this newsletter?\nThis can not be undone.");
	}

	function confirmCustomerDelete()
	{
		return confirm("Are you sure you want to delete this Customer?\nThis can not be undone.");
	}

	function confirmCancel()
	{
		return confirm("Are you sure you want to cancel? All changes will be lost.");
	}

	function confirmSend()
	{
		return confirm("Are you sure you want to send this newsletter?");
	}

	function alertNoDel()
	{
		alert("You can not delete this item.");
		return false;
	}

	function alertNoEdit()
	{
		alert("You can not edit this item.");
		return false;
	}
	
	function selectAllPrivileges(field)
	{
		var flag = true;
		
		if(field[0].checked != true)
			flag = false;
		
		for (i=0; i < field.length; i++)
		{
			field[i].checked = flag;
		}
	}
	

	function autogenerateCustomerPwd()
	{	
		var keylist="abcdefghijklmnopqrstuvwxyz123456789"
		var temp=''

		for (i=0;i<7;i++)
			temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
		

		document.custform.password.value = temp;
	}
	
	function toggleSpecificState(specCountry)
	{
		country = document.getElementById('country').value;
		
		if(specCountry != "")
			country = specCountry;

		if(country == "Australia")
		{
			document.getElementById('state_specific').style.display = 'none';
			document.getElementById('state').style.display = 'block';
		}
		else
		{
			document.getElementById('state_specific').style.display = 'block';
			document.getElementById('state').style.display = 'none';
		}
	}
	
	function selectProduct(prodid)
	{
		var productid = document.getElementById(prodid).value;

		if(productid == "true")
		{
			document.getElementById(prodid).value = "false";
			document.getElementById('tick'+prodid).style.display = 'none';
			document.getElementById('td1'+prodid).style.background = 'transparent';
			document.getElementById('td2'+prodid).style.background = 'transparent';
			document.getElementById('td3'+prodid).style.background = 'transparent';
		}
		else
		{
			document.getElementById(prodid).value = "true";
			document.getElementById('tick'+prodid).style.display = 'block';
			document.getElementById('td1'+prodid).style.background = '#e6edf5';
			document.getElementById('td2'+prodid).style.background = '#e6edf5';
			document.getElementById('td3'+prodid).style.background = '#e6edf5';
		}

	}
	
	function textCounter(field,cntfield,maxlimit)
	{
		if (field.value.length > maxlimit)
			field.value = field.value.substring(0, maxlimit);
		else
			cntfield.value = maxlimit - field.value.length;
	}
	
	function toggleNewsletterOptions(id)
	{
		options = new Array("locations","specific");
		
		for(i=0;i<options.length;i++)
		{
			document.getElementById(options[i]).style.display = 'none';
		}
		
		if(id != "")
			document.getElementById(id).style.display = 'block';
	}
	
	function showYearMonths(theyear, thetype, themonth)
	{
		var yearz = new Array("2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018","2019","2020");
		
		for(i=0;i<yearz.length;i++)
		{
			if(document.getElementById('monthRow'+thetype+yearz[i]))
				document.getElementById('monthRow'+thetype+yearz[i]).style.display = 'none';
			
			if(document.getElementById('year'+thetype+yearz[i]))
				document.getElementById('year'+thetype+yearz[i]).style.textDecoration = 'none';
		}
		
		if(document.getElementById('monthRow'+thetype+theyear))
			document.getElementById('monthRow'+thetype+theyear).style.display = 'block';
	
		if(document.getElementById('year'+thetype+theyear))
			document.getElementById('year'+thetype+theyear).style.textDecoration = 'underline';
			
		if(document.getElementById(theyear+'month'+thetype+themonth))
			document.getElementById(theyear+'month'+thetype+themonth).style.textDecoration = 'underline';
	}
	
	function openNewVersionWindow(url, type)
	{
		var pagehistoryid = document.getElementById('pagehistoryid').value;
		
		var finalURL = url + "&pagehistoryid="+pagehistoryid;
		
		if(type == "View")
		{
			finalURL = finalURL + "&viewHistory=true";
			window.open(finalURL,'viewHistory');
		}
		else if(type == "Restore")
		{
			finalURL = finalURL + "&restoreHistory=true";
			window.location.href = finalURL;
		}
	}
	
function validateInterShipping()
{
	var shippingtotal = document.getElementById('shippingtotal').value
	shippingtotal = shippingtotal.replace("$","");
	
	if(shippingtotal == "")
	{
		alert("Please enter in a shipping cost.");
		return false;
	}
	else
	{
		return true;
	}
}