function myKeyDownHandler(e){if(!e)var e=window.event;if(e.target)targ=e.target;else if(e.srcElement)targ=e.srcElement;if(targ.nodeType==3)
targ=targ.parentNode;if(e.keyCode)code=e.keyCode;else if(e.which)code=e.which;if(targ.tagName.toLowerCase()=='input'){if(code==38||code==37){nextTabindex(targ,-1);}
if(code==40||code==39){nextTabindex(targ,1);}}}
    
    function nextTabindex(el,n) {
    	var frm = el.form;
    	for (var i = 0; i < frm.elements.length; i++) {
    		if (frm.elements[i].tabIndex == el.tabIndex + n) {
            	frm.elements[i].focus();
        	}
    	}
	}	

function showDropDown(menuId, show) {
	if (show == 1) {
		document.getElementById(menuId).style.display="block";
	} else {
		document.getElementById(menuId).style.display="none";
	}
	
}

function checkAll() {
	d=document.getElementsByTagName("input");
	for(i=0;i<d.length;i++) {
		if(d[i].type=="checkbox") {
      		d[i].checked=true;
		}
	}	
}

function uncheckAll() {
	d=document.getElementsByTagName("input");
	for(i=0;i<d.length;i++) {
		if(d[i].type=="checkbox") {
      		d[i].checked=false;
		}
	}
}

function changeStyle(classStr){
	var menuLi = document.getElementsByTagName('li');	
	for (var i = 0; i < menuLi.length; i++) {
		if (menuLi[i].className == 'levelhide' || menuLi[i].className == 'levelhide2')	{	
			menuLi[i].className=classStr;			
		}
	}
}

function getData(remoteURL, containerId) {
        //create the Cross-browser XMLHttpRequest object
        if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
               xmlhttp=new XMLHttpRequest();
              if (xmlhttp.overrideMimeType) {
                     xmlhttp.overrideMimeType('text/xml');
              }     
              xmlhttp.onreadystatechange= function() { loadData(containerId); };
              xmlhttp.open("GET", remoteURL, true);
              xmlhttp.send(null);    
       } else if (window.ActiveXObject) { //IE
              xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
              if (xmlhttp) {
                     xmlhttp.onreadystatechange= function() { loadData(containerId); };
                     xmlhttp.open('GET', remoteURL, true);
                     xmlhttp.send();
              }
       }
  }

  function loadData(containerId) {
       if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById(containerId).innerHTML=xmlhttp.responseText;
       }
  }


function showStar(divId) {
	textArray = new Array("Poor", "Nothing new", "Worth watching", "Pretty good", "Fantastic!");
	for (i=0;i<5;i++){
		if (i<divId){
			document.getElementById('star'+(i+1)).src = "/images/icon/star_on.gif";
		}
		if ((i+1)==divId) {
			document.getElementById('rateText').innerHTML = textArray[i];
		}
	}
}

function clearStar() {
	for (i=0;i<5;i++){		
		document.getElementById('star'+(i+1)).src = "/images/icon/star_off.gif";
	}
	document.getElementById('rateText').innerHTML = '';
}

function confirmSubmit() {
	var agree=confirm("Are you sure you wish to delete this record ?");
	if (agree)
	return true ;
	else
	return false ;
}

function reviewSwitch(divId) {
	if (!(document.equipReview.productCheck.checked)) {
		document.getElementById('productName').style.display = "none";
		try {
			document.getElementById('reviewProduct').style.display = "";
		} catch (e) {
		}
	} else {
		document.getElementById('productName').style.display = "";
		try {
			document.getElementById('reviewProduct').style.display = "none";	
		} catch (e) {
		}
	}
}

