var prodname = new Array(27)
var prodpoids = new Array(27)
var prodprixcan = new Array(27)
var prodprixeuro = new Array(27)
var priceship = new Array(27)
var prodlivre = new Array(27)
// prod1
prodname[1] = 'Le Chant du Cygne';
prodprixcan[1] = 20;
prodprixeuro[1]=17;
prodpoids[1]=260;
priceship[1]=0;
prodlivre[1]=1;
// prod2
prodname[2] = 'L\'EGO ET LE SOI'; 
prodprixcan[2] = 20;
prodprixeuro[2]=17;
prodpoids[2]=410;
priceship[2]=0;
prodlivre[2]=1;
// prod3
prodname[3] = 'LES 13 PRINCIPES';
prodprixcan[3] = 20;
prodprixeuro[3]=17;
prodpoids[3]=410;
priceship[3]=0;
prodlivre[3]=1;
// prod4
prodname[4] = 'JE SUIS CONSCIENCE';
prodprixcan[4] = 20;
prodprixeuro[4]=17;
prodpoids[4]=410;
priceship[4]=0;
prodlivre[4]=1;
// prod5
prodname[5] = 'Supreme lacher-prise';
prodprixcan[5] = 25;
prodprixeuro[5]=21;
prodpoids[5]=284;
priceship[5]=0;
prodlivre[5]=1;
// prod6
prodname[6] = 'Le Secret de Jesus';
prodprixcan[6] = 25;
prodprixeuro[6]=21;
prodpoids[6]=335;
priceship[6]=0;
prodlivre[6]=1;
// prod7
prodname[7] = 'La Hierarchie Solaire';
prodprixcan[7] = 27;
prodprixeuro[7]=26;
prodpoids[7]=370;
priceship[7]=0;
prodlivre[7]=1;
// prod8
prodname[8] = 'CD Chant du Cygne';
prodprixcan[8] = 20;
prodprixeuro[8]=17;
prodpoids[8]=95;
priceship[8]=0;
prodlivre[8]=0;
// prod9
prodname[9] = 'CD Ascension';
prodprixcan[9] = 20;
prodprixeuro[9]=17;
prodpoids[9]=40;
priceship[9]=1;
prodlivre[9]=0;
// prod10
prodname[10] = 'CD du 7e CIEL';
prodprixcan[10] = 20;
prodprixeuro[10]=17;
prodpoids[10]=40;
priceship[10]=1;
prodlivre[10]=0;
// prod11
prodname[11] = 'CD Gongs de Cristal ';
prodprixcan[11] = 20;
prodprixeuro[11]=17;
prodpoids[11]=40;
priceship[11]=1;
prodlivre[11]=0;
// prod12
prodname[12] = 'une conference';
prodprixcan[12] = 13;
prodprixeuro[12]=9;
prodpoids[12]=60;
priceship[12]=0;
prodlivre[12]=0;
// prod13
prodname[13] = 'deux conferences';
prodprixcan[13] = 22;
prodprixeuro[13]=16;
prodpoids[13]=120;
priceship[13]=0;
prodlivre[13]=0;
// prod14
prodname[14] = 'trois ou plus';
prodprixcan[14] = 10;
prodprixeuro[14]=8;
prodpoids[14]=60;
priceship[14]=0;
prodlivre[14]=0;
// prod15
prodname[15] = 'AMOUR ame soeur';
prodprixcan[15] = 27;
prodprixeuro[15]=20;
prodpoids[15]=180;
priceship[15]=0;
prodlivre[15]=0;
// prod16
prodname[16] = 'ARGENT Abondance, prosperite';
prodprixcan[16] = 27;
prodprixeuro[16]=20;
prodpoids[16]=180;
priceship[16]=0;
prodlivre[16]=0;
// prod17
prodname[17] = 'ASCENSION';
prodprixcan[17] = 27;
prodprixeuro[17]=20;
prodpoids[17]=180;
priceship[17]=0;
prodlivre[17]=0;
// prod18
prodname[18] = 'GUERISON';
prodprixcan[18] = 27;
prodprixeuro[18]=20;
prodpoids[18]=180;
priceship[18]=0;
prodlivre[18]=0;
// prod19
prodname[19] = '2 conf sur le RIRE';
prodprixcan[19] = 20;
prodprixeuro[19]=17;
prodpoids[19]=130;
priceship[19]=0;
prodlivre[19]=0;

