// SINOPSIS
// Funciones relativas a la carga de datos de autosuggest para la carga de lugares en el form para users
// BITACORA
// GB 15-4-2009 Creacion

// SINOPSIS
// Inicia datos para autosuggest de lugares
// BITACORA
// GB, 15-4-200, Creacion en base a la que esta en admin
// GB 3-3-2010 Agrego autosuggest para artistas
// ASSUMPTIONS & BUGS
// GB 3-3-2010 no encuentro forma facil de unificar cuando hay mas de un artista. No se comoo sacar el id o nombre del control adonde estoy desde dentro de la funcion callback cuando se selecciona un artista, o leer donde esta el primer parametro en el new bsn.Autosuggest(...). OPTIMIZAR CODIGO.
// GB 17-3-2010 Saco datos de common/php
function startAutosuggestFormCargaEvento()
{	
	// LUGAR
	var options = {
		// script: "../admin/v2-obtener-lugares-activos.php?",
		script: "../common/php/v2-obtener-lugares-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: false,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosLugar( obj );
		}
	};
	
	var as = new bsn.AutoSuggest('lugar', options);

	// ARTISTA 0
	var optionsArtista0 = {
		script: "../common/php/v2-obtener-artistas-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: true,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosArtista0( obj );
		}
	};

	var artista0 = new bsn.AutoSuggest('artista0', optionsArtista0 );

	// ARTISTA 1
	var optionsArtista1 = {
		script: "../common/php/v2-obtener-artistas-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: false,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosArtista1( obj );
		}
	};

	var artista1 = new bsn.AutoSuggest('artista1', optionsArtista1 );

	// ARTISTA 2
	var optionsArtista2 = {
		script: "../common/php/v2-obtener-artistas-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: true,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosArtista2( obj );
		}
	};

	var artista2 = new bsn.AutoSuggest('artista2', optionsArtista2 );
	
	// ARTISTA 3	
	var optionsArtista3 = {
		script: "../common/php/v2-obtener-artistas-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: true,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosArtista3( obj );
		}
	};

	var artista4 = new bsn.AutoSuggest('artista3', optionsArtista3 );

	// ARTISTA 4
	var optionsArtista4 = {
		script: "../common/php/v2-obtener-artistas-activos.php?",
		varname: "input",
		json: false,
		timeout: 15000,
		cache: true,
		minchars: 2,
		noresults: "No hay resultados. Probá sin acentos!",		
		callback: function (obj) { 
			updateDatosArtista4( obj );
		}
	};
	
	var artista4 = new bsn.AutoSuggest('artista4', optionsArtista4 );
}

// SINOPSIS
// Actualiza los datos del lugar en el form
// INPUT
// obj, contiene obj.id, obj.name, obj.info
// OUTPUT
// None
// BITACORA
// GB 15-4-2009 Creacion
// gb 6-5-2009 comienzo a agregar idlugar, por ahora en 1 si se completa
// el campo lugar, no guardo el id propiamente dicho
function updateDatosLugar( obj )
{
	// alert( "En updateDatosLugar() en V2_1/js/v2-autosuggest-form-carga-evento-user.js, info = " + obj.info);
	document.getElementById("info-lugar").innerHTML = obj.info;
	// gb 7-7-2009 esto no va mas, unifico forma de trabajar con admin
	/* guardo en campo hidden para poder pasar a grabarlo
	document.getElementById("infoLugar").value = obj.info;
	*/	
	// gb 7-7-2009 guardo variables separadas como en admin, que estan hidden en el form
	var aux = obj.info.split(",");
	// copio a variables
	var direccion = trim(aux[0]);
	var barrio = trim(aux[1]);
	var localidad = trim(aux[2]);
	var provincia = trim(aux[3]);
	var pais = trim(aux[4]);
	// Paso a form
	document.getElementById("direccion").value = direccion;
	document.getElementById("barrio").value = barrio;
	document.getElementById("localidad").value = localidad;
	document.getElementById("provincia").value = provincia;
	document.getElementById("pais").value = pais;
	
	// guardo en campo hidden para grabarlo
	// gb 7-7-2009 puedo pasar ya el id!
	// document.getElementById("idLugar").value = 1;
	document.getElementById("id-lugar").value = obj.id;
}

// SINOPSIS
// Actualiza los datos de los artistas en el form
// Hago cinco funciones iguales porque no encuentro alternativa por ahora
// INPUT
// obj, contiene obj.id, obj.name, obj.info
// OUTPUT
// None
// BITACORA
// GB 3-3-2010 Creacion
function updateDatosArtista0( obj )
{
	document.getElementById("id-artista0").value = obj.id;
}

function updateDatosArtista1( obj )
{
	document.getElementById("id-artista1").value = obj.id;
}

function updateDatosArtista2( obj )
{
	document.getElementById("id-artista2").value = obj.id;
}

function updateDatosArtista3( obj )
{
	document.getElementById("id-artista3").value = obj.id;
}

function updateDatosArtista4( obj )
{
	document.getElementById("id-artista4").value = obj.id;
	// alert ("Id artista 4 = " + obj.id );
}