function checkVideoUploadForm() {
	missinginfo = "";		
	if (document.video.title.value == "") {
			missinginfo += "\n     -  Video Title";
	}
	if (document.video.source_url.value == "") {
			missinginfo += "\n     -  Video Code";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
}	

function checkVideoCommentForm() {
	missinginfo = "";		
	if (document.videoReview.review.value == "") {
			missinginfo += "\n     -  Comment text";
	}
	rating = 0;
	for (i=0;i<document.videoReview.rate.length;i++){
		if (document.videoReview.rate[i].checked==true){
			rating = 1;
			break //exist for loop, as target acquired.
		}
	}
	if (rating == 0) {
			missinginfo += "\n     -  Rating";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkCourseReviewForm() {
	missinginfo = "";		
	if (document.courseReview.review.value == "") {
			missinginfo += "\n     -  Review text";
	}
	rating = 0;
	for (i=0;i<document.courseReview.rate4.length;i++){
		if (document.courseReview.rate4[i].checked==true){
			rating = 1;
			break //exist for loop, as target acquired.
		}
	}
	if (rating == 0) {
			missinginfo += "\n     -  Overall rating";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkEquipReviewForm() {
	missinginfo = "";	
	try {		
		if (document.equipReview.type.value == "simple") {		
		}		
	} 
	catch(e) {
		if (document.equipReview.supplierID.options[0].selected) {
			missinginfo += "\n     -  Brand manufacturer";
		}
		if (document.equipReview.reviewCategoryID.options[0].selected) {
			missinginfo += "\n     -  Category";
		}
		if (document.equipReview.productCheck.checked) {		
			if (document.equipReview.productName.value == '') {
				missinginfo += "\n     -  Product";
			}
		} else {			
			try {
				if (document.equipReview.productID.options[0].selected) {
					missinginfo += "\n     -  Product";
				}				
			}
			catch (e) {				
				missinginfo += "\n     -  Product";
			}
		}
	}
	if (document.equipReview.review.value == "") {
			missinginfo += "\n     -  Review text";
	}
	rating = 0;
	for (i=0;i<document.equipReview.rate4.length;i++){
		if (document.equipReview.rate4[i].checked==true){
			rating = 1;
			break //exist for loop, as target acquired.
		}
	}
	if (rating == 0) {
			missinginfo += "\n     -  Overall rating";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function clearLoginForm() {
	document.loginform.username2.value = '';
	document.loginform.password2.value = '';
}

function clearSearchForm() {
	document.searchform.quicksearch.value = '';
}

function formSubmit(frmValue) {
	document.form.selectFrm.value = frmValue;
	document.form.submit();
}

function changePlayerHcp(obj) {
	var oselect = document.getElementById(obj);
	//var cselectVal=oselect.options[oselect.selectedIndex].value;
	var arrayVal = oselect.selectedIndex;
	//alert(oselect.options[oselect.selectedIndex]);
	document.getElementById("txtGst").innerHTML=array1[arrayVal];
	document.getElementById("txtHcp").innerHTML=array2[arrayVal];
	document.form.hcpStrokes.value=array2[arrayVal];
}

function openHelp(page) {
	var winlink = "/help/" + page + ".htm";
	window.open(winlink,"","height=450,width=380,left=35,top=35,location=no,scrollbars=yes");
}

function newwin(URL) {
	window.open(URL,"","height=400,width=550,left=15,top=15,location=no,scrollbars=yes");
}

function checkCompForm() {
	if (document.form.stage.value == 4) {
		selectAll();
		return true;
	}
	else if (document.form.stage.value == 1) {
		missinginfo = "";
		if (document.form.comp.value == '') {
			missinginfo += "\n     -  Competition";
		}
		if (document.form.date.value == '') {
			missinginfo += "\n     -  Date";
		}
		if (document.form.comptype.options[0].selected) {
			missinginfo += "\n     -  Type";
		}
		if (missinginfo != "") {
			missinginfo ="_____________________________\n" +
			"You failed to correctly fill in :\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and submit again.";
			alert(missinginfo);
			return false;
		}
		else {
			return true;
		}
	}
	else return true;
}

function checkCourseStage0Form() {
	var missinginfo = "";
	if (document.form.clubname.value == '') {
		missinginfo += "\n     -  Clubname";
	}
	try {
		if (document.form.country.options[0].selected) {
			missinginfo += "\n     -  Country";
		}
	}
	catch (e) {
	}
	try {
		if (document.form.location.options[0].selected) {
			missinginfo += "\n     -  Location";
		}
	}
	catch (e) {
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkCourseStage1Form() {
	missinginfo = "";
	if (document.form.tee.value == '') {
		missinginfo += "\n     -  Tee";
	}
	if (document.form.holes.value == '') {
		missinginfo += "\n     -  Holes";
	}
	if (document.form.SSS.value == '') {
		//document.form.SSS.value = document.form.partot.value;
	}
	if (isNaN(document.form.holes.value)) {
		missinginfo += "\n     -  Holes must be numeric";
	}
	if (!(document.form.holes.value == 18 | document.form.holes.value == 9)) {
		missinginfo += "\n     -  Holes must be 9 or 18";
	}
	if (isNaN(document.form.SSS.value)) {
		missinginfo += "\n     -  SSS must be numeric";
	}
	if (isNaN(document.form.slope.value)) {
		missinginfo += "\n     -  Slope must be numeric";
	}
	if (document.form.holes.value != '') {
		for (var i=1; i<=document.form.holes.value; i++){
			if ( (isNaN(eval("document.form.par"+i+".value"))) | (eval("document.form.par"+i+".value") == '') ) {
				missinginfo += "\n     - Hole " + i + " Par not numeric";
			}
			if ( (isNaN(eval("document.form.yds"+i+".value"))) | (eval("document.form.yds"+i+".value") == '') ) {
				missinginfo += "\n     - Hole " + i + " Yards not numeric";
			}
			if ( (isNaN(eval("document.form.si"+i+".value"))) | (eval("document.form.si"+i+".value") == '') ) {
				missinginfo += "\n     - SI " + i + " not numeric";
			}
			if ((eval("document.form.par"+i+".value") < 3) | (eval("document.form.par"+i+".value") > 6)) {
				missinginfo += "\n     - Hole " + i + " Par must be between 3 and 6";
			}
			if ((eval("document.form.yds"+i+".value") < 1) | (eval("document.form.yds"+i+".value") > 700)) {
				missinginfo += "\n     - Yards " + i + " must be between 1 - 700";
			}
			if ((parseInt(eval("document.form.si"+i+".value")) > parseInt(document.form.holes.value)) | (parseInt(eval("document.form.si"+i+".value")) < 1)) {
				missinginfo += "\n     - SI " + i + " must be between 1 and " + document.form.holes.value;
			}
		}
		for (var i=1; i<=document.form.holes.value; i++){
			for (var j=1;j<=document.form.holes.value; j++){
				if (i != j){
					if (eval("document.form.si"+i+".value") == eval("document.form.si"+j+".value")){
						missinginfo += "\n     - SI error for holes " + i + " and " + j;
					}
				}
			}
		}
	}
	var paroutcalc = ((document.form.par1.value*1) + (document.form.par2.value*1)+ (document.form.par3.value*1) + (document.form.par4.value*1) + (document.form.par5.value*1) + (document.form.par6.value*1) +(document.form.par7.value*1) + (document.form.par8.value*1) + (document.form.par9.value*1));
	var parincalc = ((document.form.par10.value*1) + (document.form.par11.value*1)+ (document.form.par12.value*1) + (document.form.par13.value*1) + (document.form.par14.value*1) + (document.form.par15.value*1) +(document.form.par16.value*1) + (document.form.par17.value*1) + (document.form.par18.value*1));
	var ydsoutcalc = ((document.form.yds1.value*1) + (document.form.yds2.value*1)+ (document.form.yds3.value*1) + (document.form.yds4.value*1) + (document.form.yds5.value*1) + (document.form.yds6.value*1) +(document.form.yds7.value*1) + (document.form.yds8.value*1) + (document.form.yds9.value*1));
	var ydsincalc = ((document.form.yds10.value*1) + (document.form.yds11.value*1)+ (document.form.yds12.value*1) + (document.form.yds13.value*1) + (document.form.yds14.value*1) + (document.form.yds15.value*1) +(document.form.yds16.value*1) + (document.form.yds17.value*1) + (document.form.yds18.value*1));
	if (document.form.parout.value != paroutcalc) {
		missinginfo += "\n     -  Par Out doesn't match 1 - 9, please check";
		document.form.parout.value = paroutcalc;
	}
	if (document.form.parin.value != parincalc) {
		missinginfo += "\n     -  Par In doesn't match 10 - 18, please check";
		document.form.parin.value = parincalc;
	}
	if (document.form.partot.value != (paroutcalc + parincalc)) {
		missinginfo += "\n     -  Par Total doesn't match, please check";
		document.form.partot.value = paroutcalc + parincalc;
	}
	if (document.form.ydsout.value != ydsoutcalc) {
		missinginfo += "\n     -  Yards Out doesn't match 1 - 9, please check";
		document.form.ydsout.value = ydsoutcalc;
	}
	if (document.form.ydsin.value != ydsincalc) {
		missinginfo += "\n     -  Yards In doesn't match 10 - 18, please check";
		document.form.ydsin.value = ydsincalc;
	}
	if (document.form.ydstot.value != (ydsoutcalc + ydsincalc)) {
		missinginfo += "\n     -  Yards Total doesn't match, please check";
		document.form.ydstot.value = ydsoutcalc + ydsincalc;
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkCompetitionForm() {
	missinginfo = "";
	if (document.form.A.value == 1) {
		checkCompetitionScoreCheck('A');
		checkCompetitionScoreTotCheck('A');
	}
	if (document.form.B.value == 1) {
		checkCompetitionScoreCheck('B');
		checkCompetitionScoreTotCheck('B');
	}
	if (document.form.C.value == 1) {
		checkCompetitionScoreCheck('C');
		checkCompetitionScoreTotCheck('C');
	}
	if (document.form.D.value == 1) {
		checkCompetitionScoreCheck('D');
		checkCompetitionScoreTotCheck('D');
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"The following information is missing or incorrect:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkCompetitionScoreTotCheck(cardPos) {
	eval("var scoreoutcalc = ((document.form.score"+cardPos+"1.value*1) + (document.form.score"+cardPos+"2.value*1)+ (document.form.score"+cardPos+"3.value*1) + (document.form.score"+cardPos+"4.value*1) + (document.form.score"+cardPos+"5.value*1) + (document.form.score"+cardPos+"6.value*1) +(document.form.score"+cardPos+"7.value*1) + (document.form.score"+cardPos+"8.value*1) + (document.form.score"+cardPos+"9.value*1))");
	eval("var scoreincalc = ((document.form.score"+cardPos+"10.value*1) + (document.form.score"+cardPos+"11.value*1)+ (document.form.score"+cardPos+"12.value*1) + (document.form.score"+cardPos+"13.value*1) + (document.form.score"+cardPos+"14.value*1) + (document.form.score"+cardPos+"15.value*1) +(document.form.score"+cardPos+"16.value*1) + (document.form.score"+cardPos+"17.value*1) + (document.form.score"+cardPos+"18.value*1))");
	if (eval("document.form.score"+cardPos+"out.value != scoreoutcalc")) {
		missinginfo += "\n     -  Card "+cardPos+" Score Out doesn't match 1 - 9, please check";
		eval("document.form.score"+cardPos+"out.value = scoreoutcalc");
		eval("document.form.score"+cardPos+"out2.value = scoreoutcalc");
	}
	if (eval("document.form.score"+cardPos+"in.value != scoreincalc")) {
		missinginfo += "\n     -  Card "+cardPos+" Score In doesn't match 10 - 18, please check";
		eval("document.form.score"+cardPos+"in.value = scoreincalc");
	}
	if (eval("document.form.score"+cardPos+"tot.value != (scoreoutcalc + scoreincalc)")) {
		missinginfo += "\n     -  Card "+cardPos+" Score Total doesn't match, please check";
		eval("document.form.score"+cardPos+"tot.value = scoreoutcalc + scoreincalc");
	}
}

function checkCompetitionScoreCheck(cardPos) {
	for (var i=1; i<=document.form.holes.value; i++){
		if ((isNaN(eval("document.form.score"+cardPos+i+".value"))) | (eval("document.form.score"+cardPos+i+".value") == '')) {
			missinginfo += "     - Hole " + i + " Card " + cardPos + " Score not numeric";
		}
	}
	if (missinginfo != "") {
		missinginfo += "\n";
	}
}

function checkRoundStage1Form() {
	missinginfo = "";
        scoreoutcalc = 0;
        scoreincalc = 0;
        calcScore();
	if (document.form.date.value == '') {
		missinginfo += "\n     -  Date";
	}
	for (var i=1; i<=document.form.holes.value; i++){
		if ((isNaN(eval("document.form.score"+i+".value")) && eval("document.form.score"+i+".value")!='n') || (eval("document.form.score"+i+".value") == '')) {
			missinginfo += "\n     - Hole " + i + " Score not numeric";
		}
                if (i<10) {
                    if (eval("document.form.score"+i+".value")!='n') {
                        scoreoutcalc = eval("scoreoutcalc+document.form.score"+i+".value");
                    }
                } else {
                    if (eval("document.form.score"+i+".value")!='n') {
                        scoreincalc = eval("scoreincalc+document.form.score"+i+".value");
                    }
                }
	}
	//var scoreoutcalc = ((document.form.score1.value*1) + (document.form.score2.value*1)+ (document.form.score3.value*1) + (document.form.score4.value*1) + (document.form.score5.value*1) + (document.form.score6.value*1) +(document.form.score7.value*1) + (document.form.score8.value*1) + (document.form.score9.value*1));
	//var scoreincalc = ((document.form.score10.value*1) + (document.form.score11.value*1)+ (document.form.score12.value*1) + (document.form.score13.value*1) + (document.form.score14.value*1) + (document.form.score15.value*1) +(document.form.score16.value*1) + (document.form.score17.value*1) + (document.form.score18.value*1));
	/*if (document.form.scoreout.value != scoreoutcalc) {
		missinginfo += "\n     -  Score Out doesn't match 1 - 9, please check";
		document.form.scoreout.value = scoreoutcalc;
		document.form.scoreout2.value = scoreoutcalc;
	}
	if (document.form.scorein.value != scoreincalc) {
		missinginfo += "\n     -  Score In doesn't match 10 - 18, please check";
		document.form.scorein.value = scoreincalc;
	}
	if (document.form.scoretot.value != (scoreoutcalc + scoreincalc)) {
		missinginfo += "\n     -  Score Total doesn't match, please check";
		document.form.scoretot.value = scoreoutcalc + scoreincalc;
	}*/
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}
function checkRoundStage2Form(){missinginfo="";if(!(document.form.statTrack.checked)){missinginfo+="\n     -  Please check the track stats box if you want to submit";document.form.statTrack.checked=true;}
for(var i=1;i<=document.form.holes.value;i++){if(isNaN(eval("document.form.putt"+i+".value"))){missinginfo+="\n     - Hole "+i+" putts not numeric";eval("document.form.putt"+i+".value = 0");}
if(eval("document.form.putt"+i+".value")==''){eval("document.form.putt"+i+".value = 0");}
if(isNaN(eval("document.form.penalty"+i+".value"))){missinginfo+="\n     - Hole "+i+" penalty not numeric";eval("document.form.penalty"+i+".value = 0");}
if(eval("document.form.penalty"+i+".value")==''){eval("document.form.penalty"+i+".value = 0");}
if((eval("document.form.sandsave"+i+".checked")==true)&&(eval("document.form.bunker"+i+".checked")==false)){missinginfo+="\n     - Hole "+i+" sandsave checked, in bunker not !";eval("document.form.bunker"+i+".checked=true");}}
var puttoutcalc=((document.form.putt1.value*1)+(document.form.putt2.value*1)+(document.form.putt3.value*1)+(document.form.putt4.value*1)+(document.form.putt5.value*1)+(document.form.putt6.value*1)+(document.form.putt7.value*1)+(document.form.putt8.value*1)+(document.form.putt9.value*1));var penaltyoutcalc=((document.form.penalty1.value*1)+(document.form.penalty2.value*1)+(document.form.penalty3.value*1)+(document.form.penalty4.value*1)+(document.form.penalty5.value*1)+(document.form.penalty6.value*1)+(document.form.penalty7.value*1)+(document.form.penalty8.value*1)+(document.form.penalty9.value*1));if(document.form.holes.value==18){var puttincalc=((document.form.putt10.value*1)+(document.form.putt11.value*1)+(document.form.putt12.value*1)+(document.form.putt13.value*1)+(document.form.putt14.value*1)+(document.form.putt15.value*1)+(document.form.putt16.value*1)+(document.form.putt17.value*1)+(document.form.putt18.value*1));var penaltyincalc=((document.form.penalty10.value*1)+(document.form.penalty11.value*1)+(document.form.penalty12.value*1)+(document.form.penalty13.value*1)+(document.form.penalty14.value*1)+(document.form.penalty15.value*1)+(document.form.penalty16.value*1)+(document.form.penalty17.value*1)+(document.form.penalty18.value*1));}
else{var puttincalc=0;var penaltyincalc=0;}
if(document.form.puttout.value==''){document.form.puttout.value=0;}
if(document.form.puttin.value==''){document.form.puttin.value=0;}
if(document.form.putttot.value==''){document.form.putttot.value=0;}
if(document.form.penaltyout.value==''){document.form.penaltyout.value=0;}
if(document.form.penaltyin.value==''){document.form.penaltyin.value=0;}
if(document.form.penaltytot.value==''){document.form.penaltytot.value=0;}
if(document.form.puttout.value!=puttoutcalc){missinginfo+="\n     -  Putt Out doesn't match 1 - 9, please check";document.form.puttout.value=puttoutcalc;document.form.puttout2.value=puttoutcalc;}
if(document.form.puttin.value!=puttincalc){missinginfo+="\n     -  Putt In doesn't match 10 - 18, please check";document.form.puttin.value=puttincalc;}
if(document.form.putttot.value!=(puttoutcalc+puttincalc)){missinginfo+="\n     -  Putt Total doesn't match, please check";document.form.putttot.value=puttoutcalc+puttincalc;}
if(document.form.penaltyout.value!=penaltyoutcalc){missinginfo+="\n     -  Penalty Out doesn't match 1 - 9, please check";document.form.penaltyout.value=penaltyoutcalc;document.form.penaltyout2.value=penaltyoutcalc;}
if(document.form.penaltyin.value!=penaltyincalc){missinginfo+="\n     -  Penalty In doesn't match 10 - 18, please check";document.form.penaltyin.value=penaltyincalc;}
if(document.form.penaltytot.value!=(penaltyoutcalc+penaltyincalc)){missinginfo+="\n     -  Penalty Total doesn't match, please check";document.form.penaltytot.value=penaltyoutcalc+penaltyincalc;}
if(document.form.putttot.value<=0){missinginfo+="\n     -  Putt Total must be greater than 0";}
if(missinginfo!=""){missinginfo="_____________________________\n"+"You failed to correctly fill in your:\n"+missinginfo+"\n_____________________________"+"\nPlease re-enter and submit again.";alert(missinginfo);return false;}
else return true;}

function checkProfileForm() {
	missinginfo = "";
	if (document.form.firstname.value == '') {
		missinginfo += "\n     -  Firstname";
	}
	if (document.form.lastname.value == '') {
		missinginfo += "\n     -  Lastname";
	}
	if (document.form.email.value == "") {
		missinginfo += "\n     -  E-Mail Address";
	}
	else {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form.email.value))) {
			missinginfo += "\n     -  Invalid E-mail Address, please re-enter.";
		}
	}
	try {
		if (document.form.country.options[0].selected) {
			missinginfo += "\n     -  Country";
		}
	}
	catch (e) {
	}
	try {
		if (document.form.location.options[0].selected) {
			missinginfo += "\n     -  Location";
		}
	}
	catch (e) {
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkPasswordForm() {
	missinginfo = "";
	if (document.form.oldPassword.value == '') {
		missinginfo += "\n     -  Old Password";
	}
	else if (document.form.newPassword.value.length <= 5) {
		missinginfo += "\n     -  Password must be greater than 5 characters.";
	}
	else if (document.form.confirmPassword.value == '') {
		missinginfo += "\n     -  Confirmation Password";
	}
	else if (!(document.form.newPassword.value == document.form.confirmPassword.value)) {
		missinginfo += "\n     -  Your passwords do not match, please re-enter.";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkMaintenanceForm() {
	missinginfo = "";
	if (document.form.newHcp.value == '') {
		missinginfo += "\n     -  New Handicap";
	}
	if (document.form.hcpNotes.value == '') {
		missinginfo += "\n     -  Handicap Change Notes";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	else return true;
}

//maxSize = 4;

function hasOptions(obj){
	if(obj!=null && obj.options!=null){
		return true;
	}
	else {
		return false;
	}
}

function selectNames(From, To, maxSize){
	var varTo = To;
	//documents.forms[0].elements['var[]'];
	eval("var From = document.forms['form'].elements['" + From + "']");
	eval("var To = document.forms['form'].elements['" + To + "']");
	var ToCnt = To.length;
	passLen = From.length;
	for (var i = 0; i < passLen; i++) {
		toLen = To.length;
		if (varTo == 'selFrom[]') {
			try {
				if (From.options[i].selected) {
					To[ToCnt++] = new Option(From.options[i].text, From.options[i].value);
					From.options[i] = null;
					i--;
				}
			}
			catch(e) {
			}
		}
		else if (toLen < maxSize) {
			try {
				if (From.options[i].selected) {
					To[ToCnt++] = new Option(From.options[i].text, From.options[i].value);
					From.options[i] = null;
					i--;
				}
			}
			catch(e) {
			}
		}
	}
}

function clearValues(To) {
	var varTo = eval("document.forms['form'].elements['selTo"+ To + "[]']");
	for (var i = 0; i < varTo.length; i++) {
		varTo.options[i].selected = true;
	}
	selectNames('selTo'+To+'[]', 'selFrom[]');
}

function selectAll() {
	try {
		var varTo1 = eval("document.forms['form'].elements['selTo1[]']");
		for (var i = 0; i < varTo1.length; i++) {
			varTo1.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo2 = eval("document.forms['form'].elements['selTo2[]']");
		for (var i = 0; i < varTo2.length; i++) {
			varTo2.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo3 = eval("document.forms['form'].elements['selTo3[]']");
		for (var i = 0; i < varTo3.length; i++) {
			varTo3.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo4 = eval("document.forms['form'].elements['selTo4[]']");
		for (var i = 0; i < varTo4.length; i++) {
			varTo4.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo5 = eval("document.forms['form'].elements['selTo5[]']");
		for (var i = 0; i < varTo5.length; i++) {
			varTo5.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo6 = eval("document.forms['form'].elements['selTo6[]']");
		for (var i = 0; i < varTo6.length; i++) {
			varTo6.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo7 = eval("document.forms['form'].elements['selTo7[]']");
		for (var i = 0; i < varTo7.length; i++) {
			varTo7.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo9 = eval("document.forms['form'].elements['selTo9[]']");
		for (var i = 0; i < varTo9.length; i++) {
			varTo9.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo10 = eval("document.forms['form'].elements['selTo10[]']");
		for (var i = 0; i < varTo10.length; i++) {
			varTo10.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo11 = eval("document.forms['form'].elements['selTo11[]']");
		for (var i = 0; i < varTo11.length; i++) {
			varTo11.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo12 = eval("document.forms['form'].elements['selTo12[]']");
		for (var i = 0; i < varTo12.length; i++) {
			varTo12.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo13 = eval("document.forms['form'].elements['selTo13[]']");
		for (var i = 0; i < varTo13.length; i++) {
			varTo13.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo8 = eval("document.forms['form'].elements['selTo8[]']");
		for (var i = 0; i < varTo8.length; i++) {
			varTo8.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo14 = eval("document.forms['form'].elements['selTo14[]']");
		for (var i = 0; i < varTo14.length; i++) {
			varTo14.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo15 = eval("document.forms['form'].elements['selTo15[]']");
		for (var i = 0; i < varTo15.length; i++) {
			varTo15.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo16 = eval("document.forms['form'].elements['selTo16[]']");
		for (var i = 0; i < varTo16.length; i++) {
			varTo16.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo17 = eval("document.forms['form'].elements['selTo17[]']");
		for (var i = 0; i < varTo17.length; i++) {
			varTo17.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo18 = eval("document.forms['form'].elements['selTo18[]']");
		for (var i = 0; i < varTo18.length; i++) {
			varTo18.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo19 = eval("document.forms['form'].elements['selTo19[]']");
		for (var i = 0; i < varTo19.length; i++) {
			varTo19.options[i].selected = true;
		}
	}
	catch (e) {
	}
	try {
		var varTo20 = eval("document.forms['form'].elements['selTo20[]']");
		for (var i = 0; i < varTo20.length; i++) {
			varTo20.options[i].selected = true;
		}
	}
	catch (e) {
	}
}

function moveOptions(selectObj, direction)
{
	eval("var selectObj = document.forms['form'].elements['" + selectObj + "']");
	if(selectObj.selectedIndex != -1)
	{
		if(direction < 0)
		{
			for(i = 0; i < selectObj.options.length; i++)
			{
				swapValue = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
				swapText = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
				if(selectObj.options[i].selected && swapValue != null && swapText != null)
				{
					thisValue = selectObj.options[i].value;
					thisText = selectObj.options[i].text;
					selectObj.options[i].value = swapValue;
					selectObj.options[i].text = swapText;
					selectObj.options[i + direction].value = thisValue;
					selectObj.options[i + direction].text = thisText;
					selectObj.options[i].selected = false;
					selectObj.options[i + direction].selected = true;
				}
			}
		}
		else
		{
			for(i = selectObj.options.length - 1; i >= 0; i--)
			{
				swapValue = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
				swapText = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
				if(selectObj.options[i].selected && swapValue != null && swapText != null)
				{
					thisValue = selectObj.options[i].value;
					thisText = selectObj.options[i].text;
					selectObj.options[i].value = swapValue;
					selectObj.options[i].text = swapText;
					selectObj.options[i + direction].value = thisValue;
					selectObj.options[i + direction].text = thisText;
					selectObj.options[i].selected = false;
					selectObj.options[i + direction].selected = true;
				}
			}
		}
	}
}

function calcPar() {
	var paroutcalc = ((document.form.par1.value*1) + (document.form.par2.value*1)+ (document.form.par3.value*1) + (document.form.par4.value*1) + (document.form.par5.value*1) + (document.form.par6.value*1) +(document.form.par7.value*1) + (document.form.par8.value*1) + (document.form.par9.value*1));
	var parincalc = ((document.form.par10.value*1) + (document.form.par11.value*1)+ (document.form.par12.value*1) + (document.form.par13.value*1) + (document.form.par14.value*1) + (document.form.par15.value*1) +(document.form.par16.value*1) + (document.form.par17.value*1) + (document.form.par18.value*1));
	document.form.parout.value = paroutcalc;
	document.form.parin.value = parincalc;
	document.form.partot.value = paroutcalc + parincalc;
}

function calcYds() {
	var ydsoutcalc = ((document.form.yds1.value*1) + (document.form.yds2.value*1)+ (document.form.yds3.value*1) + (document.form.yds4.value*1) + (document.form.yds5.value*1) + (document.form.yds6.value*1) +(document.form.yds7.value*1) + (document.form.yds8.value*1) + (document.form.yds9.value*1));
	var ydsincalc = ((document.form.yds10.value*1) + (document.form.yds11.value*1)+ (document.form.yds12.value*1) + (document.form.yds13.value*1) + (document.form.yds14.value*1) + (document.form.yds15.value*1) +(document.form.yds16.value*1) + (document.form.yds17.value*1) + (document.form.yds18.value*1));
	document.form.ydsout.value = ydsoutcalc;
	document.form.ydsin.value = ydsincalc;
	document.form.ydstot.value = ydsoutcalc + ydsincalc;
}

function isNumber(n) {
    if (!isNaN(parseFloat(n)) && isFinite(n)) {
        return true;
    } else {
        return false;
    }
}

function calcScore () {
	scoreincalc = 0;
        scoreoutcalc = 0;
        for (var i=1; i<=9; i++){
            if (eval("document.form.score"+i+".value")!='n'&&isNumber(eval("document.form.score"+i+".value"))) {
                scoreoutcalc = eval("scoreoutcalc+document.form.score"+i+".value*1");
            }
        }
        //scoreoutcalc = ((document.form.score1.value*1) + (document.form.score2.value*1)+ (document.form.score3.value*1) + (document.form.score4.value*1) + (document.form.score5.value*1) + (document.form.score6.value*1) +(document.form.score7.value*1) + (document.form.score8.value*1) + (document.form.score9.value*1));
	if (document.form.holes.value == 18) {
		//scoreincalc = ((document.form.score10.value*1) + (document.form.score11.value*1)+ (document.form.score12.value*1) + (document.form.score13.value*1) + (document.form.score14.value*1) + (document.form.score15.value*1) +(document.form.score16.value*1) + (document.form.score17.value*1) + (document.form.score18.value*1));
		for (var j=10; j<=18; j++){
                    if (eval("document.form.score"+j+".value")!='n'&&isNumber(eval("document.form.score"+j+".value"))) {
                        scoreincalc = eval("scoreincalc+document.form.score"+j+".value*1");
                    }
                }
                document.form.scorein.value = scoreincalc;
	}
	document.form.scoreout.value = scoreoutcalc;
	document.form.scoreout2.value = scoreoutcalc;
	document.form.scoretot.value = scoreoutcalc + scoreincalc;
}

function calcPen() {
	penaltyincalc = 0;
	penaltyoutcalc = ((document.form.penalty1.value*1) + (document.form.penalty2.value*1)+ (document.form.penalty3.value*1) + (document.form.penalty4.value*1) + (document.form.penalty5.value*1) + (document.form.penalty6.value*1) +(document.form.penalty7.value*1) + (document.form.penalty8.value*1) + (document.form.penalty9.value*1));
	if (document.form.holes.value == 18) {
		penaltyincalc = ((document.form.penalty10.value*1) + (document.form.penalty11.value*1)+ (document.form.penalty12.value*1) + (document.form.penalty13.value*1) + (document.form.penalty14.value*1) + (document.form.penalty15.value*1) +(document.form.penalty16.value*1) + (document.form.penalty17.value*1) + (document.form.penalty18.value*1));
	}
	document.form.penaltyout.value = penaltyoutcalc;
	document.form.penaltyout2.value = penaltyoutcalc;
	document.form.penaltyin.value = penaltyincalc;
	document.form.penaltytot.value = penaltyoutcalc + penaltyincalc;
}

function calcPutts() {
	puttincalc = 0;
	puttoutcalc = ((document.form.putt1.value*1) + (document.form.putt2.value*1)+ (document.form.putt3.value*1) + (document.form.putt4.value*1) + (document.form.putt5.value*1) + (document.form.putt6.value*1) +(document.form.putt7.value*1) + (document.form.putt8.value*1) + (document.form.putt9.value*1));
	if (document.form.holes.value == 18) {
		puttincalc = ((document.form.putt10.value*1) + (document.form.putt11.value*1)+ (document.form.putt12.value*1) + (document.form.putt13.value*1) + (document.form.putt14.value*1) + (document.form.putt15.value*1) +(document.form.putt16.value*1) + (document.form.putt17.value*1) + (document.form.putt18.value*1));
	}
	document.form.puttout.value = puttoutcalc;
	document.form.puttout2.value = puttoutcalc;
	document.form.puttin.value = puttincalc;
	document.form.putttot.value = puttoutcalc + puttincalc;
}

function checkSignUpForm() {
	missinginfo = "";
	//if (document.form.screenname.value == '') {
		//missinginfo += "\n     -  Screen name";
	//}
	if (document.form.password.value == '') {
		missinginfo += "\n     -  Password";
	}
	if (document.form.password2.value == '') {
		missinginfo += "\n     -  Confirmation Password";
	}
	if (document.form.firstname.value == '') {
		missinginfo += "\n     -  Firstname";
	}
	if (document.form.lastname.value == '') {
		missinginfo += "\n     -  Lastname";
	}
	if (document.form.email.value == "") {
		missinginfo += "\n     -  E-Mail Address";
	}
	try {
		if (document.form.country.options[0].selected) {
			missinginfo += "\n     -  Country";
		}
	}
	catch (e) {
	}
	try {
		if (document.form.location.options[0].selected) {
			missinginfo += "\n     -  Location";
		}
	}
	catch (e) {
	}
        if (document.form.gender.options[0].selected) {
		missinginfo += "\n     -  Gender";
	}
        /*
	if (document.form.postal.value == "") {
		missinginfo += "\n     -  Postal Code";
	}
	if (document.form.house_name.value == "" && document.form.house_no.value == "") {
		missinginfo += "\n     -  House Name/No.";
	}	
	if (document.form.dob.value == '') {
		missinginfo += "\n     -  Date of birth";
	}
      */
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again.";
		alert(missinginfo);
		return false;
	}
	if (!(document.form.email.value == document.form.emailconfirm.value)) {
		alert("Your emails do not match, please re-enter.");
		document.form.email.focus();
		return false;
	}
	if (!(document.form.password.value == document.form.password2.value)) {
		alert("Your passwords do not match, please re-enter.");
		document.form.password.focus();
		return false;
	}
	if (document.form.password.value.length <= 5) {
		alert("Password must be greater than 5 characters.");
		document.form.password.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form.email.value))) {
		alert("Invalid E-mail Address, please re-enter.");
		document.form.email.focus();
		return (false)
	}

	if (!(document.form.confirm.checked)) {
		alert("Please confrim you agree to our terms and conditions.");
		document.form.confirm.focus();
		return false;
	}

	else return true;
}


/*
 * Facebox (for jQuery)
 * version: 1.3 (26/11/2009)
 * @requires jQuery v1.2 or later
 *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 *   Updated by Kevin McPhillips
 *   http://github.com/kimos/facebox
 *
 * Usage:
 *
 *  jQuery(document).ready(function() {
 *    jQuery('a[rel=facebox]').facebox()
 *  })
 *
 *  <a href="#terms" rel="facebox">Terms</a>
 *    Loads the #terms div in the box
 *
 *  <a href="terms.html" rel="facebox">Terms</a>
 *    Loads the terms.html page in the box
 *
 *  <a href="terms.png" rel="facebox">Terms</a>
 *    Loads the terms.png image in the box
 *
 *
 *  You can also use it programmatically:
 *
 *    jQuery.facebox('some html')
 *    jQuery.facebox('some html', 'my-groovy-style')
 *
 *  The above will open a facebox with "some html" as the content.
 *
 *    jQuery.facebox(function($) {
 *      $.get('blah.html', function(data) { $.facebox(data) })
 *    })
 *
 *  The above will show a loading screen before the passed function is called,
 *  allowing for a better ajaxy experience.
 *
 *  The facebox function can also display an ajax page, an image, or the contents of a div:
 *
 *    jQuery.facebox({ ajax: 'remote.html' })
 *    jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')
 *    jQuery.facebox({ image: 'stairs.jpg' })
 *    jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')
 *    jQuery.facebox({ div: '#box' })
 *    jQuery.facebox({ div: '#box' }, 'my-groovy-style')
 *
 *  Want to close the facebox?  Trigger the 'close.facebox' document event:
 *
 *    jQuery(document).trigger('close.facebox')
 *
 *  Facebox also has a bunch of other hooks:
 *
 *    loading.facebox
 *    beforeReveal.facebox
 *    reveal.facebox (aliased as 'afterReveal.facebox')
 *    init.facebox
 *
 *  Simply bind a function to any of these hooks:
 *
 *   $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
 *
 */
(function($) {
  $.facebox = function(data, klass) {
    $.facebox.loading()

    if (data.iframe) fillFaceboxFromIFrame(data.iframe, klass)
    else if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
    else if (data.image) fillFaceboxFromImage(data.image, klass)
    else if (data.div) fillFaceboxFromHref(data.div, klass)
    else if ($.isFunction(data)) data.call($)
    else $.facebox.reveal(data, klass)
  }

  /*
   * Public, $.facebox methods
   */

  $.extend($.facebox, {
    settings: {
      opacity       : 0,
      overlay       : true,
      positionInfo   : function(position, total) { return position + ' of ' + total },
      loadingImage  : '/styles/images/loading.gif',
      closeImage    : '/styles/images/closelabel.gif',
      nextImage     : '/styles/images/next.png',
      previousImage : '/styles/images/prev.png',
      imageTypes    : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxHtml   : '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div class="content"> \
                </div> \
                <div class="footer"> \
                  <table> \
                    <tr> \
                      <td class="tableLeft"><div class="navigation"></div></td> \
                      <td class="tableCenter"><div class="info"></div></td> \
                      <td class="tableRight"><a href="#" class="close"><img src="" title="close" alt="Close" class="close_image" /></a></td> \
                    </tr> \
                  </table> \
                </div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    },

    loading: function() {
      init()
      if ($('#facebox .loading').length == 1) return true
      showOverlay()

      $('#facebox .content').empty()
      $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="' + $.facebox.settings.loadingImage + '"/></div>')

      $('#facebox').css({
        top:	getPageScroll()[1] + (getPageHeight() / 20),
        left:	$(window).width() / 2 - 205
      }).show()

      $(document).bind('keydown.facebox', function(e) {
        if (e.keyCode == 27) $.facebox.close()
        return true
      })
      $(document).trigger('loading.facebox')
    },

    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.facebox')
      if (klass) $('#facebox .content').addClass(klass)
      $('#facebox .info').empty()
      $('#facebox .navigation').empty()
      $('#facebox .content').append(data)
      $('#facebox .loading').remove()
      $('#facebox .body').children().fadeIn('normal')
      $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
      $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
    },

    close: function() {
      $(document).trigger('close.facebox')
      return false
    }
  })

  /*
   * Public, $.fn methods
   */

  $.fn.facebox = function(settings) {
    init(settings)

    // suck out the images
    var images = []
    $(this).each(function() {
      if (this.href.match($.facebox.settings.imageTypesRegexp) && $.inArray(this.href, images) == -1)
        images.push(this.href)
    })
    if (images.length == 1) images = null

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      if (settings && settings.iframe) fillFaceboxFromIFrame(settings.iframe, klass)

      fillFaceboxFromHref(this.href, klass, images)
      return false
    }

    return this.bind('click.facebox', clickHandler)
  }

  /*
   * Private methods
   */

  // called one time to setup facebox on this page
  function init(settings) {
    if ($.facebox.settings.inited) return true
    else $.facebox.settings.inited = true

    $(document).trigger('init.facebox')
    makeCompatible()

    var imageTypes = $.facebox.settings.imageTypes.join('|')
    $.facebox.settings.imageTypesRegexp = new RegExp("\\.(" + imageTypes + ")(\\?[\\d]+)?$", 'i')

    if (settings) $.extend($.facebox.settings, settings)
    $('body').append($.facebox.settings.faceboxHtml)

    var preload = [ new Image(), new Image() ]
    preload[0].src = $.facebox.settings.closeImage
    preload[1].src = $.facebox.settings.loadingImage

    $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })

    $('#facebox .close').click($.facebox.close)
    $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
  }

  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;
    }
    return new Array(xScroll,yScroll)
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }
    return windowHeight
  }

  // Backwards compatibility
  function makeCompatible() {
    var $s = $.facebox.settings

    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  }

  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillFaceboxFromHref(href, klass, images) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox.reveal($(target).show().replaceWith("<div id='facebox_moved'></div>"), klass)

    // image
    } else if (href.match($.facebox.settings.imageTypesRegexp)) {
      fillFaceboxFromImage(href, klass, images)
    // ajax
    } else {
      fillFaceboxFromAjax(href, klass)
    }
  }

  function fillFaceboxFromImage(href, klass, images) {
    var image = new Image()
    image.onload = function() {
      $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
      if (images) {
        faceboxSetupGallery(href, klass, images)
        var position = $.inArray(href, images)
        var next = new Image()
        next.src = images[position+1] ? images[position+1] : images[0]
      }
    }
    image.src = href
  }

  function fillFaceboxFromIFrame(data, klass) {
    var iframe = '<iframe src="' + data.href + '"'
    if (data.klass)
        iframe += ' class="' + data.klass + '"'
    else
        iframe += ' class="facebox_iframe"'
    iframe += ' />'
    $.facebox.reveal(iframe, klass)
  }

  function fillFaceboxFromAjax(href, klass) {
    $.get(href, function(data) { $.facebox.reveal(data, klass) })
  }

  function faceboxSetupGallery(href, klass, images) {
    var position = $.inArray(href, images)

    var jump = function(where) {
      $.facebox.loading()
      if (where >= images.length) where = 0
      if (where < 0) where = images.length - 1
      fillFaceboxFromHref(images[where], klass, images)
    }

    $('#facebox .image').click(function() { jump(position + 1) }).css('cursor', 'pointer');
    $('#facebox .info').html($.facebox.settings.positionInfo(position + 1, images.length));
    $('#facebox .navigation')
      .html('<img class="prev" src="' + $.facebox.settings.previousImage + '" alt="Previous"/><img class="next" src="' + $.facebox.settings.nextImage + '" alt="Next"/>')
      .find('img').css('cursor', 'pointer').end().find('.prev').click(function() { jump(position - 1); return false })
      .end().find('.next').click(function() { jump(position + 1); return false }).end();
  }

  function skipOverlay() {
    return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
  }

  function showOverlay() {
    // IE 6 is so totally balls that SELECT elements are always in the foreground. Hide them on loading.
    if ( $.browser.msie && /6.0/.test(navigator.userAgent) )
      $("select").hide();

    if (skipOverlay()) return

    if ($('#facebox_overlay').length == 0)
      $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

    $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox.settings.opacity)
      .click(function() { $(document).trigger('close.facebox') })
      .fadeIn(200)
    return false
  }

  function hideOverlay() {
    // Undo IE 6 hack.
    if ( $.browser.msie && /6.0/.test(navigator.userAgent) )
      $("select").show();

    if (skipOverlay()) return

    $('#facebox_overlay').fadeOut(200, function(){
      $("#facebox_overlay").removeClass("facebox_overlayBG")
      $("#facebox_overlay").addClass("facebox_hide")
      $("#facebox_overlay").remove()
    })

    return false
  }

  /*
   * Bindings
   */

  $(document).bind('close.facebox', function() {
    $(document).unbind('keydown.facebox')
    $('#facebox').fadeOut(function() {
      if ($('#facebox_moved').length == 0) $('#facebox .content').removeClass().addClass('content')
      else $('#facebox_moved').replaceWith($('#facebox .content').children().hide())
      hideOverlay()
      $('#facebox .loading').remove()
    })
  })

})(jQuery);


/**
 * jQuery maphighlight
 */
(function(f){var b,c,j,m,l,i,g,e,h,a,k;b=document.namespaces;has_canvas=!!document.createElement("canvas").getContext;if(!(has_canvas||b)){f.fn.maphilight=function(){return this};return}if(has_canvas){g=function(p,o,n){if(o<=1){p.style.opacity=o;window.setTimeout(g,10,p,o+0.1,10)}};e=function(n){return Math.max(0,Math.min(parseInt(n,16),255))};h=function(n,o){return"rgba("+e(n.substr(0,2))+","+e(n.substr(2,2))+","+e(n.substr(4,2))+","+o+")"};c=function(n){var o=f('<canvas style="width:'+n.width+"px;height:"+n.height+'px;"></canvas>').get(0);o.getContext("2d").clearRect(0,0,o.width,o.height);return o};j=function(q,n,t,p,o){var s,r=q.getContext("2d");r.beginPath();if(n=="rect"){r.rect(t[0],t[1],t[2]-t[0],t[3]-t[1])}else{if(n=="poly"){r.moveTo(t[0],t[1]);for(s=2;s<t.length;s+=2){r.lineTo(t[s],t[s+1])}}else{if(n=="circ"){r.arc(t[0],t[1],t[2],0,Math.PI*2,false)}}}r.closePath();if(p.fill){r.fillStyle=h(p.fillColor,p.fillOpacity);r.fill()}if(p.stroke){r.strokeStyle=h(p.strokeColor,p.strokeOpacity);r.lineWidth=p.strokeWidth;r.stroke()}if(p.fade){g(q,0)}};m=function(n){n.getContext("2d").clearRect(0,0,n.width,n.height)}}else{c=function(n){return f('<var style="zoom:1;overflow:hidden;display:block;width:'+n.width+"px;height:"+n.height+'px;"></var>').get(0)};j=function(o,r,s,v,n){var t,u,p,q;t='<v:fill color="#'+v.fillColor+'" opacity="'+(v.fill?v.fillOpacity:0)+'" />';u=(v.stroke?'strokeweight="'+v.strokeWidth+'" stroked="t" strokecolor="#'+v.strokeColor+'"':'stroked="f"');p='<v:stroke opacity="'+v.strokeOpacity+'"/>';if(r=="rect"){q=f('<v:rect name="'+n+'" filled="t" '+u+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+s[0]+"px;top:"+s[1]+"px;width:"+(s[2]-s[0])+"px;height:"+(s[3]-s[1])+'px;"></v:rect>')}else{if(r=="poly"){q=f('<v:shape name="'+n+'" filled="t" '+u+' coordorigin="0,0" coordsize="'+o.width+","+o.height+'" path="m '+s[0]+","+s[1]+" l "+s.join(",")+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+o.width+"px;height:"+o.height+'px;"></v:shape>')}else{if(r=="circ"){q=f('<v:oval name="'+n+'" filled="t" '+u+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(s[0]-s[2])+"px;top:"+(s[1]-s[2])+"px;width:"+(s[2]*2)+"px;height:"+(s[2]*2)+'px;"></v:oval>')}}}q.get(0).innerHTML=t+p;f(o).append(q)};m=function(n){f(n).find("[name=highlighted]").remove()}}l=function(o){var n,p=o.getAttribute("coords").split(",");for(n=0;n<p.length;n++){p[n]=parseFloat(p[n])}return[o.getAttribute("shape").toLowerCase().substr(0,4),p]};k=function(p,o){var n=f(p);return f.extend({},o,f.metadata?n.metadata():false,n.data("maphilight"))};a=function(n){if(!n.complete){return false}if(typeof n.naturalWidth!="undefined"&&n.naturalWidth==0){return false}return true};i={position:"absolute",left:0,top:0,padding:0,border:0};var d=false;f.fn.maphilight=function(p){p=f.extend({},f.fn.maphilight.defaults,p);if(f.browser.msie&&!d){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var o=document.createStyleSheet();var n=["shape","rect","oval","circ","fill","stroke","imagedata","group","textbox"];f.each(n,function(){o.addRule("v\\:"+this,"behavior: url(#default#VML); antialias:true")});d=true}return this.each(function(){var v,s,z,r,u,w,y,t,x;v=f(this);if(!a(this)){return window.setTimeout(function(){v.maphilight(p)},200)}z=f.extend({},p,f.metadata?v.metadata():false,v.data("maphilight"));x=v.get(0).getAttribute("usemap");r=f('map[name="'+x.substr(1)+'"]');if(!(v.is("img")&&x&&r.size()>0)){return}if(v.hasClass("maphilighted")){var q=v.parent();v.insertBefore(q);q.remove();f(r).unbind(".maphilight").find("area[coords]").unbind(".maphilight")}s=f("<div></div>").css({display:"block",background:"url("+this.src+")",position:"relative",padding:0,width:this.width,height:this.height});if(z.wrapClass){if(z.wrapClass===true){s.addClass(f(this).attr("class"))}else{s.addClass(z.wrapClass)}}v.before(s).css("opacity",0).css(i).remove();if(f.browser.msie){v.css("filter","Alpha(opacity=0)")}s.append(v);u=c(this);f(u).css(i);u.height=this.height;u.width=this.width;y=function(C){var A,B;B=k(this,z);if(!B.neverOn&&!B.alwaysOn){A=l(this);j(u,A[0],A[1],B,"highlighted");if(B.groupBy&&f(this).attr(B.groupBy)){var D=this;r.find("area["+B.groupBy+"="+f(this).attr(B.groupBy)+"]").each(function(){if(this!=D){var F=k(this,z);if(!F.neverOn&&!F.alwaysOn){var E=l(this);j(u,E[0],E[1],F,"highlighted")}}})}}};f(r).bind("alwaysOn.maphilight",function(){if(w){m(w)}if(!has_canvas){f(u).empty()}f(r).find("area[coords]").each(function(){var A,B;B=k(this,z);if(B.alwaysOn){if(!w&&has_canvas){w=c(v.get());f(w).css(i);w.width=v.width();w.height=v.height();v.before(w)}A=l(this);if(has_canvas){j(w,A[0],A[1],B,"")}else{j(u,A[0],A[1],B,"")}}})});if(z.alwaysOn){f(r).find("area[coords]").each(y)}else{f(r).find("area[coords]").trigger("alwaysOn.maphilight").bind("mouseover.maphilight",y).bind("mouseout.maphilight",function(A){m(u)})}v.before(u);v.addClass("maphilighted")})};f.fn.maphilight.defaults={fill:true,fillColor:"000000",fillOpacity:0.2,stroke:true,strokeColor:"ff0000",strokeOpacity:1,strokeWidth:1,fade:true,alwaysOn:false,neverOn:false,groupBy:false,wrapClass:true}})(jQuery);

/*
	bMap - © 2010 Darren Dignam
	darren.dignam@blocsoft.com
	http://www.blocsoft.com/bMap
	Released under the GPL License
	http://www.gnu.org/licenses/gpl-3.0.txt

	This version requires the V3 Google Maps API
*/
(function(a){a.fn.bMap=function(b){eachOptions=b;return this.each(function(){obj=a(this);var d={mapCenter:[51,0],mapZoom:1,mapCanvas:obj.attr("id"),mapSidebar:"none",mapLayerbar:"none",mapType:google.maps.MapTypeId.ROADMAP,loadMsg:"<h2>Loading...</h2>"};var c=a.extend(d,eachOptions);obj.data("bMap",new bMap(c))});return this}})(jQuery);function bMap(b){var c={mapCenter:[51,0],mapZoom:1,mapCanvas:"map",mapSidebar:"none",mapLayerbar:"none",mapType:google.maps.MapTypeId.ROADMAP,loadMsg:"<h2>Loading...</h2>"};var b=$.extend(c,b);this.mapSidebar=b.mapSidebar;this.useSidebar=(this.mapSidebar!="none")?true:false;this.mapLayerbar=b.mapLayerbar;this.useLayerbar=(this.mapLayerbar!="none")?true:false;this.layerMgrArray=[];var a={zoom:b.mapZoom,center:new google.maps.LatLng(b.mapCenter[0],b.mapCenter[1]),mapTypeId:b.mapType};this.map=new google.maps.Map(document.getElementById(b.mapCanvas),a);this.mapCanvas=b.mapCanvas;$("#"+this.mapCanvas).append("<div id='"+this.mapCanvas+"bMapLoadMsg' class='bMapLoadMsg'>"+b.loadMsg+"</div>");$("#"+this.mapCanvas+"bMapLoadMsg").css("left",($("#map").width()/2)-50);$("#"+this.mapCanvas+"bMapLoadMsg").css("top",($("#map").height()/2)-50);if(b.icons){this.icons=b.icons}if(b.markers){this.insertMarkers(b.markers)}this.infoWindow=new google.maps.InfoWindow();this.geoCoder=new google.maps.Geocoder()}bMap.prototype.insertMarkers=function(a){tmpThis=this;var b=tmpThis.layerMgrArray.length;var c={name:"Layer"+b,type:"marker",visible:"true"};var a=$.extend(c,a);tmpThis.layerMgrArray[b]=a;tmpThis.layerMgrArray[b].toggleLayer=function(){if(this.visible!="false"){this.visible="false";for(i=0,j=this.data.length;i<j;i++){this.data[i].setMap(null);tmpThis.infoWindow.close()}$("#bMapLyr"+b).addClass("bLyrHide");$("#"+tmpThis.mapSidebar+' div[rel^="'+b+'"]').slideUp("fast");return false}else{this.visible="true";for(i=0,j=this.data.length;i<j;i++){this.data[i].setMap(tmpThis.map)}$("#bMapLyr"+b).removeClass("bLyrHide");$("#"+tmpThis.mapSidebar+' div[rel^="'+b+'"]').slideDown("fast");return true}};jQuery.each(a.data,function(f,g){var d=new google.maps.LatLng(g.lat,g.lng);if(g.icon){tmpThis.layerMgrArray[b].data[f]=new google.maps.Marker({position:d,map:tmpThis.map,icon:tmpThis.icons[parseInt(g.icon)]})}else{tmpThis.layerMgrArray[b].data[f]=new google.maps.Marker({position:d,map:tmpThis.map})}if(g.title){var e="<h2>"+g.title+"</h2>";if(g.body){e+=g.body}google.maps.event.addListener(tmpThis.layerMgrArray[b].data[f],"click",function(){tmpThis.infoWindow.setContent(e);tmpThis.infoWindow.open(tmpThis.map,tmpThis.layerMgrArray[b].data[f]);$("#"+tmpThis.mapSidebar+" div").removeClass("bSideSelect");$("#"+tmpThis.mapSidebar+' div[rel="'+b+" "+f+'"]').addClass("bSideSelect");var h=$("#"+tmpThis.mapSidebar).scrollTop()+$("#"+tmpThis.mapSidebar+' div[rel="'+b+" "+f+'"]').position().top-($("#"+tmpThis.mapSidebar).offset().top+($("#"+tmpThis.mapSidebar).height()/2));$("#"+tmpThis.mapSidebar).animate({scrollTop:h},500)});google.maps.event.addListener(tmpThis.layerMgrArray[b].data[f],"infowindowclose",function(){$("#"+tmpThis.mapSidebar+' div[rel="'+b+" "+f+'"]').removeClass("bSideSelect")})}if(tmpThis.useSidebar){$('<div rel="'+b+" "+f+'">'+g.title+"</div>").click(function(){google.maps.event.trigger(tmpThis.layerMgrArray[b].data[f],"click");$("#"+tmpThis.mapSidebar+" div").removeClass("bSideSelect");$(this).addClass("bSideSelect")}).appendTo("#"+tmpThis.mapSidebar)}});if(a.visible!="true"){for(i=0,j=tmpThis.layerMgrArray[b].data.length;i<j;i++){tmpThis.layerMgrArray[b].data[i].setMap(null);$("#"+tmpThis.mapSidebar+' div[rel^="'+b+'"]').hide()}$("#bMapLyr"+b).addClass("bLyrHide");return false}this.refreshLayerbar();return this};bMap.prototype.AJAXMarkers=function(c){var b={serviceURL:"mapService.php",action:"getMarkers",vars:[],options:{}};var c=$.extend(b,c);var a=this;$("#"+this.mapCanvas+"bMapLoadMsg").show();$.getJSON(c.serviceURL,{action:c.action,vars:c.vars},function(d){c.options=$.extend(d,c.options);a.insertMarkers(c.options);$("#"+a.mapCanvas+"bMapLoadMsg").hide()});return this};bMap.prototype.insertLine=function(c){tmpThis=this;var a=tmpThis.layerMgrArray.length;var d={name:"Layer"+a,type:"line",visible:"true",color:"#00F",weight:5,opacity:1};var c=$.extend(d,c);tmpThis.layerMgrArray[a]=c;tmpThis.layerMgrArray[a].toggleLayer=function(){if(this.visible!="false"){this.visible="false";this.data.setMap(null);$("#bMapLyr"+a).addClass("bLyrHide");return false}else{this.visible="true";this.data.setMap(tmpThis.map);$("#bMapLyr"+a).removeClass("bLyrHide");return true}};var b=[];jQuery.each(c.data,function(e,f){b.push(new google.maps.LatLng(f.lat,f.lng))});tmpThis.layerMgrArray[a].data=new google.maps.Polyline({path:b,strokeColor:tmpThis.layerMgrArray[a].color,strokeOpacity:parseFloat(tmpThis.layerMgrArray[a].opacity),strokeWeight:parseInt(tmpThis.layerMgrArray[a].weight)});tmpThis.layerMgrArray[a].data.setMap(tmpThis.map);if(c.visible!="true"){tmpThis.layerMgrArray[a].data.setMap(null)}this.refreshLayerbar();return this};bMap.prototype.AJAXLine=function(b){var c={serviceURL:"mapService.php",action:"getLine",vars:[]};var b=$.extend(c,b);var a=this;$("#"+this.mapCanvas+"bMapLoadMsg").show();$.post(b.serviceURL,{action:b.action,vars:b.vars},function(d){a.insertLine(d);$("#"+a.mapCanvas+"bMapLoadMsg").hide()},"json");return this};bMap.prototype.insertPolygon=function(d){tmpThis=this;var b=tmpThis.layerMgrArray.length;var a={name:"Layer"+b,type:"polygon",visible:"true",color:"#00F",weight:5,opacity:0.5};var d=$.extend(a,d);tmpThis.layerMgrArray[b]=d;tmpThis.layerMgrArray[b].toggleLayer=function(){if(this.visible!="false"){this.visible="false";this.data.setMap(null);$("#bMapLyr"+b).addClass("bLyrHide");return false}else{this.visible="true";this.data.setMap(tmpThis.map);$("#bMapLyr"+b).removeClass("bLyrHide");return true}};var c=[];jQuery.each(d.data,function(e,f){c.push(new google.maps.LatLng(f.lat,f.lng))});tmpThis.layerMgrArray[b].data=new google.maps.Polygon({path:c,strokeColor:tmpThis.layerMgrArray[b].color,strokeOpacity:1,strokeWeight:parseInt(tmpThis.layerMgrArray[b].weight),fillColor:tmpThis.layerMgrArray[b].color,fillOpacity:parseFloat(tmpThis.layerMgrArray[b].opacity)});tmpThis.layerMgrArray[b].data.setMap(tmpThis.map);if(d.visible!="true"){tmpThis.layerMgrArray[b].data.setMap(null)}this.refreshLayerbar();return this};bMap.prototype.AJAXPolygon=function(b){var c={serviceURL:"mapService.php",action:"getPolygon",vars:[]};var b=$.extend(c,b);var a=this;$("#"+this.mapCanvas+"bMapLoadMsg").show();$.post(b.serviceURL,{action:b.action,vars:b.vars},function(d){a.insertPolygon(d);$("#"+a.mapCanvas+"bMapLoadMsg").hide()},"json");return this};bMap.prototype.removeAllLayers=function(){for(i=0,j=this.layerMgrArray.length;i<j;i++){if(this.layerMgrArray[i].type=="marker"){for(i2=0,j2=this.layerMgrArray[i].data.length;i2<j2;i2++){this.layerMgrArray[i].data[i2].setMap(null)}this.infoWindow.close()}else{this.layerMgrArray[i].data.setMap(null)}this.layerMgrArray[i].data=0;if(this.useSidebar){$("#"+this.mapSidebar+' div[rel^="'+i+'"]').remove()}}this.layerMgrArray.length=0;this.refreshLayerbar();return this};bMap.prototype.removeLayer=function(a){if(this.layerMgrArray[a].type=="marker"){for(i2=0,j2=this.layerMgrArray[a].data.length;i2<j2;i2++){this.layerMgrArray[a].data[i2].setMap(null)}}else{this.layerMgrArray[a].data.setMap(null)}this.layerMgrArray[a].data=0;if(this.useSidebar){$("#"+this.mapSidebar+' div[rel^="'+a+'"]').remove()}this.refreshLayerbar();return this};bMap.prototype.popLayer=function(){var a=this.layerMgrArray.length-1;var b=this.layerMgrArray.pop();if(b.type=="marker"){for(i2=0,j2=b.data.length;i2<j2;i2++){b.data[i2].setMap(null)}}else{b.data.setMap(null)}b.data=0;if(this.useSidebar){$("#"+this.mapSidebar+' div[rel^="'+a+'"]').remove()}this.refreshLayerbar();return this};bMap.prototype.shiftLayer=function(){for(i3=0,j3=this.layerMgrArray.length;i3<j3;i3++){if(this.layerMgrArray[i3].data!=0){var a=i3;break}}if(this.layerMgrArray[a].type=="marker"){for(i2=0,j2=this.layerMgrArray[a].data.length;i2<j2;i2++){this.layerMgrArray[a].data[i2].setMap(null)}}else{this.layerMgrArray[a].data.setMap(null)}this.layerMgrArray[a].data=0;this.layerMgrArray[a].name="";this.layerMgrArray[a].type="";if(this.useSidebar){$("#"+this.mapSidebar+' ^"'+a+'"]').remove()}this.refreshLayerbar();return this};bMap.prototype.refreshLayerbar=function(){if(this.mapLayerbar){var b=this;$("#"+this.mapLayerbar).html("");for(var d=0,c=this.layerMgrArray.length;d<c;d++){if(this.layerMgrArray[d].data!=0){if(this.layerMgrArray[d].visible!="false"){var a=""}else{a="class='bLyrHide' "}$("<div "+a+"id='bMapLyr"+d+"' rel='"+d+"'>"+this.layerMgrArray[d].name+"</div>").click(function(){b.layerMgrArray[$(this).attr("rel")].toggleLayer()}).appendTo("#"+this.mapLayerbar)}}}};bMap.prototype.centerAtAddress=function(b){var a=this;this.geoCoder.geocode({address:b},function(d,c){if(c==google.maps.GeocoderStatus.OK){a.map.setCenter(d[0].geometry.location)}});return this};



var MYMAP = {
    map: null,bounds: null,markersArray: [],markersArrayHTML: []
}

MYMAP.init = function(selector, latLng, zoom) {
    //[52.8492298820527,-1.142578125] layLng
    var myOptions = {
        zoom:11,
        mapCenter: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    this.map = new google.maps.Map($(selector)[0], myOptions);
    this.bounds = new google.maps.LatLngBounds();
}

function cm_markerClicked(markerNum) {
  var infowindowOptions = {
    content: MYMAP.markersArrayHTML[markerNum]
  }
  var infowindow = new google.maps.InfoWindow(infowindowOptions);
  infowindow.open(MYMAP.map, MYMAP.markersArray[markerNum]);
}

function codeAddress(address) {
    //geocoder = new google.maps.Geocoder();
    //var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        MYMAP.map.setCenter(results[0].geometry.location);
        MYMAP.map.setZoom(11);
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }

function openInFacebox(url) {
        $('#facebox .body').width('800px');
        $.facebox({ ajax: url });
}

MYMAP.placeMarkers = function(filename) {
//$('#map').data('bMap').removeAllLayers()
    if (MYMAP.markersArray) {
        for (i in MYMAP.markersArray) {
            MYMAP.markersArray[i].setMap(null);
        }
        MYMAP.markersArray.length = 0;
        MYMAP.markersArrayHTML.length = 0;
    }


    var data2 = "<h2>Search Results</h2>";
    var data = "";
    $.get(filename, function(xml){
        j=0;
        data = data+"<p><b>Courses found "+$(xml).find("results").text();
        if ($(xml).find("results").text() > 30) {
            data = data+" only 30 records shown";
        }
        data = data+"</b></p>";
        data2 = data2+"";
        
        $(xml).find("club").each(function(){
            var cmid = $(this).attr('id');
            var clubname = $(this).find('clubname').text();
            var address = $(this).find('address').text();
            var url = $(this).find('url').text();
            var rating = $(this).find('rating').text();
            var img_thumb = $(this).find('img_thumb').text();
            var description = $(this).find('description').text();
            if (img_thumb == '') { img_thumb = '/images/no_photo_available.gif'; }
            // create a new LatLng point for the marker
            var lat = $(this).find('lat').text();
            var lng = $(this).find('lon').text();
            var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
            // extend the bounds to include the new point
            MYMAP.bounds.extend(point);
            var marker = new google.maps.Marker({
                position: point,
                map: MYMAP.map
            });
            MYMAP.markersArray.push(marker);
            var infoWindow = new google.maps.InfoWindow();
            //'+address+'<br/>
            var popurl = '/course/courseReviewPop.php?ID='+cmid;
            //<img src=\"'+img_thumb+'\" align=\"left\" class=\"thumb\">
            var html='<strong>'+clubname+'</strong><br />'+address+'<br /><a href=\"'+url+'\">View</a>';
            MYMAP.markersArrayHTML.push(html);
            google.maps.event.addListener(marker, 'click', function() {
                infoWindow.setContent(html);
                infoWindow.open(MYMAP.map, marker);
            });
            //var title = $(this).find("clubname").attr("title");
            //var surname = $(this).find("surname").text();
            //data = data + title + " " + firstname + " " + surname + "<br>";
            //<div id=\"productCinfoImg\"><img src=\"'+img_thumb+'\"  align=\"left\" class=\"thumb\"></div> rated '+rating+'<br/><br/>'+description+'
            data2 = data2 + '<div id=\"productCinfo\"><div id=\"productCinfoText\"><a href=\"javascript:cm_markerClicked('+j+')\">' + clubname + '</a><br/><br/><a href=\"'+url+'\">Full Information</a></div></div>';
            //MYMAP.map.fitBounds(MYMAP.bounds);
            //MYMAP.map.setCenter(point);
            //MYMAP.map.setCenter(51.31714872961282,-1.0788917541503906);
            j++;
        });
        $("#maptopBar").html(data);
        $("#mapsideBar").html(data2);
        $('a[rel*=facebox]').facebox();
        $.facebox.settings.opacity = 0.5;
    });

}
function getCourseData(pass) {
          var bounds = MYMAP.map.getBounds();
          var lat = bounds.getSouthWest().lat();
          var lon = bounds.getSouthWest().lng();
          var lat2 = bounds.getNorthEast().lat();
          var lon2 = bounds.getNorthEast().lng();
          //MYMAP.map.getCenter();
          var urlstr = "";
          if (pass == 1) {
          lat=52.872;
          lon=-1.316;
          lat2=53.038;
          lon2=-0.982;
          }
          if ($('#TT').is(':checked')) { urlstr += "&tt=1"; }
          if ($('#SOCOK').is(':checked')) { urlstr += "&socok=1"; }
          if ($('#SOCDEAL').is(':checked')) { urlstr += "&socdeal=1"; }
          if ($('#DAYMEM7').is(':checked')) { urlstr += "&daymem7=1"; }
          if ($('#DAYMEM5').is(':checked')) { urlstr += "&daymem5=1"; }
          if ($('#VOUDEAL').is(':checked')) { urlstr += "&voudeal=1"; }
          if ($('#DRVRNG').is(':checked')) { urlstr += "&drvrng=1"; }
          if ($('#HANDICAP').is(':checked')) { urlstr += "&hcp=1"; }
          if ($('#BGYHIRE').is(':checked')) { urlstr += "&bgy=1"; }
          if ($('#RES').is(':checked')) { urlstr += "&res=1"; }
          if ($('#CLUBHOUSE').is(':checked')) { urlstr += "&clubhouse=1"; }
          if ($('#BAR').is(':checked')) { urlstr += "&bar=1"; }
          if ($('#CHGRM').is(':checked')) { urlstr += "&chgrm=1"; }
          if ($('#PROSHP').is(':checked')) { urlstr += "&proshp=1"; }
          if ($('#GSHCP').is(':checked')) { urlstr += "&gshcp=1"; }

          var url = 'http://server.golfscoretracker.co.uk/api/api.php?rpc=getClub&key=a0f794cc2a57745b041272ed702e6486&radius=50&max=30&lat='+lat+'&lon='+lon+'&lat2='+lat2+'&lon2='+lon2+urlstr;
          var dt = new Date();
          var proxy = '/proxy.php?currDate='+dt.getTime()+'&proxy_url=';
          url = proxy + encodeURIComponent(url);
          MYMAP.placeMarkers(url);
        }


