// JavaScript Document

var defaultSearchField = "Enter Search Term";
var maxtikestabs = 0;
var imgArray = new Array(); 
var imgCounter = 0;
var originalUrl = "";


'';

// copy the value of one field to another
function copyit(name) {
	oldfm = document.getElementById("c"+name);
	newfm = document.getElementById("d"+name);
	if ((oldfm)&&(newfm)) newfm.value=oldfm.value;
}

// Copy fields
function copyFormFields() {
	country = document.getElementById("ccountry");
	if (!country) return; else if (country.selectedIndex>0) {
		alert("Sorry we cannot deliver to your address, we only deliver to the UK mainland.");
		return;
	}

	copyit('name');
	copyit('address1');
	copyit('address2');
	copyit('city');
	copyit('postcode');
	copyit('tel');
}


// Nasty, but efficiant
function fixSubmit(form,field,value) {
	src = document.getElementById(field);
	if (src) src.value = value;
	src = document.getElementById(form);
	if (src) src.submit();
}

// valid string
function validstring(s) {	
	var txt = s+"";  // ensure a string
	var s2 = "";
	for (var a=0; a<txt.length; a++) if (txt.charAt(a)!=" ") s2+=txt.charAt(a);
	return (s2.length>1);
}

// checks if pc is a valid email address
function validemail(pc) {	
	var txt=pc+" ";
	var a = txt.indexOf("@");
	if (a<1) return false;
	txt = txt.substr(a+1,(txt.length-a)-1);
	a = txt.indexOf(".");
	if (a<1) return false;
	if (a>=txt.length-2) return false;
	return true;
}

// make image go large
function showImage(number) {
	img = document.getElementById("largeImage");
	if (img) img.src = imgArray[number].src;
}

// Restore image
function restoreImage() {
	img = document.getElementById("largeImage");
	if (img) img.src = originalUrl;
}

// Add an image
function addImage(largeUrl) {
	imgArray[imgCounter] = new Image();
	imgArray[imgCounter].src = largeUrl;
	imgCounter++;
}

// Sort thing
function changeSortMethod(urlBase) {
	field = document.getElementById("sortmodebox");
	if (field) 
		if (field.selectedIndex)
			document.location.href = urlBase + field.selectedIndex;
}

// On box enter, reset the search box
function searchFocus() {
	field = document.getElementById("searchbox");
	if (field) 
		if (field.value==defaultSearchField) field.value="";
}


// On box exit, restore the search box
function searchBlur() {
	field = document.getElementById("searchbox");
	if (field) 
		if (field.value=="") field.value=defaultSearchField;
}

// Submit search
function submitSearch() {
	field = document.getElementById("searchbox");
	if (field) 
		if ((!validstring(field.value)) || (field.value==defaultSearchField)) {
			alert("Please type in something to search for before clicking Go!");
			return false;
		}
	return true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// Onload, prepare the roll-overs
function prepareOnload() {
	MM_preloadImages('images/layout/layout-navigation-comp-ov.jpg','images/layout/layout-navigation-store-ov.jpg','images/layout/layout-navigation-about-ov.jpg');
}

// Check competition entry
function checkEntry(frm) {
	err="";
	field = document.getElementById("name"+frm);
	if (field) if (!validstring(field.value)) err+="Please enter your name\r\n";
	field = document.getElementById("email"+frm);
	if (field) if (!validemail(field.value)) err+="Please enter/correct your friends email address\r\n";
	field = document.getElementById("check"+frm);
	if (field) if (!field.checked) err+="Please agree to the terms and conditions\r\n";
	
	if (err.length>0) {
		alert("Before you can enter this competition, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;
}

// Check tell a friend is completed properly
function checkFriends() {
	err="";
	field = document.getElementById("yourname");
	if (field) if (!validstring(field.value)) err+="Please enter your name\r\n";
	field = document.getElementById("friendname");
	if (field) if (!validstring(field.value)) err+="Please enter your friends name\r\n";
	field = document.getElementById("friendemail");
	if (field) if (!validemail(field.value)) err+="Please enter/correct your friends email address\r\n";
	
	if (err.length>0) {
		alert("Before you can submit this form, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;
}

// Subscribe
function testSubscribe() {
	err="";
	field = document.getElementById("yourname");
	if (field) if (!validstring(field.value)) err+="Please enter your name\r\n";
	field = document.getElementById("youremail");
	if (field) if (!validemail(field.value)) err+="Please enter/correct your email address\r\n";
	
	if (err.length>0) {
		alert("Before you can submit this form, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;	
}


// Cataloge Form
function checkCatForm() {
	err="";
	field = document.getElementById("firstname");
	if (field) if (!validstring(field.value)) err+="Please enter your forename\r\n";
	field = document.getElementById("lastname");
	if (field) if (!validstring(field.value)) err+="Please enter your surname\r\n";
	field = document.getElementById("address1");
	if (field) if (!validstring(field.value)) err+="Please enter your address\r\n";
	field = document.getElementById("postcode");
	if (field) if (!validstring(field.value)) err+="Please enter your postal code\r\n";
	
	if (err.length>0) {
		alert("Before you can submit this form, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;	
}

// Contact Form
function checkContactForm() {
	err="";
	field = document.getElementById("yourname");
	if (field) if (!validstring(field.value)) err+="Please enter your name\r\n";
	field = document.getElementById("youremail");
	if (field) if (!validemail(field.value)) err+="Please enter/correct your email address\r\n";
	field = document.getElementById("yourmessage");
	if (field) if (!validstring(field.value)) err+="Please enter a message\r\n";
	
	if (err.length>0) {
		alert("Before you can submit this form, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;	
}

// UnSubscribe
function testUnSubscribe() {
	err="";
	field = document.getElementById("youremail2");
	if (field) if (!validemail(field.value)) err+="Please enter/correct your email address\r\n";
	
	if (err.length>0) {
		alert("Before you can submit this form, please ensure the following is correct:\r\n\r\n"+err+"\r\n");
		return false;
	} else return true;	
}

// Display a tab
function chooseTab(visTab) {
	for (a=0; a<maxtikestabs; a++) {
		heading = document.getElementById("tab"+a);
		content = document.getElementById("box"+a);
		
		if ((heading)&&(content)) {
			if (a==visTab) {
				heading.className="layout-infoTab-Selected"; 
				content.style.position = "relative";
				content.style.visibility = "visible";
			} else {
				heading.className="layout-infoTab-unSelected";
				content.style.position = "absolute";
				content.style.visibility = "hidden";
			}
		}
	}
}



		