	function invoice_address() {
		var f = document.getElementById("invoice_address_form");
		if (document.getElementById("addressesAreEquals").checked) {
			f.style.display='none';
 		}
		else {
			f.style.display='block';
		} 

	} 


var countries_zones = new Array();
var recentZone = 0;

 function carriers_display(id_country) {
  if (id_country > 0)
  {
   if (recentZone > 0) {
     document.getElementById('zone_'+recentZone).style.display = 'none';
   }
   recentZone = countries_zones[id_country];
   document.getElementById('zone_'+recentZone).style.display = 'block';
  }
 }
 function add_country_zone(id_country, id_zone) {
   countries_zones[id_country] = id_zone;
 }
 function getRadioNum(radioName) {
   var rads = document.getElementsByName(radioName);

   return rads.length;
 }


//fix for IE's getElementsByName
if(typeof(window.external) != 'undefined'){
document.getElementsByName = function(name){
    var elems = document.getElementsByTagName('input');
    var res = []
    for(var i=0;i<elems.length;i++){
        att = elems[i].getAttribute('name');
        if(att == name) {
            res.push(elems[i]);
        }
    }
    return res;
}
} 

 function getRadioVal(radioName) {
   var rads = document.getElementsByName(radioName);

   //fix for IE's 2 radio buttons selected
   var selected_count = 0;
   var selected_radio_value = null;

   for(rad=0;rad<rads.length;rad++) {
     if(rads[rad].checked)
       //return rads[rad].value;
     {
	if (selected_count > 0) {
	  //uncheck already selected value
	  rads[rad].checked = false;
	} else {
	  selected_radio_value = rads[rad].value;
          selected_count++;
	}
     }
   }
   return selected_radio_value;
 }
 function set_carrier(carrier_price) {

   carrier_price = parseFloat(carrier_price.replace(/[^\d,.]/g,'').replace(',','.'));

   //document.getElementById('id_carrier_hidden').value = getRadioVal('id_carrier_zone_'+recentZone);
   if (document.getElementById('id_carrier_hidden') != null) {
    document.getElementById('id_carrier_hidden').value = getRadioVal('id_carrier');
    document.getElementById('id_zone_hidden').value = countries_zones[$('#id_country').val()];
    document.getElementById('price_carrier_hidden').value = carrier_price;
    ajaxShipp.updateShipping($('#id_carrier_hidden').val());
   }

   return true;
 }

function onepage_cartupdate(doc, form, link)
{
  //set_carrier();
  doc.validate_conditions = 'no';
  form.step.value = '2';
  form.cartupdateflag.value = '1';
  form.link.value = link;
  form.submit();
}



var ajaxShipp = {
	
	//override every button in the page in relation to the cart
	overrideButtonsInThePage : function(){

		$('#id_country').unbind('change').change(function(){
			ajaxShipp.country_change_handler(false);
			updateState(); // USA states
		});

	},

	country_change_handler : function(force_display) {
		id_country_x = $('#id_country').val();
		recentZone_x = countries_zones[id_country_x];
		if (recentZone_x != $('#id_zone_hidden').val() || force_display) {
 		  ajaxShipp.updateZonesCarriers(recentZone_x); 
		}
		return false;
	},


	updateShipping : function(shippingId){

		//send the ajax request to the server
		$.ajax({
			type: 'GET',
			url: 'order.php',
			async: true,
			cache: false,
			dataType : "json",
			data: 'ajax_carrier=' + shippingId + '&ajax_zone_id='+countries_zones[$('#id_country').val()],
			success: function(jsonData)
			{
				ajaxCart.refresh();
			//	$('#order-detail-content td.price').val();

				delivery_price = $('#order-detail-content tr.cart_total_delivery td.price').text();
				new_carrier_price = $('#price_carrier_hidden').val();
				total_price = $('#order-detail-content tr.cart_total_price td.price').text();

				has_comma = (total_price.indexOf(',') > 0);
				
				delivery_price_uniform = delivery_price.replace(',','.');
				new_carrier_price_uniform = new_carrier_price.replace(',','.');
				total_price_uniform = total_price.replace(',','.');

				actualTotalShipping = parseFloat(delivery_price_uniform.replace(/[^\d,.]/g,''));
				newTotalShipping = parseFloat(new_carrier_price_uniform.replace(/[^\d,.]/g,''));
				actualTotalPrice =  parseFloat(total_price_uniform.replace(/[^\d,.]/g,''));

				newTotalShippingStr = newTotalShipping.toFixed(2) + '';
				newTotalPrice = (actualTotalPrice - actualTotalShipping + newTotalShipping);
				newTotalPriceStr = newTotalPrice.toFixed(2) + '';

//				alert('[deliver_price_unifomr]actual/newTotalShippingStr = '+delivery_price_uniform+']' +actualTotalShipping +'/'+ newTotalShippingStr);
				newTotalShippingStr = delivery_price_uniform.replace(''+actualTotalShipping.toFixed(2), newTotalShippingStr);
				newTotalPriceStr = total_price_uniform.replace(''+actualTotalPrice.toFixed(2), newTotalPriceStr);

				if (has_comma) {
				  newTotalShippingStr = newTotalShippingStr.replace('.', ',');
			  	  newTotalPriceStr = newTotalPriceStr.replace('.',',');
				}

				$('#order-detail-content tr.cart_total_delivery td.price').html(newTotalShippingStr);// + ' &euro;');
				if (!isNaN(actualTotalShipping)) 
				$('#order-detail-content tr.cart_total_price td.price').html(newTotalPriceStr);// + ' &euro;');
//				alert('success');
								//reactive the button when adding has finished
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				//alert("TECHNICAL ERROR: unable to updateShipping.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
				//alert('ajax_carrier=' + shippingId + '&ajax_zone_id='+countries_zones[$('#id_country').val()]);
			}
		});
	},

	updateZonesCarriers : function(zoneId){
	
		//send the ajax request to the server
		$.ajax({
			type: 'GET',
			url: 'order.php',
			async: true,
			cache: false,
			dataType : "json",
			data: 'zone_carriers=' + zoneId,
			success: function(jsonData)
			{
		//		ajaxCart.refresh();
			//	$('#order-detail-content td.price').val();
				$('#carriers2').html(jsonData.html_data);
				set_carrier(jsonData.selected_price);
			//	alert('success');
								//reactive the button when adding has finished
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				//alert("TECHNICAL ERROR: unable to updateZonesCarriers.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
			}
		});
	}


}//var ajaxShipp


//when document is loaded...
$(document).ready(function(){
	ajaxShipp.overrideButtonsInThePage();
	ajaxShipp.country_change_handler(true);
//	ajaxCart.refresh();
});


