function sizeme(ref) {
  if (document.getElementById) {
  var itm = document.getElementById(ref);
    if (itm) {
      //if (screen.availWidth > 1300){
      //  if (itm.width > 400){
      //  itm.style.width = 400 + "px";
        //alert("HERE!400");
      //  }
      //}
     // else {
       //       if (screen.availWidth > 900){
          if (itm.width > 500)  {
          itm.style.width = 500 + "px";
          //alert("HERE!500");
  //        }
 //             }
 //             else {
 //         if (itm.width > 200)  {
 //         itm.style.width = 200 + "px";
          //alert("HERE!200");
  //        }
  //      }
	    }
    }
  }
}


// PAGE HEIGHT SCRIPT //


function setFooter() {
if (document.getElementById) {
var windowHeight = getWindowHeight();

if (windowHeight > 0) {
var contentHeight = (document.getElementById('centre').offsetHeight);
var container     = document.getElementById('container');
var rightBorder   = document.getElementById('outrb');
var leftBorder    = document.getElementById('outlb');
var rightPanel    = document.getElementById('rpanel');
var leftPanel     = document.getElementById('lpanel');

var panelHeight
var leftHeight    = (document.getElementById('lpanel').offsetHeight);
var rightHeight   = (document.getElementById('rpanel').offsetHeight);
if (document.getElementById('xtra')) {
var xtraContent = (document.getElementById('xtra').offsetHeight);
contentHeight = (contentHeight + xtraContent)-450;
}

if (document.getElementById('prix')) {
var prixContent = (document.getElementById('prix').offsetHeight);
contentHeight = (contentHeight + prixContent)
}

if (leftHeight > rightHeight) {
panelHeight = leftHeight;
}
else {
panelHeight = rightHeight;
}

if (panelHeight > contentHeight)  {
contentHeight = (panelHeight-140);
}

if (contentHeight > 400) {


if (navigator.appVersion.indexOf("MSIE") != -1) {

var isIE = true;

document.getElementById("content").style.height = (contentHeight+180)+'px';
rightBorder.style.height = (contentHeight+276)+'px';
leftBorder.style.height  = (contentHeight+276)+'px';
rightPanel.style.height  = (contentHeight+120)+'px';
leftPanel.style.height   = (contentHeight+120)+'px';
//alert("IE ContentHeight : " + contentHeight);
}
else {

document.getElementById("content").style.height = (contentHeight+180)+'px';
rightBorder.style.height = (contentHeight+276)+'px';
leftBorder.style.height  = (contentHeight+276)+'px';
rightPanel.style.height  = (contentHeight+120)+'px';
leftPanel.style.height   = (contentHeight+120)+'px';
//alert(contentHeight + "pxH" + prixContent);
}
}
else {
if (navigator.appVersion.indexOf("MSIE") != -1) {
document.getElementById("content").style.height = (600)+'px';
rightBorder.style.height = (696)+'px';
leftBorder.style.height  = (696)+'px';
rightPanel.style.height  = (600)+'px';
leftPanel.style.height   = (600)+'px';
//alert("IEIE")
}

else {
document.getElementById("content").style.height = (600)+'px';
rightBorder.style.height = (696)+'px';
leftBorder.style.height  = (696)+'px';
rightPanel.style.height  = (600)+'px';
leftPanel.style.height   = (600)+'px';
// alert("WH = " + windowHeight + "; CH = " + contentHeight);

//alert(contentHeight +  "px")
}
}
}


}
}

function getWindowHeight() {
var windowHeight = 0;
if (typeof(window.innerHeight)=="number") {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body && document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}

function getWindowWidth() {
var windowWidth = 0;
if (typeof(window.innerWidth)=="number") {
windowWidth=window.innerWidth;
}
else {
if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
}
else {
if (document.body && document.body.clientWidth) {
windowWidth=document.body.clientWidth;
}
}
}
return windowWidth;
}

// A partial fix for IE width issues
function setWidth() {

if (document.getElementById) {
var outrb = document.getElementById('outrb');
var centre = document.getElementById('centre');
var windowWidth = getWindowWidth();
if (navigator.appVersion.indexOf("MSIE") != -1) {
//if (windowWidth > 900) {
outrb.style.right = "0";
//}
if (windowWidth < 1000) {
var is = new Is();
if (centre && is.ie6 || is.ie7) {
centre.style.width = "40%";

}
}
}
}
}

