// JavaScript Document


function imgswap2(theid, state)
	{
	document.getElementById(theid).src = 'gfx/buttons/menuarrow'+state+'.gif';
	//document.getElementById('test').innerHTML = 'gfx/backgrounds/'+theid+state+'.gif';
	}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  var w = window.open(theURL,winName,features);
  w.focus();
}

function subformpc()
	{
	if(document.searchbypc.postcode.value.length >1)
		{
			document.searchbypc.submit()
			//location.href='quicksearch.php?qstext='+document.sf.qstext.value+'&soption='+document.sf.soption.value;
		}
		else
		{
			alert('Oops, you didn\'t enter a post code!');
		}
	}
	
function subform()
	{
	if(document.searchbysport.qstext.value.length >1)
		{
			document.searchbysport.submit()
			//location.href='quicksearch.php?qstext='+document.sf.qstext.value+'&soption='+document.sf.soption.value;
		}
		else
		{
			alert('Oops, you didn\'t enter a search!');
		}
	}
	
function subformdir()

		{
			document.searchbyborough.submit()
			//location.href='quicksearch.php?qstext='+document.sf.qstext.value+'&soption='+document.sf.soption.value;
		}


function menuhover(cellname)
	{
		document.getElementById(cellname).style.backgroundImage = "url(gfx/blkmenubarhover.gif)";
		document.getElementById(cellname).style.backgroundRepeat = "repeat-x";
		document.getElementById(cellname+'link').style.color = "#000000";
		//tweenit(cellname+'link', 'color', '#000000');
	}
	
function menuout(cellname)
	{
		document.getElementById(cellname).style.backgroundImage = "none";
		document.getElementById(cellname+'link').style.color = "#FFFFFF";
		//tweenit(cellname+'link', 'color', '#FFFFFF');
	}
	
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Msxml2.XMLHTTP");

    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function showFeed(rssfeed, title, ts)
	{
		document.getElementById('rsstitle').innerHTML = title;
		document.getElementById('rssfeed'+ts).innerHTML = "Loading, please wait....";
		http.open('get', 'chngrss.php?rss='+rssfeed+'&ts='+ts);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}

function listscat()
	{
		http.open('get', 'listsubcats.php?mcat='+document.wform.mcat.value);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}
	
function senpw(email)
	{
		http.open('get', 'sndpw.php?email='+email);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}

function submitpoll()
	{
		 chosen = ""
				len = document.pollform.answer.length
				
				for (i = 0; i <len; i++) {
				if (document.pollform.answer[i].checked) {
				chosen = document.pollform.answer[i].value
				}
				}
				
				if (chosen == "") {
				alert("No Answer Selected")
				}
				else {
					http.open('get', 'polls/submitpoll.php?qid='+document.pollform.qid.value+'&aid='+chosen+'&ip='+document.pollform.ip.value);
					http.onreadystatechange = handleResponse;
					http.send(null);
				}
	}

function addMapArea(sid, aid)
	{
		document.getElementById('selection'+sid).innerHTML = "<img src=\"gfx/loading.gif\" height=\"16\" width=\"16\" /> Loading, please wait";
		ts = Date.parse( new Date() );
		http.open('get', 'addmaparea.php?sid='+sid+'&aid='+aid+ "&ts=" + ts);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}
	
function delMapArea(sid, aid)
	{
		document.getElementById('selection'+sid).innerHTML = "<img src=\"gfx/loading.gif\" height=\"16\" width=\"16\" /> Loading, please wait";
		ts = Date.parse( new Date() );
		http.open('get', 'delmaparea.php?sid='+sid+'&aid='+aid+ "&ts=" + ts);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}
	
function addMapArea2()
	{
		if (document.addform.aid.value == 'nill')
		{
			alert('Invalid selection, Please select an area or click GO');
		}
		else
		{
		document.getElementById('selection'+document.addform.sid.value).innerHTML = "Loading, please wait";
		http.open('get', 'addmaparea.php?sid='+document.addform.sid.value+'&aid='+document.addform.aid.value);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
		}
		
	}
	
function addMapMcat()
	{
		sid = document.catsel.sid.value;
		document.getElementById('subcatdir'+sid).innerHTML = "Loading, please wait";
		document.getElementById('instr'+sid).innerHTML = "<strong>PART 2 OF 2</strong><br />Now select one of the sub-catagories from your chosen sport/s and your results will appear below. Note, you can switch between your sports and sub-catagories. You can even add more sports to browse by selecting another sport and clicking go. Your results are indicated by the results box title bar. Your search is saved on our system. To clear the search, click Re-Start on the first page or Reset Search next to the green go button.";
		ts = Date.parse( new Date() );
		http.open('get', 'addmapmcat.php?sid='+document.catsel.sid.value+'&aid='+document.catsel.aid.value+ "&ts=" + ts);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}

