


// --------------------------------------------------------
function getFormValues(form_name) // name of Form
{
	var params = '';

	var form_elt;
	var key;
	var val;

	for (var i=0; i<document.forms[form_name].elements.length; i++) {
	//for (var i=0; i<document.getElementById(form_name).elements.length; i++) {
		form_elt = document.forms[form_name].elements[i];
		//form_elt = document.getElementById(form_name).elements[i];
		key = form_elt.name;
		if (key) {
			val = getFormElementValue(form_elt);
			nam = getFormElementName(form_elt);
			params += key + '=' + encodeURI(val) + '&';
			if (nam) params += key + '_name=' + encodeURI(nam) + '&';
		}
	}

	return params;
}

function getFormValues1(form_name) // name of Form
{
	var params = '';

	var form_elt;
	var key;
	var val;

	for (var i=0; i<document.forms[form_name].elements.length; i++) {
	//for (var i=0; i<document.getElementById(form_name).elements.length; i++) {
		form_elt = document.forms[form_name].elements[i];
		//form_elt = document.getElementById(form_name).elements[i];

		key = form_elt.name;
		if (key) {
			val = getFormElementValue(form_elt);
			nam = getFormElementName(form_elt);
			if (val) {
				params += key + '=' + encodeURIComponent(val) + '&';
			}
			if (nam)
				if (key.match("\\[")) params += key.replace("\[","_name\[") + '=' + encodeURI(nam) + '&';
				else params += key + '_name=' + encodeURIComponent(nam) + '&';
		}
	}

	return params;
}

// --------------------------------------------------------
function getFormValuesWithEmptyValues(form_name) // name of Form
{
	var params = '';

	var form_elt;
	var key;
	var val;

  count_element = document.forms[form_name].elements.length;
  
	for (var i=0; i<count_element; i++) {
	//for (var i=0; i<document.getElementById(form_name).elements.length; i++) {
		form_elt = document.forms[form_name].elements[i];
		//form_elt = document.getElementById(form_name).elements[i];

		key = form_elt.name;
		if (key) {
			val = getFormElementValue(form_elt);
			nam = getFormElementName(form_elt);
			

			if ((form_elt.type != 'file' && form_elt.type != 'radio') || val)
				params += key + '=' + encodeURIComponent(val) + '&';

			if (nam)
				if (key.match("\\[")) params += key.replace("\[","_name\[") + '=' + encodeURI(nam) + '&';
				else params += key + '_name=' + encodeURIComponent(nam) + '&';
		}
	}

	return params;
}

// --------------------------------------------------------
function getFormElementName(form_elt) // Element Object
{
	var elt_val;

	switch (form_elt.type) {
		case "hidden":
		case "text":
		case "textarea":
		case "password":
		case "checkbox":
		case "radio":
			break;
		case "select-one":
			elt_val = form_elt.options[form_elt.selectedIndex].text;
			break;
	}

	return elt_val;
}

// --------------------------------------------------------
function getFormElementValue(form_elt) // Element Object
{
	var elt_val;

	switch (form_elt.type) {
		case "hidden":
		case "text":
		case "textarea":
		case "password":
			if (!elt_val) {
				elt_val = form_elt.value;
			}
			break;
		case "checkbox":
		case "radio":
			if (form_elt.checked == true) {
				elt_val = form_elt.value;
			}
			break;
		case "select-one":
			elt_val = form_elt.options[form_elt.selectedIndex].value;
			break;
	}

	return elt_val;
}

// --------------------------------------------------------
function getElementsByClassName(needle) {
   var my_array = document.getElementsByTagName("*");
   var retvalue = new Array();
   var i;
   var j;

   for (i=0,j=0;i<my_array.length;i++) {
      var c = " " + my_array[i].className + " ";
      if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
   }
   return retvalue;
} 


// --------------------------------------------------------
function loadSecteur(theme_id, field_name)
{
	params  = "theme_id="+theme_id;
	params += '&task=loadSecteur';
	//alert(params);
	new Ajax.Request('/lib/Ajax/ajax.select.update.php', {method:'post', postBody:params, parameters:fn=field_name, onSuccess:responseLoadSecteur});
}

