// суммарный вес текстовых объявлений
var text_inc_weight = 0;
// тексты объявлений и их относительные веса
var text_inc = new Array (
 '<b>Hint:</b> Try <a href="/en/bb/">convert-me.com forum</a> where you can discuss your conversion issues and find answers to your questions.', 50,
 '<b>Hint:</b> Click <b>any</b> "convert" button to make conversions, they all act the same.', 20,
 'You can help us make the site better.  Support convert-me.com by <a href="/en/link2us_en.html">linking to our site from yours</a>.', 100,
 'Do you have a blog?  Spread the word about Convert-Me.Com by <a href="/en/link2us_en.html">mentioning our site in your blog</a>.', 100,
 '<b>Hint:</b> By clicking on the name of the unit you can get a list of all conversion factors from this unit to all others.', 30,
 '<b>Hint:</b> Drop-down menu on the top of the page is a quick navigation to other measurement conversion pages.', 30,
 'Your ideas on how to make Convert-Me.Com better are very appreciated! Please use <a href="/en/bb/">convert-me.com forum</a> for your thoughs and feedback.', 20,
 '<b>Hint:</b> Try adjusting "significant figures" option on the top of the page to get either cleaner or more precise figures.', 30,
 '<b>Hint:</b> It might be a good idea to bookmark Convert-Me.Com in your browser, don\'t you think so?', 20,
 '<b>Hint:</b> You can do as many conversions as you need without reloading the page.  Simply enter a new value in the appropriate box and click "Convert" again.', 30,
 '<b>Hint:</b> Do you know that as soon as the conversion page is loaded you don\'t need the Internet connection any more to make conversions? The calculations work offline just fine.', 30,
 '<b>Hint:</b> Tired or banner ads on our site?  <a href="/en/disable_banners_en.html">Switch them off</a>!', 50,
 'Want to know what happens on convert-me.com?  <a href="https://twitter.com/convertme">Visit our twitter news feed</a>!', 150,
 '<table border=0 cellpadding=0 cellspacing=0 align="left" style="margin-right:20px"><tr><td><a href="/en/en_gadget.html"><img src="/GG/convert-me-120x60.png" width=120 height=60 style="margin-right:20px; border: solid 1px #666666" alt="Units Conversion Gadget" title="Units Conversion Gadget"></a></td><td><b>Now you can add Units Conversion to your desktop, homepage or blog!</b> Convert-Me.Com gadget is free and easy to install. &nbsp;&nbsp;<a href="/en/en_gadget.html"><b>Read on</b></a>.</td></tr></table>',200,
// '*goadse*', 1000,
 '', 0
);


// вывести рекламное объявление перед n-ным заголовком
function formInc ( n ) {

//	( n == 2 && goSearchFeed() == 0 ) ||
        if( n== 2 || n == 3 || n == 4 || n == 6 || n == 9 || n == 11 ) {
		var r = Math.round(Math.random() * text_inc_weight);
		var r0 = r;
		var i = 0;
		while( i<text_inc.length ) {
			r -= text_inc[i+1];
                	if( r < 0 ) {
                		if( text_inc[i] == '*goadse*' ) {
                			goadse()
                                } else {
                			textInc( text_inc[i] );
                                }
               			text_inc_weight-=text_inc[i+1];
               			text_inc[i+1] = 0;
				break;
                	}
			i+=2;
                }
	}
}

// собственно вывод текстового объявления
function textInc ( txt ) {
	document.write('<tr><td colspan="2"><table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" class="infotable">');
	document.write('<tr><td bgcolor="#666666"><table width="100%" border="0" cellspacing="1" cellpadding="6" class="infoblock">');
	document.write('<tr class="infoblock" align="center" valign="middle"><td class="infoblock">');
	document.write(txt);
	document.write('</td></tr></table></td></tr></table></td></tr>');
}

// реклама Google AdSence
function goadse () {
	document.writeln('<center>');
	document.writeln('<script type="text/javascript"><!--');
	document.writeln('google_ad_client = "pub-5439772599903806";');
	document.writeln('google_ad_width = 468;');
	document.writeln('google_ad_height = 60;');
	document.writeln('google_ad_format = "468x60_as";');
	document.writeln('google_ad_type = "text_image";');
	//2007-08-30: en-468x60-inline
	document.writeln('google_ad_channel = "8919943654";');
	document.writeln('google_color_border = "CCCCCC";');
	document.writeln('google_color_bg = "FFF5C8";');
	document.writeln('google_color_link = "663300";');
	document.writeln('google_color_text = "000000";');
	document.writeln('google_color_url = "0000FF";');
	document.writeln('google_ui_features = "rc:6";');
	document.writeln('//-->');
	document.writeln('</script>');
	document.writeln('<script type="text/javascript"');
	document.writeln('  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
	document.writeln('</script>');
	document.writeln('</center>');
}

// вычислим суммарный вес
for( var i=1; i<text_inc.length; i+=2 )
	text_inc_weight += text_inc[i];

// для совместимости
function formAd ( n ) { formInc( n ) }

// делаем запрос в searchfeed
var listings = new Array();
var seRef = escape(document.referrer);
var numRes = 1;
var partnerId = 29122;
var rndStr = Math.random()*100000;
var keyword = 'conversion';
//пока забудем про SF
//document.write("<scr" + "ipt src='ht" + "tp:" + "//ww" + "w.se" + "arc" + "hfe" + "ed.co" + "m/r" + "d/fe" + "ed/J"+ "av"+ "aScr" + "ipt" + "Fee" + "dS" + "E.jsp?rnd=" + rndStr + "&cat=" + escape(keyword) + "&pID=" + partnerId + "&nl=" + numRes + "&ref=" + seRef + "'>" + "</scr" + "ipt>");

// выводим объявление searchfeed
function goSearchFeed() {
  return 0; //пока забудем про SF
  if (listings && listings.length > 0) {
	var sKeyword = SearchEngineKeyword.split(" ");
	for (i = 0; i < listings.length; i++) {
	  	var url = listings[i].url;
	 	var title = listings[i].title;
		var description = listings[i].description;
		for (j = 0; j < sKeyword.length; j++) {
		  if (sKeyword[j].length >= 3) {
			var _kExp = new RegExp(sKeyword[j], "gi");
			description = description.replace(_kExp, "<b>" + sKeyword[j] + "</b>");
		  }
		}
		textInc('<a href="' + listings[i].uri + '" target="_blank" onMouseOver="window.status=\'visit: ' + url  + '\';return true;" onMouseOut="window.status=\' \';return true;"><b>' + title + '</b></a><br><a style="text-decoration: none;color:black" href="' + listings[i].uri + '" target="_blank" onMouseOver="window.status=\'visit: ' + url  + '\';return true;" onMouseOut="window.status=\' \';return true;">' + description +  '</a>');
	}
	return 1;
  }
  return 0;
}
