/* add this otpions */
addthis_pub  = 'pitcherocom';
addthis_options = 'favorites, facebook, stumbleupon, digg, delicious, google, myspace, reddit, live, more';


window.js_sport_id = '0';

var openDivs = new Array();
var number = 0;


var win=null;

String.prototype.reverse = function(){
splitext = this.split("");
revertext = splitext.reverse();
reversed = revertext.join("");
return reversed;
}


function URLcheck(string)
{
	if(confirm('You are about to navigate away from Pitchero.\nPitchero is not responsible for the content of external internet sites.\n\nIf you have a popup blocker, hold down the control button and click OK')) 
	{
		window.open(string, '_blank');
	}
}

function showHideFlash() {
	var e=document.getElementsByTagName("embed");
	for(i=0;i<e.length;i++){
			if (e[i].style.visibility == "hidden") {
				e[i].style.visibility="visible";
			}else{
				e[i].style.visibility="hidden";
			}
		}
}

function thisBrowser() {
	if (window.XMLHttpRequest) {
	if(document.all){
	return 'ie7';
	//IE7
	}else{
	return 'mozilla';
	}
	} else {
	return 'ie6';
	}
}

function open_window(mypage,myname,w,h,scroll,status,pos){

	if(pos=="center"){
	
	  LeftPosition=(screen.width)?(screen.width-w)/2:100;
	
	  TopPosition=(screen.height)?(screen.height-h)/2:100;
	
	}
	
	else if((pos!="center" && pos!="random") || pos==null){
	
	  LeftPosition=0;
	
	  TopPosition=20;
	
	}
	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status='+status+',menubar=no,toolbar=no,resizable=no';
	
	win=window.open(mypage,myname,settings);

}



/*-----------------------------------------------------------------------------------------*/ 
/* profile black bar functions DB, 07 May 2008 */
/* function to check if the user has inputted a username and password */
function validateLogin() {
	
	if(!document.login.loginUsername.value)
	{
		alert('Please type in your Email address');
		document.login.loginUsername.focus();
		return false;
	}
	else
	{
			if(!document.login.loginPassword.value)
			{
				alert('Please type in your Password');
				document.login.loginPassword.focus();
				return false;
			}
			else
			{
				return true;
			}
	}

	
	
}

function validatehpLogin() {
	if ((document.hplogin.loginUsername.value == '') && (document.hplogin.loginPassword.value == '')){
		return false;
	}else{
		return true;
	}
}

/* function to show or hide the links section div */
	function showMyLinks()
	{
		var element = document.getElementById('myLinks');
		
		
		if(element.style.display == "block")
		{
			

			showHideFlash();
			element.style.display = "none";
			if (document.getElementById('vidPlayer')) {
			document.getElementById('vidPlayer').style.display = "block";
			}
			
			if (document.getElementById('hpImage')) {
			document.getElementById('hpImage').style.display = "block";
			}
			
			if (document.getElementById('hp_tabs')) {
			document.getElementById('hp_tabs').style.display = "block";
			}
			
			
			if (document.getElementById('scroll-v')) {
			document.getElementById('scroll-v').style.display = "block";
			}

		}else{
			showHideFlash();
			element.style.display = "block";

			
			if (document.getElementById('vidPlayer')) {
			document.getElementById('vidPlayer').style.display = "none";
			}
			
			if (document.getElementById('hpImage')) {
			document.getElementById('hpImage').style.display = "none";
			}
			
			
			if (document.getElementById('hp_tabs')) {
			document.getElementById('hp_tabs').style.display = "none";
			}
			
			if (document.getElementById('scroll-v')) {
			document.getElementById('scroll-v').style.display = "none";
			}
			
		}
	}
	
/*-----------------------------------------------------------------------------------------*/ 



function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}



//DB 27/03/08 - same as above but toggles all on and all off depending on the value of the check all checkbox.
function SetAllCheckBoxesToggle(FormName, FieldName, CheckValue, Check)
{

	
	if (document.forms[FormName].elements[Check].checked) {
		CheckValue = true;
	}else{
		CheckValue = false;
	}

	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}


/* NEW IMAGE AJAX 08, July 2008 */

