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(fieldMaxLength)
{
	fieldToCheck = 'description';
	
	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 CheckLen(fieldMinLength, fieldMaxLength)
{
	fieldToCheck = 'description';
	
	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 < fieldMinLength)
				{
					if (StrLen > 1)
					{
						document.forms[i].reste.value = StrLen+' caractères entrés';
					}
					else
					{
						document.forms[i].reste.value = StrLen+' caractère entré';
					}
				}
				else 
				{
					if ( StrLen > fieldMaxLength || StrLen < fieldMinLength)
					{
						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+' caractères restants';
				}
			}
		}
	}
};

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

/*
	** improved version of Ajax.Autocompleter in controls.js of Scriptaculous
	** according to http://tetlaw.id.au/view/blog/adding-a-local-cache-to-ajaxautocompleter/
	*/
Ajax.CachedAutocompleter = Class.create();
Object.extend(Object.extend(Ajax.CachedAutocompleter.prototype, Autocompleter.Base.prototype),
{
	initialize: function(element, update, url, options)
	{
		this.baseInitialize(element, update, options);
		this.options.asynchronous  = true;
		this.options.onComplete    = this.onComplete.bind(this);
		this.options.defaultParams = this.options.parameters || null;
		this.url                   = url;
		this.cache                 = {};
	},
	getUpdatedChoices: function()
	{
		var t = this.getToken();
		if (this.cache[t])
		{
			this.updateChoices(this.cache[t]);
		}
		else
		{
			this.startIndicator();
			entry = encodeURIComponent(this.options.paramName) + '=' + encodeURIComponent(t);
			this.options.parameters = this.options.callback ? this.options.callback(this.element, entry) : entry;
			if (this.options.defaultParams)
			{
				this.options.parameters += '&' + this.options.defaultParams;
			}
			new Ajax.Request(this.url, this.options);
		}
	},
	onComplete: function(request)
	{
		this.updateChoices(this.cache[this.getToken()] = request.responseText);
	}
});

/*
Author   : bieler batiste
Company  : doSimple : http://www.dosimple.ch
send me a mail for more informations : faden@PASDEPOURRIELaltern.org - remove ( PASDEPOURRIEL )

Short javascript function to create and handle a CSS navigation menu

Copyright (C) 2004  Bieler Batiste

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// the timeout for the menu
var timeout = 1000;

// not very clean but simple
// the function can be run in the HTML for faster display
// window.onload=initMenu;

// this fonction apply the CSS style and the event
function initMenu(menuName, classMenuName)
{
    // a test to avoid some browser like IE4, Opera 6, and IE Mac
    if ( browser.isDOM1 
    && !( browser.isMac && browser.isIE ) 
    && !( browser.isOpera && browser.versionMajor < 7 )
    && !( browser.isIE && browser.versionMajor < 5 ) )
    {
        // get some element
        var menu = document.getElementById(menuName); // the root element
        var lis = menu.getElementsByTagName('li'); // all the li
        
        // change the class name of the menu, 
        // it's usefull for compatibility with old browser
        menu.className=classMenuName;
        
        // i am searching for ul element in li element
        for ( var i=0; i<lis.length; i++ )
        {
            // is there a ul element ?
            if ( lis.item(i).getElementsByTagName('ul').length > 0 )
            {        
                // improve IE key navigation
                if ( browser.isIE )
                {
                    addAnEvent(lis.item(i),'keyup',show);
                }
                // link events to list item
                addAnEvent(lis.item(i),'mouseover',show);
                addAnEvent(lis.item(i),'mouseout',timeoutHide);
                addAnEvent(lis.item(i),'blur',timeoutHide);
                addAnEvent(lis.item(i),'focus',show);
                
                // add an id to list item
                lis.item(i).setAttribute( 'id', "li"+i );
				
				hideUlUnderLi(lis.item(i)); // setup submenu class for <a>
            }
        }
    }
}

function addAnEvent( target, eventName, functionName )
{
    // apply the method to IE
    if ( browser.isIE )
    {
        //attachEvent dont work properly with this
        eval('target.on'+eventName+'=functionName');
    }
    // apply the method to DOM compliant browsers
    else
    {
        target.addEventListener( eventName , functionName , true ); // true is important for Opera7
    }
}
    
// hide the first ul element of the current element
function timeoutHide()
{
    // start the timeout
    eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
}

// hide the ul elements under the element identified by id
function hideUlUnder( id )
{   
	var li = document.getElementById(id);
	var uls = li.getElementsByTagName('ul');
	if (uls.length > 0)
	{
		uls[0].style['visibility'] = 'hidden';
		// li.className = "submenu";
		li.getElementsByTagName('a')[0].className = "submenu";
	}
}

// show the first ul element found under this element
function show()
{
    // show the sub menu
	var uls = this.getElementsByTagName('ul');
	if (uls.length > 0)
	{
		uls[0].style['visibility'] = 'visible';
	}
    var currentNode=this;
    while(currentNode)
    {
		if( currentNode.nodeName=='LI')
		{
			currentNode.getElementsByTagName('a')[0].className = 'linkOver';
		}
		currentNode=currentNode.parentNode;
    }
    // clear the timeout
    eval ( "try { clearTimeout( timeout"+ this.id +");} catch (err) { }" );
    hideAllOthersUls( this );
}

// hide all ul on the same level of  this list item
function hideAllOthersUls( currentLi )
{
    var lis = currentLi.parentNode;
    for ( var i=0; i<lis.childNodes.length; i++ )
    {
        if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id )
        {
            hideUlUnderLi( lis.childNodes[i] );
        }
    }
}

// hide all the ul wich are in the li element
function hideUlUnderLi( li )
{
    var uls = li.getElementsByTagName('ul');
	if (uls.length > 0)
	{
		// li.className="submenu";
		for ( var i=0; i<li.childNodes.length; i++ )
		{
			if (li.childNodes[i].nodeName == 'A')
			{
				li.childNodes[i].className="submenu";
			}
			else if (li.childNodes[i].nodeName == 'UL')
			{
				li.childNodes[i].style['visibility'] = 'hidden';
				var lis = li.childNodes[i].getElementsByTagName('li');
				for ( var j=0; j<lis.length; j++ )
				{
					hideUlUnderLi( lis[j] );
				}
			}
		}
	}
} 

// Browser Detect Lite  v2.1.4
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)

function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser name
   this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isMozilla   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
   this.isSafari    = (ua.indexOf('safari') != - 1);
   this.isOpera     = (ua.indexOf('opera') != -1); 
   this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari); 
   this.isIcab      = (ua.indexOf('icab') != -1); 
   this.isAol       = (ua.indexOf('aol') != -1); 
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isNS && this.isGecko) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isOpera) {
      if (ua.indexOf('opera/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
      }
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isIcab) {
      if (ua.indexOf('icab/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
      }
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin   = (ua.indexOf('win') != -1);
   this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac   = (ua.indexOf('mac') != -1);
   this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();

//-->
