
var my_base_url = "http://www.blog-news.it";
var my_pligg_base = "";


dochref = document.location.href.substr(document.location.href.search("/")+2, 1000);
if(dochref.search("/") == -1) {
	$thisurl = document.location.href.substr(0, document.location.href.search("/")+2) + dochref;
} 
else {
	$thisurl = document.location.href.substr(0, document.location.href.search("/")+2) + dochref.substr(0, dochref.search("/"));
}
$thisurl = $thisurl + "";

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")} 
	catch(e) {
		try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")} 
		catch(E) {xmlhttp = false}
	}
@else xmlhttp = false
@end @*/

if(!xmlhttp && typeof XMLHttpRequest != "undefined") {
  try {xmlhttp = new XMLHttpRequest();}
  catch(e) {xmlhttp = false}
}

function myXMLHttpRequest() {
	var xmlhttplocal;
  
	try {xmlhttplocal = new ActiveXObject("Msxml2.XMLHTTP")}
	catch(e) {
		try {xmlhttplocal = new ActiveXObject("Microsoft.XMLHTTP")}
		catch(e) {xmlhttplocal = false;}
	}

	if(!xmlhttplocal && typeof XMLHttpRequest != "undefined") {
		try {var xmlhttplocal = new XMLHttpRequest();}
		catch(e) {var xmlhttplocal = false;}
	}  
	return (xmlhttplocal);
}

var mnmxmlhttp = Array();
var xvotesString = Array();
var mnmPrevColor = Array();
var responsestring = Array();
var myxmlhttp = Array();
var responseString = new String;

