<!--

//************ Start Default Commands ************
var h = "hidden";
var v = "visible";
var db = "block";
var dn = "none";
var graphic = "";   
var isNS4 = 0; var isIE4 = 0; var isNS6 = 0; var isNew = 0;
var docObj, styleObj, currObj, cstyleObj;

var bVer = (parseInt(navigator.appVersion));
var bName = navigator.appName;
var brow = ((navigator.appName) + (parseInt(navigator.appVersion)));

if (bName == "Netscape" && bVer >= 3) version = "js";
else if (bName == "Microsoft Internet Explorer" && bVer >= 4) version = "js";
else if (bName == "Netscape" && bVer == 2) version = "no";
else if (bName == "Microsoft Internet Explorer" && bVer >= 2) version = "no";

if (parseInt(navigator.appVersion >= 5)){isNew = 1}
else if (brow == "Netscape4") {isNS4 = 1;}
else if (brow == "Netscape5") {isNS6 = 1;}
else if (brow == "Microsoft Internet Explorer4") {isIE4 = 1;}
				
if (isNS4||isNS6||isIE4||isNew) {
  if(isNS4){ docObj = "document."; }
  else if(isNS6){ docObj = "document.getElementById('"; }
  else { docObj = "document.all."; }

  if(isNS4){ styleObj = ""; }
  else if(isNS6){ styleObj = "').style"; }
  else { styleObj = ".style"; }
  
  if(isNS4){ cstyleObj = ""; }
  else if(isNS6){ cstyleObj = "').currentStyle"; }
  else { cstyleObj = ".currentStyle"; }
}

function getQuery(val){
  var querystring = location.search.substring(1,location.search.length);
  var o = "";
  var tSec = querystring.indexOf(val+"=");
  var tStr = querystring.substring( (tSec+(val.length+1)),querystring.length);
  
  if(tSec != -1){
    if(tStr.indexOf('&') != -1){
      o = tStr.substring(0,tStr.indexOf('&'));
    } else {
      o = tStr;
    }
  }
  return o;
}

function replaceSubstring(s,f,w){
  rtn = "";
  flg = 0;
  
  for(i = 0; i < s.length; i++){
    if(s.substr(i,f.length) == f){
      rtn += w;
      i += (f.length - 1);
    } else {
      rtn += s.charAt(i);
    }
  }
  
  return (rtn);
}

function writeFlash(fName,bg,w,h){
  if( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= 4) ){
    document.write('<embed src="' + fName + '" quality="high" bgcolor="#' + bg + '" WIDTH="' + w + '" HEIGHT="' + h + '" NAME="header" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />');
  } else {
    document.write('<OBJECT data="' + fName + '" width="' + w + '" height="' + h + '" id="header" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" codetype="application/x-shockwave-flash">');
    document.write(' <PARAM NAME="movie" VALUE="' + fName + '" />');
    document.write(' <PARAM NAME="quality" VALUE="high" />');
    document.write(' <PARAM NAME="bgcolor" VALUE="#' + bg + '" />');
    document.write('<embed src="' + fName + '" quality="high" bgcolor="#' + bg + '" WIDTH="' + w + '" HEIGHT="' + h + '" NAME="header" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</OBJECT>');
  }
}

function openPopup(URL,id,width,height){
  window.open(URL, id, "toolbar=no,location=no,width="+width+",height="+height+",status=yes,scrollbars=yes,scrolling=yes,menubar=no,resizable=yes");
}

function openPopupLocked(URL,id,width,height){
  window.open(URL, id, "toolbar=no,location=no,width="+width+",height="+height+",status=yes,scrollbars=yes,scrolling=yes,menubar=no,resizable=no");
}

function goPage(u){
  location.href = u;
}

function layerChange(tmpLayer,tmpVisible) {
  if (isNS4||isNS6||isIE4||isNew) { eval(docObj + tmpLayer + styleObj + '.visibility = ' + tmpVisible) }
}

function displayChange(tmpLayer,tmpVisible) {
  if (isNS4||isNS6||isIE4||isNew) { eval(docObj + tmpLayer + styleObj + '.display = ' + tmpVisible) }
}

