//------------------------------------------//
// Javascript Functions                     //
// (C) Copyright 2005, Kevin Green          //
// E-Mail: kevin@green.id.au                //
// ---------------------------------------- //
// Use of this code is not permitted        //
// unless this header remains intact        //
//------------------------------------------//

// Set menu CSS display options
if (document.getElementById) {
	document.write('<style type="text/css">\n')
	document.write('.submenu{display: none;}\n')
	document.write('</style>\n')
}

// Simple E-Mail address spam protection
function nospam(name,domain,showText) {
	if(!showText) {
		document.write('<a href=\"mailto:' + name + '@' + domain + '\">' + name + '@' + domain + '</a>');
	} else {
		document.write('<a href=\"mailto:' + name + '@' + domain + '\">' + showText + '</a>');
	}
}

// Confirmation box
function confirmThis(msg,url) {
	input_box = confirm(msg);
	if (input_box==true) { 
		// User clicked OK
		window.location.replace(url);
	}
}

// Toggle <div> display status
function toggleview(id) {
	if ( ! id ) return;

	itm = document.getElementById(id);

	if (itm.style.display == "none") {
		my_show_div(id);
	} else {
		my_hide_div(id);
	}
}

// Toggle 2 <div>'s display status
function togglediv(id1, id2) {
        toggleview(id1);
        toggleview(id2);
}

// Hide <div>
function my_hide_div(id) {
	itm = document.getElementById(id);

	if ( ! itm ) return;
	itm.style.display = "none";
}

// Show <div>
function my_show_div(id) {
	itm = document.getElementById(id);

	if ( ! itm ) return;
	itm.style.display = "";
}

// Ignore [Enter] key on field
function checkKey() {
	if(event.keyCode==13) event.keyCode = false;
}

// Convert [Enter] to [Tab] (jumps to next field)
function enterTab() {
	if(event.keyCode==13) event.keyCode=9;
}

// Reset forms
function resetForms() {
	if(document.getElementById) {
		var ff = document.getElementsByTagName('form');

		for (var i=0; i<ff.length; i++) {
			ff[i].reset();
		}
		
	}
}

// Random Number
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

// Search type switcher code
function SwitchSearch(obj){
	if(document.getElementById) {
		var el = document.getElementById(obj);
		var ar = document.getElementById("searchdiv").getElementsByTagName("span");

		if(el.style.display != "block") {
			for (var i=0; i<ar.length; i++) {
				ar[i].style.display = "none";
			}

			el.style.display = "block";
		}
	}
}

// Search Results switcher code
function SwitchSearchResults(obj){
	if(document.getElementById) {
		var el = document.getElementById(obj);
		var ar = document.getElementById("searchResultsTable").getElementsByTagName("span");

		if(el.style.display != "block") {
			for (var i=0; i<ar.length; i++) {
				ar[i].style.display = "none";
			}

			el.style.display = "block";
		}
	}
}

// Search Results table scroller
function checkRegForm(form) {
	if(form.username.value == '') {
		alert('You must supply a username that you will use to log in to MyAccount.net.au');
		return false;

	} else if(form.password.value == '') {
		alert('You must supply a password that you will use to log in to MyAccount.net.au');
		return false;

	} else if(form.password.value != form.passwordconfirm.value) {
		alert('Your passwords do not match, please retype them and try again');
		return false;

	} else if(form.name.value == '') {
		alert('You must supply either your full name, or your company name in the Name field');
		return false;

	} else if(form.email.value == '') {
		alert('You must supply an email address');
		return false;

	} else if(form.email.value != form.emailconfirm.value) {
		alert('Your email address does not match the one in the confirm field');
		return false;

	} else if(form.password.value.length < 6) {
		alert('Your password must be longer than 6 characters, please try again.');
		return false;

	} else {
		var parsed = true;
		var validchars = "abcdefghijklmnopqrstuvwxyz0123456789";
  
		for (var i=0; i < form.username.value.length; i++) {
			var letter = form.username.value.charAt(i).toLowerCase();
			if (validchars.indexOf(letter) != -1) {
				continue;
			} else {
				parsed = false;
				break;
			}
		}

		if(parsed == false) {
			alert('Your username contains invalid characters.\nYou can only use letters and numbers - no spaces or special characters are allowed.');
			return false;
		} else {
			return true;
		}
	}
}

function showMenu(id) {
	var d = document.getElementById(id);

 	for(var i = 1; i<=10; i++) {
 		if (document.getElementById('dropmenu'+i)) {
			document.getElementById('dropmenu'+i).style.display = 'none';
		}
 	}

	if(d) {
		d.style.display = 'block';
	}
}