/**
 * (c) copyright lx barjon <lx.barjon@gmail.com>
 * (18-12-2006)
 *
 * version: 0.3
 * licence: GNU GPL
 * Depend on :
 *		prototype.js (v 1.4)
 */
 
// racine modules
var sitePath = '/gmod.05/';
 
function hideMyf(fieldName) {
	if($(fieldName)) $(fieldName).hide();
	if($(fieldName+'_lbl')) $(fieldName+'_lbl').hide();
	if($(fieldName+'_helpImg')) $(fieldName+'_helpImg').hide();
}
function showMyf(fieldName) {
	if($(fieldName)) $(fieldName).show();
	if($(fieldName+'_lbl')) $(fieldName+'_lbl').show();
	if($(fieldName+'_helpImg')) $(fieldName+'_helpImg').show();
}
 
 function compatibleBrowsersCheck( warningPageUrl ) {
	if (!document.getElementById ||
	    !document.getElementsByTagName ||
	    !document.createElement ) {
		if ( !warningPageUrl ) {
			warningPageUrl = 'oldBrowsersWarning.php';
		}
	window.location.href = warningPageUrl;
	}
}

function inArray( value, array ) {
	for ( var cpt = 0; cpt < array.length; cpt++ ) {
		if ( array[cpt] == value ) return true;
	}
	return false;
}

/*Array.prototype.isMember = function( search ) {
    for ( var elt in this ) if ( this[elt] == search ) return true;
    return false;
};*/

/*
 * fonction setElementHeight()
 * version: 0.3 (12-04-2006)
 *
 * @desc					établie la hauteur des éléments fournis
 *     en fonction de la hauteur de la fenêtre si le scrollHeight est plus petit
 *     sinon ne fait rien
 * @param array 	elements		liste des éléments à redimensionner
 * @param integer	correction	correction à appliquer
 */
function setElementHeight( elements, correction, force ) {
	var elmtHeight;
	
	// correction par défaut
	if ( typeof correction == 'undefined' ) {
		correction = 2;
	}

	var refElmtHeight = 0;
	if ( typeof refElement != 'undefined' ) {
		if ( $(refElement) ) {
			$(refElement).style.display = '';
			refElmtHeight = $(refElement).offsetHeight + Position.cumulativeOffset(refElement)[1];
		}
	}
	scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight || 0;
	if (!window.innerHeight) winHeight = screen.availHeight-window.screenTop;
	else winHeight = window.innerHeight;
	if ( scrollHeight <= winHeight  || force ) {
		for ( var cpt = 0; cpt < elements.length; cpt++ ) {
			if( $(elements[cpt]) )
				$(elements[cpt]).style.height = ( winHeight - Position.cumulativeOffset(elements[cpt])[1] - correction ) + 'px';
		}
	}
}

function jumpTo(e) {
	var selectTag = window.event ? window.event.srcElement : e ? e.target : null;
	if ( !selectTag ) return;
	eval( "parent.location = '" + selectTag.options[selectTag.selectedIndex].value + "'" );
}

function jumpMenu( target, selectObj, restore ){
	eval( target+".location='"+selectObj.options[selectObj.selectedIndex].value+"'" );
	if (restore) selectObj.selectedIndex=0;
}

function go_to( where, what, tableToolsObj, paramSup ){
	if ( !paramSup ) paramSup = '';
	if ( tableToolsObj.selectedValues ) {
		if ( tableToolsObj.selectedValues.indexOf("|") != -1 ) {
			window.alert("Impossible de modifier plusieurs éléments d\'un seul coup...");
		} else {
			window.location = where + "?" + what + "=" + tableToolsObj.selectedValues + paramSup;
		}
	} else window.alert("Merci de sélectionner un élément avant de cliquer.");
}

function del( where, what, gp, msg ){
	if ( gp.selectedValues == -1 ) {
		window.alert("Merci de sélectionner au moins un élément à supprimer.");
	} else {
		if ( !varIsDefined( msg ) ) msg = 'Supprimer le(les) éléments séléctioné(s)?';
		if ( confirm(msg) ) {
			window.location = where + "?" + what + "=" + gp.selectedValues;
		}
	}
}

function http_uri( httpUri, what, gp ) {
	if ( gp.selectedValues == -1 ) {
		window.alert("Merci de sélectionner un élément avant de cliquer.");
	} else if ( gp.selectedValues.indexOf("|") != -1 ) {
		window.alert("Veuillez ne séléctionner qu'un élément.");
	} else {
		vars = what + "=" + gp.selectedValues;
		httpUri = httpUri.replace( '{VARS}', vars );
		eval(httpUri);
	}
}