/* **********************HEADER*************************
   USAGE:
   The Javascript contained in this file was written for 
   use in the production of the WedgeDoc Network. This
   file contains all the generic scripts that may be
   used on multiple sites within the network.
 
   AUTHOR:
   Antony Thickitt (WedgeDoc)

   DATE CREATED:
   21 Jan 2008

   DATE MODIFIED:
   04 Feb 2008
 
  *********************END HEADER*********************** */

/* -----------------------------------------------------
   Queue functions intothe onload event of the page.
   This script was taken from http://www.dccomics.com/
   ----------------------------------------------------- */

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
    {
      oldonload();
      func();
    }
  }
}

addLoadEvent(ExternalLinks);
addLoadEvent(DisplayPng);
addLoadEvent(StatusMsg);

/* -----------------------------------------------------
   Ensure IE Versions 6 and lower can correctly display
   PNG transparent graphics. Thanks to bobosola for the
   original script:
   (http://homepages.ntlworld.com/bobosola)
   ----------------------------------------------------- */
function DisplayPng()
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

var ver = navigator.appVersion;
if (ver.indexOf("MSIE") != -1)
{
if (version < 7)

{

if ((version >= 5.5) && (document.body.filters)) 
{
   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
      }
   }
}

}

}

}





/* -----------------------------------------------------
   This Function Opens links in new windows as a 
   replacement to target = "_blank". Code adapted from 
   http://www.sitepoint.com/article/standards-compliant-
   world/3. Thanks to the original script writer!
   ----------------------------------------------------- */

function ExternalLinks() 

   { 
   
      // Check if the browser is capable of running the DOM getElementsByTagName
      // method. If not, then the function terminates and links will be opened
      // in the same window.
 
      if (!document.getElementsByTagName) 
         return; 
		 
         // Find all <a> elements, and store them in an array, then go through all
	 // checking for href attributes and cases where the rel attribute is set
	 // to "newwindow"
		 
         var anchors = document.getElementsByTagName("a"); 
		 
         for (var i=0; i<anchors.length; i++) 

         { 
			
            var anchor = anchors[i]; 
   
            if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "NewWindow") 
     
               anchor.target = "_blank"; 
         } 
			
   } 
   



/* -----------------------------------------------------
   OPEN A POPUP WINDOW THAT HAS NO TOOLBARS ETC.
   ----------------------------------------------------- */


function NewWindow(URL, Height, Width)

   {

      window.open(URL, 'Video_Window', 'Toolbar=no,width='+Width+',height='+Height+',status=no,scrollbars=no,resize=no,menubar=no')

   }




/* -----------------------------------------------------
   USE THE STATUS BAR TO RETURN MEANINGFUL LINK INFO
   ----------------------------------------------------- */

function StatusMsg(Status)

   {
	   
      if (Status === undefined )
	  
      {
		  
         window.status = ('Part of the WedgeDoc Network')
		 
      }

      else if (Status == 'Default_Msg')

      {

         window.status = ('Part of the WedgeDoc Network')

      }

      else if (Status == 'Image_Msg')

      {

         window.status = ('Click To Open This Image In A New Window')            

      }

      else

      {

         window.status = (Status);

      }

      return true

   }


   
/* -----------------------------------------------------
   SWAP ONE IMAGE WITH ANOTHER
   ----------------------------------------------------- */

function SwapImages(imgName, imgSrc) 

   {

      if (document.images)

      {

         if (imgSrc != "none")

         {
     
            document.images[imgName].src = imgSrc;

         }
                  
      }

   }
	 

  /* -----------------------------------------------------
   SWAP CSS CLASS
   ----------------------------------------------------- */ 
   
   function SwapClass(itemID, cssName)
   
   {
	   document.getElementById(itemID).className = cssName;
   }
	  

/* -----------------------------------------------------
   SHOW / HIDE DIVS ON LINK CLICK
   ----------------------------------------------------- */

var doit = true

function showme(ob) 

   {
 
   if(doit) 
  
     {
		 
     /* NOTE: height attribute will need to be flexible to
	    ensure all content is contained without too much 
		expansion on screen. This is accomplished by
		setting a variable to the element's trueheight: */
		
      var section_height=document.getElementById(ob)
      section_height.trueheight=section_height.scrollHeight +"px";
      section_height.style.overflow="hidden"
	  
	  /* NOTE: Because the script runs based on the true or
	     false value of "doit", the page becomes a mite
		 glitchy if the user opens more than one droptext
		 reveal on the page at once */
   
	 document.getElementById(ob).style.height = section_height.trueheight
     doit = false
	 
	 ob = ""
	 
     }
	 
  else 
  
     {
    
	    document.getElementById(ob).style.height = '17px';
        doit = true
		
		ob = ""
		
     }

   }

/* -----------------------------------------------------
   VALIDATE FEEDBACK FORM ENTRIES
   ----------------------------------------------------- */
      
function ValidateFeedback(message, email)

   {

      if (message == "")

      {

         alert("Please enter a message before sending.");

         return false;


      }

      var string = new String(email);
      var index = string.indexOf("@");

      if (index <=0)

      {

         alert("please enter a valid e-mail address before sending.");

         return false;

      }
         
   }
