function QuickTrack(){
	if(document.tracking_form.tracking_courier.selectedIndex == 0) {
		document.getElementById("tracking_BMC").style.display = 'block';		
		document.getElementById("tracking_number").style.display = 'none';		
	} else {
		document.getElementById("tracking_BMC").style.display = 'none';		
		document.getElementById("tracking_number").style.display = 'block';		
	};
}

function PrintMe(){
	window.print();
}

function money(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function CVC(){
	window.open ("cvc.php","CVC","status=0,toolbar=0,menubar=0,resizable=1,width=252,height=142");
}

function CVC_calc(){
	D = document.getElementById("D").value;
	H = document.getElementById("H").value;
	W = document.getElementById("W").value;
	//pcs = document.getElementById("pcs").value;
	//lbs = document.getElementById("lbs").value;
	vol = D*H*W/166;
	cft = D*H*W/1728;
	document.getElementById("vol").value = Math.round(vol*1000)/1000;
	document.getElementById("cft").value = Math.round(cft*1000)/1000;
}

function showhide(){
	cb_d2d = document.getElementById("cb_d2d").checked;
	if (cb_d2d == true) {
		document.getElementById("T2").style.display = 'block';
	} else {
		document.getElementById("T2").style.display = 'none';
	}
}

function showhide2(x) {
	document.getElementById(x).style.display = (document.getElementById(x).style.display=='block') ? 'none' : 'block';
}

// -----------------------------------------------
// -----------------------------------------------
// -----------------------------------------------
function calculate_m(){

	// only for MIA-SDQ
	if( document.getElementById("origin").value != "Miami" || document.getElementById("destination").value != "Santo Domingo" ){
		return;
	}

	// calculate the weight
	WEIGHT = document.getElementById("weight").value;
	W = WEIGHT * 0.08;
	if (W<85) W=85;

	// calculate the cubic footage
	CFT = document.getElementById("cft").value;
	C = CFT * 1.70;
	if (C<85) C=85;

	// get the dollar value
	USD = document.getElementById("value").value;

	// calculate the hidden element
	HE = WEIGHT * 0.08 / 1.70
	if (CFT>HE) HE=CFT;

	// -----------------------------------------------

	// ocean_freight
	if (C-W>0) OF=C;
	else OF=W;
	document.getElementById("ocean_freight_value").innerHTML=money(OF);

	// security
	SEC1 = CFT * 0.08;
	document.getElementById("security_price").innerHTML=money(SEC1);
	SEC2 = HE * 0.08;
	document.getElementById("security_price").innerHTML=money(SEC2);
	if (SEC2<10) SEC2=10;
	document.getElementById("security_value").innerHTML=money(SEC2);

	// insurance
	INS = USD * 0.01;
	if (INS<10) INS=10;
	document.getElementById("insurance_value").innerHTML=money(INS);
	
	// BL?
	BL = 50;
	document.getElementById("bl_value").innerHTML=money(BL);
	
	// SED?
	if (USD>=2500) SED=50;
	else SED=0;
	document.getElementById("sed_value").innerHTML=money(SED);
	
	// unloading
	UNL = HE * 0.2;
	document.getElementById("unloading_price").innerHTML=money(UNL);
	if (UNL<25) UNL=25;
	document.getElementById("unloading_value").innerHTML=money(UNL);
	
	// manifest
	MAN = 10;
	document.getElementById("manifest_value").innerHTML=money(MAN);

	// door 2 port
	d2p = OF + SEC2 + INS + BL + SED + UNL + MAN;
	document.getElementById("door2port_value").innerHTML = money(d2p);

	// -----------------------------------------------

	// storage
	ST = 100;
	document.getElementById("storage_value").innerHTML=money(ST);

	// handling
	if (WEIGHT<501) HA = 500 * 0.03125;
	else if (WEIGHT<751) HA = 750 * 0.03125;
	else if (WEIGHT<1001) HA = 1000 * 0.03125;
	else if (WEIGHT<2001) HA = 2000 * 0.02343;
	else if (WEIGHT<3001) HA = 3000 * 0.02083;
	else if (WEIGHT<5001) HA = 5000 * 0.01875;
	else if (WEIGHT<10001) HA = 10000 * 0.0125;
	else if (WEIGHT<20001) HA = 20000 * 0.0104;
	else HA = 0;
	document.getElementById("handling_value").innerHTML=money(HA);

	// door 2 door
	d2d = d2p + ST + HA;
	document.getElementById("door2door_value").innerHTML = money(d2d);
}

// -----------------------------------------------
// -----------------------------------------------
// -----------------------------------------------
function calculate_a(){

	// only for MIA-SDQ
	if( document.getElementById("origin").value != "Miami" || document.getElementById("destination").value != "Santo Domingo" ){
		return;
	}
	
	if ((document.getElementById("netweight").value == "")||(document.getElementById("value").value == ""))
	{
		document.getElementById("door2port_value").value = "";
		return;
	}

	// calculate the net weight
	NETWEIGHT = document.getElementById("netweight").value;
	NW = NETWEIGHT * 2.00;
	if (NW<85) NW=85;

	// calculate the volume weight
	VOLWEIGHT = document.getElementById("volweight").value;
	VW = VOLWEIGHT * 2.00;
	if (VW<85) VW=85;

	// get the dollar value
	USD = document.getElementById("value").value;

	// calculate the hidden element
	HE = NETWEIGHT * 2.00 / 2.00
	if (VOLWEIGHT>=HE) HE=VOLWEIGHT;

	// -----------------------------------------------

	// air_freight
	if (VW-NW>0) AF=VW;
	else AF=NW;
	document.getElementById("air_freight_value").innerHTML=money(AF);
	
	// dga
	DGA1 = 0.22;
	document.getElementById("dga_price").innerHTML=money(DGA1);
	DGA2 = 0;
	if (USD > 200) DGA2 = DGA1 * NETWEIGHT;
	document.getElementById("dga_value").innerHTML=money(DGA2);

	// insurance
	INS = USD * 0.01;
	if (INS<10) INS=10;
	document.getElementById("insurance_value").innerHTML=money(INS);
	
	// Fuel
	FUEL1 = 0.30;
	document.getElementById("fuel_price").innerHTML=money(FUEL1);
	FUEL2 = FUEL1 * NETWEIGHT;
	document.getElementById("fuel_value").innerHTML=money(FUEL2);
	
	// SED
	if (USD>=2500) SED=50;
	else SED=0;
	document.getElementById("sed_value").innerHTML=money(SED);
	
	// door 2 port
	d2p = AF + DGA2 + INS + FUEL2 + SED
	document.getElementById("door2port_value").innerHTML = money(d2p);
}

function calculate_x(){

    delivery_charge = 160;
    exchange_rate = 36.5;
	
	if ((document.getElementById("netweight").value == "")||(document.getElementById("value").value == ""))
	{
		document.getElementById("door2port_value").value = "";
		return;
	}

	// calculate the net weight
	NETWEIGHT = document.getElementById("netweight").value;

	// get the dollar value
	VALUE = document.getElementById("value").value;

	// what rate to use 
	
	PRICE=0;
	if (NETWEIGHT < 5000) PRICE=0.99;
	if (NETWEIGHT < 30) PRICE=2.75;
	if (NETWEIGHT < 20) PRICE=2.95;
	if (NETWEIGHT < 0) PRICE=0;

	// -----------------------------------------------

	// air_freight
	var AF = NETWEIGHT * PRICE;
	
	// dga
	var DGA = NETWEIGHT * 0.12;

	// AP Fee
	var APFEE = NETWEIGHT * 0.06;
	
	// Fuel
	var FUEL = NETWEIGHT * 0.25;

	// SED
	if (VALUE>=2500) {var SED=15;}
	else {var SED=0;}

	// insurance
	var INS = VALUE * 0.015;
	if (INS<10) INS=10;
	
	// ITBIS
	var ITBIS = AF * 0.16;

	// Total (door-to-port)
	    if (document.getElementById("delivery").checked )
        DEL = delivery_charge;
       else DEL = 0;
	   
    // door 2 port
    d2p = (AF + DGA + APFEE + FUEL + SED + INS + ITBIS) * exchange_rate + DEL;
	document.getElementById("door2port_value").value = money(d2p);

}



// -----------------------------------------------
// -----------------------------------------------
// -----------------------------------------------
//function mia_sdq() {
//	if( document.getElementById("origin").value != "Miami" || document.getElementById("destination").value != "Santo Domingo" ){
//		alert("Esta calculadora sólo funciona para envíos con origen en Miami, USA y destino en Santo Domingo, RD.");
//		return true;
//	} else {
//		return false;
//	}
//}
