//<script type="text/javascript">
//<!--
function doit() {
var colours = 0;
var i=0;
while (i<4096)
{
  var j = i;
  var count = 0;
  var k=32;
  while (k!=0)
  {
    if (j & 1) count = count + 1;
    j = j>>>1;
    k = k-1;
  }
  if (count>4) colours = colours+1;
  i = i+1;
}
document.writeln
  (colours + " colours.");
return colours;
}

var temp;

/**
 * debugFunctions.js
 *
 * This file contains a collection of debug functions for javascript.
 *
 * This source file is subject to version 2.1 of the GNU Lesser
 * General Public License (LPGL), found in the file LICENSE that is
 * included with this package, and is also available at
 * http://www.gnu.org/copyleft/lesser.html.
 * @package     Javascript
 *
 * @author      Dieter Raber <dieter@dieterraber.net>
 * @copyright   2004-12-27
 * @version     1.0
 * @license     http://www.gnu.org/copyleft/lesser.html
 *
 */

/**
 * TOC
 *
 * - getObjectProperties
 * - print_ob
 * - alert_ob
 * - window_ob
 *
 * - format_r
 * - print_r
 * - alert_r
 * - window_r
 */

/**
 * showProps
 *
 * Shows the properties of an given object
 *
 * object object
 * return array
 *
 * Use print_ob(), alert_ob() or window_ob() to display the result
 */
function getObjectProperties(item)
{
  var retVal = '';
  for (var prop in item)
  {
    if (item[prop].constructor != Function)
    {
      retVal += prop + ' => ' + item[prop] + "\n";
    }
  }
  return retVal;
}




/**
 * showProps
 *
 * Shows the properties of an given object
 *
 * object object
 * return array
 *
 * Use print_ob(), alert_ob() or window_ob() to display the result
 */
function getUserFunctions()
{
  var retVal = '';
  for (var prop in document)
  {
//    if (document[prop].constructor == Function)
//    {
//      retVal += prop + ' => ' + document[prop] + "\n";
//    }
  }
  return document;
}



/**
 * print_ob(), alert_ob(), window_ob()
 *
 * These three functions are different ways to display the result of getObjectProperties()
 * print_ob uses document.write and can hence only be called onload
 * alert_ob displays the result in an alert box
 * window_ob opens a popup window and writes the results there
 */
function alert_ob(expr)
{
  alert(getObjectProperties(expr))
}

function window_ob(expr)
{
  win = window.open('', 'format','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
  win.document.open();
  win.document.write('<pre>' + getObjectProperties(expr) + '</pre>');
  win.document.close()
  win.focus();
}

function print_ob(expr)
{
  document.write('<pre>' + getObjectProperties(expr) + '</pre>');
}


/**
 * format_r
 *
 * Returns human-readable information about a variable
 *
 * format_r() returns information about a variable in a way that's readable by humans.
 * If given a string, integer or float, the value itself will be printed.
 * If given an array, values will be presented in a format that shows keys and elements.
 *
 * example:
 *   test = new Array ('foo', 'bar', 'foobar')
 *   format_r(test)
 *   returns: Array
 *            {
 *                 [0] => foo
 *                 [1] => bar
 *                 [3] => foobar
 *            }
 *
 */
function format_r(expr)
{
  var dim    = 0;
  var padVal = '\xA0\xA0\xA0\xA0\xA0';

  switch(typeof expr)
  {
    case 'string':
    case 'number':
      retVal = expr;
      break;
    case 'object':
      retVal = 'Array\n{\n' + outputFormat(expr, dim) + '\n}';
      break;
    default:
      retVal = false;
  }

  function pad(dim)
  {
    padding = '';
    for (i = 0; i < dim; i++)
    {
      padding += padVal;
    }
    return padding;
  }

  function outputFormat(expr, dim)
  {
    var retVal = '';
    for (var key in expr)
    {
        if (typeof expr[key] == 'object' && expr[key].constructor == Array)
        {
          retVal += padVal + pad(dim) + '[' + key + '] => Array\n'
                  + padVal + pad(dim) + '{\n'
                  + outputFormat(expr[key], dim + 1) + padVal + pad(dim) + '}\n';
        }
        else if (expr[key].constructor == Function)
        {
          continue;
        }
        else
        {
          retVal = retVal + padVal + pad(dim) + '[' + key + '] => ' + expr[key] + '\n';
        }
    }
    return retVal;
  }
  return retVal;
}

/**
 * print_r(), alert_r(), window_r()
 *
 * These three functions are just different ways to display the result of format_r()
 * print_r uses document.write and can hence only be called onload
 * alert_r displays the result in an alert box
 * window_r opens a popup window and writes the results there
 */
function alert_r(expr)
{
  alert(format_r(expr))
}

function window_r(expr)
{
  win = window.open('', 'format','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
  win.document.open();
  win.document.write('<pre>' + format_r(expr) + '</pre>');
  win.document.close()
  win.focus();
}

function print_r(expr)
{
  document.write('<pre>' + format_r(expr) + '</pre>');
}

/////////////////////// Cookie reading and writing ////////////////////////////////////

function writeCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else
    var expires = "";
  document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function writeArrayCookie(name,valueArray,days) {
  writeCookie(name, valueArray.join("|"), days);
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}

function readArrayCookie(name) {
  var cookieArray = readCookie(name);
  if (cookieArray)
    return cookieArray.split("|");
  return null;
}

function eraseCookie(name) {
  writeCookie(name,"",-20*365);
}

//////////////////////////// Navigation Menu handling /////////////////////////////////

function initiate(name) {
  var cookieCount = 0;
  var cookieArray = readArrayCookie(name);
  // try to write a cookie that the shop can read to determine if cookies are enabled
  writeCookie("Cookies","",0);
  if (!cookieArray)
    cookieArray = new Array;
  temp=document.getElementById("containerul");
  for (var o=0;o<temp.getElementsByTagName("li").length;o++) {
    if (temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0) {
      var temp2 = document.createElement("span");
      temp2.className = "symbols";
      temp2.style.backgroundImage = //"none";
      (cookieArray.length>0)?((cookieArray[cookieCount]=="true")?"url(/minus.png)":"url(/plus.png)"):"url(/plus.png)";
      temp2.onclick=function() {
        showhide(this.parentNode);
        writeNavCookie(name);
      }
      temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild)
      temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";
      if (cookieArray[cookieCount]=="true"){
        showhide(temp.getElementsByTagName("li")[o]);
      }
      cookieCount++;
    }
    else {
      var temp2 = document.createElement("span");
      temp2.className = "symbols";
      temp2.style.backgroundImage = "none";
      //"url(/page.png)";
      temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild);
    }
  }
}

