// Max thumb sizes
var MAXTW=75;
var MAXTH=75;

// Default thumb size
var DTW=100;
var DTH=85;

// Pages to display
var PAGES = 10;

// How many images pages to preload
var PRELOAD_IMAGE_PAGES = 0;

// How many show pages to preload
var PRELOAD_SHOW_PAGES = 0;

// How many video pages to preload
var PRELOAD_VIDEO_PAGES = 0;

// How many comments pages to preload
var PRELOAD_COMMENTS_PAGES = 0;

// How many images pages to preload (homepage)
var PRELOAD_HOME_IMAGE_PAGES = 0;

// How many show pages to preload (homepage)
var PRELOAD_HOME_SHOW_PAGES = 0;

// How many video pages to preload (homepage)
var PRELOAD_HOME_VIDEO_PAGES = 0;

// How many comments pages to preload (homepage)
var PRELOAD_HOME_COMMENTS_PAGES = 0;



var ITEM_ID = 'div';

// image loader counter
var img_counter     = 0;
var img_loader      = null;
// slideshow loader counter
var show_counter    = 0;
var show_loader     = null;
// video loader counter
var video_counter    = 0;
var video_loader     = null;

// comments loader counter
var comments_counter    = 0;
var comments_loader     = null;

// tags loader counter
var tags_counter    = 0;
var tags_loader     = null;
// content loader counter
var content_counter = 0;
var content_loader  = null;

var saved_tag_id    = null;

var TAGS            = null;
var IMAGES          = null;
var SHOWS           = null;
var VIDEOS          = null;
var COMMENTS        = null;


var PCOUNTERS       = new Array();

var cur_year = 0;
var cur_month = 0;
var cur_day = 0;

var is_filter_by_date = false;


function filter_by_tag(id, name)
{
  cur_year = 0;
  cur_month = 0;
  cur_day = 0;
  csel(-1);
  is_filter_by_date = false;
  toggle_tag(id);

  get('tagid').value = id;
  get('tagname').value = name;

  show_tag(name);

  get('iloader').innerHTML = '';

  if (is_full_content('i', 1) && get('ifiltered').value == 'false')
  {
    initialize_pages('i', IMAGES);
    images_go_page(1);
  }
  else
  {

      get('inavinfo').style.display = 'none';
      get('inavbar').style.display = 'none';
      get('ihascontent').style.display = 'none';
      get('inocontent').style.display = 'none';

      set_loading('imageinfo_content_loading');
      var o = get('imageinfo_content_loading');
      if (o)
        o.style.display = '';

      var callback_url = '/homepage/images.php';
      img_counter++;
      abort_connection(img_loader);
      get('ifiltered').value = 'true';
      callback_url += '?ipage=1&id=' + get('id').value + '&tagid=' + id + '&rand=' + Math.random();

      callback =
      {
          success:  fetch_images_callback,
          failure:  fetch_images_callback,
          argument: [img_counter, 1]
      };

      img_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
  }

  get('sloader').innerHTML = '';

  if (is_full_content('s', 1) && get('sfiltered').value == 'false')
  {
    initialize_pages('s', SHOWS);
    slideshows_go_page(1);
  }
  else
  {

      get('snavinfo').style.display = 'none';
      get('snavbar').style.display = 'none';
      get('shascontent').style.display = 'none';
      get('snocontent').style.display = 'none';
      set_loading('slideshowinfo_content_loading');
      var o = get('slideshowinfo_content_loading');
      if (o)
        o.style.display = '';

      var callback_url = '/homepage/slideshows.php';
      show_counter++;
      abort_connection(show_loader);
      get('sfiltered').value = 'true';
      callback_url += '?spage=1&id=' + get('id').value + '&tagid=' + id + '&rand=' + Math.random();

      callback =
      {
          success:  fetch_shows_callback,
          failure:  fetch_shows_callback,
          argument: [show_counter, 1]
      };

      show_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
  }

  var o = get('vloader');
  if (o)
    o.innerHTML = '';

  if (get('videoinfo_content'))
  {
      if (is_full_content('v', 1) && get('vfiltered').value == 'false')
      {
        initialize_pages('v', VIDEOS);
        videos_go_page(1);
      }
      else
      {

          get('vnavinfo').style.display = 'none';
          get('vnavbar').style.display = 'none';
          get('vhascontent').style.display = 'none';
          get('vnocontent').style.display = 'none';
          set_loading('videoinfo_content_loading');
          var o = get('videoinfo_content_loading');
          if (o)
            o.style.display = '';

          var callback_url = '/homepage/videos.php';
          video_counter++;
          abort_connection(video_loader);
          get('vfiltered').value = 'true';
          callback_url += '?vpage=1&id=' + get('id').value + '&tagid=' + id + '&rand1=' + Math.random();

          callback =
          {
              success:  fetch_videos_callback,
              failure:  fetch_videos_callback,
              argument: [video_counter, 1]
          };

          video_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
      }
  }
}

function show_notable_callback(rsp)
{
    get('related_content_loading').style.display = 'none';
    var o = get('related_content');
    if (!o)
        return;
    o.style.display = '';

    o = get('related_content_data');
    if (!o)
        return;
    o.innerHTML = rsp.responseText;
    var profiles = o.getElementsByTagName('div');
    if (!profiles || profiles.length == 0)
        return;
    var html = '';
    for (var i = 0; i < profiles.length; i++)
    {        
        if (profiles[i].className != 'profile')
            continue;
        var username = get_attr(profiles[i], 'profilename');
        var userpic  = get_attr(profiles[i], 'profilepicture');
        var tt = "<table style=\"border-left:2px solid gray;border-top:2px solid gray;border-right:4px solid gray;border-bottom:4px solid gray;\"><tr>";
        tt += "<td width=\"150\" height=\"150\" align=\"center\" valign=\"middle\" style=\"margin: 0px;\">";
        tt += "<img src=\"" + userpic + "\" width=\"1\" height=\"1\" onload=\"pok(this)\" onerror=\"perror(this)\"/></td></tr></table>";
        html += '<a target="_new" class="ser" onmouseover="fixedtooltip(\'' + quote_html(tt) + '\', this, event, \'155px\')" onmouseout="delayhidetip()" href="http://profile.imageshack.us/user/' +  username + '">' + username +  '</a><br/>';
    }
    o = get('related_content');
    o.innerHTML = html;
}