// ----------------------------------------------

function stuffGetOptions(divElement,table,options) {
	options.name = options.name || divElement;
	var params = 'task=getOptions&table='+table+'&'+hash2query(options);
	new Ajax.Updater(divElement,'/lib/Ajax/ajax.stuff.php',{method:'post',postBody:params});
}

// Convert hash to QUERY_STRING.
function hash2query(content, prefix) {
    if (prefix == null) prefix = "";
    var query = [];
    if (content instanceof Object) {
        for (var k in content) {
            var v = content[k];
            if (v == null || ((v.constructor||{}).prototype||{})[k]) continue;
            var curPrefix = prefix? prefix+'['+encodeURIComponent(k)+']' : encodeURIComponent(k);
            if (v instanceof Object)
                query[query.length] = hash2query(v, curPrefix);
            else
                query[query.length] = curPrefix + "=" + encodeURIComponent(v);
        }
    } else {
        query = [content];
    }
    return query.join('&');
}

// Cross-browser addEventListener()/attachEvent() replacement.
function addEvent(elt, name, handler, atEnd) {
  name = name.replace(/^(on)?/, 'on');
  var prev = elt[name];
  var tmp = '__tmp';
  elt[name] = function(e) {
    if (!e) e = window.event;
    var result;
    if (!atEnd) {
      elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null; // delete() does not work in IE 5.0 (???!!!)
      if (result === false) return result;
    }
    if (prev) {
      elt[tmp] = prev; result = elt[tmp](e); elt[tmp] = null;
    }
    if (atEnd && result !== false) {
      elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null;
    }
    return result;
  }
  return handler;
}

// ----------------------------------------------

function responseLoadSecteur(t)
{
	var repObj = eval('(' + t.responseText + ')');
	//alert(t.responseText);

	var key;
	var val;

	form_elt = document.forms['registerform'].theme_secteur_id;
	form_elt.options.length = 0;
	form_elt.options[0] = new Option('--- Choose ---', '');
	num = 1;
	for (i in repObj) {
		if (typeof(repObj[i]) != 'function') {
			key = repObj[i]['theme_secteur_id'];
			val = repObj[i]['theme_secteur_name'];
			form_elt.options[num++] = new Option(val, key);
		}
	}
}

function loginInputKeypress()
{

	if(window.event.keyCode == 13)
	{
		doCheckLoginForm();
	}
}

var wasChecking = 0;

// -----------------------------------------------

function doCheckLoginForm() {
	if (wasChecking) {return;}		
	wasChecking++;

	var error = $('login_error');
	error.innerHTML = 'Veuillez patienter...';
	error.showed = true;

	$('login_error_animate').style.display = "block";

	var form = document.getElementById('loginform');
	params = getFormValues('loginform');
	params += 'action=checkForm';
	new Ajax.Request('/lib/Ajax/ajax.expert.php', {method:'post', postBody:params, onSuccess:doCheckHandler_});
	//new Ajax.Updater('debug', '/lib/Ajax/ajax.client.php', {method:'post', postBody:params});
}

// -----------------------------------------------
function doCheckHandler_(t)
{
	if (t.responseText != 'expert' && t.responseText != 'client') {
		var error = $('login_error');
		error.innerHTML = t.responseText;
		if(!error.showed) {
			error.showed = true;
			$('login_error_animate').style.display = "block";
		}
		else {

		}
		//Effect.Shake('login_error_animate');
		wasChecking = 0;
	}
	else {
		url = document.getElementById('loginform').url.value;
		if (url) document.location.href = url;
		else document.location.href = "/" + t.responseText + "_tableau.php";
	}
}

// -----------------------------------------------
function runScript(content)
{
	var exp = new RegExp("<script[^>]*>(.*)<\/script>");
	var m = String(content).match(exp);

	if(m) {
		for(i = 1; i < m.length; i++) {
			eval('with(window){'+m[i]+'}');
		}
	}
}

