$(document).ready(function(){
        /** pop **/

/*
	$('.fAmount').click(function() {
		//document.getElementById('submit_liqpay').disabled = true
		$('.submit_liqpay').attr("disabled","disabled");

	})
*/
	//When you click on a link with class of poplight and the href starts with a #
	$('#liqpaq_reload').click(function() {

	var el_input = document.getElementById('fAmount')
	var el_submit = document.getElementById('submit_liqpay')


	var onLoadError = function(error) {
        var msg = "Ошибка "+error.errcode
        if (error.message) msg = msg + ' :'+error.message
        alert(msg)
    }
    
    var showLoading = function(on) {
        el_input.disabled = on
		el_submit.disabled = on
			if(on)
				$('#loading').addClass('loading');
			else
				$('#loading').removeClass();
    }

	var onLoaded = function(data){
	 
	 $('#liqpaq_form').html(data);

	}

    var onSuccess = function(data) {
		showLoading(false)
        if (!data.errcode) {
            onLoaded(data)

        } else {
           
            onLoadError(data)            
        }
    }
    
    
    var onAjaxError = function(xhr, status){
        showLoading(false)
        var errinfo = { errcode: status }
        if (xhr.status != 200) {
            errinfo.message = xhr.statusText
        } else {
            errinfo.message = 'Некорректные данные с сервера'
        }
        onLoadError(errinfo)
    }



		var orderID = $('#orderID').val(); //Get orderID
		var fAmount = $('#fAmount').val(); //Get fAmount
		var comment = $('#comment').val(); //Get fAmount

		if(comment!='')
			comment = '&comment='+comment;
		else
			comment = '';

		var load = function(url) {
				showLoading(true)

				$.ajax({ 
					url: 'http://copybrand.com.ua/prices/ajax_liqpay.php?orderID='+orderID+'&fAmount='+fAmount+comment,
					dataType: "text",
					success: onSuccess,
					error: onAjaxError,
					cache: false
				})
			}


		load();


	});


});

	function disSub() {
	$('#submit_liqpay').attr("disabled","disabled");
	}
