function initBoxes(box1,box2) {
var country=document.getElementById(box1);
var city=document.getElementById(box2);
for (i=0; i<countries.length; i++) {
  var x=document.createElement('option');
  var y=document.createTextNode(countries[i]['country']);
  if (window.attachEvent) { // for IE
  x.setAttribute('value',y.nodeValue);
  }
  x.appendChild(y);
  country.appendChild(x);
}

country.onchange=function() {
  if(this.value!="") {
   var list=document.getElementById(box2);
   while (list.childNodes[0]) {
   	list.removeChild(list.childNodes[0])
  	}
   fillBox2(city,this.value);
   }
  }

fillBox2(city,country.value);
}

function fillBox2(box2,country) {
for (i=0; i<countries.length; i++) {
 	if (countries[i]['country']==country) {
  	var cities=countries[i]['cities'];
 	}
}
for (i=0; i<cities.length; i++) {
  var x=document.createElement('option');
  var y=document.createTextNode(cities[i]);
  x.appendChild(y);
  box2.appendChild(x);
  }
}
