// js form validation stuff
/**/
var errorMsgMinLenght = 'Inserire almeno x caratteri';
var errorMsg0   = 'Valore mancante nel form!';
//var errorMsg1   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
//var errorMsg2   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotValidNumber']); ?>';
//var noDropDbMsg = '<?php echo((!$GLOBALS['cfg']['AllowUserDropDatabase']) ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''); ?>';
//var confirmMsg  = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>';
/**/
/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
        theForm.reset();
        theField.select();
        alert(errorMsg0);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' 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



/**
 * Displays an error message if a value of a form hasn't the minimum lenght of characters
 * should have
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  integer  the minimum charachter's lenght
 */
function minFormCharsLen(theForm, theFieldName, theMinLength)
{
    var theField = theForm.elements[theFieldName];
     
    var val        = theField.value;
    var len        = val.length;
        
    isRightLen = (len >= theMinLength) ? 1 : 0;
    
    if (!isRightLen) {
        theForm.reset();
        theField.select();
        alert('Inserire almeno ' + theMinLength +' caratteri!');
        theField.focus();
        return false;
    }

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


/** Funzione che cambia il bordo di una immagine
*
*  @param   object   l' id dell'elemento su cui agire
*  @param   string valori da attribuire al bordo
**/
function bd(id,val)
{
	document.getElementById(id).style.border = val;
} 

//========================
// Apre una finestraPopup
//========================
var newWin;
function nuovaFinestra(nomeFile){

var nomeFinestra="f1";
var newHeight=500;
var newWidth=600;
//newTop=(screen.height/2) - (newHeight/2);
newTop=0;
newLeft=(screen.width/2) - (newWidth/2);

var caratteristiche="width=" + newWidth + ", height=" + newHeight + ", top=" + newTop + ", left=" + newLeft + ", scrollbars=yes,resizable=yes";

newWin=window.open(nomeFile, nomeFinestra, caratteristiche);
newWin.focus();
}


 
//=================================
// Apre una finestraPopup simile a
// quella sopra ma con parametri
//=================================
function apriFinestra(in_nomeFile, in_nomeFinestra, newWidth, newHeight, in_pos){

//var nomeFinestra="f2";
//var newHeight=500;
//var newWidth=600;
//newTop=(screen.height/2) - (newHeight/2);
//newTop=0;
//newLeft=(screen.width/2) - (newWidth/2);

if(in_pos=="top left")
{
  newTop=0;
  newLeft=0;
  
}
else if(in_pos=="center")
{
newTop=(screen.height/2) - (newHeight/2);
newLeft=(screen.width/2) - (newWidth/2);
}

var caratteristiche="width=" + newWidth + ", height=" + newHeight + ", top=" + newTop + ", left=" + newLeft + ", scrollbars=yes,resizable=yes";

newWin=window.open(in_nomeFile, in_nomeFinestra, caratteristiche);
newWin.focus();
}


 
function apri_finestra(smId) {
	f = window.open("modules/shopping/templates/tabella_costi.php?smId="+smId, "tabella", "statusbar=0, menubar=0, scrollbars=1, resizable=1, width=200, height=150");
	f.focus();
}