// Copyright 1999,2000 Roman Krzyzanowski / intermedien GmbH, Nuernberg
//
var isBasketLoaded = false;
var SSL = false;
var backToShopURL = new String("home.html");
var items = new Array();
var nrOfItems = 0;
var versand = 0;
var nachnahme = 0;
var orderitems = new String("");
var orderpaymethod = new String("");
var Kunde = new customer('','','','','','','','','','','','','',0,'',0,'','','','','','','','','','');
var Bestellung = new order('','','','','','','','','');
var orderWindow;
var shipuid_inland = new Array();
var shipuid_ausland = new Array();
var vatitems = new Array();
vatitems[vatitems.length] = new vat(0,'','','aucune','0',0);
vatitems[vatitems.length] = new vat(1,'','','Logiciels et papiers','20.6',0);
vatitems[vatitems.length] = new vat(2,'','','Livres','5.5',0);
vatitems[vatitems.length] = new vat(4,'','','Port','20.6',0);

function showBasket(location) {
  var pos = location.pathname.lastIndexOf('/');
  if (pos != -1) {
    backToShopURL = location.pathname.substring(pos+1,location.pathname.length);
  }  
  window.main_frame.location = "basket.html";
}

function getURL(filename) {
  var url = new String(filename);
  if (document.location.protocol == 'https:') {
    if (filename == 'basket.html') {
      alert('Vous ne pouvez pas afficher le contenu du panier pendant l\'opération de commande.');
    }
    else if (filename == 'home.html') {
      if (confirm('ATTENTION : vous quittez le serveur sécurisé !\n\nVotre commande va être annulée et votre panier vidé !')) {
        url = 'http://http:/www.lecygne.com/';
        self.location = url;
      }
    }  
  } else {
    window.main_frame.location = url;
  }
}

function browser() {
  var b = new String("unknown");
  if (navigator.appName == "Netscape")
    b = "NN" + navigator.appVersion.charAt(0)
  else if (navigator.appName == "Microsoft Internet Explorer")
         b = "MSIE" + navigator.appVersion.charAt(0);
  return b;         
}

function checknum(str) {
  if (str == "") {
    alert("Veuillez indiquer une valeur comprise entre 0 et 10.")
    return false
  }
  for (var i = 0; i < str.length; i++) {
    var ch = str.substring(i, i + 1)
    if (ch < "0" || ch > "9") {
      alert("Veuillez indiquer une valeur comprise entre 0 et 10.")
      return false
    }
  }
  return true
}

function StringToFloat(str) {
  var s = new String("");
  if (str.indexOf(",") >= 0) {
    s = str.substring(0, str.indexOf(",")) + "." + str.substring(str.indexOf(",")+1, str.length);
  } else s = str;  
  return(parseFloat(s));
}

var eurokurs = StringToFloat('6.55957');

function convdec(str) {
  if (str == 0) {
    return "0,00";
  } else {
    var s = "" + Math.round(str * 100);
    return(s.substring(0, s.length-2) + "," + s.substring(s.length-2, s.length));
  }
}

function position(artnr) {
  var j = -1;
  for (var i = 0; i < items.length; i++) {
    if (items[i].artnr == artnr) {
	    j = i;
    }
  }
  return j;  
}

function posname(name) {
  var j = -1;
  for (var i = 0; i < items.length; i++) {
    if (items[i].name == name) {
	    j = i;
    }
  }
  return j;  
}

function getNrOfItems() {
  var j = 0;
  for (var i = 0; i < items.length; i++) {
    j += items[i].qty;
  }  
  return j;  
}

function vat(vid,vstateshort,vstatelong,vname,vvalue,vtotal) {
  this.vid = vid;
  this.vstateshort = vstateshort;
  this.vstatelong = vstatelong;
  this.vname = vname;
  this.vvalue = StringToFloat(vvalue);
  this.vtotal = vtotal;
}

function item(artnr,name,price,qty,uid,image) {
  this.artnr = artnr;
  this.name = name;
  this.price = price;
  this.qty = qty;
  this.uid = uid;
  this.image = image;      
}

function customer(anrede,vorname,nachname,zusatz,firma,strasse,plz,ort,land,telefon,email,
                  sendemail,shipto,shipcost,shiptext,shipuid,paymethod,cc,ccvalid,ccnr,
				  cccustname,bank,bankktonr,bankblz,bankcustname,bemerkung)
{
  this.anrede = anrede;
  this.vorname = vorname;
  this.nachname = nachname;
  this.zusatz = zusatz;
  this.firma = firma;
  this.strasse = strasse;
  this.plz = plz;
  this.ort = ort;
  this.land = land;
  this.telefon = telefon;
  this.email = email;
  this.sendemail = sendemail;
  this.shipto = shipto;
  this.shipcost = shipcost;
  this.shiptext = shiptext;
  this.shipuid = shipuid;
  this.paymethod = paymethod;
  this.cc = cc;
  this.ccvalid = ccvalid;
  this.ccnr = ccnr;
  this.cccustname = cccustname;
  this.bank = bank;
  this.bankktonr = bankktonr;
  this.bankblz = bankblz;
  this.bankcustname = bankcustname;
  this.bemerkung = bemerkung;
}

function order(paymethod,items,subtotal,delivery,cod,total,euro,vat,paymethodshort) {
  this.paymethod = paymethod;
  this.items = items;
  this.subtotal = subtotal;
  this.delivery = delivery;
  this.cod = cod;
  this.total = total;
  this.euro = euro;      
  this.vat = vat;
  this.paymethodshort = paymethodshort;      
}

function initBasket(redirect,timeout) {
  var danke = false;
  var ret = false;
  var mailScript = true;
  var msgTxt = new String("Les informations vont être transmises par e-mail grâce au service de traitement automatique mis en place par Micro Application. Ce service ne contrôle ni n\'enregistre aucune donnée contenue dans cet e-mail.\n\nCes informations ne sont ni cryptées ni sécurisées. Elles sont susceptibles d\'être interceptées par un tiers.\n\nVous pouvez poursuivre ou annuler cette opération.");
  var mailscripturl = 'http://microapp.internet-fr.net/mailscript/mws_mail.cgi';
/*  if (navigator.javaEnabled() == true) {
    if (navigator.userAgent.indexOf('Mac') == -1) {
      if (window.main_frame.document.mailer.send()) {
	    danke = true;
      } else {
	    mailScript = true;
  	  }
	} else {
	  mailScript = true;
	}  
  } else {
    mailScript = true;
  }*/
  if (mailScript == true) {
	if (mailscripturl == 'http://microapp.internet-fr.net/mailscript/mws_mail.cgi') {
  	  if (confirm(msgTxt)) { 
        ret = true;
        danke = true;
	  }
	} else {
      ret = true;
  	  danke = true;
	}
  }
  if (ret == true) {
    var orderWin=window.open("", "OrderWindow", "scrollbars=yes,width=300,height=100");
  }	
  for (var i = 0; i < items.length; i++) {
    items[i].qty = 0;
  }
  nrOfItems = 0;
  if (danke == true) {
    if (redirect != '') {
	  window.main_frame.location=redirect;
    }
  }	  
  return ret;
}

function cancelOrder() {
  if (document.location.protocol == 'https:') {
    self.location = 'http://http:/www.lecygne.com/';
  } else {
    for (var i = 0; i < items.length; i++) {
      items[i].qty = 0;
    }
    nrOfItems = 0;
    window.main_frame.location = 'home.html';
  }
  alert("Votre commande est annulée !");  
}

function addToBasket(form) {
//  for (v
