window.onload = function() {
	while(o = enum_elements('input')) { if(o.type=='text'){ input_hover(o); }}
	while(o = enum_elements('textarea')) { input_hover(o); }
	while(o = enum_elements('select')) { input_hover(o); }
	
	if(o=document.getElementById('courseList_0')) {
		var i=0;
		while(o) {
			o.style.display = 'none';
			i++;
			o = document.getElementById('courseList_'+i);
		}
	}
	
	// Selected Course
	if(o=document.getElementById('oSelectedCourse')) {
		oListId = o.parentNode.id.split('_');
		tglList(oListId[1]);
		new Effect.ScrollTo('oSelectedCourse', {offset: -200});
		setTimeout('new Effect.Highlight(\'oSelectedCourse\');',2000);
	}
}

function tglList(i) {
	if(o = document.getElementById('courseList_'+i)) {
		if(o.style.display=='none') {
			o.style.display = '';
			document.getElementById('courseListToggle_'+i).innerHTML = 'Hide';
		}
		else {
			o.style.display = 'none';
			document.getElementById('courseListToggle_'+i).innerHTML = 'Show';
		}
	}
}

function validate(ofrm) {
	allgood = true;

	o = $('frmPaymate-PMT_CONTACT_FIRSTNAME');
	if(o.value=='') {
		alert('Please enter your first name');
		o.focus();
		allgood = false;
	}
	
	o = $('frmPaymate-PMT_CONTACT_SURNAME');
	if(allgood && o.value=='') {
		alert('Please enter your surname');
		o.focus();
		allgood = false;
	}
	
	o = $('frmPaymate-PMT_SENDER_EMAIL');
	if(allgood && o.value=='') {
		alert('Please enter your email address');
		o.focus();
		allgood = false;
	}
	
	o = $('frmPaymate-regindi_address1');
	if(allgood && o.value=='') {
		alert('Please enter your street address');
		o.focus();
		allgood = false;
	}
	
	o = $('frmPaymate-regindi_sub');
	if(allgood && o.value=='') {
		alert('Please enter your suburb');
		o.focus();
		allgood = false;
	}
	
	o = $('frmPaymate-regindi_pcode');
	if(allgood && o.value=='') {
		alert('Please enter your postcode');
		o.focus();
		allgood = false;
	}
	
	o = $('frmState');
	if(allgood && o.value=='') {
		alert('Please enter your state');
		o.focus();
		allgood = false;
	}
	
	return allgood;
}

function mt(oLnk){
	document.location = 'mail'+'to:'+oLnk+'@'+'training-1'+'.com';
}

var iTotal = 0;
var iDeposit = 0;

function Total(oEle,iTot,iDep) {

	if(oEle.checked){
		iTotal = iTotal + iTot;
		iDeposit = iDeposit + iDep;
	}
	else {
		iTotal = iTotal - iTot;
		iDeposit = iDeposit - iDep;
	}

	document.getElementById('disTotal').innerHTML =  toCurrency(iTotal);
	document.getElementById('disDeposit').innerHTML = toCurrency(iDeposit);
	document.getElementById('frmTotal_Amount').value =  iTotal;
	document.getElementById('frmPaymate-amt').value = iDeposit;
}

function toCurrency(sNum) {

	sNum = sNum.toString().replace(/[^0-9.]/g,'');

	if(isNaN(sNum)) { sNum = "0"; }
	sign = (sNum == (sNum = Math.abs(sNum)));
	sNum = Math.floor(sNum*100+0.50000000001);
	iCen = sNum%100;
	sNum = Math.floor(sNum/100).toString();
	if(iCen<10){ iCen = "0" + iCen; }

	for (var i = 0; i < Math.floor((sNum.length-(1+i))/3); i++) {
		sNum = sNum.substring(0,sNum.length-(4*i+3))+','+ sNum.substring(sNum.length-(4*i+3));
	}
	return (((sign)?'':'-') + '$' + sNum + '.' + iCen);
}
		
function input_hover(o) {
	o.onfocus = function(){ this.style.backgroundColor = '#fffff1'; }
	o.onblur = function(){ this.style.backgroundColor = '#fff'; }
}

var oEEs;
var oEEc = -1;

function enum_elements(sTag) {
	if(oEEc==-1){ oEEs = document.getElementsByTagName(sTag); oEEc = 0; }
	if(oEEc<oEEs.length){ oEEc++; return oEEs[oEEc-1]; }
	else { oEEc = -1; return false; }
}

function openWin(l) {
	window.open(l,'DialogWindow','height=300,width=400');
}

function openDetails(l) {
	window.open(l,'DetailsWindow','height=300,width=400,scrollbars=1,resizable=1');
}

function openDialog(l) {
	window.open(l,'DialogWindow','height=550,width=600');
}

function $(s) {
	return document.getElementById(s);
}

function closeDialog() {
	if(confirm('Are you sure you want to close this window?\nAny changes you have made will not be saved')) {
		window.close();
	}
}

function cr_change(oList) {
	if(oList.value==''||oList.value=='0'){
		oList.selectedIndex=0;
		$('oSectionsPanel').style.display='block';
	}
	else{
		$('oSectionsPanel').style.display='none';
	}
}

