//-------------------------v.1.0.2----------------
function myScript(thisObj) {
    function myScript_buildUI(thisObj) {
        var myPanel = thisObj instanceof Panel ? thisObj : new Window("palette", "Change Resolution", [0, 0, 50, 25]);
    
     var groupOne = myPanel.add("group", undefined, "grpOne");
        groupOne.orientation = "column";
        groupOne.alignment = ["left", "top"];
        groupOne.alignChildren = ["left", "center"];
        groupOne.spacing = 5;

        var s;
        s = groupOne.add("statictext",undefined,"Width:");   
        var  wh = groupOne.add("edittext",undefined,"1920");   
       wh.size = [80,24];   
        s = groupOne.add("statictext",undefined,"Height:");   
        var  ht = groupOne.add("edittext",undefined,"1080");   
       ht.size = [80,24];   
         var goButton = groupOne.add("button",undefined,"Change");
             
       myPanel.layout.layout(true);
        myPanel.layout.resize();
        myPanel.onResizing = myPanel.onResize = function() {
            this.layout.resize();
        };
    
        
        goButton.onClick = function() {
            
                var w = returnNumber(wh.text, "Width", 0, 10000);
                var h = returnNumber(ht.text, "Height", 0, 10000);
                if(w[0]==false || h[0]==false)return;
                var proj = app.project;
                var selItems= proj.selection;
                      if(selItems!=""){
                          app.beginUndoGroup("Change Resolution");
                            for(var i=0;i<selItems.length;i++){
                                changeResolution(selItems[i],w[1],h[1]);
                             }
                         app.endUndoGroup;
                        }else{
                            alert("Select folders or compositions in the project window");
                        }
            };
      
                //-------------------------Check edittext element panel for numberic value----------------
        function returnNumber(b, name, rangeMin, rangeMax) {
            var bT = new Array();

            if (isNaN(+b)) {
                alert("Invalid value -" + name);
                bT[0] = false;
            } else {
                bT[1] = parseFloat(b, 10);
                if (bT[1] >= rangeMin && bT[1] <= rangeMax)
                    bT[0] = true;
                else {
                    bT[0] = false;
                    alert("Out of Range - " + name + ". Value must be in range " + rangeMin + " - " + rangeMax);
                }
            }
            return bT;
        };
        //------------------------------------------------------------
            function changeResolution(curItem,w,h) {
                var parFolder = "";
                var countFolder = 0;
                var checkFolder = false;
                var curFolder;
                    if(curItem instanceof FolderItem)
                    {
                        for(var k=1;k<=curItem.numItems;k++)
                        {
                            changeResolution(curItem.item(k),w,h);
                        }
                     }
                    if(curItem instanceof CompItem)
                    {
                        curFolder = curItem.parentFolder;
                        while(countFolder<5)
                        {
                        try{
                            if(curFolder.name == "// Assets"  || curFolder.name == "Assets" || curFolder.name == "Holders"){checkFolder = true;break; }
                            curFolder = curFolder.parentFolder;
                           // parFolder = curItem.parentFolder.name;
                          }
                        catch(err){checkFolder = false;}
                        countFolder++;
                        }
                        if(checkFolder==false)
                        {
                          curItem.width = w;
                          curItem.height = h;
                        }
                        parFolder="";
                     }
            }
          
                  return myPanel;
    }
 var myScriptPal = myScript_buildUI(thisObj);
    if (myScriptPal != null && myScriptPal instanceof Window) {
        myScriptPal.center();
        myScriptPal.show();
    }
}
myScript(this);
                     
                     