/*
**
**	OR.js - javascripts for running OR Website
**	Author: 		Adrian Fowler
**	
*/
var memWindow;

function membersLogIn(url){
	window.name = 'ORHCMainWindow';
	if ((memWindow == null) || (memWindow.closed)) {
		memWindow = window.open(url,"ORHCMembersWindow","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=500");
	} else {
		memWindow.location.href = url;
	}
}

function membersLogOut(url){
	window.name = 'ORHCMainWindow';
	if ((memWindow == null) || (memWindow.closed)) {
		memWindow = window.open(url,'ORHCMembersWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=500');
	} else {
		memWindow.focus;
		memWindow.location.href = url;
		memWindow.close;
		window.close;
	}
}

function searchOR(){
	var str ='<form name="search_form" action="./search.asp"  method="POST">';
	str += '<table border="0"><tr>';
	str += '<td><input class="ui-corner-all" name="search" size="35"></input><br />';
	str += '<label>Search for the exact phrase:</label>';
	str += '<input type="checkbox" class="ui-corner-all" name="exact"></input></td>';
	str += '<td><img class="pointer" src="./images/search.png" alt="Click to search" onclick="document.forms.search_form.submit();"></td>';
	str += '</tr></table>';
	str += '</form>';
	
	return hs.htmlExpand(null, {
      objectType: 'iframe',
		maincontentText: str,
		width: 270,
		height: 120,
		headingText: 'Search'
   });
}


// Special - Retrieve Match report based on MatchID number
function GetMatchReport(ele, id, auth, theme) {
   if (auth === undefined) {
      auth = 0; //default auth level
   }
	if (theme === undefined) {
	  theme = 'fitTabNoBorder'; //default theme
	}

	//get results for match id
	var y = getJSONData('db.asp?search=fixtures&where=MatchID=' + id);
	if (y != '') { 
		var array = typeof y != 'object' ? $.parseJSON(y) : y;

		if (array[0].Result != null) {
			$(ele).html('<div id="title"></div><div id="result"></div>');
//			$('#title').html('<h4 class="ui-corner-all">'+ formatORdate(array[0].Date) + ' - ' + array[0].Team + ' v ' + array[0].Opponent + ' (' + array[0].HA + ')</h4>');
			$('#title').html('<h4 class="ui-corner-all">'+ array[0].Date + ' - ' + array[0].Team + ' v ' + array[0].Opponent + ' (' + array[0].HA + ')</h4>');
	

			//get reports for match id
			var opts = {};
			opts.url = 'db.asp?search=match-rpt&where=MatchID=' + id;
			if (auth > 0) {
				opts.url					=	[opts.url, 'db.asp?search=match-rpt-goals&where=MatchID=' + id, 'db.asp?search=match-rpt-motm&where=MatchID=' + id, 'db.asp?search=match-rpt-team&where=MatchID=' + id];
				opts.stringifyArray	=	[undefined,'Scored','MoM','Team'];
			}

			$('#result').ORjsonHTML({
				url				:	opts.url,
				arrayToHide		:	['MatchID'],
				stringifyArray	:	opts.stringifyArray,
				type				:	'detail',
				theme				:	theme,
				over				:	false,
				suffix			:	'<p class="center">Games in CAPITALS are league fixtures</p>'
			});
		}
	} else {
		$(ele).html('No report found.');
	}
}

// Special - Retrieve Member Detail report based on ID number
function GetMemberReport(ele, id, theme) {
	if (theme === undefined) {
	  theme = 'fitTabGreen'; //default theme
	}

	$(ele).ORjsonHTML({
		url			:	'db.asp?search=stat_members&where=MemberID=' + id,
		type			:	'table',
		theme			:	theme,
		arrayToHide	:	['Name','MemberID']
	});
	
	//get member name
	var y = getJSONData('db.asp?search=stat_members&cols=Name&limit=1&where=MemberID=' + id);
	if (y != '') { 
		var array = typeof y != 'object' ? $.parseJSON(y) : y;
		if (array[0].Name != null) {
			$(ele).prepend('<h4 class="ui-corner-all">' + array[0].Name + '</h4>');
		}
	}
	

}
