function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
  
  currentVal += frameAmt;
  if((frameAmt > 0 && currentVal >= finalVal) 
      || (frameAmt < 0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}

function doFrame(eID, cLeft, nLeft, fLeft)
{
  var t;
  var el = document.getElementById(eID);
  if(el == null)
    return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);

  el.style.left = Math.round(cLeft) + 'px';
  
  if(cLeft == nLeft)
  {
	clearTimeout(t);
	return;
  }
    
  t = setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+')', 40);
}

function animate(elementID, newLeft, time)
{
  var el = document.getElementById(elementID);
  if(el == null)
    return;
 
  var cLeft = parseInt(el.style.left);
  
  var totalFrames = 1;
  if(time > 0)
    totalFrames = time/40;

  var fLeft = newLeft - cLeft;
  if(fLeft != 0)
    fLeft /= totalFrames;
  
  doFrame(elementID, cLeft, newLeft, fLeft);
}

function getY(elementID) {
	return document.getElementById(elementID).offsetTop;
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
  
  currentVal += frameAmt;
  if((frameAmt > 0 && currentVal >= finalVal) 
      || (frameAmt < 0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}

function doFrame(eID, cLeft, nLeft, fLeft)
{
  var t;
  var el = document.getElementById(eID);
  if(el == null)
    return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);

  el.style.left = Math.round(cLeft) + 'px';
  
  if(cLeft == nLeft)
  {
	clearTimeout(t);
	return;
  }
    
  t = setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+')', 40);
}

function animate(elementID, newLeft, time)
{
  var el = document.getElementById(elementID);
  if(el == null)
    return;
 
  var cLeft = parseInt(el.style.left);
  
  var totalFrames = 1;
  if(time > 0)
    totalFrames = time/40;

  var fLeft = newLeft - cLeft;
  if(fLeft != 0)
    fLeft /= totalFrames;
  
  doFrame(elementID, cLeft, newLeft, fLeft);
}

function getY(elementID) {
	return document.getElementById(elementID).offsetTop;
}

function submit_keyreq(lang) {
  if(document.keyreq.email.value == "") { 
    if (lang == 'magyar') {
      alert("Kérjük, adja meg e-mail címét!"); 
    } else {
      alert("Please enter your e-mail address!"); 
    }
    document.keyreq.email.focus(); 
  } else { 
    document.keyreq.submit(); 
  }
}
