 function trim(str)
 {
  return (str ? '' + str : '').replace(/^\s*|\s*$/g, '');
 }

 function isDef(arg, argtype)
 {
  try
  {
   if (argtype === null || typeof(argtype) == 'undefined') return (arg !== null && typeof(arg) != 'undefined');
   return (arg !== null && typeof(arg) == argtype);
  }
  catch (e) {}
  return false;
 }

 function el(id)
 {
  try
  {
   if (!isDef(id, 'string') || id == '') return null;
   return document.getElementById(id);
  }
  catch(e) {}
  return null;
 }

function resizePage()
{
// setTimeout('_resizePage()', 100);
}

function _resizePage()
{
// var headerDiv = el('headerDiv');
// var menuDiv = el('menuDiv');
// var contentDiv = el('contentDiv');
// var footerDiv = el('footerDiv');
//
// var headerHeight = getHeight(headerDiv);
// var menuHeight = getHeight(menuDiv);
// var footerHeight = getHeight(footerDiv);
// var windowSize = getWindowSize();
//
// var contentHeight = windowSize.height - headerHeight - menuHeight - footerHeight;
// contentDiv.style.height = contentHeight + 'px';
//
// setTimeout('scrollToAnchor()', 100);  // Hack to stop browser losing the anchor page position when the page is resized
}

function displayImage(image, imageId)
{
 if (image == null || typeof(image) == 'undefined') return;
 if (imageId == null || typeof(imageId) == 'undefined' || imageId == '') return;

 var newImage = document.getElementById(imageId);
 if (newImage == null || typeof(newImage) == 'undefined' || newImage == '') return;

 newImage.style.display = 'inline';
 image.style.display = 'none';
}


 //////////////////////////////////////////////////////////////////
 //  Function:     submitForm                                    //
 //  Description:  Iterates through each of the selected form's  //
 //                elements and applies the regular expression   //
 //                validation test to their respective values.   //
 //  Arguments:    formID - Id of selected form to submit        //
 //  Returns:      true on Success, false on Failure             //
 //////////////////////////////////////////////////////////////////

 function submitForm(formID)
 {
  try
  {
   var result = true;

   var form = el(formID);                      // Select the form using the provided Id string
    if (!isDef(form)) return false;

   for (var i=0; i<form.elements.length; i++)  // Iterate through the form's input element array
   {
    var element = form.elements[i];

     var required = element.getAttribute('required');        // Get the form input element's custom "required" attribute, (required="false" will override all validation)
     if (!isDef(required) || required != 'false' || trim(element.value) != '')
    {
     var validate = element.getAttribute('validate');                            // Get the form input element's custom "validate" attribute
      if (isDef(validate) && validate != '')                 // Only apply validation test to form input elements that have a custom "validate" attribute defined
     {
      var validated = false;
      var tagType = element.type.toUpperCase();  // Determine if form input element is of type "CHECKBOX" or "RADIO"
      var isCheckbox = (tagType == 'CHECKBOX');
      var isRadioButton = (tagType == 'RADIO');

      if (isCheckbox) validated = element.checked; // Checkbox must be checked
      else if (isRadioButton)                      // Test that at least one of a set of radio buttons is checked
      {
       var j, radioButtons = eval('form.' + element.name);                          // Get the array holding all the radio button and all of its siblings

       for (j=0; j<radioButtons.length; j++) {if (radioButtons[j].checked) break;}  // Iterate through the array of radio buttons until one is found to be checked
       validated = (j < radioButtons.length);                                       // Test if no radio buttons checked
       i += (radioButtons.length - 1);
      }
      else
      {
       if (element.value != 'value required')               // Value not equal to default error string
       {
        var regExParam = validate.split('!');               // Extract the regular expression and any associated pattern flags by splitting the "validate" value on the '!' delimiter
        if (regExParam[0] == '' && regExParam.length == 3)  // Validation string must be in the form "!expression!flags" (flags are optional)
        {
         var regEx = RegExp(regExParam[1], regExParam[2]);  // Create Regular Expression
         validated = regEx.test(element.value);             // Passes Regular Expression Test
        }
       }
      }

      if (validated)
      {
        if (element.parentNode) element.parentNode.style.color = '#404040';  // If validated set the text colour of the input element and its parent cell to the default
        element.style.color = '#404040';
      }
      else
      {
       result = false;

       if (element.parentNode) element.parentNode.style.color = 'red';      // Visually indicate error by setting text colour of the input element and its parent cell to red
       element.style.color = 'red';

       if (element.value == '') element.value = 'value required';           // If input element's value is an empty string, set it to the error string, "value required"
      }
     }
    }
   }

   if (result)
   {
    form.submit();          // Submit validated form, ignored for demo
    return true;
   }
   else alert('Form values shown in red are invalid!');  // Show alert dialog to indicate that form has failed to validate
  }
  catch (e) {}

  return false;
 }


 ////////////////////////////////////////////////////////////////
 //  Function:     resetForm                                   //
 //  Description:  Clear all the values in the selected form.  //
 //  Arguments:    formID - Id of selected form to submit      //
 //  Returns:      true on Success, false on Failure           //
 ////////////////////////////////////////////////////////////////

 function resetForm(formID)
 {
  try
  {
   var form = el(formID);               // Select the form using the provided Id string
   if (form == null) return false;

   form.reset();                        // Clear the form

   return true;
  }
  catch (e) {}

  return false;
 }



