// --- Common Functions --- //

Element.extend({
	SelectedValue: function() { 
		if (this.nodeName.toLowerCase() == "select") {
			return this.options[this.selectedIndex].value;
		} else {
			return false;	
		}; 
	},
	SelectedLabel: function() {
		if (this.nodeName.toLowerCase() == "select") {
			return this.options[this.selectedIndex].text;
		} else {
			return false;	
		}; 
	},
	cleanWhitespace: function() {
        $A(this.childNodes).each(function(node){
            if ($type(node) == 'whitespace') {
                this.removeChild(node);
            }
        }, this);
        return this;
    }
});

function scalar(obj, str) {return obj.getElementsByTagName(str)[0].firstChild.nodeValue;}


 

var DataSet = new Class({
	cell: function(iRows, sCol) {
		return this.rows[iRows].get(sCol);
	},
	transform: function() {
		var arrRows = new Array();
		var dt = this.source.getElementsByTagName("Table");
		for (i=0; i<dt.length; i++) // rows
		{
			var hash = new Hash();
			for (j=0; j<dt[i].childNodes.length; j++)
			{
				if (dt[i].childNodes[j].nodeType != 3) // avoid whitespace (MOZ/SAF)
				{
				    try {
					    hash.set(dt[i].childNodes[j].nodeName, dt[i].childNodes[j].childNodes[0].nodeValue);
					} catch(e) {
					    hash.set(dt[i].childNodes[j].nodeName, " ");
					}
				}
			}
			arrRows.push(hash);
		}
		
		return arrRows;
	},
	rowcount: function() {
		return this.rows.length;
	},
	initialize: function(oXml) {
		this.source = oXml;
		this.rows = this.transform();
	}
});




window.onload = function() {
	if (document.all) // this code is to get IE6 to accept the dropdown
	{
		var arrMenus = $$("div.dropdown");
		for (i=0; i<arrMenus.length; i++)
		{
			arrMenus[i].style.left = (window.getWidth() - 750) / 2;
		}
		
		for (i=0; i<$("menulist").childNodes.length; i++) {
			node = $("menulist").childNodes[i];
			if (node.nodeName=="LI") {
				node.setAttribute("id", "menuli_" + i); // generate unique ID for LI
				node.onmouseover = new Function("$('menuli_" + i + "').lastChild.style.display = 'block';");
				node.onmouseout = new Function("$('menuli_" + i + "').lastChild.style.display = 'none';")
			}
   		}
	}
};

function ShowFullImage(src, title, height)
{
	oWin = window.open( "/images/photos-of-the-week/full/" + src , "FullSizeImage", "height=" + height + ",width=650,status=no,toolbar=no,menubar=no,location=no");
}

function GetPlayer(PlayerID)
{
    url = "/services/default.asmx/GetPlayerStats";
    pars = "strPlayerID=" + PlayerID;
    new Ajax(url, {postBody: pars, onComplete: DisplayPlayerStats}).request();
}
    
function DisplayPlayerStats(sText, oXml)
{
    var ds = new DataSet(oXml);
    var sSupp = ds.cell(0, "Supplier");
    $("plImage").innerHTML = "<a href='javascript:ShowFullSize(" + ds.cell(0, "PlayerID") + ")'><img src='/images/players/thumbnails/" + ds.cell(0, "ImageUrl") + "' border='0' />";
	var player = ds.cell(0,"PlayerName");
	var nickname = ds.cell(0,"Nickname");
	var position = ds.cell(0,"PlayerPosition");
	var moment = ds.cell(0,"BestRugbyMoment");
	var quote = ds.cell(0,"FavQuote");
	if (player == "Allister Hogg" || player == "Ryan Grant" || player == "Roland Reid" || player == "John Houston") {
		$("plName").innerHTML = player+"<br>(Edinburgh)";
	}
	else if (player == "Mark McMillan" || player == "Al Kellock") {
		$("plName").innerHTML = player+"<br>(Glasgow)";
	}
	else {
	    $("plName").innerHTML = ds.cell(0, "PlayerName");
	}
	$("plNickname").innerHTML = ds.cell(0, "Nickname");
    $("plPosition").innerHTML = ds.cell(0, "PlayerPosition");
    $("plMoment").innerHTML = ds.cell(0, "BestRugbyMoment");
    $("plQuote").innerHTML = ds.cell(0, "FavQuote");
}
    
function ShowFullSize(PlayerID)
{
    var load = window.open('/go/club/PlayerFullSize.aspx?PlayerID=' + PlayerID ,'','scrollbars=no,menubar=no,height=450,width=360,resizable=no,toolbar=no,location=no,status=no');
}