function loadImageInfo(image_id, imageURL, image_div, album, folder) {
	
	document['mainImage'].src=imageURL;

	//load image comments
	makeHttpRequest('/v2/ajax.clubMedia.php?ajax=true&action=imageInfo&image_id=' + image_id, 'document.getElementById(\'ajaxImageComments\').innerHTML=');
	
	//load information in image box
	makeHttpRequest('/ajax/imageTitle.php?action=loadImageInfo&image_id=' + image_id + '&album_id=' + album + '&folder=' + folder, 'document.getElementById(\'' + image_div + '\').innerHTML=');
	
	//load data for send to friend
	makeHttpRequest('/ajax/imageTitle.php?action=loadFriend&image_id=' + image_id + '&album_id=' + album + '&folder=' + folder, 'document.getElementById("ajaxSendVideo").innerHTML=');
	
	//load data for report.
	makeHttpRequest('/ajax/imageTitle.php?action=loadReport&image_id=' + image_id + '&album_id=' + album + '&folder=' + folder, 'document.getElementById("reportContent").innerHTML=');
	
	//change add this url dynamically
	if(document.getElementById("addThis")) {
		makeHttpRequest('/ajax/imageTitle.php?action=addThis&album_id=' + album + '&image_id=' + image_id + '&folder=' + folder, 'document.getElementById("addThis").innerHTML=');
	}
	
	
	document.getElementById('forwardImg').src = '/v2/images/clubs/photos/next.png';
	document.getElementById('backImg').src = '/v2/images/clubs/photos/back.png';
	

	if (image[0][0] == image_id) {
		document.getElementById('backImg').src = '/v2/images/clubs/photos/trans.gif';					
	}
	
	if (image[image.length-1][0] == image_id) {
		document.getElementById('forwardImg').src = '/v2/images/clubs/photos/trans.gif';					
	}


}

function rateImage(image_id, rating, album)
{

		document.getElementById('ajaxRating').innerHTML= '';
		document.getElementById('ajaxMyRating').innerHTML= '';
	
		//process user rating replace div with new image and user rating
		makeHttpRequest('/v2/ajax.imageRating.php?action=rateImage&image_id=' + image_id + '&rating=' + rating, 'document.getElementById("ajaxMyRating").innerHTML=');
						
		//update album avg rating and total ratings.
		makeHttpRequest('/v2/ajax.imageRating.php?action=getAlbumRating&album_id=' + album, 'document.getElementById("ajaxAlbumRating").innerHTML=');				
		
		
}


function commentImages() {
		
		
		if(!document.comment.comment.value)
		{
			alert('Please type in your comment....');
			document.comment.comment.focus();
			return false;
		}
		else
		{
			document.comment.button.disabled=true;
			document.comment.button.value='Adding comment......';
			makeHttpPostRequest('/v2/ajax.clubMedia.php', 'action=postComment&ajax=true&image_id=' + document.comment.image_id.value + '&comment=' + document.comment.comment.value, 'document.getElementById(\'ajaxImageComments\').innerHTML=');
			return false;
		}

}




function deleteVideoComment(div, comment_id) {
		if(confirm('Are you sure you want to delete this comment?'))
		{
				makeHttpRequest('/v2/ajax.videos.php?action=deleteComment&comment_id=' + comment_id, 'document.getElementById("' + div + '").innerHTML=');
		}
		
}

/* END NEW IMAGE AJAX */


function loadImage(image_id, imageURL, image_div, comments_div) {
	
	// load the image
	//makeHttpRequest('/ajax/loadImage.php?image_id=' + image_id, 'document.getElementById(\'' +  image_div + '\').innerHTML=');
	
	document['mainImage'].src=imageURL;
	
	// update the title of the image
	//document.getElementById(image_div).innerHTML = imageTitle;
	
	// load comments too
	//makeHttpRequest('/ajax/comment_images.php?image_id=' + image_id, 'document.getElementById(\'' + comments_div + '\').innerHTML=');
	
	makeHttpRequest('/ajax/addComment.php?type=im&id=' + image_id, 'document.getElementById(\'' + comments_div + '\').innerHTML=');
	
	// load title
	makeHttpRequest('/ajax/imageTitle.php?image_id=' + image_id, 'document.getElementById(\'' + image_div + '\').innerHTML=');
}


function commentPage(div, type, id, start) 
{
	makeHttpRequest('/ajax/addComment.php?type=' + type  + '&id=' + id + '&start=' + start, 'document.getElementById(\'' + div + '\').innerHTML=');
	return false;
}

