var setT;
document.onkeydown = NavigateThrough;
function updateTime(time, step, prfirst, flag, time_rem) {
	var percent = 0;
	var par = window.document;
	var blok_step_cons = 0;
	var blok_step = 0;
	var timer = 0;

	if(flag == 1){
		step = step*60*1000;
	  percent = (prfirst/time)*100; // real percent
	  blok_step_cons = (percent/100)*120;
	  block_step = 120;
	  timer = 0;
  }
  else if(flag == 2){
  	step = step*60*1000;
	  percent = (prfirst/time)*100; // real percent
	  blok_step_cons = (percent/100)*120;
	  block_step = 120;
	  timer = time_rem;
  }
  else {
		 percent = (prfirst/time)*100;
		 blok_step_cons = (percent/100)*120;
		 block_step = flag;
		 timer = time_rem;
  }

  var prpercent = (block_step/120)*100;

  //color of status block
  if(prpercent > 50) {
  	par.getElementById('strong_1').style.background = "#5EAA5E";
  }
  if(prpercent > 25 && prpercent <= 50) {
  	par.getElementById('strong_1').style.background = "#E8911B";
  }
  if(prpercent <= 25) {
  	par.getElementById('strong_1').style.background = "#FF0000";
  }

  block_step = block_step - blok_step_cons;
  if (flag == 1 || flag == 2) {
  	timer = time;
  }
  else {
  	timer = timer - prfirst;
  }

  par.getElementById('strong_1').style.width = prpercent+"%";

  if (timer >= 10) {
  	par.getElementById('beeper_time').innerHTML = timer+":00 min";
  }
  else {
  	par.getElementById('beeper_time').innerHTML = "0"+timer+":00 min";
  }

  if (block_step < 0) {
  	window.location.reload();
  }
  if(flag == 2) {
  	clearTimeout(setT);
  }
  setT = setTimeout("updateTime("+time+", "+step+", "+prfirst+", "+block_step+", "+timer+");", step);
}
function checkLogin(uid) {
  xajax_studioLogoutByAdmin(uid,0);  
  setTimeout("checkLogin('"+uid+"');",10000);     
}
function addCaseSelf(edit) {
	xajax_addCaseSelf(top.xajax.getFormValues('case_add_form'), edit);   
}
function addWordSelf(edit) {
	xajax_addWordSelf(top.xajax.getFormValues('word_add_form'), edit);   
}
function wordFocus() {
	document.getElementById('word').focus();	
}

function NavigateThrough (event){
	if (!document.getElementById) return;

	if (window.event) event = window.event;

	if (event.ctrlKey)	{
		var link = null;
		var href = null;
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
		{
			case 0x27://up
				//link = document.getElementById ('AddWordLink');
				if(!document.getElementById('word') || document.getElementById('word').value == "")xajax_addWordForm();
				break;
			case 0x28://down
				//link = document.getElementById ('saveWord');
				if(document.getElementById('word') && document.getElementById('word').value != "") addWordSelf(0);
				break;
			case 0xA://down
				//link = document.getElementById ('saveWord');
				if(document.getElementById('word') && document.getElementById('word').value != "") addWordSelf(0);
				break;
			case 0xD://down
				//link = document.getElementById ('saveWord');
				if(document.getElementById('word') && document.getElementById('word').value != "") addWordSelf(0);
				break;
		}
		//if (link && link.href) document.location = link.href;
		//if (href) document.location = href;
	}			
}

