/*
 * @include "/searchfood/web/js/lib/prototype.js" @include
 * "/searchfood/web/js/lib/scriptaculous.js" @include
 * "/searchfood/web/js/lib/builder.js" @include
 * "/searchfood/web/js/lib/controls.js" @include
 * "/searchfood/web/js/jquery.js" @include
 * "/searchfood/web/js/lib/effects.js" @include
 * "/searchfood/web/js/lib/sound.js" @include "/searchfood/web/js/lib/slider.js"
 * @include "/searchfood/web/js/lib/dragdrop.js"
 */

var EMPTY = 0, EMAIL = 1, PASSWORD = 2, DATE = 3, CHECKED = 4, TEXTSIZE = 5, INTVAL = 6, FLOATVAL = 7;



function IsNumeric(strString)
// check for valid numeric strings
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0)
		return false;

	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function isInteger(s) {
	var i;

	if (isEmpty(s))
		if (isInteger.arguments.length == 1)
			return 0;
		else
			return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);

		if (!isDigit(c))
			return false;
	}

	return true;
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

function isDigit(c) {
	return ((c >= "0") && (c <= "9"))
}

function showHideDiv(id) {

	if ($(id).style.display == "none") {
		$(id).show();
	} else {
		$(id).hide();
	}
}

Date.prototype.toDDMMYYYYString = function() {
	return isNaN(this) ? 'NaN' : [
			this.getDate() > 9 ? this.getDate() : '0' + this.getDate(),
			this.getMonth() > 8 ? this.getMonth() + 1
					: '0' + (this.getMonth() + 1), this.getFullYear() ]
			.join('/');
}

Date.fromDDMMYYYY = function(s) {
	return (/^(\d\d?)\D(\d\d?)\D(\d{4})$/).test(s) ? new Date(RegExp.$3,
			RegExp.$2 - 1, RegExp.$1) : new Date(s);
}
Date.testfromDDMMYYYY = function(s) {
	return (/^(\d\d?)\D(\d\d?)\D(\d{4})$/).test(s) ? true : false;
}
function checkDateInterval(startdate, enddate) {
	var start = Date.fromDDMMYYYY(startdate);
	var end = Date.fromDDMMYYYY(enddate);
	if (end > start) {
		return true;
	} else {
		return false;
	}
}

function checkDateTimeInterval(startdate, starthour, startmin, enddate,
		endhour, endmin) {
	var start = Date.fromDDMMYYYY(startdate);
	var end = Date.fromDDMMYYYY(enddate);

	if (end > start) {
		return true;

	} else if (end < start) {
		return false;
	} else {

		if (Number(endhour) > Number(starthour)
				|| (Number(endhour) == Number(starthour) && Number(endmin) > Number(startmin))) {

			return true;
		}
	}
}

function addMinutes(date, addMin) {
	var now = new Date();

	var hour = now.getHours();
	var minute = now.getMinutes();
	var monthnumber = now.getMonth() + 1;
	var monthday = now.getDate();
	var year = now.getFullYear();

	minute = minute + addMin;
	if (minute > 59) {
		hour += 1;
		minute = minute - 60;
	}
	if (hour > 23) {
		hour = 0;
		monthday++;
	}
	if (!checkStandardDate(year, monthnumber - 1, monthday)) {
		monthday = 1;
		monthnumber++;
	}
	if (!checkStandardDate(year, monthnumber - 1, monthday)) {
		monthnumber = 1;
		year++;
	}
	now.setFullYear(year, monthnumber - 1, monthday);
	now.setHours(hour, minute, 0, 0);
	return now;
}

function checkDateFurtherToNow(sdate, shour, smin, addMin) {
	if (addMin == undefined || addMin == null)
		addMin = 0;
	var now = addMinutes(new Date(), addMin);

	var hour = now.getHours();
	var minute = now.getMinutes();
	var monthnumber = now.getMonth() + 1;
	var monthday = now.getDate();
	var year = now.getFullYear();

	var monthtext = "" + monthnumber;
	if (monthtext.length < 2)
		monthtext = "0" + monthtext;
	var daytext = "" + monthday;
	if (daytext.length < 2)
		daytext = "0" + daytext;

	return checkDateTimeInterval(daytext + "/" + monthtext + "/" + year, hour,
			minute, sdate, shour, smin);

}