function show_notable_failure(rsp)
{
    get('related_content_loading').style.display = 'none';
}

function display_tags_sorting_options(order)
{
    obj = get('tags.sort.usage.on');
    if (obj)
        obj.style.display = order == 'c' ? 'inline' : 'none';
    obj = get('tags.sort.usage.off');
    if (obj)
        obj.style.display = order != 'c' ? 'inline' : 'none';
    obj = get('tags.sort.name.on');
    if (obj)
        obj.style.display = order != 'c' ? 'inline' : 'none';
    obj = get('tags.sort.name.off');
    if (obj)
        obj.style.display = order == 'c' ? 'inline' : 'none';

}


function sort_tags(order)
{
  get('order').value = order;
  if (!is_full_content('t', 0))
  {
      get('tstartpage').value = -1;
      get('tendpage').value = -1;
  }
  else
  {
    if (order == 'c')
        TAGS.sort(count_sort)
    else
        TAGS.sort(name_sort);
  }
  tags_go_page(0);
}

function fetch_tags_callback(rsp)
{
    if (rsp.argument[0] != tags_counter)
        return;

    get('taginfo_content_loading').style.display = 'none';

    obj = get("tcontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_tags(rsp.argument[2]);
        display_tag(rsp.argument[1], rsp.argument[2], rsp.argument[3]);
    }
}

function fetch_images_callback(rsp)
{
    if (rsp.argument[0] != img_counter)
    {
        return;
    }

    get('imageinfo_content_loading').style.display = 'none';

    obj = get("icontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_images('i');
        images_go_page(rsp.argument[1]);
    }
}

function fetch_shows_callback(rsp)
{
    if (rsp.argument[0] != show_counter)
    {
        return;
    }

    get('slideshowinfo_content_loading').style.display = 'none';

    obj = get("scontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_shows('s');
        slideshows_go_page(rsp.argument[1]);
    }
}

function fetch_videos_callback(rsp)
{
    if (rsp.argument[0] != video_counter)
    {
        return;
    }

    get('videoinfo_content_loading').style.display = 'none';

    obj = get("vcontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_videos('v');
        videos_go_page(rsp.argument[1]);
    }
}


function fetch_comments_callback(rsp)
{
    if (rsp.argument[0] != comments_counter)
    {
        return;
    }

    get('commentsinfo_content_loading').style.display = 'none';

    obj = get("mcontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_comments('m');
        comments_go_page(rsp.argument[1]);
    }
}



function filter_callback(rsp)
{
    if (rsp.argument[0] != content_counter)
        return;

    get('imageinfo_content_loading').style.display = 'none';
    get('slideshowinfo_content_loading').style.display = 'none';
    var o = get('videoinfo_content_loading');
    if (o)
        o.style.display = 'none';

    o = get("content");
    if (o)
    {
        o.innerHTML = rsp.responseText;
        images_go_page(1);
        slideshows_go_page(1);
        videos_go_page(1);
    }
}

function clear_filter()
{
  cur_year = 0;
  cur_month = 0;
  cur_day = 0;
  csel(-1);
  get('tagid').value = '-1';
  get('tagname').value = '';

  is_filter_by_date = false;

  hide_tag();

  toggle_tag(null);

  get('iloader').innerHTML = '';

  if (is_full_content('i', 1) && get('ifiltered').value == 'false')
  {
    initialize_pages('i', IMAGES);
    images_go_page(1);
  }
  else
  {

      get('inavinfo').style.display = 'none';
      get('inavbar').style.display = 'none';
      get('ihascontent').style.display = 'none';
      get('inocontent').style.display = 'none';

      set_loading('imageinfo_content_loading');
      var o = get('imageinfo_content_loading');
      if (o)
        o.style.display = '';

      var callback_url = '/homepage/images.php';
      img_counter++;
      abort_connection(img_loader);
      get('ifiltered').value = 'true';
      callback_url += '?ipage=1&id=' + get('id').value + '&tagid=-1&rand=' + Math.random();

      callback =
      {
          success:  fetch_images_callback,
          failure:  fetch_images_callback,
          argument: [img_counter, 1]
      };

      img_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
  }

  get('sloader').innerHTML = '';

  if (is_full_content('s', 1) && get('sfiltered').value == 'false')
  {
    initialize_pages('s', SHOWS);
    slideshows_go_page(1);
  }
  else
  {

      get('snavinfo').style.display = 'none';
      get('snavbar').style.display = 'none';
      get('shascontent').style.display = 'none';
      get('snocontent').style.display = 'none';
      set_loading('slideshowinfo_content_loading');
      var o = get('slideshowinfo_content_loading');
      if (o)
        o.style.display = '';

      var callback_url = '/homepage/slideshows.php';
      show_counter++;
      abort_connection(show_loader);
      get('sfiltered').value = 'true';
      callback_url += '?spage=1&id=' + get('id').value + '&tagid=-1&rand=' + Math.random();

      callback =
      {
          success:  fetch_shows_callback,
          failure:  fetch_shows_callback,
          argument: [show_counter, 1]
      };

      show_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
  }

  var o = get('vloader');
  if (o)
    o.innerHTML = '';


  if (get('videoinfo_content'))
  {
      if (is_full_content('v', 1) && get('vfiltered').value == 'false')
      {
        initialize_pages('v', VIDEOS);
        videos_go_page(1);
      }
      else
      {

          get('vnavinfo').style.display = 'none';
          get('vnavbar').style.display = 'none';
          get('vhascontent').style.display = 'none';
          get('vnocontent').style.display = 'none';
          set_loading('videoinfo_content_loading');
          var o = get('videoinfo_content_loading');
          if (o)
            o.style.display = '';

          var callback_url = '/homepage/videos.php';
          video_counter++;
          abort_connection(video_loader);
          get('vfiltered').value = 'true';
          callback_url += '?vpage=1&id=' + get('id').value + '&tagid=-1&rand=' + Math.random();

          callback =
          {
              success:  fetch_videos_callback,
              failure:  fetch_videos_callback,
              argument: [video_counter, 1]
          };

          video_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
      }
  }

}

