function ouvrir(url)
{
	w = document.body.clientWidth;
	h = document.body.clientHeight;
	var popW = 950, popH = 600;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	window.open(url,'popup','scrollbars=1,width=' + popW + ',height='+popH+',top='+topPos+',left='+leftPos);
}
function bp3_submit(form)
{
	document.getElementById(form).submit();
}

//
// MENU
//
window.onload=montre;
function montre(id)
{
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}

function setClass(objet,dmcNom)
{
	objet.className=dmcNom;
}


//
// GESTION DES COOKIES
//
function EcrireCookie(nom, valeur, expires)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expires);

	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+exdate.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}


//
// CACHE / MONTRE UNE BOITE
//
function cacherBoite(thabox, expires)
{
	var to_expires = expires ? expires : null ; 
	document.getElementById(thabox).style.display="none";
	EcrireCookie(thabox, "non", expires);
}
function montrerBoite(thabox)
{
	document.getElementById(thabox).style.display="block";
	EcrireCookie(thabox, "oui");
}
function changerBoite(thabox)
{
	var showadmin;
	showadmin = LireCookie(thabox);
	if (showadmin == "oui") {
		montrerBoite(thabox);
	} else {
		cacherBoite(thabox);
	}
}
function openwindow(url,w,h)
{
	window.open(url,"bp3","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width="+w+", height="+h);
}


//
// AFFICHE LA DATE ET L'HEURE
//
function date()
{
	var today=new Date();
	var date_heure="";
	D = today.getDate();
	M =	today.getMonth()+1;
	Y = 1900+today.getYear();
	h = today.getHours();
	m = today.getMinutes();
	s = today.getSeconds();
		if(D<10) {D = '0'+D;}
		if(M<10) {M = '0'+M;}
        if(h<10) {h = '0'+h;}
        if(m<10) {m = '0'+m;}
        if(s<10) {s = '0'+s;}
	date_heure = ''+D+'-'+M+'-'+Y+' '+h+'h'+m+'m'+s+'';
	document.getElementById('date').innerHTML = date_heure;
}
// setInterval("date()",1000);


//
// Nettoyage
//

// Callback TinyMce
function mceTagWrap(element_id, html, body) {
 html = trim(html);
  if(html.charAt(0) != "<" || (html.charAt(html.length - 1) != ">" || html.charAt(html.length -2) == "/")) {
	html = "<p>"+html+"</p>";	
  }
 return html;
}
function trim(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );
  return sInString.replace( /\s+$/g, "" );
}

function antiSlash(key)
{
	key = key.replace( /\//g, "" );
	return key;
}


//
// AJAX
//
function callServer(fonction,get)
{
	var http = getHTTPObject();
	var key = document.getElementById(get).value;
	if ((fonction == null) || (get == null) || (key == null) || (key == '')) {
//		var response = '<img src="/public/images/ko.gif" width="15px" height="15px" alt="ko" />';
//		document.getElementById('result_' + get).innerHTML = response;
		return false;
	} else {
		key = encodeURIComponent(antiSlash(key));
		var url = '/ajax/index/' + fonction + '/' + get + '/' + key;
		http.open("GET", url, true);
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				var response = http.responseText;
				dest = 'result_' + get;
				document.getElementById(dest).innerHTML = response;
			}
		}
		http.send(null);
	}
}
function getHTTPObject()
{
  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) {
              alert(xmlhttp.responseText);
           }
        }
     }
  }
  return xmlhttp;
}
function verifIdentique(a,b)
{
	var motsclef1 = document.getElementById(a).value;
	var motsclef2 = document.getElementById(b).value;
	var dest = 'result_' + b;
	var response;
	if ((motsclef1===motsclef2) && (motsclef2.length > 3)) {
		response = '<img src="/public/images/ok.gif" width="15px" height="15px" alt="ok" />';
		document.getElementById(dest).innerHTML = response;
		return true;
	} else {
		response = '<img src="/public/images/ko.gif" width="15px" height="15px" alt="ko" />';
		document.getElementById(dest).innerHTML = response;
		return false;
	}
}


