function setContact(_action,value,type,obj) {
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
        	
            // Write result to pae element ($_RESULT become responseJS). 
            if(req.responseJS.setcontact == 'ok') {
            	//
            	if(_action=='sendMessage'){
           			document.getElementById('preloader').style.display = 'none';    
           			document.getElementById('contact').innerHTML = req.responseJS.contentBlock;
           			if(req.responseJS.errormessage=='ok'){
	            		pos = getPosition(obj);
						showBlock(document.getElementById('errorMessage'),pos['x']+150,pos['y']+180,'show'); 
						setTimeout("showBlock(document.getElementById('errorMessage'),1,1,'hide');",10000);
           			}
           			
            	}
            }
                      
            // Write debug information too (output become responseText).
           	if(req.responseText){
	           alert(req.responseText);
	           //document.getElementById('addmess').innerHTML = req.responseText;
            }    
        }
    }    
    if(_action=='sendMessage'){
	   	pos = getPosition(obj);
		showBlock(document.getElementById('preloader'),pos['x']+230,pos['y']+180,'show'); 
    }
    
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/page/ajax/php/contact_loader.php', true);
    // Send whole form data to backend.
    if(type == 'item') req.send( { '_action': _action, 'item': value} );
    if(type == 'form') req.send( { 'form': value } );
}

//
function getPosition(obj) {
	var x=0, y=0;
	while(obj) {
	   x+=obj.offsetLeft;
	   y+=obj.offsetTop;
	   obj=obj.offsetParent;
	}//alert("x="+x+", y="+y);
	// 
	return {x: x, y:y};
}

//
function showBlock(obj,x,y,_action){
	if(_action=='show'){
		obj.style.left = x+'px';
		obj.style.top = y+'px';
		obj.style.display = 'block';
	} else {
		obj.style.display = 'none';
	}
}