function preload_images(page, prefix, pages, objects)
{
    var all_items = is_filter_by_date ? filter_by_date(objects) : filter_items(objects, get('tagid').value);

    var rows  = parseInt(get(prefix + 'rows').value);
    var cols  = parseInt(get(prefix + 'cols').value);

    var start = getstartpage(prefix);
    var end   = getendpage(prefix);
    start = (page - start + 1) * cols * rows;
    end   = Math.min(start + pages * rows * cols, all_items.length);
    for (var i = start; i < end; i++)
    {
        var img = new Image;
        img.src = all_items[i][0];
    }
}


function c_ok(src, id, prefix, url, is_new)
{
    var o = document.getElementById(prefix + 'h_' + id);
    if (!o)
        return;


    if(prefix == 'm')
    {

         var html ='';
         var html_image ='';
         var tmp = new Image;
         tmp.src = src.src;
         var scaled = get_scaled_size(tmp.width, tmp.height, MAXTW, MAXTH);
         var rect = get_rect(scaled, MAXTW, MAXTH);


         if(COMMENTS[id][8]!='')
             html_image += '<a target="_new" href="'+  COMMENTS[id][8]  +'">';

         html_image += '<img style="margin: 0px 0px 0px 0px;  clip: ' + css_rect(rect) + '" src="' + src.src + '" width="' + scaled[0] + '" height="' + scaled[1] + '" title="' + src.title + '" alt="' + src.alt + '" border="0" />';

         if(COMMENTS[id][8]!='')    
             html_image += '</a>';

         html +=   '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
         html +=   '<tr>';
         html +=   '    <td><img src="' + iurl('1pix.gif') + '" width="14" height="1" alt=""></td>';
         html +=   '    <td valign="top" align="center">' + html_image + '<br/><img src="' + iurl('1pix.gif') + '" width="85" height="1" alt=""></td>';
         html +=   '    <td width="25" align="right" valign="top" style="padding-top:20px"><img src="' + iurl('comments_arrow.gif') + '" width="8" height="15"></td>';
         html +=   '    <td bgcolor="#EAEAEA" style="padding:10px" width="100%">';
         html +=   '         <table width="100%" cellpadding="0" cellspacing="0" border="0">';
         html +=   '            <tr>';
         html +=   '                <td width="74%"><strong>' +  COMMENTS[id][7]  + ' say</strong></td>';
         html +=   '                <td width="25%" nowrap class="nmr">' + COMMENTS[id][3] +'</td>';
         html +=   '            </tr>';
         html +=   '            <tr><td  colspan="2" height="32" background="' + iurl('wspacer.gif') + '"></td></tr>';
         html +=   '         </table>';
         html +=   COMMENTS[id][6];
         html +=   '    </td> ';
         html +=   '</tr>';


         if(COMMENTS[id][7]!='')    
         {
              var who = get_comments_master(COMMENTS[id][7]);

              if(who)
                 html += '<tr><td colspan="4" align="right"><a class="ser" alt="delete comment" title="delete comment" href="javascript:delete_comment('+ COMMENTS[id][10] +',\''+ who +'\')">[x]</a></td></tr>';
         }


         html +=   '</table>';
         html +=   '<p>&nbsp;</p>';


         o.style.left = '' + (5 - rect[4]) + 'px';
         o.style.top = '4px';
         o.innerHTML  = html;
    }
    else
    {
         var html = '<a href="' + url + '"';
         if (is_new)
         html += ' target="_new"';
         html += '>';
         var tmp = new Image;
         tmp.src = src.src;
         var scaled = get_scaled_size(tmp.width, tmp.height, MAXTW, MAXTH, true);
         var rect = get_rect(scaled, MAXTW, MAXTH);
         html += '<img style="margin: 0px 0px 0px 0px; position: absolute; clip: ' + css_rect(rect) + '" src="' + src.src + '" width="' + scaled[0] + '" height="' + scaled[1] + '" title="' + src.title + '" alt="' + src.alt + '"/>';
         html += '</a>';
         o.style.left = '' + (5 - rect[4]) + 'px';
         o.style.top = '4px';
         o.innerHTML  = html;
         o.parentNode.style.backgroundImage = 'url(' + ICO_BG + ')';
     }
}

function c_error(src, id, prefix, url, is_new, defaultpic)
{
    var o = document.getElementById(prefix + 'h_' + id);
    if (!o)
        return;

    if (!defaultpic)
        defaultpic = noimage_url();
    if(prefix == 'm')
    {

         var html ='';
         var html_image ='';
         
         html_image += '<a target="_new" href="'+  COMMENTS[id][8]  +'">';
         html_image += '<img src="' + iurl('comments_user.jpg') + '"   border="0" />';
         html_image += '</a>';

         html +=   '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
         html +=   '<tr>';
         html +=   '    <td width="34"><img src="images/spacer.gif" width="34" height="1" alt=""></td>';
         html +=   '    <td valign="top">' + html_image + '</td>';
         html +=   '    <td width="25" align="right" valign="top" style="padding-top:20px"><img src="' + iurl('comments_arrow.gif') + '" width="8" height="15"></td>';
         html +=   '    <td bgcolor="#EAEAEA" style="padding:10px">';
         html +=   '         <table width="100%" cellpadding="0" cellspacing="0" border="0">';
         html +=   '            <tr>';
         html +=   '                <td width="74%"><strong>' +  COMMENTS[id][7]  + ' say</strong></td>';
         html +=   '                <td width="25%" nowrap class="nmr">' + COMMENTS[id][3] +'</td>';
         html +=   '            </tr>';
         html +=   '            <tr><td  colspan="2" height="32" background="' + iurl('wspacer.gif') + '"></td></tr>';
         html +=   '         </table>';
         html +=   COMMENTS[id][6];
         html +=   '    </td> ';
         html +=   '</tr>';


         if(COMMENTS[id][7]!='')    
         {
              var who = get_comments_master(COMMENTS[id][7]);

              if(who)
                 html += '<tr><td colspan="4" align="right"><a class="ser" alt="delete comment" title="delete comment" href="javascript:delete_comment('+ COMMENTS[id][10] +',\''+ who +'\')">[x]</a></td></tr>';
         }



         html +=   '</table>';
         html +=   '<p>&nbsp;</p>';

         o.style.top = '4px';
         o.innerHTML  = html;

    }
    else
    {

        var html = '<a href="' + url + '"';
        if (is_new)
            html += ' target="_new"';
        html += '>';
        html += '<img src="' + defaultpic + '" width="' + MAXTW + '" height="' + MAXTH + '" alt="' + src.alt + '" title="' + src.title + '"/>';
        html += '</a>';
        o.style.left = '5px';
        o.style.top  = '4px';
        o.innerHTML  = html;
        o.parentNode.style.backgroundImage = 'url(' + ICO_BG + ')';
   }

}

