String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function checkLinks(){
	if ( typeof lcw_nh_li != 'undefined' && lcw_nh_li == "1" ) {
		return true;
	}
	
    var liveChartsLinks     = document.getElementById('lcw-nh-links');
	var liveChartsLinkOne   = document.getElementById('lcw-nh-linkone');
	var liveChartsLinkTwo   = document.getElementById('lcw-nh-linktwo');
	
	var liveChartsContainer = document.getElementById('lcw-nh-container');
	if ( liveChartsContainer.style.display != '' ||  liveChartsContainer.style.visibility == 'hidden' ) {
		return false;
	}
	var children = liveChartsContainer.getElementsByTagName('*');
	for ( var i = 0; i < children.length; i++ ) {
		if ( children[i].style.display != '' ||  children[i].style.visibility == 'hidden' ) {
			return false;
		}
	}
	
	if ( liveChartsLinkOne && 
		 liveChartsLinkTwo && 
		 (liveChartsLinkOne.getAttribute("href") == "http://www.livecharts.co.uk/share_prices/share_price.php" || liveChartsLinkOne.getAttribute("href") == "http://www.livecharts.co.uk/share_prices/share_price.php" ) && 
		 liveChartsLinkOne.innerHTML            == "Share prices" &&
		 liveChartsLinkTwo.getAttribute("href") == "http://www.livecharts.co.uk/share_prices/market_news.php" && 
		 liveChartsLinkTwo.innerHTML            == "Stock Market News"
	) {
		return true;
	}
	return false;
}
function writeWidget() {
	var divIFrame          = document.createElement('DIV');
	var w                  = 310;
	var h                  = 50 + ((lcw_nh_headlinescount-1)*18);
	//var heights = new Array("50", "70", "90", "110");
	
	var url  = "http://www.livecharts.co.uk/widgets/news_headlines/nh.php?";
	url += "location=" + escape(document.location);
	url += "&title=" + escape(lcw_nh_title);
	url += "&titleColor=" + escape(lcw_nh_titleColor);
	url += "&titleBGColor=" + escape(lcw_nh_titleBGColor);
	url += "&borderColor=" + escape(lcw_nh_borderColor);
	url += "&backgroundColor=" + escape(lcw_nh_backgroundColor);
	url += "&section=" + escape(lcw_nh_section);
	url += "&headlinesCount=" + escape(lcw_nh_headlinescount);
	if ( typeof lcw_nh_wp != 'undefined' ) {
		url += "&wp=" + lcw_nh_wp;
	}
	
	document.getElementById('lcw-nh-container').style.width=300;
	divIFrame.innerHTML    = '<iframe ALLOWTRANSPARENCY="true" style="width:' + w + 'px; height:' + h + 'px; padding:0px; margin:0px;" frameborder="0" marginheight="0" marginwidth="0" src="' + url + '" />';
	if ( typeof lcw_nh_li != 'undefined' && lcw_nh_li == "1" ) {
		document.getElementById('lcw-nh-container').appendChild(divIFrame);
	}
	else {
		document.getElementById('lcw-nh-container').insertBefore(divIFrame, document.getElementById('lcw-nh-links'));
	}
	
}
//alert(document.getElementById('lcw-nh-container').style.visibility);
if ( checkLinks() ) {
    writeWidget();
}
else {
	document.getElementById('lcw-nh-container').style.display    = '';
	document.getElementById('lcw-nh-container').style.visibility = 'visible';
    document.getElementById('lcw-nh-container').innerHTML        = 'Wrong widget code';
}