function getStandardDateFromDMY(d) {
	var resdate = Date.fromDDMMYYYY(d);
	var monthnumber = resdate.getMonth() + 1;
	var monthday = resdate.getDate();
	var year = resdate.getFullYear();
	var monthtext = "" + monthnumber;
	if (monthtext.length < 2)
		monthtext = "0" + monthtext;
	var daytext = "" + monthday;
	if (daytext.length < 2)
		daytext = "0" + daytext;
	return "" + year + "-" + monthtext + "-" + daytext;
}

function validDate(date) {
	return date.length == 10 && Date.testfromDDMMYYYY(date);
}

function setDisabled(id, disabled) {
	if (!document.getElementById || !document.getElementsByTagName)
		return;

	var nodesToDisable = {
		button :'',
		input :'',
		optgroup :'',
		option :'',
		select :'',
		textarea :''
	};

	var node, nodes;
	var div = document.getElementById(id);
	if (!div)
		return;

	nodes = div.getElementsByTagName('*');
	if (!nodes)
		return;

	var i = nodes.length;
	while (i--) {
		node = nodes[i];
		if (node.nodeName && node.nodeName.toLowerCase() in nodesToDisable) {
			node.disabled = disabled;
		}
	}
}

function setDivDisabled(id, disabled) {
	setDisabled(id, disabled);
	if (disabled)
		new Effect.Fade(id, {
			from :1,
			to :0.3
		});
	else
		new Effect.Appear(id, {
			from :0.3,
			to :1
		});

}

function checkPwdSecurity(url) {

	var pwd = $('pwd1').value;
	new Ajax.Updater('pwdsecurity', url, {
		parameters :'pwd=' + pwd
	});
	$('pwd1').focus();
	checkPwdConf();
	return false;
}

function showPwdSecurity(url, div, input, error) {

	var pwd = $(input).value;
	new Ajax.Updater(div, url, {
		parameters :'pwd=' + pwd
	});

}

function checkPwdConf() {
	if (checkPwds()) {
		$('pwdconf').innerHTML = "<img src='/images/ok_conf.png'>";
	} else {
		$('pwdconf').innerHTML = "<img src='/images/ko_conf.png'>";
	}
}

function checkPwds() {
	if ($('pwd1').value == $('pwd2').value && $('pwd1').value.length > 0) {
		return true;
	} else {
		return false;
	}
}

function fireFormElement(id, event){
	element = $(id);
	if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt);
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}

function checkFormElement(event, validation, errors) {
	checkFormElementById(Event.element(event), validation, errors);
}

