// JavaScript Document
//fonctions n�essaires �la prise de commande 
function verifForm(formulaire)
	{
	if(formulaire.nom.value == "") 
		alert('Remplissez tous les champs obligatoires ...'); 
	else if(formulaire.email.value == "") 
		alert('Remplissez tous les champs obligatoires ...'); 
	else if(formulaire.societe.value == "") 
		alert('Remplissez tous les champs obligatoires ...'); 
	else {
		document.commande.mode.value=1;
		bonCommande(); 
		document.commande.submit(); }
	}

function verifFormmail(formulaire)
	{
	if(formulaire.societe.value == "part" && formulaire.nom.value =="") 
		alert('Renseignez nom  ou entreprise ...'); 
	else if(formulaire.email.value == "") 
		alert('Renseignez votre email ...'); 
	else     if (! isValidEmail(formulaire.email.value)) 
        alert("Votre adresse email est incorrecte !");
    else	
	{
		document.commande.mode.value=2;
		document.commande.submit(); }
		}


	// alterError - fixes a rounding bug in Netscape 2
	function alterError(value) {
		if (value<=0.99) {
			newPounds = '0';
		} else {
			newPounds = parseInt(value);
		}
		newPence = parseInt((value+.0008 - newPounds)* 100);
		if (eval(newPence) <= 9) newPence='0'+newPence;
		newString = newPounds + '.' + newPence;
		return (newString);
	}

	// showItems () - creates a table of items in the basket and
	// creates the start of a form which sets information for
	// basket items.
	function showItems() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0.00;
	
		
		document.writeln('<TABLE BORDER=1 COLS=3 cellspacing=0>');

		document.writeln('<TR bgcolor=#ccccc><TD align=center widht="100%"><FONT color=#000000><b>Produit</b></TD><TD align=right width="50"><FONT color=#000000><b>Quantite</b></TD><TD align=right width="100"><FONT color=#000000><b>Prix</b></TD></TR>');
		itemlist = 0;

		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				itemlist=itemlist+1;

		document.writeln('<tr><td>'+theitem+'</td><td align=right>'+theprice+'</td><td align=right>'+thequantity+'</td></tr>');
				document.writeln('<INPUT TYPE="hidden" NAME="item'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
				document.writeln('<INPUT TYPE="hidden" NAME="quantity'+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
				document.writeln('<INPUT TYPE="hidden" NAME="priceeach'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}
		totprice=Math.round(totprice*100)/100 ;
		document.writeln('<tr bgcolor=#FFFFFF align=right><td colspan=2><font color=#000000><b>Total en Euros HT </b></td><td align=right><font color=#000000><b>'+totprice+'</b></td></tr>');
		document.writeln('<INPUT TYPE="hidden" NAME="GoodsTotal" VALUE="'+totprice+'" SIZE="40">');
		totpricettc = totprice + (totprice * 19.6 / 100);
		totpricettc = Math.round(totpricettc * 100)/100;
		document.writeln('<tr bgcolor=#FFFFFF align=right><td colspan=2><font color=#000000><b>Total en Euros TTC</b></td><td align=right><font color=#000000><b>'+totpricettc+'</b></td></tr>');
		document.writeln('<INPUT TYPE="hidden" NAME="GoodsTotalTTC" VALUE="'+totpricettc+'" SIZE="40">');
		document.writeln('</TABLE>');

	}
function showItems2() {
		index = document.cookie.indexOf("Votre commande");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0.00;
		itemlist=0 ;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				itemlist=itemlist+1;

				document.writeln('<INPUT TYPE="hidden" NAME="item'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
				document.writeln('<INPUT TYPE="hidden" NAME="quantity'+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
				document.writeln('<INPUT TYPE="hidden" NAME="priceeach'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}
		totprice=Math.round(totprice*100)/100 ;
		document.writeln('<INPUT TYPE="hidden" NAME="GoodsTotal" VALUE="'+totprice+'" SIZE="40">');
		totpricettc = totprice + (totprice * 19.6 / 100);
		totpricettc = Math.round(totpricettc * 100)/100;
		document.writeln('<INPUT TYPE="hidden" NAME="GoodsTotalTTC" VALUE="'+totpricettc+'" SIZE="40">');

	}

//-------------------------------------------------------
// creation fenetre avec recapitilatif du bon de commande
// pour validation
//-------------------------------------------------------
function bonCommande()
{
	var page="<HTML><HEAD><TITLE>DEVIS</TITLE></HEAD>";
	page+="<body text=#000000 bgcolor=#FFFFFF link=#0000EE vlink=#551A8B alink=#FF0000>";
	page+="<img src=logo4.jpg width=200>";

	var societe=document.commande.societe.value
	var nom=document.commande.nom.value;
	var prenom=document.commande.prenom.value;
	var salutation=document.commande.SALUTATION.value;
	var adresse=document.commande.adresse.value;
	var codepostal=document.commande.postal.value;
	var ville=document.commande.ville.value;
	var pays=document.commande.pays.value;
	var tel=document.commande.tel.value;
	var fax=document.commande.fax.value;

	var email=document.commande.email.value;
	page+="<br><br><div align=right>";	
	page+="<table CELLSPACING=0 CELLPADDING=0>";
	page+="<tr><td align=left><font size=3><b>";
	page+=societe;
	page+="</b></font></td>";
	page+="</tr>";
	page+="<tr><td align=left><font size=3><u>";
	page+=salutation;
	page+=nom;
	page+="&nbsp;";
	page+=prenom;
	page+="</u></font></td></tr>";
	page+="<tr><td align=left><font size=3>";
	page+=adresse;
	page+="</font></td></tr>";
	page+="<tr><td align=left><font size=3>";
	page+=codepostal;
	page+="&nbsp;";
	page+=ville;
	page+="<font></td></tr>";
	page+="<tr><td align=left><font size=3>";
	page+=pays;
	page+="</font></td></tr>";
	page+="<tr><td align=left><font size=3>";
	page+="T�:";
	page+=tel;
	page+="&nbsp;-&nbsp;"
	page+="Fax:";
	page+=fax;
	page+="</font></td></tr>";
	page+="<tr><td align=left><font size=3>";
	page+="E-mail:";
	page+=email;
	page+="</font></td></tr>";
	page+="</table></div>";
	page+="<center><font size=5><br><br><br>";
	page+="DEVIS ANTIVIRUS";
	page+="<br><br></font></center>";

		index = document.cookie.indexOf("Votre commande");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);

		totprice = 0.00;
		page+="<center><TABLE BORDER=1 COLS=3 cellspacing=0>";
		page+="<TR bgcolor=#FFFFFF><TD align=center widht=100%><FONT color=#000000><b>Produit</b></TD><TD align=right width=50><FONT color=#000000><b>Quantit�/b></TD><TD align=right width=100><FONT color=#000000><b>Prix</b></TD></TR>";
		itemlist = 0;
		for (var i = 1; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				itemlist=itemlist+1;
				page+="<tr><td>";
				page+=theitem;
				page+="</td><td align=right>"
				page+=theprice;
				page+="</td><td align=right>";
				page+=thequantity;
				page+="</td></tr>";
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}

		page+="<tr bgcolor=#FFFFFF align=right><td colspan=2><font color=#000000><b>";
		page+="Total en Euros HT";
		page+="</b></td><td align=right><font color=#000000><b>";
		totprice=Math.round(totprice*100)/100 ;
		page+=totprice;
		page+="</b></td></tr>";
		//page+="<tr bgcolor=#FFFFFF align=right><td colspan=2><font color=#000000><b>";
		//page+="Total en Euros TTC";
		//page+="</b></td><td align=right><font color=#000000><b>";
		totprice=Math.round(totpricettc*100)/100 ;
		//page+=totpricettc;
		//page+="</b></td></tr>";
		page+="</TABLE></center><br>";
	page+="<center>";
	page+="<p><i>TVA �d�larer par le preneur : Article 259B du CGI<p></i>";

	page+="<TABLE>";
	page+="<td width=200>";
	page+="A";
	page+="<br><br>";
	page+="Le";
	page+="</td>";
	page+="<td>";
	page+="<TABLE BORDER=1 CELLPADING=0 CELLSPACING=0 align=right>";
	page+="<td width=200 height=100 valign=top>";
	page+="Bon pour accord";
	page+="</td></table></td>";
	page+="</TABLE>";
	page+="</center>";
	page+="<br><br><br><br><br><br><br>";
	page+="<center>";
	page+="<TABLE>";
	page+="<tr><td align=center>";	
	page+="<b>";
	page+="Bureau France : 31, chemin des Pierris - 77400 Saint Thibault des Vignes";
	page+="</b></td></tr>";
	page+="<tr><td align=center><b>";
	page+="T�. : 01 60 07 31 31 - Fax : 01 60 07 31 32 - email: contact@tmbnet.com - Web: www.tmbnet.com";
	page+="</b></td></tr></TABLE>";
	page+="</center>";
	page+="</body></html>";
	winBon = window.open("", "BonCommande", "toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=600");
	winBon.document.open();
	winBon.document.write(page);
}


