function focusForm() {
  if (document.login)
    document.login.username.focus();
} 

 function openPic(url) {
   width = 600;
   height = 600;
   url = '/pic.php?src=' + url;
   var win  = window.open( url, 'pic',
                'height = ' + height + ', width = ' + width + ', ' +
                'resizable = yes, ' +
                'location = no, menubar = no, status = no, toolbar = no, ' +
                'screenX = 100, left = 100, ' +
                'screenY = 100, top = 100' );
   win.focus();
 }

 function openMap(url) {
   width = 600;
   height = 600;
   var win  = window.open( url, 'map',
                'height = ' + height + ', width = ' + width + ', ' +
                'resizable = yes, ' +
                'location = no, menubar = no, status = no, toolbar = no, ' +
                'screenX = 50, left = 50, ' +
                'screenY = 50, top = 50' );
   win.focus();
 }

function openPDF(url) {
   var width = 600;
   var height = 500;
   var win  = window.open( url, 'pdf',
                'height = ' + height + ', width = ' + width + ', ' +
                'resizable = yes, ' +
                'location = no, menubar = no, status = no, toolbar = no, ' +
                'screenX = 100, left = 100, ' +
                'screenY = 100, top = 100' );
   win.focus();

}

function changeInputStyle(id, ok) {
  var e = document.getElementById(id);
  if (!ok)
   e.className = "badinput";
  else
   e.className = "goodinput";
}

function checkDateFormat(id) {
  var e = document.getElementById(id);
  if (isValidDate(e.value)) {
    e.className = "goodinput";
  } else {
    e.className = "badinput";
  }
}

/* Jos on numeroita, validoi päivämääräksi. Kirjaimet jostain syystä
 * menevät läpi.
 */
function isValidDate(dtStr) {
  var isGood = true;
  var dtCh = ".";

  var pos1 = dtStr.indexOf(dtCh);
  var pos2 = dtStr.indexOf(dtCh, pos1+1);
  var strDay = dtStr.substring(0, pos1);
  var strMonth = dtStr.substring(pos1+1, pos2);
  var strYear = dtStr.substring(pos2+1);
  var month = parseInt(strMonth)
  var day = parseInt(strDay)
  var year = parseInt(strYear)


  // löytyykö pisteet
  if (pos1 <  1 || pos2 < 2) {
    isGood = false;
  } else
  // onko oikea määrä merkkejä
  if (strMonth.length !=2 || strDay.length != 2 || strYear.length != 4) {
    isGood = false;
  } else
  // onko järkeviä merkkejä
  if (month < 1 || month > 12 || day < 1 || day > 31 || year < 1917 || year > 2011) {
   
    isGood = false;
  }
  return isGood;

}

