/* ================================================================================= */	

/* Various JavaScriptlets written by Tady Walsh for use on all websites...			 */
/*									...just to make my life easier!!!				 */

/* 						Copyright Tady Walsh 1996-2004								 */
/* ================================================================================= */	
/* Drop down menus for both cascading and heirarchical menus */

	var currentMenu = 1;
	var currentSubMenu = 1;	
	function changeMenu(tier1) {
	oldDivId = document.all('toptier1'+currentMenu);
	newDivId =  document.all('toptier1'+tier1);
	if (tier1 != currentMenu)
		{
		oldDivId.style.display = 'none';
		newDivId.style.display = '';
		currentMenu = tier1;
		}
	else
		{
		if (newDivId.style.display == '')
			{
			newDivId.style.display = 'none';
			}
		else
			{
			newDivId.style.display = '';
			}
		currentMenu = tier1;
		}
	}
	function changeSubMenu(tier2) {
	oldDivId = document.all('tier2'+currentSubMenu);
	newDivId =  document.all('tier2'+tier2);
	if (tier2 != currentSubMenu)
		{
		oldDivId.style.display = 'none';
		newDivId.style.display = '';
		currentSubMenu = tier2;
		}
	else
		{
		if (newDivId.style.display == '')
			{
			newDivId.style.display = 'none';
			}
		else
			{
			newDivId.style.display = '';
			}
		currentSubMenu = tier2;
		}
	}

/* ================================================================================= */	
/* Form validation scripts... these are priceless...								 */
/* ================================================================================= */	
/* Validate Name */

function validateName(name)
	{
	if(name.value=="")
		{
		alert("You must enter your name");
		name.focus();
		name.select();
		return false;
		}
	else
		{
		return true;
		}
	}
	
/* ================================================================================= */	
/* Validate Data Field */

function validateData(data,name)
	{
	if(data.value=="")
		{
		alert("Your "+name+" must have a value");
		data.focus();
		data.select();
		return false;
		}
	else
		{
		return true;
		}
	}
	
/* ================================================================================= */	
/* Validate Combo Field */

function validateCombo(combo,name)
	{
	if(combo.value < 1)
		{
		alert("Invalid selection in the "+name+" field");
		combo.focus();
		return false;
		}
	else
		{
		return true;
		}
	}
	
/* ================================================================================= */	
/* Validate Company */

function validateCompany(company)
	{
	if(company.value=="")
		{
		alert("You must enter a company name (If not relevant type \"Private User\")");
		company.focus();
		company.select();
		return false;
		}
	else
		{
		return true;
		}
	}

/* ================================================================================= */	
/* Validate Phone */

function validFone(fone)
	{
	validChars = "0123456789-+() .";
	if(fone == "")
		{
		return false;
		}
	for(i=0; i<fone.length; i++)
		{
		temp = "" + fone.substring(i, i+1);
		if (validChars.indexOf(temp) == "-1")
			{
			return false;
			}
		}
	return true
	}

function validatePhone(fone)
	{
	if(!validFone(fone.value))
		{
		alert("Invalid Telephone Number");
		fone.focus();
		fone.select();
		return false;
		}
	else
		{
		return true;
		}
	}
	
/* ================================================================================= */	
/* Validate URL */
	
function validURL(url)
	{
	invalidChars = "!\"£$%^&*()+={}[];@\'#,<>?|`\\¬";
	if(url == "")
		{
		return false;
		}
	for(i=0; i<invalidChars.length; i++)
		{
		badChar=invalidChars.charAt(i);
		if (url.indexOf(badChar,0) != -1)
			{
			return false;
			}
		}
	return true;
	}
	
function validateURL(url)
	{
	if(!validURL(url.value))
		{
		alert("Invalid Website Address");
		url.focus();
		url.select();
		return false;
		}
	else
		{
		return true;
		}
	}
	
/* ================================================================================= */	
/* Validate Email Address */

function validEmail(email)
	{
	invalidChars = "/:;,";
	if(email == "")
		{
		return false;
		}
	for(i=0; i<invalidChars.length; i++)
		{
		badChar=invalidChars.charAt(i);
		if (email.indexOf(badChar,0) != -1)
			{
			return false;
			}
		}
	atPos = email.indexOf("@",1);
	if(atPos == -1)
		{
		return false;
		}
	if (email.indexOf("@", atPos+1) != -1)
		{
		return false;
		}
	periodPos = email.indexOf(".",atPos);
	if(periodPos == -1)
		{
		return false;
		}
	if(periodPos+3>email.length)
		{
		return false;
		}
	return true;
	}

function validateEmail(email)
	{	
		if (!validEmail(email.value))
		{
		alert("Invalid Email Address");
		email.focus();
		email.select();
		return false;
		}
	else
		{
		return true;
		}
	}

/* ================================================================================= */	
/* Add to Favourites */

function bookmark(url,title)
	{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
		{
		window.external.AddFavorite(url,title)
		}
	else
		{
		var msg = "Don't forget to bookmark us!";
		if(navigator.appName == "Netscape") msg += " (CTRL+D)";
		alert(msg);
		}
	}

/* ================================================================================= */	
/* popUp window */

function popUp(url,w,h,l,t)
	{
	newWindow = window.open (url,'newWin','scrollbars=no,width='+w+',height='+h+',left='+l+',top='+t);
	}
	
function popFNF(url)
	{
	newWindow = window.open (url,'newWin','scrollbars=no,width=350,height=200,left=150,top=300');
	}
	
/* ================================================================================= */	