function chk_browser()
	{
	if(!document.getElementsByTagName){alert('You will need to update your browser to view this site properly')}
	else{menu()}
	}
	
function menu()
	{
	navRoot = document.getElementById("nav");
	for (i=0;i<navRoot.childNodes.length;i++) 
		{
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") 
			{
			node.onmouseover=function(){this.className="show"}
			node.onclick	=function(){this.className="show"}
			node.onmouseout =function(){this.className=""}
			}
		}		
	}
	
function flash_movie()
	{
	document.write ('<object type="application/x-shockwave-flash" data="/images/movie.swf?link=/" id=flash width="760" height="180">')
	document.write ('<param name="movie" value="/images/movie.swf?link=/">')
	document.write ('<param name="wmode" value="transparent">')
	document.write ('</object>') 
	}

google_ad_client = "pub-4285960298918530";
google_ad_type = "text";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_channel ="2417700354";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "990000";
google_color_url = "cccccc";
google_color_text = "000000";

function ads2()
	{
	google_ad_client = "pub-4285960298918530";
	google_ad_type = "text";
	google_ad_width = 468;
	google_ad_height = 60;
	google_ad_format = "468x60_as";
	google_ad_channel ="2417700354";
	google_color_border = "FFFFFF";
	google_color_bg = "FFFFFF";
	google_color_link = "990000";
	google_color_url = "cccccc";
	google_color_text = "000000";
	}

window.name='home'

function get_logos()
	{
	document.write ('<p class=sponsors>')
	document.write ('<a href="http://www.play-cricket.com" target="_blank"><img src="http://img.nidderdaleleague.co.uk/images/play-cricket.gif" border=0 alt="Play Cricket"><\/a>')
	//document.write ('<a href="http://www.harrogatetoday.co.uk" target="_blank"><img src="/images/harrogate-today.gif" border=0 alt="Harrogate Today"><\/a>')
	document.write ('<a href="http://www.arrowselfdrive.com/" target="_blank"><img src="http://img.nidderdaleleague.co.uk/images/arrow-readydrive_logo.gif" alt="Arrow Ready Drive" border=0><\/a>')
	document.write ('<a href="http://www.ycb-yca.org.uk" target="_blank"><img src="http://img.nidderdaleleague.co.uk/images/cyb.gif" border=0 hspace=5 alt="YCB"><\/a>')
	document.write ('<\/p>')
	}
		
function news()
	{
	mt=false;fm=document.news
	checker(fm.title2,'Title');checker(fm.details,'News')
	if(mt==false){fm.submit()}
	}
	
function get_tables()
	{
	y=document.tables.yr.options[document.tables.yr.selectedIndex].text
	d=document.tables.division.options[document.tables.division.selectedIndex].value
	if(parseInt(y) && parseInt(d))location.href='?yr='+ y + '&division='+ d	
	}
	
function minutes()
	{
	mt=false;fm=document.minutes
	checker(fm.title2,'Title');checker(fm.minutes,'Minutes')
	if(mt==false){fm.submit()}
	}

function results()
	{
	mt=false;fm=document.results
	checker(fm.results,'Results')
	if(mt==false){fm.submit()}
	}
	
function fixtures()
	{
	mt=false;fm=document.fixtures
	checker(fm.fixtures,'Fixtures')
	if(mt==false){fm.submit()}
	}
	
function login()
	{
	mt=false;fm=document.members
	checker(fm.userid,'User Name');checker(fm.password,'Password')
	if(mt==false){fm.submit()}
	}

function get_days(fm)
	{
	a=new Date(fm.ydate.options[fm.ydate.selectedIndex].text,fm.mdate.options[fm.mdate.selectedIndex].value,0);
	b=a.getDate();fm.ddate.options.length=b;
	for(x=1;x<=b;x++){fm.ddate.options[x-1].text=x}
	}
		
