	var gAutoPrint =  true;
	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (trymicosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}
		}
	}

	if (!request) {
		alert("Error creating XMLHttpRequest");
	}

	function newsLetterSave(name,surname,email,captcha) {
		var url = "scripts/nl_save.php?name=" + name + "&surname=" + surname + "&email=" + email + "&captcha=" +captcha;
		request.open("GET",url,true);
		request.onreadystatechange = saveSub;
		request.send(null);
	}

	function newsLetterDel(email,captcha) {
		var url = "scripts/nl_del.php?email=" + email + "&captcha=" +captcha;
		request.open("GET",url,true);
		request.onreadystatechange = delSub;
		request.send(null);
	}

	function delSub() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var response = request.responseText;
				document.getElementById("title").innerHTML = "";
				document.getElementById("nl_content").innerHTML = response;
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}

	function saveSub() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var response = request.responseText;
				document.getElementById("nl_content").innerHTML = response;
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}

	function updatePage() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var response = request.responseText;
				history.go(0);
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}


	function loadRes(type,cat,stage,event){
		if (type == "team") {
			var url = "scripts/team_results.php?cat="+cat+"&stage="+stage+"&event="+event;
		} else {
			var url = "scripts/individual_results.php?cat="+cat+"&stage="+stage+"&event="+event;
		}
			document.getElementById("res").innerHTML = "<center><br><br><br><br><img src='img/ajax-loading.gif' border='0'><br><br><br><br></center>";
			request.open("GET",url,true);
			request.onreadystatechange = displayResults;
			request.send(null);
	}

	function displayResults() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var response = request.responseText;
				//alert(response);
				var text = response.split("-|||-");
				document.getElementById("res").innerHTML = text[0];
				document.getElementById("cat").value = text[1];
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}
	
	function loadRes2008(type,cat,stage,event){
		if (type == "team") {
			
			var url = "scripts/2008_team_results.php?cat="+cat+"&stage="+stage+"&event="+event+"&tipe="+type;
		} else {
			var url = "scripts/2008_individual_results.php?cat="+cat+"&stage="+stage+"&event="+event+"&tipe="+type;
		}
			document.getElementById("res").innerHTML = "<center><br><br><br><br><img src='img/ajax-loading.gif' border='0'><br><br><br><br></center>";
			request.open("GET",url,true);
			request.onreadystatechange = displayResults;
			request.send(null);
	}
	
	function printSpecial() {
		if (document.getElementById != null) {
			var html = '<HTML>\n<HEAD>\n';
			if (document.getElementsByTagName != null) {
				var headTags = document.getElementsByTagName("head");
				if (headTags.length > 0)
					html += headTags[0].innerHTML;
				}
		
				html += '\n</HE>\n<BODY>\n';
		
				var printReadyElem = document.getElementById("xsnazzy");
		
				if (printReadyElem != null) {
					html += printReadyElem.innerHTML;
				} else 	{
					alert("Could not find the printReady function");
					return;
				}
				html += '\n</BO>\n</HT>';
				var printWin = window.open("","printSpecial");
				printWin.document.open();
				printWin.document.write(html);
				printWin.document.close();
				if (gAutoPrint) {
					printWin.print();
				} else 	{
					alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
				}	
		}
	}
	
	function getTeamName(e,name) {
		if (name != "") {
			var img = document.getElementById("search");
				img.style.visibility = "visible";
			var date = new Date();
			var timestamp = date.getTime();
			var url = "scripts/find_team.php?teamName="+escape(name)+"&time="+timestamp;
			request.open("GET",url,true);
			request.onreadystatechange = displayTeamNames;
			request.send(null);
		} else {
			var matchList = document.getElementById("matches");
			removeAllMatches(matchList);
			document.getElementById("error").style.visibility = "hidden";
			document.getElementById("error").innerHTML = "";
		}
	}
	
	function displayTeamNames() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var err = document.getElementById("error");
				var response = request.responseText;
				var ret = response.split("----");
				var code = ret[0];
				var matchList = document.getElementById("matches");
				var img = document.getElementById("search");
				img.style.visibility = "hidden";	
				if (code == 0) {
					
					document.getElementById("error").style.visibility = "hidden";
					document.getElementById("error").innerHTML = "";	
					var res = ret[1].split("-||-");
					matchList.style.visibility = "visible";
					matchList.options.length = 0;
					if (res.length-1 > 10) {
						matchList.size = 10;	
					} else {
						matchList.size = res.length-1;	
					}
					for (var i=0; i < res.length-1; i++) {
						var vals = res[i].split("-|||-");
						var newOpt = document.createElement('option');
							newOpt.text = vals[0];
							newOpt.value = vals[1];
						try {
							matchList.add(newOpt,null);	
						} catch(ex)	 {
							matchList.add(newOpt);	
						}
					}	
				} else if (code == 1) {	//DB Error
						err.style.visibility = "visible";
						err.innerHTML = "An error occurred : "+ret[1];
				} else {	//No results
						if (matchList.style.visibility == "visible") {
						removeAllMatches(matchList);
						}
						err.style.visibility = "visible";
						err.innerHTML = ret[1];
				}
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}
	
	function removeAllMatches(el) {
		for (var i=el.length; i >=0; i--) {
			el.remove(i);
		}
		el.size = 0;	
		el.options.length = 0;
		el.style.visibility = 'hidden';
		
	}
	
	function checkcap(val) {
		var url = "scripts/checkcap.php?val="+val; 
		request.open("GET",url,true);
		request.onreadystatechange = capdone;
		request.send(null);	
	}
	
	
	
	function capdone() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				var res1 = request.responseText;
				if (res1 == 1) {
					document.getElementById("capin").value = res1;		
					document.getElementById("cap").innerHTML = "";
					document.getElementById("cap").style.visibility = "hidden";
					document.getElementById("capin").style.borderColor = '#00688F';
					document.getElementById("spaar").disabled = false;
					document.getElementById("spaar").focus();
				} else {
					document.getElementById("cap").innerHTML = res1;
					document.getElementById("cap").style.visibility = "visible";
					document.getElementById("spaar").disabled = true;
					document.getElementById("capin").style.borderColor = '#FFCC00';
					document.getElementById("captcha").focus();
				}
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}	
	}

    function clearText() {
        document.getElementById("teamName").value="";
    }

    function searchTeam(eventId) {
        var date = new Date();
		var timestamp = date.getTime();
        var teamName = document.getElementById("teamName");
        if (teamName.value == "") {
            alert("Please enter your team name!");
            teamName.focus()
        } else {
            document.getElementById("seedingContent").innerHTML = "<br><br><center>Searching...<br/><br/><img src='img/ajax-loading.gif' border='0' /><br/><br/></center>";
            var url = "scripts/searchTeam.php?raceId="+eventId+"&time="+timestamp+"&teamName="+escape(teamName.value);
            request.open("GET",url,true);
            request.onreadystatechange = teamFound;
            request.send(null);
        }
        
    }

     function teamFound() {
		if (request.readyState == 4) {
			if (request.status == 200) {
                var response = request.responseText;
                var res = response.split("-|||-");
                if (res[0] == 1) { //Success
                     document.getElementById("seedingContent").innerHTML = res[1];
                } else {
                     document.getElementById("seedingContent").innerHTML = res[1];
                }
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}

    function clearTeamSearch(eventId) {
       
        var date = new Date();
		var timestamp = date.getTime();
        document.getElementById("teamName").value = "";
        document.getElementById("seedingContent").innerHTML = "<br><br><center>Loading...<br/><br/><img src='img/ajax-loading.gif' border='0' /><br/><br/></center>";
        var url = "scripts/clearSearch.php?raceId="+eventId+"&time="+timestamp;
        request.open("GET",url,true);
        request.onreadystatechange = teamCleared;
        request.send(null);
    }

    function teamCleared() {
		if (request.readyState == 4) {
			if (request.status == 200) {
                var response = request.responseText;
                document.getElementById("seedingContent").innerHTML = response;
			} else if (request.status == 404) {
				alert("The requested url was not found");
			} else {
				alert("Error : status code is : "+ request.status);
			}
		}
	}

    function showBlogger(bloggerId) {
		blogwin=dhtmlmodal.open('blogwin', 'iframe', 'bloggerDetail.php?bloggerId='+bloggerId, 'Blogger Profile', 'width=600px,height=500px,center=1,resize=1,scrolling=1');
    }

    function showWeather() {
        var url = "http://dev2.weathersa.co.za/Weather.asp?Dte=Today&Vw=Over&Zoom=Regn&Ref=08&Ad=4&Skin=LightBlue&ProdType=1&Menu=1&VI=True&M=0&Ad=5&ProdType=5&fpgid=7ful68287"
        weatherwin=dhtmlmodal.open('weatherwin', 'iframe', url, 'Graskop Weather', 'width=750px,height=500px,center=1,resize=1,scrolling=1');

    }

