function buscar_cliente(){

	var url = "index.php?option=com_invoices&controller=invoice&task=buscar_cliente&searchword=" + jQuery('#buscar_cliente').val() ;

	jQuery.ajax({
	  url: url,
	  cache: false,
	  context: document.body
	}).done(function(responseText) {

	    jQuery('#log_clientes').html( responseText);
	});

}

function load_contact(resultat){

	for (var property in resultat) {

		if(property != "id") vm.current_invoice[property] = resultat[property];

		if(property == "user_id" && resultat[property] != 0) {
			vm.current_invoice.vincular_cliente_checkbox = 1;
		}
		else if(property == "user_id" && resultat[property] == 0) {
			vm.current_invoice.vincular_cliente_checkbox = 2;
		}
	}

}

function neteja_camps(){

	jQuery("#fields_personal_data input[type='text']").each(function(field, i) {
		jQuery(this).val( "" );
	});
}

function search_items(){

	var url = "index.php?option=com_invoices&controller=invoice&task=search_items&searchword=" + jQuery('#search_items').val() ;

	jQuery.ajax({
	  url: url,
	  cache: false,
	  context: document.body
	}).done(function(responseText) {

	    jQuery('#log_items').html( responseText );
	});

}

function obtain_item(id, component){

	var url = "index.php?option=com_invoices&controller=invoice&task=obtain_item&id=" + id + "&component=" + component ;

	jQuery.ajax({
	  url: url,
	  cache: false,
	  context: document.body
	}).done(function(responseText) {

	    load_item( responseText );
	});

}

function load_item(product, index){

	vm.current_invoice.items[index].name = product.name;
	vm.current_invoice.items[index].desc = product.description;
	vm.current_invoice.items[index].sku = product.sku;
	vm.current_invoice.items[index].amount = product.amount;
	vm.current_invoice.items[index].tax = product.tax;
	vm.current_invoice.items[index].external_type = product.external_type;
	vm.current_invoice.items[index].value = product.value;
	vm.current_invoice.items[index].product_id = product.product_id;

}

function set_tab(tab){
	current_tab = tab;
	document.getElementById("adminForm_modal").tab.value = tab;
}
