SearchForm = function(options)
{
	this.options = options;
	this.saveRegion = "";
	this.defaultValues = {};
	this.filterId = 0;

	if(typeof this.options.defaultValues != "undefined")
	{
		this.defaultValues = this.options.defaultValues;
	}
	if(typeof this.options.dateDeb == "undefined")
	{
		this.options.dateDeb = 0;
	}
	this.geo = {};
	this.jours = {};
	if(Util.Component.exists("sf.filtre"))
	{
		this.filtre = new Util.Component({id: "sf.filtre"});
		this.filterId = this.filtre.getElement().value;
	}
	
	if(Util.Component.exists("sf.pays"))
	{
		this.pays = new SearchForm.Select({id: "sf.pays"});
	}
	else
	{
		this.pays = null;
	}
	if(Util.Component.exists("sf.region"))
	{
		this.region = new SearchForm.Select({id: "sf.region"});
	}
	else
	{
		this.region = null;
	}
	if(Util.Component.exists("sf.departement"))
	{
		this.departement = new SearchForm.Select({id: "sf.departement"});
	}
	else
	{
		this.departement = null;
	}
	if(Util.Component.exists("sf.domaine"))
	{
		this.domaine = new SearchForm.Select({id: "sf.domaine"});
	}
	else
	{
		this.domaine = null;
	}
	if(Util.Component.exists("sf.ville"))
	{
		this.ville = new SearchForm.Select({id: "sf.ville"});
	}
	else
	{
		this.ville = null;
	}
	if(Util.Component.exists("sf.date"))
	{
		this.date = new SearchForm.Select({id: "sf.date"});
	}
	//champ date type promovac
	if(Util.Component.exists("sf.dateText"))
	{
		this.dateText = new Util.Component({id: "sf.dateText"});
	}
	else
	{
		this.dateText = null;
	}
	if(Util.Component.exists("sf.capacite"))
	{
		this.capacite = new SearchForm.Select({id: "sf.capacite"});
	}
	else
	{
		this.capacite = null;
	}
	if(Util.Component.exists("sf.nuite"))
	{
		this.nuite = new SearchForm.Select({id: "sf.nuite"});
	}
	else
	{
		this.nuite = null;
	}
	this.themes = [];
	//themes
	for(var i = 1; i < 10; i++)
	{
		if(Util.Component.exists("sf.theme."+i))
		{
			this.themes[i] = new Util.Component({id: "sf.theme."+i});
		}
	}
	
	if(Util.Component.exists("sf.reset"))
	{
		this.reset = new Util.Component({id: "sf.reset"});
	}
	else
	{
		this.reset = null;
	}
	
	this.init();
};