// prod20
prodname[20] = 'Poster «JE SUIS»';
prodprixcan[20] = 15;
prodprixeuro[20]=15;
prodpoids[20]=70;
priceship[20]=0;
prodlivre[20]=0;


// prod21
prodname[21] = 'CD Danube Bleu';
prodprixcan[21] = 20;
prodprixeuro[21]=17;
prodpoids[21]=40;
priceship[21]=0;
prodlivre[21]=0;

// prod21
prodname[22] = 'Les Cathares et l\'Ascension';
prodprixcan[22] = 23;
prodprixeuro[22]=23;
prodpoids[22]=100;
priceship[22]=0;
prodlivre[22]=0;

// prod21
prodname[23] = 'La Guerison Christique';
prodprixcan[23] = 23;
prodprixeuro[23]=23;
prodpoids[23]=100;
priceship[23]=0;
prodlivre[23]=0;



prodname[24] = 'L\'energie financiere maitrisee';
prodprixcan[24] = 23;
prodprixeuro[24]=23;
prodpoids[24]=325;
priceship[24]=0;
prodlivre[24]=1;



prodname[25] = 'L\'energie sexuelle maitrisee';
prodprixcan[25] = 23;
prodprixeuro[25]=23;
prodpoids[25]=280;
priceship[25]=0;
prodlivre[25]=1;

prodname[26] = 'LE CODE D\'ASCENSION';
prodprixcan[26] = 23;
prodprixeuro[26]=23;
prodpoids[26]=310;
priceship[26]=0;
prodlivre[26]=1;