//window.onload = function() {
//stayopen();
//setFooter();
//setWidth();
//sizeme('smart250');
//checkBrowser();


//function checkBrowser () {
//var is = new Is();
//if (is.ie6) {
//alert (is.ie6);
//}
//}
//window.onresize = function() {
//location.reload();
//setFooter();

//}


//  NAVI ROLLOVER SCRIPTS //

function overn(ref) {
var nav = document.getElementById(ref);
var anc = document.getElementById("anc_" + ref);
nav.style.backgroundImage="url(img/build/overButton.jpg)";
nav.style.color="red";
nav.style.cursor="pointer";
anc.style.color="red";
}

function downn(ref) {
var nav = document.getElementById(ref);
var anc = document.getElementById("anc_" + ref);
nav.style.backgroundImage="url(img/build/onButton.jpg)";
nav.style.color="white";
nav.style.cursor="pointer";
anc.style.color="white";
}

function outn(ref) {
var nav = document.getElementById(ref);
var anc = document.getElementById("anc_" + ref);
nav.style.backgroundImage="url(img/build/baseButton.jpg)";
nav.style.color="rgb(112,112,112)";
anc.style.color="rgb(112,112,112)";
}

// NAVIGATION SCRIPT //


function navi(el,j) {
var elem = document.getElementById(el);
elem.style.display="block";
elem.style.visibility="visible";
for(var c = 1;c < (j+1); c++) {
var elem2 = document.getElementById(el + "b" + c);
if (elem2) {
elem2.style.display="block";
elem2.style.visibility="visible";
}
}
setFooter();
}

function navig(el) {
var elem = document.getElementById(el);
elem.style.display="block";
elem.style.visibility="visible";
setFooter();
}

function clox(ref) {
var el = 1
while (el<30) {
if (el != ref) {
var eln = document.getElementById("a" + el + "");
if (eln) {
eln.style.display="none";
eln.style.visibility="hidden";
}
}
el++;
}

clos(ref);

setFooter();
}

function clos(ref) {
var el = 1;


for (var sl=1; sl<10; sl++) {
for (var rf=1;rf<5;rf++) {
var el3 = document.getElementById("a" + sl + "b" + rf + "");
if (el3 && sl != ref) {
el3.style.display="none";
el3.style.visibility="hidden";
}
}
}

while (el<30) {
if (el != ref) {
var eln = document.getElementById("n" + el + "");
var el2 = document.getElementById("a" + el + "");


if (el2 && el != ref) {
el2.style.display="none";
el2.style.visibility="hidden";
}
if (eln && el != ref) {
eln.style.display="none";
eln.style.visibility="hidden";
}
}
el++;
}
var sch = document.getElementById("cz");
if (sch) {
sch.style.display="none";
sch.style.visibility="hidden";
}

setFooter();

}

function ocz() {

var sch = document.getElementById("cz");
if (sch) {
sch.style.display="block";
sch.style.visibility="visible";
}

setFooter();

}


function openw(loc) {
window.open(loc,"_self");
}

function opennew(loc) {
window.open(loc,"_blank");
}

function openA(ref) {
var el = 1;
while (el<100) {
if (el != ref) {
var eln = document.getElementById("ans_" + el + "");
if (eln) {
eln.style.display="none";
eln.style.visibility="hidden";
}
}
el++;
}

var opn = document.getElementById("ans_" + ref + "");
if (opn) {
opn.style.display="block";
opn.style.visibility="visible";
}

setFooter();

}


/* Script to swop image [Caterstyle] */


function changeI(ig) {
var mi = document.getElementById("mainI");
mi.src = "img/products/" + ig + "";
}

/* */


