var form = document.frm1;

var area = 4;
var town = new Array(area);
var townselect = new Array(1);
for (i=0; i<area; i++){town[i]=new Array();}


function fncNoZero() {
  town = new Array(area);
  townselect[0]  = new Option("Select Town","0");
  
  for (i=0; i<area; i++){town[i]=new Array();}

  // Costa Blanca
  town[0][0]  = new Option("Albir","230");
  town[0][1]  = new Option("Alenda Golf","293");
  town[0][2]  = new Option("Alfaz del Pi","294");
  town[0][3]  = new Option("Algorfa","227");
  town[0][4]  = new Option("Alicante","93");
  town[0][5]  = new Option("Almoradi","232");
  town[0][6]  = new Option("Altea","3");
  town[0][7]  = new Option("Benejuzar","236");
  town[0][8]  = new Option("Benidorm","295");
  town[0][9]  = new Option("Benijofar","237");
  town[0][10] = new Option("Benimantell","238");
  town[0][11] = new Option("Benissa","26");
  town[0][12] = new Option("Benitachell","27");
  town[0][13] = new Option("Blue Lagoon","239");
  town[0][14] = new Option("Bonalba Golf","296");
  town[0][15] = new Option("Busot","240");
  town[0][16] = new Option("Cabo Roig","297");
  town[0][17] = new Option("Calpe","25");
  town[0][18] = new Option("Campoamor","226");
  town[0][19] = new Option("Campoverde","299");
  town[0][20] = new Option("Castalla","245");
  town[0][21] = new Option("Catral","300");
  town[0][22] = new Option("Cumbre de Sol","302");
  town[0][23] = new Option("Daya Nueva","1332");
  town[0][24] = new Option("Daya Vieja","247");
  town[0][25] = new Option("Denia","23");
  town[0][26] = new Option("Dolores","248");
  town[0][27] = new Option("Dona Pepa","303");
  town[0][28] = new Option("El Campello","250");
  town[0][29] = new Option("El Galan","251");
  town[0][30] = new Option("El Mojon","304");
  town[0][31] = new Option("El Portet","305");
  town[0][32] = new Option("El Raso","306");
  town[0][33] = new Option("Finestrat","307");
  town[0][34] = new Option("Formentera","255");
  town[0][35] = new Option("Gata de Gorgos","308");
  town[0][36] = new Option("Gran Alacant","257");
  town[0][37] = new Option("Guadalest","258");
  town[0][38] = new Option("Guardamar","21");
  town[0][39] = new Option("Guardamar del Segura","253");
  town[0][40] = new Option("Jacarilla","261");
  town[0][41] = new Option("Javea","2");
  town[0][42] = new Option("Jesus Pobre","256");
  town[0][43] = new Option("La Cala","310");
  town[0][44] = new Option("La Finca","311");
  town[0][45] = new Option("La Marina","263");
  town[0][46] = new Option("La Mata","264");
  town[0][47] = new Option("La Nucia","312");
  town[0][48] = new Option("La Regia","265");
  town[0][49] = new Option("La Siesta","313");
  town[0][50] = new Option("La Zenia","317");
  town[0][51] = new Option("Las Ramblas","318");
  town[0][52] = new Option("Lo Crispin","319");
  town[0][53] = new Option("Lo Marabu","320");
  town[0][54] = new Option("Los Altos","322");
  town[0][55] = new Option("Los Balcones","323");
  town[0][56] = new Option("Los Dolses","324");
  town[0][57] = new Option("Los Montesinos","268");
  town[0][58] = new Option("Mil Palmeras","327");
  town[0][59] = new Option("Monforte del Cid","231");
  town[0][60] = new Option("Moraira","8");
  town[0][61] = new Option("Murla","272");
  town[0][62] = new Option("Mutxamel","273");
  town[0][63] = new Option("Orihuela Costa","241");
  town[0][64] = new Option("Orxeta","275");
  town[0][65] = new Option("Pilar De La Horadada","269");
  town[0][66] = new Option("Playa Flamenca","330");
  town[0][67] = new Option("Polop","331");
  town[0][68] = new Option("Punta Prima","332");
  town[0][69] = new Option("Quesada","249");
  town[0][70] = new Option("Relleu","333");
  town[0][71] = new Option("Rojales","197");
  town[0][72] = new Option("San Fulgencio","336");
  town[0][73] = new Option("San Juan de Alicante","220");
  town[0][74] = new Option("San Miguel de Salinas","338");
  town[0][75] = new Option("Teulada","175");
  town[0][76] = new Option("Torre De La Horadada","340");
  town[0][77] = new Option("Torrestrella","341");
  town[0][78] = new Option("Torremanzanas","285");
  town[0][79] = new Option("Torremendo","342");
  town[0][80] = new Option("Torrevieja","228");
  town[0][81] = new Option("Villajoyosa","291");
  town[0][82] = new Option("Xixona","289");
  
  // Costa Calida
  town[1][0]  = new Option("Camposol","298");
  town[1][1]  = new Option("Condado De Alhama","301");
  town[1][2]  = new Option("El Mojon","304");
  town[1][3]  = new Option("El Valle","277");
  town[1][4]  = new Option("La Manga","262");
  town[1][5]  = new Option("La Tercia","314");
  town[1][6]  = new Option("La Torre Golf","315");
  town[1][7]  = new Option("La Union","316");
  town[1][8]  = new Option("Los Alcazares","321");
  town[1][9]  = new Option("Mar de Cristal","325");
  town[1][10] = new Option("Mar Menor","266");
  town[1][11] = new Option("Mazarron","243");
  town[1][12] = new Option("Murcia","328");
  town[1][13] = new Option("Playa Honda","278");
  town[1][14] = new Option("Puerto De Mazarron","279");
  town[1][15] = new Option("Roda Golf","334");
  town[1][16] = new Option("San Javier","337");
  town[1][17] = new Option("San Pedro del Pinatar","284");
  town[1][18] = new Option("Sucina","259");
  town[1][19] = new Option("Totana","343");

// Granada
  town[2][0]  = new Option("Granada","361");
  town[2][1]  = new Option("Velez de Benaudalla","362");

// Costa Almeria
  /*
  town[2][0]  = new Option("Arboleas","233");
  town[2][1]  = new Option("Bedar","234");
  town[2][2]  = new Option("Los Gallardos","235");
  town[2][3]  = new Option("Mojacar","270");
  town[2][4]  = new Option("Palomares","276");
  town[2][5]  = new Option("Turre","286");
  town[2][6]  = new Option("Valle del Este","344");
  town[2][7]  = new Option("Vera","287");
  town[2][8]  = new Option("Villaricos","288");

  // Costa del Sol
  town[3][0]  = new Option("Benalmadena","110");
  town[3][1]  = new Option("Estepona","117");
  town[3][2]  = new Option("Marbella","127");
  town[3][3]  = new Option("Mijas","128");
*/
}