function vote(user, id, htmlid, md5, value, frame) {
	if(xmlhttp) {
		url = $thisurl + "/vote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value + "&frame=" + frame;
		anonymous_vote = false;
		if(anonymous_vote == false && user == "0") {
			parent.window.location = "http://www.blog-news.it/login";
		} 
		else {
			mnmxmlhttp[htmlid] = new myXMLHttpRequest();
			if(mnmxmlhttp) {
				target1 = document.getElementById("xvotes-" + htmlid);
				mnmPrevColor[id] = target1.style.backgroundColor;
				if(frame == 1) {
					target1 = document.getElementById("imgWait-" + htmlid);
					var voto = target1.innerHTML;
					target1.innerHTML = "<span style='color:C30;'><img src='/templates/onenews/images/icon_loading.gif' style='vertical-align:middle; border:none;' /> Salvataggio in corso...</span>";
				}
				else {
					var voto = target1.innerHTML;
					target1.innerHTML = "<span><img src='/templates/onenews/images/icon_loading.gif' style='vertical-align:middle; border:none;' />";
				}
				target2 = document.getElementById("xvote-" + htmlid);
				target2.innerHTML = "<span>Votato</span>";
	
				mnmxmlhttp[htmlid].open("POST", url, true);
				mnmxmlhttp[htmlid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				mnmxmlhttp[htmlid].send(mycontent);
				errormatch = new RegExp("^ERROR:");
				
				mnmxmlhttp[htmlid].onreadystatechange = function() {
					if(mnmxmlhttp[htmlid].readyState == 4) {
						xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
						if(xvotesString[htmlid].match(errormatch)) {
							xvotesString[htmlid] = xvotesString[htmlid].substring(6, xvotesString[htmlid].length);
							changemnmvalues(htmlid, value, true, frame);						} 
						else {if(xvotesString[htmlid].substring(1, 6) == 'ERROR') {
alert('Avviso' + xvotesString[htmlid].substring(6, xvotesString[htmlid].length));
setTimeout('doRefresh()', 1000);
}
 else {changemnmvalues(htmlid, value, false, frame);}}
					}
				}
			}
		}
	}
}

function cvote(user, id, htmlid, md5, value) {
	if(xmlhttp) {
		url = $thisurl + "/cvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;

		if(anonymous_vote == false && user == "0") {
			parent.window.location = "http://www.blog-news.it/login";
		} 
		else {
			mnmxmlhttp[htmlid] = new myXMLHttpRequest();
			if(mnmxmlhttp) {
				target = document.getElementById("cvote-" + htmlid);
				mnmPrevColor[id] = target.style.backgroundColor;
				target.style.backgroundColor = "#FFFFFF";
				var voto = target.innerHTML;
				target.innerHTML = "<span><img src='/templates/onenews/images/icon_loading.gif' style='vertical-align:middle; border:none;' />";		
				mnmxmlhttp[htmlid].open("POST", url, true);
				mnmxmlhttp[htmlid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
				mnmxmlhttp[htmlid].send(mycontent);
				errormatch = new RegExp("^ERROR:");
				
				mnmxmlhttp[htmlid].onreadystatechange = function() {
					if(mnmxmlhttp[htmlid].readyState == 4) {
						xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
						if(xvotesString[htmlid].match(errormatch)) {
							xvotesString[htmlid] = xvotesString[htmlid].substring(6, xvotesString[htmlid].length);						
							changecvotevalues(htmlid, false);						
						} 
						else {if(xvotesString[htmlid].substring(1, 6) == 'ERROR') {
alert('Avviso' + xvotesString[htmlid].substring(6, xvotesString[htmlid].length));
setTimeout('doRefresh()', 1000);
}
 else {changecvotevalues(htmlid, false);}}
					}
				}
			}
		}
	}
}

function stampMsg1(id, value, frame) {
	target1 = document.getElementById("xvotes-" + id);
	target1.innerHTML = value;
	target1.style.backgroundColor = mnmPrevColor[id];
	if(frame == 1) {
		target3 = document.getElementById("imgWait-" + id);
		target3.innerHTML = "<span></span>";
	}
}

function stampMsg2(id, value) {	
	target1 = document.getElementById("cvote-" + id);
	target1.innerHTML = value;
	target1.style.backgroundColor = mnmPrevColor[id];
	target2 = document.getElementById("ratebuttons-" + id);
	target2.style.display = "none";
	target3 = document.getElementById("ratetext-" + id);
	target3.innerHTML = "<span class='rateme' style='color:#CC3300;'>Votato</span>";
}

function doRefresh() {document.location.reload();}

function changemnmvalues(id, value, error, frame) {
	split = new RegExp("~--~");
	b = xvotesString[id].split(split);
	target2 = document.getElementById("xvote-" + id);
	target3 = document.getElementById("xreport-" + id);
	target4 = document.getElementById("xnews-" + id);
	
	if(error) {
		if(value > 0) {target2.innerHTML = "<span>Votato</span> ";}
		else if(value < 0) {target2.innerHTML = "<span>Buried</span> ";}
		return false;
	}
	if(b.length <= 3) {
		sentTimer = setTimeout("stampMsg1("+id+","+b[0]+","+frame+")", 1000);
		//new Effect.Fade(target3);
		if(value > 0) {target2.innerHTML = "<span>Votato</span> ";}
		else if(value < 0) {
			target2.innerHTML = "<span>Buried</span> ";
			//new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3});
		}
	}
	return false;
}

function changecvotevalues(id, error) {
	split = new RegExp("~--~");
	b = xvotesString[id].split(split);
	if(error) {return false;}
	if(b.length <= 3) {sentTimer = setTimeout("stampMsg2("+id+","+b[0]+")", 1000);}	
	return false;
}

function enablebutton(button, button2, target) {
	var string = target.value;
	button2.disabled = false;
	if(string.length > 0) {button.disabled = false;} 
	else {button.disabled = true;}
}

function checkfield(type, form, field) {
	url = $thisurl + "/checkfield.php?type="+type+"&name=" + field.value;
	checkitxmlhttp = new myXMLHttpRequest();
	checkitxmlhttp.open("GET", url, true);
	checkitxmlhttp.onreadystatechange = function() {
		if(checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			if(responsestring == "OK") {
				document.getElementById(field.name+"checkitvalue").innerHTML = "<span style='color:black'>'" + field.value + "': " + responsestring + "</span>";
				form.submit.disabled = "";
			} 
			else {
				document.getElementById(field.name+"checkitvalue").innerHTML = "<span style='color:red'>'" + field.value + "': " + responsestring + "</span>";
				form.submit.disabled = "";
			}
		}
	}
	checkitxmlhttp.send(null);
	return false;
}

function emailto(original_id, htmlid, instpath, address_count) {
	email_message = document.getElementById("email_message" + htmlid).value;
	email_address = document.getElementById("email_address_1_" + htmlid).value;
	
	if(address_count > 1) { 
		for($i=2; $i<=address_count; $i++) {
			if(document.getElementById("email_address_" + $i + "_" + htmlid).value != "") {
				email_address = email_address + ", " + document.getElementById('email_address_' + $i + '_' + htmlid).value;
			}
		}
	}
	
	if(xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";
		target2 = document.getElementById("emailto-" + htmlid);		
		target2.innerHTML = "<br/><br/>&nbsp;&nbsp;<img src='/templates/onenews/images/icon_loading.gif' style='vertical-align:middle; border:none;' />";
		target2.innerHTML += "&nbsp;Invio del messaggio in corso...<br/>";
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest();
		if(mnmxmlhttp) {
			mnmxmlhttp[htmlid].open("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			mnmxmlhttp[htmlid].send(mycontent);
			errormatch = new RegExp("^ERROR:");
			target1 = document.getElementById("emailto-" + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function() {
				if(mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
					if(xvotesString[htmlid].match(errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring(6, xvotesString[htmlid].length);
						target2 = document.getElementById("emailto-" + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} 
					else {
						target2 = document.getElementById("emailto-" + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
			alert('La tua richiesta è stata inviata con successo');
		}
	}
}

function show_recommend(htmlid, linkid, instpath) {
	var emailtodisplay = document.getElementById("emailto-" + htmlid).style.display ? "" : "none";
	document.getElementById("emailto-" + htmlid).style.display = emailtodisplay;

	if(xmlhttp) {
		url = $thisurl + "/recommend.php";
		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;
		target2 = document.getElementById("emailto-" + htmlid);
		target2.innerHTML = "<br/><br/>&nbsp;&nbsp;<img src='/templates/onenews/images/icon_loading.gif' style='vertical-align:middle; border:none;' />";
		target2.innerHTML += "&nbsp;Apertura modulo segnalazione in corso...<br/>";
		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest();
		if(mnmxmlhttp) {
			mnmxmlhttp[htmlid].open("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp("^ERROR:");
			target1 = document.getElementById("emailto-" + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function() {
				if(mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;			
					if(xvotesString[htmlid].match(errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring(6, xvotesString[htmlid].length);						
						target2 = document.getElementById("emailto-" + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} 
					else {
						target2 = document.getElementById("emailto-" + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}
