function viamichelin() {
  var strStartCity        = '';
  var strDestCity         = '';
  var strStartCity        = Trim(codepage(document.route.city1.value));
  var strDestCity    = Trim(codepage(document.route.city2.value));
  var reinit              = 1;
  var strStartAddress     = '';
  var strStartCP          = '';
  var strDestAddress      = '';
  var strDestCP           = '';
//  var strDestCityCountry  = 1746;
//  var strStartCityCountry = 1746;
  var x                   = 30;
  var y                   = 15;
//  okno = window.open("http://www.viamichelin.com/viamichelin/gbr/dyn/controller/ItiWGPerformPage?reinit=" + reinit + "&strStartAddress=" + strStartAddress + "&strStartCity=" + strStartCity + "&strStartCP=" + strStartCP + "&strStartCityCountry=" + strStartCityCountry + "&strDestAddress=" + strDestAddress + "&strDestCity=" + strDestCity + "&strDestCP=" + strDestCP + "&strDestCityCountry=" + strDestCityCountry + "&x=" + x + "&y=" + y , 'michelin', 'scrollbars=yes,resizable=yes,left=0,top=0');
  okno = window.open("http://www.viamichelin.com/viamichelin/gbr/dyn/controller/ItiWGPerformPage?reinit=" + reinit + "&strStartAddress=" + strStartAddress + "&strStartCity=" + strStartCity + "&strStartCP=" + strStartCP + "&strDestAddress=" + strDestAddress + "&strDestCity=" + strDestCity + "&strDestCP=" + strDestCP + "&x=" + x + "&y=" + y , 'michelin', 'scrollbars=yes,resizable=yes,left=0,top=0');
  return false;
}

function codepage(k) {
  k = replace(k, 'È', '%3B');
  k = replace(k, '?', '%8A');
  k = replace(k, '?', '%8E');
  k = replace(k, 'è', '%26%23269%3B');
  k = replace(k, '±', '%9A');
  k = replace(k, 'µ', '%9E');
  return k;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

 function Trim(s)
{
// Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
// Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function Kraj1()
{
  if (document.route.city1.value == 'Kraj') {
    document.route.city1.value = '';
    document.route.city1.style.color = '#000000';
  }
}

function Kraj2()
{
  if (document.route.city2.value == 'Kraj') {
    document.route.city2.value = '';
    document.route.city2.style.color = '#000000';
  }
}