/*
' ------------------------------------------------
' Page name: MailLib.js
' Date: 31.7.02
' Developer: Jeffrey Burns
' Email: jeff@deepend.com.au
'
' Page Desc: JavaScript Library.
' ------------------------------------------------
' VERSION HISTORY:
' 31.7.02 - Created
' ------------------------------------------------
*/

function validateEmail() {
	var alrt = '';
	if(document.myform.name.value == ''){
		alrt = 'Your name is blank.'
	}
	if(document.myform.email.value != ''){
		if(checkEmail(document.myform.email.value,'Email')) {
			alrt = alrt + 'Your email address needs to be fixed.';
		}
	}else{
		alrt = alrt + '\nYour email address is blank.';
	}
	if(document.myform.message.value == ''){
		alrt = alrt + '\nYour comment is blank.'
	}
	if(alrt){
		alert(alrt + '\n\nPlease correct these errors before submitting.');
	}else{
		document.myform.submit();
	}
}

function checkEmail(email,position) {
	var err = true;
    if (email != '') {
		invalidChars = ' /:,;'
		for(j=0; j<invalidChars.length; j++) {
			badChar = invalidChars.charAt(j)
			if (email.indexOf(badChar,0) != -1) {
                alert('The e-mail address you entered \nfor ' + position + 'contains one or more invalid characters.')
                err = false
			}
		}

		atPos = email.indexOf('@',1)
        if (atPos == -1) {
			alert('The e-mail address you entered for ' + position + '\nis missing its @ sign.')
			err = false
		}

		if (email.indexOf('@',atPos+1) != -1) {
			alert('The e-mail address you entered for ' + position + '\ncontains too many @ signs.')
			err = false
		}

		periodPos = email.indexOf('.',atPos)
		if (periodPos == -1) {
			alert('The e-mail address you entered for ' + position + '\nis missing its extension.')
			err = false
		}

		if (periodPos+3 > email.length){
			alert('The e-mail address you entered for ' + position + 'appears\nto use an invalid extension.')
            err = false
		}
	}
	if (err) {
		return false
	}else {
		return true
	}
}