/*
 * s8.js - JavaScript functions for syndic8.com
 * Copyright (c) 2001-2006 - Jeff Barr
 */

function SelectToText(sel, txt)
{
  text  = sel.options[sel.selectedIndex].text;
  value = sel.options[sel.selectedIndex].value;

  if (value != '_')
  {
    if (value.indexOf('_') != -1)
    {
      text = text + ' ';
    }

    txt.value = text
  }
  else
  {
    txt.value = '';
  }
}

function OpenFeedListQuery(Root)
{
  var w = 
    window.open(Root + 'feedlistquery.php','',
                'status=0,menubar=0,resizable=1,scrollbars=0,width=600,height=600');
  w.focus();
  return false;
}

function OpenFeedStateHelp(Root)
{
  var w = 
    window.open(Root + 'help_feedstates.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1, height=650,width=750');
  w.focus();

  return false;
}

function OpenReviewerHelp(Root)
{
  var w = 
    window.open(Root + 'help_reviewer.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1,height=330,width=500');
  w.focus();

  return false;
}

function OpenSubscriptionHelp(Root)
{
  var w = 
    window.open(Root + 'help_subscription.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1,height=600,width=500');
  w.focus();
  return false;
}

function OpenMetadataHelp(Root)
{
  var w = 
    window.open(Root + 'help_metadata.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1, height=575,width=700');
  w.focus();
  return false;
}

function OpenLanguageHelp(Root)
{
  var w = 
    window.open(Root + 'help_language.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1, height=575,width=700');
  w.focus();
  return false;
}

function OpenArchiveHelp(Root)
{
  var w = 
    window.open(Root + 'help_archive.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1, height=575,width=500');
  w.focus();
  return false;
}

function OpenNewsHelp(Root)
{
  var w = 
    window.open(Root + 'help_news.php','',
                'status=0,menubar=0,resizable=1,scrollbars=1, height=575,width=500');
  w.focus();
  return false;
}