function c_abort(src, id, prefix, url, is_new)
{
    var f_param = 'this, ' + id + ', \'' + prefix + '\', \'' + url + '\', ' + is_new;
    if (!window.opera)
    {
        var o = get(prefix + 'loader');
        if (o.innerHTML.length == 0)
            return;
        var html = '<img id="' + src.id + '" onload="c_ok(' + f_param + ')" onabort="c_abort(' + f_param + ')" onerror="c_error(' + f_param + ')" width="1" height="1" src="' +  src.src + '"/>'; 
        o.innerHTML += html;
    }
    else
    {
        var tmp = new Image;
        tmp.id = src.id;
        tmp.width    = 1;
        tmp.height   = 1;
        tmp.onload   = 'c_ok(' + f_param + ')';
        tmp.onerror  = 'c_error(' + f_param + ')';
        tmp.onaboirt = 'c_abort(' + f_param + ')';
        tmp.src    = src.src;
    }
}

function mprofiles_go_page(page)
{
    var f = get('navform');
    f.ipage.value = page;
    f.submit();
}


function images_go_page(page)
{
  var o = get('iloader');
  if (o)
    o.innerHTML = '';

  o = get('inumitems');
  if (!has_page(page, 'i') && o && o.value != '0')
  {
      get('inavinfo').style.display = 'none';
      get('inavbar').style.display = 'none';
      get('ihascontent').style.display = 'none';
      get('inocontent').style.display = 'none';

      set_loading('imageinfo_content_loading');
      get('imageinfo_content_loading').style.display = '';
      
      callback_url = '/homepage/images.php?ipage=' + page + '&id=' + get('id').value + '&tagid=' + get('tagid').value + '&rand=' + Math.random() + date_restrictions();

      img_counter++;
      abort_connection(img_loader);

      get('ifiltered').value = 'true';

      var callback =
      {
          success:  fetch_images_callback,
          failure:  fetch_images_callback,
          argument: [img_counter, page]
      };
      img_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
    }
    else
    {        
        display(page, 'i', 'Images', 'images_go_page', IMAGES, PRELOAD_HOME_IMAGE_PAGES, true);
        show_more_tagged();
    }
}

function slideshows_go_page(page)
{
  var o = get('sloader');
  if (o)
    o.innerHTML = '';

  o = get('snumitems');
  if (!has_page(page, 's') && o && o.value != '0')
  {
      get('snavinfo').style.display = 'none';
      get('snavbar').style.display = 'none';
      get('shascontent').style.display = 'none';
      get('snocontent').style.display = 'none';

      set_loading('slideshowinfo_content_loading');
      get('slideshowinfo_content_loading').style.display = '';
      
      callback_url = '/homepage/slideshows.php?spage=' + page + '&id=' + get('id').value + '&tagid=' + get('tagid').value + '&rand=' + Math.random();

      show_counter++;
      abort_connection(show_loader);

      var callback =
      {
          success:  fetch_shows_callback,
          failure:  fetch_shows_callback,
          argument: [show_counter, page]
      };
      show_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
    }
    else
    {
        display(page, 's', 'Slideshows', 'slideshows_go_page', SHOWS, PRELOAD_HOME_SHOW_PAGES, true);
    }
}

function videos_go_page(page)
{
  if (!get('videoinfo_content'))
     return;

  var o = get('vloader');
  if (o)
    o.innerHTML = '';

  o = get('vnumitems');
  if (!has_page(page, 'v') && o && o.value != '0')
  {
      get('vnavinfo').style.display = 'none';
      get('vnavbar').style.display = 'none';
      get('vhascontent').style.display = 'none';
      get('vnocontent').style.display = 'none';

      set_loading('videoinfo_content_loading');
      get('videoinfo_content_loading').style.display = '';
      
      callback_url = '/homepage/videos.php?vpage=' + page + '&id=' + get('id').value + '&tagid=' + get('tagid').value + '&rand=' + Math.random();

      video_counter++;
      abort_connection(video_loader);

      var callback =
      {
          success:  fetch_videos_callback,
          failure:  fetch_videos_callback,
          argument: [video_counter, page]
      };
      video_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
    }
    else
    {
        display(page, 'v', 'Videos', 'videos_go_page', VIDEOS, PRELOAD_HOME_VIDEO_PAGES, true);
    }
}


function comments_go_page(page,force)
{
  if (!get('commentsinfo_content'))
     return;

  var o = get('mloader');
  if (o)
    o.innerHTML = '';

  o = get('mnumitems');
  if ((!has_page(page, 'm') && o && o.value != '0') || force)
  {
//      get('mnavinfo').style.display = 'none';
//      get('mnavbar').style.display = 'none';
//      get('mhascontent').style.display = 'none';
      get('mnocontent').style.display = 'none';

      set_loading('commentsinfo_content_loading');
      get('commentsinfo_content_loading').style.display = '';
      
      callback_url = '/homepage/comments.php?mpage=' + page + '&id=' + get('id').value + '&user='+ get('user').value +'&rand=' + Math.random();

      comments_counter++;
      abort_connection(comments_loader);

      var callback =
      {
          success:  fetch_comments_callback,
          failure:  fetch_comments_callback,
          argument: [comments_counter, page]
      };
      comments_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
   }
   else
   {
        display(page, 'm', 'Comments', 'comments_go_page', COMMENTS, PRELOAD_HOME_COMMENTS_PAGES, false);
   }
}




function tags_go_page(page)
{
  var order = get('order').value;
  var o = get('tnumitems');

  if (!has_page(page, 't') && o && o.value != '0')
  {
      get('tnavbar').style.display = 'none';
      get('thascontent').style.display = 'none';
      get('tnocontent').style.display = 'none';
      get('tsort').style.display = 'none';

      set_loading('taginfo_content_loading');
      get('taginfo_content_loading').style.display = '';

      callback_url = '/homepage/tags.php?o=' + order + '&p=' + page + '&id=' + get('id').value + '&rand=' + Math.random();

      tags_counter++;
      abort_connection(tags_loader);

      var callback =
      {
          success:  fetch_tags_callback,
          failure:  fetch_tags_callback,
          argument: [tags_counter, page, order, '']
      };
      tags_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
    }
    else
    {
        display_tag(page, order, '');
    }
}

