//
//	Javascript globals
//
window.onload = wonload;
window.onunload = wunload;

function wonload()
{
	return;
}
function wunload()
{
	return;
}
function forgotpassword(id)
{
	var f = document.getElementById(id);
	if (f.login.value == '')
	{
		alert("You must provide your login to retrieve your password");
	} else {
		var url='cmd.php';
		var params = 'rnd='+(Math.random()*100000)+'&do=forgotpassword&forgotpassword='+f.login.value;

		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);

		alert(xmlHttp.responseText);
	}
	return false;
}

function confirmCaptcha(v)
{
	if(xmlHttpIsSupported)
	{
		var url= 'index.php';
		var params = 'rnd='+(Math.random()*100000)+'&do=captcha&captcha='+v;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		return (xmlHttp.responseText=='ok');
	}
	return false;
}

function showDiv(showlist,hidelist)
{
	if (hidelist != '')
	{
		var hideids = hidelist.split(',');
		for (var i = 0; i < hideids.length; i++)
			document.getElementById(hideids[i]).style.display='none';
	}
	if (showlist != '')
	{
		var showids = showlist.split(',');
		for (var i = 0; i < showids.length; i++)
			document.getElementById(showids[i]).style.display='block';
	}
	return false;
}

function region_select(region)
{
	if(xmlHttpIsSupported)
	{
		var url= 'prospects.php';
		var params = 'show='+(Math.random()*100000)+'&region='+region;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('prospect_zone_schools').innerHTML = xmlHttp.responseText;
		showDiv('map_sidebar','admincontent');
	}
	return false;
}

function school_select(school)
{
	if(xmlHttpIsSupported)
	{
		var url= 'prospects.php';
		var params = 'show='+(Math.random()*100000)+'&school='+school;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('prospect_zone_schools').innerHTML = xmlHttp.responseText;
		showDiv('map_sidebar','admincontent');
	}
	return false;
}

function player_select(player)
{
	if(xmlHttpIsSupported)
	{
		var url= 'prospects.php';
		var params = 'show='+(Math.random()*100000)+'&player='+player;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('admincontent').innerHTML = xmlHttp.responseText;
		showDiv('admincontent','map_sidebar');
	}
	return false;
}

function myplayer_select(player)
{
	if(xmlHttpIsSupported)
	{
		var url= 'myprospects.php';
		var params = 'show='+(Math.random()*100000)+'&player='+player;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profile').innerHTML = xmlHttp.responseText;
		showDiv('profile','');
	}
	return false;
}

function state_enable(s,enable)
{
	if(xmlHttpIsSupported)
	{
		var url= 'state.php';
		var params = 'show='+(Math.random()*100000)+'&op=enable&state='+s+'&enable='+((enable)?'y':'n');
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('process_result').innerHTML = xmlHttp.responseText;
	}
	return false;
}

function country_change(c)
{
	if(xmlHttpIsSupported)
	{
		var url= 'state.php';
		var params = 'show='+(Math.random()*100000)+'&op=country_change&geo_country='+c;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('states').innerHTML = xmlHttp.responseText;
	}
	return false;
}

function edit_countries() {
	if(xmlHttpIsSupported)
	{
		var url= 'state.php';
		var params = 'show='+(Math.random()*100000)+'&op=edit_country';
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('states').innerHTML = xmlHttp.responseText;
	}
	return false;
}

function country_enable(s,enable)
{
	if(xmlHttpIsSupported)
	{
		var url= 'state.php';
		var params = 'show='+(Math.random()*100000)+'&op=enable_country&id='+s+'&enable='+((enable)?'y':'n');
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('process_result').innerHTML = xmlHttp.responseText;
		
		var url= 'state.php';
		params = 'show='+(Math.random()*100000)+'&op=refresh_countries&geo_country='+s;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('list_form').innerHTML = xmlHttp.responseText;
	}
	return false;
}

function load_regions(c,s)
{
	var f=document.getElementById('form_state');
	f.geo_country.value=c;
	f.geo_state.value=s;
	f.submit();
	return false;
}

function load_profiles(t)
{
	return load_profiles_page(t,1);
}

function load_profiles_page(t,pg)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url= 'profiles.php';
		var params='show='+(Math.random()*100000)+'&op=listall&pt='+t+'&pg='+pg;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profiles').innerHTML = xmlHttp.responseText;
		showDiv('profiles','profile');
		document.getElementById('run_indicator').src='images/spacer.gif';
	}
	return false;
}

function load_profile(id,pt)
{
	if(xmlHttpIsSupported)
	{
		var url= 'profiles.php';
		var params = 'show='+(Math.random()*100000)+'&op=edit&id='+id+'&pt='+pt;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profile').innerHTML = xmlHttp.responseText;
		showDiv('profile','profiles');
	}
	return false;
}

function list_search(f)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url = 'profiles.php';
		var params = 'show=r';
		for(x=0;x<f.elements.length;x++)
			params += '&'+f.elements[x].name+'='+f.elements[x].value;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profiles').innerHTML = xmlHttp.responseText;
		document.getElementById('run_indicator').src='images/spacer.gif';
	}
	return false;
}

