/*
**  File:	ifg.js
**
**  Desc:	JavaScript functions used by interformic.com
*/

/*
**  Function:	checkCrap()
**
**  Action:		Return false if the text contains crap.
**
*/
function checkCrap(form)
{
  var arCrap = new Array( "porn" );

  var szemail = form.email.value;
  var szDomain = szemail.substr(szemail.length-3,3);
  if ( szDomain == ".ru" )
  {
	return false;
  }

  var szText = form.text.value;
  for ( wCrapID = 0; wCrapID < arCrap.length; wCrapID++ )
  {
	if ( szText.match(arCrap[wCrapID]) )
	  return false;
  }

  return true;
}

/*
**  Function:	writeemail()
**
**  Action:	Write an interformic.com email address.  The purpose of this
**		is to hide the address from spammer trolling software.
*/
function writeemail( szName )
{
  if ( ! szName )
    szName = "info";

  szAddress  = "<a href='mailto:";
  szAddress += szName;
  szAddress += "@interformic.com'>";
  szAddress += szName;
  szAddress += "@interformic.com</a>";

  document.write( szAddress );
}

/*
**  jQuery body.
*/
$(document).ready(function() 
{
  /*
  **  Control slide toggle of Table of Contents tables.
  */

  //
  //  Hide (Collapse) the toggle containers on load.
  //
  $(".toggle_body").hide(); 
  
  //
  //  Switch the "Open" and "Close" state on click.
  //
  $("div.toggle_switch").toggle(function()
  {
    $(this).addClass("active");
  }, function () 
  {
    $(this).removeClass("active");
  });

  //
  //  Slide up and down on click.
  //
  $("div.toggle_switch").click(function()
  {
    $(this).next(".toggle_body").slideToggle("slow");
  });

  /*
  **  Control hover over popups in right column.
  */
  $('div.popover').hover(function() 
  {
    $(this).find('div.popup').fadeIn( 'normal' );
  },function()
  {
    $(this).find('div.popup').fadeOut( 'normal' );
  });

  /*
  **  Make AJAX call to log PDF downloads.
  */
  $('#leftcol a[href$=.pdf]').click(function()
  {
    szFile = $(this).attr('href');
    $.get( 'http://interformic.com/logDL/logDL.php', { file: szFile } );
    window.open(szFile); 
    return false;
  });

  /*
  **  Fix pulldown menus for IE6.
  */
  if ( $.browser.msie && /6.0/.test(navigator.userAgent) )
  {
    $('#button-games').hover(function() 
    {
      $(this).find('ul').addClass( 'show' );
    },function()
    {
      $(this).find('ul').removeClass( 'show' );
    });

    $('#button-page-nav').hover(function() 
    {
      $(this).find('ul').addClass( 'show' );
    },function()
    {
      $(this).find('ul').removeClass( 'show' );
    });
  }
});