function result()
	{
	mt=false;fm=document.results
	ncheck(fm.markings,'Markings');ncheck(fm.outfield,'Outfield');ncheck(fm.pitch,'Pitch');ncheck(fm.square,'Square')
	checker(fm.home,'Home');checker(fm.opposition,'Opposition');option_checker(fm.type,'Match type');
	ncheck(fm.start1,'Start time (hours)');ncheck(fm.start2,'Start time (mins)');ncheck(fm.finish1,'Finish time (hours)');ncheck(fm.finish2,'Finish time (mins)');
	checker(fm.sent,'Sheet Sent in by');checker(fm.result,'Result');ncheck(fm.sport,'Sportsmanship');
	ncheck(fm.hpoints,'Points');ncheck(fm.hextras,'Extras');ncheck(fm.opoints,'Points');ncheck(fm.oextras,'Extras')
	for (var a=1;a<12;a++)
		{
		b=eval('document.results.runs'+a);ncheck(b,'Batsman('+a+') Runs')
		ob=eval('document.results.obruns'+a);ncheck(ob,'Batsman('+a+') Runs')
		if(a<11)
			{
			hw=eval('document.results.wicket'+a);ncheck(hw,'Fall of Wicket ('+a+')')
			ow=eval('document.results.owicket'+a);ncheck(ow,'Fall of Wicket ('+a+')')
			}
		ho=eval('document.results.hboovers'+a);ncheck(ho,'Bowler('+a+') Overs')
		hm=eval('document.results.hbomaidens'+a);ncheck(hm,'Bowler('+a+') Maidens')
		hr=eval('document.results.hboruns'+a);ncheck(hr,'Bowler('+a+') Runs')
		hw=eval('document.results.hbowickets'+a);ncheck(hw,'Bowler('+a+') Wickets')
		oo=eval('document.results.oboovers'+a);ncheck(oo,'Bowler('+a+') Overs')
		om=eval('document.results.obomaidens'+a);ncheck(om,'Bowler('+a+') Maidens')
		or=eval('document.results.oboruns'+a);ncheck(or,'Bowler('+a+') Runs')
		ow=eval('document.results.obowickets'+a);ncheck(ow,'Bowler('+a+') Wickets')
		}
		
	if(fm.captcha && fm.captcha.value!=get_cookie('security_code') && mt==false)
		{
		alert('Please ensure you have entered the security code correctly at the bottom of the form');
		fm.captcha.focus()
		mt=true;	
		}	

	if(mt==false){fm.submit()}
	}
	

function get_cookie(Name) 
	{
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) 
		{
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) 
			{ 
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
			}
		}
 	return returnvalue;
	}
	
function result2()
	{
	mt=false;fm=document.results
	checker(fm.home,'Home');checker(fm.opposition,'Opposition');option_checker(fm.type,'Match type');
	ncheck(fm.start1,'Start time (hours)');ncheck(fm.start2,'Start time (mins)');ncheck(fm.finish1,'Finish time (hours)');ncheck(fm.finish2,'Finish time (mins)');
	checker(fm.sent,'Sheet Sent in by');checker(fm.result,'Result')
	ncheck(fm.hpoints,'Points');ncheck(fm.hextras,'Extras');ncheck(fm.opoints,'Points');ncheck(fm.oextras,'Extras')
	for (var a=1;a<12;a++)
		{
		b=eval('document.results.runs'+a);ncheck(b,'Batsman('+a+') Runs')
		ob=eval('document.results.obruns'+a);ncheck(ob,'Batsman('+a+') Runs')
		if(a<11)
			{
			hw=eval('document.results.wicket'+a);ncheck(hw,'Fall of Wicket ('+a+')')
			ow=eval('document.results.owicket'+a);ncheck(ow,'Fall of Wicket ('+a+')')
			}
		ho=eval('document.results.hboovers'+a);ncheck(ho,'Bowler('+a+') Overs')
		hm=eval('document.results.hbomaidens'+a);ncheck(hm,'Bowler('+a+') Maidens')
		hr=eval('document.results.hboruns'+a);ncheck(hr,'Bowler('+a+') Runs')
		hw=eval('document.results.hbowickets'+a);ncheck(hw,'Bowler('+a+') Wickets')
		oo=eval('document.results.oboovers'+a);ncheck(oo,'Bowler('+a+') Overs')
		om=eval('document.results.obomaidens'+a);ncheck(om,'Bowler('+a+') Maidens')
		or=eval('document.results.oboruns'+a);ncheck(or,'Bowler('+a+') Runs')
		ow=eval('document.results.obowickets'+a);ncheck(ow,'Bowler('+a+') Wickets')
		}
		
	if(fm.captcha && fm.captcha.value!=get_cookie('security_code') && mt==false)
		{
		alert('Please ensure you have entered the security code correctly at the bottom of the form');
		fm.captcha.focus()
		mt=true;	
		}	
		
	if(mt==false){fm.submit()}
	}

function home_total()
	{
	tot=0;fm=document.results;e=parseInt(fm.hextras.value)
	for (var a=1;a<12;a++)
		{r=eval('document.results.runs'+a);if(r.value!=""){tot=tot+parseInt(r.value)}}
	if(e){tot=tot+e};fm.htotal.value=tot
	}

function opp_total()
	{tot=0;fm=document.results;e=parseInt(fm.oextras.value);
	for (var a=1;a<12;a++)
		{r=eval('document.results.obruns'+a);if(r.value!=""){tot=tot+parseInt(r.value)}}
	if(e){tot=tot+e};fm.ototal.value=tot
	}
	
function home_total2()
	{
	tot=0;fm=document.results;e=parseInt(fm.hextras.value)
	for (var a=1;a<12;a++)
		{r=eval('document.results.runs'+a);if(r.value!=""){tot=tot+parseInt(r.value)}}
	if(e){tot=tot+e};fm.htotal.value=tot
	
	if(fm.type.options[fm.type.selectedIndex].value==5 || fm.type.options[fm.type.selectedIndex].value==6 || fm.type.options[fm.type.selectedIndex].value==22)
		{p=Math.abs(parseInt(fm.hpenalty.value));s=parseInt(fm.plus1.value);fm.htotal.value=tot+s-p}
	}

