function ws_results(obj) {
 var div = document.getElementById("ynum");
 var numofres = obj.ResultSet.totalResultsAvailable;
 removeContents(div);
 var t = document.createTextNode("" + numofres);
 div.appendChild(t);
 delete obj;
}

function extra_initialize() {

//only recent W3C DOM Javascript browsers!
if (document.getElementById("article_extradiv")) {

var c_link = document.getElementById("link_count");
c_link.onclick = function() { article_linkcount(); return(false);};

var r_link = document.getElementById("link_react");
r_link.onclick = function() { article_react(); return(false);};
var b_link = document.getElementById("link_bookmark");
b_link.onclick = function() { article_bookmark(); return(false);};
var p_link = document.getElementById("link_print");
p_link.onclick = function() { article_print(); return(false);};

}
}


function article_linkcount() {
var exdiv = document.getElementById("article_extradiv");
removeContents(exdiv);

var wdiv = document.createElement("div");
wdiv.id = "article_extra_wrapper";
exdiv.appendChild(wdiv);

var xdiv = document.createElement("div");
xdiv.id = "article_extra_contents";
wdiv.appendChild(xdiv);

var cdiv = document.createElement("div");
cdiv.id = "article_extra_closediv";
xdiv.appendChild(cdiv);


var xclose = document.createElement("a");
xclose.href = "#";
xclose.onclick = function() { extra_close(); return(false);};
var xclose_txt = document.createTextNode("CLOSE");
xclose.appendChild(xclose_txt);
cdiv.appendChild(xclose);

var popdown = document.createElement("div");
popdown.id = "article_extrapop_linkcount";
xdiv.appendChild(popdown);

var popdown_p1 = document.createElement("p");
var popdown_p1_txt = document.createTextNode("Number of pages linking to this article:");
popdown_p1.appendChild(popdown_p1_txt);
popdown.appendChild(popdown_p1);

//YBADGE
var sh1c = document.createElement('div');
sh1c.style.textAlign = "center";
sh1c.style.margin = "0 auto";
sh1c.style.width = "105px";
popdown.appendChild(sh1c);

var yba_div = document.createElement('div');
yba_div.id = "ybadge";
yba_div.onclick = function() { window.top.location = "http://siteexplorer.search.yahoo.com/advsearch?p=" + encodeURIComponent(js_permalink) + "&bwm=i&bwmf=u"; };
yba_div.style.position = "relative";
yba_div.style.left = "0px";
yba_div.style.top = "0px";
yba_div.style.width = "105px";
yba_div.style.height = "35px";
yba_div.style.zIndex = "1";
yba_div.style.border = "1px solid #8ea9ba";
yba_div.style.background = "url(https://sec.yimg.com/us.yimg.com/i/us/sch/el/siteex_badgesml_bg.gif) repeat-x";
yba_div.style.overflow = "hidden";
yba_div.style.cursor = "pointer";
sh1c.appendChild(yba_div);

var ybaimg = document.createElement('img');
ybaimg.setAttribute("src", "https://sec.yimg.com/us.yimg.com/i/us/sch/el/siteex_badgesml_logo.gif");
ybaimg.setAttribute("alt", "Yahoo!");
ybaimg.setAttribute("width" ,"18");
ybaimg.setAttribute("height", "10");
ybaimg.style.margin = "0";
ybaimg.style.padding = "0";

var yba_im = document.createElement('div');
yba_im.id = "yimg";
yba_im.style.position = "absolute";
yba_im.style.left = "3px";
yba_im.style.top = "13px";
yba_im.style.width = "25px";
yba_im.style.font = "5px Arial";
//yba_im.style.color = "#2d2a25";
yba_im.style.height = "15px";
yba_im.style.zIndex = "2";
yba_im.style.textAlign = "center";

yba_im.appendChild(ybaimg);
yba_div.appendChild(yba_im);

var yba_num = document.createElement('div');
yba_num.id = "ynum";
yba_num.style.position = "absolute";
yba_num.style.left = "30px";
yba_num.style.top = "3px";
yba_num.style.width = "75px";
yba_num.style.font = "bold 11px Tahoma, Verdana, Arial";
yba_num.style.color = "#2d2a25";
yba_num.style.height = "15px";
yba_num.style.zIndex = "2";
yba_num.style.textAlign = "center";

var ynumt = document.createTextNode("Loading...");
yba_num.appendChild(ynumt);
yba_div.appendChild(yba_num);

var yba_txt = document.createElement('div');
yba_txt.id = "ytxt";
yba_txt.style.position = "absolute";
yba_txt.style.left = "30px";
yba_txt.style.top = "18px";
yba_txt.style.width = "75px";
yba_txt.style.font = "normal 11px Tahoma, Verdana, Arial";
yba_txt.style.color = "#1b1a17";
yba_txt.style.height = "15px";
yba_txt.style.zIndex = "3";
yba_txt.style.textAlign = "center";
var ytx = document.createTextNode("Links to URL");
yba_txt.appendChild(ytx);
yba_div.appendChild(yba_txt);

//JAVASCRIPT ADDS JAVASCRIPT
var randNum = Math.round(1209*Math.random());


// http://search.yahooapis.com/SiteExplorerService/V1/inlinkCount?appid=&query=http://www.yahoo.it

var surl = "http://search.yahooapis.com/SiteExplorerService/V1/inlinkCount?appid=m.o.mjHV34FLPi9u4XviKgLoznbhAFaEVNwsQxcUbsJBszuHKt7vHxoNOwsaDHKAvsA-&entire_site=0&query=" + encodeURIComponent(js_permalink) + "&output=json&callback=ws_results&rando=" + randNum;
var screle = document.createElement("script");
screle.src = surl;
popdown.appendChild(screle);

var popdown_p = document.createElement("p");
var popdown_p_txt = document.createTextNode("Data provided by Yahoo! Site Explorer web services API.");
popdown_p.appendChild(popdown_p_txt);
popdown.appendChild(popdown_p);

var popdown_p3 = document.createElement("p");
var popdown_p3_txt = document.createTextNode("You can also explore the incoming links on the Yahoo! Site Explorer website, by clicking on the Yahoo! Badge above.");
popdown_p3.appendChild(popdown_p3_txt);
popdown.appendChild(popdown_p3);

}