function addComment(div, type, comment, id)
{
	document.getElementById("comment").disabled = true;
	makeHttpPostRequest('/ajax/addComment.php', 'type=' + type + '&comment=' + comment + '&id=' + id, 'document.getElementById(\'' + div + '\').innerHTML=');
	return false;
}


function ajaxsupporthelpfull(question,email,helpful) {
	makeHttpRequest('/v2/ajax.supportHelpful.php?&show=submitted&helpful='+helpful+'&question_id='+question+'&email='+email, 'document.getElementById(\'questionhelpful\').innerHTML=');
}

function ajaxsupportcomments(row,question) {
	if (document.supportcomments.email.value != '' && document.supportcomments.message.value != '') {
	makeHttpRequest('/v2/ajax.supportHelpful.php?row='+row+'&question_id='+question+'&show=feedbacksubmitted&&email='+document.supportcomments.email.value+'&comments='+document.supportcomments.message.value, 'document.getElementById(\'questionhelpful\').innerHTML=');
	}else{
		alert('Please make sure you have entered some information first!');	
	}
}



function ajaxClubSignup(field, value, div, sport_id)
{
	if(value.length > 1)
	{
		makeHttpRequest('/clubsignup/ajax.php?field=' + field + '&value=' + value + '&sport_id=' + sport_id, 'document.getElementById(\'' + div + '\').innerHTML=');
	}
}

function validateClubSignup()
{

		if(checkPostcode('postcode') && check2('clubname') && checkTeamName() && checkAddress() && checkTac()  && document.form.postcode.value != '')
		{
			// check we have content for each bit
			disable(document.form.submit);

			return true;
		}
		else
		{
			return false;
		}
}



function getData()
{
	stop();
}

function attachImages(maximum, div, formfield, club_id)
{
	day = new Date();
	id = day.getTime();
	
	//newwindow = window.open('/myAccount/attachImages.php?club_id=' + club_id + '&max=' + maximum + '&div=' + div + '&formfield=' + formfield,'myWin','toolbar=no,width=700,height=400,top=300,left=300');
	eval("page" + id + " = window.open('/myAccount/attachImages.php?club_id=" + club_id + "&max=" + maximum + "&div=" + div + "&formfield=" + formfield + "','myWin','toolbar=no,width=700,height=400,top=300,left=300');");
}


function openDoc(url)
{
	day = new Date();
	id = day.getTime();
	
	eval("page" + id + " = window.open(URL, 'myWin','toolbar=no,width=600,height=450,top=300,left=300,scrollbars=1');");

}






function trim(a){
	var tmp=new Array();
	for(j=0;j<a.length;j++)
		if(a[j])
			tmp[tmp.length]=a[j];
	a.length=tmp.length;
	for(j=0;j<tmp.length;j++)
		a[j]=tmp[j];
	return a;
}


// http://www.thescripts.com/forum/thread89465.html
Array.prototype.removeItems = function(itemsToRemove) {

if (!/Array/.test(itemsToRemove.constructor)) {
itemsToRemove = [ itemsToRemove ];
}

 var j;
for (var i = 0; i < itemsToRemove.length; i++) {
 j = 0;
while (j < this.length) {
 if (this[j] == itemsToRemove[i]) {
this.splice(j, 1);
} else {
j++;
}
}
}
}


// call like this arrayName.inArray(value)
Array.prototype.inArray = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}



function checkAlbum(club_id, string, checkbox)
{
	var IDarray = string.split(",");
	
	if(document.getElementById(checkbox).checked==true)
	{
		if(IDarray)
		{
			for(i=0;i<IDarray.length;i++) {
				document.getElementById('club_' + club_id + '_' + IDarray[i]).checked=true;
			}
		}
		else
		{
			document.getElementById('club_' + club_id + '_' + string).checked=true;
		}
	}
	else
	{
		if(IDarray)
		{
			for(i=0;i<IDarray.length;i++) {
				document.getElementById('club_' + club_id + '_' + IDarray[i]).checked=false;
			}
		}
		else
		{
			document.getElementById('club_' + club_id + '_' + string).checked=false;
		}
	}
}


function checkIDs()
{
	var IDarray = string.split(",");
	
	for(i=0;i<IDarray.length;i++) {
		//alert('file_' + IDarray[i]);
		displayRegister('file_' + IDarray[i]);
		//document.getElementById().style.display = '';
	}
}


