Zend certified PHP/Magento developer

How can I update “Photoshop Script – Grid to Layers” for rectangles instead of squares..?

Can anyone please tell me how to change the below code, for rectangles instead of squares…

/*
——–Photoshop Script – Grid to Layers————
Original Script Author: Oisin Conolly (www.DigitalBiscuits.co.uk)
Modified by a stackoverflow user.

This basic script will create new layers from your active layer, each equal in size according to the grid dimensions specified.
*/

//Use docRef.selection.copy() will throw exception when try to copy empty selection
//https://community.adobe.com/t5/photoshop/try-to-copy-when-no-pixels-where-selected/td-p/10417075
function TryCopySelection()
{
try { executeAction(stringIDToTypeID(“copyEvent”), undefined, DialogModes.NO); } catch(e) { return false; }
return true;
}

//Paste in place is required as otherwise, paste item could be at incorrect position
//https://stackoverflow.com/questions/25904603/paste-in-place-photoshop-script
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function PasteInPlace() {
var dialogMode = DialogModes.NO;
var desc1 = new ActionDescriptor();
desc1.putBoolean(sTID(“inPlace”), true);
desc1.putEnumerated(cTID(‘AntA’), cTID(‘Annt’), cTID(‘Anno’));
executeAction(cTID(‘past’), desc1, dialogMode);
};

//this is the size of our squares in pixels
var squareSize = 1024;
squareSize = parseInt(prompt(“Please enter slice grid size:”, 1024));

var docRef = app.activeDocument;

//set the ruler type
if (app.preferences.rulerUnits != Units.PIXELS)
app.preferences.rulerUnits = Units.PIXELS;

var sourceLayer = docRef.activeLayer;
var layerSet = docRef.layerSets.add(); //Create new layer group
layerSet.name = sourceLayer.name + ” Group”;

for (y = 0; y<docRef.height; y+=squareSize)
{
for (x = 0; x<docRef.width; x+=squareSize)
{
//activate the original layer
docRef.activeLayer = sourceLayer;
//make the selection
docRef.selection.select(Array (Array(x, y), Array(x, y+squareSize), Array(x+squareSize,y+squareSize), Array(x+squareSize,y)), SelectionType.REPLACE, 0, false);

    //copy the selection
    if(TryCopySelection())
    {
        var layer = docRef.artLayers.add(); //create and paste new layer
        PasteInPlace()
        layer.move(layerSet, ElementPlacement.INSIDE);
    }
}

}

Help would be much appreciated.

Regards

Nick.