function show_tag(name)
{
    st(name, 'i');st(name, 's');st(name, 'v');st(name, '');
}

function hide_tag()
{
    ht('i');ht('s');ht('v');ht('');
}

function st(name, suffix)
{
    var o = get('ttp' + suffix);
    if (!o)
        return;
    get('ttp' + suffix).style.display = '';
    get('tts' + suffix).style.display = '';
    get('ttn' + suffix).style.display = '';
    get('ttn' + suffix).innerHTML = '<b>' + quote_html(name) + '</b>';
    get('ttr' + suffix).style.display = '';
    get('ttcd' + suffix).style.display = 'none';
    get('ttsd' + suffix).style.display = 'none';
}

function ht(suffix)
{
    var o = get('ttp' + suffix);
    if (!o)
        return;
    get('ttp' + suffix).style.display = 'none';
    get('tts' + suffix).style.display = 'none';
    get('ttn' + suffix).style.display = 'none';
    get('ttr' + suffix).style.display = 'none';
    get('ttcd' + suffix).style.display = 'none';
    get('ttsd' + suffix).style.display = 'none';
}

function hide_it(id)
{
    get(id + '_content').style.display = 'none';
    get(id + '_off').style.display = '';
    get(id + '_on').style.display = 'none';
}

function show_it(id)
{
    get(id + '_content').style.display = '';
    get(id + '_off').style.display = 'none';
    get(id + '_on').style.display = '';
}

function fok(src, offset)
{
    var id = src.id;
    var o = get('c' + id.substring(1));
    var html='';
    var tmp = new Image;
    tmp.src = src.src;
    var scaled = get_scaled_size(tmp.width, tmp.height, 75, 75, false);

    var u = get('u' + id.substring(1));
    if (u)
        html += '<a href="' + u.value + '" target="_new">';
    html += '<img src="' + src.src + '" width="' + scaled[0] + '" height="' + scaled[1] + '" title="' + src.title + '" alt="' + src.alt + '"/>';
    if (u)
        html += '</a>';
    o.style.display = 'block';
    o.style.left = Math.floor(5 + offset + (75 - scaled[0]) / 2) + 'px';
    o.style.top  = Math.floor(4 + offset + (75 - scaled[1]) / 2) + 'px';
    o.innerHTML  = html;
    o.parentNode.style.backgroundImage = 'url(' + ICO_BG + ')';
    o.innerHTML  = html;
}

function ferror(src, offset)
{
    var id = src.id;
    var o = get('c' + id.substring(1));
    var u = get('u' + id.substring(1));
    var html = '';
    if (u)
        html += '<a href="' + u.value + '" target="_new">';
    html += '<img src="' + ICO_NO_PHOTO + '" width="67" height="75" alt="' + src.alt + '" title="' + src.title + '"/>';
    if (u)
        html += '</a>';
    o.innerHTML  = html;
    o.style.left = (5 + offset + (75 - 67) / 2) + 'px';
    o.style.top  = (4 + offset) + 'px';
    o.parentNode.style.backgroundImage = 'url(' + ICO_BG + ')';
    o.style.display = 'block';
}

function add_to_friends(username)
{
  callback_url = '/friends/addfriend.php?user=' + username + '&rand=' + Math.random();
  get('add_friend').style.display = 'none';
  get('friend').style.display = '';
  callback =
  {
      argument: null
  };
  YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);

}

function add_to_friends_ex(id, username)
{
  callback_url = '/friends/addfriend.php?user=' + username + '&rand=' + Math.random();
  get('add_friend' + id).style.display = 'none';
  get('friend' + id).style.display = '';
  callback =
  {
      argument: null
  };
  YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);

}

function add_to_friends_ex2(username)
{
  callback_url = '/friends/addfriend.php?user=' + username + '&rand=' + Math.random();
  get('add_friend' + username).style.display = 'none';
  get('friend' + username).style.display = '';
  callback =
  {
      argument: null
  };
  YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);

}

function pok(src)
{
    var tmp = new Image;
    tmp.src = src.src;
    var scaled = get_scaled_size(tmp.width, tmp.height, 150, 150, false);
    src.width = scaled[0];
    src.height = scaled[1];
}

function perror(src)
{
    src.src    = ICO_NO_PHOTO;
}

function abort_connection(o)
{
/*    if (o != null)
    {
        YAHOO.util.Connect.abort(o);
        o = null;
    }*/
}

function toggle_tag(id)
{
    if (saved_tag_id)
    {
        var o = get('tl' + saved_tag_id);
        if (o && o.innerHTML)
        {
            var html = o.innerHTML.substr(3);
            html = html.substr(0, html.length - 4);
            o.innerHTML = html;
        }
    }
    saved_tag_id = id;
    if (saved_tag_id)
    {
        var o = get('tl' + saved_tag_id);
        if (o && o.innerHTML)
            o.innerHTML = '<b>' + o.innerHTML + '</b>';
    }
}