function showhide(el) {
  el.getElementsByTagName("ul")[0].style.display=
     (el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";
  el.getElementsByTagName("span")[0].style.backgroundImage=//"none"
     (el.getElementsByTagName("ul")[0].style.display=="block")?"url(/minus.png)":"url(/plus.png)";
}

function writeNavCookie(name){ // Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.
  var cookieArray=new Array();
  for (var q=0; q<temp.getElementsByTagName("li").length; q++) {
    if (temp.getElementsByTagName("li")[q].childNodes.length>0) {
      if (temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0) {
        cookieArray[cookieArray.length] = (temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");
      }
    }
  }
  writeArrayCookie(name, cookieArray, 2*365);
}

////////////////////////// Read / Write user details cookie ////////////////////////////

function writeDetailsCookie(detailsArray) {
  writeArrayCookie("details", detailsArray, 2*365);
}

var details;
var order;
function updateDetailsCookie()
{
  details[0] = document.clientdetails.Ecom_BillTo_Online_Email.value;
  details[1] = document.clientdetails.Ecom_BillTo_Online_Email_Confirm.value;
  details[2] = document.clientdetails.Ecom_BillTo_Telecom_Phone_Number.value;
  details[3] = document.clientdetails.Ecom_BillTo_Telecom_Phone_Number_Evening.value;
  details[4] = String(document.clientdetails.Ecom_BillTo_Postal_Name_Prefix.options.selectedIndex);
  details[5] = String(document.clientdetails.Ecom_BillTo_Postal_CountryCode.options.selectedIndex);
  details[6] = document.clientdetails.Ecom_BillTo_Postal_Name_First.value;
  details[7] = document.clientdetails.Ecom_BillTo_Postal_Name_Last.value;
  details[8] = document.clientdetails.Ecom_BillTo_Postal_Company.value;
  details[9] = document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value;
  details[10] = document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value;
  details[23] = document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value;
  details[11] = document.clientdetails.Ecom_BillTo_Postal_City.value;
  details[12] = document.clientdetails.Ecom_BillTo_Postal_PostalCode.value;
  details[25] = document.clientdetails.Ecom_BillTo_Postal_StateProv.value;
  details[13] = String(document.clientdetails.Ecom_ShipTo_Postal_Name_Prefix.options.selectedIndex);
  //details[14] = String(document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex);
  details[15] = document.clientdetails.Ecom_ShipTo_Postal_Name_First.value;
  details[16] = document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value;
  details[17] = document.clientdetails.Ecom_ShipTo_Postal_Company.value;
  details[18] = document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value;
  details[19] = document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value;
  details[24] = document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value;
  details[20] = document.clientdetails.Ecom_ShipTo_Postal_City.value;
  details[21] = document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value;
  details[26] = document.clientdetails.Ecom_ShipTo_Postal_StateProv.value;
  details[22] = document.clientdetails.Ecom_ShipTo_Instructions.value;
  writeDetailsCookie(details);
}

function getDetailsArray()
{
  details = readArrayCookie("details");
  if (!details)
  {
    details = new Array("","","","","0","0","","","","","","","","0","0","","","","","","","","","","","","");
    writeDetailsCookie(details);
  }
  else
  {
    if (!details[23])
      details[23] = "";
    if (!details[24])
      details[24] = "";
    if (!details[25])
      details[25] = "";
    if (!details[26])
      details[26] = "";
  }
  return details;
}

function cartUpdateDetailsCookie()
{
  details = getDetailsArray();
  details[14] = String(document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex);
  writeDetailsCookie(details);
  var browservsn = 0;
  var ie8 = false;
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
    browservsn =new Number(RegExp.$1); // capture x.x portion and store as a number
    if (browservsn >=8)
      ie8 = true;
  } else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
    browservsn =new Number(RegExp.$1); // capture x.x portion and store as a number
  else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
    browservsn =new Number(RegExp.$1); // capture x.x portion and store as a number

  if (ie8)
    window.location.reload(true);
  else
    window.location.reload(true);
}

function updateOrdersCookie()
{
  order = readArrayCookie("order");
  if (!order)
  {
    order = new Array("");
  }
  order[0] = String(document.ordersdetails.order.options[document.ordersdetails.order.options.selectedIndex].text);
  writeArrayCookie("order", order, 2*365);
  var ie8 = false;
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
    var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
    if (ieversion>=8)
      ie8 = true;
  }

  if (ie8)
    window.location.reload(true);
  else
    window.location.reload(true);
}

function updateDispatchEmailText(name,products)
{
var whatproducts;
var msg;
var tracking;

if (products<2)
  whatproducts="CamNest product has";
else
  whatproducts=products+" CamNest products have";
msg=
"Dear "+name+",\n"+"Your "+whatproducts+" been posted and payment taken from your card.\n"+
"\n";

tracking = document.ordersdetails.tracking.value;
if (tracking.length>0)
{
  if ((tracking.length>3) && (tracking.charAt(0)=='P'||tracking.charAt(0)=='p') &&
     (tracking.charAt(1)=='4') && (tracking.charAt(2)=='D'||tracking.charAt(2)=='d'))
  {
    msg = msg + "To track your purchase please click on http://www.p4d.co.uk/track.php?number="+tracking+
                " (or paste the link into an internet explorer). You should expect to receive your purchase within 48 hours, and most deliveries are made the next day.\n";
  }
  else if ((tracking.length>1) && (tracking.charAt(0)>='0' && tracking.charAt(0)<='9') && tracking.search('-')<0)
  {
    msg = msg + "To track your purchase please click on http://www.interparcel.com/tracking.php?action=dotrack&trackno="+tracking+
                " (or paste the link into an internet explorer). You should expect to receive your purchase within 2 to 5 days.\n";
  }
  else if (tracking.search('-')>-1)
  {
    msg = msg + "You should expect to receive your purchase within 2 days.\n\n"+
                "Your iCode Registration information is...\n" +
                "Product: \n" +
                "Registered Name: \n" +
                "Registration Code: " + tracking + "\n";
  }
  else
  {
    msg = msg + "You should expect to receive your purchase within 3 days.\n";
  }
}
else
{
  msg = msg + "You should expect to receive your purchase within 3 days.\n";
}

msg = msg + "\n"+
"Thank you for choosing CamNest to buy from.\n"+
"\n"+
"Best regards,\n"+
"\n"+
"Peggy and Lionel.\n"+
"\n"+
"CamNest Ltd.\n"+
"URL: http://www.camnest.co.uk\n";

document.ordersdetails.Message.value=msg;
}



//////////////////////////// other fns //////////////////////////////////////

function checkpostcode(postcode, whatpostcode, country)
{
  updateDetailsCookie();
  if (postcode=="" || country>4)
    return true; // allow no postcode and don't check for non-UK countries
  if (!/^[A-Z]?[A-Z][0-9][A-Z]?[A-Z0-9]? *[0-9][A-Z][A-Z]$/.test(postcode.toUpperCase()))
  {
    alert(postcode+" is not a valid "+whatpostcode+", please re-enter. \n\n\
Valid postcodes have two parts separated by a space.\n\
The first part must start with a letter and end with a number.\n\
The second part must start with a number and end with a letter.\n\
     ");
    return false;
  }
  return true;
}

// email

function checkemail (strng, whatemail) {
  updateDetailsCookie();
  if (strng == "") {
    alert("You have not supplied your "+whatemail+".\n\
We need this information to process your order.\n");
    return false;
  }

  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) { 
    alert("You have not supplied a valid "+whatemail+",\n\
it should be something like me@place.com\n\
please re-enter.\n");
    return false;
  }
  else {
    //test email for illegal characters
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\|]/
    if (strng.match(illegalChars)) {
      alert("Your "+whatemail+" contains unacceptable charaters,\n\
please re-enter.\n");
      return false;
    }
  }
  return true;    
}

function checkconfirmationemail (email, confirmation) {
  if (!checkemail(confirmation, "Confirmation E-mail address"))
    return false;
  if (email != confirmation)
  {
    alert("Your Confirmation E-mail address does not match your entered E-mail address,\n\
please correct it.\n");
    return false;
  }
  return true;
}

// phone number - strip out delimiters and check for 11 digits

function checkphone (strng, whatphone) {
  updateDetailsCookie();
  if (strng != "") {
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
      alert("Your "+whatphone+" phone number contains unacceptable characters,\n\
please re-enter.\n");
      return false;
    }
    if (stripped.length < 11) {
      alert("Your "+whatphone+"phone number is the wrong length.\n\
Make sure you included an area code,\n\
please re-enter.\n");
      return false;
    }
  } 
  return true;
}