function checkFormElementById(id, validation, errors) {
	var el = $(id);
	var err = "";
	var type = validation["type"];
	if (type == TEXTSIZE || type == INTVAL || type == FLOATVAL) {
		var min = validation["min"];
		var max = validation["max"];
		var min_len = validation["min_len"];
		var max_len = validation["max_len"];
	}
	if (type == PASSWORD)
		var url = validation["url"];
	if (type == EMPTY)
		if (el.value != "") {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else {

			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		}
	else if (type == CHECKED)
		if (el.checked) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else {

			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		}
	else if (type == EMAIL)
		if (emailcheck(el.value)) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else if (el.value.length == 0) {
			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		} else {
			err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['error'] + "\">";
		}
	else if (type == TEXTSIZE)
		if (el.value.length >= min && el.value.length <= max) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else if (el.value.length == 0) {
			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		} else {
			err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['error'] + "\">";
		}
	else if (type == INTVAL)
		if (isInteger(el.value) && Number(el.value) >= min
				&& Number(el.value) <= max && el.value.length <= max_len
				&& el.value.length >= min_len) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else if (el.value.length == 0) {
			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		} else {
			err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['error'] + "\">";
		}
	else if (type == FLOATVAL)
		if (IsNumeric(el.value) && Number(el.value) >= min
				&& Number(el.value) <= max) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else if (el.value.length == 0) {
			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		} else {
			err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['error'] + "\">";
		}
	else if (type == DATE)
		if (validDate(el.value) && validDateValue(el.value)) {
			$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
		} else if (el.value.length == 0) {
			err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['need'] + "\">";
		} else {
			err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
					+ el.id
					+ "');\" onmouseout=\"return nd();\">"
					+ "<input type='hidden' id='error_required_flag_"
					+ el.id
					+ "' value=\"" + errors['error'] + "\">";
		}
	else if (type == PASSWORD)
		if ($('pwd1') && $('pwd2')) {
			if (el.id == "pwd1") {
				if (el.value.length > 0) {
					showPwdSecurity(url, 'required_flag_' + el.id, 'pwd1',
							errors['error']);
				} else {
					err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
							+ el.id
							+ "');\" onmouseout=\"return nd();\">"
							+ "<input type='hidden' id='error_required_flag_"
							+ el.id + "' value=\"" + errors['need'] + "\">";
				}
			} else if (el.id == "pwd2") {
				if (checkPwds()) {
					$('required_flag_' + el.id).innerHTML = "<img src='/images/ok.png' class='inputok'>";
				} else if (el.value.length == 0) {
					err = "<img src='/images/required_red.png' class='inputko' onmouseover=\"return showError('"
							+ el.id
							+ "');\" onmouseout=\"return nd();\">"
							+ "<input type='hidden' id='error_required_flag_"
							+ el.id + "' value=\"" + errors['need'] + "\">";
				} else {
					err = "<img src='/images/err.png' class='inputko' onmouseover=\"return showError('"
							+ el.id
							+ "');\" onmouseout=\"return nd();\">"
							+ "<input type='hidden' id='error_required_flag_"
							+ el.id + "' value=\"" + errors['pass'] + "\">";
				}
			}
		}

	if (err != "") {
		$('required_flag_' + el.id).innerHTML = err;
	}
	return false;
}

function showError(elid) {

	return overlib($('error_required_flag_' + elid).value, CAPTION,
			$('required_error_title_' + elid).value, BGCLASS, 'overbg', BORDER,
			0, CAPTIONFONTCLASS, 'overtitle', CLOSEFONTCLASS, 'overclose',
			CLOSECLICK, FGCLASS, 'olfg', TEXTFONTCLASS, 'overtext', CGCLASS,
			'olcg_alert', BELOW, RIGHT);

}

function showInfoTT(caption, text) {
	return overlib(text, CAPTION, caption, BGCLASS, 'overbg', BORDER, 0,
			CAPTIONFONTCLASS, 'overtitle', CLOSEFONTCLASS, 'overclose',
			CLOSECLICK, FGCLASS, 'olfg', TEXTFONTCLASS, 'overtext', CGCLASS,
			'olcg', BELOW, RIGHT);
}

function validDateValue(value) {
	var val = value.split('/');
	var year = val[2];
	var month = val[1] - 1;
	var day = val[0];
	source_date = new Date(year, month, day);
	if (year != source_date.getFullYear()) {
		return false;
	}

	if (month != source_date.getMonth()) {
		return false;
	}

	if (day != source_date.getDate()) {
		return false;
	}
	return true;

}

function checkStandardDate(year, month, day) {

	source_date = new Date(year, month, day);
	if (year != source_date.getFullYear()) {
		return false;
	}

	if (month != source_date.getMonth()) {
		return false;
	}

	if (day != source_date.getDate()) {
		return false;
	}
	return true;
}

function getFormParent(el) {
	var divel = null;
	$$('form').each(
			function(form) {
				var elArray = (el.type == "input" ? form.getInputs(el.type)
						: form.descendants());
				elArray.each( function(but) {

					if (but == el) {

						divel = form;
					}
				});
			});

	return divel;
}

function getDivParent(el) {
	var divel = el;
	while (divel.tagName.toLowerCase() != "div")
		if (divel.tagName.toLowerCase() == "body") {
			divel = null;
			break;
		} else {
			divel = Element.up(divel);
		}
	return divel;
}

function formCheck(button) {
	var formel = getFormParent(button);
	if (document.forms.length > 1)
		var kos = formel.select('.inputko');
	else
		var kos = $$('.inputko');
	if (kos.length == 0) {
		return true;
	} else {
		var eltohighlight = null;
		for (i = 0; i < kos.length; i++) {
			var inputid = Element.up(kos[i]).id.sub("required_flag_", "");
			if (!$(inputid).disabled && $(inputid).disabled != "disabled"
					&& $(inputid).disabled != "true"
					&& $(inputid).style.display != "none"
					&& getDivParent(kos[i]).style.display != "none") {
				eltohighlight = $(inputid);
				break;
			}
		}
		if (eltohighlight != null) {
			new Effect.ScrollTo(eltohighlight, {
				duration :0.5
			});
			var divel = getDivParent(eltohighlight);

			new Effect.Shake("required_flag_" + eltohighlight.id, {
				duration :0.5,
				delay :0.5,
				distance :8
			});
			eltohighlight.focus();
		} else {
			return true;
		}

		return false;
	}
}

function formCheckAndSubmit(button) {
	var formel = getFormParent(button);
	if (formCheck(button)) {
		if (formel.onsubmit != null && formel.onsubmit != "")
			formel.onsubmit();
		else
			formel.submit();
		return true;
	}
	return false;
}

function emailcheck(str) {

	var at = "@"
	var dot = "."
	var lat = str.indexOf(at)
	var lstr = str.length
	var ldot = str.indexOf(dot)

	if (lstr == 0) {
		return false;
	}

	if (str.indexOf(at) == -1) {
		return false;
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {

		return false;
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		return false;
	}

	if (str.indexOf(at, (lat + 1)) != -1) {
		return false;
	}

	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		return false;
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false;
	}

	if (str.endsWith(dot) || str.substring(lstr - 2, lstr).indexOf(dot) != -1) {
		return false;
	}

	if (str.indexOf(" ") != -1) {
		return false;
	}

	return true;
}

function stopInput(input, maxlength, event) {

	var key = event.which;
	// all keys including return.
	if (key >= 47 || key == 13 || key == 32) {
		var length = input.value.length;
		return (length < maxlength);
	} else {
		return true;
	}

}

function validateOnEnter(elid, func) {
	Event.observe(elid, 'keyup', function(event) {
		var el = event.element();
		if (el.tagName.toLowerCase() == "input") {
			var key = event.which;
			// all keys including return.
			if (key == 13) {
				func();
			}
		}
	});

}

function loadWhenOk(fct, domEl) {
	if ($(domEl) && $(domEl).style.display != "none")
		fct();
	else {
		setTimeout(fct, 1000);
	}
}

function setRightBounds(map, pts) {
	var bounds = map.getBounds();
	for (i = 0; i < pts.length; i++) {
		if (!bounds.containsLatLng(pts[i]))
			bounds.extend(pts[i]);
	}
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds) - 1);
}

