/* **********************HEADER*************************
   USAGE:
   The Javascript contained in this file was written for 
   use in the production of the WedgeDoc Network and edited
   for use on the Preseli and Pembrokeshire Conseervatives 
   site.
 
   AUTHOR:
   Antony Thickitt (WedgeDoc)

   DATE CREATED:
   03 Mar 2009

   DATE MODIFIED:

 
  *********************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);

/* -----------------------------------------------------
   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')

   }
  
	  

/* -----------------------------------------------------
   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;

      }
         
   }
