var popWin = '';

function showSimpleFormWindow( name, getVars, width, height ){
  var features = "scrollbars=yes,resizable=yes,width=" + width + ",height=" + height;
  popWin = window.open( name + ".php" + getVars, name, features );
  popWin.focus();
  return false;
} // fin de simpleFormWindow

function reloadClose( xtra ){
//alert( window.opener.location );
  if( xtra == '' )
    window.opener.location = window.opener.location;
  else
    window.opener.location = "http://" + window.opener.location.host + window.opener.location.pathname + xtra; 
  window.close();
} // fin de realoadClose

function redirect( locat ){
	window.opener.location = locat;
	window.close();
} // fin de realoadClose

/**
 * Displays an confirmation box before doing some action 
 *
 * @param   object   the message to display 
 *
 * @return  boolean  whether to run the query or not
 */
function confirmAction(theMessage)
{
    // TODO: Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);

    return is_confirmed;
} // end of the 'confirmAction()' function

/**
 * Ensures a value submitted in a form is numeric and is in a range
 *
 * @param   object   the form
 * @param   string   the name of the form field to check
 * @param   integer  the minimum authorized value
 * @param   integer  the maximum authorized value
 *
 * @return  boolean  whether a valid number has been submitted or not
 */
function checkFormElementInRange(theForm, theFieldName, min, max)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

    if (typeof(min) == 'undefined') {
        min = 0;
    }
    if (typeof(max) == 'undefined') {
        max = Number.MAX_VALUE;
    }

    // It's not a number
    if (isNaN(val)) {
        theField.select();
        alert(errorMsg1);
        theField.focus();
        return false;
    }
    // It's a number but it is not between min and max
    else if (val < min || val > max) {
        theField.select();
        alert(val + errorMsg2);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function

/**
 * getElement
 */
function getElement(e,f){
    if(document.layers){
        f=(f)?f:self;
        if(f.document.layers[e]) {
            return f.document.layers[e];
        }
        for(W=0;i<f.document.layers.length;W++) {
            return(getElement(e,fdocument.layers[W]));
        }
    }
    if(document.all) {
        return document.all[e];
    }
    return document.getElementById(e);
}

function showHide( elem, disp ){
	var elem = getElement( elem );
	elem.style.display = disp;
}	// showHide()