SearchForm.prototype = {
		
	init: function()
	{
		this.setHistory();
		if(this.reset)
		{
			this.reset.on("click", function(){
				this.resetForm();
			}, this);
		}
	},
	
	
	resetForm: function()
	{
		if(Util.Component.exists("sf.pays"))
		{
			this.pays.setValue("");
			this.history.pays_id = "";
		}
		if(Util.Component.exists("sf.region"))
		{
			this.region.setValue("");
			this.history.region_id = "";
		}
		if(Util.Component.exists("sf.departement"))
		{
			this.departement.setValue("");
			this.departement.enable();
			this.history.departement_id = "";
		}
		if(Util.Component.exists("sf.domaine"))
		{
			this.domaine.setValue("");
			this.domaine.enable();
			this.history.domaine_id = "";
		}
		if(Util.Component.exists("sf.ville"))
		{
			this.ville.setValue("");
			this.history.ville_id = "";
		}
		if(Util.Component.exists("sf.date"))
		{
			this.date.setValue("");
		}
		if(Util.Component.exists("sf.capacite"))
		{
			this.capacite.setValue("0");
		}
		if(Util.Component.exists("sf.nuite"))
		{
			this.nuite.setValue("1:28");
		}
		
		this.initSelectsGeo();
	}, 
	
	setGeo: function()
	{
		var http = new Util.HttpReader({
			url: "/ajax/sf.selects.php",
			params: {
				type: "geo",
				siteId: this.options.siteId,
				filtreId: this.filterId
			},
			method: "post",
			handler: function(response)
			{				
				this.geo = eval("("+response+")");
				this.initSelectsGeo();
				if(this.history.pays_id && this.pays)
				{
					this.pays.setValue(this.history.pays_id);
				}
				
				if(this.history.region_id && this.region)
				{
					this.region.setValue(this.history.region_id);
				}
				
				if(this.history.dep_id && this.departement)
				{
					this.departement.setValue(this.history.dep_id);
				}
				
				if(this.history.domaine_id && this.domaine)
				{
					this.domaine.setValue(this.history.domaine_id);
				}
				
				if(this.history.ville_id && this.ville)
				{
					this.ville.setValue(this.history.ville_id);
				}
			},
			scope: this
		});
		
		http.load();
	},
	
	setDate: function()
	{
		var http = new Util.HttpReader({
			url: "/ajax/sf.selects.php",
			params: {
				type: "date", 
				dateDeb: this.options.dateDeb
			},
			method: "post",
			handler: function(response)
			{
				this.jours = eval('('+response+')');
				var dow = 6;
				if(this.history.nuite_id)
				{
					if(this.history.nuite_id == "1:6")
					{
						dow = 5;
					}
				}
				this.date.set(this.jours[dow]);
				if(this.history.date)
				{
					this.date.setValue(this.history.date);
				}
			},
			scope: this
		});
		
		http.load();
	},
	
	setCapacite: function()
	{
		var http = new Util.HttpReader({
			url: "/ajax/sf.selects.php",
			params: {
				type: "capacite"
			},
			method: "post",
			handler: function(response)
			{
				var cap = eval('('+response+')');
				this.capacite.set(cap);
				if(this.history.capacite_id)
				{
					this.capacite.setValue(this.history.capacite_id);
				}
			},
			scope: this
		});
		
		http.load();
	},
	
	setNuite: function()
	{
		var http = new Util.HttpReader({
			url: "/ajax/sf.selects.php",
			params: {
				type: "nuite"
			},
			method: "post",
			handler: function(response)
			{
				var nuite = eval('('+response+')');
				this.nuite.set(nuite);
				if(this.history.nuite_id)
				{
					this.nuite.setValue(this.history.nuite_id);
				}
			},
			scope: this
		});
		
		http.load();
	},
	
	setDuree: function()
	{
		if(Util.Component.exists("sf.duree.1"))
		{
			var input = new Util.Component({id: "sf.duree.1"});
			input.on("click", function(){
				this.date.set(this.jours[6]);
			}, this);
			if(!this.history.nuite_id)
			{
				input.addAttribute("checked", "1");
			}
		}
		
		if(Util.Component.exists("sf.duree.2"))
		{
			var input = new Util.Component({id: "sf.duree.2"});
			input.on("click", function(){
				this.date.set(this.jours[5]);
			}, this);
			if(this.history.nuite_id)
			{
				if(this.history.nuite_id == "1:6")
				{
					input.addAttribute("checked", "1");
				}
			}
		}
	},
	
	initSelectsGeo: function()
	{
		if(this.paysDefault){
			this.history.pays_id = this.paysDefault;
		}
		if(this.defaultValues){
			if(this.defaultValues.pays_id){
				this.history.pays_id = this.defaultValues.pays_id;
			}
		}
		
		if(this.pays){
			this.pays.clear();
			this.pays.add("", "Tous les pays");
		}
		if(this.region){
			this.region.clear();
			this.region.add("", "Toutes les régions");
		}
		if(this.departement){
			this.departement.clear();
			this.departement.add("", "Tous les départements");
		}
		if(this.domaine){
			this.domaine.clear();
			this.domaine.add("", "Tous les domaines");
		}
		if(this.ville){
			this.ville.clear();
			this.ville.add("", "Toutes les villes");
		}
		var pId = "";
		if(this.history.pays_id && this.pays)
		{
			this.pays.setValue(this.history.pays_id);
			pId = this.history.pays_id;
		}
		var rId = "";
		if(this.history.region_id && this.region)
		{
			this.region.setValue(this.history.region_id);
			/*if(this.region.keyExists(this.history.region_id))
			{*/
				rId = this.history.region_id;
			//}
		}
		var dId = "";
		if(this.history.dep_id && this.departement)
		{
			this.departement.setValue(this.history.dep_id);
			dId = this.history.dep_id;
		}
		
		var doId = "";
		if(this.history.domaine_id && this.domaine)
		{
			this.domaine.setValue(this.history.domaine_id);
			doId = this.history.domaine_id;
		}
		
		for(var p in this.geo)
		{
			if(this.pays){
				this.pays.add(p, this.geo[p].label);
			}
			if(p == pId || pId == "")
			{
				var regions = this.geo[p].regions;
				if(this.region){
					this.region.addGroup(this.geo[p].label);
				}
				
				var tmpDep = [];
				var tmpVille = [];
				var tmpQuartiers = {};
				var tmpDomaines = {};
				if(rId == "")
				{
					if(this.departement){
						this.departement.addGroup(this.geo[p].label);
					}
					if(this.ville){
						this.ville.addGroup(this.geo[p].label);
					}
				}

				for(var r in regions)
				{
					if(this.region){
						this.region.add(r, regions[r].label);
					}
					var departements = regions[r].departements;

					if(rId != "" && rId == r)
					{
						if(this.departement){
							this.departement.addGroup(this.geo[p].label);
						}
						if(this.ville){
							this.ville.addGroup(this.geo[p].label);
						}
					}
					for(var d in departements)
					{
						if(d && this.departement)
						{
							if(rId == r || rId == "")
							{
								tmpDep[tmpDep.length] = departements[d].label+"#"+d;
								tmpDomaines[d] = departements[d].domaines;
							}
						}
											
						var villes = departements[d].villes;
						
						for(var v in villes)
						{						
							if(!in_array(tmpVille, villes[v].label+"#"+v))
							{
								if((rId == r || rId == "") )
								{								
									tmpVille[tmpVille.length] = villes[v].label+"#"+v;
									tmpQuartiers[v] = villes[v].quartiers;
								}
							}
						}
					}
				}
				
				if(this.departement){
					
					tmpDep.sort();
					
					for(var i in tmpDep)
					{	
						if(typeof tmpDep[i] == "string")
						{
							var code = tmpDep[i].split("#");
							this.departement.add(code[1], code[0]);
						}
					}
					
				}
				
				if(this.domaine){
					for(var i in tmpDomaines)
					{
						for(var j in tmpDomaines[i])
						{
							this.domaine.add(j, tmpDomaines[i][j].label);
						}
					}
				}
				
				if(this.ville){
					tmpVille.sort();
					for(var i in tmpVille)
					{	
						var code = tmpVille[i].split("#");
						this.ville.add(code[1], code[0]);

						for(var qId in tmpQuartiers[code[1]])
						{
							var qNom = tmpQuartiers[code[1]][qId].label;
							this.ville.add("q"+qId, "&nbsp;&nbsp;&nbsp;"+code[0]+" - "+qNom);
						}
						
					}
				}
			}
		}
		/*****pays******/
		if(this.pays){
		this.pays.on("change", function(){
			
			var pId =this.pays.getValue();
			
			this.savePays = pId;
			if(this.region){
				this.region.clear();
				this.region.add("", "Toutes les régions");
				this.region.enable();
			}
			if(this.departement){
				this.departement.clear();
				this.departement.add("", "Tous les départements");
				this.departement.enable();
			}
			if(this.domaine){
				this.domaine.clear();
				this.domaine.add("", "Toutes les domaines");
				this.domaine.enable();
			}
			if(this.ville){
				this.ville.clear();
				this.ville.add("", "Toutes les villes");
				this.ville.enable();
			}
			var countDomaine = 0;
			for(var p in this.geo)
			{
				
				var regions = this.geo[p].regions;
				if(pId == "")
				{
					if(this.departement){
						this.departement.addGroup(this.geo[p].label);
					}
					if(this.ville){
						this.ville.addGroup(this.geo[p].label);
					}
				}
				
				var tmpReg = [];
				var tmpDep = [];
				var tmpVille = [];
				var tmpDomaines = {};
				var tmpQuartiers = {};
				if(p == pId || pId == "")
				{
					if(pId != "") 
					{
						if(this.region){
							this.region.addGroup(this.geo[p].label);
						}
						if(this.departement){
							this.departement.addGroup(this.geo[p].label);
						}
						if(this.ville){
							this.ville.addGroup(this.geo[p].label);
						}
					}
					
					for(var r in regions)
					{
						
						//if(p == pId || pId == "")
						//{
							/*
							if(pId != "") 
							{
								if(this.departement){
									this.departement.addGroup(this.geo[p].label);
								}
								if(this.ville){
									this.ville.addGroup(this.geo[p].label);
								}
							}
							*/
							if(r && this.region)
							{
								tmpReg[tmpReg.length] = regions[r].label+"#"+r;
							}
							var departements = regions[r].departements;
							
							for(var d in departements)
							{
								
								if(d && this.departement)
								{
									tmpDep[tmpDep.length] = departements[d].label+"#"+d;
									tmpDomaines[d] = departements[d].domaines;
									//this.departement.add(d, departements[d].label);
								}
								else
								{
									/* pour le cas ou il n'y a pas de departement
									if(pId != "" && this.departement)
									{
										this.departement.clear();
										this.departement.add("","Pas de département");
										this.departement.disable();
									}
									*/
								}
								
								var villes = departements[d].villes;
								for(var v in villes)
								{
									if(!in_array(tmpVille, villes[v].label+"#"+v))
									{
										tmpVille[tmpVille.length] = villes[v].label+"#"+v;
										tmpQuartiers[v] = villes[v].quartiers;
									}
								}
							}
						//}
					}
				}
				if(this.region){
					tmpReg.sort();
					
					for(var i in tmpReg)
					{	
						var code = tmpReg[i].split("#");
						this.region.add(code[1], code[0]);
						/*
						if(this.domaine)
						{						
							for(var j in tmpDomaines[code[1]])
							{
								countDomaine++;
								this.domaine.add(j, tmpDomaines[code[1]][j].label);
								
							}							
						}
						*/
					}
					
				}
				
				if(this.departement){
					tmpDep.sort();
					
					for(var i in tmpDep)
					{	
						var code = tmpDep[i].split("#");
						this.departement.add(code[1], code[0]);
						if(this.domaine)
						{						
							for(var j in tmpDomaines[code[1]])
							{
								countDomaine++;
								this.domaine.add(j, tmpDomaines[code[1]][j].label);
								
							}							
						}
					}
					
				}
				if(this.ville){
					tmpVille.sort();
					for(var i in tmpVille)
					{	
						var code = tmpVille[i].split("#");
						this.ville.add(code[1], code[0]);

						for(var qId in tmpQuartiers[code[1]])
						{
							var qNom = tmpQuartiers[code[1]][qId].label;
							this.ville.add("q"+qId, "&nbsp;&nbsp;&nbsp;"+code[0]+" - "+qNom);
						}
					}
				}
			}
			if(this.domaine)
			{
				if(countDomaine == 0)
				{
					this.domaine.add("", "Pas de domaine");
					this.domaine.disable();
				}
			}
		}, this);
		}
		/******region*****/
		if(this.region){
		this.region.on("change", function(){
			
			var rId =this.region.getValue();
			this.saveRegion = rId;
			if(this.departement){
				this.departement.clear();
				this.departement.add("", "Tous les départements");
				this.departement.enable();
			}
			if(this.domaine){
				this.domaine.clear();
				this.domaine.add("", "Toutes les domaines");
				this.domaine.enable();
			}
			if(this.ville){
				this.ville.clear();
				this.ville.add("", "Toutes les villes");
				this.ville.enable();
			}
			var countDomaine = 0;
			for(var p in this.geo)
			{
				
				var regions = this.geo[p].regions;
				if(rId == "")
				{
					if(this.departement){
						this.departement.addGroup(this.geo[p].label);
					}
					if(this.ville){
						this.ville.addGroup(this.geo[p].label);
					}
				}
				var tmpDep = [];
				var tmpVille = [];
				var tmpDomaines = {};
				var tmpQuartiers = {};
				for(var r in regions)
				{
					
					if(r == rId || rId == "")
					{
						if(rId != "") 
						{
							
							if(this.pays){
								this.pays.setValue(p);
							}
							
							if(this.departement){
								this.departement.addGroup(this.geo[p].label);
							}
							if(this.ville){
								this.ville.addGroup(this.geo[p].label);
							}
						}
						var departements = regions[r].departements;
						
						for(var d in departements)
						{
							
							if(d && this.departement)
							{
								tmpDep[tmpDep.length] = departements[d].label+"#"+d;
								tmpDomaines[d] = departements[d].domaines;
								//this.departement.add(d, departements[d].label);
							}
							else
							{
								if(rId != "" && this.departement)
								{
									this.departement.clear();
									this.departement.add("","Pas de département");
									this.departement.disable();
								}
							}
							
							var villes = departements[d].villes;
							for(var v in villes)
							{
								if(!in_array(tmpVille, villes[v].label+"#"+v))
								{
									tmpVille[tmpVille.length] = villes[v].label+"#"+v;
									tmpQuartiers[v] = villes[v].quartiers;
								}
							}
						}
					}
				}
				
				if(this.departement){
					tmpDep.sort();
					
					for(var i in tmpDep)
					{	
						var code = tmpDep[i].split("#");
						this.departement.add(code[1], code[0]);
						if(this.domaine)
						{						
							for(var j in tmpDomaines[code[1]])
							{
								countDomaine++;
								this.domaine.add(j, tmpDomaines[code[1]][j].label);
								
							}							
						}
					}
					
				}
				if(this.ville){
					tmpVille.sort();
					for(var i in tmpVille)
					{	
						var code = tmpVille[i].split("#");
						this.ville.add(code[1], code[0]);

						for(var qId in tmpQuartiers[code[1]])
						{
							var qNom = tmpQuartiers[code[1]][qId].label;
							this.ville.add("q"+qId, "&nbsp;&nbsp;&nbsp;"+code[0]+" - "+qNom);
						}
					}
				}
			}
			if(this.domaine)
			{
				if(countDomaine == 0)
				{
					this.domaine.add("", "Pas de domaine");
					this.domaine.disable();
				}
			}
		}, this);
		}
		/******departement*****/
		if(this.departement){
		this.departement.on("change", function(){
			var dId =this.departement.getValue();
			if(this.ville){
				this.ville.clear();
				this.ville.add("", "Toutes les villes");
				this.ville.enable();
			}
			
			if(this.domaine){
				this.domaine.clear();
				this.domaine.add("", "Tous les domaines");
				this.domaine.enable();
			}
			tmpDomaines = {};
			for(var p in this.geo)
			{
				var regions = this.geo[p].regions;
				if(dId == "" && this.ville)
				{
					this.ville.addGroup(this.geo[p].label);
				}
				var tmpVille = [];
				var tmpQuartiers = {};
				for(var r in regions)
				{
					var departements = regions[r].departements;
					for(var d in departements)
					{
						if(dId == d || dId == "")
						{
							if(dId == d && this.region && dId != "")
							{
								
								if(this.pays){
									this.pays.setValue(p);
								}
								this.region.setValue(r);
																
							}
							tmpDomaines[d] = departements[d].domaines;
							if(dId != "" && this.ville) 
							{
								this.ville.addGroup(this.geo[p].label);
							}
							var villes = departements[d].villes;
							for(var v in villes)
							{
								if(!in_array(tmpVille, villes[v].label+"#"+v))
								{
									tmpVille[tmpVille.length] = villes[v].label+"#"+v;
									tmpQuartiers[v] = villes[v].quartiers;
								}
							}
						}
					}
				}
				if(this.ville){
					tmpVille.sort();
					for(var i in tmpVille)
					{	
						var code = tmpVille[i].split("#");
						this.ville.add(code[1], code[0]);
						for(var qId in tmpQuartiers[code[1]])
						{
							var qNom = tmpQuartiers[code[1]][qId].label;
							this.ville.add("q"+qId, "&nbsp;&nbsp;&nbsp;"+code[0]+" - "+qNom);
						}
					}
				}
				

				
			}
			var countDomaine = 0;
			if(this.domaine){
				for(var i in tmpDomaines)
				{	
					for(var j in tmpDomaines[i])
					{
						countDomaine++;
						this.domaine.add(j, tmpDomaines[i][j].label);
					}						
				}
			}
			if(this.domaine)
			{
				if(countDomaine == 0)
				{
					this.domaine.add("", "Pas de domaine");
					this.domaine.disable();
				}
			}
			if(dId == "" && this.region)
			{
				this.region.setValue(this.saveRegion);
			}
		}, this);
		}
		
		if(this.domaine){
			this.domaine.on("change", function(){
				var doId = this.domaine.getValue();
				var tmpVille = [];
				if(this.ville){
					this.ville.clear();
					this.ville.add("", "Toutes les villes");
					this.ville.enable();
				}
				for(var p in this.geo)
				{
					var tmpVille = [];
					var regions = this.geo[p].regions;
					for(var r in regions)
					{
						var departements = regions[r].departements;
						for(var d in departements)
						{
							if(doId != "")
							{
								for(var dom in departements[d].domaines)
								{
									if(dom == doId)
									{
										var domaine = departements[d].domaines[dom];
										var villes = domaine.villes;
										for(var v in villes)
										{
											if(!in_array(tmpVille, villes[v]+"#"+v))
											{
												tmpVille[tmpVille.length] = villes[v]+"#"+v;
											}
										}
									}
								}
							}
							else
							{
								var villes = departements[d].villes;
								for(var v in villes)
								{
									if(!in_array(tmpVille, villes[v].label+"#"+v))
									{
										tmpVille[tmpVille.length] = villes[v].label+"#"+v;
									}
								}
							}
						}
					}
					
					if(this.ville){
						tmpVille.sort();
						for(var i in tmpVille)
						{	
							var code = tmpVille[i].split("#");
							this.ville.add(code[1], code[0]);
						}
					}
				}
			}, this);
		}
		/******ville*****/
		if(this.ville){
		this.ville.on("change", function(){
			var vId = this.ville.getValue();
			if(this.departement){
				this.departement.enable();
			}
			for(var p in this.geo)
			{
				var regions = this.geo[p].regions;

				for(var r in regions)
				{
					var departements = regions[r].departements;
					for(var d in departements)
					{
						if(d)
						{
							var villes = departements[d].villes;
							for(var v in villes)
							{							
								if(vId == v && vId != "")
								{
								
									if(this.pays){
										this.pays.setValue(p);
									}
									
									if(this.region){
										this.region.setValue(r);
									}
									if(this.departement){									
										this.departement.setValue(d);
									}
								}
							}
						}
					}
				}
			}
		}, this);
		}
	},
	
	setHistory: function()
	{
		var http = new Util.HttpReader({
			url: "/ajax/sf.selects.php",
			params: {
				getParams: "1"
			},
			method: "post",
			handler: function(response)
			{				
				this.history = eval('('+response+')');
				for(var k in this.defaultValues)
				{
					this.history[k] = this.defaultValues[k];
				}
				
				this.setGeo();
				if(Util.Component.exists("sf.date"))
				{
					this.setDate();
				}
				
				if(Util.Component.exists("sf.dateText"))
				{
					if(this.history.date)
					{
						this.dateText.getElement().value = this.history.date;
					}
				}
				if(Util.Component.exists("sf.capacite"))
				{
					this.setCapacite();
				}
				
				if(Util.Component.exists("sf.nuite"))
				{
					this.setNuite();
				}
				
				this.setDuree();
				if(this.history.theme_res)
				{
					var themes = this.history.theme_res.split("-");

					for(var i=0; i < themes.length; i++)
					{
						//this.themes[themes[i]].addAttribute("checked", "1");
						//pour octopode
						this.themes[themes[i]].getElement().click();
					}
				}
				
			},
			scope: this
		});

		
		http.load();
	}
	
};

