String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function checkLinks(){
	if ( typeof lcw_mp_li != 'undefined' && lcw_mp_li == "1" ) {
		return true;
	}

    var liveChartsLinks   = document.getElementById('lcw-mp-links');
	var liveChartsLinkOne = document.getElementById('lcw-mp-linkone');
	var liveChartsLinkTwo = document.getElementById('lcw-mp-linktwo');
	
	var liveChartsContainer = document.getElementById('lcw-mp-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            == "UK Share Prices" &&
		 liveChartsLinkTwo.getAttribute("href") == "http://www.livecharts.co.uk/MarketCharts/gold.php" && 
		 liveChartsLinkTwo.innerHTML            == "Gold Price"
	) {
		return true;
	}
	return false;
}
function writeWidget() {
	var divIFrame          = document.createElement('DIV');
	var heights            = new Array(48, 66, 86);
	var w                  = 310;
	var h                  = heights[lcw_mp_symbols.split(";").length-1];
	var url  = "http://www.livecharts.co.uk/widgets/market_prices/mp.php?";
	url += "location=" + escape(document.location);
	url += "&title=" + escape(lcw_mp_title);
	url += "&titleColor=" + escape(lcw_mp_titleColor);
	url += "&titleBGColor=" + escape(lcw_mp_titleBGColor);
	url += "&borderColor=" + escape(lcw_mp_borderColor);
	url += "&backgroundColor=" + escape(lcw_mp_backgroundColor);
	url += "&symbols=" + escape(lcw_mp_symbols);
	if ( typeof lcw_mp_wp != 'undefined' ) {
		url += "&wp=" + lcw_mp_wp;
	}
	
	document.getElementById('lcw-mp-container').style.width=300;
	divIFrame.innerHTML    = '<iframe ALLOWTRANSPARENCY="true" style="border:0px solid green;width:' + w + 'px; height:' + h + 'px; padding:0px; margin:0px;" frameborder="0" marginheight="0" marginwidth="0" src="' + url + '" />';
	if ( typeof lcw_mp_li != 'undefined' && lcw_mp_li == "1" ) {	
		document.getElementById('lcw-mp-container').appendChild(divIFrame);
	}
	else {
		document.getElementById('lcw-mp-container').insertBefore(divIFrame, document.getElementById('lcw-mp-links'));
	}
}
if ( checkLinks() ) {
    writeWidget();
}
else {
	document.getElementById('lcw-mp-container').style.display    = '';
	document.getElementById('lcw-mp-container').style.visibility = 'visible';
    document.getElementById('lcw-mp-container').innerHTML        = 'Wrong widget code';
	
    //document.getElementById('lcw-mp-container').innerHTML = 'Please add live charts links';
}