var paypalurl;


  function Commander() {
    if(window.document.orderform.Nom.value == '' || window.document.orderform.Addresse.value == '' || window.document.orderform.Ville.value == '' || window.document.orderform.Pays.value == '' || window.document.orderform.Email.value == '' || window.document.orderform.zipcode.value == '' ) { 
	  alert('Vous devez obligatoirement saisir votre nom,  adresse, ville, pays, code postal et courriel pour completer votre commande.'); 
	 } else {
	   calcCart();
	   if (window.document.orderform.methode_paiement[0].checked) {
			document.getElementById('redirect').value = paypalurl;
	   } else {
		  document.getElementById('redirect').value = 'http://www.katarosnectar.com/merci.htm';   
	   }
	   window.document.invoice.submit();
	 }
  
  }
  function calcCart() {
    var today = new Date() 
    var myform = window.document.orderform;
	var totalprix =0, livraison=0, tps=0, tvq=0, poids=0, temptps=0, priceshipcan=0, priceshipeu=0;
	var paystring = '';
	var invoicestring = '', coord = '';
	var nbritem = 0;
    var onlypriceship = 1;
	var can = 1;
	
	if (myform.reglement[1].checked) {
	  can = 0;	
	}
	
	for (k=0;k<myform.elements.length;k++) {
      if (myform.elements[k].name.indexOf('prod_') > -1 && myform.elements[k].value > 0) {
		
		//  Si checkbox		  
		  
	    idprod = myform.elements[k].name.substr(5, myform.elements[k].name.length);
		
		//  Si cest les 3 produits en checkbox,  faut ca soit checker sinon BUBYE.
		if ((idprod == 12 || idprod == 13 || idprod == 14) && !myform.elements[k].checked) { continue; }
		
		
		invoicestring = invoicestring + '<input type=hidden name="produit' + idprod + '" value="'+myform.elements[k].value+' x '+prodname[idprod]+'">';
		
		if (can==1) {
		  		invoicestring = invoicestring + '<input type=hidden name="produitprix' + idprod + '" value="'+prodprixcan[idprod]+'">';  
		} else {
		  		invoicestring = invoicestring + '<input type=hidden name="produitprix' + idprod + '" value="'+prodprixeuro[idprod]+'">';  			
		}
		
			  
		if (idprod==14) {
		  if (can==1) {
		    totalprix = totalprix + (prodprixcan[idprod]* myform.qty_14.value);	
			poids = poids + (prodpoids[idprod]* myform.qty_14.value);	
		  } else {
		  totalprix = totalprix + (prodprixeuro[idprod]* myform.qty_14.value);	
		   poids = poids + (prodpoids[idprod]* myform.qty_14.value);	
		  }
		} 
		else {
		  if (can==1) {
		    totalprix = totalprix + (prodprixcan[idprod]* myform.elements[k].value);	
			poids = poids + (prodpoids[idprod]* myform.elements[k].value);	
		  } else {
		  totalprix = totalprix + (prodprixeuro[idprod]* myform.elements[k].value);	
		   poids = poids + (prodpoids[idprod]* myform.elements[k].value);	
		  }
		}
		
	   //alert(poids);
	    
		// Si on ship Canada.
		if (window.document.orderform.reglement[0].checked) {
		  nbritem++;
		  if (prodlivre[idprod]==1) {
            if (idprod==14) {		  
		      tps = tps + ((prodprixcan[idprod]* myform.qty_14.value)*0.05);
			} else {
			  tps = tps + ((prodprixcan[idprod]* myform.elements[k].value)*0.05);
			}
		  } else {
		    if (idprod==14) {		  
		      			tps = tps + ((prodprixcan[idprod]* myform.qty_14.value)*0.05);
			temptps = ((prodprixcan[idprod]* myform.qty_14.value)*0.05);
			tvq = tvq + (((prodprixcan[idprod]* myform.qty_14.value)+temptps)*0.095);
			} else {
			  			tps = tps + ((prodprixcan[idprod]* myform.elements[k].value)*0.05);
			temptps = ((prodprixcan[idprod]* myform.elements[k].value)*0.05);
			tvq = tvq + (((prodprixcan[idprod]* myform.elements[k].value)+temptps)*0.095);
			}

		  }	
		}
		
	    // Si on calcule au poids ou les fameux CDs
		  if (priceship[idprod]==0) {
		    onlypriceship=0;  
		  }
		  if (priceship[idprod]==1) {
		    if (can==1){
			  livraison = livraison+2;	
			} else {
			  livraison=5;	
			}
		  }
		  
	  }
	}
    
	poids = poids + (poids * 0.20); 
	
	//alert(poids);
	
	if (!onlypriceship) {
	  if (can==1){
	    livraison = 10;	  
	  } 
	  else {
		if (poids<=2000) {
		  livraison = 33; 	
		}
		if (poids<=1000) {
		  livraison = 21; 	
		}
	    if (poids<=500) {
		  livraison = 11; 	
		}
		
		if (poids > 2000) {
		  livraison = 53; 	
		}
	  }
	}
	
	if (can==1) {
	  temptps = livraison * 0.05;
	  tps = tps + temptps;
	  tvq = tvq + ((temptps+livraison)*0.095);
	}
	gtotal = totalprix+livraison+tps+tvq;
  window.document.getElementById('total').innerHTML = totalprix.toFixed(2);
  window.document.getElementById('livraison').innerHTML = livraison.toFixed(2);
  window.document.getElementById('tps').innerHTML = tps.toFixed(2);
  window.document.getElementById('tvq').innerHTML = tvq.toFixed(2);
  window.document.getElementById('grandtotal').innerHTML = gtotal.toFixed(2);


  /*paystring = paystring + '<input type="hidden" name="first_name" value="'+document.orderform.Nom.value.split(' ')[0]+'">';
  paystring = paystring + '<input type="hidden" name="last_name" value="'+document.orderform.Nom.value.split(' ')[1]+'">';
  paystring = paystring + '<input type="hidden" name="address1" value="'+document.orderform.Addresse.value+'">';
  paystring = paystring + '<input type="hidden" name="city" value="'+document.orderform.Ville.value+'">';
  paystring = paystring + '<input type="hidden" name="zip" value="'+document.orderform.zipcode.value+'">';*/
  //paystring = paystring + '<input type="hidden" name="H_PhoneNumber" value="'+document.orderform.Phone.value+'">';
  
  var ppurl = 'www.paypal.com'; 
  var business = 'das@katarosnectar.com';
  //business = 'matt_1285687468_biz@utsn.net';
  paypalurl = 'https://'+ppurl+'/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&business='+business+'&item_name=Paiement en ligne Kataros&item_number=1&amount='+totalprix.toFixed(2)+'&shipping='+livraison.toFixed(2)+'&tax='+(tps+tvq).toFixed(2)+'&notify_url=http://www.katarosnectar.com/postback.php&return_url=http://www.katarosnectar.com/merci.htm';
  
/*
  paystring = paystring + '<input type="hidden" name="item_name" value="Paiement en ligne Kataros">';
  paystring = paystring + '<input type="hidden" name="item_number" value="1">'; 
  paystring = paystring + '<input type="hidden" name="amount" value="' + totalprix.toFixed(2) + '">';
  paystring = paystring + '<input type="hidden" name="shipping" value="' + livraison.toFixed(2) + '">';
  paystring = paystring + '<input type="hidden" name="tax" value="' + (tps+tvq).toFixed(2) + '">';
*/

  if (window.document.orderform.reglement[0].checked) {
	paypalurl = paypalurl + '&currency_code=CAD';
    //paystring = paystring + '<input type="hidden" name="currency_code" value="CAD">';
   // paystring = paystring + '<input type="hidden" name="country_code" value="CA">';
	
	invoicestring = invoicestring + '<input type="hidden" name="Devise" value="CAD">';
	window.document.getElementById('grandtotal').innerHTML = window.document.getElementById('grandtotal').innerHTML + ' $';
  } else {
	paypalurl = paypalurl + '&currency_code=EUR';
   // paystring = paystring + '<input type="hidden" name="currency_code" value="EUR">';
	invoicestring = invoicestring + '<input type="hidden" name="Devise" value="EURO">';
 // paystring = paystring + '<input type="hidden" name="country_code" value="FR">';
	
	window.document.getElementById('grandtotal').innerHTML = window.document.getElementById('grandtotal').innerHTML + ' EURO';	
  }
  
  if (window.document.orderform.methode_paiement[0].checked) {
      invoicestring = invoicestring + '<input type="hidden" name="MethodePaiement" value="Paypal">';	
  } else {
  	
      invoicestring = invoicestring + '<input type="hidden" name="MethodePaiement" value="Cheque">';	  
  }
	
  invoicestring = invoicestring + '<input type="hidden" name="ValeurTotale" value="' + totalprix.toFixed(2) + '">';
  invoicestring = invoicestring + '<input type="hidden" name="FraisLivraison" value="' + livraison.toFixed(2) + '">';
  invoicestring = invoicestring + '<input type="hidden" name="TPS" value="' + tps.toFixed(2) + '">';
  invoicestring = invoicestring + '<input type="hidden" name="TVQ" value="' + tvq.toFixed(2) + '">';
  
  invoicestring = invoicestring + '<input type="hidden" name="Total" value="' + gtotal.toFixed(2) + '">';
  invoicestring = invoicestring + '<input type="hidden" name="Date" value="' + today + '">';
  
  coord = coord + '<input type="hidden" name="Nom" value="' + window.document.orderform.Nom.value + '">';
  coord = coord + '<input type="hidden" name="Email" value="' + window.document.orderform.Email.value + '">';
  coord = coord + '<input type="hidden" name="Phone" value="' + window.document.orderform.Phone.value + '">';
  coord = coord + '<input type="hidden" name="Addresse" value="' + window.document.orderform.Addresse.value + '">';
  coord = coord + '<input type="hidden" name="Ville" value="' + window.document.orderform.Ville.value + '">';
   coord = coord + '<input type="hidden" name="CodePostal" value="' + window.document.orderform.zipcode.value + '">';
  coord = coord + '<input type="hidden" name="Province" value="' + window.document.orderform.Province.value + '">';
  coord = coord + '<input type="hidden" name="Pays" value="' + window.document.orderform.Pays.value+'">';
  
  
  invoicestring = invoicestring + '<input type="hidden" name="Commentaires" value="' + window.document.orderform.Commentaires.value + '">';
  invoicestring = coord + invoicestring;
  
  

  //window.document.getElementById('paypaladd').innerHTML = paystring;
  window.document.getElementById('invoiceadd').innerHTML = invoicestring;

   paypalurl = paypalurl + '&return=http://www.katarosnectar.com/merci.htm';
  
  }
  
  
  
  function submitPayPal() {
                        var _target = document.paypal.target;
                        document.paypal.action ='https://www.paypal.com/cgi-bin/webscr';
                        document.paypal.target = '_blank';
                        document.paypal.submit();
                        document.paypal.target = _target;
                        return false;
 }
  
  
  

