function SwapIMG(imageName, image, imagePath)
{
	if (image.src == '')
	{
		image.src = imagePath;
	}
	document.images[imageName].src = image.src;
}

function validateForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.Name.value == ''))
	{
		alert('You must enter your Name so we can contact you');
		bValid = false;
	}

	if ((bValid) && (pForm.Email.value == ''))
	{
		alert('You must enter your Email Address so we can contact you');
		bValid = false;
	}

	else if (bValid)
	{
		bValid = validEmail(pForm.Email.value);
	}

	if ((bValid) && (pForm.Enquiry.value == ''))
	{
		alert('You must enter your Enquiry');
		bValid = false;
	}

	return bValid;
}

function getSkillDetail(pSkill)
{
	var sHTML = '';

	switch (pSkill)
	{
		case 'XHTML 1.1':
			sHTML = '<p class="tooltip">XHTML 1.1 is a widely accepted standard of coding your website similar to HTML.  It means that this website was built in a way which adheres to strict standards set out by the W3C Governing body.  Adhering to these standards helps with cross browser compatibility, and also with basic accessibility.  This is currently the highest standard a website can be coded to.</p>';
			break;
		case 'CSS 2':
			sHTML = '<p class="tooltip">CSS standards for Cascading Style Sheets and is a common method used to &quot;style&quot; a website.  CSS Level 2 is another of the W3Cs widely accepted standards when is comes to writing your CSS and is currently the highest available for CSS scripting.</p>';
			break;
		case 'C#':
			sHTML = '<p class="tooltip">C#.NET is a programming language that is part of Microsoft&acute;s .NET environment.  It controls any changing content, or dynamic functionality on a website and is commonly used to communicate with a database.</p>';
			break;
		case 'ASP.NET':
			sHTML = '<p class="tooltip">ASP.NET is a programming language that is part of Microsoft&acute;s .NET environment.  It controls any changing content, or dynamic functionality on a website and is commonly used to communicate with a database.</p>';
			break;
		case 'SQL':
			sHTML = '<p class="tooltip">SQL standards for Structured Query Language and is the programming language used when reading and writing data to and from a database.</p>';
			break;
		case 'MS SQL Server':
			sHTML = '<p class="tooltip">MS SQL Server is Microsoft&acute;s industry standard database.  It can be used to store all information associated with a website, and is fast and reliable.</p>';
			break;
		case 'JavaScript':
			sHTML = '<p class="tooltip">Javascript is a programming language that runs in your web browser.  It is generally used to change images and content on a page without the page having to reload.  Its also common used to check a form for incorrect/empty fields before its submitted.</p>';
			break;
		case 'AJAX':
			sHTML = '<p class="tooltip">AJAX is actually Javascript and allows you to retrieve information from a database, or any external source, without having to reload the page.  Commonly, a loading animation is shown whilst the content is collected by AJAX.</p>';
			break;
		case 'Google Mapping':
			sHTML = '<p class="tooltip">Google allow developers to integrate their mapping application into websites, and to populate the maps as required.  This allows offices, shops and any locations to be highlighted on a live interactive map.</p>';
			break;
		case 'WCAG AA':
			sHTML = '<p class="tooltip">WCAG stands for the Web Content Accessibility Guidelines and are accessibility guidelines provided by the W3C. These guidelines focus on making content accessible, primarily for disabled users, but also for all user agents such as mobile phones as well as normal web browsers.  There are varying levels of these standards - A, AA and AAA.</p>';
			break;
		case 'CMS':
			sHTML = '<p class="tooltip">Content Managed means that this website is powered by a Content Management System (CMS).  This allows users to securly edit the content of their website themselves, without any need to know website programming languages.  This interface is simple and allows a client to manage the content of their own website.</p>';
			break;
		case 'YouTube':
			sHTML = '<p class="tooltip">YouTube is one of the most famous user driven video sites.  Users are able to upload their own videos and watch them for free.  YouTube allow these videos to be embedded within other websites meaning video content can be included on your site if you want it to.</p>';
			break;
		case 'SSL':
			sHTML = '<p class="tooltip">SSL stands for Secure Socket Layer and is a way of securing all connections to your website.  When viewing a website with SSL your connection to that website is encrypted meaning your information cannot be read by anyone else.  It commnly used when entering credit card details, and you look for the padlock icon in your browser.</p>';
			break;
		case 'PHP':
			sHTML = '<p class="tooltip">PHP is an open source programming language used to create dynamic web pages.  It controls any changing content, or dynamic functionality on a website and is commonly used to communicate with a database.</p>';
			break;
		case 'ASP':
			sHTML = '<p class="tooltip">ASP, now known as Classic ASP after the introduction the .NET Framework is a Microsoft programming language used to create dynamic web pages.  It controls any changing content, or dynamic functionality on a website and is commonly used to communicate with a database.</p>';
			break;
		case 'MySQL':
			sHTML = '<p class="tooltip">MySQL is an open source database system.  It can be used to store all information associated with a website, and is fast and reliable.</p>';
			break;
		case 'Flash':
			sHTML = '<p class="tooltip">Flash is a multimedia platform that is popular for adding animation and interactivity to web pages.  A common use is for embedding and streaming video too.</p>';
			break;
		case 'XML':
			sHTML = '<p class="tooltip">XML is a text formatted document commonly used to define data and its structure within a website.  XML can be output from one page, and read on another allowing data to be transferred with ease.</p>';
			break;
		case 'RSS':
			sHTML = '<p class="tooltip">RSS stands for Really Simple Syndication and is actually a form of XML.  Its used to define and transmit news articles and their information and uses a common format allowing it to be read on many different platforms.</p>';
			break;
	}

	return sHTML;
}

