TablaRF = new Array("#Resultados#v2#")
TablaLF = new Array("#Resultados#v2#")

function CLF(datos){
  datos=datos.split("|")
  num=TablaLF.length
  TablaLF[num]=new DatosCLF(num,datos)
}

function DatosCLF(numero,datos){
  this.num    = numero
  this.texto  = datos[0]
  this.codigo = datos[1]
}

function CRF(datos){
  datos=datos.split("|")
  num=TablaRF.length
  TablaRF[num]=new DatosCRF(num,datos)
}

function DatosCRF(numero,datos){
  this.num    = numero
  this.texto  = datos[0]
  this.liga   = datos[1]
  this.codigo = datos[2]
  this.grupos = datos[3]
}

CLF("Ligas Españolas|esp")
CRF("Primera División|esp|primera|0")
CRF("Segunda División|esp|segunda|0")
CRF("Segunda División B|esp|segundab|4")
CRF("Tercera División|esp|tercera|18")
CRF("Copa del Rey|esp|copa_del_rey|0")
CRF("Primera Castilla y León|esp|castilla_y_leon|2")
CRF("Primera Castilla la Mancha|esp|castilla_la_mancha|2")
CRF("Primera Catalana|esp|catalunya|0")
CRF("Primera Andaluza|esp|andaluza|4")
CRF("Preferente Valenciana|esp|valenciana|4")
CRF("Preferente Madrid|esp|madrid|2")
CRF("Preferente Rioja|esp|rioja|0")
CRF("Preferente Galicia|esp|galicia|2")
CRF("Preferente Asturias|esp|asturias|0")
CRF("Preferente Aragón|esp|aragon|2")
CRF("Preferente País Vasco|esp|euskadi|3")
CRF("Preferente Murcia|esp|murcia|0")
CRF("Preferente Extremadura|esp|extremadura|2")
CRF("Preferente Cantabria|esp|cantabria|0")
CRF("Preferente Canarias|esp|canarias|2")
CRF("Preferente Baleares|esp|illes_balears|0")
CRF("Regional Navarra|esp|navarra|2")
CRF("Liga Territorial Juvenil|esp|territorial_juvenil|0")
CRF("Liga Regional Juvenil|esp|regional_juvenil|0")
CRF("Liga Nacional Juvenil|esp|nacional_juvenil|17")

CLF("Ligas Europeas|eur")
CRF("Champions League|eur|champions|8")
CRF("Permier League|eur|premier|0")
CRF("Bundesliga Alemana|eur|bundesliga|0")
CRF("Europa League|eur|uefa|12")
CRF("Liga Rumana|eur|rumania|0")
CRF("Liga Portuguesa|eur|portugal|0")
CRF("Liga Holandesa|eur|holanda|0")
CRF("Liga Escocia|eur|escocia|0")
CRF("Liga Checa|eur|checa|0")
CRF("Liga Belga|eur|belgica|0")
CRF("Liga Turca|eur|turquia|0")
CRF("Liga Griega|eur|grecia|0")
CRF("Liga Danesa|eur|dinamarca|0")
CRF("Liga Austriaca|eur|austria|0")
CRF("Liga Finlandesa|eur|finlandia|0")
CRF("Liga Irlandesa|eur|irlanda|0")
CRF("Liga Galesa|eur|gales|0")
CRF("Liga Maltesa|eur|malta|0")

CLF("Fútbol Internacional|int")
CRF("Copa Confederaciones|int|copa_confederaciones|2")
CRF("Liga Sudafricana|int|sudafrica|0")
CRF("Liga China|int|china|0")
CRF("Liga Tunecina|int|tunez|0")
CRF("Liga Australiana|int|australia|0")
CRF("Liga Hondureña|int|honduras|0")
CRF("Liga Iraní|int|iran|0")
CRF("Mundial 2010|int|mundial|8")

function MuestraTablaRF(tipo,codigo)
{
  if(tipo=="res"){tipo=1}
  if(tipo=="clx"){tipo=2}
  if(tipo=="clr"){tipo=3}

  datpas=codigo.split("|")
  ligpas=datpas[0]
  codpas=datpas[1]
  grppas=datpas[2]

  archivo=codpas+"-2010-"+grppas+"/"+tipo

  html='<script type="text/javascript">'
  html=html+'padding="2";'
  html=html+'width="240px";'
  html=html+'bgColor="#DDDDDD";'
  html=html+'linkColor="#003300";'
  html=html+'textColorA="#006600";'
  html=html+'textColorB="#666666";'
  html=html+'border="1px solid #BBBBBB";'
  html=html+'textFont="11px Tahoma, Arial, Helvetica, Sans serif";'
  html=html+'</script>'
  html=html+'<script language="javascript" src='
  html=html+'"http://www.resultados-futbol.com/web/'+archivo+'">'
  html=html+'</script>'

  document.write(html)
}

