if (typeof(sendQuery) != 'function') {
function sendQuery(url) {
	var s = ce('script');
	s.type='text/javascript';
	s.language='Javascript';
	s.src=url;
	document.documentElement.firstChild.appendChild(s);
}

function ce (tagName) {
	return document.createElement(tagName)
}
function ct (text) {
	return document.createTextNode(text)
}

function ge(id) {
	return document.getElementById(id)
}
function ges(tagName) {
	return document.getElementsByTagName(tagName)
}

}

var current;
var opcode;
function del(obj,id,opc) {
	current = obj.parentNode.parentNode.parentNode.parentNode;
	opcode = opc;
	var f11 = ge('f11');
	var f12 = ge('f12');
	var f2 = ge('f2');
	var f3 = ge('f3');

	var deleted = f3.firstChild.nodeValue;
	var inbox_all = f11.firstChild.nodeValue;
	var inbox_unread = f12.firstChild.nodeValue.replace('/','');
	var sent_all = f2.firstChild.nodeValue;

	if (opc == 'del') {
		deleted++;
		if (current.className.indexOf('unread')!=-1) {
			inbox_unread--;
			inbox_all--;
		} else {
			inbox_all--;
		}

	} else if (opc == 'del2') {
		deleted++;
		sent_all--;
	} else if (opc == 'rem') {
		deleted--;
	} else if (opc == 'und') {
		deleted--;
		var type = obj.parentNode.parentNode.firstChild.firstChild.nodeValue;
		if (type.indexOf('TO:')!=-1) {
			sent_all++;
		} else if (type.indexOf('FROM:')!=-1) {
			inbox_all++;
		}
	}

	f3.firstChild.nodeValue = deleted;
	f11.firstChild.nodeValue = inbox_all;
	f12.firstChild.nodeValue = '/'+inbox_unread;
	f2.firstChild.nodeValue = sent_all;

	sendQuery(obj.href.replace(/sid=(.+)&/,'sid=$1_js&'));
	obj.firstChild.nodeValue = '...';
	return false;
}

var current;
function delall(obj,opc) {

	var f11 = ge('f11');
	var f12 = ge('f12');
	var f2 = ge('f2');
	var f3 = ge('f3');

	var deleted = f3.firstChild.nodeValue;
	var inbox_all = f11.firstChild.nodeValue;
	var inbox_unread = f12.firstChild.nodeValue.replace('/','');
	var sent_all = f2.firstChild.nodeValue;

	if (opc == 'outbox') {
		deleted= 1*deleted + 1*sent_all;
		sent_all = 0;
	} else if (opc == 'trash') {
		deleted = 0;
	} else if (opc == 'inbox') {
		deleted=1*deleted+1*inbox_all;
		inbox_all = 0;
		inbox_unread = 0;
	}

	f3.firstChild.nodeValue = deleted;
	f11.firstChild.nodeValue = inbox_all;
	f12.firstChild.nodeValue = '/'+inbox_unread;
	f2.firstChild.nodeValue = sent_all;

	current = obj.parentNode;
	sendQuery(obj.href.replace(/sid=(.+)&/,'sid=$1_js&'));
	obj.firstChild.nodeValue = '...';
	return false;
}

function clear(result) {
	if (result == true) {
		current.parentNode.removeChild(current);
	} else {
		showAlert('Requested operation not supported. Please contact us to report');
	}
}

function mclear(result) {
	if (result == true) {
		while(current.nextSibling) {
			current.parentNode.removeChild(current.nextSibling);
		}
		current.lastChild.firstChild.nodeValue = 'Done';
	} else {
		showAlert('Requested operation not supported. Please contact us to report');
	}
}

function c(cell) {
	if (cell.firstChild)
		if (cell.firstChild.href)
			window.location.href=cell.firstChild.href;
}

function handleTableHover(ev) {
	var el = ev.target||ev.srcElement;

	if (el.nodeName=='TD' && el.firstChild && el.firstChild.nodeName=='A') {
		el.style.backgroundColor='#eeeef5';
		el.style.cursor = 'pointer';
		el.onmouseout = function () {this.style.backgroundColor = ''}
		el.onclick = function () {return simClick(this.firstChild)}
	}

	if (el.nodeName=='A' && el.parentNode && el.parentNode.nodeName=='TD') {
		el.parentNode.style.backgroundColor='#eeeef5';
		el.style.cursor = 'pointer';
		el.parentNode.onmouseout = function () {this.style.backgroundColor = ''}
		el.parentNode.onclick = function () {return simClick(this.firstChild);}
	}
}

