

function selectMenu(n) {
	var src = document.images['Img' + n];
	var anch = document.anchors['Img' + n + '_Anchor'];
	
	if (src != null)
	{
		src.src = 'images/menu/selected_' + n + '.gif';
	}


}

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_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_findObj(n, d) { //v4.01
	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);
	if (!x && d.getElementById) x = d.getElementById(n); 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 MM_displayStatusMsg(msgStr) { //v1.0
	status = msgStr;
	document.MM_returnValue = true;
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
	window.open(theURL, winName, features);
}

function MM_popupMsg(msg) { //v1.0
	alert(msg);
}

//check the Contact Us form
function checkContactForm() {

var name = document.mailForm.Name.value;
var email = document.mailForm.EMail.value;
var phone = document.mailForm.Phone.value;
var comments = document.mailForm.Comments.value;


var bValid = true;
var sErrorFields = '';

	if (isEmpty(name))
	{
		sErrorFields += '- Name is missing \n\r';
		bValid = false; 
	}
	

	if (isEmpty(email))
	{
		sErrorFields += '- E-Mail is missing\n\r';
		bValid = false; 
	}
	else
	{
		// check if e-mail is valid
		if (!validEmail(email))
		{
			sErrorFields += '- E-Mail does not look like a valid e-mail\n\r';
			bValid = false; 
		}
	}

	if (isEmpty(phone))
	{
		sErrorFields += '- Phone is missing\n\r';
		bValid = false; 
	}
	

	if (isEmpty(comments))
	{
		sErrorFields += '- Comments are missing\n\r';
		bValid = false; 
	}
			
	if (bValid)
	{
		document.mailForm.submitForm.value='Y';
		document.mailForm.submit();
	}
	else
	{
		alert('Please correct the following information:\n\r\n\r' + sErrorFields);
	}
}

//check the Tell a Colleague form
function checkTellForm() {

	var name = document.mailForm.Name.value;
	var email = document.mailForm.EMail.value;
	var name2 = document.mailForm.Name2.value;
	var email2 = document.mailForm.EMail2.value;
	var comments = document.mailForm.Comments.value;


	var bValid = true;
	var sErrorFields = '';

	if (isEmpty(name)) {
		sErrorFields += '- Your Name is missing \n\r';
		bValid = false;
	}


	if (isEmpty(email)) {
		sErrorFields += '- Your E-Mail is missing\n\r';
		bValid = false;
	}
	else {
		// check if e-mail is valid
		if (!validEmail(email)) {
			sErrorFields += '- Your E-Mail does not look like a valid e-mail\n\r';
			bValid = false;
		}
	}

	if (isEmpty(name2)) {
		sErrorFields += '- Colleague\'s Name is missing \n\r';
		bValid = false;
	}


	if (isEmpty(email)) {
		sErrorFields += '- Colleague\'s E-Mail is missing\n\r';
		bValid = false;
	}
	else {
		// check if e-mail is valid
		if (!validEmail(email)) {
			sErrorFields += '- Colleague\'s E-Mail does not look like a valid e-mail\n\r';
			bValid = false;
		}
	}


	if (isEmpty(comments)) {
		sErrorFields += '- Comments are missing\n\r';
		bValid = false;
	}

	if (bValid) {
		document.mailForm.submitForm.value = 'Y';
		document.mailForm.submit();
	}
	else {
		alert('Please correct the following information:\n\r\n\r' + sErrorFields);
	}
}
		/*
		**************************************
			Section to check form validity
		**************************************
		*/


        // returns true if string is empty
        function isEmpty(s)
        {
           return ((s == null) || (s.length == 0));
        }


        // returns true is character is numeric
        function isDigit(c)
        {
                return ((c >= "0") && (c <= "9"));
        }

        // returns true if character is alphabetic

        function isLetter (c)
        {   
                return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
        }

        // returns true if character is alpha/numeric
        function isLetterOrDigit (c)
        {   
                return (isLetter(c) || isDigit(c));
        }

        // returns true if character is a empty or a whitespace character
        function isSpace(c)
        {
                return ( (c == null) || (c == "/t") || (c == " "));
        }

        // returns true if character is an allowable special character
        function isSpecialChar(c)
        {
                return ( (c == "'") || (c == ",") || (c == "-") || (c == "&") );
        }

        // returns true if character is an allowable phone character
        function isPhoneChar(c)
        {
                return ( (c =="-") || (c == null) || (c == "+") || (c == "(") || (c == ")") );
        }

        // returns true if string contains alpha, spaces or allowable special characters
        function isAlphaOrSpace(s)
        {
                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if ( (!isLetterOrDigit(c)) && (!isSpace(c)) && (!isSpecialChar(c)) )
                                return false;
                }
                return true;
        }    

        // returns true if string contains alpha, spaces or allowable special characters
        function isAlphaNumericOrSpace(s)
        {
                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if ( (!isLetter(c)) && (!isSpace(c)) && (!isSpecialChar(c)) )
                                return false;
                }
                return true;
        }    

        // returns true if string contains numeric characters
        function isNumeric(s)
        {
                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if (!isDigit(c)) 
                                return false;
                }
                return true;
        }

        // returns true if string contains alpha/numeric characters
        function isAlphaNumeric(s)
        {
                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if (!isLetterOrDigit(c)) 
                                return false;
                }
                return true;
        }

        // returns true if string contains alpha/numeric characters
        function validPhone(s)
        {
                if (s.length < 7)
                        return false;

                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if ( (!isDigit(c)) && (!isPhoneChar(c)) && (!isSpace(c))  )
                                return false;
                }
                return true;
        }

        function validMobile(s)
        {
                if (!validPhone(s))
                        return false;

                var c = s.substring(0, 4);
                    
				if (((c.indexOf('04', 0) < 0) || (c.indexOf('04', 0) > 1)) && (c.indexOf('+614') < 0))
				{
					return false;
				}

                return true;
        }
        
        // returns true if string contains alpha/numeric characters
        function validCode(s)
        {
                if (s.length < 2)
                        return false;

                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);

                        if ( (!isDigit(c)) && (!isPhoneChar(c)) && (!isSpace(c))  )
                                return false;
                }
                return true;
        }
        
        // returns true if strig contains valid date
        function validDate(s)
        {
        
			if (s.length != 8)
				return false;
			
			if ((isNaN(parseInt(s.substr(0,2)))) || (isNaN(parseInt(s.substr(3,2)))) || (isNaN(parseInt(s.substr(6)))))
			{
				return false;
			}
				
			if (( parseInt(s.substr(0,2)) > 31) || (parseInt(s.substr(3,2)) > 12))
			{
				return false;
			}
				
			return true;
        }

        // Returns true if string contains a valid email address
        // Assumes there must be at least 1 character before and after the @ character,
        // also assumes there must be at least 1 character before and after the . character.
        function validEmail(s)
        {
                var i = 1;
                mailLength = s.length;

                // look for @
                while ((i < mailLength) && (s.charAt(i) != "@"))
                {
                        i++;
                }

                if ( (i >= mailLength) || (s.charAt(i) != "@") ) 
                {
                        return false;
                }
                else
                { 
                        i += 2;
                }
                // look for .
                while ( (i < mailLength) && (s.charAt(i) != ".") )
                { 
                        i++;
                }

                // there must be at least one character after the .
                if ( (i >= mailLength - 1) || (s.charAt(i) != ".") ) 
                        return false;
                else 
                        return true;
        }


        function homeImage(n) {
        	var r = Math.ceil(Math.random() * n);
        	document.write('<img src="images/home_' + r + '.gif" alt="Home"/>');
        }