function getResults(sid, aid, scid, titletxt, name)
	{
		
		document.getElementById('results'+sid).innerHTML = "Loading, please wait";
		document.getElementById('titletxt'+sid).innerHTML = "Results for "+titletxt+" - "+name;
		ts = Date.parse( new Date() );
		http.open('get', 'getresults.php?sid='+sid+'&mcid='+aid+'&scid='+scid+ "&ts=" + ts);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function handleResponse2() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
document.dform.html.value = document.getElementById('hairsearch').innerHTML;
        }
    }
}

function refine()
	{
		if (document.dform.type.value != 'all'){
			setTimeout("resetRefine()", 150);
			setTimeout("doRefine()", 250);
			
		} else {resetRefine();}
	}

function resetRefine()
	{
		var cidlist = document.getElementById('all').value;
		var cidarray = cidlist.split('#');
		for (var i=0; i<cidarray.length-1; i++) {
			document.getElementById(cidarray[i]).style.backgroundColor = '#FFFFFF';
		}
		document.getElementById('filtertext').innerHTML = 'All deselected';
		document.dform.html.value = document.getElementById('hairsearch').innerHTML;
	}

function doRefine()
	{
		var count = 0;
		var subcatid = document.dform.type.value;
		var cidlist = document.getElementById(subcatid).value;
		var cidarray = cidlist.split('#');
		for (var i=0; i<cidarray.length-1; i++) {

			document.getElementById(cidarray[i]).style.backgroundColor = '#FEFB83';
			count++; 
			}
			document.getElementById('filtertext').innerHTML = '<span style="background-color:#FEFB83">'+count+' Highlighted </span>';
		document.dform.html.value = document.getElementById('hairsearch').innerHTML;
	}

function selectday(day, month)
	{
		document.searchform.cdate.value = day;
		document.searchform.cmonth.value = month;
		doSearchW();
	}