function getProjectImage(pProjectCode,pNumber)
{
	document.getElementById("mainprojectimage").src = 'images/projects/' + pProjectCode + '_' + pNumber + '.jpg';
}

function winPop(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=0,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}

function winPopFull(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=1,"
    + "menubar=1,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=1,"
    + "toolbar=1,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}


var arrNews	= new Array();
var iCurrentNewsStory = 0;
var iCurrentChar = 0;
var iDelay = 0;
var oDiv = null;

function OutputNews()
{
	oDiv = document.getElementById("news");
	revealNews();
}

function revealNews(pDiv)
{
	iDelay = 50;
	var sText = arrNews[iCurrentNewsStory][0];
	var sLinkID = arrNews[iCurrentNewsStory][1];
	var sPage = arrNews[iCurrentNewsStory][2];
	var sHTML = '<a href="' + sPage + '?id=' + sLinkID + '" title="' + sText + '"><span class="title">NEWS &gt;</span> ' + sText.substr(0, iCurrentChar) + "</a>";
	oDiv.innerHTML = sHTML;

	iCurrentChar++;

	if (iCurrentChar > (sText.length + 3))
	{
		iCurrentNewsStory++;
		iDelay = 2000;
		iCurrentChar = 0;
	}

	if (iCurrentNewsStory >= arrNews.length)
	{
		iCurrentNewsStory = 0;
	}

	setTimeout('revealNews()', iDelay);
}

function switchPattern(pPattern)
{

	switch (pPattern)
	{
		case "weave":
			document.getElementsByTagName("body")[0].style.background = 'url(images/background.gif)';
			break;
		case "circles":
			document.getElementsByTagName("body")[0].style.background = 'url(images/background_circle.gif)';
			break;
		case "bricks":
			document.getElementsByTagName("body")[0].style.background = 'url(images/background_bricks.gif)';
			break;
	}
}

function switchColour(pColour)
{
	switch (pColour)
	{
		case "grey":
			document.getElementById("mainblock").style.background = 'url(images/background_main_block.png)';
			break;
		case "red":
			document.getElementById("mainblock").style.background = 'url(images/background_main_block_red.png)';
			break;
		case "blue":
			document.getElementById("mainblock").style.background = 'url(images/background_main_block_blue.png)';
			break;
		case "green":
			document.getElementById("mainblock").style.background = 'url(images/background_main_block_green.png)';
			break;
	}
}

function NumberOfChar(str,char)
{
	var ii, charCount;
	charCount = 0;
	for (ii=0; ii < str.length;ii++)
	{
		var cc = str.charAt(ii);
		if (cc == char)
		{
			charCount = charCount + 1;
		}
	}
	return charCount;
}

function validEmail(str)
{
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(str)) {
		alert('Please provide a valid email address');
		return false;
	}
	else
		return true;
}

function validateContactForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.Name.value == ''))
	{
		alert('You must enter your Name');
		bValid = false;
	}

	if ((bValid) && (pForm.Email.value == ''))
	{
		alert('You must enter your Email Address');
		bValid = false;
	}

	if (bValid)
	{
		bValid = validEmail(pForm.Email.value);
	}

	if ((bValid) && (pForm.Enquiry.value == ''))
	{
		alert('You must enter your Enquiry Address');
		bValid = false;
	}

	return bValid;
}

function validateCommentForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.ArticleID.value == ''))
	{
		alert('You must select an article to comment on');
		pForm.ArticleID.focus();
		pForm.ArticleID.className = 'errortext';
		bValid = false;
	}

	if ((bValid) && (pForm.CreatedByName.value == ''))
	{
		alert('You must enter Your Name when commenting on an article');
		pForm.CreatedByName.focus();
		pForm.CreatedByName.className = 'errortext';
		bValid = false;
	}

	if ((bValid) && (pForm.Content.value == ''))
	{
		alert('You must enter Your Comment when commenting on an article');
		pForm.Content.focus();
		pForm.Content.className = 'errortext';
		bValid = false;
	}

	return bValid;
}

function validateArticleForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.ArticleTitle.value == ''))
	{
		alert('You must enter an Article Title');
		pForm.ArticleTitle.focus();
		pForm.ArticleTitle.className = 'errortext';
		bValid = false;
	}

	if ((bValid) && (pForm.Content.value == ''))
	{
		alert('You must enter the Article Content');
		pForm.Content.focus();
		pForm.Content.className = 'errortext';
		bValid = false;
	}

	if ((bValid) && (pForm.ArticleDate.value == ''))
	{
		alert('You must enter the Article Date');
		pForm.Content.focus();
		pForm.Content.className = 'errortext';
		bValid = false;
	}

	return bValid;
}

function Left(pString, pLength)
{
	if (pLength <= 0)
	{
	    return "";
	}
	else if (pLength > String(pString).length)
	{
	    return pString;
	}
	else
	{
	    return String(pString).substring(0,pLength);
	}
}

function Right(pString, pLength)
{
    if (pLength <= 0)
    {
		return "";
	}
    else if (pLength > String(pString).length)
    {
    	return pString;
    }
    else
    {
       var iStringLength = String(pString).length;
       return String(pString).substring(iStringLength, iStringLength - pLength);
    }
}

function resetSearchFields()
{
	var oForm = document.getElementById('searchform');
	for (var ii=0; ii < oForm.elements.length; ii++)
	{
		if ((oForm.elements[ii].name != 'OrganisationIDHIDE') &&
			(oForm.elements[ii].name != 'SearchSubmitted') &&
			(oForm.elements[ii].name != 'Search') &&
			(oForm.elements[ii].name != 'Reset'))
		{
			document.getElementById('searchform').elements[ii].value = '';
		}
	}
}

var bPassphraseIsStrong = false;

function checkPassphraseStrength(pPhrase)
{
	if ((checkLength(pPhrase)) &&
		(checkForCapitals(pPhrase)) &&
		(checkForLowerCase(pPhrase)) &&
		(checkForSpace(pPhrase)) &&
		(checkForSpecialCharacters(pPhrase)))
	{
		document.getElementById('passphrasefeedback').innerHTML = '<img src="images/icon_success.gif" alt="Passphrase is STRONG"><p class="greentxt">Passphrase is STRONG</p>';
		bPassphraseIsStrong = true;
	}
	else
	{
		document.getElementById('passphrasefeedback').innerHTML = '<img src="images/icon_failed.gif" alt="Passphrase NOT STRONG"><p class="redtxt">Passphrase NOT STRONG</p>';
		bPassphraseIsStrong = false;
	}
}

function checkLength(pPhrase)
{
	if ((pPhrase.length >= 7) &&
		(pPhrase.length <= 50))
		return true;
	else
		return false;
}

function checkForCapitals(pPhrase)
{
	var myRegExp = '[A-Z]';
	var matchPos1 = pPhrase.search(myRegExp);

	if (matchPos1 != -1)
		return true;
	else
		return false;
}

function checkForLowerCase(pPhrase)
{
	var myRegExp = '[a-z]';
	var matchPos1 = pPhrase.search(myRegExp);

	if (matchPos1 != -1)
		return true;
	else
		return false;
}

function checkForSpace(pPhrase)
{
	var myRegExp = ' .';
	var matchPos1 = pPhrase.search(myRegExp);

	if (matchPos1 != -1)
		return true;
	else
		return false;
}

