﻿// this javascript file contains functions for AJAX interaction
// whilst editing page content block size and position
var req;

function ajaxBlockUpdate(varBlockID,varDataX,varDataY,varDataW,varDataH)
{
    /* This function performs a database record update via AJAX to store
     * block property changes in the SQL Server table CMS_BlockPositioned */
    
    // define the URL for the update
    var varURL = "/admin/scripts/ajax_cmsblockupdate.aspx?id=" + varBlockID;
    varURL += "&x=" + varDataX + "&y=" + varDataY + "&w=" + varDataW + "&h=" + varDataH;
    
    // call the URL via AJAX
    loadXMLDoc(varURL);
}

function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
        } else {
            alert("There was a problem saving the block data:\n" + req.statusText);
        }
    }
}