function checkadd() {
var frm = document.billing;
if (frm.fname.value.length == 0) {
alert("Please enter your first name.");
    frm.fname.focus();
    frm.fname.select();
return false;
}
if (frm.surname.value.length == 0) {
alert("Please enter your last name.");
    frm.surname.focus();
    frm.surname.select();
return false;
}
if (frm.add1.value.length == 0) {
alert("Please enter an address.");
    frm.add1.focus();
    frm.add1.select();
return false;
}
if (frm.town.value.length == 0) {
alert("Please enter the city or town.");
    frm.town.focus();
    frm.town.select();
return false;
}
if (frm.pc.value.length == 0) {
alert("Please enter your zip or postcode.");
    frm.pc.focus();
    frm.pc.select();
return false;
}
if (frm.country.value == "") {
alert("Please select your country.");
    frm.country.focus();
    frm.country.select();
return false;
}
// check to see if the email is valid
if (!validEmail(frm.eml.value)) {
alert("We require a valid email address.");
    frm.eml.focus();
return false;
}

if (!frm.tc.checked){
alert("Please confirm you agree to our terms and conditions.");
    frm.tc.focus();
    frm.tc.select();
return false;
        }
if(!frm.deladd.checked){
if (confirm("You have not checked the box to confirm this is the delivery address.\n Click 'OK' to be directed to the delivery address page or 'Cancel' to confirm."))
return true;
else
return false;
  }

return true;
}



function checkdeladd() {
var frm = document.delivery;
if (frm.cname.value.length == 0) {
alert("Please enter a contact name.");
    frm.cname.focus();
    frm.cname.select();
return false;
}

if (frm.add1.value.length == 0) {
alert("Please enter an address.");
    frm.add1.focus();
    frm.add1.select();
return false;
}
if (frm.town.value.length == 0) {
alert("Please enter the city or town.");
    frm.town.focus();
    frm.town.select();
return false;
}
if (frm.pc.value.length == 0) {
alert("Please enter your zip or postcode.");
    frm.pc.focus();
    frm.pc.select();
return false;
}
if (frm.country.value == "") {
alert("Please select your country.");
    frm.country.focus();
    frm.country.select();
return false;
}

return true;
}

function testall() {
var frm = document.contact;
if (frm.cname.value.length == 0) {
alert("Please enter a contact name.");
    frm.cname.focus();
    frm.cname.select();
return false;
}

if (!validEmail(frm.eml.value)) {
alert("We require a valid email address.");
    frm.eml.focus();
return false;
}

if (frm.tel.value == "") {
alert("Please enter a contact telephone no..");
    frm.tel.focus();
    frm.tel.select();
return false;
}

if (frm.brochure.checked && frm.add1.value.length == 0) {
alert("Please enter an address.");
    frm.add1.focus();
    frm.add1.select();
return false;
}
if (frm.brochure.checked && frm.town.value.length == 0) {
alert("Please enter the city or town.");
    frm.town.focus();
    frm.town.select();
return false;
}
if (frm.brochure.checked && frm.pc.value.length == 0) {
alert("Please enter your zip or postcode.");
    frm.pc.focus();
    frm.pc.select();
return false;
}

return true;
}

function accinfo() {
var frm = document.account;

if (frm.accountname.value.length == 0) {
alert("Please enter an account.");
    frm.accountname.focus();
return false;
}

if (frm.cname.value.length == 0) {
alert("Please enter a contact name.");
    frm.cname.focus();
return false;
}

if (!validEmail(frm.eml.value)) {
alert("We require a valid email address.");
    frm.eml.focus();
return false;
}

if (frm.tel.value == "") {
alert("Please enter a contact telephone no..");
    frm.tel.focus();
return false;
}

return true;
}

function cardinfo() {
var frm = document.card;

if (frm.cname.value.length == 0) {
alert("Please enter a contact name.");
    frm.cname.focus();
return false;
}

if (!validEmail(frm.eml.value)) {
alert("We require a valid email address.");
    frm.eml.focus();
return false;
}

if (frm.tel.value == "") {
alert("Please enter a contact telephone no..");
    frm.tel.focus();
return false;
}

if (frm.add1.value == "") {
alert("We require a delivery address.");
    frm.add1.focus();
return false;
}

if (frm.pc.value == "") {
alert("Please enter a zip or postcode.");
    frm.pc.focus();
return false;
}

return true;
}


// EMail Checker

function validEmail(email) {
  invalidChars = " /:,;"

  if (email == "") {// cannot be empty
    return false;
  }
  for (i=0; i<invalidChars.length; i++) {  // does it contain any invalid characters?
    badChar = invalidChars.charAt(i)
    if (email.indexOf(badChar,0) > -1) {
      return false;
    }
  }
  atPos = email.indexOf("@",1)// there must be one "@" symbol
  if (atPos == -1) {
    return false;
  }
  if (email.indexOf("@",atPos+1) != -1) {  // and only one "@" symbol
    return false;
  }
  periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) {// and at least one "." after the "@"
    return false;
  }
  if (periodPos+3 > email.length) {// must be at least 2 characters after the "."
    return false;
  }
  return true;
}