function profile_status_change(id,status)
{
	if(xmlHttpIsSupported)
	{
		var url = 'profiles.php';
		var params = 'show='+(Math.random()*100000)+'&op=changestatus&changeid='+id+'&changestatus='+status;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var response = xmlHttp.responseText;
		alert("Status has been changed.");
	}
	return false;
}

function profile_activate(id)
{
	if(xmlHttpIsSupported)
	{
		var url = 'profiles.php';
		var params = 'show='+(Math.random()*100000)+'&op=activate&id='+id;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var response = xmlHttp.responseText;
		alert("Activation Notification has been sent.");
	}
	return false;
}

function profile_region_change(id,region)
{
	if(xmlHttpIsSupported)
	{
		var url = 'profiles.php';
		var params = 'show='+(Math.random()*100000)+'&op=changeregion&changeid='+id+'&changeregion='+region;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var response = xmlHttp.responseText;
		alert("Region has been reassigned.");
	}
	return false;
}

function getRankings(f)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		if(f.name=='rankform2')
			var url = 'rankings.php';
		else
			var url = 'ranking.php';
		var params = 'show='+(Math.random()*100000)+'&op=listall';
		params += '&top='+f.top.value+'&Class_Of='+f.Class_Of.value+'&position='+f.position.value;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profiles').innerHTML = xmlHttp.responseText;
		document.getElementById('run_indicator').src='images/spacer.gif';
	}
	return false;
}

function saveAndRefreshRanking(f)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url = 'ranking.php';
		var params = 'show='+(Math.random()*100000)+'&op=save';
		for(x=0;x<f.elements.length;x++)
			params += '&'+f.elements[x].name+'='+f.elements[x].value;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		getRankings(document.getElementById('rankform'));
		document.getElementById('run_indicator').src='images/spacer.gif';
	}
	return false;
}

function rankingReport(c,t,p)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url = 'rankings.php';
		var params = 'show='+(Math.random()*100000)+'&op=listall';
		params += '&top='+t+'&Class_Of='+c+'&position='+p;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profiles').innerHTML = xmlHttp.responseText;
		var f=document.getElementById('rankform2');
		f.top.value=t;
		f.Class_Of.value=c;
		f.position.value=p;
		document.getElementById('run_indicator').src='images/spacer.gif';
		showDiv('profiles','profile');
	}
	return false;
}

function view_profile(id,pt)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url= 'rankings.php';
		var params = 'show='+(Math.random()*100000)+'&op=view&id='+id+'&pt='+pt;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profile').innerHTML = xmlHttp.responseText;
		document.getElementById('run_indicator').src='images/spacer.gif';
		showDiv('profile','profiles');
	}
	return false;
}

function view_school(school)
{
	if(xmlHttpIsSupported)
	{
		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var url= 'rankings.php';
		var params = 'show='+(Math.random()*100000)+'&op=view_school&school='+school;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('profile').innerHTML = xmlHttp.responseText;
		document.getElementById('run_indicator').src='images/spacer.gif';
		showDiv('profile','profiles');
	}
	return false;
}

function fr_filter_change(c)
{
	if(xmlHttpIsSupported)
	{
//		document.getElementById('run_indicator').src='styles/images/loading.gif';
		var f=c.form;
		var url= 'fixed_reports.php';
		var params = 'show='+(Math.random()*100000)+'&op=filter&filter='+c.value;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('fixed_reports_div').innerHTML = xmlHttp.responseText;
//		document.getElementById('run_indicator').src='images/spacer.gif';
	}
	return false;
}

function view_blog(id)
{
	if(xmlHttpIsSupported)
	{
		var url='blog.php';
		var params='show=r&op=edit&id='+id;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('blog_edit').innerHTML = xmlHttp.responseText;
		showDiv('blog_edit','blog_entries');
	}
	return false;
}

function publish_blog(id)
{
	if(xmlHttpIsSupported)
	{
		var url='blog.php';
		var params='show=r&op=publish&id='+id;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var s = xmlHttp.responseText;
		var f=document.getElementById('blog_search');
		search_blog(f,f.jumptopage.value);
	}
	return false;
}

function unpublish_blog(id)
{
	if(xmlHttpIsSupported)
	{
		var url='blog.php';
		var params='show=r&op=unpublish&id='+id;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var s = xmlHttp.responseText;
		var f=document.getElementById('blog_search');
		search_blog(f,f.jumptopage.value);
	}
	return false;
}

function drop_blog(id)
{
	if(xmlHttpIsSupported)
	{
		var url='blog.php';
		var params='show=r&op=drop&id='+id;
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		var s = xmlHttp.responseText;
		var f=document.getElementById('blog_search');
		search_blog(f,f.jumptopage.value);
	}
	return false;
}

function search_blog(f,pg)
{
	if(xmlHttpIsSupported)
	{
		f.jumptopage.value=pg;
		var url='blog.php';
		var params=f.elements[0].name+'='+escape(f.elements[0].value);
		for(var x=1;x<f.elements.length;x++)
			params += '&'+f.elements[x].name+'='+escape(f.elements[x].value);
		var xmlHttp	=GetXmlHttpObject();
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		document.getElementById('blog_entries').innerHTML = xmlHttp.responseText;
		showDiv('blog_entries','blog_edit');
	}
	return false;
}

function runUtility(u)
{
	document.getElementById('utility_frame').src = 'utilities.php?run='+u;
	return false;
}