function selectRegions(elem) {
  fncNoZero();
  var m=0;
  var whichArray=new Array;

  if (elem.value == "0") {
//    document.frm1.taH.value = "";

	// CLEAR THE CURRENT OPTIONS OUT
    for (j=document.frm1.location.options.length;j>-1;j--) {
      document.frm1.location.options[j]=null;
    }
	
	document.frm1.location.options[0]=new Option("Select Region");

    // SET THE ARRAY WITH THE town ARRAYS NEEDED FOR THE LIST
    for (k=0;k<area;k++) {
      whichArray[m] = k;
      m++;
    }
  } else {
//	  if(elem.selectedIndex != -1) {
//        document.frm1.taH.value = "turistic_area=" + elem.value + "&";
//	  }

      // CLEAR THE CURRENT OPTIONS OUT
      for (j=document.frm1.location.options.length;j>-1;j--) {
        document.frm1.location.options[j]=null;
      }

      // SET THE ARRAY WITH THE town ARRAYS NEEDED FOR THE LIST

      for (k=0;k<area;k++) {
        if (document.frm1.turistic_area.options[k].selected == true) {
          whichArray[m] = k;
          m++;
        }
      }
	  
      // ADD THE SECOND LIST ITEMS IN
      var i=0;
	  document.frm1.location.options[i] = new Option("Select Town","0");
	  i++;

      for (y=0;y<whichArray.length;y++) {
        x=whichArray[y]-1;
        for (s=0;s<town[x].length;s++) {
          document.frm1.location.options[i]=new Option(town[x][s].text,town[x][s].value);
          i++;
        }
      }
  }
  
  selectTowns();
}

function checkID(evt) {
  var evt  = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

  if (evt.keyCode == 13) {
	takeValue(document.frm1.id)
    document.frm1.submit();
  } else if (evt.keyCode == 44) {
    window.event.cancelBubble = false;
    window.event.returnValue = true;
    return false;
  } else if (evt.keyCode < 48 || evt.keyCode > 57) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
  }
}
  
function emptyIDField(elem) {
  if(elem.value=="Property ID") {
    elem.value="";
  }
}
  
function takeValue(elem) {
  if(elem.value=="") {
    elem.value="Property ID";
//    document.frm1.idH.value = "";
  } else if(elem.value=="Property ID") {
    elem.value="Property ID";
//    document.frm1.idH.value = "";
  }
  else {
//    document.frm1.idH.value = "id=" + elem.value + "&";
  }
}

function selectTowns() {
  var v_ref = document.frm1.location;
  var selec = "";
  for(i=0;i<v_ref.options.length;i++) {
    if (v_ref.options[i].selected == true && v_ref.options[i].value != 0) {
      selec += "location=" + v_ref.options[i].value + "&";
    }
  }
//  document.frm1.lnH.value = selec;
}
	
function selectPeople(elem) {
  if(elem.value > 0) {
    document.frm1.peH.value = "people=" + elem.value + "&";
  } else {
	document.frm1.peH.value = "";
  }
}
	
function selectPTypes(elem) {
  if (elem.value == "0") {
    document.frm1.tyH.value = "";
  } else {
    document.frm1.tyH.value = "type=" + elem.value + "&";
  }
}

function selectPStyles() {
  var v_ref = document.frm1.st;
  var ptypes = "";
  for(i=0;i<v_ref.options.length;i++) {
    if (v_ref.options[i].selected == true) {
      ptypes += "st=" + v_ref.options[i].value + "&";
    }
  }
  document.frm1.stH.value = ptypes;
}

function jump2Page(page) {
  elemPage = document.frm1.pagenumber;
  
  if(page=="+") {
    elemPage.value = ++elemPage.value;
  } else if(page=="-") {
    elemPage.value = --elemPage.value;
  } else {
    elemPage.value = page;
  }

  document.frm1.submit();
}

function newSearch() {
  window.open("../rentals/en/search.html","_self");
}

function changeSearch() {
  document.frm1.method = "get";
  document.frm1.action = "../rentals/en/search.html";
  document.frm1.submit();
}
