
function elDisp(eId, eDisp) {
  if (eId != 'undefined' & eId != null) {
    var tempId = eId[0] == '#' ? eId : '#' + eId;
	  var ha = $(tempId)[0];
	  ha.style.display = eDisp;
  }
	return false;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

// ----------- Ajax Stuff

var xmlhttp;
var responseStr;
function loadAjaxContent(url,elId) {
	xmlhttp = null;
	responseStr = null;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
	if (xmlhttp != null) {
	  xmlhttp.open("GET", url, false);
		xmlhttp.send(null);
		//document.getElementById().innerHTML = xmlhttp.status;
		//document.getElementById().innerHTML = xmlhttp.statusText;
		//alert(xmlhttp.responseText);
		if (elId != '') {
			document.getElementById(elId).innerHTML = xmlhttp.responseText;
		}
  } else {
	  alert("Sorry, your browser does not support this type of ajax request.");
  }
  return false;
}

// ------ Adverts

function loadAds() {
	try {
		//alert('ads...');
		//$('leaderBoardIframe').src = '/ajax/adverts/advert.ashx?adtag=oldhamsunday&leaguetype=junior&adsize=728x90';
		$('#leaderBoardIframe')[0].src = '/ajax/adverts/advert.ashx?leagueid=' + advertLeagueId + '&adsize=728x90';
		$('#skyScraperIframe')[0].src = '/ajax/adverts/advert.ashx?leagueid=' + advertLeagueId + '&adsize=120x600,160x600';
	} catch (ex) {
	}
	return false;
}

// ------------ Modal iframe

function setModalIframe(w,h,url) {
	var haIf = $('#modalIFrame')[0];
	haIf.width = w;
	haIf.height = h;	
	haIf.src = url;
	var vh = getViewportHeight();
	var sh = getScrollHeight();
	var haP = $('#modalPopup2')[0];
	var pt = (((vh/2) - (h/2)) + sh - 15 ) + 'px';
	//alert(pt);
	haP.style.paddingTop = pt;
	haP.style.display = '';
}

// ----------- Viewport Height

function getViewportHeight() {
	var h = 0;

	if (typeof window.innerHeight != 'undefined') {
		h = window.innerHeight;
	} else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0) {
		h = document.documentElement.clientHeight;
	} else {
		h = document.getElementsByTagName('body')[0].clientHeight;
	}

	return h;
}

// ----------- Scroll Height

function getScrollHeight() {

	var h = document.body.scrollTop ? document.body.scrollTop 
					: ( window.pageYOffset ? window.pageYOffset
						: ( document.body.parentElement ? document.body.parentElement.scrollTop 
							: 0 ) );
							
	return h;

}

function applyReferees(fixtureId, referee, linesman1, linesman2, progressControl) {
  ClientServices.ApplyRefereeRating(fixtureId, referee, linesman1, linesman2, applyRefereesSuccess, null, progressControl);
}

function applyRefereesSuccess(data, context) {
  context.style.display = 'none';
}

function showSubMenu(el) {
  var coords = findPos(el);
  var x = coords[0];
  var y = coords[1];
  try {
    //if ($(el.id.replace('topMenu', 'subMenu')) != null) {
    var subM = $('#' + el.id.replace('topMenu', 'subMenu'))[0];
    subM.style.top = (y + 30) + 'px';
    subM.style.left = x + 'px';
    subM.style.display = 'block';
    hideAdverts();
  } catch (err) {
  }
  return false;
}

function showSubMenuSelf(el) {

  topM = $('#' + el.id.replace('subMenu', 'topMenu'))[0];
  var coords = findPos(topM);
  var x = coords[0];
  var y = coords[1];
  el.style.top = (y + 30) + 'px';
  el.style.left = x + 'px';
  el.style.display = 'block';
  hideAdverts();
  return false;
}

function hideSubMenu(el) {
  try {
    var subM = $('#' + el.id.replace('topMenu', 'subMenu')).css('display', 'none');
  } catch (err) {
  }
  showAdverts();
  return false;
}

function hideAdverts() {
  var i = $('#leaderBoardAdHolder');
  if (i != null) i.css('display', 'none');

  return false;
}
function showAdverts() {
  var i = $('#leaderBoardAdHolder');
  if (i != null) i.css('display', '');

  return false;
}