function display(page, prefix, label, navscript, objects, numfetchpages, link_to_details)
{

    var all_items;

    // comments not filtered

    if(prefix == 'm') all_items = objects;
    else              all_items = is_filter_by_date ? filter_by_date(objects) : filter_items(objects, get('tagid').value);

    var items = extract_items(all_items, page, prefix);

    var cols = get(prefix + 'cols').value;
    var rows = get(prefix + 'rows').value;

    var counter = items.length;


    for (var i = 0; i < rows; i++)
    {

        var o = get(prefix + 'r_' + i);
        if(o)o.style.display = "";


        for (var j = 0; j < cols; j++)
        {
            var o = get(prefix + 'h_' + (i * cols + j));
            if(o)
            {
                o.innerHTML = '';
                o.parentNode.style.backgroundImage = 'none';
            }
        }
    }


    if(prefix == 'm')
    {
        hide_unused_cells(prefix,counter,rows,cols);
    }

    var loader = get(prefix + 'loader');

    if (counter == 0)
    {
        get(prefix + 'navinfo').style.display = 'none';
        get(prefix + 'navbar').style.display = 'none';
        get(prefix + 'nocontent').style.display = '';

    }
    else
    {
        get(prefix + 'hascontent').style.display = '';
        get(prefix + 'nocontent').style.display = 'none';
        var o = get(prefix + 'more');
        if (o)
        {
            o.style.display = '';
            o = get(prefix + 'morelink');
            if (o)
            {
                var href = '/user/' + get('user').value;
                switch (prefix)
                {
                    case 'i':
                        href += '/images';
                        break;
                    case 's':
                        href += '/slideshows';
                        break;
                    case 'v':
                        href += '/videos';
                        break;
                }
                if (get('tagname').value != '')
                    href += '/tag/' + encodeURIComponent(get('tagname').value);
                o.innerHTML = '<a class="ser" href="' + href + '">[more...]</a>';
            }
        }
        istart = (page - 1) * cols * rows + 1;
        iend   = istart + counter - 1;
        var o = get(prefix + 'navinfo');

        var numitems = getnumitems(prefix);
        o.innerHTML = label + ':&nbsp;' + istart + '..' + iend + '/' + numitems + '&nbsp;';
        o.style.display = '';

        var o = get(prefix + 'navbar');

        var numpages = Math.ceil(numitems / (rows * cols));

        o.style.display = (numpages == 1) ? 'none' : '';

        start_page = 0;
        end_page   = 0;
        prev       = false;
        next       = false;



        if (numpages > PAGES)
        {
            if (page <= (PAGES / 2) + 1)
            {
                start_page = 1;
                end_page   = PAGES;
                prev       = page > 1;
                next       = true;
            }
            else
            {   
                start_page = page - (PAGES / 2);
                end_page   = start_page + PAGES - 1;
                prev       = true;
                if (end_page > numpages)
                    end_page = numpages;
                next       = page < end_page;
            }
        }
        else
        {
            start_page = 1;
            end_page   = numpages;
            prev       = page > 1;
            next       = page < end_page;
        }

        var html = make_nav(navscript, page, start_page, end_page, numpages, prefix);
        o.innerHTML = html;

        var html_block = '';

        for (var i = 0; i < counter; i++)
        {
            var i_href = items[i][0];
            var t_href;
            var is_new;
            if (link_to_details)
            {
                if (items[i][1].indexOf('.smil') > 0)
                    t_href = slideshow_details_url(get('user').value, items[i][4], get('tagname').value);
                else
                if (items[i][5].indexOf('.flv') > 0 || items[i][5].indexOf('.mp4') > 0 )
                    t_href = video_details_url(get('user').value, items[i][4], items[i][5], get('tagname').value);
                else
                    t_href = image_details_url(get('user').value, items[i][4], items[i][5], get('tagname').value);
                is_new = false;
            }
            else
            {
                t_href = items[i][1];
                is_new = true;
            }


            if (i_href.length == 0 || is_pdf(i_href))
            {
                var img = new Image;
                img.id = prefix + 'im' + i;
                c_error(img, i, prefix, t_href, is_new, is_pdf(i_href) ? pdflogo() : noimage_url());
            }
            else
            {
                var f_param = 'this, ' + i + ', \'' + prefix + '\', \'' + t_href + '\', ' + is_new;
                if (!window.opera)
                {
                    var html = '<img id="' + prefix + 'im' + i + '" onload="c_ok(' + f_param + ')" onabort="c_abort(' + f_param + ')" onerror="c_error(' + f_param + ')" width="1" height="1" src="' + i_href + '"/>'; 
                    html_block += html;
                }
                else
                {
                    var tmp = new Image;
                    tmp.id = prefix + 'im' + i;
                    tmp.width   = 1;
                    tmp.height  = 1;
                    tmp.onload  = 'c_ok(' + f_param + ')';
                    tmp.onabort = 'c_abort(' + f_param + ')';
                    tmp.onerror = 'c_error(' + f_param + ')';
                    tmp.src    = i_href;
                }
            }
        }
        if (!window.opera)
            loader.innerHTML = html_block;

        preload_images(page, prefix, numfetchpages, objects);
    }

}

function display_tag(page, order, prefix)
{    
    var tags = extract_tags(page);
    var rows = get('trows').value;

    var counter = tags.length;

    if (counter == 0)
    {
        get('tnavbar').style.display = 'none';
        get('thascontent').style.display = 'none';
        get('tnocontent').style.display = '';
        get('tsort').style.display = 'none';
    }
    else
    {
        get('thascontent').style.display = '';
        get('tnocontent').style.display = 'none';
        get('tsort').style.display = '';

        var o = get('tnavbar');
        var numpages = getnumpages('t');
        o.style.display = (numpages == 1) ? 'none' : 'inline';

        prev       = page > 0;
        next       = page < numpages - 1;

        var jsfunc = 'javascript:' + prefix + 'tags_go_page';

        var html = '<table border="0" width="100%">';
        html += '<tr>';
        html += '<td width="10%" nowrap align="left">';
        if (prev)
            html += "<a title=\"Prev\" alt=\"Prev\" href=\"" + jsfunc + "(" + (page - 1) + ")\"><img src=\"" + ICO_PREV + "\"/></a>\n";
        else
            html += '<img src="' + ICO_PREVD + '"/>';
        html += '</td>';
        html += '<td nowrap align="center">';
        istart = page * rows + 1;
        iend   = istart + counter - 1;
        var numitems = getnumitems('t');
        html += 'Tags:&nbsp;' + istart + '..' + iend + '/' + numitems;
        html += '</td>';
        html += '<td width="10%" nowrap align="right">';
        if (next)
            html += "<a title=\"Next\" alt=\"Next\" href=\"" + jsfunc + "(" + (page + 1) + ")\"><img src=\"" + ICO_NEXT + "\"/></a>\n";
        else
            html += '<img src="' + ICO_NEXTD + '"/>';
        html += '</td>';
        html += '</tr>';
        html += '</table>';

        o.innerHTML = html;

        o = get('thascontent');

        html = '';
        for (var i = 0; i < counter; i++)
        {
            html += '<span id="tl' + tags[i][0] + '"><a class="ser" title="' + tags[i][1] + '" href="javascript:void(0)" onclick="javascript:' + prefix + 'filter_by_tag(' + tags[i][0] + ',\'' + jsstring(tags[i][1]) + '\');return false;">';
            var tname = tags[i][1];
            if (tname.length > 18)
                tname = tname.substring(0, 18);
            html += tname + ' (' + tags[i][2] + ')';
            html += '</a></span><br/>';
        }

        o.innerHTML = html;

        tag_id = saved_tag_id;
        saved_tag_id = null;
        toggle_tag(tag_id);

        display_tags_sorting_options(order);
    }
}