function doSearchW() {
    //document.getElementById('sresult').innerHTML = 'Loading....';
	http.open('get', 'dosearchw.php?mcat='+document.searchform.mcat.value+'&date='+document.searchform.cdate.value+'&month='+document.searchform.cmonth.value);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function chgscalen() {
	month = document.searchform.month.value;
	year = document.searchform.year.value;
	//aid = document.calendar.aid.value;
	http.open('get', 'changecals.php?m='+month+'&y='+year+'&aid=n');
    http.onreadystatechange = handleResponse;
    http.send(null);
	//selectday('all', month);
}


function chkpswd() {

	if(document.eform.pswd.value == document.eform.pswdconf.value)
		{
			document.getElementById('password').innerHTML = "<strong style=\"color:#009900\">Password OK</strong>"
		}
		else
		{
			document.getElementById('password').innerHTML = "<strong style=\"color:#FF0000\">X</strong>"
		}
}



function chkuser() {
	var howbig = document.eform.username.value;
	if(howbig.length < 3)
	{
    document.getElementById('usercheck').innerHTML = 'URL requires 3 or more letters';
	} else
	{
	http.open('get', 'checkuser.php?username='+document.eform.username.value);
    http.onreadystatechange = handleResponse;
    http.send(null);
	}
}

function findclub() {
    //document.getElementById('sresult').innerHTML = 'Loading....';
	http.open('get', 'findclub.php?clubname='+document.eform.email.value);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function linkclub(id, name)
	{
		document.eform.clubid.value=id;
		document.getElementById('clubcheck').innerHTML = 'You Selected:<br>'+name;
	}

function chkSubmit()
{
if (document.eform.clubid.value=='0')
	{
		alert('Please select a club by entering your clubs email, clicking the confirm email button and then clicking SELECT THIS CLUB next to the club name that appears');
	}
	else
	{
for (i=0;i<9;i++)
	{
box = document.eform.elements[i]; 
	if (!box.value)
		{
		var check = 1;
		document.eform.elements[i].style.borderColor='#FF0000';
		}
		else {document.eform.elements[i].style.borderColor='#ABD0BC';}
	}
if (check == 1)
	{
	 alert('One or more required fields are empty');
	}
	else
	{
	if (document.eform.pswd.value == document.eform.pswdconf.value)
		{
			if (document.eform.urlchk.value == 'y')
				{
					document.eform.submit();
				}
				else
				{
					alert('Your profile address cannot be accepted. No spaces or characters other than numbers and letters are required. Must contain more than 3 characters');
				}
		}
		else
		{
		document.eform.elements[6].style.backgroundColor='#FFBFBF';
		document.eform.elements[7].style.backgroundColor='#FFBFBF';
		alert('Password and confirmation password do not match, please try again');
		}
	}
}
}
function addwoDay(day, aid, mcat) {
    //document.getElementById('result').innerHTML = 'Loading....';
	http.open('get', 'addday.php?day='+day+'&aid='+aid+'&mcat='+mcat+'&timehr='+document.calendar.timehr.value+'&timemin='+document.calendar.timemin.value+'&scid='+document.calendar.scid.value);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
//calen functions
function deldate(ts, aid) {
	http.open('get', 'delday.php?ts='+ts+'&aid='+aid);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function chgcalen() {
	month = document.calendar.month.value;
	year = document.calendar.year.value;
	aid = document.calendar.aid.value;
	http.open('get', 'changecalev.php?m='+month+'&y='+year+'&aid='+aid);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function selectday(day, month)
	{
		document.searchform.cdate.value = day;
		document.searchform.cmonth.value = month;
		doSearchW();
	}

function userlogin()
	{
	var check = 0;
	for (i=0;i<2;i++)
		{
		box = document.login.elements[i]; 
		if (!box.value)
			{
			var check = 1;
			document.login.elements[i].style.backgroundColor='#FFBFBF';
			}
		else {document.login.elements[i].style.backgroundColor='#ABD0BC';}
		}
		if (check != 1){document.login.submit();} else {alert('please enter your email address and password');}
	}
	
function reloadStats()
	{
		window.setTimeout("statsLoad()", 25000);
	}

function statsLoad() {
	http.open('get', 'statsupdate.php');
    http.onreadystatechange = handleResponse;
    http.send(null);
	reloadStats();
}

function editGi(uid, cid)
	{
		formcontent = document.getElementById('gihtml').value;
		document.getElementById('gi').innerHTML="<form name=\"editGi\" action=\"editgi.php?id="+uid+"&cid="+cid+"\" method=\"post\"><textarea name=\"gi\" style=\"font-family:'Trebuchet MS', Arial, sans-serif; width:590px; font-size:14px; height:200px; border:hidden\">"+formcontent+"</textarea><br /><input type=\"submit\" value=\"Save\" /></form>";	
		document.editGi.gi.focus();
	}
function menuhover2(cellname)
	{
		document.getElementById(cellname).style.backgroundImage = "url(gfx/blumenubar.gif)";
		document.getElementById(cellname).style.backgroundRepeat = "repeat-x";
		document.getElementById(cellname+'link').style.color = "#D9D9FF";
	}
	
function menuout2(cellname)
	{
		document.getElementById(cellname).style.backgroundImage = "none";
		document.getElementById(cellname+'link').style.color = "#FFFFFF";
	}

function showNe()
	{
		document.getElementById('ned').style.visibility = "visible";
		document.getElementById('ned').style.height = "160px";

	}

function showGm()
	{
		document.getElementById('map').style.visibility = "visible";
		document.getElementById('map').style.height = "400px";
		//document.getElementById('tbmap').style.height = "400px";
		document.getElementById('gmlink').innerHTML = "<a href=\"javascript:hideGm();\">Hide Map</a>";
		//map.setCenter(point, 15);
	}
	
function hideGm()
	{
		document.getElementById('map').style.visibility = "hidden";
		document.getElementById('map').style.height = "0px";
		document.getElementById('gmlink').innerHTML = "<a href=\"javascript:showGm();\">Show Map</a>";
	}

function reloadmail()
	{
		window.setTimeout("mailLoad()", 1000);
	}

function mailLoad()
	{
		http.open('get', 'mailconsexe.php?mid='+document.wform.mid.value+'&tot='+document.wform.total.value);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
		document.title = document.getElementById('percent').value;
		if (document.getElementById('finished').value == 'n') {reloadmail();} else {document.title = 'COMPLETED';}
	}
	
function regformsub()
	{
		for (i=0;i<11;i++)
		{
			box = document.eform.elements[i]; 
			if (!box.value)
				{
				var check = 1;
				document.eform.elements[i].style.borderColor='#FF0000';
				}
		else {document.eform.elements[i].style.borderColor='#ABD0BC';}
	}
if (check == 1)
	{
	 alert('One or more required fields are empty');
	}
	else
		{
		document.eform.submit();	
		}
	}
	
	
function spacelogin()
	{
	var check = 0;
	for (i=0;i<3;i++)
		{
		box = document.oslogin.elements[i]; 
		if (!box.value)
			{
			var check = 1;
			document.oslogin.elements[i].style.backgroundColor='#FFBFBF';
			}
		else {document.oslogin.elements[i].style.backgroundColor='#ABD0BC';}
		}
		if (check != 1){document.oslogin.submit();} else {alert('please enter your username, email address and password');}
	}
	

function oslogin()
	{
	var check = 0;
	for (i=0;i<3;i++)
		{
		box = document.oslogin.elements[i]; 
		if (!box.value)
			{
			var check = 1;
			document.oslogin.elements[i].style.backgroundColor='#FFBFBF';
			}
		else {document.oslogin.elements[i].style.backgroundColor='#ABD0BC';}
		}
		if (check != 1){document.oslogin.submit();} else {alert('please enter your username, email address and password');}
	}
	
function tweenit(id, attrib, value)
	{
		$(id).set('tween', {
				duration: 3000,
				transition: Fx.Transitions.Circ.easeOut // This could have been also 'bounce:out'
			}).tween(attrib, value);	
	}
	
function pcLookup()
	{
		pc = document.dform.postcode.value;
		sport = document.dform.selcat.value;
		tweenit('areabox', 'background-color', '#FFFB9F');
		document.getElementById('pcode').innerHTML = "<img src='clubhouse/images/icons/loading.gif' /><br>Searching...";
		if (pc.length>2)
			{
				//document.dform.reset();
				document.dform.postcode.value = pc;
				document.getElementById('hairsearch').innerHTML = "<table width='100%' style='background-color:#FFFFFF; height:30px'><tr><tr><td><img src='clubhouse/images/icons/search16.gif' /></td><td>Checking your post code... click the SHOW NOW button when it appears above</td></tr></table>";
			}
		http.open('get', 'inc/pclookup.php?pc='+pc+'&sport='+sport);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}
	
function nameLookup()
	{
		name = document.dform.name.value;
		tweenit('areabox', 'background-color', '#FFFB9F');
		document.getElementById('pcode').innerHTML = "<img src='clubhouse/images/icons/loading.gif' /><br>Minimum 3 characters required";
		if (name.length>2)
			{
				document.getElementById('pcode').innerHTML = "<img src='clubhouse/images/icons/loading.gif' /><br>Searching....";
				http.open('get', 'inc/namelookup.php?name='+name);
    			http.onreadystatechange = handleResponse2;
    			http.send(null);
				document.getElementById('pcode').innerHTML = "Search valid, your results will load below.";
				document.getElementById('hairsearch').innerHTML = "Searching, please wait ....";
			} else {document.getElementById('hairsearch').innerHTML = "Keep typeing";}
		
	}

function areaLookup()
	{
		document.dform.postcode.value = '';
		document.dform.type.options[0].selected=true;
		document.getElementById('hairsearch').innerHTML = "Searching, please wait ....<br>Please click <strong>show now</strong> if nothing happens";
		cid = document.dform.selarea.value;
		http.open('get', 'inc/arealookup.php?cid='+cid);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
		setTimeout("showNowArea()", 1250);
	}
	
function showNowPc()
	{
		document.getElementById('hairsearch').innerHTML = "<table width='100%' style='background-color:#FFFFFF'><tr><td><img src='clubhouse/images/icons/loading2.gif' /></td><td>Calculating distances, please wait ....</td></tr></table>";
		pc = document.dform.postcode.value;
		cid = document.dform.cid.value;
		mcat = document.dform.selcat.value;
		document.dform.cidtmp.value = cid;
		document.dform.stypetmp.value = document.dform.stype.value;
		http.open('get', 'inc/dirsearchpc.php?pc='+pc+'&cid='+cid+'&selcat='+mcat);
    	http.onreadystatechange = handleResponse2;
    	http.send(null);
	}

function showNowArea()
	{
		document.getElementById('hairsearch').innerHTML = "Loading ....";
		cid = document.dform.cid.value;
		document.dform.cidtmp.value = cid;
		document.dform.stypetmp.value = document.dform.stype.value;
		http.open('get', 'inc/dirsearcharea.php?cid='+cid);
    	http.onreadystatechange = handleResponse;
    	http.send(null);
	}
	
function getHtml()
	{
		if(document.dform.html.value != 'n')
		{
		document.getElementById('hairsearch').innerHTML = document.dform.html.value;
		document.dform.cid.value = document.dform.cidtmp.value;
		document.dform.stype.value = document.dform.stypetmp.value;
		}
	}
	
