var nn4=(document.layers)? true:false;
var ie4=(document.all)? true:false;

var basketPopup=null;

if (nn4) {
  window.captureEvents(Event.RESIZE);
  window.onresize = resize;
}

function resize(e) {
    window.location.reload();
    return false;
}

function findLayer(layerName) {
  if (ie4) {
    if (document.all[layerName].style)
      return document.all[layerName].style;
    else
      return "";
  }
  if (nn4)
    return findNNlayer(layerName, document);
}

function findNNlayer(layerName, currLayer) {
  var found="";
  if (currLayer.layers[layerName])
    return currLayer.layers[layerName];
  else {
    for (var i=0; i<currLayer.layers.length; ++i) {
      found = findNNlayer(layerName, currLayer.layers[i]);
      if (found)
	return found;
    }
    return found;
  } 
}

function showLayer(currLayer) {findLayer(currLayer).visibility=(nn4)?"show":"visible";}
function hideLayer(currLayer) {findLayer(currLayer).visibility=(nn4)?"hide":"hidden";}
function raiseLayer(currLayer) {findLayer(currLayer).zIndex=2;}
function lowerLayer(currLayer) {findLayer(currLayer).zIndex=0;}

function writeLayer(currLayer, content) {
  if (ie4) {
    eval("document.all."+currLayer).innerHTML = content;
  }
  if (nn4) {
    lay=findNNlayer(currLayer, document);
    lay.document.write(content);
    lay.document.close();
  }
}

function mouseOnImage(imageName) {document.images[imageName].src = eval(imageName+"_on.src");} 
function mouseOffImage(imageName) {document.images[imageName].src = eval(imageName+"_off.src");} 

function showBasket(name)
{
  basketPopup=window.open(name, 'basketPopup', 'scrollbars=yes,resize=yes,width=600,height=350');
  window.basketPopup.focus();
}

function popupSmall(p_page)
{
  smallPopup=open(p_page, "popupSmall", "toolbar=no,width=300,height=200,left=275,top=200,directories=no,status=no,scrollbars=auto,resize=no,menubar=no","false");
  if (window.smallPopup && !window.smallPopup.closed)
    window.smallPopup.focus();
}

function popupMedium(p_page, p_width, p_height)
{
  popup=open(p_page, "popupMedium", "toolbar=no,width="+p_width+",height="+p_height+",left=275,top=200,directories=no,status=no,scrollbars=yes,resize=no,menubar=no","false");
  if (window.popup && !window.popup.closed)
    window.popup.focus()
}


//Define CLASS ValidateAttr

//METHOD validate
function validate(title, formElement)
{
  if (window.RegExp) {  //does this version of JS support RegExp
    if (!this.regex.test(formElement.value)) {
      alert(title+":\n\n"+this.message+"\n\n");
      formElement.focus();
      return false ;
    }
  }
}

//CONSTRUCTOR
function ValidateAttr(regex, message)
{
  this.regex=regex;
  this.message=message;
  this.validate=validate;
}

var validName = new ValidateAttr(new RegExp("^[a-z ']*$","gi"), "Only letters, spaces and apostrophies allowed");
var validHouse = new ValidateAttr(new RegExp("^[a-z0-9 ',.()]*$","gi"), "Only letters, numbers, spaces and the characters  . , ' ( )  allowed");
var validAddress = new ValidateAttr(new RegExp("^[a-z ',.]*$","gi"), "Only letters, spaces and the characters  . , '  allowed");
var validPostcode = new ValidateAttr(new RegExp("^[a-z0-9 ]*$","gi"), "Only letters, numbers and spaces allowed");
var validNumber = new ValidateAttr(new RegExp("^[0-9 +()]*$","gi"), "Only numbers, spaces and the characters  + ( )  allowed");
var validEmail = new ValidateAttr(new RegExp("^([-a-z0-9]+(\.[-a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)+)*$","gi"), "Only valid email addresses allowed");

function confirmPassword(password, confirm)
{
  if (password.value != confirm.value) {
    alert("Passwords do not match.\nPlease try again.\n\n");
    confirm.focus();
    return false;
  }
}


/*
Pop up information box II
By Mike McGrath (mike_mcgrath@lineone.net,  http://website.lineone.net/~mike_mcgrath)
Permission granted to Dynamicdrive.com to feature script in archive
For full source code and installation instructions to this script, visit http://dynamicdrive.com
*/



function pop(msg,bak) 
{

var content ="<TABLE WIDTH=130 BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=#336633><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><CENTER><FONT FACE=TAHOMA COLOR=#FFFFFF SIZE=1><B>Miss Matty says...</B></FONT></CENTER></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+bak+"><TR><TD><FONT FACE=TAHOMA COLOR=#000000 SIZE=1><CENTER>"+msg+"</CENTER></FONT></TD></TR></TABLE></TD></TR></TABLE>";

  if (nav) 
  { 
    skn.document.write(content); 
	  skn.document.close();
	  skn.visibility = "visible";
  }
    else if (iex) 
  {
	  document.all("topdeck").innerHTML = content;
	  skn.visibility = "visible";  
  }
}

function get_mouse(e) 
{
	var x = (nav) ? e.pageX : event.x+document.body.scrollLeft; 
	var y = (nav) ? e.pageY : event.y+document.body.scrollTop;
	skn.left = x - 60;
  skn.top  = y+20;
}

function kill() 
{
  skn.visibility = "hidden";
}


function checkForm(form)
{
  if (form.elements['quantity'].value >0) {
    showBasket('');
    return true;
  }
  else {
    form.elements['quantity'].value = 1;
    return false;
  }
}

function submitItem(form, itemID)
{
  form.elements['id'].value = itemID;
  form.elements['quantity'].value = form.elements['quantityFor'+itemID].value;
  if (form.elements['quantity'].value >0) {
   // showBasket('');
    form.submit();
  }
  else
    form.elements['quantityFor'+itemID].value = 1;
}