function checkCP(el, departement, event) {

	var value;
	value = event.keyCode;

	if (departement != null
			&& ((el.selectionStart <= 1 && (value == 46 || value == 8)) || el.selectionStart == 2
					&& value == 8))
		return false;
	else
		return true;

}

function addInputChecker(target, checkArray, jsoptions, errors) {
	if ($(target).tagName.toLowerCase() == 'select'
			|| $(target).tagName.toLowerCase() == 'hidden') {
		Event.observe(target, 'change', function(event) {
			eval(jsoptions['before']);
			checkFormElement(event, {
				type :EMPTY
			}, errors);
			eval(jsoptions['after']);
		});
		setTimeout("checkFormElementById('" + target + "', {type:EMPTY},"
				+ errorArrayToString(errors) + ")", 500);
	} else if ($(target).type.toLowerCase() == 'text'
			|| $(target).type.toLowerCase() == 'password') {
		if ($('trigger_' + target)) {
			Event.observe('trigger_' + target, 'blur', function(event) {
				eval(jsoptions['before']);
				checkFormElementById(target, {
					type :DATE
				}, errors);
				eval(jsoptions['after']);
			});
			Event.observe(target, 'keyup', function(event) {
				eval(jsoptions['before']);
				checkFormElementById(target, {
					type :DATE
				}, errors);
				eval(jsoptions['after']);
			});
			Event.observe(target, 'change', function(event) {
				eval(jsoptions['before']);
				checkFormElementById(target, {
					type :DATE
				}, errors);
				eval(jsoptions['after']);
			});
			checkFormElementById(target, {
				type :DATE
			}, errors);
		} else {
			Event.observe(target, 'keyup', function(event) {
				eval(jsoptions['before']);
				checkFormElement(event, checkArray, errors);
				eval(jsoptions['after']);
			});

			Event.observe(target, 'change', function(event) {
				eval(jsoptions['before']);
				checkFormElement(event, checkArray, errors);
				eval(jsoptions['after']);
			});
			setTimeout("checkFormElementById('" + target + "',"
					+ checkArrayToString(checkArray) + ","
					+ errorArrayToString(errors) + ")", 500);

		}
	} else if ($(target).type == 'checkbox') {

		Event.observe(target, 'click', function(event) {
			eval(jsoptions['before']);
			checkFormElement(event, {
				type :CHECKED
			}, errors);
			eval(jsoptions['after']);
		});
		Event.observe(target, 'change', function(event) {
			eval(jsoptions['before']);
			checkFormElement(event, {
				type :CHECKED
			}, errors);
			eval(jsoptions['after']);
		});
		setTimeout("checkFormElementById('" + target + "',{type:CHECKED},"
				+ errorArrayToString(errors) + ")", 500);
	}

}

