var xmlhttp=false;

// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} 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 mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function vote (id, instpath)
{
  	if (xmlhttp) {
		url = instpath + "/vote.php";
		content = "id=" + id;
		anonymous_vote = true;

		mnmxmlhttp[id] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[id].send (content);
			errormatch = new RegExp ("^ERROR:");

			target1 = document.getElementById ('vote-' + id);

			mnmPrevColor[id] = target1.style.backgroundColor;
			mnmxmlhttp[id].onreadystatechange = function () {
				if (mnmxmlhttp[id].readyState == 4) {
					mnmString[id] = mnmxmlhttp[id].responseText;
					if (mnmString[id].match (errormatch)) {
						mnmString[id] = mnmString[id].substring (6, mnmString[id].length);
						changemnmvalues (id, true);
					} else {
						changemnmvalues (id, false);
					}
				}
			}
		}
	}
};

function changemnmvalues (id, error)
{
	split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('voted-' + id);
	target2 = document.getElementById ('vote-' + id);
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
	}
	return false;
};


function clk(id)
{
	(new Image()).src="clic.php?id="+id;
	return true;
};

function CheckLen(Target)
{
	StrLen = Target.value.length;
	if ( StrLen>255 ) {
		Target.value = Target.value.substring(0,255);
		CharsLeft = 255;
	} else {
		CharsLeft = StrLen;
	};
	var CharsLeft1 = 255 - CharsLeft;
	document.form2submit.reste.value = CharsLeft1;
};

function confirm_broken( myid, myurl)
{
	confirmation = confirm( "!!! ATTENTION !!!\n\nNe cliquez sur OK que si ce site est inaccessible ou contient du spam :\n\n" + myurl + "\n\n" );
	if(confirmation)
	{
		(new Image()).src = "broken.php?id="+myid;
		alert( "Merci pour votre cooperation !\n\nLe site sera verifie dans les plus brefs delais." );
	};
};

function ac_return(field, item){
        // on met en place l'expression régulière
        var regex = new RegExp('[0123456789]*-mini', 'i');
        // on l'applique au contenu
        var nomimage = regex.exec($(item).innerHTML);
        //on récupère l'id
        id = nomimage[0].replace('-mini', '');
        // et on l'affecte au champ caché
        $(field.name+'_id').value = id;
}