function rollover(graphic,state) {
  if(state==1){ if (version == "js") { document[graphic].src = "/graphics/" + graphic + "_dn.gif" } }
  if(state==0){ if (version == "js") { document[graphic].src = "/graphics/" + graphic + "_up.gif" } }
}

function imageover(graphic,filename) {
  if (version == "js") { document[graphic].src = "/graphics/" + filename }
}

function inputover(graphic,state) {
  if(state==1){ if (version == "js") { document.getElementById(graphic).src = "/graphics/" + graphic + "_dn.gif" } }
  if(state==0){ if (version == "js") { document.getElementById(graphic).src = "/graphics/" + graphic + "_up.gif" } }
}

function clearText(f,t,d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];
  var ele = doc.elements[f].value;

  if(ele == t){
    doc.elements[f].value = "";
  }
}

//************ Start Validation Functions ************
function setFocus(f,d){
  document.forms[d].elements[f].focus();
}

function testEmail(f,d){
  var a = document.forms[d].elements[f].value;
  var at = a.indexOf("@")
  var name = a.substring(0, at)
  var isp = a.substring(at + 1, a.length)
  var dot = a.lastIndexOf(".")

  if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (a.length - 1)) {
    alert('You must enter a valid email address');
    setFocus(f,d);
  } else {
    return true;
  }
}

function testText(f,t,c,d){
  if( (document.forms[d].elements[f].value != "") && (document.forms[d].elements[f].value != c) ){
    return true;
  } else {
    alert('You must enter ' + t);
    setFocus(f,d);
  }
}

function testSelect(f,t,d){
  var a = document.forms[d].elements[f];
  if( (a.selectedIndex >= 0) && (a.options[a.selectedIndex].value != "") ){
    return true;
  } else {
    alert('You must select a ' + t);
    setFocus(f,d);
  }
}

function testCheck(f,l,d){
  var a = document.forms[d].elements[f];
  var str = "";

  for(i = 0; i < a.length; i++){
    if(a[i].checked == true){
      str = "yes";
	break;
    } else {
      str = "no";
    }
  }

  if(str == "yes"){
    return true;
  } else {
    alert('You must select a ' + t);
  }
}

function getCheck(f,d){
  var a = document.forms[d].elements[f];
  var str = "";

  for(i = 0; i < a.length; i++){
    if(a[i].checked == true){
      return a[i].value;
    }
  }
}

function validate_signin(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testEmail('email',d) && testText('pass','your password','',d) ){
    doc.action.value = "signinuser";
    doc.submit();
  }
}

function validate_registration(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testText('name','your name','',d) && testText('address1','your address','',d) && testText('towncity','your town/city','',d) && testText('postcode','your post code','',d) && testEmail('email',d) && testText('password','a password','',d) ){
    doc.action.value = "saveregistration";
    doc.submit();
  }
}

function validate_basket(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testText('bil_firstname','your first name','',d) && testText('bil_lastname','your last name','',d) && testText('bil_address1','your address','',d) && testText('bil_address2','your address','',d) && testText('bil_postcode','your post code','',d) && testEmail('bil_emailaddress',d) ){
    doc.action.value = "sendpayment";
    doc.submit();
  }
}

function validate_competition(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testText('answer','your answer','',d) && testText('firstname','your first name','',d) && testText('lastname','your last name','',d) && testEmail('emailaddress',d) ){
    doc.action.value = "submitcompetition";
    doc.submit();
  }
}

function validate_comments(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testText('name','name','name',d) && testEmail('emailaddress',d) ){
    doc.action.value = "submitenquiry";
    doc.submit();
  }
}

function validate_survey(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  doc.action.value = "submitsurvey";
  doc.submit();
}

function validate_email_alerts(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testEmail('emailaddress',d) ){
    doc.action.value = "showcategories";
    doc.submit();
  }
}

function validate_email_alerts_categories(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testEmail('emailaddress',d) ){
    doc.action.value = "savecategories";
    doc.submit();
  }
}

function validate_email_alerts_remove(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if( testEmail('emailaddress',d) ){
    doc.action.value = "unsubscribeuser";
    doc.submit();
  }
}

//************ End Default Commands ************
function getIndexPos(s,n,a){
  return a;
}

