function OpenConverter (cur, amount) {
	var url = "http://www.xe.com/ucc/convert.cgi?template=pca-new&Amount="+amount+"&From=EUR&To="+cur;
//	window.open(url);
	window.location = url;
}
function createArray(size) {
 for (var i=0; i < size; i++) {
  	this[i] = null
  }
 return this;
}

function Product(ponum, frdesc, endesc, price, weight) {
 this.ponum = ponum;
 this.endesc = endesc;
 this.frdesc = frdesc;
 this.price = price;
 this.weight = weight;
}

function AddProduct(ponum, frdesc, endesc, price, weight) {
	product[nProduct++] = new Product(ponum, frdesc, endesc, price, weight);
}

function Carrier(name, p2, p8, i10, i21, i45) {
 this.title = name;
 this.p2 = p2;
 this.p8 = p8;
 this.i10 = i10;
 this.i21 = i21;
 this.i45 = i45;
}

function SetLengths() {
  product.length = j;
}

function CarrierNum (selin) {
	switch (selin) {
		case "0": return 0;
		case "1": return 2;
		case "2": return 3;
		case "3": return 4;
		case "4": return 5;
		case "A": return 6;
		case "B": return 7;
		case "C": return 8;
		case "D": return 9;
		case "E": return 10;
		case "F": return 11;
		default: return -1;
	}
}

function EvalShipCost() {
	if (net_weight == 0) {
			shipCost = 0;
			return;
	}
	var gw = net_weight+1;
	if (gw > 70.0) {
		shipCost = -1;
		return;
	}
	var cn = CarrierNum(document.form1.destCountry.value);
	if (cn==0 && document.form1.paris[1].checked) cn = 1; // regional
	if (cn < 0) {
		shipCost = -1;
		return;
	}	
	var a = (carrier[cn].p8 - carrier[cn].p2)/6;
	var b = carrier[cn].p2 - a*2;
	if (gw <= 10.0) {
		shipCost = gw*a + b;
	} 
	else if (gw <= 21) {
		shipCost = 10*a + b;
		shipCost += (gw-10)*2*carrier[cn].i10;
	}
	else if (gw <= 45){
		shipCost = 10*a + b + 22*carrier[cn].i10;
		shipCost += (gw-21)*2*carrier[cn].i21;
	}
	else {
		shipCost = 10*a + b + carrier[cn].i10*22 + carrier[cn].i21*48;
		shipCost += (gw-45)*2*carrier[cn].i45;
	}
	shipCost *= fuelSurcharge;
}

function update(num) {
	eval('selected = document.form1.menu'+num+'.selectedIndex;');
	eval('q_selected = document.form1.quantity'+num+'.selectedIndex;');
	eval('quant = document.form1.quantity'+num+'.options[q_selected].value;');
	var cost = fix(product[selected].price * quant);
	var pu = fix(product[selected].price);
	eval('document.form1.pu'+num+'.value = pu');
	eval('document.form1.tot'+num+'.value = cost;');
	weight[num] = product[selected].weight * quant;
	var sub_total = 0;
	net_weight = 0;
	for (i=1; i <= 6; i++){
		eval('sub_total += parseFloat(document.form1.tot' + i + '.value);');
		net_weight += weight[i];
	}
	shipCost = 0;
	if (sub_total > 0 && net_weight > 0)
		EvalShipCost();
	if (shipCost < 0) {
		shipCost = 0.0;
		document.form1.shippingcost.value = "??????????????";
	}
	else {
		document.form1.shippingcost.value = fix(shipCost);
	}
	sub_total += shipCost;
	sub_total = fix(sub_total);
	document.form1.subtotal.value = sub_total;
	var wtaxes = fix(sub_total * .196 + 0.005); 
	if (document.form1.destCountry.value =="0") {
		document.form1.taxes.value = wtaxes;
		document.form1.grandtotal.value = fix(eval(sub_total)+ eval(wtaxes));
	} else {
		document.form1.taxes.value = "0.00";
		document.form1.grandtotal.value = sub_total;
	}
	eval('document.form1.model'+num+'.value=document.form1.menu'+num+'.options[selected].text;');
}

function fix(num) {
	 string = "" + num;
	 if (string.indexOf('.') == -1)
	  return string + '.00';
	 separation = string.length - string.indexOf('.');
	 if (separation > 3)
	  return string.substring(0,string.length-separation+3);
	 else if (separation == 2)
	  return string + '0';
	 return string;
}

function emailko(email){
     var pos=email.indexOf("@");
     if (pos==-1 || pos==0 || pos==email.length-1)return true;
     return false;
}