function checkForSpecialCharacters(pPhrase)
{
	var myRegExp = '[0123456789!\£$%^\&*()@~\{\}_+-=#<>\;]';
	var matchPos1 = pPhrase.search(myRegExp);

	if (matchPos1 != -1)
		return true;
	else
		return false;
}

function alertNoProducts()
{

}

function validateCodeBatchEntry(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm['TotalProductCount'].value == '0'))
	{
		if ((pForm['ProductCode|1'].value == '') &&
			(pForm['Strength|1'].value == '') &&
			(pForm['Packsize|1'].value == '') &&
			(pForm['Formulation|1'].value == ''))
		{
			alert('You must enter at least one Product Code');
			return false;
		}
		else if ((pForm['ProductCode|1'].value != '') &&
			(pForm['Strength|1'].value != '') &&
			(pForm['Packsize|1'].value != '') &&
			(pForm['Formulation|1'].value != ''))
		{}
		else
		{
			alert('You must complete a full row in order to submit a new code.');
			bValid = false;
		}
	}
	else
	{
		if ((pForm['ProductCode|1'].value == '') &&
			(pForm['Strength|1'].value == '') &&
			(pForm['Packsize|1'].value == '') &&
			(pForm['Formulation|1'].value == ''))
		{ }
		else if ((pForm['ProductCode|1'].value != '') &&
			(pForm['Strength|1'].value != '') &&
			(pForm['Packsize|1'].value != '') &&
			(pForm['Formulation|1'].value != ''))
		{}
		else
		{
			alert('You must complete a full row in order to submit a new code.');
			bValid = false;
		}
	}

	return bValid;
}

function validateProductName(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.ProductName.value == ''))
	{
		alert('You must enter a Product Name to continue');
		bValid = false;
	}

	return bValid;
}

