function clickEditWithChanges()
{
	if (!confirm("Changes have already been made to this item and are awaiting approval.\nIf you continue these changes may be lost.\nAre you sure you wish to edit this item?"))
		return false;
}

function clickApproveEdit()
{
	if (!confirm("This action can not be easily reversed.\nAre you approving these changes?"))
		return false;
}

function clickRefuseEdit()
{
	if (!confirm("Refusing this item or changes will delete them.\nAre you ABSOLUTELY SURE you wish to refuse this item or changes?"))
		return false;
}

function clickCheckReason()
{
	var objFieldReason, strProcessed;
	
	objFieldReason = document.getElementById("fieldReason");
	strProcessed = objFieldReason.value;
	strProcessed = strProcessed.replace(/^\s+|\s+$/g, '');
	
	if (strProcessed.length < 10)
	{
		alert("The reason you have given for this deletion request is too short!\nInvalid reasons will result in the request being ignored.\nPlease expand on your reason and try again!");
		return false;
	}
	
	return true;
}

function clickCheckReportReason()
{
	var objFieldReason, strProcessed;
	
	objFieldReason = document.getElementById("fieldReason");
	strProcessed = objFieldReason.value;
	strProcessed = strProcessed.replace(/^\s+|\s+$/g, '');
	
	if (strProcessed.length < 10)
	{
		alert("The reason you have given for this complaint is too short!\nInvalid reasons will result in the request being ignored.\nPlease expand on your reason and try again!");
		return false;
	}
	
	return true;
}

function clickCheckDeleteAndReason()
{
	if (!clickCheckReason())
		return false;
		
	if (!confirm("Agreeing to delete this item cannot be easily undone.\nAre you sure you wish to proceed?"))
		return false;
}

function clickCheckClose()
{
	if (!confirm("Are you sure you want to CLOSE this support request?"))
		return false;
}

function clickCheckAttachId()
{
	var objFieldId, strProcessed;
	
	objFieldId = document.getElementById("fieldAttachId");
	strProcessed = objFieldId.value;
	strProcessed = strProcessed.replace(/^\s+|\s+$/g, '');
	
	if (strProcessed.length < 10)
	{
		alert("You must enter a valid 10 digit Unique ID Code!\nPlease enter more digits and try again!");
		return false;
	}
	
	if (strProcessed.search(/[^0-9]+/) != -1)
	{
		alert("You must enter a valid 10 digit Unique ID Code!\nPlease edit the ID code and try again!");
		return false;
	}
	
	return true;
}

function clickCheckTitle()
{
	var objFieldTitle;
	
	objFieldTitle = document.getElementById("fieldTitle");
	if (objFieldTitle && objFieldTitle.value.length < 5)
	{
		alert("The title of any item must be at least 5 characters long!\nPlease edit the title and try again!");
		return false;
	}
		
	return true;
}

function clickCheckTitleAndTags()
{
	var objFieldTitle;
	
	objFieldTitle = document.getElementById("fieldTitle");
	if (objFieldTitle && objFieldTitle.value.length < 5)
	{
		alert("The title of any item must be at least 5 characters long!\nPlease edit the title and try again!");
		return false;
	}
		
	return clickCheckTags();
}

function clickCheckBodyTitleAndTags(objBody)
{
	if (objBody && objBody.value.length < 5)
	{
		alert("The body of any item must be at least 5 characters long!\nPlease edit the body of this item and try again!");
		return false;
	}
	
	return clickCheckTitleAndTags();
}

function clickSubmitFormBody(strID)
{
	var strBody, objBody;
	
	if (document.getElementById("fieldBody"))
		strBody = "fieldBody";
	else if (document.getElementById("fieldComment"))
		strBody = "fieldComment";
	else if (document.getElementById("fieldDescription"))
		strBody = "fieldDescription";
		
	objBody = document.getElementById(strBody);
	
	if (objBody && strBody && tinyMCE)
		objBody.value = tinyMCE.get(strBody).getContent();
		
	if (document.getElementById(strID))
	{
		if (clickCheckBodyTitleAndTags(objBody))
			document.getElementById(strID).submit();
		else
			return false;
	}
}

