// JavaScript Document

var typoSendURL="/doSendTypo.php";

var add_req;

function ctrlEnter(event, selection)
{
  if( (event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)) && (''+selection) && document.getElementById('typo-form') ) {
    //alert (''+selection);
    document.getElementById('typo-form').style.display='block';
    document.getElementById('typo-form-block').style.display='block';
    document.getElementById('typo-form-sended').style.display='none';
    document.getElementById('typo-textarea').innerHTML=selection;
    document.getElementById('typo-form-textarea-new').value='';
    document.getElementById('typo-form-textarea-new').focus();
    //document.getElementById('typo-form-textarea-new').value='There is no sens in this phrase. I\'d recommend it to correct like this: "'+selection+'"';
  }
}

function getSel() {
  var selected
 
  if (window.getSelection) selected = window.getSelection()
  else if (document.getSelection) selected = document.getSelection()
  else selected = document.selection.createRange().text

  return selected;
}
function hideTypoForm() {
  document.getElementById('typo-form').style.display='none';
}
function hideTypoFormR() {
  document.getElementById('typo-form').style.display='none';
  return false;
}
function sendTypoForm(form) {
  var params='typoformid=1';
  if ( document.getElementById('typo-textarea').innerHTML ) {
    params=params+'&typo='+document.getElementById('typo-textarea').innerHTML;
  }
  if ( form.typofixtext.value ) {
    params=params+'&fixtypo='+form.typofixtext.value;
  }
  if ( form.typopage.value ) {
    params=params+'&typopage='+form.typopage.value;
  }
  if ( form.typoname.value ) {
    params=params+'&typoname='+form.typoname.value;
  }
  if ( form.typoemail.value ) {
    params=params+'&typoemail='+form.typoemail.value;
  }
  
  typoRequest(typoSendURL,params);
  document.getElementById('typo-form-block').style.display='none';
  document.getElementById('typo-form-sended').style.display='block';
  return false; 
}

function typoRequest(url,params) {

	if (window.XMLHttpRequest) {
		 add_req = new XMLHttpRequest();
		 add_req.onreadystatechange = typoRequestResult;
		 add_req.open("POST", url, true);
     add_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     add_req.setRequestHeader("Content-length", params.length);
     add_req.setRequestHeader("Connection", "close");
		 add_req.send(params);
	} else if (window.ActiveXObject) {
		 add_req = new ActiveXObject("Microsoft.XMLHTTP");
		 if (add_req) {
		   add_req.onreadystatechange = typoRequestResult;
		   add_req.open("POST", url, true);
       add_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
       add_req.setRequestHeader("Content-length", params.length);
       add_req.setRequestHeader("Connection", "close");
		   add_req.send(params);
		 }
	}
}
function typoRequestResult(){
   if (add_req.readyState == 4) {
     if (add_req.status == 200) {
       cur = add_req.responseText;
  	   if (cur)
  	   {
  	       //document.getElementById('elem_id').innerHTML = cur;
  	   }
  	   else {
         //document.getElementById('elem_id').innerHTML = '';
       }
	   }
	   else {
       //document.getElementById('elem_id').innerHTML = 'Error '+add_req.status;
     }
   }
}