function display_notable()
{

    set_loading('related_content_loading');
    get('related_content_loading').style.display = '';
    get('related_content').style.display = 'none';

    callback_url = '/homepage/notable.html?rand=' + Math.random();

    callback =
    {
        success:  show_notable_callback,
        failure:  show_notable_failure,
        argument: []
    };
    YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
}

function valid_page(prefix)
{
    var o = get(prefix + 'pageno');
    if (!o)
        return;
    var page = parseInt(o.value, 10);
    if (page == "Nan") 
        return false;

    if (get('tagid').value == '-1' && !is_filter_by_date)
        return page > 0 && page <= getnumpages(prefix);

    for (var i = 0; i < PCOUNTERS.length; i++)
    {
        if (PCOUNTERS[i][0] == prefix)
        {
            if (page > 0 && page <= PCOUNTERS[i][1])
                return true;
            return false;
        }
    }
    return false;
}

function extract_tags(page)
{
    var rows  = parseInt(get('trows').value);
    var start = getstartpage('t');
    var end   = getendpage('t');
    start = page * rows - start * rows;
    end   = Math.min(start + rows, getnumitems('t'));
    return TAGS.slice(start, end);
}

function count_sort(a, b)
{
    var ret = b[2] - a[2];
    if (ret == 0)
        return name_sort(a, b);
    return ret;
}

function name_sort(a, b)
{
    var x = a[1].toLowerCase();
    var y = b[1].toLowerCase();
    if (x == y)
        return 0;
    return x > y ? 1 : -1;
}

function initialize_tags(order)
{
    get('order').value = order;
    var start = getstartpage('t');
    var end   = getendpage('t');
    var rows  = get('trows').value;

    TAGS = new Array();

    for (i = start; i <= end; i++)
    {
        for (j = 0; j < rows; j++)
        {
            var id = i + '_' + j;
            var o = get('ti' + id);
            if (!o)
                break;
            var tid    = o.value;
            var tname  = get('tn' + id).value;
            var tcount = parseInt(get('tc' + id).value);
            TAGS[TAGS.length] = [tid, tname, tcount];
        }   
    }

    if (order == 'c')
        TAGS.sort(count_sort)
    else
        TAGS.sort(name_sort);
}

function initialize_images(prefix)
{
    IMAGES = new Array();

    var cached = getnumcached(prefix);

    for (var i = 0; i < cached; i++)
    {        
        var o = get('i' + i);
        var ts = get_attr(o, 'is');
        var tb = get_attr(o, 'ib');
        var tf = get_attr(o, 'if');
        var tt = get_attr(o, 'it');
        var td = get_attr(o, 'id');

        var thumbname;
        var iurl;

        if (tt == 'y')
            thumbname = thumb_name(tf);
        else
            thumbname = tf;
        iurl = thumb_url(ts, tb, thumbname);
            
        //apply new format
        //var ihref = 'http://img' + ts + '.imageshack.us/my.php?image=' + tf;
        var ihref = 'http://img' + ts + '.imageshack.us/i/' + tf + '/';

        var tags = get_tags(o);
        var dt = make_date(td);
        IMAGES[IMAGES.length] = [iurl, ihref, tags, dt, ts, tf];
    }

    initialize_pages(prefix, IMAGES);

}

function initialize_shows(prefix)
{
    SHOWS = new Array();

    var cached = getnumcached(prefix);

    for (var i = 0; i < cached; i++)
    {        
        var o = get('s' + i);
        var ts = get_attr(o, 'ts');
        var tb = get_attr(o, 'tb');
        var tf = get_attr(o, 'tf');
        var td = get_attr(o, 'td');
        var ti = get_attr(o, 'si'); 

        var iurl;
        var thumbname = thumb_name(tf);

        if (thumbname.length > 0)  
            iurl = thumb_url(ts, tb, thumbname);
        else
            iurl = '';
        var ihref = player_url(ti);

        var tags = get_tags(o);
        var dt = make_date(td);
        SHOWS[SHOWS.length] = [iurl, ihref, tags, dt, ti];
    }

    initialize_pages(prefix, SHOWS);

}

function initialize_videos(prefix)
{    
    if (!get('videoinfo_content'))
        return;
    VIDEOS = new Array();

    var cached = getnumcached(prefix);

    for (var i = 0; i < cached; i++)
    {        
        var o = get('v' + i);
        var ts = get_attr(o, 'vs');
        var tb = get_attr(o, 'vb');
        var tf = get_attr(o, 'vf');
        var tt = get_attr(o, 'vt');
        var td = get_attr(o, 'vd');

        var thumbname;
        var iurl;

        if (tt == 'y')
            thumbname = tf + '.th.jpg';
        else
            thumbname = '';
        iurl = thumb_url(ts, tb, thumbname);
            
        var ihref = 'http://profile.imageshack.us/user/' + get('user').value + '/videos/detail/#' + ts + '/' + tf;

        var tags = get_tags(o);
        var dt = make_date(td);
        VIDEOS[VIDEOS.length] = [iurl, ihref, tags, dt, ts, tf];
    }

    initialize_pages(prefix, VIDEOS);
}


function initialize_comments(prefix)
{    
    if (!get('commentsinfo_content'))
        return;
    COMMENTS = new Array();

    var cached = getnumcached(prefix);

    for (var i = 0; i < cached; i++)
    {        
        var o = get('m' + i);

        var ts = get_attr(o, 'ms');
        var tb = get_attr(o, 'mb');
        var tf = get_attr(o, 'mf');
        var tt = get_attr(o, 'mt');
        var td = get_attr(o, 'md');
        var tc = get_attr(o, 'mc');
        var tu = get_attr(o, 'mu');
        var tl = get_attr(o, 'ml');
        var ti = get_attr(o, 'mi');
        var tz = '';

        var thumbname;
        var imurl;


        if(ts && tf && tb)
        {
             if(tt == 'y')
             {
                  thumbname =  thumb_name(tf);
                  imurl = thumb_url(ts, tb, thumbname);
             }
             else imurl = thumb_url(ts, tb, tf);
        }
        else    imurl = iurl('comments_user.jpg');
            
        var ihref = 'http://profile.imageshack.us/user/' + get('user').value ;

        var tags = get_tags(o);
        var dt = td;

        COMMENTS[COMMENTS.length] = [imurl, ihref, tags, td, ts, tf, tc, tu, tl, tz, ti ];
    }

    initialize_pages(prefix, COMMENTS);
}


