function roundAuthSwitch(varswitch) {
	if (varswitch == 1) {
		document.rounds.action.value = 1;
	} else {
		document.rounds.action.value = 0;
	}
	document.rounds.submit();
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}
	else { 
		document.getElementById(cntfield).innerHTML=maxlimit - field.value.length;
		//var countTxt = document.getElementById('counterTxt').value;
		//document.getElementById('counterTxt').innerHTML="boo";
		//.innerHTML = maxlimit - field.value.length;
	}
}

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) // defeat Safari bug
			targ = targ.parentNode;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;

		if ( targ.tagName.toLowerCase() == 'input' ) {
      		if (code == 38) {
	  			nextTabindex(targ,-1);
      		}
      		if (code == 40) {	  	
	  			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 imgUpload(control){			
	if(navigator.appName == 'Microsoft Internet Explorer'){
		control.value = window.showModalDialog('http://www.golfshake.com/scripts/tiny_mce/plugins/ibrowser/ibrowser_ind.php', new Object(), '').popSrc;
	}
	else {
		window.open('http://www.golfshake.com/scripts/tiny_mce/plugins/ibrowser/ibrowser_ind.php','kfm','modal');
		return false;
	}
}

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 clearForm(obj) {
	obj.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 mailThisUrl(code) {
	m = "I thought this might interest you...";
	t = "on-line golf handicap and golf score tracking site, easy to use, loads of courses and excellent stat facilities available.";
	t = t + " signup now using code " + code;
	t = t + " http://www.golfshake.com/signup.php?code=" + code;
	window.location = "mailto:?subject="+m+"&body="+t;
}

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 = "";
	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") == '')) {
			missinginfo += "\n     - Hole " + i + " Score not numeric";
		}
	}
	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 calcScore () {
	scoreincalc = 0;
	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));
		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.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.gender.options[0].selected) {
		missinginfo += "\n     -  Gender";
	}
	/*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;
}