function checkArrayToString(myArray) {
	var retVal = "{"
			+ "type:"
			+ myArray["type"]
			+ ","
			+ "min: "
			+ myArray['min']
			+ ", max: "
			+ myArray['max']
			+ ",min_len: "
			+ myArray['min_len']
			+ ", max_len: "
			+ myArray['max_len']
			+ (myArray["type"] == PASSWORD && myArray["url"] != null ? ", url: '"
					+ myArray['url'] + "'"
					: "") + "}";
	return retVal;
}

function errorArrayToString(myArray) {
	var retVal = "{error:\"" + myArray['error'] + "\", need:\""
			+ myArray['need'] + "\", pass:\"" + myArray['pass'] + "\"}";
	return retVal;
}

function adaptElementToWindow(el, positions) {
	var dims = document.viewport.getDimensions();
	var newheight = dims['height'] - positions['top'] - positions['bottom']
			- 65;
	$(el).style.maxHeight = '' + newheight + 'px';
	Event.observe(window, 'resize', function(event) {
		adaptElementToWindow(el, positions);
	});
}

function stopAdapting() {
	Event.stopObserving(window, 'resize');
}
// ==================WEB 2 WINDOW=================

function closeWeb2() {

	if ($('winweb2').style.display != "none") {
		$$('div.calendar').each( function(el) {
			el.style.position = "absolute";
		});
		stopAdapting();
		new Effect.Fade('winweb2', {
			duration :0.5
		});
		new Effect.Fade('contentweb2_outter', {
			duration :0.5
		});
	}

}

function winweb2visible(){
	if($('winweb2'))
	return $('winweb2').style.display != "none";
	else
		return false;
}

function showWeb2WithClose(action) {
	$('contentwebclose').innerHTML = "<a href='#' onclick=\"" + action
			+ ";closeWeb2();\"><img src='/images/del_small.png'></a>";
	showWeb2Window();
}

function showWeb2Window() {
	if (nbloadings > 0) {
		nbloadings = 1;
		endLoading();
	}

	if ($('winweb2').style.display == "none") {

		new Effect.Appear('winweb2', {
			from :0,
			to :0.7,
			duration :0.5
		});
		new Effect.Appear('contentweb2_outter', {
			duration :0.5
		});
		adaptElementToWindow('contentweb2', {
			top :'94',
			bottom :'41'
		});

	}

}

function showWeb2() {

	$('contentwebclose').innerHTML = "<a href='#' onclick=\"closeWeb2()\"><img src='/images/del_small.png'></a>";
	showWeb2Window();

}

function web2winLoading() {
	$('contentweb2').innerHTML = $('contentloading').innerHTML;
}

var nbloadings = 0;

function showLoading() {
	if (nbloadings < 0)
		nbloadings = 0;
	nbloadings++;
	$('contentloading_outter').show();
}

function endLoading() {
	nbloadings--;
	if (nbloadings <= 0) {
		$('contentloading_outter').hide();
		nbloadings = 0;
	}
}

// =============Ajax Informations===========================

function showHideAjaxInfoForSelect(id, url, slideid) {
	if (id != "") {

		new Ajax.Updater(slideid + '_inner', url, {
			onComplete : function() {
				endLoading();

				new Effect.SlideDown(slideid, {
					duration :0.5,
					queue :'front'
				});
				setTimeout("new Effect.ScrollTo('" + slideid
						+ "',{queue:'end'})", 500);
			},
			onLoading : function() {
				showLoading();
			},
			evalScripts :true,
			parameters :'id=' + id
		});
	} else {
		new Effect.SlideUp(slideid, {
			queue :'end',
			duration :0.5
		});
	}

	return false;
}