// -----------------------------------------------
function getMouseXY2() {alert(event);
  e = window.event;
  if (document.all) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  return { x: tempX, y: tempY };
}

var infoPopup = null;

// -----------------------------------------------
function showInfoPopup(title,name,className,width,height,observer)
{
	if(infoPopup) {
		infoPopup.destroy();
	}

	infoPopup = new Window(
		'infoPopup', {
			className: className || "pheadline",
//			width: width || 1,
//			height: height || 1,
			width: width,
			height: height,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: title
		}
	);

	Windows.addObserver({
		onClose: function(e,w) {
			if(w == infoPopup) { infoPopup = null; }
		}
	});

	if(observer) {
		Windows.addObserver(observer);
	}

	if(!width || !height) {
		Windows.addObserver({
			onShow: function(e,w) {
				if(w == infoPopup) {
					if(!width) w.updateWidth();
					if(!height) w.updateHeight();
				}
			}
		});
	}

	infoPopup.setDestroyOnClose();

	infoPopup.setAjaxContent('/lib/Ajax/ajax.info.php', {
		method: 'post',
		postBody: 'get='+name
	},true);

	//document.location.href = '#top';

}

// -----------------------------------------------
function changeImage(img,act,src) {

	if(typeof(img.initialized) == "undefined") {
		img.state = 0;

		if(typeof(src) == "undefined") {
			img.oldSrc = img.src;
		}

		img.initialized = true;
	}

	if(img.state == 0) {
		img.src = act;
		img.state = 1;
	}
	else {
		if(typeof(src) == "undefined") {
			src = img.oldSrc;
		}

		img.src = src;
		img.state = 0;
	}

}

// -----------------------------------------------

var loginPopup = null;
var loginPopupUrl = null;
var loginPopupOkFunc = function() {

	var login = encodeURIComponent($('loginField').value);
	var password = encodeURIComponent($('passwordField').value);

	new Ajax.Request('/lib/Ajax/ajax.expert.php', {
		method: 'post',
		postBody: 'action=checkForm&login='+login+'&password='+password,

		onSuccess: function(req) {
			if(req.responseText != 'expert' && req.responseText != 'client') {
				$('login_error_msg').innerHTML = req.responseText;
				$('login_error_msg').show();
				Dialog.win.updateHeight();
				new Effect.Shake('modal_dialog');
				return false;
			}
			else {
				if(loginPopupUrl) document.location.href = loginPopupUrl;
				else document.location.href = "/" + req.responseText + "_tableau.php";
			}

		}
	});

	return false;
};

function showLoginPopup(url) {
	if(typeof(url) == "undefined") {
		loginPopupUrl = $('request_uri').value;
	}
	else {
		loginPopupUrl = url;
	}

	Dialog.confirm($('loginFormDiv').innerHTML, {
		windowParameters: {
			className: "alphacube",
			width: 300,
			showEffect: function(e) { Element.show(e); setTimeout(function(){$('loginField').focus()},100) },
			hideEffect: Element.hide
		},

		okLabel: "Valider",
		cancelLabel: "Annuler",

		ok: loginPopupOkFunc
	});

}

/**
 * Validates the num field
 */
function validateNumberField(field) {
	field.value = field.value.replace(/[^0-9]/,"");
}
/* alias: */
function vnf(f) { return validateNumberField(f) }

function permDenided(go) {

	Dialog.alert("You don`t have permissions to this page", {
		windowParameters: {
			width:300,
			height:90,
			showEffect: Element.show,
			hideEffect: Element.hide
		},

		okLabel: "close",
		ok: ( go ? function() {
			history.go(-1);
		} : go )
	});

}

// -----------------------------------------------

function handleEnter(e,func) {
	/*var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) { return func(); }
	return false;*/
	var characterCode;

	if(e && e.which){
		e = e;
		characterCode = e.which;
	}
	else{
		e = event;
		characterCode = e.keyCode;
	}

	if(characterCode == 13) {
		func();
	}

	return false;
}

