﻿var comActualPage=1;
var comPageSize=10;

function comPokazStrone(comPgNumber) {
         comPagButton=document.getElementById("comPaginator"+comActualPage).className="glwn_komentarze_page";
         comPagButton=document.getElementById("comPaginator"+comPgNumber).className="glwn_komentarze_pageOn";
         comActualPage=comPgNumber;

         comListContainerObj=document.getElementById("comListContainer");

         comRowMin=(comPageSize*comActualPage)-comPageSize;
         comRowMax=(comPageSize*comActualPage);
         var i=1;
         
         for (var j=0;j<comListContainerObj.childNodes.length;j++)
			   {  
			      node=comListContainerObj.childNodes[j];
				    if (node.nodeType == 1) {
  			  	   if (node.tagName.toLowerCase()=="dd") {  			  	      
                   if (i>comRowMin&&i<=comRowMax) {
                     node.style.display="block";
                   } else {
                     node.style.display="none";                   
                   } 
                   i++;
				       }
						
						}
				}		    
				return false;         
}

function comLimitText(limitField) {
    var limitNum=500;
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
    comFitToContent(limitField,500);
}

function comFitToContent(text, maxHeight)
{
   var adjustedHeight = text.clientHeight;
   if ( !maxHeight || maxHeight > adjustedHeight )
   {
      adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
      if ( maxHeight )
         adjustedHeight = Math.min(maxHeight, adjustedHeight);
      if ( adjustedHeight > text.clientHeight )
         text.style.height = adjustedHeight + "px";
   }
}


function comDelete(comid) {
  lightboxObj=new lightbox("/async/list_com_delete.asp?comid=" + comid );
}


function comDeleteClick(comid,reasonid) {
    var params = "comid=" + comid + "&reason=" + reasonid;
  	var ajax_req = new Ajax.Request(
  		"/async/list_com_delete_post.asp",
  		{
  			method: 'post',
  			postBody: params,
  			onSuccess: function(t) { comDeleted(t.responseText); },
  			onFailure: function(t) { alert("Błąd połączenia: Nie można skasować komentarza." + t.responseText); }
  		}
  	);   
   lightboxObj.deactivate();
   return false;
}


function comDeleted(comid) {
         comListDeleteObj=document.getElementById("listCom"+comid);
         comListDeleteObj.parentNode.removeChild(comListDeleteObj);
         comPokazStrone(comActualPage);
}
