function recargaselect(sel,tv,tt,qui,x){
 if (qui=="0"){
  sel.length=0;
  sel.length=sel.length+1;
  sel.options[0].value="0";
  sel.options[0].text=" ";
  sel.options.selectedIndex=0;
 } else {
  sel.length=0;
  for (i=0;i<tv.length;i++){
   sel.length=sel.length+1;
   sel.options[i].value=tv[i]
   sel.options[i].text=tt[i]
   sel.options[i].className='comboEnter';

  }
  sel.options[x].selected=true;
 }
 return true;
}
function cambiar_pro(me,selectzona){
	selected=me.options[me.selectedIndex].value;
	seleccion = new Seleccion()
	seleccion.addtots("-1","","");
	seleccionar=0;
	selec=0;
		for(x=0;x<zonas.idzona.length;x++){
			if (zonas.provincia[x]==selected){
				selec++;
				seleccion.addtots(zonas.idzona[x],zonas.nombre[x],zonas.provincia[x]);
				if (zonas.idzona[x]==selectzona.value){
				 	seleccionar=selec;
				}
			}else{
				if (me.options[me.selectedIndex].value=="TODOS"){
					seleccion.addtots(zonas.idzona[x],zonas.nombre[x],zonas.provincia[x]);
				}
			}

		}
	//seleccion.nombre=selectzona.options[selectzona.selectedIndex].text;

	recargaselect(selectzona,null,null,0,0);
	recargaselect(selectzona,seleccion.idzona,seleccion.nombre,1,seleccionar);
	//document.forms[0].zon.options['1'].selected=true;
}
function Zonas() {
	this.idzona = new Array()
	this.nombre = new Array()
	this.provincia = new Array()
	this.addtot = addtot
}
function addtot(idzona,nombre,provincia) {
	this.idzona[this.idzona.length] = idzona;
	this.nombre[this.nombre.length] = nombre;
	this.provincia[this.provincia.length] = provincia;
}
function Seleccion() {
	this.idzona = new Array()
	this.nombre = new Array()
	this.provincia = new Array()
	this.addtots = addtots
}
function addtots(idzona,nombre,provincia) {
	this.idzona[this.idzona.length] = idzona;
	this.nombre[this.nombre.length] = nombre;
	this.provincia[this.provincia.length] = provincia;
}
function Provincias() {
	this.idprovincia = new Array()
	this.nombre = new Array()
	this.addtotp = addtotp
}
function addtotp(idprovincia,nombre) {
	this.idprovincia[this.idprovincia.length] = idprovincia;
	this.nombre[this.nombre.length] = nombre;
}

//esta funcion, le pasas un select y un valor, y te marca en la select el valor que tu has pedido
function buscar_provincia(valor){
	for (x=0;x<zonas.idzona.length;x++){
		if (valor==zonas.idzona[x]){
			return zonas.provincia[x];
		}
	}
}
function buscar_zona(valor){
	for (x=0;x<provincias.idprovincia.length;x++){
		if (valor==provincias.idprovincia[x]){
			return provincias.nombre[x];
		}
	}
}
function selecciona(valores,valor)
{
     	if(!isNaN(valor.value)){
  			valor.value=buscar_provincia(valor.value);
		}
   for (i=0;i<valores.options.length; i++)
   {
   	//alert(valores.options[i].value+" "+valor.value);
      if(valores.options[i].value==valor.value)
      {
	  	//alert("valores:"+valores.options[i].value);
        valores.options[i].selected=true;
        i=valores.options.length;
      }
   }
}
function seleccionaini(valores,valor)
{
   for (i=0;i<valores.options.length; i++)
   {
      if(valores.options[i].value==valor.value)
      {
        valores.options[i].selected=true;
        i=valores.options.length;
      }
   }
}
function seleccionainivalor(valores,valor)
{
   for (i=0;i<valores.options.length; i++)
   {
      if(valores.options[i].value==valor)
      {
        valores.options[i].selected=true;
        i=valores.options.length;
      }
   }
}
function selecciona_zona(valores,valor)
{
   for (i=0;i<valores.options.length; i++)
   {
      if(valores.options[i].value==valor.value)
      {
        valores.options[i].selected=true;
        i=valores.options.length;
      }
   }
}
var provincias = new Provincias();
var zonas = new Zonas();

