function loadGMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("googlemap"));
		map.setCenter(new GLatLng(-19.291717,146.773712), 16);
		map.addControl(new GSmallMapControl());
		map.openInfoWindowHtml(map.getCenter(), "<p class=\"googleaddress\"><strong>Aitkenvale PCYC</strong><br />Wellington Street<br>Aitkenvale</p>");
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);

		var point = new GLatLng(-19.291717,146.773712);
		map.addOverlay(new GMarker(point, icon));

	}
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
 } 
}
function init() {
	externalLinks();
	if (document.getElementById("googlemap")) {
		loadGMap();
	}
}
window.onload = init;
if (document.getElementById("googlemap")) {
	window.onunload = GUnload;
}

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

function testForm(theForm) {
	var reqTextArray = document.getElementsByClassName("reqText");
	var reqTextCount = reqTextArray.length;
	
	document.getElementById("entryErrors").innerHTML = "";
	errorCount = 0;

	//Check Basic Required Fields (Text and Select)
	for (i=0;i<reqTextCount;i++) {
		if (reqTextArray[i].value == "") {
			reqTextArray[i].style.backgroundColor = "#FFCCCC";
			errorCount++;
		} else {
			reqTextArray[i].style.backgroundColor = "#ffffff";
		}
	}
	if ( theForm.cEmail.value == "" && theForm.cPhone.value == "" ) {
		theForm.cEmail.style.backgroundColor = "#FFCC99";
		theForm.cPhone.style.backgroundColor = "#FFCC99";
		errorCount++;
	} else {
		theForm.cEmail.style.backgroundColor = "#ffffff";
		theForm.cPhone.style.backgroundColor = "#ffffff";
	}
	if (errorCount > 0) {
		document.getElementById("entryErrors").innerHTML = "There " + (errorCount>1?"are":"is") + " " + errorCount + " field" + (errorCount>1?"s":"") + " that need" + (errorCount>1?"":"s") + " correcting.<br />Please fill out all required fields correctly.";
		return false;
	}
	else {
		return true;
	}

}
function testEnrolForm(theForm,thePrint) {
	var reqTextArray = document.getElementsByClassName("reqText");
	var reqTextCount = reqTextArray.length;
	
	document.getElementById("entryErrors").innerHTML = "";
	errorCount = 0;

	//Check Basic Required Fields (Text and Select)
	for (i=0;i<reqTextCount;i++) {
		if (reqTextArray[i].value == "") {
			reqTextArray[i].style.backgroundColor = "#FFCCCC";
			errorCount++;
		} else {
			reqTextArray[i].style.backgroundColor = "#ffffff";
		}
	}

	if ( (document.forms[0].ePhone.value === "") && (document.forms[0].eMobile.value === "") ) {
		document.forms[0].ePhone.style.backgroundColor = "#FFCC99";
		document.forms[0].eMobile.style.backgroundColor = "#FFCC99";
		errorCount++;
	} else {
		document.forms[0].eMobile.style.backgroundColor = "#ffffff";
		document.forms[0].ePhone.style.backgroundColor = "#ffffff";
	}

	//Check Checkboxes Selected
	if ( !document.getElementById("eAgree").checked) {
		document.getElementById("eAgreeDiv").style.backgroundColor = "#ffcccc";
		errorCount++;
	} else {
		document.getElementById("eAgreeDiv").style.backgroundColor = "#ffffff";
	}
	if ( document.forms[0].ePay[0].checked == false && document.forms[0].ePay[1].checked == false ) {
		document.getElementById("ePayDiv").style.backgroundColor = "#ffcccc";
		errorCount++;
	} else {
		document.getElementById("ePayDiv").style.backgroundColor = "#ffffff";
	}

	if (errorCount > 0) {
		document.getElementById("entryErrors").innerHTML = "There " + (errorCount>1?"are":"is") + " " + errorCount + " field" + (errorCount>1?"s":"") + " that need" + (errorCount>1?"":"s") + " correcting.<br />Please fill out all required fields correctly.";
		return false;
	}
	else {
		if (thePrint==0) {
			document.forms[0].action = "/enrol-now/step2.php";
			document.forms[0].target = "_self";
			return true;
		} else {
			document.forms[0].action = "/enrol-now/print.php";
			document.forms[0].target = "_blank";
			document.forms[0].submit();
		}
	}

}