function MuestraSelector()
{
  html='<form name="selector">'
  html=html+'Liga: '
  html=html+'<select size="1" name="ligas" OnChange="CambiaLiga()">'
  html=html+'<option>---</option>'
  html=html+'</select>'
  html=html+'&nbsp;&nbsp;'
  html=html+'Categoría: '
  html=html+'<select size="1" name="categ" OnChange="CambiaCategoria()">'
  html=html+'<option>---</option>'
  html=html+'</select>'
  html=html+'&nbsp;&nbsp;'
  html=html+'Grupo: '
  html=html+'<select size="1" name="grupo">'
  html=html+'<option>---</option>'
  html=html+'</select>'
  html=html+'&nbsp;&nbsp;'
  html=html+'<input type=button value="Mostrar" OnClick="BotonMostrar()">'
  html=html+'</form>'
  document.write(html)

  if(codigo==0){codigo="esp|primera|1"}
  datpas=codigo.split("|")
  ligpas=datpas[0]
  codpas=datpas[1]
  grppas=datpas[2]

  for(lst=1;lst<TablaLF.length;lst++)
  {
    lig=TablaLF[lst].codigo

    if(lig==ligpas)
    {
      ligsel=lst-1
      break
    }
  }

  catsel=-1
  for(cat=1;cat<TablaRF.length;cat++)
  {
    lig=TablaRF[cat].liga
    cod=TablaRF[cat].codigo
    grp=TablaRF[cat].grupos

    if(lig==ligpas)
    {
      catsel=catsel+1
      if(cod==codpas)
      {
        if(grp==0){grpsel=0}else{grpsel=grppas}
        break
      }
    }
  }

  CargaLigas()
  document.selector.ligas[ligsel].selected=true
  CargaCategorias()
  document.selector.categ[catsel].selected=true
  CargaGrupos()
  document.selector.grupo[grpsel].selected=true
}

function CambiaLiga()
{
  CargaCategorias()
  CargaGrupos()
}

function CambiaCategoria()
{
  CargaGrupos()
}

function CargaLigas()
{
  for(lig=1;lig<TablaLF.length;lig++)
  {
    texto=TablaLF[lig].texto
    document.selector.ligas[lig-1]=new Option(texto,lig)
  }
}

function CargaCategorias()
{
  lig=document.selector.ligas.selectedIndex
  lig=document.selector.ligas[lig].value
  lig=TablaLF[lig].codigo

  document.selector.categ[0].selected=true
  for(cat=document.selector.categ.length;cat>=0;cat--)
  {document.selector.categ[cat]=null}

  elem=0
  for(cat=1;cat<TablaRF.length;cat++)
  {
    if(lig==TablaRF[cat].liga)
    {
      texto=TablaRF[cat].texto
      document.selector.categ[elem]=new Option(texto,cat)
      elem=elem+1
    }
  }
}

function CargaGrupos()
{
  cat=document.selector.categ.selectedIndex
  cat=document.selector.categ[cat].value
  grupos=TablaRF[cat].grupos

  if(grupos==0)
  {
    document.selector.grupo.disabled=true
    document.selector.grupo[0].selected=true
  }
  else
  {
    document.selector.grupo.disabled=false
    document.selector.grupo[0].selected=true
    for(grp=document.selector.grupo.length;grp>=1;grp--)
    {document.selector.grupo[grp]=null}
    for(grp=1;grp<=grupos;grp++)
    {document.selector.grupo[grp]=new Option(grp,grp)}
  }
}

function BotonMostrar()
{
  ligsel=document.selector.ligas.selectedIndex
  ligsel=document.selector.ligas[ligsel].value

  catsel=document.selector.categ.selectedIndex
  catsel=document.selector.categ[catsel].value

  grpsel=document.selector.grupo.selectedIndex

  texto=TablaRF[catsel].texto
  liga=TablaRF[catsel].liga
  codigo=TablaRF[catsel].codigo
  grupos=TablaRF[catsel].grupos

  if(grupos>0 && grpsel==0)
  {alert("Seleccione un grupo de "+texto);return}

  if(grupos==0){grpsel="1"}

  document.location.href="resultados.html?c="+liga+"|"+codigo+"|"+grpsel
}
