function sw(n) { myRe=/&(ct=\d+|s=\d+)/g;
 location = String(location).replace(myRe, "") + "&ct=" + n.value;
}
function swd(n) {
 myRe=/&s=\d+/g;
 location = String(location).replace(myRe, "") + "&s=" + n.value;
}
function switchO(id){
 o=document.getElementById(id).style;
 o.display=(o.display=="none")?"":"none";
}
function dispAdd(id) {
 switchO("b"+id);
 switchO("hp"+id);
 switchO("hm"+id);
}
function donoth(){
 return;
}
function popup(src,width,height) {
 var w='menubar=no,location=no,scrollbars=yes,status=no,titlebar=yes,toolbar=no,resizable=yes,width='+(width)+',height='+(height)+',top=30'+',left=100';
 nw=window.open(src,'popup',w);
 nw.focus();
 return nw;
}
function textCounter(field, countfield, maxlimit) 
 { 
/*  if (field.value.length > maxlimit)
   {
    field.value = field.value.substring(0, maxlimit);
   }
  else
   {*/
    cnt = maxlimit - field.value.length;
    if (cnt <= 0) countfield.style.color='red'; else countfield.style.color='';
    countfield.innerHTML = cnt;
//   }
 }
function checkForm(field, maxlimit){
  if (document.getElementById('cntnt').value.length>0 && document.getElementById('wnm').value.length>0 && 
      document.getElementById('eml').value.length>0 && document.getElementById('wur').value.length>0   &&
      document.getElementById('aut').value.length>0 ) {
    if (maxlimit - field.value.length < 0) {
        alert("Слишком длинный текст новости.");
	return false;
    } else {
	return true;
    }
  } else {
    alert("Для размещения новости должны быть заполнены все поля.");
  }
  return false;
}
// notify admin on errors
function getKeyPress(e){
	var p = 0;
	if (ev = window.event) {
		p = (ev.keyCode==10) || (ev.keyCode==13 && ev.ctrlKey); 
	} else if (e) {
		p = (e.which==10 && e.modifiers==2) || (e.keyCode==0 && e.charCode==106 && e.ctrlKey) || (e.keyCode==13 && e.ctrlKey);
	}		
	if(p){
		notify();
		return false;
	}
	
}
function notify(){
	if (window.getSelection) {
		sel = window.getSelection();
	} else if (window.document.getSelection) {
		sel = window.document.getSelection();
	}	else if (document.selection) { 
		sel = document.selection.createRange();
	}			
	if (!sel) {alert("Ошибка: Не могу обработать выделение."); return; } 

	res = '';
	if (sel.getRangeAt) { //W3C code
		if (sel.isCollapsed) {
			alert("Ничего не выбрано. Выделите текст перед отправкой.");
			return;
		} else {
			res = sel.getRangeAt(0).toString();
		}
	} else if (sel.text != undefined) { //IE code
			if (!sel.text) {alert("Ничего не выбрано. Выделите текст перед отправкой."); return;}
			res = sel.text;
	} else {
			res = sel + '';
	}
	if (res.length > 200) {alert("Выделен слишком длинный фрагмент.");return;}

	//if (confirm('Пожалуйста, подтвердите отправку найденной ошибки:\n\n'+'    '+res+'\n')) {
	if (corr=prompt('Пожалуйста, предложите свой вариант исправления найденной ошибки:',res)) {
	    var req = new JsHttpRequest();
	    req.onreadystatechange = function() {
		if (req.readyState == 4) {
		    if (req.responseJS) {
			alert("Спасибо за помощь!");
		    } else {
			alert("Ошибка отправки сообщения.");
		    }
		}
	    }
	    req.open('POST', 'syntax_handler.php', true);
	    req.send( { url:document.URL, err:res, corr:corr } );
	}
}

function showLF() {
	document.getElementById('ilogin').style.display='none';
	document.getElementById('flogin').style.display='block';
	document.getElementById('nlogin').focus();
	
	return false;
}

function adjust_popup(el)
{
	var el=document.getElementById(el);
    var w, h, fixedW, fixedH, diffW, diffH;
    
    fixedW = el.offsetWidth;
    fixedH = el.offsetHeight;

    if (document.documentElement && document.body.clientHeight==0) {
            window.resizeTo(fixedW, fixedH);
            diffW = fixedW - document.documentElement.clientWidth;
            diffH = fixedH - document.documentElement.clientHeight;
            w = fixedW + diffW + 16;
            h = fixedH + diffH;
            if (w >= screen.availWidth) h += 16;
    } else if (document.all) {
            window.resizeTo(fixedW, fixedH);
            diffW = fixedW - document.body.clientWidth;
            diffH = fixedH - document.body.clientHeight;
            w = fixedW + diffW + 2;
            h = fixedH + diffH - 15;
            if (h >= screen.availHeight) w += 16;
            if (w >= screen.availWidth)  h += 16;
    } else {
            window.resizeTo(fixedW, fixedH);
            diffW = fixedW - window.innerWidth;
            diffH = fixedH - window.innerHeight;
            w = fixedW + diffW + 2;
            h = fixedH + diffH + 2;
            if (w >= screen.availWidth)  h += 16;
            if (h >= screen.availHeight) w += 16;
    }
    
    w = Math.min(w,screen.availWidth);
    h = Math.min(h,screen.availHeight);
    window.resizeTo(w,h);
    window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

document.onkeypress=getKeyPress;
