function OpenWindow(url,iWidth,iHeight) {
	var pw_left=(screen.Width-parseInt(iWidth))/2;
	var pw_top=(screen.Height-parseInt(iHeight))/2;
	
	if  (url.indexOf("showbars")==-1) {
		popup_win=window.open(url, 'popupwin', 'menus=0, scrollbars=auto, toolbars=0, width='+iWidth+', height='+iHeight+', screenX='+pw_left+',screenY='+pw_top+',top='+pw_top+',left='+pw_left+';');
	} else {
		popup_win=window.open(url, 'popupwin', 'menus=0, scrollbars=1, toolbars=0, width='+iWidth+', height='+iHeight+', screenX='+pw_left+',screenY='+pw_top+',top='+pw_top+',left='+pw_left+';');
	}
}

function addToFavorites() {
	if (window.sidebar) {
		window.sidebar.addPanel(pageName, urlAddress, "");
	} else if (window.opera && window.print){
		var elem = document.createElement('a');
		elem.setAttribute('href',urlAddress);
		elem.setAttribute('title',pageName);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if (document.all) {
		window.external.addfavorite(urlAddress, pageName);
	} else {
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function emailLinkLSE(sToAddress,sLinkClass) {
	if (sToAddress != '') {
		document.write('<a href="' + 'mail' + 'to:' + sToAddress + '@lse.co.uk" class="' + sLinkClass + '">'+ sToAddress + '@lse.co.uk</a>');
	}
}

function loadImage(imgSrc, sImageName, iWidth, iHeight) {
	$('#' + imgSrc).attr('src', 'images/ajax-loader.gif');
	setTimeout('$(\'#' + imgSrc + '\').attr(\'src\', \'' + sImageName + '\')',800);
}

//Text Area Counter - Limits and returns the number of characters allowed
function textCounter(Text,Counter,iMaxLimit) {
	if (Text.value.length > iMaxLimit) {
		Text.value = Text.value.substring(0, iMaxLimit);
	} else {
		Counter.value = iMaxLimit - Text.value.length;
	}
}

var phone = "()- 0123456789";
var numb = "0123456789";
var numbDec = "0123456789.";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

function res(t,v,formatFlag) {
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1) w += x;
	}
	t.value = w;
	if (formatFlag) {
		t.value = addCommas(t.value);
	}
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function breakoutOfFrames() {
	if (window.top.location.href != window.location.href) {
		window.top.location.href = window.location.href;
	}
}

function showHideFilters() {
	if (sFiltersState == "hide") {
		$('div.shareChatFiltersDropDown:visible').slideUp('fast', setFiltersSession('hide'));
		sFiltersState = "show";
		$('#filterTab').removeClass('selected');
	} else {
		$('div.shareChatFiltersDropDown:hidden').slideDown('fast', setFiltersSession('show'));
		sFiltersState = "hide";
		$('#filterTab').addClass('selected');
	}
}
function setFiltersSession(sDDStatus) {
	$.get(siteURL + 'setFiltersDD.asp?status=' + sDDStatus);
}

function showHideQP() {
	if (sQPState == "hide") {
		if (livePrices==true) {clearTimeout(quickPickLiveTimer);clearTimeout(quickPickLiveIconTimer);}
		$('#quickPicks:visible').slideUp('fast', setQPSession('hide'));
		$('#QuickPickLiveIcon').attr('src',staticURL + 'images/livePricesIconYellow.png');
		$('#QuickPickLiveIcon').attr('title','Live Prices Paused');
		sQPState = "show";
		$('#QPTab').removeClass('selected');
	} else {
		if (livePrices==true) {clearTimeout(quickPickLiveTimer);runQuickPickLiveUpdates();}
		$('#quickPicks:hidden').slideDown('fast', setQPSession('show'));
		sQPState = "hide";
		$('#QPTab').addClass('selected');
	}
}
function setQPSession(sQPStatus) {
	$.get(siteURL + 'setQPDD.asp?status=' + sQPStatus);
}

function loadPremFancybox() {
	$("a.premVideo").fancybox({
		'width' : 600,
		'height' : 500,
		'type' : 'iframe',
		'overlayOpacity' : 0.7,
		'overlayColor' : '#111111',
		'margin' : 0,
		'padding' : 10,
		'scrolling' : 'no'
	});
}

$(document).ready(function() {
	$("a.smPopup").click(function() {
		var iMyWidth = (window.screen.width/2) - (275 + 10);
		var iMyHeight = (window.screen.height/2) - (200 + 50);
		window.open($(this).attr('href'), "popup", "status=no,width=550,height=400,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight)
		return false;
	});
});
