var fwm = 0;
var hid = 0;
var to  = 50;
var logf="";
var winh;
var lsc = 0;

function showFW(winc,mode) {
  switch(winc) {
    case 0x0:
	if(document['getElementById']==null) {
	    logonWindow(mode); return;
	}    
	if(mode=='on') {
	    if(fwm != 0) return; else fwm = 1;
	    document.getElementById('loglayer').style.visibility = "visible";
	    logf.login.focus();
	} else {
	    document.getElementById('loglayer').style.visibility = "hidden";
	    fwm = 0;
	}	
    break;
    case 0x1:
	if(document['getElementById']==null) {
	    langSelWindow(mode); return;
	}    
	if(mode=='on') {
	    if(fwm != 0) return; else fwm = 2;
	    to = 50;
	    document.getElementById('lnglayer').style.visibility = "visible";
	} else {
	    if(to) {
		hid = setTimeout("showFW(1,'off')",to);
		to = 0;
		return;
	    }
	    document.getElementById('lnglayer').style.visibility = "hidden";
	    if(hid) {
		clearTimeout(hid); hid = 0;
	    }
	    fwm =0;
	}	
    break;    
  }
}

function openMessageBox(mode) {
  alert('Sorry. This feature still doesn`t work.');
}

function langSelWindow(mode) {
  if(mode=='on') {
    if(fwm != 0) {
	winh.focus(); return; 
    } else fwm = 1;
    winh = popWindow('oper/winman.php?&sm=2','scrollbars=no,status=no,dependent=yes,resizable=no','50','130','120','61');
  } else {  
    if(window.opener==null) 
	return;
    window.opener.fwm = 0;
    window.opener.selectLanguage(lsc);    
    window.opener.wincle();
  }
}

function logonWindow(mode) {
  if(mode=='on') {
    if(fwm != 0) {
	winh.focus(); return; 
    } else fwm = 1;
    winh = popWindow('oper/winman.php?&sm=1','scrollbars=no,status=no,dependent=yes,resizable=no','50','130','420','150');
  } else {
    window.opener.fwm = 0;
    window.opener.wincle();
  }
}

function selectLanguage(lnc) {
  to = 0;
  lsc = lnc;
  showFW(1,'off');
  setCookie('ehwaz_lang',lnc,8*365*24*3600);
  location.reload();
}

function checkFields() {
  if(!logf.login.value.length) {
    alert('Warning! You must specify your login.');
    logf.login.focus(); return false;
  }
  if(!logf.passw.value.length) {
    alert('Warning! You must specify your password.');
    logf.passw.focus(); return false;
  }
  return true;
}