function showHideAjaxInformation(id, url, slideid) {
	if (id != '') {
		if ($$('#' + slideid + '_inner_' + id + ' .need_ajax').length > 0) {
			new Ajax.Updater(slideid + '_inner_' + id, url, {
				onComplete : function() {
					endLoading();

					new Effect.SlideDown(slideid + '_' + id, {
						duration :0.5,
						queue :'front'
					});
					setTimeout("new Effect.ScrollTo('"+slideid + "_" + id+"',{queue:'end'})",50);

				},
				onLoading : function() {
					showLoading();
				},
				evalScripts :true,
				parameters :'id=' + id
			});
		} else if ($(slideid + '_' + id).style.display == "none") {
			new Effect.SlideDown(slideid + '_' + id, {
				duration :0.5,
				queue :'front'
			});
			setTimeout("new Effect.ScrollTo('"+slideid + "_" + id+"',{queue:'end'})",50);

		} else {
			new Effect.SlideUp(slideid + '_' + id, {
				queue :'end',
				duration :0.5
			});
		}
	}
	return false;
}

function selectInputText(event) {
	var el = $(Event.element(event));
	el.select();
}

var playlist = [];
var actualtrack = null;
var soundPlaying = false;
function addSoundInGlobalPlaylist(s, l) {
	playlist.push( {
		sound :s,
		length :l
	});
	if (!soundPlaying)
		nextTrack();
}

function nextTrack() {
	soundPlaying = true;
	if (playlist.length > 0) {
		Sound.enable();
		actualtrack = playlist.first();
		playlist = playlist.without(actualtrack);
		// alert("playing : "+actualtrack['sound']);
		Sound.play(actualtrack['sound'], {
			replace :true
		});
		setTimeout("nextTrack()", actualtrack['length']);
	} else {
		Sound.disable();
		soundPlaying = false;
		actualtrack = null;
	}
}

function stopAllSound() {
	Sound.enable();
	Sound.play('', {
		replace :true
	});
	Sound.disable();
}
var loadingcontent = null;
function showLockMessage(msg) {
	if (loadingcontent == null) {
		if ($('contentloadingmes')) {
			loadingcontent = $('contentloadingmes').innerHTML;
			$('contentloadingmes').innerHTML = msg;
			new Effect.Appear('winweb2', {
				from :0,
				to :0.7,
				duration :0.5
			});
			new Effect.Appear('contentloading_outter');
		} else {
			setTimeout("showLockMessage(\"" + msg + "\")", 1000);
		}
	}
}

function hideLockMessage(url) {
	if (loadingcontent != null) {
		$('contentloadingmes').innerHTML = loadingcontent;
		loadingcontent = null;
		if (url != undefined && url != null) {
			document.location.href = url;
		}
	}
}

var mesid = null;
function showMessage(message, timeout) {
	if (mesid)
		window.clearTimeout(mesid);

	$('contentweb2').innerHTML = "<div class='panier_popup_message_header1'>"
			+ message + "</div>";
	
	if (timeout == undefined || timeout == null){
		showWeb2();
		mesid = window.setTimeout('hideMessage()', 3000);
	}
	else if (isInteger(timeout) && timeout>0){
		showWeb2();
		mesid = window.setTimeout('hideMessage()', timeout);
	}
	else{
		
		showWeb2WithClose('hideMessage()');
	}
	
}

function hideMessage() {
	closeWeb2();
}

function getRadioValue(form, id){
	var radios = $(form).getInputs('radio',id);
	var val = null;
	radios.each(function(el){
		if(el.checked)
			val = el.value;
	});
	return val;
}

function makePopupCalendar(){
	$$('.calendar').each(function(el){
		el.style.position='fixed';
	});
}

function unmakePopupCalendar(){
	$$('.calendar').each(function(el){
		el.style.position='absolute';
	});
}

function getVersionIE(){
	if(Prototype.Browser.IE){
		var vers = 0;
		if(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+6)==".")
			vers = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5,3));
		else
			vers = parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5));
		return vers;
	}
	else
		return 0;
}

function connectOrRegisterFB(uid){
	return false;
}