function createEnLists() {
	for (iprod=1; iprod<nProduct; iprod++) {
		if (product[iprod].ponum == "-")
			var libel = "-----------------------------------------------------------";
		else
			libel = product[iprod].ponum +" : "+product[iprod].endesc;
			
		document.form1.menu1[iprod]=new Option(libel, iprod);
		document.form1.menu2[iprod]=new Option(libel, iprod);
		document.form1.menu3[iprod]=new Option(libel, iprod);
		document.form1.menu4[iprod]=new Option(libel, iprod);
		document.form1.menu5[iprod]=new Option(libel, iprod);
		document.form1.menu6[iprod]=new Option(libel, iprod);
	}
}
function createFrLists() {
	for (iprod=1; iprod<nProduct; iprod++) {
		if (product[iprod].ponum == "-")
			var libel = "-----------------------------------------------------------";
		else
			libel = product[iprod].ponum +" : "+product[iprod].frdesc;
			
		document.form1.menu1[iprod]=new Option(libel, iprod);
		document.form1.menu2[iprod]=new Option(libel, iprod);
		document.form1.menu3[iprod]=new Option(libel, iprod);
		document.form1.menu4[iprod]=new Option(libel, iprod);
		document.form1.menu5[iprod]=new Option(libel, iprod);
		document.form1.menu6[iprod]=new Option(libel, iprod);
	}
}

function createQtys(num) {
	var i;
	for (i=0; i<=num; i++) {
		document.form1.quantity1[i]=new Option(i,i);
		document.form1.quantity2[i]=new Option(i,i);
		document.form1.quantity3[i]=new Option(i,i);
		document.form1.quantity4[i]=new Option(i,i);
		document.form1.quantity5[i]=new Option(i,i);
		document.form1.quantity6[i]=new Option(i,i);
	}
}

function showLocations() {
	if (document.form1.destCountry.value == "0")
		document.getElementById("locparis").style.display="";
	else 
		document.getElementById("locparis").style.display="none";
}

var product = new createArray(1);
var nProduct = 0;
AddProduct("select"             ,"selection"                               ,"select"                                 ,  0.00     ,0.000);