function displayRegister(div)
{
	// make the div display and register the fact that it is open
	document.getElementById(div).style.display = '';
	
	// register the fact we are open
	openDivs[number] = div;
	number++;
}

function closeRegistered()
{
	for (i=0;i<openDivs.length;i++)
	{
		document.getElementById(openDivs[i]).style.display = 'none';
	}
}

function showIDs(string)
{
	var IDarray = string.split(",");
	
	for(i=0;i<IDarray.length;i++) {
		//alert('file_' + IDarray[i]);
		displayRegister('file_' + IDarray[i]);
		//document.getElementById().style.display = '';
	}
	
	
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function noTeam()
{
	window.location = '3.php?sport_id=' + window.js_sport_id;
}

function checkAddDocument()
{
	// make sure we have a name
	if(document.addForm.title.value)
	{
		return true;
	}
	else
	{
		alert('As a minimum, you must select a file to upload and specify a title');
		return false;
	}
}

function checkAddOfficial()
{
	// make sure we have a name
	if(document.form.name.value)
	{
		return true;
	}
	else
	{
		alert('As a minimum, you must enter a name for your official');
		return false;
	}
}

function checkDeleteOfficial(message)
{
	if(confirm(message)) 
	{
		return true;
	}
	else
	{
		return false;
	}
}



function checkDeleteSponsor(message)
{
	if(confirm(message)) 
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkAddSponsor()
{
	// make sure we have a name
	if(document.addForm.name.value)
	{
		return true;
	}
	else
	{
		alert('As a minimum, you must enter a name for your sponsor');
		return false;
	}
}

function checkAssociation(string, message)
{
	if(confirm(message)) 
	{
		window.location=string;
	}
}

function check(field)
{
	var box = ('document.form.' + field);
	makeHttpRequest('/ajax/signup_checker.php?field=' + field + '&string=' + document.getElementById(field).value, 'document.getElementById("div_' + field + '").innerHTML=');
	document.getElementById("div_" + field).innerHTML='Checking....';
	return true;
}


function check2(field)
{
	var box = ('document.form.' + field);
	//alert(document.getElementById(field).value);
	if(document.getElementById(field).value.length >= 2)
	{
		makeHttpRequest('/ajax/query.php?field=' + field + '&string=' + document.getElementById(field).value, 'document.getElementById("div_' + field + '").innerHTML=');
		document.getElementById("div_" + field).innerHTML='Checking....';
		return true;
	}
	else
	{
			document.getElementById("div_" + field).innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> Please include a club name!';
	}
}

function checkPostcode(field)
{
	// post code needs to be checked against country_id
	var box = ('document.form.' + field);
	//alert(document.getElementById(field).value);
	if(document.getElementById(field).value.length >= 0)
	{
		makeHttpRequest('/ajax/query.php?field=' + field + '&string=' + document.getElementById(field).value + '&pc2=' +document.getElementById('postcode2').value + '&country_id=' + document.getElementById('country_id').value, 'document.getElementById("div_' + field + '").innerHTML=');
		document.getElementById("div_" + field).innerHTML='Checking....';
		return true;
	}
}

function validateClub()
{
	if(check2('name') && checkTeamName() && checkAddress() && checkPostcode('postcode') && checkTac() && document.form.postcode.value != '')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkPasswords()
{
	if(!document.form.password.value)
	{
		var error = 'No password specified.';
	}
	else if(document.form.password.value != document.form.password2.value)
	{
		var error = 'Passwords do not match.';
	}
	else if(document.form.password.value.length < 6)
	{
		var error = 'Password should be at least 6 characters.';
	}

	
	// output
	if(error)
	{
		document.getElementById("div_password2").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> ' + error;
		return false;
	}
	else
	{
		document.getElementById("div_password2").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		return true;
	}

}

function checkDay()
{
	if(document.form.dob_day.value.length == 2)
		document.form.dob_month.focus();
}

function checkMonth()
{
	if(document.form.dob_month.value.length == 2)
		document.form.dob_year.focus();
}

function checkYear()
{
		// only validate if we have a year selected
		// else return please choose dob
		if(document.form.dob_year.value)
		{
		
			// first check all numbers are he right length
			if(!document.form.dob_year.value || !document.form.dob_month.value || !document.form.dob_day.value)
			{
				var error = 'Day, Month and Year required.';
			}
			else if(document.form.dob_year.value.length != 4)
			{
				var error = 'Year must be 4 digits eg. "1980".';
			}
			else if(document.form.dob_day.value.length != 2) 
			{
				var error = 'Day must be 2 digits eg. "01".';
			}
			else if(document.form.dob_month.value.length != 2)
			{
				var error = 'Month must be 2 digits eg. "01".';
			}
			else if(document.form.dob_day.value == 0 || document.form.dob_day.value >= 32) 
			{
				var error = 'There are not ' + document.form.dob_day.value + ' days in a month!';
			}
			else if(document.form.dob_month.value == 0 || document.form.dob_month.value >= 13)
			{
				var error = 'There are not ' + document.form.dob_month.value + ' months in a year!';
			}
			else if(document.form.dob_year.value >= 2007 || document.form.dob_year.value <= 1907)
			{
				var error = 'Being born in ' + document.form.dob_year.value + ' is unlikely!';
			}
			
			// output
			if(error)
			{
				document.getElementById("div_dob").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> ' + error;
				//document.getElementById("div_dob").innerHTML='<img src="error.gif" width="14" height="14" align="baseline">';
				return false;
			}
			else
			{
				document.getElementById("div_dob").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
				return true;
			}
		
		}
		else
		{
			document.getElementById("div_dob").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> Please select your Full DoB';
			//document.getElementById("div_dob").innerHTML='<img src="error.gif" width="14" height="14" align="baseline">';
			return false;
		}
}

function checkTac()
{
	if(document.form.tac.checked == false)
	{
		document.getElementById("div_tac").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> You must agree to the terms and conditions.';
		return false;
	}
	else
	{
		document.getElementById("div_tac").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		return true;
	}
}

function checkTeamName()
{
	if(document.form.teamname.value == '')
	{
		document.getElementById("div_teamname").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> You must enter a primary team name; e.g. \'First Team\' ';
		return false;
	}
	else
	{
		document.getElementById("div_teamname").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		return true;
	}
}

function checkNames()
{
	if((document.form.firstname.value == '') || (document.form.lastname.value == '') || (document.form.firstname.value.length < 2) || (document.form.lastname.value.length < 2))
	{
		document.getElementById("div_lastname").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> Firstname and Lastname must be entered and be larger than 2 characters';
		return false;
	}
	else
	{
		document.getElementById("div_lastname").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		return true;
	}
}

function checkAddress()
{
	if((document.form.address1.value == '') || (document.form.address2.value == ''))
	{
		if(document.form.address1.value == '')
		{
				document.getElementById("div_address1").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> Please enter a postal address for your club.';
		}
		else
		{
				document.getElementById("div_address1").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		}
		
		if(document.form.address2.value == '')
		{
				document.getElementById("div_address2").innerHTML='<img src="/images/error.gif" width="14" height="14" align="baseline"> Please enter a postal address for your club.';
		}
		else
		{
				document.getElementById("div_address2").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		}

		return false;
	}
	else
	{
		document.getElementById("div_address1").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		document.getElementById("div_address2").innerHTML='<img src="/images/tick.gif" width="14" height="14" align="baseline">';
		return true;
	}
}

function validate()
{
	
	if(checkPasswords() && checkNames() && checkYear() && checkTac() && document.getElementById("div_emailchecker"))
	{
		//alert('Validate ok.');
		return true;
	}
	else
	{
		//alert('Validate false.');
		return false;
	}
}


function checkEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true;			
}

function sportSelected(id)
{
	makeHttpRequest('ajax.php?y=' + Math.random() + '&sport_id=' + id, 'document.getElementById("competitions").innerHTML=');

	document.getElementById('competitions').innerHTML='';
	document.getElementById('regions').innerHTML='';
	document.getElementById('divisions').innerHTML='';
	document.getElementById('teams').innerHTML='';
	document.getElementById('info').innerHTML='';
	
	window.js_sport_id = id;
	//alert(window.js_sport_id);
}

function competitionSelected(id)
{
	makeHttpRequest('ajax.php?y=' + Math.random() + '&competition_id=' + id, 'document.getElementById("regions").innerHTML=');

	document.getElementById('regions').innerHTML='';
	document.getElementById('divisions').innerHTML='';
	document.getElementById('teams').innerHTML='';
	document.getElementById('info').innerHTML='';
}

function regionSelected(competition_id, region_id)
{

	makeHttpRequest('ajax.php?y=' + Math.random() + '&competition_id=' + competition_id + '&region_id=' + region_id, 'document.getElementById("divisions").innerHTML=');

	document.getElementById('divisions').innerHTML='';
	document.getElementById('teams').innerHTML='';
	document.getElementById('info').innerHTML='';

}



function divisionSelected(competition_id, division_id)
{
	makeHttpRequest('ajax.php?y=' + Math.random() + '&competition_id=' + competition_id + '&division_id=' + division_id, 'document.getElementById("teams").innerHTML=');
	
	document.getElementById('teams').innerHTML='';
	document.getElementById('info').innerHTML='';

}

function teamSelected(competition_id, team_id)
{	
	makeHttpRequest('ajax.php?y=' + Math.random() + '&competition_id=' + competition_id + '&team_id=' + team_id, 'document.getElementById("info").innerHTML=');
	document.getElementById('info').innerHTML='';

}

function userMenu(option)
{
	makeHttpRequest('../clubIncludes/userMenu.php?option=' + option, 'document.getElementById("user-content").innerHTML=');
	//document.getElementById('user-content').innerHTML='Checking....';
}

function result_info(id)
{
	if(document.getElementById('result_' + id).style.display == "none")
	{
		document.getElementById('result_' + id).style.display = "";
	}
	else
	{
		document.getElementById('result_' + id).style.display = "none";
	}
	document.getElementById('result_' + id).focus();
}


function playerImage(dir, player_id)
{
	document["playerimage" + player_id].src = dir + '/' + document.getElementById("image_" + player_id).value;		
}


function show(id)
{
		document.getElementById(id).style.display = "";
		return true;
}

function hide(id)
{
		document.getElementById(id).style.display = "none";
		return true;
}

function showhide(id)
{
	if(document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "";
		if(document[id + "_arrow"])
		{
				document[id + "_arrow"].src = "/images/arrow_down.gif";
		}
	}
	else
	{
		document.getElementById(id).style.display = "none";
		if(document[id + "_arrow"])
		{
				document[id + "_arrow"].src = "/images/arrow.gif";
		}
	}
}

function fixture_info(id)
{
	if(document.getElementById('fixture_' + id).style.display == "none")
	{
		document.getElementById('fixture_' + id).style.display = "";
	}
	else
	{
		document.getElementById('fixture_' + id).style.display = "none";
	}
	document.getElementById('fixture_' + id).focus();
}

function showMessage(id)
{
	if(document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "";
	}
	else
	{
		document.getElementById(id).style.display = "none";
	}
	document.getElementById(id).focus();
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


// ajax wait period
// http://forums.devshed.com/javascript-development-115/time-restraint-430177.html?&highlight=onkeyup+AJAX
var count = 0;
function ajaxWait(field)
{
   count = count+1;
   setTimeout("ajaxCheck("+count+")",500);
}

function ajaxCheck(currCount)
{
   if(currCount == count)
   {
      count = 0;
      siteSearch();
   }
}



function siteSearch(field)
{
	var field = 'search_string';
	
	var box = ('document.form.' + field);
	if(document.getElementById(field).value.length > 1)
	{
		makeHttpRequest('/search/ajax.php?string=' + document.getElementById(field).value, 'document.getElementById("div_' + field + '").innerHTML=');
		document.getElementById("div_" + field).innerHTML='Searching....';
		return true;
	}
	else
	{
		document.getElementById("div_" + field).innerHTML='';
	}
}

function makeHttpPostRequest(url, params, callback_function, refreshrequired) {

	var number = Math.random();
      var loading = 'Loading.....';
	  
	  params = params + '&n=' + number;
	  
   //eval(callback_function + '(loading)');
   
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

		http_request.open("POST", url, true);
		
		//Send the proper header information along with the request
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", params.length);
		http_request.setRequestHeader("Connection", "close");
		
		http_request.onreadystatechange = function() {//Call a function when the state changes.
			if(http_request.readyState == 4 && http_request.status == 200) {
				eval(callback_function + '(http_request.responseText)');
			}
			
			   // this ensures that the page has loaded AND that we require a data refresh
			   if (refreshrequired) {
			   		refreshAfterPost();
			   }
		}
		http_request.send(params);
		return false;
}

function makeHttpRequest(url, callback_function, return_xml, refreshrequired)
{
   
   var loading = 'Loading.....';
   eval(callback_function + '(loading)');
   
   // IE sometimes caches requests, so send a random number with each query
   var number = Math.random();
   var http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       alert('Unfortunatelly you browser doesn\'t support this feature.');
       return false;
   }
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML)');
               } else {
                   eval(callback_function + '(http_request.responseText)');
               }
			   
			   // this ensures that the page has loaded AND that we require a data refresh
			   if (refreshrequired) {
			   		getData();
			   }
			   
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url + '&rand=' + number, true);
   
   http_request.send(null);
   
   return false;
}

