var d = document;
var offsetfromcursorY=15 // y offset of tooltip
var ie=d.all && !window.opera;
var ns6=d.getElementById && !d.all;
var tipobj,op;


function tooltip(el,txt) {
tipobj=d.getElementById('mess');
tipobj.innerHTML = txt;
op = 0.1;   
tipobj.style.opacity = op; 
tipobj.style.visibility="visible";
el.onmousemove=positiontip;
appear();
}

function hide_info(el) {
d.getElementById('mess').style.visibility='hidden';
el.onmousemove='';
}

function ietruebody(){
return (d.compatMode && d.compatMode!="BackCompat")? d.documentElement : d.body
}

function positiontip(e) {
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
var winwidth=ie? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie? ietruebody().clientHeight : window.innerHeight-20
 
var rightedge=ie? winwidth-event.clientX : winwidth-e.clientX;
var bottomedge=ie? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
 
if (rightedge < tipobj.offsetWidth)  tipobj.style.left=curX-tipobj.offsetWidth+"px";
else tipobj.style.left=curX+"px";
 
if (bottomedge < tipobj.offsetHeight) tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
else tipobj.style.top=curY+offsetfromcursorY+"px";
}
 
function appear() { 
if(op < 1) {
op += 0.1;
tipobj.style.opacity = op;
tipobj.style.filter = 'alpha(opacity='+op*100+')';
t = setTimeout('appear()', 30);
}
}


var targetObj;
var httpReq;
function makeRequest(url) {

        httpReq = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            httpReq = new XMLHttpRequest();
            if (httpReq.overrideMimeType) {
                httpReq.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                httpReq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpReq) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpReq.onreadystatechange = function() { writeContents(httpReq); };
        httpReq.open('GET', url, true);
        httpReq.send(null);

}
var requestLoading = function() {}
var requestReady = function() {}
var requestError = function() {}
function writeContents(httpReq) {
        
        if (httpReq.readyState == 1)
        {
            requestLoading();
        }
        
        if (httpReq.readyState == 4) {
            if (httpReq.status == 200) {
                requestReady();
            } else {
                requestError();
            }
        }

}
function sentComment(inputObjID)
{	
	inputObj = document.getElementById(inputObjID);
	comm_author = document.getElementById("comm_author");
	comm_mail = document.getElementById("comm_mail");
	comm_text = document.getElementById("comm_text");
	comm_block = document.getElementById("comm_block");
	i_robot = document.getElementById("i_robot");
	
    requestLoading = function() {
        inputObj.innerHTML = comm_author.value + " - Ваш комментарий оптравляется на проверку!";
    }
    requestReady = function() {
        var resp = httpReq.responseText;
		inputObj.innerHTML = resp;
    }
    if (comm_author.value == "")
    {
      alert("Вы не ввели свое имя!");
    } else {
      if (comm_mail.value == "")
      {
        alert("Вы не ввели свой почтовый адрес!");
      } else {
        if (comm_text.innerText == "")
        {
          alert("Вы не ввели текст комментария!");
        } else {
          if (i_robot.value == "0")
          {
            alert("Вы представились как бот. Спам-ботам запрещено оставлять сообщения на сайте!");
          } else {
            makeRequest("http://vslevel.com/comm_ajax.php?author="+comm_author.value+"&email="+comm_mail.value+"&comment="+comm_text.innerText + "&block=" + comm_block.value);
          }
        }
      }    
    }
}
