var lang = "en";// Encodé en UTF-8
function confirmer($url, $msg)
{
	if (confirm($msg))
	{
	location.href = $url;
	}
}

function getHTTPObject(myField, myAdd, myDel, orderby, myList, myCote)	{
	var xmlhttp = false;
  /*@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;
     }
  }

  if (xmlhttp)	{
     xmlhttp.onreadystatechange=function()	{
        if (xmlhttp.readyState == 4)	{
           if (xmlhttp.status == 200)	{
              if (myField)	{
				getOptions(xmlhttp.responseText, myField);
				}
			  else if (myAdd)	{
			  	ajaxCat(xmlhttp.responseText, myAdd, orderby);
				}
			  else if (myDel)	{
			  	ajaxCat('', myDel, orderby);
				}
			  else if (myList)	{
			  	getList(xmlhttp.responseText, myList);
				}
			  else if (myCote)	{
			  	displayCote(xmlhttp.responseText, myCote);
				}
           }
        }
     }
  }
  return xmlhttp;
}

function ajaxListCat(scat, field, orderby, smod)	{
	stamp = new Date();
	cats = new Array;
	if (scat) cats = scat;
	else	{
		currentdiv = (document.getElementById('div'+field))  ? document.getElementById('div'+field).getElementsByTagName('input') : null;
		for (var i in currentdiv)	{
			if (currentdiv[i].checked && currentdiv[i].name == 'speakers[]')	{
				cats[currentdiv[i].value] = currentdiv[i].value;
				}
			}
		}
		
		
	if (smod) mods = smod;
	else	{
		currentdiv = (document.getElementById('div'+field))  ? document.getElementById('div'+field).getElementsByTagName('input') : null;
		for (var i in currentdiv)	{
			if (currentdiv[i].checked && currentdiv[i].name == 'moderator-'+currentdiv[i].value)	{
				mods[currentdiv[i].value] = currentdiv[i].value;
				}
			}
		}
		
	typesvar = '?type=' + field;
	for (i = 0; i < cats.length; i++) typesvar += '&cat[]=' + escape(cats[i]);
	for (i = 0; i < mods.length; i++) typesvar += '&mod[]=' + escape(mods[i]);
	typesvar += '&orderby=' + orderby + '&time=' + stamp;

	var xmlhttp = new getHTTPObject(false, false, false, false, field);
	xmlhttp.open("GET", "/js/speakers.php"+typesvar, true); 
	xmlhttp.send(null);
	}
	
function getList(result, field) {
	myArray = eval(result);
	
	if (document.getElementById('div'+field))	{
		cible = document.getElementById('div'+field);
		
		while (cible.firstChild)	{
			cible.removeChild(cible.firstChild);
			};
		
		// document.getElementById('div'+field).innerHTML = '';
		var output = '';
	
		for(i = 0; i < myArray.length; i++) {

			newli = document.createElement("li");

			newinput = document.createElement("input");
			newinput.setAttribute('type', 'checkbox');
			newinput.setAttribute('name', field+'[]');
			newinput.setAttribute('id', field+myArray[i][0]);
			newinput.value = myArray[i][0];
			
			newlabel = document.createElement("label");
			newlabel.setAttribute('for',field+myArray[i][0]);
			newtext = document.createTextNode(myArray[i][1]);
			newlabel.appendChild(newtext);

			newa = document.createElement("a");
			newa.setAttribute('onclick', 'launchLight(\'../'+field+'/edit.php?inpopup=true&id='+myArray[i][0]+'\', \'Edit this '+ field+'\', 700, 450); return false;');
			// IE only
			if (document.all)	{
				newa.i = i; newa.onclick = function() { launchLight('../'+field+'/edit.php?inpopup=true&id='+myArray[this.i][0], 'Edit this '+ field, 700, 450); return false; };
				}
			newa.setAttribute('href', '#');
			newtext = document.createTextNode("Edit");
			newa.appendChild(newtext);
		
			//space = document.createTextNode(" ");
		
			newinputmod = document.createElement("input");
			newinputmod.setAttribute('type', 'checkbox');
			newinputmod.setAttribute('name', 'moderator-'+myArray[i][0]);
			newinputmod.setAttribute('id', 'moderator-'+myArray[i][0]);
			newinputmod.value = myArray[i][0];
		
			newlabelmod = document.createElement("label");
			newlabelmod.setAttribute('for','moderator-'+myArray[i][0]);
			newtextmod = document.createTextNode("Moderator/Initiator ?");
			newlabelmod.appendChild(newtextmod);
			
			
			newli.appendChild(newinput);
			space = document.createTextNode(" ");
			newli.appendChild(space);
			newli.appendChild(newlabel);
			space = document.createTextNode(" ");
			newli.appendChild(space);
			newli.appendChild(newa);
			space = document.createTextNode(" | ");
			newli.appendChild(space);
			newli.appendChild(newlabelmod);
			space = document.createTextNode(" ");
			newli.appendChild(space);
			newli.appendChild(newinputmod);
			cible.appendChild(newli);

			if (myArray[i][2] == true) document.getElementById(field+myArray[i][0]).checked = true;
			if (myArray[i][3] == true) document.getElementById('moderator-'+myArray[i][0]).checked = true;
			}
			
	//	output += '<li><input type="checkbox" class="checkbox" name="'+field+'[]" id="'+field+myArray[i][0]+'" value="'+myArray[i][0]+'"';
	//	if (myArray[i][2] == true) output += ' checked="checked"';
	//		output += ' /> <a onclick="launchLight(\'../'+field+'/edit.php?id='+myArray[i][0]+'\', \'Édition d\\\'un '+ field+'\'); return false;" href="#">'+myArray[i][1]+'</a></li>';
	//		}
		// document.getElementById('div'+field).innerHTML = output;
		}
	}
	
function launchLight(href, title, boxwidth, boxheight)	{
	urlObject = new Object();
	urlObject.href = href;
	urlObject.type = 'external';
	urlObject.width = boxwidth;
	urlObject.height = boxheight;
	urlObject.title = title;
	myLightWindow.activateWindow(urlObject);
	}	
	
function modifChamp()	{
	var obj = document.getElementById("q-search")
	obj.value = "";
	}