var x;
var y;

function cursorPosition(e){
    x = e.clientX + document.body.scrollLeft;
    y = e.clientY + document.body.scrollTop;
}

var startx;
var starty;
var objMove = false;

function objectDown(obj, e){
    obj.style.cursor = "move";
    
    if (!objMove) {
        startx = x;
        starty = y;
        objMove = true;
        wyrreg = /([-0-9]*)/;
        
        w = obj.style.left;
        h = obj.style.top;
        
        polx = parseInt(w.match(wyrreg)[1]);
        poly = parseInt(h.match(wyrreg)[1]);
    }
}

function objectMove(obj){
    obj = document.getElementById('RV_report_view');
    if (objMove) {
        vx = startx - x;
        vy = starty - y;
        
        obj.style.left = (polx - vx) + "px";
        obj.style.top = (poly - vy) + "px";
        obj.style.cursor = "move";
    }
    else {
        obj.style.cursor = "";
    }
}

function objectUp(obj){
    obj.style.cursor = "";
    objMove = false;
}


function RV_fcenter(ob){
    ob.style.display = "block";
    
    width = document.body.offsetWidth;
    height = document.body.offsetHeight;
    
    wh = alertSize();
    scr = getScrollXY();
    w = Math.min(wh[0], width);
    
    widthCont = ob.offsetWidth;
    heightCont = ob.offsetHeight;
    
    ob.style.left = (100 + wh[0] / 2 + scr[0] - widthCont / 2) + 'px';
    ob.style.top = '0px';
    //ob.style.top = (wh[1]/2+scr[1]-heightCont/2)+'px';
}


var RV_http_r3 = false;
function RV_makeRequest3(hash, fId){
    url = "reportsVault/update.php";
    RV_http_r3 = false;
    
    if (window.XMLHttpRequest) {
        RV_http_r3 = new XMLHttpRequest();
        if (RV_http_r2.overrideMimeType) {
            RV_http_r3.overrideMimeType("text/xml");
        }
    }
    else 
        if (window.ActiveXObject) {
            try {
                RV_http_r3 = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    RV_http_r3 = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
    if (!RV_http_r3) {
        return false;
    }
    
    RV_http_r3.onreadystatechange = function(){
        RV_alertContents3(RV_http_r3, hash);
    };
    RV_http_r3.open("POST", url, true);
    RV_http_r3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    RV_http_r3.send("function=show_report&hash=" + hash + "&fId=" + fId);
}

function RV_alertContents3(RV_http_r3, hash){
    if (RV_http_r3.readyState == 4) {
        ob = document.getElementById('RV_report_view_content');
        if (RV_http_r3.status == 200) {
            ob.innerHTML = RV_http_r3.responseText;
        }
        else {
            ob.innerHTML = "Wystąpił problem z zapytaniem.";
        }
    }
}

var RV_http_r2 = false;
function RV_makeRequest2(hash, val, sett){
    url = "reportsVault/update.php";
    RV_http_r2 = false;
    
    if (window.XMLHttpRequest) {
        RV_http_r2 = new XMLHttpRequest();
        if (RV_http_r2.overrideMimeType) {
            RV_http_r2.overrideMimeType("text/xml");
        }
    }
    else 
        if (window.ActiveXObject) {
            try {
                RV_http_r2 = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    RV_http_r2 = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
    if (!RV_http_r2) {
        return false;
    }
    
    RV_http_r2.onreadystatechange = function(){
        RV_alertContents2(RV_http_r2, hash);
    };
    RV_http_r2.open("POST", url, true);
    RV_http_r2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    RV_http_r2.send("function=submit_report&hash=" + hash + "&val=" + val + "&ch[0]=" + sett[0] + "&ch[1]=" + sett[1] + "&ch[2]=" + sett[2] + "&ch[3]=" + sett[3] + "&ch[4]=" + sett[4]);
}

function RV_alertContents2(RV_http_r2, hash){
    if (RV_http_r2.readyState == 4) {
        ob = document.getElementById('report_info');
        ob2 = document.getElementById('report_txt');
        if (RV_http_r2.status == 200) {
            ob.innerHTML = RV_http_r2.responseText;
            ob2.value = '';
        }
        else {
            ob.innerHTML = "Wystąpił problem z zapytaniem.";
        }
    }
}

var RV_http_r = false;
function RV_makeRequest(obid, ob, hash, val){
    url = "reportsVault/update.php";
    RV_http_r = false;
    
    if (window.XMLHttpRequest) {
        RV_http_r = new XMLHttpRequest();
        if (RV_http_r.overrideMimeType) {
            RV_http_r.overrideMimeType("text/xml");
        }
    }
    else 
        if (window.ActiveXObject) {
            try {
                RV_http_r = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    RV_http_r = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
    if (!RV_http_r) {
        return false;
    }
    
    RV_http_r.onreadystatechange = function(){
        RV_alertContents(RV_http_r, ob, hash);
    };
    RV_http_r.open("POST", url, true);
    RV_http_r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    RV_http_r.send("function=change&hash=" + hash + "&obid=" + obid + "&val=" + val);
}

function RV_alertContents(RV_http_r, ob, hash){
    if (RV_http_r.readyState == 4) {
        if (RV_http_r.status == 200) {
            ob.innerHTML = RV_http_r.responseText;
        }
        else {
            ob.innerHTML = "Wystąpił problem z zapytaniem.";
        }
    }
}
