// Fonction d'ouverture de fenetre popup centree
// Simon - egzakt.com
// 2004-10-28
//
function egz_openwindow(lien,cible,w,h) {
	var _win;
	_win = window.open(lien,cible,'width=' + w + ',height=' + h + ',top=' + (screen.height - 400)/2 + 'left='+ (screen.width - 400)/2);
	_win.moveTo((screen.width - w)/2,(screen.height - h)/2);
	_win.focus();

	return _win;
}

// Fonction d'ouverture de fenetre popup centree
// Simon - egzakt.com
// 2004-10-28
//
function egz_openwindow_param(lien,cible,w,h,param) {
	var _win;
	_win = window.open(lien,cible,param);
	_win.moveTo((screen.width - w)/2,(screen.height - h)/2);
	_win.focus();

	return _win;
}


// Dropdown
// Original : http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
// Modification : Simon - egzakt.com
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
	jsddm_canceltimer();
	jsddm_close($(this).next());
	$(this).addClass('over');
	ddmenuitem = $(this).next().show();
}

function jsddm_close(select) {
	if(ddmenuitem)
		ddmenuitem.hide();
	$(select).removeClass('over');
}

function jsddm_timer() {
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}


// EquipRental
// Page liste
// Simon - egzakt.com
function showrentalsubcats(obj,event) {
	if (event == "hover") {
		$(obj).addClass("preview_on");
		$(obj).children("a.previewlink").hide();
		$(obj).children("ul").show();
	} else {
		$(obj).removeClass("preview_on");
		$(obj).children("a.previewlink").show();
		$(obj).children("ul").hide();
	}
	return false;
}

// EquipRental
// Page detail
// Simon - egzakt.com
function showrentaldetail(obj) {
	var specs = $(obj).parent().next().children("table");
	var equipselectedclass = $(obj).parent().parent().hasClass("equiprentalpremier") ? "equiprentalpremierselected" : "equiprentalselected";
	if ($(obj).hasClass("detailselected")) {
		$(obj).removeClass("detailselected").parent().parent().removeClass(equipselectedclass);
		$(specs).find("tr.hidden").hide();
	} else {
		$(obj).addClass("detailselected").parent().parent().addClass(equipselectedclass);
		$(specs).find("tr.hidden").show();
	}
	return false;
}


// Envoyer un formulaire
// Simon - egzakt.com
function sendform(submit) {
	$('#'+submit).attr('disabled','disabled');
	$('#'+submit).val(langue == 'fr' ? 'Un instant...':'Loading...');
	return true;
}


// Loading (lors de requete ajax)
// Simon - egzakt.com

// Vider les resultats
function axloading(bool) {
	if (bool) {
		$('#loading').show();
	} else {
		$('#loading').hide();
	}
	return;
}


// Erreur suite a une requete ajax
// Simon - egzakt.com
function axerror(res) {
	axloading(false);
	var undef = langue == "fr" ? "Erreur du serveur. Veuillez essayer plus tard." : "Server error. Please try again later.";
	alert(res.message ? res.message : undef);
}


function formatFloat(num) {
	if (!num)
		return 0.0;
	return parseFloat(num.replace(/ /g,'').replace(/\,/g, '.'));
}
function formatFloatfix(num,decimal) {
	if ((!num) || isNaN(num))
		return 0;
	if (!decimal)
		decimal = 1;
	return parseInt(num * decimal) / decimal;
}

function formatInt(num) {
	if ((!num) || isNaN(num))
		return 0;
	return parseInt(num.replace(/ /g,''));
}


// Simon - egzakt.com
// 2006
// t:input - f:obj form - s:section_id
var action_ori = "";
function rechercher(f){
	if (f.motscles.value == searchtxtval)
		f.motscles.value = "";
	if (!action_ori) action_ori = f.action;
	var e = encodeURI(f.motscles.value).replace(/\%20/g, '+');
	var s = (f.recherche_par_section.checked ||
			((f.recherche_par_section.type != "checkbox") && (f.recherche_par_section.value == "1")))?f.recherche_section_id.value:1;
	f.action = action_ori + s + "/" + e;
	return true;
}

// Fonction qui change la photo moyenne du modele
// Emilie - egzakt.com
// 2006-08-10
function change_photo_modele(cible,cible_lightbox,photo,path) {
	document.getElementById(cible).src = photo;
	document.getElementById(cible_lightbox).href = photo.replace(path + "ap_",path);
}



// trim
// http://www.webtoolkit.info/javascript-trim.html
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}