//          reference            french description                         english description                       price       weight
//------------------------------------------------------------------------------------------------------------------------------------
AddProduct("PROATM-V155F"       ,"ATM155, PCI, fib opt multimode 2km"      ,"ATM155, PCI, fib opt multimode 2km"     ,590.00     ,0.500);
AddProduct("PROATM-V155FM"      ,"ATM155, PCI, fib opt monomode 15km"      ,"ATM155, PCI, fib opt singlemode 15km"   ,650.00     ,0.500);
AddProduct("PROATM-V155FLH"     ,"ATM155, PCI, fib opt monomode 40km"      ,"ATM155, PCI, fib opt singlemode 40km"   ,690.00     ,0.500);
AddProduct("PROATM-E155F"       ,"ATM155, PCIe, fib opt multimode 2km"     ,"ATM155, PCIe, fib opt multimode 2km"    ,630.00     ,0.500);
AddProduct("PROATM-E155FM"      ,"ATM155, PCIe, fib opt monomode 15km"     ,"ATM155, PCIe, fib opt singlemode 15km"  ,690.00     ,0.500);
AddProduct("PROATM-E155FLH"     ,"ATM155, PCIe, fib opt monomode 40km"     ,"ATM155, PCIe, fib opt singlemode 40km"  ,730.00     ,0.500);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("K5DS-BR8"           ,"Broadcaster DSNet 8 ports"               ,"8-port DSNet Broadcaster"               ,290.00      ,2.800);
AddProduct("K5DS-BR16"          ,"Broadcaster DSNet 16 ports"              ,"16-port DSNet Broadcaster"              ,420.00      ,2.800);
AddProduct("K5DS-SP8"           ,"Splitter DSNet 8 ports"                  ,"8-port DSNet Splitter"                  ,220.00      ,1.100);
AddProduct("K5DS-RC2"           ,"Récepteur DSNet pour 2 écrans"           ,"DSNet Receiver for 2 Monitors"          ,179.00      ,0.900);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("PRIMA-4"            ,"KVM, 4 ports USB/PS2 avec OSD"           ,"4-port USB/PS2 with OSD"                ,185.00     ,3.000);
AddProduct("PRIMA-8"            ,"KVM, 8 ports USB/PS2 avec OSD"           ,"8-port USB/PS2 with OSD"                ,236.00     ,3.000);
AddProduct("PRIMA-16"           ,"KVM, 16 ports USB/PS2, avec OSD"         ,"16-port USB/PS2 with OSD"               ,320.00     ,3.200);
AddProduct("CAB-2067-1.8M"      ,"Câble 1.8m pour KVM PRIMA et PRIMA-IP"   ,"1.8m cable for PRIMA and PRIMA-IP"      ,10.00      ,0.500);
AddProduct("CAB-2067-3M"        ,"Câble 3m pour KVM PRIMA et PRIMA-IP"     ,"3m cable for PRIMA and PRIMA-IP"        ,14.00      ,0.800);
AddProduct("CAB-2067-5M"        ,"Câble 5m pour KVM PRIMA et PRIMA-IP"     ,"5m cable for PRIMA and PRIMA-IP"        ,20.00      ,1.250);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("PRIMA IP-8"         ,"KVM IP SSL, 8 ports USB/PS2"             ,"8-port IP SSL KVM"                      ,599.00     ,3.200);
AddProduct("PRIMA IP-16"        ,"KVM IP SSL, 16 ports USB/PS2"            ,"16-port IP SSL KVM"                     ,699.00     ,3.400);
AddProduct("PROKLE"             ,"Contrôle à distance IP SSL"              ,"IP SSL Remote Control"                  ,449.00     ,2.000);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("K5EXT300"           ,"Déport cat5 300m KVM/audio/port COM"     ,"300m cat5 KVM/audio/COM-port extender"  ,479.00     ,3.000);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("IOPOWER"            ,"Gestion d'alimentation par RS232"        ,"Power Control over RS232"               ,180.00     ,3.000);
AddProduct("IOPOWER.NET-EU"     ,"Gestion d'alimentation par IP"           ,"Remote Power Control over IP"           ,390.00     ,3.000);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("PROK-104"           ,"KVM PS2 4 ports"                         ,"4-port PS2 KVM"                         ,169.00     ,2.300);
AddProduct("PROK-108"           ,"KVM PS2 8 ports"                         ,"8-port PS2 KVM"                         ,215.00     ,3.200);
AddProduct("PROK-104o"          ,"KVM PS2 4 ports avec OSD"                ,"4-port PS2 KVM with OSD"                ,166.00     ,2.300);
AddProduct("PROK-108o"          ,"KVM PS2 8 ports avec OSD"                ,"8-port PS2 KVM with OSD"                ,239.00     ,3.200);
AddProduct("PROK-116o"          ,"KVM PS2 16 ports avec OSD"               ,"16-port PS2 KVM with OSD"               ,360.00     ,5.200);
AddProduct("CAB-180"            ,"Câble 1.8m pour PROK"                    ,"1.8m PROK cable"                        , 18.72     ,0.520);
AddProduct("CAB-300"            ,"Câble 3m pour PROK"                      ,"3m PROK cable"                          , 24.96     ,0.800);
AddProduct("CAB-500"            ,"Câble 5m pour PROK"                      ,"5m PROK cable"                          , 35.36     ,1.250);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("DVI202AU"           ,"KVM DVI USB 2 ports avec câbles (1.20m)" ,"2-port USB DVI KVM with 1.2m cables"    ,99.00      ,1.500);
AddProduct("DVI204AU"           ,"KVM DVI USB 4 ports avec câbles (1.80m)" ,"4-port USB DVI KVM with 1.8m cables"    ,102.00     ,2.000);
AddProduct("-"," ", " ", 0 , 0);
AddProduct("PROEXPERT-100WL"    ,"Carte Ethernet 10-100 Chipset AMD"       ,"Ethernet card with AMD chipset"         , 29.00     ,0.500);
 

product.length = nProduct;

var weight = new createArray(7);
weight[0] = 0;
weight[1] = 0;
weight[2] = 0;
weight[3] = 0;
weight[4] = 0;
weight[5] = 0;
weight[6] = 0;

var carrier = new createArray(12);
carrier[0] = new Carrier("Regional", 10.15, 13.45, 0.1875, 0.1875, 0.1875);
carrier[1] = new Carrier("National", 12.15, 16.85, 0.225, 0.225, 0.225)
carrier[2] = new Carrier("Fedex1", 60.5, 111.2, 2.2, 1.6, 1.4);
carrier[3] = new Carrier("Fedex2", 153.7, 296.6, 13.5, 10.6, 10.1);
carrier[4] = new Carrier("Fedex3", 119.0, 151.3, 4.5, 3.6, 4.1);
carrier[5] = new Carrier("Fedex4", 165.2, 323.4, 13.9, 11.7, 12.1);
carrier[6] = new Carrier("FedexA", 121.2, 176.3, 6.6, 5.3, 5.5);
carrier[7] = new Carrier("FedexB", 161.6, 293.7, 12.9, 11.7, 12.1);
carrier[8] = new Carrier("FedexC", 173.6, 339.0, 14.7, 13.3, 11.6);
carrier[9] = new Carrier("FedexD", 177.2, 345.5, 17.5, 16.0, 15.8);
carrier[10] = new Carrier("FedexE", 185.0, 377.8, 17.5, 16.6, 16.0);
carrier[11] = new Carrier("FedexF", 161.8, 291.7, 12.7, 11.6, 12.2);

var fuelSurcharge = 1.185;
var shipCost = "";
var net_weight = "";
