document.onkeypress = kHCorrection;
function validateEmail(email) {
  if (email.length > 0) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false) {
      alert('Неверный формат поля e-Mail');
      return false;
    }
  }
  return true;
}
function correctText(sStr) {
  var sStr = sStr.replace("'", ' ')
  sStr = sStr.replace("\x0D\x0A", ' ')
  sStr = sStr.replace('"', ' ')
  sStr = sStr.replace('%', ' ')
  sStr = sStr.replace('?', ' ')
  return sStr;
}
function correctSuccess(e) {
    $('contOrph').hide(); 
	if(!e.responseJSON.error){
	  $('ansOrphCont').style.top = document.body.scrollTop + 300 + "px";	
      $('ansOrphCont').show();  
	}
}
function putSelCorrection(txt) {
/*
  if (txt.length < 3) {
    $('inpOrph').update(
        'Вы не выделили текст ошибки. Выделите и нажмите Ctrl+Enter.');
    $('recinfoOrph').setValue('');
  } else {
  */
    if(txt.toString().length>200){
	  $('contOrph').style.top= document.body.scrollTop + 50 + "px";
	  $('contOrph').style.left= "10%";
	  $('contOrph').style.width= "80%";
	}
    $('inpOrph').update('В выражении "' + txt.toString().substring(0,1000) + '" замечена ошибка.');
    $('recinfoOrph').setValue(txt);  
}
function getSelCorrection() {
  var txt;
  if (window.getSelection) {
    txt = window.getSelection();
  } else if (document.getSelection) {
    txt = document.getSelection();
  } else if (document.selection) {
    // txt = document.selection.createRange().text;
    var oRange = document.selection.createRange();

    for (i = 0; i < oRange.length; i++)
      if (oRange(i).style.display == 'none'
          || oRange(i).style.visibility == 'hidden')
        oRange.remove(oRange(i));
    txt = oRange.text;

  }
  return txt;
}
function kHCorrection(e) {
  var pressed = 0;
  var we = null;
  if (window.event)
    we = window.event;
  else if (parent && parent.event)
    we = parent.event;
  if (we) {
    pressed = we.keyCode == 10 || (we.keyCode == 13 && we.ctrlKey);
  } else if (e) {
    pressed = (e.which == 10 && e.modifiers == 2)
        || (e.keyCode == 0 && e.charCode == 106 && e.ctrlKey)
        || (e.keyCode == 13 && e.ctrlKey)
  }
  if (pressed) {
    putSelCorrection(getSelCorrection());
    $('gberrId').setValue(1);
    $('rectextOrph').setValue('');
    $('ansOrphCont').hide();    
    $('contOrph').show();
  }
}
function doHide(divName) {
  document.getElementById(divName).style.display = 'none';
}