function validateUser(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.Organisation.value == ''))
	{
		alert('You must select an Organisation to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.UserType.value == ''))
	{
		alert('You must select an User Type to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.Username.value == ''))
	{
		alert('You must enter a Username to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.FirstName.value == ''))
	{
		alert('You must enter a First Name to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.Surname.value == ''))
	{
		alert('You must enter a Surname to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.Email.value == ''))
	{
		alert('You must enter a First Name to continue');
		bValid = false;
	}
	else if (bValid)
	{
		bValid = validEmail(pForm.Email.value);
	}

	return bValid;
}

function validateOrganisation(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.OrganisationTitle.value == ''))
	{
		alert('You must enter an Organisation Title to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.Country.value == ''))
	{
		alert('You must select a Country to continue');
		bValid = false;
	}

	var iRowCount = document.getElementById('ContactCount').value;

	for (var ii = 1; ii <= iRowCount; ii++)
	{
		if ((pForm['FirstName|' + ii.toString()].value == '') &&
			(pForm['Surname|' + ii.toString()].value == '') &&
			(pForm['Email|' + ii.toString()].value == ''))
		{ }
		else if ((pForm['FirstName|' + ii.toString()].value != '') &&
			(pForm['Surname|' + ii.toString()].value != '') &&
			(pForm['Email|' + ii.toString()].value != ''))
		{
			bValid = validEmail(pForm['Email|' + ii.toString()].value);
		}
		else
		{
			alert('You must complete a full row in order to add a new contact.');
			bValid = false;
		}
	}

	return bValid;
}

function validateCountry(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.CountryName.value == ''))
	{
		alert('You must enter a Country Name to continue');
		bValid = false;
	}

	if ((bValid) && (pForm.CountryCode.value == ''))
	{
		alert('You must enter a Country Code to continue');
		bValid = false;
	}

	var iRowCount = document.getElementById('LanguageCount').value;

	for (var ii = 1; ii <= iRowCount; ii++)
	{
		if ((pForm['LanguageTitle|' + ii.toString()].value == '') &&
			(pForm['LanguageCode|' + ii.toString()].value == ''))
		{ }
		else if ((pForm['LanguageTitle|' + ii.toString()].value != '') &&
			(pForm['LanguageCode|' + ii.toString()].value != ''))
		{ }
		else
		{
			alert('You must complete a full row in order to add a new language.');
			bValid = false;
		}
	}

	return bValid;
}

function validateProductEntry(pForm)
{
	var bValid = true;

	if (pForm.Validate.value == 'TRUE')
	{
		if ((bValid) && (pForm.ProductName.value == ''))
		{
			alert('You must enter a Product Name to continue');
			bValid = false;
		}

		var iRowCount = document.getElementById('ProductCount').value;

		for (var ii = 1; ii <= iRowCount; ii++)
		{
			if ((pForm['ProductCode|' + ii.toString()].value == '') &&
				(pForm['Strength|' + ii.toString()].value == '') &&
				(pForm['Packsize|' + ii.toString()].value == '') &&
				(pForm['Formulation|' + ii.toString()].value == ''))
			{ }
			else if ((pForm['ProductCode|' + ii.toString()].value != '') &&
				(pForm['Strength|' + ii.toString()].value != '') &&
				(pForm['Packsize|' + ii.toString()].value != '') &&
				(pForm['Formulation|' + ii.toString()].value != ''))
			{}
			else
			{
				alert('You must complete a full row in order to submit a new code.');
				bValid = false;
			}
		}
	}

	return bValid;
}

function validateReason(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.RecallReason.value == ''))
	{
		alert('You must enter a Reason');
		bValid = false;
	}

	if ((bValid) && (pForm.RecallAction.value == ''))
	{
		alert('You must enter an Action');
		bValid = false;
	}

	if ((bValid) && (pForm.ReturnDate.value != ''))
	{
		var myRegExp = '(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}';
		var matchPos1 = pForm.ReturnDate.value.search(myRegExp);

		if (matchPos1 == -1)
		{
			alert('Your Return Date is not in the correct format.\n\nDates must be in dd/mm/yyyy format.');
			bValid = false;
		}
	}

	if ((bValid) && (pForm.ReturnDate.value != ''))
	{
		var dtNow = new Date();

		var sDay = pForm.ReturnDate.value.split("/")[0];
		var sMonth = pForm.ReturnDate.value.split("/")[1];
		var sYear = pForm.ReturnDate.value.split("/")[2];
		var dtReturnDate = new Date();

		if (sDay.substr(0,1) == "0") sDay = sDay.substr(1);
		if (sMonth.substr(0,1) == "0") sMonth = sMonth.substr(1);

		dtReturnDate.setFullYear(parseInt(sYear),(parseInt(sMonth) - 1),parseInt(sDay));

		if (dtReturnDate < dtNow)
		{
			alert('The Return Date cannot be in the past.');
			bValid = false;
		}
	}


	if ((bValid) && (pForm.IssuedBy.value == ''))
	{
		alert('You must enter who the recall has been Issued By');
		bValid = false;
	}

	return bValid
}

function validateRecallType(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.RecallLevelID.value == ''))
	{
		alert('You must select a Recall Level');
		bValid = false;
	}

	return bValid;
}

function validateRecallContent(pForm)
{
	var bValid = true;

	if ((bValid) && ((pForm.ContentEN.value == '') || (pForm.ContentEN.value == '<br>')))
	{
		alert('You must enter at least an English Translation of the message');
		bValid = false;
	}

	if ((bValid) && (removeHTMLTags(pForm.ContentEN.value).length > 500))
	{
		alert('There is a 500 character limit on the message');
		bValid = false;
	}

	var iCount = document.getElementById('TranslationCount').value;

	for (var ii = 1; ii <= iCount; ii++)
	{
		if ((bValid) && (pForm['Translation|' + ii.toString()].value != ''))
		{
			if (removeHTMLTags(pForm['Translation|' + ii.toString()].value).length > 500)
			{
				alert('There is a 500 character limit on each translation');
				bValid = false;
			}
		}
	}

	return bValid;
}

function validateMessageContent(pForm)
{
	syncTextarea();
	var bValid = true;

	if ((bValid) && (pForm.MessageTitle.value == ''))
	{
		alert('You must enter a Message Title');
		bValid = false;
	}

	if ((bValid) && ((pForm.ContentEN.value == '') || (pForm.ContentEN.value == '<br>')))
	{
		alert('You must enter at least an English Translation of the message');
		bValid = false;
	}

	if ((bValid) && (removeHTMLTags(pForm.ContentEN.value).length > 500))
	{
		alert('There is a 500 character limit on the message');
		bValid = false;
	}

	var iCount = document.getElementById('TranslationCount').value;

	for (var ii = 1; ii <= iCount; ii++)
	{
		if ((bValid) && (pForm['Translation|' + ii.toString()].value != ''))
		{
			if (removeHTMLTags(pForm['Translation|' + ii.toString()].value).length > 500)
			{
				alert('There is a 500 character limit on each translation');
				bValid = false;
			}
		}
	}

	return bValid;
}

function validateMessageDates(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.StartDate.value == ''))
	{
		alert('You must select a Start Date');
		bValid = false;
	}

	if (bValid)
	{
		var myRegExp = '(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}';
		var matchPos1 = pForm.StartDate.value.search(myRegExp);

		if (matchPos1 == -1)
		{
			alert('Your Start Date is not in the correct format.\n\nDates must be in dd/mm/yyyy format.');
			bValid = false;
		}
	}

	if (bValid)
	{
		var dtNow = new Date();

		var sDay = pForm.StartDate.value.split("/")[0];
		var sMonth = pForm.StartDate.value.split("/")[1];
		var sYear = pForm.StartDate.value.split("/")[2];
		var dtStartDate = new Date();

		if (sDay.substr(0,1) == "0") sDay = sDay.substr(1);
		if (sMonth.substr(0,1) == "0") sMonth = sMonth.substr(1);

		dtStartDate.setFullYear(parseInt(sYear),(parseInt(sMonth) - 1),parseInt(sDay));

		if (dtStartDate < dtNow)
		{
			alert('The Start Date cannot be in the past.');
			bValid = false;
		}
	}

	if ((bValid) && (pForm.ExpiryDate.value == ''))
	{
		alert('You must select an Expiry Date');
		bValid = false;
	}

	if (bValid)
	{
		var myRegExp = '(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}';
		var matchPos1 = pForm.ExpiryDate.value.search(myRegExp);

		if (matchPos1 == -1)
		{
			alert('Your Expiry Date is not in the correct format.\n\nDates must be in dd/mm/yyyy format.');
			bValid = false;
		}
	}

	if (bValid)
	{
		var dtStartDate = new Date(pForm.StartDate.value);
		var dtExpiryDate = new Date(pForm.ExpiryDate.value);

		var sStartDay = pForm.StartDate.value.split("/")[0];
		var sStartMonth = pForm.StartDate.value.split("/")[1];
		var sStartYear = pForm.StartDate.value.split("/")[2];
		var dtStartDate = new Date();

		if (sStartDay.substr(0,1) == "0") sStartDay = sStartDay.substr(1);
		if (sStartMonth.substr(0,1) == "0") sStartMonth = sStartMonth.substr(1);

		dtStartDate.setFullYear(parseInt(sStartYear),(parseInt(sStartMonth) - 1),parseInt(sStartDay));

		var sExpiryDay = pForm.ExpiryDate.value.split("/")[0];
		var sExpiryMonth = pForm.ExpiryDate.value.split("/")[1];
		var sExpiryYear = pForm.ExpiryDate.value.split("/")[2];
		var dtExpiryDate = new Date();

		if (sExpiryDay.substr(0,1) == "0") sExpiryDay = sExpiryDay.substr(1);
		if (sExpiryMonth.substr(0,1) == "0") sExpiryMonth = sExpiryMonth.substr(1);

		dtExpiryDate.setFullYear(parseInt(sExpiryYear),(parseInt(sExpiryMonth) - 1),parseInt(sExpiryDay));

		if (dtExpiryDate <= dtStartDate)
		{
			alert('The Expiry Date must be later than the Start Date.');
			bValid = false;
		}
	}
	return bValid;
}

function validateAuthoriser(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.Authoriser.value == ''))
	{
		alert('You must select an Authoriser');
		bValid = false;
	}

	return bValid;
}

