var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
	/*LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;*/
	LeftPosition=0;
	TopPosition=0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

function OpenCertDetails()
{
thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=FRPRIV1', 'anew', config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}


/* ------------------------- LIVRE CADDIE -------------------------- */
function addL($userid, $idlivre, $qty, $p_date, $host, $user, $pass, $database)
{
 	mysql("$database","INSERT INTO cartitems (userid, idlivre, quantite, datecart) values ('$userid',$idlivre,$qty, '$p_date')");
	return 1;
}
function delALL($userid, $p_date, $host, $user, $pass, $database)
{
 	mysql("$database","DELETE from cartitems WHERE userid='$userid' ");
	return 1;
}

function delL($userid, $idlivre, $p_date, $host, $user, $pass, $database)
{
 	mysql("$database","DELETE from cartitems WHERE idlivre=$idlivre and userid='$userid' ");
	return 1;
}

function majL($userid, $idlivre, $qty, $p_date, $host, $user, $pass, $database)
{
 	mysql("$database","UPDATE cartitems set quantite='$qty' where idlivre=$idlivre and userid='$userid' ");
	return 1;
}
/* ------------------------ FIN LIVRE ------------------------ */

/* ------------------------ MSG ERREUR ----------------------- */
function ErreurInitialiser()
{
      ErreurMessage = "Certains champs obligatoires n'ont pas été remplis.\nVeuillez choisir :";
      ErreurMessageTaille = ErreurMessage.length;
      ErreurPremierChamp = null;
}

function ErreurAfficher()
{
      if (ErreurMessageTaille != ErreurMessage.length)
      {
            alert(ErreurMessage);
            ErreurPremierChamp.focus();

            ErreurInitialiser();
            return false;
      }
      return true;
}

function Erreur(champ, texte)
{
      ErreurMessage += '\n    -  ' + texte;
      if (!ErreurPremierChamp) {ErreurPremierChamp = champ;}
}
/* ---------------------- FIN MSG ERREUR ---------------------- */


/* -------------------- fonctions diverses -------------------- */
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

/* Verification d'un float */
function validate_float(Strtxt)
{

    if (!Strtxt) return -1;
    var Chars = "0123456789.";
	var cnt=0;
    for (var i = 0; i < Strtxt.length; i++) {
       if (Chars.indexOf(Strtxt.charAt(i)) == -1)
          return -1;
	   else if(Strtxt.charAt(i)=='.') cnt=cnt+1;
    }

	if (cnt<=1)
	    return Math.round(Strtxt);
	else
		return -1;
}

/* Verification d'un Integer */
function validate_int(Strtxt)
{
    if (!Strtxt) return -1;
    var Chars = "0123456789";

    for (var i = 0; i < Strtxt.length; i++) {
       if (Chars.indexOf(Strtxt.charAt(i)) == -1)
          return -1;
    }
	return Strtxt;
}
/* ------------------- Fin fonctions diverses ------------------ */