function add_count(v,i,c,n){
  var doc = document.forms['fastfacts'];
  var ary = doc.avail_ary.value.split(',');
  var val = (c+v);

  for(j=0; j < ary.length; j++){
    if(ary[j] == val){
      val += 1;
    }
  }

  if(ary.length > 1){
    if(i==0){ var num = 1; } else { var num = (i+1); }
    var str1 = new String(ary.slice(0,num));
    var str2 = new String(ary.slice(num,ary.length));

    var new_ary = str1 + ("," + val + ",") + str2;
  } else {
    var new_ary = ary + "," + val;
  }

  if(new_ary.charAt(new_ary.length-1) == ","){
    new_ary = new_ary.substring(0,new_ary.length-1);
  }

  if(val > 0){
    doc.action.value = "add";
    doc.count.value = val;
    doc.selnum.value = (i+1);
    doc.avail_ary.value = new String(new_ary);
    doc.submit();
  }
}

function remove_count(v,c,n){
  var doc = document.forms['fastfacts'];
  var ary = doc.avail_ary.value.split(',');

  if((c-1) > 0){
    ary.splice(v,1);
    doc.action.value = "remove";
    doc.count.value = (c-1);
    doc.selnum.value = (ary.length-1);
    doc.avail_ary.value = new String(ary);
    doc.submit();
  }
}

function submitFastFacts(){
  var doc = document.forms['fastfacts'];
  doc.action.value = "fastfacts";
  doc.submit();
}

function sendFastFacts(){
  var doc = document.forms['fastfacts'];
  if( testText('name','name','name','fastfacts') && testEmail('emailaddress','fastfacts') ){
    doc.action.value = "sendfastfacts";
    doc.submit();
  }
}

function addFastFact(d){
  var doc = document.forms['fastfacts'];
  doc.action.value = "add";
  doc.titles_1.value = d;
  doc.count.value = "1";
  doc.selnum.value = "1";
  doc.avail_ary.value = "1";
  doc.submit();
}

function set_field_value(f,v){
  var doc = document.forms[0];

  if(doc.avail_ary.value != ""){
    var ary = doc.avail_ary.value.split(',');
    for(i=0; i < ary.length; i++){
      doc.elements['tables_' + ary[i]].selectedIndex = -1;
      doc.elements['fields_' + ary[i]].selectedIndex = -1;
      doc.elements['options_' + ary[i]].selectedIndex = -1;
      doc.elements['text_' + ary[i]].value = "";
      if(doc.elements['text_to_' + ary[i]]){ doc.elements['text_to_' + ary[i]].value = ""; }
      if(doc.elements['boolean_' + ary[i]]){ doc.elements['boolean_' + ary[i]].selectedIndex = -1; }
    }
    doc.avail_ary.value = "";
    doc.action.value = "";
  }

  doc.elements[f].value = v;
  doc.submit();
}

function update_greensaver(t,p){
  if(t.selectedIndex > 0){
    location.href = "/Pages/" + p + "/" + t.options[t.selectedIndex].value + ".html";
  } else {
    location.href = "/Pages/" + p + ".html";
  }
}

function submit_course_finder(){
  var doc = document.forms['course_finder'];
  var q = doc.postcode.value;
  
  if(q.length > 8 || q.length < 2){
    alert('Please enter a valid post code.');
  } else {
    if(q.indexOf(' ') != -1){
      var oc = q.substring(0,q.indexOf(' '));
      if(oc.length < 2 || oc.length > 4){
        alert('Please enter a valid post code.');
      } else {
        doc.outcode.value = oc;
        doc.submit();
      }
    } else {
      if(q.length > 4){
        var oc = q.substring(0,q.length-3);
      } else {
        oc = q;
      }
      doc.outcode.value = oc;
      doc.submit();
    }
  }
}

function moveDigitalBlock(n){
  if(document.getElementById('digital_block')){
    var obj = document.getElementById('digital_block');
    var xp = obj.style.marginLeft;
    if(xp == ""){ xp = 0; } else { xp = parseInt(xp); }

    obj.style.marginLeft = (xp + (n*1)) + "px";
  }
}

//-->