function searchName()
{
	if(document.form.fullname.value.length >= 2)
	{
		makeHttpRequest('ajax.php?string=' + document.form.fullname.value, 'document.getElementById("div_fullname").innerHTML=');
		document.getElementById("div_fullname").innerHTML='Checking....';
		//return true;
	}
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}


function check_boxes(field, total_boxes, checkbox){

	var i;

	if(document.getElementById(checkbox).checked==true)
	{
		if(total_boxes == '1')
		{
			 field.checked=true;
		}
		else
		{
			for (i=0 ; i < total_boxes ; i++ ){
			 field[i].checked=true;
			}
		}
	}
	else
	{
		if(total_boxes == '1')
		{
			 field.checked=false;
		}
		else
		{
			for (i=0 ; i < total_boxes ; i++ ){
			 field[i].checked=false;
			}
		}
		document.getElementById(checkbox).checked=false;
	}
}


// thanks to tim for this little gem
// http://www.briardene.com/js/js.js
// Determine Browser Height and Width definition
function GetHeightDef()
{
	if (self.innerHeight){ // FF and Safari
		HeightDef = self.innerHeight;
		WidthDef = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 
		HeightDef = document.documentElement.clientHeight;
		WidthDef = document.documentElement.clientWidth;
	}
	else if (document.body){ // IE
		HeightDef = document.body.clientHeight;
		WidthDef = document.body.clientWidth;
	}
}

