var deviceNameInTextField = false;


function setDevice() {
 if(!deviceNameInTextField) {
  if(selD) {
   document.getElementById('deviceDisplay').innerHTML = selV + ' ' + selDn;
  } else {
   document.getElementById('deviceDisplay').innerHTML = '&nbsp;';
  }
 } else {
  if(selD) {
   document.getElementById('deviceDisplay').value = selV + ' ' + selDn;
  } else {
   document.getElementById('deviceDisplay').value = '';
  }
 }

 document.getElementById('sdevice_id').value = selD;
}

function setDevice4PhoneSelect() {
 if(!deviceNameInTextField) {
  if(selD) {
   document.getElementById('deviceDisplay').innerHTML = selV + ' ' + selDn;
  } else {
   document.getElementById('deviceDisplay').innerHTML = '&nbsp;';
  }
 } else {
  if(selD) {
   document.getElementById('deviceDisplay').value = selV + ' ' + selDn;
  } else {
   document.getElementById('deviceDisplay').value = '';
  }
 }

 document.getElementById('sdevice_id').value = selD;
 document.getElementById('soperator_id').value = selO;
/* document.getElementById('soperator_id').value = '';*/
}

function clearList(lst) {
 for(x = lst.length; x >= 0; x--) lst[x] = null;

 if(lst == lstC) selC = '';
 else if(lst == lstO) selO = 0;
 else if(lst == lstV) selV = '';
 else if(lst == lstD) {
  selDn = '';
  selD = 0;
  setDevice();
 }
}

function FillUpCountry() {
 clearList(lstC);
 clearList(lstO);
 clearList(lstV);
 clearList(lstD);
 lstC.value='World';
/*
 for (var i = 0; i < country.length; ++i) {
  lstC.options[i] = new Option(country[i]);
 }
*/ 
}

function FillUpOperators() {
 clearList(lstO);
 clearList(lstV);
 clearList(lstD);
 lstO.value=43;
/*
 for(var i = 0; i < operators[selC].length; ++i) {
  lstO.options[i] = new Option(operators[selC][i]['name'], operators[selC][i]['id']);
 }
*/ 
}

function FillUpVendors() {
 clearList(lstV);
 clearList(lstD);

 for(var i = 0; i < vendors['World'][43].length; ++i) {
  lstV.options[i] = new Option(vendors['World'][43][i],selO);
 }

}

function FillUpModels() {
 clearList(lstD);
/* alert(models['World'][43][selV].length); */
 for(var i = 0; i < models['World'][43][selV].length; ++i) {
  lstD.options[i] = new Option(models['World'][43][selV][i]['name'], models['World'][43][selV][i]['id']);
 }
}

/* ******************** */
/* check phone selection */
function checkPhoneSelect(msgOperator, msgVendor, msgModel, msgCountry){
/* listOperators, listVendors, listDevices,listCountry */
 var country = document.getElementById('listCountry');
/* country.value = '';*/
 if(country.value == 'Select your country'){
  alert(msgCountry);
  return false;
 }
 var operator = document.getElementById('listOperators');
/* operator.value = '';*/
 if(operator.value == ''){
  alert(msgOperator);
  return false;
 } 
 var vendor = document.getElementById('listVendors');
 if(vendor.value == ''){
  alert(msgVendor );
  return false;
 }
 
 var device = document.getElementById('listDevices');
 if(device.value == ''){
  alert(msgModel);
  return false;
 }
 return true;
}
