
function getByID(id) {
	if (document.all) {	
		return document.all[id];
	} else {
		return document.getElementById(id);
	}
}

function add_m(){
 num_s = getByID("metro_s").options.selectedIndex;
 p_id = getByID("metro_s").options[num_s].value;
 len_d = getByID("metro_holder").options.length;
 if (getByID("metro_s").options.selectedIndex!=-1){
  var set;
  for(i=0; i<len_d; i++){ if(getByID("metro_holder").options[i].value == getByID("metro_s").options[num_s].value) set = true; }
  if(!set) getByID("metro_holder").options[len_d] = new Option(getByID("metro_s").options[num_s].text, getByID("metro_s").options[num_s].value);
 }
  //metro[p_id][1] = 1;
  //if (mimg[p_id]) a.map.appendChild(mimg[p_id]);
}

function del_m(){
 num = getByID("metro_holder").options.selectedIndex;
 p_id = getByID("metro_holder").options[num].value;
 if(num!=-1) getByID("metro_holder").remove(num);
  //metro[p_id][1] = 0;
  //if (mimg[p_id]) a.metromap.removeChild(mimg[p_id]);
}

function checkpoint(p_id)
{
 if(metro[p_id][1] == 0) metro[p_id][1] = 1; else metro[p_id][1] = 0;
 if(metro[p_id][1] == 1)
 {
       len_d = getByID("metro_holder").options.length;
       var op_num=-1;
       for(i=0; i<getByID("metro_s").options.length; i++)
       {
           if(getByID("metro_s").options[i].value == p_id)
           {
               op_num = i;
               break;
           }
       }
       if (op_num != -1)
       {
           getByID("metro_holder").options[len_d] = new Option(getByID("metro_s").options[op_num].text, getByID("metro_s").options[op_num].value);
           if (mimg[p_id]) a.metromap.appendChild(mimg[p_id]);
       }
 }
 else
 {
   if (mimg[p_id]) a.metromap.removeChild(mimg[p_id]);
   len_d = getByID("metro_holder").options.length; num = -1;
   for(i=0; i<len_d; i++)
   {
       if(getByID("metro_holder").options[i].value == p_id)
       {
           num = i;
           break;
       }
   }
   if(num!=-1) getByID("metro_holder").options.remove(num);
 }
}

function fsubmit()
{
 getByID("metro_s").value = null;
 for (i=0; i<getByID("metro_holder").length; i++){ getByID("metro_holder").options[i].selected = true; }
 document.fullsearchform.submit();
}

function fadd()
{
 for (i=0; i<a["metro_s"].length;)
 {
  a["metro_s"].options[i].selected = true;
  add_m();
 }
}

function freset()
{
 for (i=0; i<getByID("metro_holder").length;)
 {
   p_id = getByID("metro_holder").options[i].value;
   if(i!=-1) getByID("metro_holder").remove(i);
   //metro[p_id][1] = 0;
   //if (mimg[p_id]) a.metromap.removeChild(mimg[p_id]);
 }
}

function country_update() {

	var country_select = getByID("country");
	var active_country;
	for (var i=0; i < country_select.childNodes.length; i++) {
		var child = country_select.childNodes[i];
		
		if (child.selected) active_country = child.value;
	}
	
	var metro_s = getByID("metro_s");
	
	while (metro_s.childNodes.length > 0) {
		metro_s.removeChild(metro_s.childNodes[0]);
	}

	for (var k in window.countries) {
		if (active_country != 0 && window.countries[k] != active_country) continue;
		
		var elem = document.createElement('OPTION');
		elem.value = k;
		elem.innerHTML = window.towns[k];
		
		metro_s.appendChild(elem);
	}

}