function uploadPanel() {

	GetHeightDef();
	// divs are called
	// uploadingscreen and uploadingpanel
	var panelWidth = 450;
	var panelHeight = 200;
	document.getElementById('uploadingscreen').style.height = HeightDef + "px";
	document.getElementById('uploadingscreen').style.width = WidthDef + "px";
	// now position the panel
	document.getElementById('uploadingpanel').style.top = (HeightDef - (panelHeight+100))/2 + "px";
	document.getElementById('uploadingpanel').style.left = (WidthDef - panelWidth)/2 + "px";
	document.getElementById('uploadingscreen').style.display='';
	document.getElementById('uploadingpanel').style.display='';

}

function disable(string)
{
		string.disabled=true;
		return true;
}

function selectArchive()
{
    var myindex  = document.archiveForm.archive_id.selectedIndex
    var SelValue = document.archiveForm.archive_id.options[myindex].value
    var baseURL  = SelValue;
    window.location.href = baseURL;
    return true;
}

function checkThreadTitle()
{
	if(document.post.title.value) 
	{ 
		return true; 
	} 
	else 
	{ 
		alert('Your thread needs a title!');
		document.post.title.focus();
		return false; 
	} 
}


function fullscreen(div) {
	GetHeightDef();
	// divs are called
	// uploadingscreen and uploadingpanel
	var panelWidth = 550;
	var panelHeight = 300;
	document.getElementById('stafscreen').style.height = HeightDef + "px";
	document.getElementById('stafscreen').style.width = WidthDef + "px";
	// now position the panel
	document.getElementById(div).style.top = (HeightDef - (panelHeight+100))/2 + "px";
	document.getElementById(div).style.left = (WidthDef - panelWidth)/2 + "px";
	
	document.getElementById('stafscreen').style.display='';
	document.getElementById(div).style.display='';
}


function reportContent() {
if ((document.report.comment.value != '') && (document.report.name.value != '') && (document.report.email.value != '')) {
	makeHttpPostRequest('/v2/ajax.reportContent.php', 'action=report&media_id=' + document.report.media_id.value + '&name=' + document.report.name.value + '&email=' + document.report.email.value + '&comments=' + document.report.comment.value + '&user_id=' + document.report.user_id.value, 'document.getElementById(\'reportContent\').innerHTML=');
return false;
}else{
	alert('please make sure you enter all the information required');
	return false;
}
}