SearchForm.Select = function(options)
{
	this.currentGroup = null;
	this.options = options;
	this.element = null;
	this.init();
};

SearchForm.Select.prototype = {
	
	init: function()
	{
		this.element = new Util.Component({id: this.options.id});
	},
	
	addGroup: function(label)
	{
		this.currentGroup = new Util.Component({tag: "optgroup", attributes: {label: label}});
		this.element.append(this.currentGroup.getElement());
	},
	
	add: function(key, value)
	{
		if(this.currentGroup == null)
		{
			var option = new Util.Component({tag: "option", content: value, attributes: {value: key, title: value.replace("&nbsp;&nbsp;&nbsp;", "")}});
			this.element.append(option.getElement());
		}
		else
		{
			var option = new Util.Component({tag: "option", content: value, attributes: {value: key, title: value.replace("&nbsp;&nbsp;&nbsp;", "")}});
			this.currentGroup.append(option.getElement());
		}
	},
	
	clear: function()
	{
		this.element.clear();
		this.currentGroup = null;
	},
		
	set: function(data)
	{
		this.clear();
						
		for(var i in data)
		{
			this.add(i, data[i]);
		}

	},
	
	getValue: function()
	{
		return this.element.getAttribute("value");
	},
	
	setValue: function(v)
	{
		//this.element.addAttribute("value", v);
		/*for(var opt in this.element.getElement().options)
		{
			if(this.element.getElement().options[opt].value == v)
			{
				//alert(this.element.getElement().options[opt].value);
				this.element.getElement().options[opt].selected=true;
			}
			else
			{
				this.element.getElement().options[opt].selected=false;
			}
		}*/
		this.element.getElement().value = v;
	},
	
	disable: function()
	{
		this.element.addAttribute("disabled", "true");
	},
	
	enable: function()
	{
		this.element.removeAttribute("disabled");
	},
		
	on: function(event, fct, scope)
	{
		this.element.on(event,fct,scope);
	},
	
	keyExists: function(k)
	{
		var test = false;
		for(var opt in this.element.getElement().options)
		{
			if(this.element.getElement().options[opt].value == k)
			{
				test = true;
			}
		}
		
		return test;
	}
};

function in_array(tab, p_val) {
    for(var i = 0, l = tab.length; i < l; i++) {
        if(tab[i] == p_val) {
            rowid = i;
            return true;
        }
    }
    return false;
}