function article_react() {
var exdiv = document.getElementById("article_extradiv");
removeContents(exdiv);

var wdiv = document.createElement("div");
wdiv.id = "article_extra_wrapper";
exdiv.appendChild(wdiv);

var xdiv = document.createElement("div");
xdiv.id = "article_extra_contents";
wdiv.appendChild(xdiv);

var cdiv = document.createElement("div");
cdiv.id = "article_extra_closediv";
xdiv.appendChild(cdiv);
 
var xclose = document.createElement("a");
xclose.href = "#";
xclose.onclick = function() { extra_close(); return(false);};
var xclose_txt = document.createTextNode("CLOSE");
xclose.appendChild(xclose_txt);
cdiv.appendChild(xclose);

var popdown = document.createElement("div");
popdown.id = "article_extrapop_react";
xdiv.appendChild(popdown);

var popdown_p = document.createElement("p");
var popdown_p_txt = document.createTextNode("Please insert a valid email address. To react to this article, just reply to the message you'll receive in your mailbox. Do NOT edit the subject of the reply message.");
popdown_p.appendChild(popdown_p_txt);
popdown.appendChild(popdown_p);

var popdown_ul = document.createElement("ul");
popdown_ul.id = "article_extra_react_ul";
popdown.appendChild(popdown_ul);
var popdown_li1 = document.createElement("li");
popdown_ul.appendChild(popdown_li1);

var popdown_input = document.createElement("input");
popdown_input.type = "text";
popdown_input.size = "20";
popdown_input.id = "article_extramail";
popdown_input.value = "your@email.here";
popdown_li1.appendChild(popdown_input);

var popdown_button = document.createElement("button");
popdown_button.id = "article_extra_react_button";
popdown_button.onclick = function() { submit_email(); return(false);};
var popdown_button_txt = document.createTextNode(" ok ");
popdown_button.appendChild(popdown_button_txt);
popdown_li1.appendChild(popdown_button);

var popdown_li2 = document.createElement("li");
popdown_ul.appendChild(popdown_li2);

var popdown_checkbox = document.createElement("input");
popdown_checkbox.type = "checkbox";
popdown_checkbox.id = "article_extracheck";
popdown_li2.appendChild(popdown_checkbox);
popdown_checkbox.checked = false;

var popdown_span = document.createElement("span");
popdown_span.id = "article_extraspan";
var popdown_span_txt = document.createTextNode("Rember email address");
popdown_span.appendChild(popdown_span_txt);
popdown_li2.appendChild(popdown_span);

var email = readcookie_email();
if (email != "") {
popdown_input.value = email;
popdown_checkbox.checked = true;
}

}