function subcat(elem) {
var block = document.getElementById(elem);
for (j=1;j < 10;j++)
if (document.getElementById("sc" + j + "")) {
document.getElementById("sc" + j + "").style.display="none";
document.getElementById("sc" + j + "").style.visibility="hidden";
}
block.style.display="block";
block.style.visibility="visible";
}

function subx(elem) {
var block = document.getElementById(elem);

block.style.display="none";
block.style.visibility="hidden";
}

function Is() {
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) &&
(agent.indexOf('spoofer') == -1) &&
(agent.indexOf('compatible') == -1) &&
(agent.indexOf('opera') == -1) &&
(agent.indexOf('webtv') == -1) &&
(agent.indexOf('hotjava') == -1));
this.ns2 = (this.ns && (this.major == 2));
this.ns3 = (this.ns && (this.major == 3));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = ((agent.indexOf("msie") != -1) &&
(agent.indexOf("opera") == -1));
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 4") != -1));
this.ie5 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.") != -1) &&
(agent.indexOf("msie 5.5") == -1) &&
(agent.indexOf("mac") == -1));
this.iem5 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.") != -1) &&
(agent.indexOf("mac") != -1));
this.ie55 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.5") != -1));
this.ie6 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 6.") != -1));
this.ie7 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 7.") != -1));
this.nsdom = (this.ns4 || this.ns6);
this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
this.iedom = (this.ie4 || this.ie5dom || this.ie6);
this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
}



function enquire(ref) {
if (ref) {
location.replace("content.asp?pge=3&ref=" + ref + "");
}
}




function win(url) {
window.open(url,"_top");
}

function win2(url) {
window.open(url,"new");
}


function viewtxt(bx) {
var box = document.getElementById(bx);
box.style.visibility="visible";
}

function notxt(bx) {
var box = document.getElementById(bx);
box.style.visibility="hidden";
}

function wht(i,j) {
var isDOM = (document.getElementById ? true : false);
var isIE = ((document.all) ? true : false);
  if (isIE) {
var e1 = document.all["lne" + i + ""];
var e2 = document.all["lne" + j + ""];
 e1.src = "img/build/sqWht.png";
 e2.src = "img/build/sqWht.png";
   }
 if (isDOM) {
var imgA = document.getElementById("lne" + i + "");
var imgB = document.getElementById("lne" + j + "");
imgA.src = "img/build/sqWht.png";
imgB.src = "img/build/sqWht.png";
  }
}

function blk(i,j) {
 var isDOM = (document.getElementById ? true : false);
 var isIE = ((document.all) ? true : false);
if (isIE){
var e1 = document.all["lne" + i + ""];
var e2 = document.all["lne" + j + ""];
 e1.src = "img/build/sqBlk.png";
 e2.src = "img/build/sqBlk.png";

   }
if (isDOM) {
var imgA = document.getElementById("lne" + i + "");
var imgB = document.getElementById("lne" + j + "");
 imgA.src = "img/build/sqBlk.png";
 imgB.src = "img/build/sqBlk.png";
  }
}

function submenuOver(cat) {
for (var i=1;i<20;i++) {
if (document.getElementById("sc" + i)) {
document.getElementById("sc" + i).style.visibility="hidden";
document.getElementById("sc" + i).style.display="none";
}
}
var categ = document.getElementById("sc" + cat);
if (categ) {
categ.style.visibility="visible";
categ.style.display="block";
categ.focus();
}
}

function submenuOut(cat) {
var categ = document.getElementById("sc" + cat);
if (categ) {
categ.style.visibility="hidden";
categ.style.display="none";
}
}

function remove(ref) {
var msg = "Do you wish to remove this item from your basket?";
if (confirm(msg)) {
location.replace("xcart.asp?idc=" + ref + "");
	}
}

function skey(which) {
if (which == "a") {
var frm = document.searchKey.key;
}
else {
var frm = document.searchPro.prokey;
}

if (frm.value.length < 3 || frm.value == "Keyword Search" || frm.value == "Product Search") {
alert("Minimum of 3 characters required.")
frm.focus();
return false;
	}
return true;
}