// Script Source: CodeLifter.com Copyright 2003

PositionX = 100;  // Set the horizontal and vertical position for the popup
PositionY = 100;

defaultWidth  = 782;  // Set these value approximately 20 pixels greater than the
defaultHeight = 555;  // size of the largest image to be used (needed for Netscape)

var AutoClose = true; // Set autoclose true to have the window close automatically. Set autoclose false to allow multiple popup windows

if (parseInt(navigator.appVersion.charAt(0))>=4)
{
 var isNN=(navigator.appName=="Netscape")?1:0;
 var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
 var isOpera=(navigator.appName.indexOf("Opera")!=-1)?1:0;
}

var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle)
{
 if (isNN || isOpera){imgWin=window.open('about:blank','',optNN);}
 if (isIE){imgWin=window.open('about:blank','',optIE);}

 with (imgWin.document)
 {
  writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
  writeln('<sc'+'ript>');
  writeln('var isNN,isIE,isOpera;');
  writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
  writeln('isNN=(navigator.appName=="Netscape")?1:0;');
  writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;');
  writeln('isOpera=(navigator.appName.indexOf("Opera")!=-1)?1:0;}');
  writeln('function reSizeToImage(){');
  writeln('if (isIE || isOpera){');
  writeln('window.resizeTo(300,300);');
  writeln('width=300-(document.body.clientWidth-document.images[0].width);');
  writeln('height=300-(document.body.clientHeight-document.images[0].height);');
  writeln('window.resizeTo(width,height);}');
  writeln('if (isNN){');
  writeln('window.innerWidth=document.images["vuShield"].width;');
  writeln('window.innerHeight=document.images["vuShield"].height;}}');
  writeln('function doTitle(){document.title="'+imageTitle+'";}');
  writeln('</sc'+'ript>');
  if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
  else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
  writeln('<img name="vuShield" src='+imageURL+' style="display:block"></body></html>');
  close();
 }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Title:          XmlHttp Helper functions                                                                             //
//  Author:         zig                                                                                                  //
//  Revised:        Ratty                                                                                                //
//  Version:        0.6a                                                                                                 //
//  Last Update:    11-09-2006                                                                                           //
//  Usage:          call sendRequest(), with a url, an action object and optionally the synchronisation type.            //
//                  Edit showReceived() and do whatever needs doing with the results in the case of that action number.  //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var xmlHttpActions = {action: 0};

var xmlhttp = null;

function showReceived(xml)  // do something with results
{
 switch(xmlHttpActions.action)
 {
  case 1:
   // Do something
  break

  case 2:
   // Do something else
  break

  default:
   // Do default something
 }
}

function sendRequest(url, action, sync)  // send xml http request
{
 if (sync == null || typeof(sync) != 'boolean') sync = true;  // default is a synchronous request

 xmlHttpActions = action;
 xmlhttp = getDomXmlRequest();
 xmlhttp.onreadystatechange = xmlhttpChange;
 xmlhttp.open("GET", url, !sync);
 xmlhttp.send(null);

 if (sync == true) return xmlhttp.responseText;
 return true;
}
/*
function getDomXmlRequest()  // create xml http request
{
 var ua = navigator.userAgent.toLowerCase();
 if (ua.indexOf('msie') == -1) request = new XMLHttpRequest();
 else if (ua.indexOf('msie 5') == -1) request = new ActiveXObject("Msxml2.XMLHTTP");
 else request = new ActiveXObject("Microsoft.XMLHTTP");

 return request;
}

function getDomXmlRequest()  // create xml http request
{
 try {ajaxRequest = new XMLHttpRequest();}  // Opera 8.0+, Firefox, Safari
 catch (e)
 {
  try {ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");}  // Internet Explorer Browsers
  catch (e)
  {
   try {ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");}
   catch (e){return false;}  // Something went wrong
  }
 }

 return ajaxRequest;
}
*/

function getDomXmlRequest()  // create xml http request
{
 if (typeof(XMLHttpRequest) != 'undefined') return new XMLHttpRequest();
// else return null;

 var ax=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
 for (var i=0; i<ax.length; i++)
 {
  try {return new ActiveXObject(ax[i]);}
  catch (e) {}
 }

 return null;
}

function xmlhttpChange()  // xml http request changed
{
 if (xmlhttp.readyState == 4)
 {
  if (xmlhttp.status==200) showReceived(getDomFromXml(xmlhttp.responseText));
  else alert("Problem retrieving response.");
 }
}

function getDomFromXml(xmlString)  // return xml doc object from xml string
{
 if (typeof ActiveXObject != 'undefined')
 {
  var dom = new ActiveXObject("Microsoft.XMLDOM");
  dom.async = false;
  dom.loadXML(xmlString);
 }
 else if (document.implementation && document.implementation.createDocument)
 {
  parser = new DOMParser();
  var dom = parser.parseFromString(xmlString, "text/xml");
 }
 return dom;
}

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26864893-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