// -----------------------------------------------

var questionInfo = null;

function showQuestionInfo(name,qid) {

	if(!questionInfo) {
		questionInfo = new Window(
			'questionInfo', {
				className: 'pheadline',
				minHeight: 440,
				minWidth: 400,
				top: 190,
				left: 600,
				zIndex: 150,
				showEffect: Element.show,
				hideEffect: Element.hide,
				minimizable: false,
				maximizable: false,
				resizable: true,
				runInlineScripts: true,
				title: name
			}
		);

		var myObserver = {
			onShow: function() {
				w.updateWidth();
				w.updateHeight();
			}
		}

//		Windows.addObserver(myObserver);
	}

	questionInfo.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=showQuestionInfo&qid='+qid
	},true);

	//document.location.href = '#top';

	//w.show();
}


// Evaluation

ev = null;

function ShowClientExpertEval(name,id,template) {

	if(ev) ev.destroy();

	ev = new Window(
		'eval_window', {
			className: template || 'pexpert',
			minHeight: 200,
			minWidth: 250,
			height: 250,
			width: 280,
			top: 200,
			left: 400,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		onClose: function(e,w) {
			if(w == ev) ev = null;
		},
		onShow: function(e,w) {
			if(w == ev) ev.setZIndex(Windows.maxZIndex + 20);
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=ShowClientExpertEval&id='+id
	},true);

	//ev.toFront();

}

function ShowExpertClientEval(name,id,template) {

	if(ev) ev.destroy();

	ev = new Window(
		'eval_window', {
			className: template || 'pclient',
			minHeight: 200,
			minWidth: 250,
			height: 250,
			width: 280,
			top: 200,
			left: 400,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=ShowExpertClientEval&id='+id
	},true);
}

function ShowExpertInfo(name,id) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			minHeight: 440,
			minWidth: 400,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=showExpertInfo&id='+id
	},true);

	//document.location.href = '#top';
}

function HideExpertInfo(name,id) {
	ev.hide();
}

//--------inscription popups-----------
function ShowExpertInscription(name) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 370,
			minHeight: 370,
			minWidth: 185,
			width: 185,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

	//ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
	//	method: 'post',
	//	postBody: 'task=showExpertInscription'
	//},true);

	ev.getContent().innerHTML = $("expertInscription").innerHTML;
	ev.showCenter();

	//document.location.href = '#top';
}

function HideExpertInscription(name) {
	ev.hide();
}

function ShowClientInscription(name) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 320,
			minHeight: 320,
			minWidth: 185,
			width: 185,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

//	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
//		method: 'post',
//		postBody: 'task=showClientInscription'
//	},true);

	ev.getContent().innerHTML = $("clientInscription").innerHTML;
	ev.showCenter();

	//document.location.href = '#top';
}

function HideClientInscription(name) {
	ev.hide();
}

function showPartners()
{
	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 450,
			minHeight: 0,
			minWidth: 270,
			width: 650,
			top: 150,
			left: 300,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

//	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
//		method: 'post',
//		postBody: 'task=showPartners'
//	},true);

	ev.getContent().innerHTML = $("partnersDuGroupe").innerHTML;
	ev.showCenter();

}

function ShowBothInscription(name) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 370,
			minHeight: 384,
			minWidth: 270,
			width: 280,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

//	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
//		method: 'post',
//		postBody: 'task=showClientInscription'
//	},true);

	ev.getContent().innerHTML = $("bothInscription").innerHTML;
	ev.showCenter();

	//document.location.href = '#top';
}

function HideBothInscription(name) {
	ev.hide();
}