function validateMessageType(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.MessageTypeID.value == ''))
	{
		alert('You must select a Message Type');
		bValid = false;
	}

	return bValid;
}

function SetDefaultPageOptions(pUserType)
{
	SetDefaultPageOptions(pUserType,'')
}

function SetDefaultPageOptions(pUserType,pCurrentDefaultPage)
{
	var oSelect = document.getElementById("DefaultPage");

	oSelect.options.length = 0;
	var oOption = null;
	var oOptionOld = null;

	if (pUserType == "3") //Administrator
	{
		oOption = document.createElement('option');
		oOption.text = 'Countries';
		oOption.value = 'admin_countries.aspx';
		if (pCurrentDefaultPage == oOption.value) oOption.selected = true;
		try {
		  oSelect.add(oOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  oSelect.add(oOption); // IE only
		}

		oOption = document.createElement('option');
		oOption.text = 'Organisations';
		oOption.value = 'admin_organisations.aspx';
		if (pCurrentDefaultPage == oOption.value) oOption.selected = true;
		try {
		  oSelect.add(oOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  oSelect.add(oOption); // IE only
		}

		oOption = document.createElement('option');
		oOption.text = 'Users';
		oOption.value = 'admin_users.aspx';
		if (pCurrentDefaultPage == oOption.value) oOption.selected = true;
		try {
		  oSelect.add(oOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  oSelect.add(oOption); // IE only
		}
	}
	else
	{
		oOption = document.createElement('option');
		oOption.text = 'Message Centre';
		oOption.value = 'message_centre.aspx';
		if (pCurrentDefaultPage == oOption.value) oOption.selected = true;
		try {
		  oSelect.add(oOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  oSelect.add(oOption); // IE only
		}

		oOption = document.createElement('option');
		oOption.text = 'Recall Centre';
		oOption.value = 'recall_centre.aspx';
		if (pCurrentDefaultPage == oOption.value) oOption.selected = true;
		try {
		  oSelect.add(oOption, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  oSelect.add(oOption); // IE only
		}
	}
}

function AddContactRow()
{
	var iRowCount = document.getElementById('ContactCount').value;
	iRowCount++;

	var tblBody = document.getElementById('productinfo').tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell0 = newRow.insertCell(0);
	newCell0.innerHTML = '<input type="text" name="FirstName|' + iRowCount.toString() + '" value=""/></td>';
	var newCell1 = newRow.insertCell(1);
	newCell1.innerHTML = '<input type="text" name="Surname|' + iRowCount.toString() + '" value=""/></td>';
	var newCell2 = newRow.insertCell(2);
	newCell2.innerHTML = '<input type="text" name="Email|' + iRowCount.toString() + '" value=""/></td>';

	document.getElementById('ContactCount').value = iRowCount;
}

function AddLanguageRow()
{
	var iRowCount = document.getElementById('LanguageCount').value;
	iRowCount++;

	var tblBody = document.getElementById('productinfo').tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell0 = newRow.insertCell(0);
	newCell0.innerHTML = '<input type="text" name="LanguageTitle|' + iRowCount.toString() + '" value=""/></td>';
	var newCell1 = newRow.insertCell(1);
	newCell1.innerHTML = '<input type="text" name="LanguageCode|' + iRowCount.toString() + '" value=""/></td>';

	document.getElementById('LanguageCount').value = iRowCount;
}

function AddProductRow()
{
	var iRowCount = document.getElementById('ProductCount').value;
	iRowCount++;

	var tblBody = document.getElementById('productinfo').tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell0 = newRow.insertCell(0);
	newCell0.innerHTML = '<input type="text" name="ProductCode|' + iRowCount.toString() + '" value=""/></td>';
	var newCell1 = newRow.insertCell(1);
	newCell1.innerHTML = '<input type="text" name="Strength|' + iRowCount.toString() + '" value=""/></td>';
	var newCell2 = newRow.insertCell(2);
	newCell2.innerHTML = '<input type="text" name="Packsize|' + iRowCount.toString() + '" value=""/></td>';
	var newCell3 = newRow.insertCell(3);
	newCell3.innerHTML = '<input type="text" name="Formulation|' + iRowCount.toString() + '" value=""/></td>';

	document.getElementById('ProductCount').value = iRowCount;
}

function AddBatchRow()
{
	var iRowCount = document.getElementById('BatchCount').value;
	iRowCount++;

	var tblBody = document.getElementById('batchinfo').tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell0 = newRow.insertCell(0);
	newCell0.innerHTML = '<input type="text" name="BatchCode|' + iRowCount.toString() + '" value=""/></td>';

	document.getElementById('BatchCount').value = iRowCount;
}

function removeHTMLTags(pInputString)
{
	var strInputCode = pInputString;
	/*
		This line is optional, it replaces escaped brackets with real ones,
		i.e. < is replaced with < and > is replaced with >
	*/
	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
		return (p1 == "lt")? "<" : ">";
	});
	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
	//alert("Output text:\n" + strTagStrippedText);
// Use the alert below if you want to show the input and the output text
	//alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);
	return strTagStrippedText;
}