function submit_email() {
var input_email = document.getElementById("article_extramail");
var checked_email = document.getElementById("article_extracheck");
if (checked_email.checked) setcookie_email(input_email.value);
else setcookie_email("");

var ajaxreq = new createXMLHttpReq();
	if (ajaxreq) {
		var xdiv = document.getElementById("article_extrapop_react");
		removeContents(xdiv);
		//loading messagge
		var loading_p = document.createElement("p");
		var loading_p_txt = document.createTextNode("Please wait...");
		loading_p.appendChild(loading_p_txt);
		xdiv.appendChild(loading_p);
		
		ajaxreq.onreadystatechange = function() {
		if(ajaxreq.readyState  == 4){
	
		if(ajaxreq.status  == 200) {
			var resptxt = ajaxreq.responseText;
			var xdiv = document.getElementById("article_extrapop_react");
			removeContents(xdiv);
			var loading_p = document.createElement("p");
			var loading_p_txt = document.createTextNode(resptxt);
			loading_p.appendChild(loading_p_txt);
			xdiv.appendChild(loading_p);
				}	else { 
				var xdiv = document.getElementById("article_extrapop_react");
				removeContents(xdiv);
				var error_h3 = document.createElement("h3");
				var error_h3_txt = document.createTextNode("Error code: " + ajaxreq.status);
				error_h3.appendChild(error_h3_txt);
				xdiv.appendChild(error_h3);
				}
			}
		};
		
var randl = Math.round(1011*Math.random());	//send a random timestamp to avoid cache problems
var urlreq = js_baseurl + "email";
var js_ajaxpar = "ajax=1&language=eng&category=" + js_category + "&idart="+ js_idart +"&ref=" + encodeURIComponent(js_permalink)+"&email="+encodeURIComponent(input_email.value)+"&rando="+randl;

ajaxreq.open("POST", urlreq, true);
ajaxreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxreq.send(js_ajaxpar);

//window.location = urlreq;

} else {	// escape to NOAJAX page

var noajax = js_baseurl + "/category/" + js_category + "/" + js_idart + "/" + encodeURIComponent(js_urltitle) + "/react";
window.location = noajax;
	}
}

