function Opcion() { 

        this.op = new String(); // opcion elegida
        this.ListaVehiculos = null;
        this.ListaOfertas = null;
}
 
Opcion.instance = null;

Opcion.getInstance = function() {
        if (Opcion.instance == null) {
        	Opcion.instance = new Opcion();
        }
 
        return Opcion.instance;
};

//------ ListaVehiculos
Opcion.prototype.guardarEnLista = function(valor){
	this.ListaVehiculos.push(valor);
};

Opcion.prototype.getLista = function(){
	
	return this.ListaVehiculos;
};

Opcion.prototype.CrearLista =function(){
	this.ListaVehiculos = new Array();
};

//----- ListaOfertas
Opcion.prototype.guardarOferta = function(valor){
	this.ListaOfertas.push(valor);
};

Opcion.prototype.getOfertas = function(){
	return this.ListaOfertas;
};

Opcion.prototype.CrearListaOf = function(){
	this.ListaOfertas = new Array();
};

//---- Opcion
Opcion.prototype.guardar = function(opcion) {
        this.op = opcion;
};

Opcion.prototype.obtener = function() {
        return this.op;
};

//---- Llenar datos
Opcion.prototype.ObtenerLista = function(){
	var opc = Opcion.getInstance();
	var lista = opc.getLista();
	var lista2 = new Array();
	var existe = false;
	
	if(lista==null){
		opc.CrearLista();
		$.ajax({
			type: "GET",
			url: "xml/vehiculos.xml",
			dataType: "xml",
			success: function(xml) {
				
				$(xml).find('Vehiculo').each(function(){
					vel = new Vehiculo();
					vel.CategoriaSet(	$(this).find('Categoria').text());
					vel.imagenSet(		$(this).find('imagen').text());
					vel.alingSet(		$(this).find('aling').text());
					vel.MarcaSet(		$(this).find('Marca').text());
					vel.AsientosSet(	$(this).find('Asientos').text());
					vel.MedidasSet(		$(this).find('Medidas').text());
					vel.MedidasPTSet(	$(this).find('MedidasPT').text());
					vel.MedidssPDSet(	$(this).find('MedidssPD').text());
					vel.MedidasZCSet(	$(this).find('MedidasZC').text());
					vel.CargaUtilSet(	$(this).find('CargaUtil').text());
					vel.CargaVolumenSet($(this).find('CargaVolumen').text());
					vel.PMASet(			$(this).find('PMA').text());
					vel.textaltSet(		$(this).find('textalt').text());

					for (i=0;i<lista2.length;i++){
						var velo = lista2[i];
						if(velo.CategoriaGet() == vel.CategoriaGet()){
							existe=true;
						}						
					}
					if(!existe){
						opc.guardarEnLista(vel);
						existe=false;
						lista2.push(vel);
					}
					else{existe=false;}
					



				});
		}});
	}
	else{
		
	}
	
};

Opcion.prototype.ObtenerOferta = function(){
	var opc = Opcion.getInstance();
	var lista = opc.getOfertas();
	
	if(lista==null){
		opc.CrearListaOf();
		$.ajax({
			type: "GET",
			url: "xml/ofertas.xml",
			dataType: "xml",
			success: function(xml) {
				
				$(xml).find('oferta').each(function(){
					var oferta = new Oferta();
					oferta.ImgSet(	$(this).find('img').text());
					oferta.AltSet(	$(this).find('alt').text());
					opc.guardarOferta(oferta);

				});
		}});
	}
	else{
		
	}
};