// a persons first or last name
function checkname (strng, whatname, musthavecontent) {
  updateDetailsCookie();
  if (strng=='') {
    if (musthavecontent==true) {
      alert("You have not supplied a "+whatname+" name.\n\
We need this information to process your order.\n");
      return false;
    }
    return true;
  }

  var illegalChars = /[0-9\(\)\,\-\'\`\¬\!\"\£\$\%\^\&\*\_\+\=\{\}\[\]\:\;\@\~\#\<\>\?\/\|\\]/i; // allow a-z and spaces
  if (illegalChars.test(strng)) {
    alert(whatname+" name can only contain the letters A-Z and spaces,\n\
please re-enter.\n");
    return false;
  }
  return true;
}       

function checkaddress (strng, whatname, musthavecontent) {
  updateDetailsCookie();
  if (strng=='') {
    if (musthavecontent==true) {
      alert("You have not supplied the "+whatname+".\n\
We need this information to process your order.\n\
       ");
      return false;
    }
    return true;
  }

  var illegalChars = /[\`\¬\!\"\£\$\%\^\&\*\_\+\=\{\}\[\]\:\;\@\~\#\<\>\?\/\|\\]/i; // allow a-z0-9(),-' and spaces
  if (illegalChars.test(strng)) {
    alert("The "+whatname+" can only contain the characters\n\
A-Z,0-9,(),comma,-,space or single quote, please re-enter.\n");
    return false;
  }
  return true;
}

function checktext (strng) {
  updateDetailsCookie();
  if (strng=='') {
    return true;
  }

  var illegalChars = /[\&\|]/i; // allow all except = & and |
  if (illegalChars.test(strng)) {
    alert("The "+strng+" can not contain a '&', '=' or a '|', please re-enter.\n");
    return false;
  }
  return true;
}

function checkNoChangeToDeliveryCountry() {
  var newCountry = String(document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex);
  if (details[14]==newCountry)
  {
    updateDetailsCookie();
    return true;
  }
  else
  {
    alert("To change the delivery country please go back to the Shopping Cart page and select it there.\n");
    document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex = parseInt(details[14]);
    return false;
  }
}

function checkSelect () {
  updateDetailsCookie();
  return true;
}

function checkalldetails()
{
  if (!checkemail(document.clientdetails.Ecom_BillTo_Online_Email.value, "E-mail address")) return false;
  if (!checkconfirmationemail(document.clientdetails.Ecom_BillTo_Online_Email.value, document.clientdetails.Ecom_BillTo_Online_Email_Confirm.value)) return false;
  if (!checkphone(document.clientdetails.Ecom_BillTo_Telecom_Phone_Number.value, "Daytime")) return false;
  if (!checkphone(document.clientdetails.Ecom_BillTo_Telecom_Phone_Number_Evening.value, "Evening")) return false;
  if (!checkname(document.clientdetails.Ecom_BillTo_Postal_Name_First.value, "Billing First", false)) return false;
  if (!checkname(document.clientdetails.Ecom_BillTo_Postal_Name_Last.value, "Billing Last", true)) return false;
  if (!checktext(document.clientdetails.Ecom_BillTo_Postal_Company.value, "Billing Company Name")) return false;
  if (!checkaddress(document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value, "First line of billing address", true)) return false;
  if (!checkaddress(document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value, "Second line of billing address", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value, "Third line of billing address", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_BillTo_Postal_StateProv.value, "Billing County", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_BillTo_Postal_City.value, "Billing City", true)) return false;
  if (!checkpostcode(document.clientdetails.Ecom_BillTo_Postal_PostalCode.value, "Billing post code", document.clientdetails.Ecom_BillTo_Postal_CountryCode.options.selectedIndex)) return false;
  if (!checkname(document.clientdetails.Ecom_ShipTo_Postal_Name_First.value, "Delivery First", false)) return false;
  if (!checkname(document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value, "Delivery Last", true)) return false;
  if (!checktext(document.clientdetails.Ecom_ShipTo_Postal_Company.value, "Delivery Company Name")) return false;
  if (!checkaddress(document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value, "First line of delivery address", true)) return false;
  if (!checkaddress(document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value, "Second line of delivery address", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value, "Third line of delivery address", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_ShipTo_Postal_StateProv.value, "Delivery County", false)) return false;
  if (!checkaddress(document.clientdetails.Ecom_ShipTo_Postal_City.value, "Delivery City", true)) return false;
  if (!checkpostcode(document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value, "Delivery post code", document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex)) return false;
  if (!checktext(document.clientdetails.Ecom_ShipTo_Instructions.value, "Delivery Instructions")) return false;
  //var CurrentTime = '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_GMT" -->' //SSI method of getting server date
  //var CurrentTime = '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' //SSI method of getting server date
  //var PHPcurrentTime = '<?php  print time()?>' //PHP method of getting server date
  //var currentDate = new Date(CurrentTime);
  //document.clientdetails.timenow.value = CurrentTime+''; //currentDate.getTime()+'';

  var currentDate = new Date();

  document.clientdetails.timenow.value = currentDate.getTime()+'';
  // details verified, now generate the encrypted data and write into document.clientdetails.Crypt
  return true;
}

//  <select type="hidden" id='Ecom_ShipTo_Postal_Name_Prefix' name='Ecom_ShipTo_Postal_Name_Prefix'>
//    <option selected>Mr</option>
//    <option>Mrs</option>
//    <option>Ms</option>
//    <option>Miss</option>
//    <option>Dr</option>
//    <option>Mr and Mrs</option>
//    <option>Lord</option>
//    <option>Lady</option>
//    <option>Sir</option>
//    <option></option>
//  </select>

/*
function getCountryCode(index)
{
  switch (index) {
  case 0: 
    return ("England (3-4 Working Days)");
  case 1: 
    return ("Scotland (3-4 Working Days)");
  case 2: 
    return ("Wales (3-4 Working Days)");
  case 3: 
    return ("England (2 Working Days)");
  case 4: 
    return ("Scotland (2 Working Days)");
  case 5: 
    return ("Wales (2 Working Days)");
  case 6: 
    return ("Highlands&Islands (3-6 Working Days)");
  case 7: 
    return ("Northern-Ireland (3-4 Working Days)");
  case 8: 
    return ("Irish-Republic (3-6 Working Days)");
  case 9: 
    return ("Guernsey (3-6 Working Days)");
  case 10: 
    return ("Jersey (3-6 Working Days)");
  case 11: 
    return ("France (3-6 Working Days)");
  case 12: 
    return ("Germany (3-6 Working Days)");
  case 13: 
    return ("Holland (3-6 Working Days)");
  case 14: 
    return ("Belgium (3-6 Working Days)");
  case 15: 
    return ("Luxembourg (3-6 Working Days)");
  case 16: 
    return ("Italy (3-6 Working Days)");
  case 17: 
    return ("Norway (3-6 Working Days)");
  case 18: 
    return ("Denmark (3-6 Working Days)");
  case 19: 
    return ("Sweden (3-6 Working Days)");
  case 20: 
    return ("Finland (3-6 Working Days)");
  case 21:
    return ("Canada (3-6 Working Days)");
  default : return ("Unknown");
  }
}
*/

function getCountryCode(index, isBilling)
{
  switch (index) {
  case 0: 
    return ("England");
  case 1: 
    return ("Scotland");
  case 2: 
    return ("Wales");
  default :
    if (isBilling!=0)
      index = index+3;
  }
  switch (index) {
  case 3: 
    return ("England");
  case 4: 
    return ("Scotland");
  case 5: 
    return ("Wales");
  case 6: 
    return ("Highlands & Islands");
  case 7: 
    return ("Northern Ireland");
  case 8: 
    return ("Irish Republic");
  case 9: 
    return ("Guernsey");
  case 10: 
    return ("Jersey");
  case 11: 
    return ("France");
  case 12: 
    return ("Germany");
  case 13: 
    return ("Holland");
  case 14: 
    return ("Belgium");
  case 15: 
    return ("Luxembourg");
  case 16: 
    return ("Italy");
  case 17: 
    return ("Norway");
  case 18: 
    return ("Denmark");
  case 19: 
    return ("Sweden");
  case 20: 
    return ("Finland");
  case 21: 
    return ("Canada");
  default : return ("Unknown");
  }
}

function getPersonTitle(index)
{
  switch (index) {
  case 0: 
    return ("Mr");
  case 1: 
    return ("Mrs");
  case 2: 
    return ("Ms");
  case 3: 
    return ("Miss");
  case 4: 
    return ("Dr");
  case 5: 
    return ("Mr and Mrs");
  case 6: 
    return ("Lord");
  case 7: 
    return ("Lady");
  case 8: 
    return ("Sir");
  default : return ("");
  }
}


function initialiseDetails2()
{
  details = getDetailsArray();
  document.clientdetails.Ecom_BillTo_Online_Email.value = details[0];
  document.clientdetails.Ecom_BillTo_Online_Email_Confirm.value = details[1];
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number.value = details[2];
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number_Evening.value = details[3];
  document.clientdetails.Ecom_BillTo_Postal_Name_Prefix.value = getPersonTitle(parseInt(details[4]));
  document.clientdetails.Ecom_BillTo_Postal_CountryCode.value = getCountryCode(parseInt(details[5]),1);
  document.clientdetails.Ecom_BillTo_Postal_Name_First.value = details[6];
  document.clientdetails.Ecom_BillTo_Postal_Name_Last.value = details[7];
  document.clientdetails.Ecom_BillTo_Postal_Company.value = details[8];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value = details[9];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value = details[10];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value = details[23];
  document.clientdetails.Ecom_BillTo_Postal_City.value = details[11];
  document.clientdetails.Ecom_BillTo_Postal_PostalCode.value = details[12];
  document.clientdetails.Ecom_BillTo_Postal_StateProv.value = details[25];
  document.clientdetails.Ecom_ShipTo_Postal_Name_Prefix.value = getPersonTitle(parseInt(details[13]));
  document.clientdetails.Ecom_ShipTo_Postal_CountryCode.value = getCountryCode(parseInt(details[14]),0);
  document.clientdetails.Ecom_ShipTo_Postal_Name_First.value = details[15];
  document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value = details[16];
  document.clientdetails.Ecom_ShipTo_Postal_Company.value = details[17];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value = details[18];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value = details[19];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value = details[24];
  document.clientdetails.Ecom_ShipTo_Postal_City.value = details[20];
  document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value = details[21];
  document.clientdetails.Ecom_ShipTo_Postal_StateProv.value = details[26];
  document.clientdetails.Ecom_ShipTo_Instructions.value = details[22];
}

function initialiseDetails()
{
  details = getDetailsArray();
  document.clientdetails.Ecom_BillTo_Online_Email.value = details[0];
  document.clientdetails.Ecom_BillTo_Online_Email_Confirm.value = details[1];
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number.value = details[2];
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number_Evening.value = details[3];
  document.clientdetails.Ecom_BillTo_Postal_Name_Prefix.options.selectedIndex = parseInt(details[4]);
  document.clientdetails.Ecom_BillTo_Postal_CountryCode.options.selectedIndex = parseInt(details[5]);
  document.clientdetails.Ecom_BillTo_Postal_Name_First.value = details[6];
  document.clientdetails.Ecom_BillTo_Postal_Name_Last.value = details[7];
  document.clientdetails.Ecom_BillTo_Postal_Company.value = details[8];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value = details[9];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value = details[10];
  document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value = details[23];
  document.clientdetails.Ecom_BillTo_Postal_City.value = details[11];
  document.clientdetails.Ecom_BillTo_Postal_PostalCode.value = details[12];
  document.clientdetails.Ecom_BillTo_Postal_StateProv.value = details[25];
  document.clientdetails.Ecom_ShipTo_Postal_Name_Prefix.options.selectedIndex = parseInt(details[13]);
  document.clientdetails.Ecom_ShipTo_Postal_CountryCode.value = getCountryCode(parseInt(details[14]),0);
  document.clientdetails.Ecom_ShipTo_Postal_Name_First.value = details[15];
  document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value = details[16];
  document.clientdetails.Ecom_ShipTo_Postal_Company.value = details[17];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value = details[18];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value = details[19];
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value = details[24];
  document.clientdetails.Ecom_ShipTo_Postal_City.value = details[20];
  document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value = details[21];
  document.clientdetails.Ecom_ShipTo_Postal_StateProv.value = details[26];
  document.clientdetails.Ecom_ShipTo_Instructions.value = details[22];
}

function initialiseCartDetails()
{
  details = getDetailsArray();
  document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex = parseInt(details[14]);
}

function clearcontact()
{
  document.clientdetails.Ecom_BillTo_Online_Email.value = '';
  document.clientdetails.Ecom_BillTo_Online_Email_Confirm.value = '';
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number.value = '';
  document.clientdetails.Ecom_BillTo_Telecom_Phone_Number_Evening.value = '';
  details[0] = '';
  details[1] = '';
  details[2] = '';
  details[3] = '';
  writeDetailsCookie(details);
}

function clearbilling()
{
  document.clientdetails.Ecom_BillTo_Postal_Name_Prefix.options.selectedIndex = 0;
  document.clientdetails.Ecom_BillTo_Postal_CountryCode.options.selectedIndex = 0;
  document.clientdetails.Ecom_BillTo_Postal_Name_First.value = '';
  document.clientdetails.Ecom_BillTo_Postal_Name_Last.value = '';
  document.clientdetails.Ecom_BillTo_Postal_Company.value = '';
  document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value = '';
  document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value = '';
  document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value = '';
  document.clientdetails.Ecom_BillTo_Postal_City.value = '';
  document.clientdetails.Ecom_BillTo_Postal_PostalCode.value = '';
  document.clientdetails.Ecom_BillTo_Postal_StateProv.value = '';
  details[4] = '0';
  details[5] = '0';
  details[6] = '';
  details[7] = '';
  details[8] = '';
  details[9] = '';
  details[10] = '';
  details[11] = '';
  details[12] = '';
  details[23] = '';
  details[25] = '';
  writeDetailsCookie(details);
}

function cleardelivery()
{
  document.clientdetails.Ecom_ShipTo_Postal_Name_Prefix.options.selectedIndex = 0;
  //document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex = 0;
  document.clientdetails.Ecom_ShipTo_Postal_Name_First.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_Company.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_City.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value = '';
  document.clientdetails.Ecom_ShipTo_Postal_StateProv.value = '';
  document.clientdetails.Ecom_ShipTo_Instructions.value = '';
  details[13] = '0';
  //details[14] = '0';
  details[15] = '';
  details[16] = '';
  details[17] = '';
  details[18] = '';
  details[19] = '';
  details[20] = '';
  details[21] = '';
  details[22] = '';
  details[24] = '';
  details[26] = '';
  writeDetailsCookie(details);
}

function transferdetails()
{
  document.clientdetails.Ecom_ShipTo_Postal_Name_Prefix.options.selectedIndex = document.clientdetails.Ecom_BillTo_Postal_Name_Prefix.options.selectedIndex;
  //document.clientdetails.Ecom_ShipTo_Postal_CountryCode.options.selectedIndex = document.clientdetails.Ecom_BillTo_Postal_CountryCode.options.selectedIndex;
  document.clientdetails.Ecom_ShipTo_Postal_Name_First.value = document.clientdetails.Ecom_BillTo_Postal_Name_First.value;
  document.clientdetails.Ecom_ShipTo_Postal_Name_Last.value = document.clientdetails.Ecom_BillTo_Postal_Name_Last.value;
  document.clientdetails.Ecom_ShipTo_Postal_Company.value = document.clientdetails.Ecom_BillTo_Postal_Company.value;
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line1.value = document.clientdetails.Ecom_BillTo_Postal_Street_Line1.value;
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line2.value = document.clientdetails.Ecom_BillTo_Postal_Street_Line2.value;
  document.clientdetails.Ecom_ShipTo_Postal_Street_Line3.value = document.clientdetails.Ecom_BillTo_Postal_Street_Line3.value;
  document.clientdetails.Ecom_ShipTo_Postal_City.value = document.clientdetails.Ecom_BillTo_Postal_City.value;
  document.clientdetails.Ecom_ShipTo_Postal_PostalCode.value = document.clientdetails.Ecom_BillTo_Postal_PostalCode.value;
  document.clientdetails.Ecom_ShipTo_Postal_StateProv.value = document.clientdetails.Ecom_BillTo_Postal_StateProv.value;
  details[13] = details[4];
  //details[14] = details[5];
  details[15] = details[6];
  details[16] = details[7];
  details[17] = details[8];
  details[18] = details[9];
  details[19] = details[10];
  details[20] = details[11];
  details[21] = details[12];
  details[24] = details[23];
  details[26] = details[25];

  writeDetailsCookie(details);

  if (getCountryCode(parseInt(details[14]),0)!=getCountryCode(parseInt(details[5]),1))
  {
    alert("To change the delivery country please go back to the Shopping Cart page and select it there.\n");
  }
}

// Image Flipper -  Cameron Gregory - http://www.bloke.com/
// http://www.bloke.com/javascript/Flipper/
// http://www.bloke.com/javascript/Flipper/link.html

function setOpacity(r, value)
{
  r.style.opacity = value/10;
  r.style.filter = 'alpha(opacity=' + value*10 + ')';
}

var fadedpic;
function changeImage(r,i,speed)
{
  r.src=i;
  fadedpic = document.getElementById('flip');
  for (var i=0;i<=10;i++)
    setTimeout('setOpacity(fadedpic,'+i+')',(speed/30)*i);
  for (i=10;i>=0;i--)
    setTimeout('setOpacity(fadedpic,'+i+')',(2*speed/3)+((speed/30)*(10-i)));
}

function goFlipURL()
{
  document.location = urlSet[currentFlip];
}

function flipFlipper(imageSet,textSet,speed)
{
  currentFlip ++;
  if (currentFlip == imageSet.length)
    currentFlip=0;
  changeImage(document.flip,imageSet[currentFlip],speed);
  if (textSet.length>0)
    document.getElementById('pictext').innerHTML=textSet[currentFlip];
  setTimeout("flipFlipper(imageSet,textSet,speed)", speed)
}



function FlipperLong(width,height,s,images,texts,hoverText,ignoredurls)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/
 speed = s;
 si = 0;
 cc=0;
 imageSet = new Array();
 ei = images.length;
  for (i=1;i<ei;i++) {
    if (images.charAt(i) == ' ') {
      imageSet[cc] = images.substring(si,i);
      cc++;
      si=i+1;
    }
  }

  textSet = new Array();
  cc = 0;
  si = 0;
  ei = texts.length;
  for (i=1;i<ei;i++) {
    if (texts.charAt(i) == '|') {
      textSet[cc] = texts.substring(si,i);
      cc++;
      si=i+1;
    }
  }

  currentFlip = 0;
   
  document.write("<a title=\""+hoverText+"\"><img name='flip' id='flip'");
  if (width >0)
    document.write("width="+width);
  if (height >0)
    document.write(" height=" +height);
  document.writeln(" src=" +imageSet[0]+ "></a>");
  changeImage(document.flip,imageSet[currentFlip], speed);

  setTimeout("flipFlipper(imageSet,textSet,speed)", speed)
}

function Flipper(width,height,images,texts,hoverText)
{
  speed=5000;
  FlipperLong(width,height,speed,images,texts,hoverText);
}


function FlipperLinkLong(width,height,s,images,hoverText,urls)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/
 speed = s;
 imageSet = new Array();
 urlSet = new Array();

 si = 0; 
 ci=0;
 cc=0;
 ei = images.length;
  for (i=1;i<ei;i++) {
    if (images.charAt(i) == ' ') {
      imageSet[cc]= images.substring(si,i);
      cc++;
      si=i+1;
      }
    }

 si = 0; 
 ci=0;
 ccu=0;
 ei = urls.length;
  for (i=1;i<ei;i++) {
    if (urls.charAt(i) == ' ') {
      urlSet[ccu]= urls.substring(si,i);
      ccu++;
      si=i+1;
      }
    }

  currentFlip = 0;
   
 document.write("<a title=\""+hoverText+"\" href=\"javascript:goFlipURL()\"><img name='flip'");
 if (width >0)
    document.write("width="+width);
 if (height >0)
    document.write(" height=" +height);
  document.writeln(" src=" +imageSet[0]+ "></a>");

  setTimeout("flipFlipper(imageSet,speed)", speed)
}

function FlipperLink(width,height,images,hoverText,urls)
{
  speed=1000;
  FlipperLinkLong(width,height,speed,images,hoverText,urls);
}

function changeText(r,i)
{
document.getElementById(r).innerHTML=i;
}

function flipTextFlipper(textSet,speed)
{
  currentTextFlip ++;
  if (currentTextFlip == textSet.length)
    currentTextFlip=0;
  changeText('pictext',textSet[currentTextFlip]);
  setTimeout("flipTextFlipper(textSet,speed)", speed)
}

function TextFlipperLong(s,text)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/
 speed = s;
 si = 0; 
 ci=0;
 cc=0;
 textSet = new Array();
 ei = text.length;
  for (i=1;i<ei;i++) {
    if (text.charAt(i) == '|') {
      textSet[cc] = text.substring(si,i);
      cc++;
      si=i+1;
    }
  }
  currentTextFlip = 0;
   
  document.write("<a id='pictext'>");
//  document.writeln(textSet[currentTextFlip]+"</a>");
  document.writeln(textSet[currentTextFlip]+"</a>");

  setTimeout("flipTextFlipper(textSet,speed)", speed)
}

function TextFlipper(text)
{
  speed=5000;
  FlipperLong(text);
}

var sysheight;
var syswidth;
var OpenWin;
var browser = new String();
var vsn;

function BrowserVersion(browser)
{
  if (/MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent))           //test for MSIE/x.x or MSIE x.x (ignoring remaining decimal places);
    browser.value = "M";
  else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))   //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
    browser.value = "F";
  else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent))    //test for Chrome/x.x or Chrome x.x (ignoring remaining digits);
    browser.value = "C";
  else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent))    //test for Safari/x.x or Safari x.x (ignoring remaining digits);
    browser.value = "S";
  else if (/SeaMonkey[\/\s](\d+\.\d+)/.test(navigator.userAgent)) //test for SeaMonkey/x.x or SeaMonkey x.x (ignoring remaining decimal places);
    browser.value = "K";
  else if (/Netscape[\/\s](\d+\.\d+)/.test(navigator.userAgent))  //test for Netscape/x.x or Netscape x.x (ignoring remaining digits);
    browser.value = "N";
  else if (/Navigator[\/\s](\d+\.\d+)/.test(navigator.userAgent)) //test for Navigator/x.x or Navigator x.x (ignoring remaining digits);
    browser.value = "N";
  else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))     //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
    browser.value = "O";
  else
  {
    browser.value = "U";
    return 0;
  }

  vsn = new Number(RegExp.$1); // capture x.x portion and store as a number
  return vsn;
}

function OpenPicture(pic,title,css,w,h,extra)
{
  caption = title;
  if (title!="")
  {
    if (extra!="")
      caption = title+' '+extra;
  }
  else
  {
    title = pic;
    caption = extra;
  }
  vcells = 2;
  if (caption=="")
    vcells = 1;

  barheight = 32;
  vscrollbar = 32;
  border = 4;
  sysborder = 6;
  cellspacing = 2;
  hspacing = (border*2)+(cellspacing*2)+vscrollbar;  // 2 borders and one cell wide (so 2 lots of cell spacing)+ scroll bar
  vspacing = (border*2)+(cellspacing*(1+vcells));  // 2 borders and two cells deep (so 3 lots of cell spacing)
  tablesurround = 16*2; // either side and top and bottom
  vtextcell = 24 * (vcells-1);

  if (!sysheight)
  {
    // open the window with a default size, just to find out how much space is used by the system
    OpenWin = window.open("", "PicWin", "height=200, width=200, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, status=no, directories=no, copyhistory=no, channelmode=no");
    OpenWin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
    OpenWin.document.writeln('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    OpenWin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">');
    OpenWin.document.writeln('<head><title>'+title+'</title>');
    OpenWin.document.writeln('</head><body>');
    OpenWin.document.writeln('<div id="resizeReference" style="position:absolute; top:0px; left:0px; width:100%; height:100%; z-index:-1;"> &nbsp; </div>');
    OpenWin.document.writeln('</body></html>');
    OpenWin.document.close();
    vsn = BrowserVersion(browser);
    var resizeRef = OpenWin.document.getElementById('resizeReference');
    if (resizeRef)
    {
      syswidth = resizeRef.offsetWidth;
      sysheight = resizeRef.offsetHeight;
      OpenWin.resizeTo(200,200);
      syswidth -= resizeRef.offsetWidth;
      sysheight -= resizeRef.offsetHeight;
      if (browser.value=="M" && vsn==7) // I have found that the first time the window opens in MSIE7 it opens slightly shorter
        OpenWin.moveTo(0,0);
      resizeRef = null;
    }
  }
  else if (OpenWin) // not the first time through so the OpenWin may still exist but be behind the main window
  {
    // Chrome has a bug where window.focus() does not bring the window forward so we have to delete it first!
    if (browser.value=="C")
    {
      OpenWin.close();
      OpenWin = null;
    }
  }

  if (!sysheight || sysheight<=0)
  {
    if (browser.value!="M" && browser.value!="O" && browser.value!="C") // no inner and outer in MSIE and Opera and Chrome just does not work!
    {
      sysheight = OpenWin.outerHeight-OpenWin.innerHeight;
      syswidth = OpenWin.outerWidth-OpenWin.innerWidth;
    }
    if (!sysheight || sysheight<=0) // ok we have failed, finally do it based on what we think we know about the browsers
    {
      if (browser.value=="M" && vsn>=7)
        sysheight = barheight*3 + sysborder*2; // ie7 or 8 
      else if (browser.value=="C")
        sysheight = 40 + sysborder*2; // Chrome's default bar height is 40 not 32
      else
        sysheight = barheight*2 + sysborder*2;
      syswidth = sysborder*2;
    }
  }

  xmax = screen.availWidth - syswidth - tablesurround - hspacing; // 2 window borders
  ymax = screen.availHeight - sysheight - tablesurround - vspacing - vtextcell; // -HeaderBar-StatusBar (assume all browsers have them)

  if (w>xmax || h>ymax) // too big, needs shrinking
  {
    if (w/xmax > h/ymax)
    {
      // the width is the deciding factor
      h = parseInt((h*xmax) / w);
      w = xmax;
    }
    else
    {
      // the height is the deciding factor
      w = parseInt((w*ymax) / h);
      h = ymax;
    }
  }
  
  htable = w+hspacing-vscrollbar;
  vtable = h+vspacing+vtextcell;
  hwindow = htable+tablesurround+vscrollbar;
  vwindow = vtable+tablesurround;

  if (OpenWin && browser.value=="K")
  {
    OpenWin.close();
    OpenWin = null;
  }
  OpenWin = window.open("", "PicWin", "height="+vwindow+", width="+hwindow+", toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes, status=no, directories=no, copyhistory=no, channelmode=no");
  
  OpenWin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
  OpenWin.document.writeln('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  OpenWin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">');
  OpenWin.document.writeln('<head><title>'+title+'</title>');

  if (css.length>0)
    OpenWin.document.writeln('<link rel="stylesheet" href="'+css+'">');
  else
  {
    OpenWin.document.writeln('<style TYPE="text/css">');
    OpenWin.document.writeln('<!--');
    OpenWin.document.writeln('.homePage    { font-family: Georgia, \'Palatino Linotype\', Palatino, \'Times New Roman\', Times, serif; font-style: normal; font-weight: 500 }');
    OpenWin.document.writeln('.pagebody    { background-color: rgb(231, 225, 205); color: rgb(0, 0, 0) }');
    OpenWin.document.writeln('.photoborder { border-style: solid; border-color: rgb(125, 189, 134) rgb(0, 102, 0) rgb(0, 102, 0) rgb(125, 189, 134) }');
    OpenWin.document.writeln('a:link       { color: #993300 }');
    OpenWin.document.writeln('a:visited    { color: #993300 }');
    OpenWin.document.writeln('a:active     { color: #993300 }');
    OpenWin.document.writeln('body         { background-color: rgb(0, 102, 0); color: rgb(0, 0, 0) }');
    OpenWin.document.writeln('body         { font-family: Georgia, \'Palatino Linotype\', Palatino, \'Times New Roman\', Times, serif; font-style: normal }');
    OpenWin.document.writeln('table        { table-border-color-light: rgb(255, 255, 204); table-border-color-dark: rgb(0, 102, 0) }');
    OpenWin.document.writeln('-->');
    OpenWin.document.writeln('</style>'); 
  }
  OpenWin.document.writeln('</head><body class="pagebody">');
  OpenWin.document.writeln('<table class="photoborder" frame="border" rules="all" border="'+border+'" cellpadding="0" cellspacing="'+cellspacing+'" width="'+htable+'px" height="'+vtable+'px" align="center" valign="middle">');
  OpenWin.document.writeln('<tr><td align="center"><img  width="'+w+'px" height="'+h+'px" src="'+pic+'">');
  OpenWin.document.writeln('</td></tr>');
  if (vcells==2)
  {
    OpenWin.document.writeln('<tr><td align="center">');
    //OpenWin.document.writeln(syswidth+browser.value+sysheight+'OH='+OpenWin.outerHeight+' IH='+OpenWin.innerHeight+' OW='+OpenWin.outerWidth+' IW='+OpenWin.innerWidth+' AW='+screen.availWidth+' AH='+screen.availHeight);
    OpenWin.document.writeln(caption);
    OpenWin.document.writeln('</td></tr>');
  }
  OpenWin.document.writeln('</table>');
  OpenWin.document.writeln('</body></html>');
  OpenWin.document.close();

  // now, just in case the window was already open, the open above did not set a new size, so do it here
  // note that resize takes the outer dimensions of the window, so include borders and title/status/etc bars
  OpenWin.resizeTo(hwindow+syswidth,vwindow+sysheight); // Plus the chrome

  OpenWin.focus();
}

//** All Levels Navigational Menu- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//** Script Download/ instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
//** Usage Terms: http://www.dynamicdrive.com/notice.htm

//** Current version: 2.2 See changelog.txt for details

if (typeof dd_domreadycheck=="undefined") //global variable to detect if DOM is ready
	var dd_domreadycheck=false

var ddlevelsmenu={

enableshim: true, //enable IFRAME shim to prevent drop down menus from being hidden below SELECT or FLASH elements? (tip: disable if not in use, for efficiency)

arrowpointers:{
	downarrow: ["/images/arrow-down.gif", 11,7], //[path_to_down_arrow, arrowwidth, arrowheight]
	rightarrow: ["/images/arrow-right.gif", 12,12], //[path_to_right_arrow, arrowwidth, arrowheight]
	showarrow: {toplevel: true, sublevel: true} //Show arrow images on top level items and sub level items, respectively?
},
hideinterval: 1000, //delay in milliseconds before entire menu disappears onmouseout.
effects: {enableswipe: true, enablefade: true, duration: 200},
httpsiframesrc: "blank.htm", //If menu is run on a secure (https) page, the IFRAME shim feature used by the script should point to an *blank* page *within* the secure area to prevent an IE security prompt. Specify full URL to that page on your server (leave as is if not applicable).

///No need to edit beyond here////////////////////

topmenuids: [], //array containing ids of all the primary menus on the page
topitems: {}, //object array containing all top menu item links
subuls: {}, //object array containing all ULs
lastactivesubul: {}, //object object containing info for last mouse out menu item's UL
topitemsindex: -1,
ulindex: -1,
hidetimers: {}, //object array timer
shimadded: false,
nonFF: !/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent), //detect non FF browsers
getoffset:function(what, offsettype){
	return (what.offsetParent)? what[offsettype]+this.getoffset(what.offsetParent, offsettype) : what[offsettype]
},

getoffsetof:function(el){
	el._offsets={left:this.getoffset(el, "offsetLeft"), top:this.getoffset(el, "offsetTop")}
},

getwindowsize:function(){
	this.docwidth=window.innerWidth? window.innerWidth-10 : this.standardbody.clientWidth-10
	this.docheight=window.innerHeight? window.innerHeight-15 : this.standardbody.clientHeight-18
},

gettopitemsdimensions:function(){
	for (var m=0; m<this.topmenuids.length; m++){
		var topmenuid=this.topmenuids[m]
		for (var i=0; i<this.topitems[topmenuid].length; i++){
			var header=this.topitems[topmenuid][i]
			var submenu=document.getElementById(header.getAttribute('rel'))
			header._dimensions={w:header.offsetWidth, h:header.offsetHeight, submenuw:submenu.offsetWidth, submenuh:submenu.offsetHeight}
		}
	}
},

isContained:function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
},

addpointer:function(target, imgclass, imginfo, BeforeorAfter){
	var pointer=document.createElement("img")
	pointer.src=imginfo[0]
	pointer.style.width=imginfo[1]+"px"
	pointer.style.height=imginfo[2]+"px"
	if(imgclass=="rightarrowpointer"){
		pointer.style.left=target.offsetWidth-imginfo[2]-2+"px"
	}
	pointer.className=imgclass
	var target_firstEl=target.childNodes[target.firstChild.nodeType!=1? 1 : 0] //see if the first child element within A is a SPAN (found in sliding doors technique)
	if (target_firstEl && target_firstEl.tagName=="SPAN"){
		target=target_firstEl //arrow should be added inside this SPAN instead if found
	}
	if (BeforeorAfter=="before")
		target.insertBefore(pointer, target.firstChild)
	else
		target.appendChild(pointer)
},

css:function(el, targetclass, action){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	if (action=="check")
		return needle.test(el.className)
	else if (action=="remove")
		el.className=el.className.replace(needle, "")
	else if (action=="add" && !needle.test(el.className))
		el.className+=" "+targetclass
},

addshimmy:function(target){
	var shim=(!window.opera)? document.createElement("iframe") : document.createElement("div") //Opera 9.24 doesnt seem to support transparent IFRAMEs
	shim.className="ddiframeshim"
	shim.setAttribute("src", location.protocol=="https:"? this.httpsiframesrc : "about:blank")
	shim.setAttribute("frameborder", "0")
	target.appendChild(shim)
	try{
		shim.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
	}
	catch(e){}
	return shim
},

positionshim:function(header, submenu, dir, scrollX, scrollY){
	if (header._istoplevel){
		var scrollY=window.pageYOffset? window.pageYOffset : this.standardbody.scrollTop
		var topgap=header._offsets.top-scrollY
		var bottomgap=scrollY+this.docheight-header._offsets.top-header._dimensions.h
		if (topgap>0){
			this.shimmy.topshim.style.left=scrollX+"px"
			this.shimmy.topshim.style.top=scrollY+"px"
			this.shimmy.topshim.style.width="99%"
			this.shimmy.topshim.style.height=topgap+"px" //distance from top window edge to top of menu item
		}
		if (bottomgap>0){
			this.shimmy.bottomshim.style.left=scrollX+"px"
			this.shimmy.bottomshim.style.top=header._offsets.top + header._dimensions.h +"px"
			this.shimmy.bottomshim.style.width="99%"
			this.shimmy.bottomshim.style.height=bottomgap+"px" //distance from bottom of menu item to bottom window edge
		}
	}
},

hideshim:function(){
	this.shimmy.topshim.style.width=this.shimmy.bottomshim.style.width=0
	this.shimmy.topshim.style.height=this.shimmy.bottomshim.style.height=0
},


buildmenu:function(mainmenuid, header, submenu, submenupos, istoplevel, dir){
	header._master=mainmenuid //Indicate which top menu this header is associated with
	header._pos=submenupos //Indicate pos of sub menu this header is associated with
	header._istoplevel=istoplevel
	if (istoplevel){
		this.addEvent(header, function(e){
		ddlevelsmenu.hidemenu(ddlevelsmenu.subuls[this._master][parseInt(this._pos)])
		}, "click")
	}
	this.subuls[mainmenuid][submenupos]=submenu
	header._dimensions={w:header.offsetWidth, h:header.offsetHeight, submenuw:submenu.offsetWidth, submenuh:submenu.offsetHeight}
	this.getoffsetof(header)
	submenu.style.left=0
	submenu.style.top=0
	submenu.style.visibility="hidden"
	this.addEvent(header, function(e){ //mouseover event
		if (!ddlevelsmenu.isContained(this, e)){
			var submenu=ddlevelsmenu.subuls[this._master][parseInt(this._pos)]
			if (this._istoplevel){
				ddlevelsmenu.css(this, "selected", "add")
			clearTimeout(ddlevelsmenu.hidetimers[this._master][this._pos])
			}
			ddlevelsmenu.getoffsetof(header)
			var scrollX=window.pageXOffset? window.pageXOffset : ddlevelsmenu.standardbody.scrollLeft
			var scrollY=window.pageYOffset? window.pageYOffset : ddlevelsmenu.standardbody.scrollTop
			var submenurightedge=this._offsets.left + this._dimensions.submenuw + (this._istoplevel && dir=="topbar"? 0 : this._dimensions.w)
			var submenubottomedge=this._offsets.top + this._dimensions.submenuh
			//Sub menu starting left position
			var menuleft=(this._istoplevel? this._offsets.left + (dir=="sidebar"? this._dimensions.w : 0) : this._dimensions.w)
			if (submenurightedge-scrollX>ddlevelsmenu.docwidth){
				menuleft+= -this._dimensions.submenuw + (this._istoplevel && dir=="topbar" ? this._dimensions.w : -this._dimensions.w)
			}
			submenu.style.left=menuleft+"px"
			//Sub menu starting top position
			var menutop=(this._istoplevel? this._offsets.top + (dir=="sidebar"? 0 : this._dimensions.h) : this.offsetTop)
			if (submenubottomedge-scrollY>ddlevelsmenu.docheight){ //no room downwards?
				if (this._dimensions.submenuh<this._offsets.top+(dir=="sidebar"? this._dimensions.h : 0)-scrollY){ //move up?
					menutop+= - this._dimensions.submenuh + (this._istoplevel && dir=="topbar"? -this._dimensions.h : this._dimensions.h)
				}
				else{ //top of window edge
					menutop+= -(this._offsets.top-scrollY) + (this._istoplevel && dir=="topbar"? -this._dimensions.h : 0)
				}
			}
			submenu.style.top=menutop+"px"
			if (ddlevelsmenu.enableshim && (ddlevelsmenu.effects.enableswipe==false || ddlevelsmenu.nonFF)){ //apply shim immediately only if animation is turned off, or if on, in non FF2.x browsers
				ddlevelsmenu.positionshim(header, submenu, dir, scrollX, scrollY)
			}
			else{
				submenu.FFscrollInfo={x:scrollX, y:scrollY}
			}
			ddlevelsmenu.showmenu(header, submenu, dir)
		}
	}, "mouseover")
	this.addEvent(header, function(e){ //mouseout event
		var submenu=ddlevelsmenu.subuls[this._master][parseInt(this._pos)]
		if (this._istoplevel){
			if (!ddlevelsmenu.isContained(this, e) && !ddlevelsmenu.isContained(submenu, e)) //hide drop down ul if mouse moves out of menu bar item but not into drop down ul itself
				ddlevelsmenu.hidemenu(submenu)
		}
		else if (!this._istoplevel && !ddlevelsmenu.isContained(this, e)){
			ddlevelsmenu.hidemenu(submenu)
		}

	}, "mouseout")
},

setopacity:function(el, value){
	el.style.opacity=value
	if (typeof el.style.opacity!="string"){ //if it's not a string (ie: number instead), it means property not supported
		el.style.MozOpacity=value
		if (el.filters){
			el.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+ value*100 +")"
		}
	}
},

showmenu:function(header, submenu, dir){
	if (this.effects.enableswipe || this.effects.enablefade){
		if (this.effects.enableswipe){
			var endpoint=(header._istoplevel && dir=="topbar")? header._dimensions.submenuh : header._dimensions.submenuw
			submenu.style.width=submenu.style.height=0
			submenu.style.overflow="hidden"
		}
		if (this.effects.enablefade){
			this.setopacity(submenu, 0) //set opacity to 0 so menu appears hidden initially
		}
		submenu._curanimatedegree=0
		submenu.style.visibility="visible"
		clearInterval(submenu._animatetimer)
		submenu._starttime=new Date().getTime() //get time just before animation is run
		submenu._animatetimer=setInterval(function(){ddlevelsmenu.revealmenu(header, submenu, endpoint, dir)}, 10)
	}
	else{
		submenu.style.visibility="visible"
	}
},

revealmenu:function(header, submenu, endpoint, dir){
	var elapsed=new Date().getTime()-submenu._starttime //get time animation has run
	if (elapsed<this.effects.duration){
		if (this.effects.enableswipe){
			if (submenu._curanimatedegree==0){ //reset either width or height of sub menu to "auto" when animation begins
				submenu.style[header._istoplevel && dir=="topbar"? "width" : "height"]="auto"
			}
			submenu.style[header._istoplevel && dir=="topbar"? "height" : "width"]=(submenu._curanimatedegree*endpoint)+"px"
		}
		if (this.effects.enablefade){
			this.setopacity(submenu, submenu._curanimatedegree)
		}
	}
	else{
		clearInterval(submenu._animatetimer)
		if (this.effects.enableswipe){
			submenu.style.width="auto"
			submenu.style.height="auto"
			submenu.style.overflow="visible"
		}
		if (this.effects.enablefade){
			this.setopacity(submenu, 1)
			submenu.style.filter=""
		}
		if (this.enableshim && submenu.FFscrollInfo) //if this is FF browser (meaning shim hasn't been applied yet
			this.positionshim(header, submenu, dir, submenu.FFscrollInfo.x, submenu.FFscrollInfo.y)
	}
	submenu._curanimatedegree=(1-Math.cos((elapsed/this.effects.duration)*Math.PI)) / 2
},

hidemenu:function(submenu){
	if (typeof submenu._pos!="undefined"){ //if submenu is outermost UL drop down menu
		this.css(this.topitems[submenu._master][parseInt(submenu._pos)], "selected", "remove")
		if (this.enableshim)
			this.hideshim()
	}
	clearInterval(submenu._animatetimer)
	submenu.style.left=0
	submenu.style.top="-1000px"
	submenu.style.visibility="hidden"
},


addEvent:function(target, functionref, tasktype) {
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

domready:function(functionref){ //based on code from the jQuery library
	if (dd_domreadycheck){
		functionref()
		return
	}
	// Mozilla, Opera and webkit nightlies currently support this event
	if (document.addEventListener) {
		// Use the handy event callback
		document.addEventListener("DOMContentLoaded", function(){
			document.removeEventListener("DOMContentLoaded", arguments.callee, false )
			functionref();
			dd_domreadycheck=true
		}, false )
	}
	else if (document.attachEvent){
		// If IE and not an iframe
		// continually check to see if the document is ready
		if ( document.documentElement.doScroll && window == window.top) (function(){
			if (dd_domreadycheck){
				functionref()
				return
			}
			try{
				// If IE is used, use the trick by Diego Perini
				// http://javascript.nwbox.com/IEContentLoaded/
				document.documentElement.doScroll("left")
			}catch(error){
				setTimeout( arguments.callee, 0)
				return;
			}
			//and execute any waiting functions
			functionref();
			dd_domreadycheck=true
		})();
	}
	if (document.attachEvent && parent.length>0) //account for page being in IFRAME, in which above doesn't fire in IE
		this.addEvent(window, function(){functionref()}, "load");
},


init:function(mainmenuid, dir){
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	this.topitemsindex=-1
	this.ulindex=-1
	this.topmenuids.push(mainmenuid)
	this.topitems[mainmenuid]=[] //declare array on object
	this.subuls[mainmenuid]=[] //declare array on object
	this.hidetimers[mainmenuid]=[] //declare hide entire menu timer
	if (this.enableshim && !this.shimadded){
		this.shimmy={}
		this.shimmy.topshim=this.addshimmy(document.body) //create top iframe shim obj
		this.shimmy.bottomshim=this.addshimmy(document.body) //create bottom iframe shim obj
		this.shimadded=true
	}
	var menubar=document.getElementById(mainmenuid)
	var alllinks=menubar.getElementsByTagName("a")
	this.getwindowsize()
	for (var i=0; i<alllinks.length; i++){
		if (alllinks[i].getAttribute('rel')){
			this.topitemsindex++
			this.ulindex++
			var menuitem=alllinks[i]
			this.topitems[mainmenuid][this.topitemsindex]=menuitem //store ref to main menu links
			var dropul=document.getElementById(menuitem.getAttribute('rel'))
			document.body.appendChild(dropul) //move main ULs to end of document
			dropul.style.zIndex=2000 //give drop down menus a high z-index
			dropul._master=mainmenuid  //Indicate which main menu this main UL is associated with
			dropul._pos=this.topitemsindex //Indicate which main menu item this main UL is associated with
			this.addEvent(dropul, function(){ddlevelsmenu.hidemenu(this)}, "click")
			var arrowclass=(dir=="sidebar")? "rightarrowpointer" : "downarrowpointer"
			var arrowpointer=(dir=="sidebar")? this.arrowpointers.rightarrow : this.arrowpointers.downarrow
			if (this.arrowpointers.showarrow.toplevel)
				this.addpointer(menuitem, arrowclass, arrowpointer, (dir=="sidebar")? "before" : "after")
			this.buildmenu(mainmenuid, menuitem, dropul, this.ulindex, true, dir) //build top level menu
			dropul.onmouseover=function(){
				clearTimeout(ddlevelsmenu.hidetimers[this._master][this._pos])
			}
			this.addEvent(dropul, function(e){ //hide menu if mouse moves out of main UL element into open space
				if (!ddlevelsmenu.isContained(this, e) && !ddlevelsmenu.isContained(ddlevelsmenu.topitems[this._master][parseInt(this._pos)], e)){
					var dropul=this
					if (ddlevelsmenu.enableshim)
						ddlevelsmenu.hideshim()
					ddlevelsmenu.hidetimers[this._master][this._pos]=setTimeout(function(){
						ddlevelsmenu.hidemenu(dropul)
					}, ddlevelsmenu.hideinterval)
				}
			}, "mouseout")
			var subuls=dropul.getElementsByTagName("ul")
			for (var c=0; c<subuls.length; c++){
				this.ulindex++
				var parentli=subuls[c].parentNode
				if (this.arrowpointers.showarrow.sublevel)
					this.addpointer(parentli.getElementsByTagName("a")[0], "rightarrowpointer", this.arrowpointers.rightarrow, "before")
				this.buildmenu(mainmenuid, parentli, subuls[c], this.ulindex, false, dir) //build sub level menus
			}
		}
	} //end for loop
	this.addEvent(window, function(){ddlevelsmenu.getwindowsize(); ddlevelsmenu.gettopitemsdimensions()}, "resize")
},

setup:function(mainmenuid, dir){
  writeCookie("Cookies","",0);
  this.domready(function(){ddlevelsmenu.init(mainmenuid, dir)})
}

}

//-->
//</script>
