 var iItemToSelect;
    var iSelectedCount=0;
    function NextPage()
    {
        if (nCurrentPage>=nTotalPages)
            return;
        Page(nCurrentPage+1);    
    }
    function PrevPage()
    {
        if (nCurrentPage<=1)
            return;
        Page(nCurrentPage-1);    
    }
    function GetPageData(ev, ct, s, o, pg, cht)
    {
       return new AJAXRequest("post", BASE_URL, '&e=' + ev + '&c=' + ct + '&s=' + s + '&o=' + o + '&page=' + pg + '&ct=' + cht, processImagesGetPageData);
    }
    function UpdateIStatus(st, iid, val)
    {
       return new AJAXRequest("post", BASE_URL, '&status=' + st + '&iid=' + iid + '&val=' + val, processImageStatusUpdate); 
    }
    function UpdateIAllStatus(st, ev, val)
    {
       return new AJAXRequest("post", BASE_URL, '&allstatus=' + st + '&iid=' + ev + '&val=' + val, processImageStatusAllUpdate); 
    }
    function UpdatePassword(ev, pass)
    {
       if (document.forms(0).txtPassword.value=='' || document.forms(0).txtPassword.value==' ')
       {
            alert('נא להזין סיסמה בת 3 תוים לפחות');
            document.forms(0).txtPassword.focus();
            return;
       }
       return new AJAXRequest("post", BASE_URL, '&iid=' + ev + '&password=' + pass, processPasswordUpdate); 
    }
    function RemoveStatusForAll(iType, iId)
    {
        document.location.href='_s_galleries.aspx?remstatus=' + iType + '&iid=' + iId + '&key=' + event_key;
    } 
    function SelectAll(bVal)
    {
            for (i=0;i<nTotalItems;i++)
            {
                aCheckBoxes1[i]=bVal;
                try { document.getElementById('chk_' + i).checked=bVal; } catch(e) {}
            }
            if (bVal) {iSelectedCount=nTotalItems;} else {iSelectedCount=0;}
            if (document.getElementById('chkMain')) 
                document.getElementById('chkMain').checked=bVal;
            UpdateSelLabel();
    } 
    function SelectAll2(bVal)
    {
            for (i=0;i<nTotalItems;i++)
            {
                aCheckBoxes2[i]=bVal;
                try { document.getElementById('chk2_' + i).checked=bVal; } catch(e) {}
            }
            if (bVal) {iSelectedCount=nTotalItems;} else {iSelectedCount=0;}
            UpdateSelLabel();
    } 
    function PrevImage()
    {        
        if (nCurrentImage<=0)
            return;
        UnSelectThumb(nCurrentImage);
        if (((nCurrentImage) % iImagesInPage)==0) { PrevPage(); iItemToSelect=nCurrentImage-1; }           
        nCurrentImage--; 
        ShowImage(nCurrentImage);
    }
    function NextImage()
    {
        if (nCurrentImage>=nTotalItems-1)
            return;
        UnSelectThumb(nCurrentImage);
        if (((nCurrentImage+1) % iImagesInPage)==0) { NextPage(); iItemToSelect=nCurrentImage+1; }    
        nCurrentImage++;    
        ShowImage(nCurrentImage);
    }
    function ResizeImage(nId)
    {
       document.getElementById('ctl00_Main_imgMain').height=aHeights[nId]; 
       document.getElementById('ctl00_Main_imgMain').width=aWidths[nId];    
    }
    function ImageOver(ind)    { if ((nCurrentImage%iImagesInPage) != ind) SelectThumb(ind);   }
    function ImageEndOver(ind) { if ((nCurrentImage%iImagesInPage) != ind) UnSelectThumb(ind); }
    function SelectThumb(ind)
    {   
        try { document.getElementById('ti_' + (ind % iImagesInPage)).style.borderColor='#DF317B'; document.getElementById('ti_' + (ind % iImagesInPage)).style.borderStyle='solid';} catch (e) {}
    }
    function UnSelectThumb(ind)
    {   
        try { document.getElementById('ti_' + (ind % iImagesInPage)).style.borderColor='transparent'; document.getElementById('ti_' + (ind % iImagesInPage)).style.borderStyle='none';} catch(e) {}
    }
    function UpdateSelLabel()
    {
        var ob=document.getElementById('ctl00_Main_lblSelectedCount');
        if (!ob) return;
        if (iSelectedCount==0)
        {
            ob.innerText='נבחרו 0 תמונות';
            return;
        }
        if (iSelectedCount==1)
            ob.innerText='נבחרה תמונה 1';
        if (iSelectedCount>1)
            ob.innerText='נבחרו'+' '+iSelectedCount+' '+'תמונות';            
    }
    function CheckSelectedCheckBoxes()
    {
            for (i=0;i<nTotalItems;i++)
            {
                if (aCheckBoxes1[i])
                    try { document.getElementById('chk_' + i).checked=true; } catch(e) {}
            }
            for (i=0;i<nTotalItems;i++)
            {
                if (aCheckBoxes2[i])
                    try { document.getElementById('chk2_' + i).checked=true; } catch(e) {}
            }
    }
    function MainCheckBoxClicked(oObj)
    {
        document.getElementById('chk_' + nCurrentImage).checked=oObj.checked;
        CheckBoxClicked(1, nCurrentImage, oObj);
    }
    function CheckBoxClicked(nNum, nImageIndex, oObj)
    {
        if (nImageIndex==nCurrentImage && nNum==1)
            if (document.getElementById('chkMain')) 
                document.getElementById('chkMain').checked=oObj.checked;
        if (nNum==1)
            aCheckBoxes1[nImageIndex]=oObj.checked;
        if (nNum==2)
            aCheckBoxes2[nImageIndex]=oObj.checked;    
        if (oObj.checked) 
            iSelectedCount++; 
        else 
            iSelectedCount--;
        UpdateSelLabel();
        try {ActionFunction(nNum, aIds[nImageIndex], oObj);} catch(e) {}
    }
    function send2croper(picpath)
    {   
        if (!document.getElementById('ctl00_Main_imgMain')) return;
        var picpath = document.getElementById('ctl00_Main_imgMain').src;
    	var nWidth = 600;
		var nHeight = 600;    
		var width = 'width=' + nWidth + ',';
		var height = 'height='+ nHeight + ',';
		tp = 'top='  + ( (screen.height / 2) - (nHeight/2) - 60 ) + ',';
		lt = 'left=' + ( (screen.width  / 2) - (nWidth/2) )  + ',';
		params = width + height + tp + lt + 'toolbar=no, scrollbars=no, status=no, resizable=yes';
        window.open("http://www.moblin.com/imgcropper2/cropview.aspx?partnerid=1773&imagepath=" + escape(picpath), "Croper",params) 
    }


