var XMLHttpArray = [
        function() {return new XMLHttpRequest()},
        function() {return new ActiveXObject("Msxml2.XMLHTTP")},
        function() {return new ActiveXObject("Msxml2.XMLHTTP")},
        function() {return new ActiveXObject("Microsoft.XMLHTTP")}
];
function createXMLHTTPObject(){
        var xmlhttp = false;
        for(var i=0; i<XMLHttpArray.length; i++){
                try{
                        xmlhttp = XMLHttpArray[i]();
                }catch(e){
                        continue;
                }
                break;
        }
        return xmlhttp;
}
function AjaxRequest(url,callback,method){
        var req = createXMLHTTPObject();
        req.onreadystatechange= function(){
                if(req.readyState != 4) return;
                if(req.status != 200) return;
                callback(req);
        }
        req.open(method,url,true);
        req.setRequestHeader('User-Agent', 'My XMLHTTP Agent');
        req.send(null);
}

function AjaxTransResponse(req){
	document.getElementById('del_method').options.length = 0;
	$(req).find("record").each(function() {
		var opt = document.createElement('option');
		document.getElementById('del_method').options.add(opt);
		opt.value = $(this).find("value").text();
		opt.text = $(this).find("name").text();
	});
}

function AjaxPaymentResponse(req){
	document.getElementById('pay_type').options.length = 0;
	$(req).find("record").each(function() {
		var opt = document.createElement('option');
		document.getElementById('pay_type').options.add(opt);
		opt.value = $(this).find("value").text();
		opt.text = $(this).find("name").text();
	});
}


function GetTrans(country, amount){	
	$.ajax({
		url: 'http://www.lumidesigns.com/xml/data_combo.php?count=' + country + '&amount=' + amount,
		type: 'GET',
		dataType: 'xml',
		beforeSend: function() {
			$('#proccessing_dialog').show();
		},
		success: AjaxTransResponse,
		complete: function() {
			$('#proccessing_dialog').hide();
		}
	});
}

function GetPayment(country, trans){
	$.ajax({
		url: 'http://www.lumidesigns.com/xml/data_combo2.php?count=' + country + '&trans=' + trans,
		type: 'GET',
		dataType: 'xml',
		beforeSend: function() {
			$('#proccessing_dialog').show();
		},
		success: AjaxPaymentResponse,
		complete: function() {
			$('#proccessing_dialog').hide();
		}
	});
}

function ShowTransRow(){
	var str = document.forms.make_order.del_method.options[document.forms.make_order.del_method.selectedIndex ].text.split(' - ');

	if (str[1] != '') {
		document.getElementById('trans_row').style.display = '';
		document.getElementById('trans_name').innerHTML = str[0];
		document.getElementById('trans_price_total').innerHTML = str[1];
		document.getElementById('trans_price_total2').innerHTML = str[1];
		document.getElementById('total_cart_temp').style.display = '';
		document.getElementById('total_cart').style.display = 'none';

		var temp_sum = parseFloat(document.getElementById('total_cart').innerHTML.replace(' ', '')) + parseFloat(str[1]);

		document.getElementById('total_cart_temp').innerHTML = temp_sum.toFixed(2);
	}
	else
	{
		document.getElementById('trans_row').style.display = 'none';
		document.getElementById('total_cart_temp').style.display = 'none';
		document.getElementById('total_cart').style.display = '';
	}
}


function UseAle(){
	var str = document.forms.make_order.del_method.options[document.forms.make_order.del_method.selectedIndex ].text.split(' - ');

	if (document.getElementById('ale').checked) {
		var temp_sum = parseFloat(document.getElementById('total_cart').innerHTML.replace(' ', '')) - parseFloat(document.getElementById('ale').value);

		document.getElementById('ale_sum').value = parseFloat(document.getElementById('ale').value);

		document.getElementById('total_cart_temp').innerHTML = temp_sum.toFixed(2);
		document.getElementById('total_cart').innerHTML = temp_sum.toFixed(2);
	}
	else
	{
		var temp_sum = parseFloat(document.getElementById('total_cart_temp').innerHTML.replace(' ', '')) + parseFloat(document.getElementById('ale').value);

		document.getElementById('ale_sum').value = 0;

		document.getElementById('total_cart_temp').innerHTML = temp_sum.toFixed(2);
		document.getElementById('total_cart').innerHTML = temp_sum.toFixed(2);
	}
}


function ShowDelivery(){

	var sd = document.getElementById('del_loc').value;
	if (sd == 1) {
		document.getElementById('deliver_address').style.display = 'none';
	}
	else
	{
		document.getElementById('deliver_address').style.display = '';
	}
}

function ShowDelivery2(){

	var sd = document.getElementById('del_loc2').value;
	if (sd == 1) {
		document.getElementById('deliver_address2').style.display = 'none';
	}
	else
	{
		document.getElementById('deliver_address2').style.display = '';
	}
}