function initialize_pages(prefix, objs)
{
    var rows  = parseInt(get(prefix + 'rows').value);
    var cols  = parseInt(get(prefix + 'cols').value);
    var count = getnumitems(prefix);

    var numpages = Math.ceil(count / (rows * cols));

    for (var i = 0; i < PCOUNTERS.length; i++)
    {
        if (PCOUNTERS[i][0] == prefix)
        {
            PCOUNTERS[i][1] = numpages;
            return;
        }
    }

    PCOUNTERS[PCOUNTERS.length] = [prefix, numpages];
}

function player_url(id)
{
    var pos = id.indexOf('/');
    var srv = id.substring(0, pos);
    return 'http://' + srv + '.imageshack.us/slideshow/player.php?id=' + id;
}

function extract_items(obj, page, prefix)
{
    var rows  = parseInt(get(prefix + 'rows').value);
    var cols  = parseInt(get(prefix + 'cols').value);

    var start = getstartpage(prefix);
    var end   = getendpage(prefix);
    start = (page - start) * cols * rows;
    end   = Math.min(start + rows * cols, getnumitems(prefix));
    return obj.slice(start, end);
}

function filter_items(objs, tagid)
{
    if (parseInt(tagid) == -1)
        return objs;
    var ret = new Array();
    for (var i = 0; i < objs.length; i++)
    {
        var found = false;
        var tags = objs[i][2];

        for (var j = 0; j < tags.length; j++)
        {
            if (tags[j][0] == tagid)
            {
                found = true;
                break;
            }
        }
        if (found)
            ret[ret.length] = objs[i];
    }
    return ret;
}

function get_attr(o, id)
{
    var items = o.getElementsByTagName(ITEM_ID);
    if (!items)
        return null;
    var i;
    for (i = 0; i < items.length; i++)
        if (items[i].className == id)
            return items[i].innerHTML;
    return null;
}

function get_tags(o)
{
    var ret = new Array();
    var items = o.getElementsByTagName(ITEM_ID);
    if (!items)
        return ret;
    var i;
    var tags = null;
    for (i = 0; i < items.length; i++)
    {
        if (items[i].className == 'tags')
        {
            tags = items[i];
            break;
        }
    }
    if (!tags)
        return ret;
    var items = tags.getElementsByTagName(ITEM_ID);
    if (!items)
        return ret;
    var i;
    for (i = 0; i < items.length; i++)
    {
        var tinfo = items[i].innerHTML;
        var pos = tinfo.indexOf(',');
        if (pos > 0)
            ret[ret.length] = [tinfo.substr(0, pos), tinfo.substr(pos + 1)];
        else
            ret[ret.length] = [tinfo, ''];
    }
    return ret;

}

function getnumitems(prefix)
{
    return parseInt(get(prefix + 'numitems').value);
}

function getnumpages(prefix)
{
    return parseInt(get(prefix + 'numpages').value);
}

function getstartpage(prefix)
{
    return parseInt(get(prefix + 'startpage').value);
}

function getendpage(prefix)
{
    return parseInt(get(prefix + 'endpage').value);
}

function has_page(id, prefix)
{
    var i = parseInt(id);
    return getstartpage(prefix) <= i && getendpage(prefix) >= i;
}

function is_full_content(prefix, offset)
{
  var o = get(prefix + 'startdate');
  if (o)
    return false;
  return (getstartpage(prefix) == offset && getendpage(prefix) == getnumpages(prefix) - (1 - offset))

}

function getnumcached(prefix)
{
    return parseInt(get(prefix + 'numcached').value);
}

function video_details_url(user, server, filename, tagname)
{
    var ret = '/user/' + user + '/videos/detail/#';
    if(tagname && tagname != '')
    {
        ret += 'tag/' + tagname + '/';
    } 
    ret += server + '/' + filename;
    return ret;
}

function show_more_tagged()
{
    show_more_tagged_images('1');
    show_more_tagged_images('2');
}

function show_more_tagged_images(idx)
{
    var o = get('imoretagged' + idx);
    if (o)
    {
        var tagname = get('tagname').value;
        if (tagname != '')
        {
            o.innerHTML = '<a target="_new" class="ser" href="/images/tag/' + encodeURIComponent(tagname) + '">Images from other users with tag \'' + tagname + '\'</a>';
            o.style.display = '';
        }
        else
            o.style.display = 'none';
    }
}

function date_restrictions()
{
    if (cur_day == 0 && cur_month == 0 && cur_year == 0)
        return '';
    return '&from_d=' + cur_day + '&from_m=' + (cur_month + 1) + '&from_y=' + cur_year + '&to_d=' + cur_day + '&to_m=' + (cur_month + 1) + '&to_y=' + cur_year;
}




function hide_unused_cells(prefix,counter,rows,cols)
{
    var nextrow = parseInt((counter/cols));

    for(var j = nextrow; j <= rows ;j++)
    {
        var o = get(prefix + 'r_' + j);
        if(o)o.style.display = "none";
    }
   
}



function delete_comment(id,by)
{
     if (!id ||!by)
         return;


     if(confirm('Are you sure?'))
     {
          callback_url = '/homepage/dbclient.php?action=deletecomment&id=' + id + '&by='+ by +'&rand=' + Math.random();

          var callback =
          {
              success:  delete_comments_callback,
              failure:  delete_comments_callback
          };
          comments_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
     }
}


function delete_comments_callback(rsp)
{
       comments_go_page(1,true);
}


function get_comments_master(viewer)
{

   var user   = get_cookie('isUSER');
   var owner  = get('user').value;
   var who    = ''; 

   if (user != null && user != '' && user.indexOf('-') < 0)
   {
        user   = user.toLowerCase();
        owner  = owner.toLowerCase();
        viewer = viewer.toLowerCase();

        if(user == owner)who = 'o';
        else 
        if(user == viewer)who = 'u'; 
    }
    return who;
}

function show_comments_form()
{
    var c = get_cookie('myimages');
    var o = get('mmore');
    if (o)
        o.style.display = c != null && c != '' ? '' : 'none';

}