function clickCheckTags()
{
	var objFieldTags, strProcessed;
	
	objFieldTags = document.getElementById("fieldTags");
	if (!objFieldTags)
		return true;
	strProcessed = objFieldTags.value;
	
	strProcessed = strProcessed.replace(/`/g, "'");
	strProcessed = strProcessed.replace(/´/g, "'");
	strProcessed = strProcessed.replace(/‘/g, "'");
	strProcessed = strProcessed.replace(/’/g, "'");
	
	strProcessed = strProcessed.replace(/^\s+|\s+$/g, '');
	
	if (strProcessed.length == 0)
	{
		objFieldTags.value = strProcessed;
		alert("You must enter at least one tag!\nPlease double check the list of tags you wish to submit and try again!")
		return false;
	}
	
	if (strProcessed.search(/[^-a-zA-Z0-9.&' \r\n]+/) != -1)
	{
		strProcessed = strProcessed.replace(/,/g, "\r\n");
		strProcessed = strProcessed.replace(/;/g, "\r\n");
		strProcessed = strProcessed.replace(/[æ]/g, "ae");
		strProcessed = strProcessed.replace(/&#230;/g, "ae");
		strProcessed = strProcessed.replace(/[Æ]/g, "AE");
		strProcessed = strProcessed.replace(/&#198;/g, "AE");
		strProcessed = strProcessed.replace(/[àâäåãá]/g, "a");
		strProcessed = strProcessed.replace(/&#22[4-9];/g, "a");
		strProcessed = strProcessed.replace(/[ÂÄÀÅÃÁ]/g, "A");
		strProcessed = strProcessed.replace(/&#19[23567];/g, "A");
		strProcessed = strProcessed.replace(/[ç]/g, "c");
		strProcessed = strProcessed.replace(/&#231;/g, "c");
		strProcessed = strProcessed.replace(/[Ç]/g, "C");
		strProcessed = strProcessed.replace(/&#199;/g, "C");
		strProcessed = strProcessed.replace(/[éèêë]/g, "e");
		strProcessed = strProcessed.replace(/&#23[2-5];/g, "e");
		strProcessed = strProcessed.replace(/[ÉÊËÈ]/g, "E");
		strProcessed = strProcessed.replace(/&#20[0-3];/g, "E");
		strProcessed = strProcessed.replace(/[ïîìí]/g, "i");
		strProcessed = strProcessed.replace(/&#23[6-9];/g, "i");
		strProcessed = strProcessed.replace(/[ÏÎÌÍ]/g, "I");
		strProcessed = strProcessed.replace(/&#20[4-7];/g, "I");
		strProcessed = strProcessed.replace(/[ñ]/g, "n");
		strProcessed = strProcessed.replace(/&#241;/g, "n");
		strProcessed = strProcessed.replace(/[Ñ]/g, "N");
		strProcessed = strProcessed.replace(/&#209;/g, "N");
		strProcessed = strProcessed.replace(/[öôóòõ]/g, "o");
		strProcessed = strProcessed.replace(/&#24[2-6];/g, "o");
		strProcessed = strProcessed.replace(/[ÓÔÖÒÕ]/g, "O");
		strProcessed = strProcessed.replace(/&#21[0-4];/g, "O");
		strProcessed = strProcessed.replace(/[ùûüú]/g, "u");
		strProcessed = strProcessed.replace(/&#249;/g, "u");
		strProcessed = strProcessed.replace(/&#25[0-2];/g, "u");
		strProcessed = strProcessed.replace(/[ÜÛÙÚ]/g, "U");
		strProcessed = strProcessed.replace(/&#21[7-9];/g, "U");
		strProcessed = strProcessed.replace(/&#220;/g, "U");
		strProcessed = strProcessed.replace(/[ýÿ]/g, "y");
		strProcessed = strProcessed.replace(/&#25[35];/g, "y");
		strProcessed = strProcessed.replace(/[Ý]/g, "Y");
		strProcessed = strProcessed.replace(/&#221;/g, "Y");
		
		strProcessed = strProcessed.replace(/[^-a-zA-Z0-9.&' \r\n]+/g, "");
		
		objFieldTags.value = strProcessed;
		alert("Some of the tags you have entered contain illegal characters, these have been removed or converted to acceptable equivalents.\nPlease double check the list of tags you wish to submit and try again!")
		return false;
	}
	else
		objFieldTags.value = strProcessed;
	
	return true;
}

function clickCheckNewAccountBoxes()
{
	var objFormField, objFormField2;
	
	objFormField = document.getElementById("fieldUserLogin");
	if (!clickCheckAlphaNumeric(objFormField.value))
	{
		alert("Your Login Name can only contain letters and numbers.\nPlease double check the Login Name you entered does not contain illegal characters, and try again!")
		return false;
	}
	if (objFormField.value.length < 5)
	{
		alert("Your new Login Name must be at least 5 characters or longer.\nPlease double check the Login Name you entered, and try again!");
		return false;
	}
	
	objFormField = document.getElementById("fieldUserPassword");
	if (!clickCheckAlphaNumeric(objFormField.value))
	{
		alert("Your Password can only contain letters and numbers.\nPlease double check the Password you entered does not contain illegal characters, and try again!")
		return false;
	}
	if (objFormField.value.length < 5)
	{
		alert("Your Password must be at least 5 characters or longer.\nPlease double check the Password you entered, and try again!");
		return false;
	}
	objFormField2 = document.getElementById("fieldConfirmUserPassword");
	if (objFormField.value != objFormField2.value)
	{
		alert("The second Password you entered in the Confirm password box does not match the one in the Your Password box.\nPlease double check the Confirmed Password you entered, and try again!")
		return false;
	}
	
	objFormField = document.getElementById("fieldUserEmail");
	if (objFormField.value.length < 7)
	{
		alert("Your Email Address must be valid for you to activate your account, and be at least 7 characters or longer.\nPlease double check the Email Address you entered, and try again!");
		return false;
	}
	
	return true;
}

function clickCheckUpdateAccountBoxes()
{
	var objFormField, objFormField2;
	
	objFormField = document.getElementById("fieldUserLogin");
	if (!clickCheckAlphaNumeric(objFormField.value))
	{
		alert("Your Login Name can only contain letters and numbers.\nPlease double check the Login Name you entered does not contain illegal characters, and try again!")
		return false;
	}
	if (objFormField.value.length < 5)
	{
		alert("Your new Login Name must be at least 5 characters or longer.\nPlease double check the Login Name you entered, and try again!");
		return false;
	}
	
	objFormField = document.getElementById("fieldUserPassword");
	if (!clickCheckAlphaNumeric(objFormField.value))
	{
		alert("Your Password can only contain letters and numbers.\nPlease double check the Password you entered does not contain illegal characters, and try again!")
		return false;
	}
	if (objFormField.value.length < 5)
	{
		alert("Your Password must be at least 5 characters or longer.\nPlease double check the Password you entered, and try again!");
		return false;
	}
	
	objFormField = document.getElementById("fieldNewUserPassword");
	if (objFormField.value.length > 0)
	{
		if (objFormField.value.length < 5)
		{
			alert("Your new Password must be at least 5 characters or longer.\nPlease double check the new Password you entered, and try again!");
			return false;
		}
		if (!clickCheckAlphaNumeric(objFormField.value))
		{
			alert("Your New Password can only contain letters and numbers.\nPlease double check the new Password you entered does not contain illegal characters, and try again!")
			return false;
		}
		if (objFormField.value.length < 5)
		{
			alert("Your New Password must be at least 5 characters or longer.\nPlease double check the new Password you entered, and try again!");
			return false;
		}
		objFormField2 = document.getElementById("fieldConfirmUserPassword");
		if (objFormField.value != objFormField2.value)
		{
			alert("The second Password you entered in the Confirm password box does not match the one in the Your New Password box.\nPlease double check the Confirmed Password you entered, and try again!")
			return false;
		}
	}
	
	objFormField = document.getElementById("fieldUserEmail");
	if (objFormField.value.length < 7)
	{
		alert("Your Email Address must be valid for you to activate your account, and be at least 7 characters or longer.\nPlease double check the Email Address you entered, and try again!");
		return false;
	}
	
	return true;
}

function clickCheckAlphaNumeric(strProcessed)
{
	if (strProcessed.search(/[^-a-zA-Z0-9'\s]+/) != -1)
		return false;
	
	return true;
}

function clickInsertTagToField(strTag)
{
	var objFormField;
	
	objFormField = document.getElementById("fieldTags");
	objFormField.value = objFormField.value.replace(/^\s*|\s*$/g,'');
	objFormField.value += "\n" + strTag;
}

function keypressCheckEnter(e)
{
	if (window.event) // IE
	{
		if (e.keyCode == 13)
			return false;
	}
	else if (e.which) // Netscape/Firefox/Opera
	{
		if (e.which == 13)
			return false;
	}
	
	return true;
}

function clickCheckEmailSubjectAndBody()
{
	var objFormField, objFormField2;
	
	objFormField = document.getElementById("fieldTitle");
	if (objFormField.value.length < 5)
	{
		alert("The Subject of your email must be at least 5 characters or longer.\nPlease double check the Subject you wish to use for this message and try again!");
		return false;
	}
	
	objFormField = document.getElementById("fieldBody");
	if (objFormField.value.length < 5)
	{
		alert("The Body of your email must be at least 5 characters or longer.\nPlease double check the Body you wish to use for this message and try again!");
		return false;
	}
	
	return true;
}

function clickDecryptEmail(objHyperlink)
{
	var strHyperlink;
	
	strHyperlink = new String(objHyperlink.href);
	strHyperlink = strHyperlink.replace(/x\.([^.]*)\.x/g, "$1");
	strHyperlink = strHyperlink.replace(/mailto:/g, "");
	
	objHyperlink.href = "mailto:" + strHyperlink;
	objHyperlink.innerHTML = strHyperlink;
}

function eventCreateNewItem()
{
	var objStep2, objStep3;
	
	objStep2 = document.getElementById("Step3");
	objStep2.style.display = "none";
	objStep3 = document.getElementById("Step4");
	objStep3.style.display = "block";
}

function hoverSetOpacity(objItem, intPercentage)
{
	objItem.style.opacity = intPercentage / 100;
	objItem.style.filter = "alpha(opacity=" + intPercentage + ")";
}

function changeImage(objSourceBox, strTargetImage)
{
	var strSrc, objImageTarget;
	
	objImageTarget = document.getElementById(strTargetImage);
	strSrc = objImageTarget.src.match(/.*\//);
	objImageTarget.src = strSrc + objSourceBox.value;
}

function changeColour(objSourceBox, strTargetClass, intProperty)
{
	for (var i = 0; i < document.styleSheets.length; i ++)
	{
		var cssRules;
		
		if (document.styleSheets[i].cssRules)
			cssRules = document.styleSheets[i].cssRules;
		else if (document.styleSheets[i].rules)
			cssRules = document.styleSheets[i].rules;
			
		for (var u = 0; u < cssRules.length; u++)
		{
			if (cssRules[u].selectorText.toLowerCase() == strTargetClass)
			{
				switch (intProperty)
				{
					case 1:
						cssRules[u].style.color = objSourceBox.value;
						break;
					case 2:
						cssRules[u].style.backgroundColor = objSourceBox.value;
						break;
					case 3:
						cssRules[u].style.borderTop = "1px solid " + objSourceBox.value;
						break;
					case 4:
						cssRules[u].style.borderBottom = "1px solid " + objSourceBox.value;
						break;
				}
			}
		}
	}
}

var arrayCoverFiles = new Array(9);

function checkCoverFile()
{
	var objCheckBox;
	
	objCheckBox = document.getElementById("fieldCoverBox");
	if (objCheckBox.checked == true)
	{
		if (!confirm("You can only upload one image when adding a cover. Do you wish to continue?"))
		{
			objCheckBox.checked = false;
			return;
		}
		for (var u = 1; u < 10; u++)
		{
			var objFormField = document.getElementById("idFile" + u);
			arrayCoverFiles[u - 1] = objFormField.value;
			objFormField.value = "";
			objFormField.disabled = true;
		}
	}
	else
	{
		for (var u = 1; u < 10; u++)
		{
			var objFormField = document.getElementById("idFile" + u);
			try
			{
				objFormField.value = arrayCoverFiles[u - 1];
			}
			catch (error)
			{
				// Have to catch this as firefox's security settings won't let it happen and will error
			}
			
			objFormField.disabled = false;
		}
	}
}

var tickerTimeout;

function rotateFlicker()
{
	for (var u = 1; u < 10; u ++)
	{
		var objDiv;
		
		objDiv = document.getElementById("flicker" + u);
		if (objDiv)
		{
			if (objDiv.style.display != "none")
			{
				var objNextDiv;
				
				objNextDiv = document.getElementById("flicker" + (u + 1));
				if (!objNextDiv)
					objNextDiv = document.getElementById("flicker1");
				objDiv.style.display = "none";
				objNextDiv.style.display = "block";
				
				rotateFlickerStart();
				return;
			}
		}
		else
		{
			// No flickers here, move along
			if (u == 0)
				return;
		}
	}
}

function rotateFlickerStart()
{
	tickerTimeout = setTimeout("rotateFlicker()", 4000);
}

function rotateFlickerStop()
{
	if (tickerTimeout)
	{
		clearTimeout(tickerTimeout);
		tickerTimeout = null;
	}
}