function simClick(obj) {
	if (obj.getAttribute('target')=='_blank') {
		window.open(obj.href);
		return false;
	} else if (!obj.onclick) {
		window.location.href = obj.href;
	}
}

function mc(mcid) {
	var url = window.SYS_MODULE_ROOT+'matchcard/view/'+mcid;
	window.open(url,'_mc'+mcid,'width=600,height=470,width=600,scrollbars=yes,resizable=yes')
	return false;
}

function tmc(id) {
	var url = '?sid=teamMatch&GET_id='+id;
	window.open(url,'_tmc'+id,'width=600,height=470,width=600,scrollbars=yes,resizable=yes')
	return false;
}

function gobmi(id) {
	var url = window.SYS_MODULE_ROOT+'bmiStatusScreenPopup&GET_id='+id;
	window.open(url,'mc'+id,'height=450,width=730,scrollbars=yes,resizable=yes');
	return false;
}

function gosmi(id) {
	var url = window.SYS_MODULE_ROOT+'socialMatchCard&GET_id='+id;
	var w = window.open(url,'sc'+id,'height=450,width=600,scrollbars=yes,resizable=yes');
	w.focus();
	return false;
}

function gosps(id) {
	var url = window.SYS_MODULE_ROOT+'socialMatchPlayerStatus&GET_id='+id;
	window.open(url,'sc'+id,'height=450,width=730,scrollbars=yes,resizable=yes');
	return false;
}

function gocourt() {
	var url = window.SYS_MODULE_ROOT+'userCourtsBooked';
	window.location.href=url;
	return false;
}

function gohelp(url) {
	window.open(url,'tjhelp','height=450,width=640,scrollbars=yes,resizable=yes');
	return false;
}

function goprofile(url){
	window.open(url,'tjfapprofile','height=450,width=450,scrollbars=yes,resizable=yes');
	return false;
}

function playerMatchesPopup(obj, bRedir) {
	window.open(obj.href,'r'+obj.href.replace(/[^\d]/g,'_'),'width=600,height=300,scrollbars=1,resizable=yes');
	if (bRedir && /GET_pid=\d+-\d+/.test(obj.href)) {
		window.location.replace(window.location.href.toString().replace(/&?GET_pid=\d+-\d+/,'')+'&'+obj.href.match(/GET_pid=\d+-\d+/));
	}
	return false;
}

function checklist(e,tbl) {
	var el = e.target||e.srcElement;
	if (el.nodeName.toLowerCase()=='input') {
		if (el.type=='checkbox') {
			var tr = el.parentNode.parentNode;
			if (el.checked) {
				tr.className = tr.className.replace('strikeout','');
			} else {
				tr.className +=' strikeout';
			}
//			tr.className = el.checked ? '' : 'strikeout';
		}
	}
}


function formCheckAll(control){

	var f=control;
	while((f.nodeName.toLowerCase()!='form') && (f=f.parentNode)) {};

	if(!f){
		alert('Error - Form not found')
	}

	var inps=f.getElementsByTagName('input');
	for(var i=0;i<inps.length;i++){
		var el=inps[i];

		if(el.type=='checkbox'){
			el.checked=true;
		}
	}
	return false;
}

function showTour(id) {
	var t = document.getElementById(id);
	t.style.display= t.style.display == 'none' ? 'block' : 'none';
}

function verifyChecks(f){
	for(var i=0,els=f.elements;i<els.length;i++){
		if(els[i].name=='PST_CTRL_InviteList[]' && els[i].checked) return true;
	}
	showAlert("Please select players to invite by clicking on the Invite Box next to the players' name.");
	return false;
}

function __wait(obj) {
	obj.parentNode.style.display='none';
	var text = document.createElement('div');
	text.className = 'AWL_PleaseWait';
	text.appendChild(document.createTextNode('Please wait - processing your request...'));
	obj.parentNode.parentNode.insertBefore(text,obj.parentNode);
}

function handleSelectionTable(e) {

	var el = e.srcElement||e.target;
	while(el && el.nodeName.toLowerCase()!='td'){el=el.parentNode};

	function hover() {
		this.className += ' hover';
	}

	function unhover() {
		this.className = this.className.replace('hover','');
	}

	if (el.firstChild && el.firstChild.nodeName.toLowerCase() == 'a') {
		el.parentNode.onmouseover = hover;
		el.parentNode.onmouseout = unhover;
	}
}