/* ====================================== OUTILS ====================================================*/

function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
       windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function getWindowWidth()
{
  var windowWidth = 0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement && document.documentElement.clientWidth) {
       windowWidth = document.documentElement.clientWidth;
     }
     else {
       if (document.body && document.body.clientWidth) {
         windowWidth = document.body.clientWidth;
       }
     }
  }
  return windowWidth;
}

function completeId(id,prefix,adheNum) {

	if (id.length == 15)    return id;
	if (id==null || id=="") return "";


	if (!adheNum) adheNum = id.substr(0,3);
	if (!prefix)  prefix  = "CL##";

	if (isNaN(adheNum)) return "";

	var cpt = "";

	switch(prefix) {
	  case "CL##" :
	    if (id.length < 4 || id.length > 12) return "";
	    cpt = id.substr(3,id.length);
	    break;

	  case "COMC" :
	    cpt = id;

	  default :
	    if (id.length < 1 || id.length > 8) return "";
	}

	if (isNaN(cpt)) return "";

	var fill = "";

	for (var i=0; i< (8-cpt.length); i++) {
		fill += "0";
	}
	return prefix+adheNum+fill+cpt;
}

/* Supprime tous les espaces avant et après la chaine de caractère*/
function trim(str) {
  str = str.replace(/ *$/ ,"");
  return str.replace(/^ */,"");
}

function imprime(obj) {
// On récupère l'objet à imprimer
  var zi = obj.innerHTML;
  var Headers = '<!DOCTYPE HTML PUBLIC ><HTML><HEAD><title>Print</title><link rel="stylesheet" media="screen" type="text/css" href="../css/main_design.css"/><link rel="stylesheet" type="text/css" media="print" href="../css/print.css" />    <div id="header">'+
      '<div id="headcornerleft"></div>'+
      '<div id="livre"></div>'+
      '<div id="logo"></div>'+
      '<div id="headcornerright"></div>'+
      '</div>'+
      '</HEAD><BODY style="color:black; background-color:white; padding:5px;" onload="window.print();window.close()">';
  //alert(Headers);
  var Footers = "</body></html>";
  // Ouvre une nouvelle fenetre
  var f = window.open("", "ZoneImpr", "height=913, width=710,toolbar=1, menubar=1, scrollbars=1, resizable=1, status=0, location=0, left=10, top=10");
  // Ajoute les Données
  f.document.write ("" + Headers + zi +Footers);
  f.document.close();
  return;
}

function verifpanier(URL) {

  var cols = document.getElementsByTagName("TD");

  for (var i=0; i<cols.length; i++) {
  	if (cols[i].hasChildNodes()) {
  		var child = cols[i].childNodes[0];
  		if (child && child.nodeName=="INPUT" && child.type=="checkbox" && child.checked ) {
  			var doCalc = confirm("Vous avez modifié une ou plusieurs quantités.\nVoulez vous recalculer le panier avant de passer à l'étape suivante ?");
  			if (doCalc==true) setValue('mySubmit','M');
  			break;
  		}
  	}
  }
  window.location.href = URL;
}





