var httpcheck_shipping_carrier_ajax = getNewHTTPObject();
var httpcheck_product_ajax = getNewHTTPObject();
var httpcheck_shipping_method_ajax = getNewHTTPObject();
var httpcheck_product_delivery_exception_ajax = getNewHTTPObject();

function getNewHTTPObject() {
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    }
	catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    
    return false;
}

function check_shipping_carrier_ajax(status, method_id, address_id, weight, quantity, subtotal, usage) {
   	httpcheck_shipping_carrier_ajax.open("GET","/apps/exchange/commerce/cart/ajax_server.html?call=ping&status="+status+"&method_id="+escape(method_id)+"&address_id="+address_id+"&weight="+weight+"&quantity="+quantity+"&subtotal="+subtotal+"&usage="+usage+"&deliverydate="+document.getElementById("del_date"+address_id).value,true);
   	httpcheck_shipping_carrier_ajax.onreadystatechange = handleHttpcheck_shipping_carrier_ajax;
   	httpcheck_shipping_carrier_ajax.send(null);
}

function check_select_ajax(val,qty) {
   	httpcheck_product_ajax.open("GET","/apps/exchange/commerce/cart/ajax_server.html?status=select&val="+val+"&qty="+qty,true);
   	httpcheck_product_ajax.onreadystatechange = handleHttpcheck_product_ajax;
   	httpcheck_product_ajax.send(null);
}

function check_shipping_method_ajax(country, state, postal, usage, sType) {
   	httpcheck_shipping_method_ajax.open("GET","/apps/exchange/commerce/cart/ajax_server.html?status=method_checking&country="+country+"&state="+state+"&postal="+postal+"&usage="+usage+"&sType="+sType,true);
   	httpcheck_shipping_method_ajax.onreadystatechange = handleHttpcheck_shipping_method_ajax;
   	httpcheck_shipping_method_ajax.send(null);
}

function check_product_delivery_exception_ajax(country, state, postal, usage) {
   	httpcheck_product_delivery_exception_ajax.open("GET","/apps/exchange/commerce/cart/ajax_server.html?status=product_delivery_exception_checking&country="+country+"&state="+state+"&postal="+postal+"&usage="+usage,true);
   	httpcheck_product_delivery_exception_ajax.onreadystatechange = handleHttpcheck_product_delivery_exception_ajax;
   	httpcheck_product_delivery_exception_ajax.send(null);
}

function handleHttpcheck_shipping_carrier_ajax() {
  	if (httpcheck_shipping_carrier_ajax.readyState == 4) {
		//document.writeln(httpcheck_shipping_carrier_ajax.responseText);
    	//Split the comma delimited response into an array
		var shipping_service, address_id, status, instruction, handling_service;

		eval(httpcheck_shipping_carrier_ajax.responseText);
		show_shipping_service_radio(shipping_service, address_id, status, instruction, handling_service);
  	}
}

function handleHttpcheck_redemption_ajax() {
  	if (httpcheck_redemption_ajax.readyState == 4) {
		//document.writeln(httpcheck_redemption_ajax.responseText);
		var valid_code, formname, faction, coupon_code, coupon_name;
		
		eval(httpcheck_redemption_ajax.responseText);
		check_redemption_usage(formname, faction, valid_code, coupon_code, coupon_name);
  	}
}

function handleHttpcheck_product_ajax() {
  	if (httpcheck_product_ajax.readyState == 4) {
		//document.writeln(httpcheck_product_ajax.responseText);
		var msg;
		eval(httpcheck_product_ajax.responseText);
		if (msg.length) {
			qty_check(false, msg);
		}
		else {
			qty_check(true, "");
		}
  	}
}

function handleHttpcheck_shipping_method_ajax() {
  	if (httpcheck_shipping_method_ajax.readyState == 4) {
		//document.writeln(httpcheck_shipping_method_ajax.responseText);
		//Split the comma delimited response into an array
		var allowed;
		eval(httpcheck_shipping_method_ajax.responseText);
		show_shipping_method_alert(allowed);
  	}
}

function handleHttpcheck_product_delivery_exception_ajax() {
  	if (httpcheck_product_delivery_exception_ajax.readyState == 4) {
		var country,state,postal,usage,is_delivery_except_location;
	    eval(httpcheck_product_delivery_exception_ajax.responseText);

		if (is_delivery_except_location == "y") {
			alert(lbl[36329]/*One of your product */);
			return false;
		}
		else {
			check_shipping_method_ajax(country, state, postal, usage, "cart");
		}
  	}
}

