// JavaScript Document
function send_selection(form,type){
	code_article = document.forms[form].code_article.value;
	qte = document.forms[form].qte.value;
	if(isNaN(qte) || qte==0)
			alert("Merci de saisir une quantité");
	else
		MM_openBrWindow("popup_commande.php?code_article="+code_article+"&qte="+qte+"&type="+type,"popup","width=500,height=400");
}


function subscribe_newsletter(form){
	email = document.forms['newsletter'].email;
	
	if(verif_input(email,"mail")=="")
		MM_openBrWindow("popup_newsletter.php?email="+email.value,"popup","width=500,height=310");
	else
		alert("L'email saisi est invalide");
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function PopupImage(img) {
	titre="Détails";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function PopupVideo(video) {
	titre="Détails";
	w=open("",'image','width=320,height=250,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<BODY leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<OBJECT ID='myPlayer' CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='320' HEIGHT='250' CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>");
	w.document.write("<PARAM NAME='bgcolor' VALUE='#000000'>");
	w.document.write("<PARAM NAME='controller' VALUE='TRUE'>");
	w.document.write("<PARAM NAME='autoplay' VALUE='true'>");
	w.document.write("<PARAM NAME='src' VALUE='"+video+"'>");
	w.document.write("<PARAM NAME='SCALE' VALUE='ASPECT'>");
	w.document.write("<PARAM NAME='pluginspage' VALUE='http://www.apple.com/quicktime/download/indext.html'>");
	w.document.write("<EMBED WIDTH='320' HEIGHT='250' CONTROLLER='TRUE' AUTOPLAY='TRUE' SRC='"+video+"' BACKGROUNDCOLOR='#000000' BORDER='0' PLUGINSPAGE='http://www.apple.com/quicktime/download/'></EMBED></OBJECT>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function verif_input(champ,type){
  erreur = "";
  // initialisaiton des couleurs d'erreurs.
  error_text = "#FFFFFF";
  error_bgcolor = "#CC0000"
  
  // réinitialisation de la couleur par défault des champs
  champ.style.backgroundColor = "";
  champ.style.color = "";
  
  switch(type){
  		// type : int, mail, default
	  case "int" : // n'est pas un entier ou est vide.
		  if(isNaN(champ.value) || champ.value == ""){ 
			erreur = "-";
			champ.style.backgroundColor = error_bgcolor;
			champ.style.color = error_text;
		  }
		  break;
	  case "mail" : // ne correspond pas à la syntaxe d'un mail correct.
		  if ((champ.value =="") || (champ.value.indexOf("@") =="-1") || (champ.value.indexOf(".") =="-1")){
			erreur = "-";
			champ.style.backgroundColor = error_bgcolor;
			champ.style.color = error_text;
		  }
		  break;

	  default:
	  	  if(champ.value == ""){
			erreur = "-";
			champ.style.backgroundColor = error_bgcolor;
			champ.style.color = error_text;
		  }
		  break;
  }
  return erreur;
}