//SOCIAL BOOKMARK
function article_bookmark() {
var exdiv = document.getElementById("article_extradiv");
removeContents(exdiv);

var wdiv = document.createElement("div");
wdiv.id = "article_extra_wrapper";
exdiv.appendChild(wdiv);

var xdiv = document.createElement("div");
xdiv.id = "article_extra_contents";
wdiv.appendChild(xdiv);

var cdiv = document.createElement("div");
cdiv.id = "article_extra_closediv";
xdiv.appendChild(cdiv);

var xclose = document.createElement("a");
xclose.href = "#";
xclose.onclick = function() { extra_close(); return(false);};
var xclose_txt = document.createTextNode("CLOSE");
xclose.appendChild(xclose_txt);
cdiv.appendChild(xclose);

var popdown = document.createElement("div");
popdown.id = "article_extrapop_bookmark";
xdiv.appendChild(popdown);

var popdown_p = document.createElement("p");
var popdown_p_txt = document.createTextNode("You can bookmark this article (and share it with the rest of the world, if you want) using one or more of the following online social bookmarking services:");
popdown_p.appendChild(popdown_p_txt);
popdown.appendChild(popdown_p);

var popdown_ul = document.createElement("ul");
popdown_ul.id = "article_extra_bookmark_ul";
popdown.appendChild(popdown_ul);

var popdown_li1 = document.createElement("li");
popdown_li1.id = "bookmark_yahoo_myweb";
var popdown_li1_a = document.createElement("a");
popdown_li1_a.href = "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + encodeURIComponent(js_permalink) + "&t=" + encodeURIComponent (js_title);
popdown_li1.appendChild(popdown_li1_a);
var popdown_li1_txt = document.createTextNode("Yahoo MyWeb");
popdown_li1_a.appendChild(popdown_li1_txt);
popdown_ul.appendChild(popdown_li1);

var popdown_li10 = document.createElement("li");
popdown_li10.id = "bookmark_live";
var popdown_li10_a = document.createElement("a");
popdown_li10_a.href = "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title) + "&top=1" ;
popdown_li10.appendChild(popdown_li10_a);
var popdown_li10_txt = document.createTextNode("Live Favorites");
popdown_li10_a.appendChild(popdown_li10_txt);
popdown_ul.appendChild(popdown_li10);

var popdown_li12 = document.createElement("li");
popdown_li12.id = "bookmark_google";
var popdown_li12_a = document.createElement("a");
popdown_li12_a.href = "http://www.google.com/bookmarks/mark?op=edit&bkmk=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title);
popdown_li12.appendChild(popdown_li12_a);
var popdown_li12_txt = document.createTextNode("Google Bookmarks");
popdown_li12_a.appendChild(popdown_li12_txt);
popdown_ul.appendChild(popdown_li12);

var popdown_li15 = document.createElement("li");
popdown_li15.id = "bookmark_ask";
var popdown_li15_a = document.createElement("a");
popdown_li15_a.href = "http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title);
popdown_li15.appendChild(popdown_li15_a);
var popdown_li15_txt = document.createTextNode("Ask MyStuff");
popdown_li15_a.appendChild(popdown_li15_txt);
popdown_ul.appendChild(popdown_li15);

var popdown_li13 = document.createElement("li");
popdown_li13.id = "bookmark_yahoo_bookmarks";
var popdown_li13_a = document.createElement("a");
popdown_li13_a.href = "http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=" + encodeURIComponent(js_permalink) + "&t=" + encodeURIComponent(js_title);
popdown_li13.appendChild(popdown_li13_a);
var popdown_li13_txt = document.createTextNode("Yahoo Bookmarks");
popdown_li13_a.appendChild(popdown_li13_txt);
popdown_ul.appendChild(popdown_li13);

var popdown_li2 = document.createElement("li");
popdown_li2.id = "bookmark_digg";
var popdown_li2_a = document.createElement("a");
popdown_li2_a.href = "http://digg.com/submit?phase=2&url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title) ;
popdown_li2.appendChild(popdown_li2_a);
var popdown_li2_txt = document.createTextNode("Digg");
popdown_li2_a.appendChild(popdown_li2_txt);
popdown_ul.appendChild(popdown_li2);

var popdown_li3 = document.createElement("li");
popdown_li3.id = "bookmark_technorati";
var popdown_li3_a = document.createElement("a");
popdown_li3_a.href = "http://www.technorati.com/faves?add=" + encodeURIComponent(js_permalink);
popdown_li3.appendChild(popdown_li3_a);
var popdown_li3_txt = document.createTextNode("Technorati");
popdown_li3_a.appendChild(popdown_li3_txt);
popdown_ul.appendChild(popdown_li3);

var popdown_li4 = document.createElement("li");
popdown_li4.id = "bookmark_delicious";
var popdown_li4_a = document.createElement("a");
popdown_li4_a.href = "http://del.icio.us/post?url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent (js_title);
popdown_li4.appendChild(popdown_li4_a);
var popdown_li4_txt = document.createTextNode("Del.icio.us");
popdown_li4_a.appendChild(popdown_li4_txt);
popdown_ul.appendChild(popdown_li4);

var popdown_li5 = document.createElement("li");
popdown_li5.id = "bookmark_furl";
var popdown_li5_a = document.createElement("a");
popdown_li5_a.href = "http://furl.net/storeIt.jsp?u=" + encodeURIComponent(js_permalink) + "&t=" + encodeURIComponent (js_title);
popdown_li5.appendChild(popdown_li5_a);
var popdown_li5_txt = document.createTextNode("Furl");
popdown_li5_a.appendChild(popdown_li5_txt);
popdown_ul.appendChild(popdown_li5);

var popdown_li16 = document.createElement("li");
popdown_li16.id = "bookmark_blogger";
var popdown_li16_a = document.createElement("a");
popdown_li16_a.href = "http://www.blogger.com/blog-this.g?u=" + encodeURIComponent(js_permalink) + "&t=" + encodeURIComponent(js_title);
popdown_li16.appendChild(popdown_li16_a);
var popdown_li16_txt = document.createTextNode("Blog this");
popdown_li16_a.appendChild(popdown_li16_txt);
popdown_ul.appendChild(popdown_li16);

var popdown_li17 = document.createElement("li");
popdown_li17.id = "bookmark_facebook";
var popdown_li17_a = document.createElement("a");
popdown_li17_a.href = "http://www.facebook.com/share.php?u=" + encodeURIComponent(js_permalink) + "&t=" + encodeURIComponent(js_title);
popdown_li17.appendChild(popdown_li17_a);
var popdown_li17_txt = document.createTextNode("Facebook");
popdown_li17_a.appendChild(popdown_li17_txt);
popdown_ul.appendChild(popdown_li17);


var popdown_li9 = document.createElement("li");
popdown_li9.id = "bookmark_slashdot";
var popdown_li9_a = document.createElement("a");
popdown_li9_a.href = "http://slashdot.org/bookmark.pl?url=" + encodeURIComponent(js_permalink);
popdown_li9.appendChild(popdown_li9_a);
var popdown_li9_txt = document.createTextNode("Slashdot");
popdown_li9_a.appendChild(popdown_li9_txt);
popdown_ul.appendChild(popdown_li9);


var popdown_li11 = document.createElement("li");
popdown_li11.id = "bookmark_netvouz";
var popdown_li11_a = document.createElement("a");
popdown_li11_a.href = "http://netvouz.com/action/submitBookmark?url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title) + "&popup=no" ;
popdown_li11.appendChild(popdown_li11_a);
var popdown_li11_txt = document.createTextNode("Netvouz");
popdown_li11_a.appendChild(popdown_li11_txt);
popdown_ul.appendChild(popdown_li11);


var popdown_li6 = document.createElement("li");
popdown_li6.id = "bookmark_magnolia";
var popdown_li6_a = document.createElement("a");
popdown_li6_a.href = "http://ma.gnolia.com/bookmarklet/add?url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent (js_title);
popdown_li6.appendChild(popdown_li6_a);
var popdown_li6_txt = document.createTextNode("Ma.gnolia");
popdown_li6_a.appendChild(popdown_li6_txt);
popdown_ul.appendChild(popdown_li6);

var popdown_li8 = document.createElement("li");
popdown_li8.id = "bookmark_blogmarks";
var popdown_li8_a = document.createElement("a");
popdown_li8_a.href = "http://blogmarks.net/my/new.php?mini=1&simple=1&url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent (js_title);
popdown_li8.appendChild(popdown_li8_a);
var popdown_li8_txt = document.createTextNode("Blogmarks");
popdown_li8_a.appendChild(popdown_li8_txt);
popdown_ul.appendChild(popdown_li8);

var popdown_li14 = document.createElement("li");
popdown_li14.id = "bookmark_reddit";
var popdown_li14_a = document.createElement("a");
popdown_li14_a.href = "http://reddit.com/submit?url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent(js_title);
popdown_li14.appendChild(popdown_li14_a);
var popdown_li14_txt = document.createTextNode("Reddit");
popdown_li14_a.appendChild(popdown_li14_txt);
popdown_ul.appendChild(popdown_li14);

var popdown_li7 = document.createElement("li");
popdown_li7.id = "bookmark_simpy";
var popdown_li7_a = document.createElement("a");
popdown_li7_a.href = "http://www.simpy.com/simpy/Login.do?_doneURI=/simpy/LinkAdd.do?href=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent (js_title);
popdown_li7.appendChild(popdown_li7_a);
var popdown_li7_txt = document.createTextNode("Simpy");
popdown_li7_a.appendChild(popdown_li7_txt);
popdown_ul.appendChild(popdown_li7);


var popdown_other = document.createElement("div");
popdown_other.id = "article_extrapop_bookmark_other";
var popdown_other_a = document.createElement("a");
popdown_other_a.href = "http://www.addthis.com/bookmark.php?pub=dofu&url=" + encodeURIComponent(js_permalink) + "&title=" + encodeURIComponent (js_title);
popdown_other.appendChild(popdown_other_a);
var popdown_other_txt = document.createTextNode("Other web2.0 social bookmarks services");
popdown_other_a.appendChild(popdown_other_txt);
popdown.appendChild(popdown_other);





}

function article_print() {
var xdiv = document.getElementById("article_extradiv");
removeContents(xdiv);
window.print();
}

function removeContents(divx) {	//clean DIV, delete all content
	while(divx.hasChildNodes() ) { 
		divx.removeChild( divx.firstChild ); 
	}
}

function createXMLHttpReq() {	//create AJAX request
	if (typeof XMLHttpRequest != 'undefined')
		return new XMLHttpRequest();
	else if (window.ActiveXObject) {
		var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"];
		for (var i = avers.length -1; i >= 0; i--) {
			try {
				httpObj = new ActiveXObject(avers[i]);
				return httpObj;
			} catch(e) {}
		}
	}
	//NO AJAX
	return false;
}


function setcookie_email(email) {
var emailcookie = "email=" + email;
var date = new Date();
date.setTime(date.getTime()+(8*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = emailcookie + expires + "; path=/";
}

function readcookie_email() {
var ca = document.cookie.split(';');
var email = "";
for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		var ind = c.indexOf("email=");
		if (ind > -1) email = c.substring(ind+6,c.length);
	}
return unescape(email);
}

function extra_close() {
 var exdiv = document.getElementById("article_extradiv");
 removeContents(exdiv);
}                                                                  