  var div_to_move = '';
  var apostid;
  var aparent;
  var tempX, tempY;
  document.onmousemove = mouseMove;

  function mouseMove(e) {
    if (e) {
      tempX = e.pageX;
      tempY = e.pageY-self.pageYOffset;
    } else {
      tempX = event.clientX;
      tempY = event.clientY;
    }
  }

function popup_div() {
    div_up = 'popupdiv';

    if(window.innerHeight) {
	//cHeight = window.innerHeight + window.outerHeight + window.pageYOffset;
	cHeight = (document.body.clientHeight<window.innerHeight) ? window.innerHeight : document.body.clientHeight ;
	cWidth = window.innerWidth + window.outerWidth;
    } else {
	if(window.pageYOffset) yoffset=window.pageYOffset;
	else yoffset=document.body.offsetHeight;
	cHeight = document.body.clientHeight + yoffset;
	cWidth = document.body.clientWidth;
    }

    popup = document.getElementById(div_up);
  
    if(tempX) {xpos = tempX;}
    else {xpos = '200';}

    pw = (document.body.clientWidth - 500 ) / 2;
    ph = 150;

    //popup.style.top = '100px';
    //popup.style.left = xpos+'px';

    popup.style.top = ph+'px';
    popup.style.left = pw+'px';
    popup.style.display='block';
    document.getElementById('dark').style.display='block';
    document.getElementById('dark').style.height= cHeight+'px';

}

function popdown_div() {
    document.getElementById('popupdiv').style.display='none';
    document.getElementById('dark').style.display='none';
}

function viewmore(id) {
	loadXMLDoc('req.php?module=posts&op=viewmore&postid='+id, 'more_'+id, '');
}

function viewcomments(id) {
    loadXMLDoc('req.php?module=comments&op=list&postid='+id, 'comments_'+id, '');
}

function addcomment(postid, parent) {
    loadXMLDoc('req.php?module=comments&op=ajaxadd&parent=' + parent + '&postid=' + postid, 'popupdiv', '');
    popup_div();
}

function update_comment(postid, parent) {
    apostid = postid;
    aparent = parent;
    form_data = document.forms['comment_form_' + postid + '-' + parent];
    loadXMLDoc('req.php?module=comments&op=ajaxadd&parent=' + parent + '&postid=' + postid + '&title=' + escape_nl(form_data.title.value) + '&comment=' + escape_nl(form_data.comment.value) + '&name=' + escape_nl(form_data.name.value) + '&notification=' + form_data.notification.value + '&code=' + form_data.code.value + '&email=' + form_data.email.value + '&step=2' , '', 'update_action' );
}

function update_action() {
    document.getElementById('add_comment_'+apostid).innerHTML = ''+req.responseText;
    string_req = ''+req.responseText;

    if(string_req.length < 200) {
        viewcomments(apostid);
        popdown_div('add_comment_'+apostid);
    }
}

function escape_nl(text) {
    var ntext = encodeURI(text);
    return ntext.replace(/\n/g, '<br>');
}

function image_popup(id, rotation) {
    window.open('imagepopup.php?id='+id+'&r='+rotation, 'preview', 'menubar=no, toolbar=no');
}

/* Funcions especials per diferents aparences */
function addcomment(postid, parent, div) {
    loadXMLDoc('req.php?module=comments&op=ajaxadd&parent=' + parent + '&postid=' + postid, 'addcomment_form', '');
}

function close_comment_form() {
    document.getElementById('addcomment_form').innerHTML='';
}
