var xmlhttp = false;
var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String();

if(window.XMLHttpRequest)
{
	// Firefox   
	xmlhttp = new XMLHttpRequest();   
}
else if(window.ActiveXObject)
{
	// Internet Explorer   
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
}
else
{
	// XMLHttpRequest non supporté par le navigateur
	alert("Your browser doesn't support XMLHTTPRequest Objects");
}

function myXMLHttpRequest ()
{
	var xmlhttplocal;
	if (window.XMLHttpRequest)
	{
		xmlhttplocal = new XMLHttpRequest();

		// Évite un bug du navigateur Safari :
		if (xmlhttplocal.overrideMimeType)
		{
			xmlhttplocal.overrideMimeType("text/xml");
		}
	}
	else
	{
		if (window.ActiveXObject)
		{

			try 
			{
				// essaie de charger l'objet pour IE
				xmlhttplocal = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					// essaie de charger l'objet pour une autre version IE
					xmlhttplocal = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					window.alert("Your browser doesn't support XMLHTTPRequest Objects");
				} // try-catch
			} // try-catch

		}
	} // if-else
	return (xmlhttplocal);
};

function vote (id, instpath)
{
  	if (xmlhttp)
	{
		url = instpath + "/vote.php";
		strContent = new String();
		strContent = 'id=' + id;
		anonymous_vote = true;
		mnmxmlhttp[id] = myXMLHttpRequest ();
		
		if (mnmxmlhttp[id])
		{
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[id].send (strContent);
			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()
{
	fieldToCheck = 'description';
	fieldMaxLength = 4500;
	
	for(var i=0;i < document.forms.length; i++)
	{
		for(j=0;j < document.forms[i].elements.length; j++)
		{
			if(document.forms[i].elements[j].name == fieldToCheck)
			{
				StrLen = document.forms[i].elements[j].value.length;
				if ( StrLen > fieldMaxLength )
				{
					document.forms[i].elements[j].value = document.forms[i].elements[j].value.substring(0,fieldMaxLength);
					CharsLeft = fieldMaxLength;
				} else {
					CharsLeft = StrLen;
				};
				var CharsLeft1 = fieldMaxLength - CharsLeft;
				
				// Updating reste field
				document.forms[i].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 vérifié dans les plus brefs délais." );
	};
};

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;
}


function multiClass(eltId) {
	arrLinkId = new Array('l_0','l_1','l_2','l_3');
	intNbLinkElt = new Number(arrLinkId.length);
	arrClassLink = new Array('current','ghost');
	strContent = new String();
	for (i=0; i<intNbLinkElt; i++) {
		strContent = "menu"+arrLinkId[i];
		if ( arrLinkId[i] == eltId ) {
			document.getElementById(arrLinkId[i]).className = arrClassLink[0];
			document.getElementById(strContent).className = 'on content';
		} else {
			document.getElementById(arrLinkId[i]).className = arrClassLink[1];
			document.getElementById(strContent).className = 'off content';
		}
	}	
}

function tS(){
    x=new Date();
    x.setTime(x.getTime());
    return x;
}
function lZ(x){
    return (x>9)?x:'0'+x;
}
function dT(){
    if(fr==0){
        fr=1;
        document.write(" " + '<span id="tP">'+eval(oT)+'</span>');
    }
    document.getElementById("tP").innerHTML =  eval(oT);
    setTimeout('dT()',1000);
}
var fr=0;
oT="tS().getHours()+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())";


function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->