function OpenSubscribeToFeed(Root, UserID, FeedID, List)
{
  var w = 
    window.open(Root + "subscribe_feed.php?UserID=" + UserID + "&FeedID=" + FeedID + "&List=" + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenSubscribeToCategory(Root, UserID, Scheme, Category, List)
{
  var w = 
    window.open(Root + "subscribe_category.php?UserID=" + UserID + "&Scheme=" + Scheme + "&Category=" +
                Category + "&List=" + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenUnSubscribeFromFeed(Root, UserID, FeedID, List)
{
  var w = 
    window.open(Root + "unsubscribe_feed.php?UserID=" + UserID + "&FeedID=" + FeedID + "&List=" + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenUnSubscribeFromCategory(Root, UserID, Scheme, Category, List)
{
  var w = 
    window.open(Root + "unsubscribe_category.php?UserID=" + UserID + "&Scheme=" + Scheme +
                "&Category=" + Category + "&List=" + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenListPreview(Link)
{
  var w = 
    window.open(Link, 'list_preview', 'status=0,menubar=0,resizable=1,scrollbars=1,height=400,width=250', true);
  w.focus();
}

function OpenAdoptFeed(Root, UserID, FeedID)
{
  var w = 
    window.open(Root + "adopt_feed.php?UserID=" + UserID + "&FeedID=" + FeedID ,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenChangeListStatus(Root, UserID, List, Status)
{
  var w = 
    window.open(Root + "change_list_status.php?UserID=" + UserID + "&List=" + List + "&Status=" + Status,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenAddList(Root, UserID)
{
  var w = 
    window.open(Root + "add_list.php?UserID=" + UserID,'',
               'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenRenameList(Root, UserID, List)
{
  var w = 
    window.open(Root + "rename_list.php?UserID=" + UserID + '&List=' + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=150,width=300');
  w.focus();
  return false;
}

function OpenDeleteList(Root, UserID, List, ChangeParent)
{
  var w = 
    window.open(Root + "delete_list.php?UserID=" + UserID + '&List=' + List + '&ChangeParent=' + ChangeParent,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=150,width=300');
  w.focus();
  return false;
}

function OpenClearList(Root, UserID, List, ChangeParent)
{
  var w = 
    window.open(Root + "clear_list.php?UserID=" + UserID + '&List=' + List + '&ChangeParent=' + ChangeParent,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=150,width=300');
  w.focus();
  return false;
}

function OpenUpdateFeed(Root, FeedID)
{
  var w = 
    window.open(Root + 'update_feed.php?FeedID=' + FeedID, '',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=150,width=300');
  w.focus();
  return false;
}

function OpenChooseCategory(Root, Prompt, Action, ActionArgName, ActionArgValue)
{
  var w = 
    window.open(Root + 'choose_category.php?Prompt=' + Prompt + '&Action=' + Action + '&' +
                ActionArgName + '=' + ActionArgValue, '',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=500,width=800');
  w.focus();
  return false;
}

function OpenDeleteListCategory(Root, UserID, Scheme, Category, List)
{
  var w = 
    window.open(Root + "delete_list_category.php?UserID=" + UserID + '&Scheme=' + Scheme +
                '&Category=' + Category + '&List=' + List,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=200,width=450');
  w.focus();
  return false;
}

function OpenBurnFeed(Link)
{
  var w = window.open(Link, '',
                      'toolbar=0,status=0,scrollbars=1,width=640,height=440,resizable=1');
  w.focus();
  return false;
}

function OpenAddToKinja(Link)
{
  var w = window.open(Link,
                      '',
	              'width=350,height=230,status=yes,scrollbars=yes');
  w.focus();
  return false;
}

function OpenSetPub(Root, Dest, Status)
{
  var w = 
    window.open(Root + 'set_pub.php?Dest=' + Dest + '&Status=' + Status, '',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=150,width=300');
  w.focus();
  return false;
}

function OpenUpdateFeedMetaData(Root, FeedID, ChangeParent)
{
  var w = 
    window.open(Root + "update_feed_metadata.php?FeedID=" + FeedID + '&ChangeParent=' + ChangeParent,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=250,width=450');
  w.focus();
  return false;
}

function OpenApproveFeed(Root, FeedID, ChangeParent)
{
  var w = 
    window.open(Root + "approve_feed.php?FeedID=" + FeedID + '&ChangeParent=' + ChangeParent,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenMakeFeedDead(Root, FeedID)
{
  var w = 
    window.open(Root + "dead_feed.php?FeedID=" + FeedID,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenMakeFeedRejected(Root, FeedID)
{
  var w = 
    window.open(Root + "reject_feed.php?FeedID=" + FeedID,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenLabelFeedPossibleSpam(Root, FeedID)
{
  var w = 
    window.open(Root + "possible_spam_feed.php?FeedID=" + FeedID, '',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}

function OpenMakeFeedExplicit(Root, FeedID)
{
  var w = 
    window.open(Root + "explicit_feed.php?FeedID=" + FeedID,'',
                'status=0,menubar=0,resizable=0,scrollbars=0,height=80,width=250');
  w.focus();
  return false;
}
function RenameList_CheckAndSubmit()
{
  FormName = document.all['FormName'];

  if (FormName.value == '')
  {
    alert("You must supply a value for the field!");
    return false;
  }
}

function AndClose()
{
  window.close();
  return false;
}

function RefreshParentAndClose()
{
  window.opener.location = window.opener.location;
  window.close();
  return false;
}

function ChangeParentAndClose(Location)
{
  window.opener.location = Location;
  window.close();
  return false;
}

function SetWindowSize(ToThis)
{
  Width  = ToThis.scrollWidth;
  Height = ToThis.scrollHeight;

  // This nearly works
  self.window.clientWidth  = Width;
  self.window.clientHeight = Height;
}

function GetTheeHence(Satan)
{
  window.location   = Satan;
  event.returnValue = false;
}

/* PNG repair code from http://homepage.ntlworld.com/bobosola/pngtestfixed.htm */
function correctPNG()
{
  /* correctly handle PNG transparency in Win IE 5.5 or higher */

  for (var i = 0; i < document.images.length; i++)
  {
      var img     = document.images[i];
      var imgName = img.src.toUpperCase();
     
     if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
     {
	 var imgID    = (img.id)        ? "id='" + img.id + "' "           : "";
	 var imgClass = (img.className) ? "class='" + img.className + "' " : "";
	 var imgTitle = (img.title)     ? "title='" + img.title + "' "     : "title='" + img.alt + "' ";

	 var imgStyle = "display:inline-block;" + img.style.cssText;

	 if (img.align == "left") imgStyle = "float:left;" + imgStyle;
	 if (img.align == "right") imgStyle = "float:right;" + imgStyle;
	 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;

	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	     + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" ;

	 img.outerHTML = strNewHTML;
	 i = i-1;
     }
  }
}

function ShowIt(Div)
{
  Div.style.display = "block";
}

function HideIt(Div)
{
  Div.style.display = "none";
}

function TagSearchKeyUp()
{
  var search  = document.tag_search.filter.value;
  var tagBox  = document.getElementById("tag_box");
  var links   = tagBox.getElementsByTagName("a");
  var count   = document.getElementById("match_count");
  var matches = 0;

  for (x = 0; x < links.length; x++)
  {
    var tagName = links[x].childNodes.item(0).data;
    if (tagName.search(search) == -1)
    {
      links[x].style.display = "none";
    }
    else
    {
      links[x].style.display = '';
      matches++;
    }
  }

  count.innerHTML = "(" + matches + " matching tags)";
}

if (navigator.appVersion.indexOf("MSIE") > 0)
{
  if (parseFloat(navigator.appVersion) >= 5.5)
  {
    window.attachEvent("onload", correctPNG);
  }
}