function showMagCGU()
{
	if (ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 450,
			minHeight: 0,
			minWidth: 270,
			width: 580,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

//	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
//		method: 'post',
//		postBody: 'task=showMagCGU'
//	},true);

	ev.getContent().innerHTML = $("MagCGU").innerHTML;
	ev.showCenter();

}

//-------------------------------------

var wasConfirm = false;


function HideEnterConfirm(name) {
	ev.hide();
	location.href = "/index.php";
}

function ShowEnterConfirm(name) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'alphacube',
			//className: 'info',
			Height: 260,
			minHeight: 260,
			minWidth: 366,
			width: 366,
			top: 200,
			left: 300,
			zIndex: 150,
			//showEffect: Effect.Appear,
			showEffect : function(e) { Element.show(e); },
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			ev = null;
			location.href = "/index.php";
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

//	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
//		method: 'post',
//		postBody: 'task=showClientInscription'
//	},true);
	ev.getContent().innerHTML = $("enterConfirm").innerHTML;
	ev.showCenter(true);

	//document.location.href = '#top';
}

//-------------------------------------
//--------error message popups-----------
var errmes = null;

function ShowErrorMessage(name) {

	if(errmes) errmes.destroy();

	errmes = new Window(
		'window', {
			className: 'info',
			height: 75,
			minHeight: 75,
			minWidth: 300,
			width: 300,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		/*onShow: function() {
			w.updateWidth();
			//w.updateHeight();
		},*/
		onClose: function() {
			errmes = null;
		}
	}

	Windows.addObserver(myObserver);
	errmes.setDestroyOnClose();

	//ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
	//	method: 'post',
	//	postBody: 'task=showExpertInscription'
	//},true);

	errmes.getContent().innerHTML = $("errorMessage").innerHTML;
	errmes.showCenter();

	//document.location.href = '#top';
}

function HideErrorMessage(name) {
	errmes.hide();
	errmes = null;
}

//-------------------------------------

//--------Miss Bank message popups-----------
var bankmes = null;

function ShowBankMessage(name) {


	if(bankmes)
	{
	 bankmes.destroy();
	}

	bankmes = new Window(
		'window', {
			className: 'info',
			height: 115,
			minHeight: 115,
			minWidth: 350,
			width: 350,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {

		onShow: function(e,w) {
			if(w == bankmes) { bankmes.setZIndex(Windows.maxZIndex + 20); }
		},

		onClose: function(e,w) {
			if (w == bankmes)
			{
				bankmes = null;
			}
		}
	}

	Windows.addObserver(myObserver);
	bankmes.setDestroyOnClose();

	bankmes.getContent().innerHTML = $("bankMessage").innerHTML;
	bankmes.showCenter();

	//document.location.href = '#top';
}

function HideBankMessage(name) {
	//bankmes.hide();
	bankmes.destroy();
	bankmes = null;
}

//-------------------------------------------

//--------Chat message popups-----------
var chatmes = null;

function ShowChatMessage(name) {

	if(chatmes)
	{
	 chatmes.destroy();
	}

	chatmes = new Window(
		'window', {
			className: 'info',
			height: 50,
			minHeight: 50,
			minWidth: 350,
			width: 350,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {

		onShow: function(e,w) {
			if(w == chatmes) { chatmes.setZIndex(Windows.maxZIndex + 20); }
		},

		onClose: function(e,w) {
			if (w == chatmes)
			{
				chatmes = null;
			}
		}
	}

	Windows.addObserver(myObserver);
	chatmes.setDestroyOnClose();

	chatmes.getContent().innerHTML = $("chatConfirm").innerHTML;
	chatmes.showCenter();

	//document.location.href = '#top';
}

function HideChatMessage(name) {
	//bankmes.hide();
	chatmes.destroy();
	chatmes = null;
}

//-------------------------------------------

function showBlock(name) {
	$(name).style.display = 'block';
}

function hideBlock(name) {
	$(name).style.display = 'none';
}

function shBlock(name, pre) {
	if ($(name).style.display == 'block')
	{
		$(name).style.display = 'none';
		$(pre + '_' + name + '_icon').src = '/img/' + pre + '-plus.gif';
	}
	else {
		$(name).style.display = 'block';
		$(pre + '_' + name + '_icon').src = '/img/' + pre + '-minus.gif';
	}
}

function showSearchBlock(name, name_img)
{
	showBlock(name_img + '0');
	hideBlock(name_img + '1');
// 	Effect.SlideDown(name);
	showBlock(name);
}

function hideSearchBlock(name, name_img)
{
	showBlock(name_img + '1');
	hideBlock(name_img + '0');
// 	Effect.SlideUp(name);
	hideBlock(name);
}

chToolbarMenu_cur = null;
function chToolbarMenu(obj,unsel) {
   var m = String(obj.className).match(/^([^\-]+)(-sel)?$/);
	if(!m[0]) return;
	var className = m[1];
	if(m[2]) {
		if(unsel) {
			obj.className = className;
			$('toolbar_content').innerHTML = "Veuillez attendre...";
		}
		return;
	}
	if(chToolbarMenu_cur) {
		chToolbarMenu(chToolbarMenu_cur,true);
		chToolbarMenu_cur = null;
	}
	obj.className = className+"-sel";
	chToolbarMenu_cur = obj;
	$('toolbar').className = className;
}

setInterval(function(){
	new Ajax.Request("/lib/Ajax/ajax.common.php",{
		'method': 'post',
		'postBody': 'task=noop'
	})
},10*60*100); /* 10 minutes / 10 */


function sendEnterConfirm()
{

	params = 'task=sendEnterConfirm&';
	params += 'value=1&';

	new Ajax.Request('/lib/Ajax/ajax.common.php', {method:'post', postBody:params, onSuccess: function(request){sendEnterConfirmResponse(request)}});
}

function sendEnterConfirmResponse(req)
{
	HideEnterConfirm('www');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popChat(user_id)
{
	var url="/chat.php?action=select&user_id="+user_id;
	MM_openBrWindow(url,'','status=no,toolbar=no,scrollbars=yes,resizable=no,width=700,height=620');
}

function popChatLogin()
{
	var url="/chat.php?action=login";
	MM_openBrWindow(url,'','status=no,toolbar=no,scrollbars=yes,resizable=no,width=700,height=620');
}

function onImageLoad(tImg)
{
	var rtio = 1;
	var w = tImg.width;
	var h = tImg.height;
	var origW = 150;
	var origH = 150;

	if ( (w >= h) && (w > origW) )
	{

		rtio = (w / origW);

		w = tImg.width = origW;
		h = tImg.height = h / rtio;

	}

	if ( (h > w) && (h > origH) )
	{

		rtio = (h / origH);

		h = tImg.height = origH;
		w = tImg.width = w / rtio;
	}

	if ( w > origW )
	{

		rtio = (w / origW);

		w = tImg.width = origW;
		h = tImg.height = h / rtio;

	}

	if ( h > origH )
	{

		rtio = (h / origH);

		h = tImg.height = origH;
		w = tImg.width = w / rtio;
	}

}

function setAction(f, ActionValue)
{
	for (var i=0; i < f.attributes.length; i++)
	{
	  if (f.attributes[i].nodeName == 'action')
	  {
	    f.attributes[i].nodeValue = ActionValue;
	    break;
	  }
	}
}

function getAction(f)
{
	for (var i=0; i < f.attributes.length; i++)
	{
	  if (f.attributes[i].nodeName == 'action')
	  {
	    return f.attributes[i].nodeValue;
	    break;
	  }
	}
}


function ShowFilterForm(phpself) {

	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 170,
			minHeight: 0,
			minWidth: 270,
			width: 280,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: name
		}
	);

	var myObserver = {
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

	ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=showFilterForm&phpself='+phpself
	},true);

	ev.getContent().innerHTML = $("bothInscription").innerHTML;
	ev.showCenter();

	//document.location.href = '#top';
}

/*
function filter(path) {
  	params = 'task=addFilter&ville='+$('ville').value+'&departement='+$('departement').value;
	new Ajax.Request('/lib/Ajax/ajax.common.php', {method:'post', postBody:params, onSuccess: document.location.href=path});
}
function clearFilter(path) {
	params = 'task=clearFilter';
	new Ajax.Request('/lib/Ajax/ajax.common.php', {method:'post', postBody:params, onSuccess: document.location.href=path});
}
*/

function selectVilleList(code,ville) {
  	params = 'task=selectVille&code='+code;
   if (ville) {params +="&ville="+ville;}
  	new Ajax.Updater('villeList', '/lib/Ajax/ajax.annuaire.php', {method:'post', postBody:params});
}

function popupSelectSecter() {
	if(ev) ev.destroy();

	ev = new Window(
		'window', {
			className: 'info',
			height: 100,
			minHeight: 80,
			minWidth: 270,
			width: 380,
			top: 200,
			left: 300,
			zIndex: 150,
			showEffect: Effect.Appear,
			hideEffect: Effect.Fade,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: "Select Secteur"
		}
	);

	var myObserver = {
		onClose: function() {
			ev = null;
		}
	}

	Windows.addObserver(myObserver);
	ev.setDestroyOnClose();

   ev.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=showSelectSecteur'
	},true);

	ev.getContent().innerHTML = $("bothInscription").innerHTML;
	ev.showCenter();

}

function changeThemeList1(id) {
	params = 'action=themeList1&id='+id;
	new Ajax.Updater('theme_secteur_id1','/lib/Ajax/ajax.theme.php', {method:'post', postBody:params});
}

function selectThemeList1() {

   if (!$('secteur2').innerHTML) {
      $('secteur2').innerHTML = "<div style=\"border-bottom: 1px solid #5682b4;padding: 0px 0px 3px 0px;\">Secteur d’activité concerné<font style=\"font-weight: bold; margin-left: 100px;\">"+$('secteur_id1')[$('secteur_id1').selectedIndex].text+"</font></div><div style=\"border-bottom: 1px solid #5682b4;padding: 5px 0px 3px 0px;\">Domaine d’expertise concerné <b>"+$('theme_id1')[$('theme_id1').selectedIndex].text+"</b></div>";
   }
}

var helpPopup = null;

function questionPopup(title) {
	if(helpPopup) {
		helpPopup.destroy();
	}

	helpPopup = new Window(
		'client_window', {
			className: 'pclient',
			width: 500,
			height: 600,
			top: 175,
			left: 300,
			zIndex: 999,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: title
		}
	);

	var onCloseObserver = {
		onClose: function() {
			helpPopup = null;
		}
	}

	Windows.addObserver(onCloseObserver);

	helpPopup.setDestroyOnClose();

	helpPopup.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=questionPoses'
	},true);

}
function ShowHelpPopup(title) {
	if(helpPopup) {
		helpPopup.destroy();
	}

	helpPopup = new Window(
		'client_window', {
			className: 'pclient',
			width: 500,
			height: 200,
			top: 175,
			left: 300,
			zIndex: 999,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: true,
			runInlineScripts: true,
			title: ""
		}
	);

	var onCloseObserver = {
		onClose: function() {
			helpPopup = null;
		}
	}

	Windows.addObserver(onCloseObserver);

	helpPopup.setDestroyOnClose();

	helpPopup.setAjaxContent('/lib/Ajax/ajax.common.php', {
		method: 'post',
		postBody: 'task=helpContent&name='+title
	},true);

}

function checkPaymentForm(step) {
	params = 'task=checkPaymentForm&' + getFormValues("payment_form") + '&step=' + step;
 	new Ajax.Request('/lib/Ajax/ajax.pay.php', {method:'post', postBody:params, onSuccess: function(request){eval(request.responseText)}});

}


function changeVille(code) {
	params = 'task=updateVille&code='+code;	
 	new Ajax.Request('/lib/Ajax/ajax.stuff.php', {method:'post', postBody:params, onSuccess: function(request){$('ville').innerHTML = request.responseText}});	
}

function setDepartament(thisObj) {	
	code = thisObj.value.substr(0,2);
	params = 'task=departament&code='+code;			
 	new Ajax.Request('/lib/Ajax/ajax.stuff.php', {method:'post', postBody:params, onSuccess: function(request){$('departament').value = request.responseText}});	
}