function opp_total2()
	{tot=0;fm=document.results;e=parseInt(fm.oextras.value);
	for (var a=1;a<12;a++)
		{r=eval('document.results.obruns'+a);if(r.value!=""){tot=tot+parseInt(r.value)}}
	if(e){tot=tot+e};fm.ototal.value=tot
	
	if(fm.type.options[fm.type.selectedIndex].value==5 || fm.type.options[fm.type.selectedIndex].value==6 || fm.type.options[fm.type.selectedIndex].value==22)
		{p=Math.abs(parseInt(fm.openalty.value));s=parseInt(fm.plus2.value);fm.ototal.value=tot+s-p}
	}
	
function bowl_second(a)
	{document.getElementById("bowl2").innerHTML=a}
	
function bowl_first(a)
	{document.getElementById("bowl1").innerHTML=a}
	
function format_form()	
	{
	//5 or 6 or 22
	fm=document.results
	if(fm.type.options[fm.type.selectedIndex].value==5 || fm.type.options[fm.type.selectedIndex].value==6 || fm.type.options[fm.type.selectedIndex].value==22)
		{
		document.getElementById("plus1").style.color='#000000'
		document.getElementById("pen1").style.color='#000000'
		fm.plus1.style.color='#000000';fm.hpenalty.style.color='#000000'
		fm.plus1.disabled=false;fm.hpenalty.disabled=false
		document.getElementById("plus2").style.color='#000000'
		document.getElementById("pen2").style.color='#000000'
		fm.plus2.style.color='#000000';fm.openalty.style.color='#000000'
		fm.plus2.disabled=false;fm.openalty.disabled=false
		}
	else
		{
		document.getElementById("plus1").style.color='#cccccc'
		document.getElementById("pen1").style.color='#cccccc'
		fm.plus1.style.color='#cccccc';fm.hpenalty.style.color='#cccccc'
		fm.plus1.disabled=true;fm.hpenalty.disabled=true
		document.getElementById("plus2").style.color='#cccccc'
		document.getElementById("pen2").style.color='#cccccc'
		fm.plus2.style.color='#cccccc';fm.openalty.style.color='#cccccc'
		fm.plus2.disabled=true;fm.openalty.disabled=true
		}
	home_total2()
	opp_total2()
	}
	
	
function checker(obj,msg)
	{
	if(obj.value=='' && mt==false){alert('The ' + msg + ' field must not be blank');mt=true;obj.focus()}
	}
	
function ncheck(obj,msg)
	{
	newStr = obj.value
	for(var k=0;k<parseInt(newStr.length);k++){var a=newStr.charAt(k);if(((a<"0" || a>"9") && a!=".")&&mt==false){alert('The ' + msg + ' field must be numeric or left blank');mt=true;obj.focus()}}
	}
	
function feedback()
	{
	mt = false;
	fm 	= document.feedback;
	checker(fm.name,"Players Name");
	checker(fm.email,"E-mail");
	email_validator(fm.email)
	if (mt == false){fm.submit()}
	}
	
//Email Validator Functions
function email_validator(obj)
	{
	var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
	if ((matchArray==null) && mt==false){message("Email address seems incorrect (check @ and .'s)",obj)}
	if (mt==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){message("The username doesn't seem to be valid.",obj)}}
	if (mt==false){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255){message("Destination IP address is invalid!",obj)}}}}
	if (mt==false){var domainArray=domain.match(domainPat);if (domainArray==null){message("The domain name doesn't seem to be valid.",obj)}}
	if (mt==false){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){message("The address must end in a three-letter domain, or two letter country.",obj)}}
	if ((len<2) && empty==false){message("This address is missing a hostname!",obj)}
	}
function message(msg,obj){alert(msg);mt=true;obj.focus()}
// End Email Validator Functions
//==============================

function option_checker(obj,msg)
	{
	o=obj.options[obj.selectedIndex];
	if(o.text=="Select" && mt==false){alert("The "+ msg +" field must be selected");mt=true;o.focus()}
	}
	
function batting(line)
	{
	fm=document.averages;
	baverage	=0;
	innings	= parseInt(eval('fm.innings'+line).value)
	no		= parseInt(eval('fm.no'+line).value)
	runs	= parseInt(eval('fm.runs'+line).value)
	average	= eval('fm.av'+line)
	if ((runs>0 && no>=0 && innings>=0) && innings-no!=0)average.value= roundNumber(runs/(innings-no),2)
	}
	
function bowling(line)
	{
	fm=document.averages;
	baverage	=0;
	bruns	= parseInt(eval('fm.bruns'+line).value)
	wick	= parseInt(eval('fm.wick'+line).value)
	average	= eval('fm.bav'+line)
	if (wick>0 && bruns!=0)average.value= roundNumber(bruns/wick,2)
	}
	
function averages()
	{
	fm=document.averages;
	fm.submit()
	}
	
function roundNumber(num,dec) 
	{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
	}


window.onload = chk_browser