﻿function fCheckCode()
{
	var retValue;
	var frmItem = '02-040';
	var frmPrice = 95.70;
	var frmDescription = 'eXtreme Plastic Lockers ';
	var iHeight;
	var iLock;
	var iColour;
	var chosen = "";
	var len=document.frmAdd.height.length;
	for (i=0; i < len; i++) {
		if (document.frmAdd.height[i].checked) {
			chosen = document.frmAdd.height[i].value;
		}
	}
	iHeight = parseFloat(chosen) * 12;
	switch (chosen) {
		case '0':
			frmDescription += '450mm';
			break;
		case '1':
			frmDescription += '600mm';
			frmPrice = frmPrice + 15.95;
			break;
		case '2':
			frmDescription += '900mm';
			frmPrice = frmPrice + 34.80;
			break;
		default:
	}
	frmDescription += ' with ';
	len=document.frmAdd.lock.length;
	for (i=0; i < len; i++) {
		if (document.frmAdd.lock[i].checked) {
			chosen = document.frmAdd.lock[i].value;
		}
	}
	iLock = parseFloat(chosen) * 4;
	switch (chosen) {
		case '0':
			frmDescription += 'Camlock';
			break;
		case '1':
			frmDescription += 'Swivel Catch';
			break;
		case '2':
			frmDescription += 'Coin Return';
			frmPrice = frmPrice + 31.90;
			break;
		default:
	}
	frmDescription += ' in ';
	len=document.frmAdd.colour.length;
	for (i=0; i < len; i++) {
		if (document.frmAdd.colour[i].checked) {
			chosen = document.frmAdd.colour[i].value;
		}
	}
	iColour = parseFloat(chosen);
	switch (chosen) {
		case '0':
			frmDescription += 'Blue';
			break;
		case '1':
			frmDescription += 'Red';
			break;
		case '2':
			frmDescription += 'Yellow';
			break;
		case '3':
			frmDescription += 'Green';
			break;
		default:
	}
	retValue = iHeight + iLock + iColour;
	if (retValue < 10) {
		frmItem += '0' + retValue.toString();
	} else {
		frmItem += retValue.toString();
	}
	document.frmAdd.fItemCd.value = frmItem;
	document.frmAdd.fPrice.value = frmPrice;
	document.frmAdd.fItemNm.value = frmDescription;
}

function showTandC() {
	var tandc = document.getElementById("txtTandC");
	var btntandc = document.getElementById("btnViewTandC");
	if (tandc.style.display != "block") {
		tandc.style.display="block";
		btntandc.innerHTML="Hide Terms";
		btntandc.value="Hide Terms";
	} else {
		tandc.style.display="none";
		btntandc.innerHTML="View Terms";
		btntandc.value="View Terms";
	}
}

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_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_findObj(n, d) { //v3.0
  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); 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];}
}

function confirmDelete() {
	return confirm("Do you really want to remove\nthis item from your basket?");
}

function confirmDeleteAll() {
	return confirm("Do you really want to remove\nall of the items from your basket?");
}

function addNote (pCd, pNm, pOpt, pNt) {
	var boxW = 445;
	var boxH = 198;
	var leftPos=(((screen.availWidth-boxW)/2)+10);
	var topPos= (((screen.availHeight-boxH)/2)-10);
	var sFeatures="top=" + topPos + ",directories=no,height=" + boxH + ",left=" + leftPos + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=" + boxW + ",dependent=yes,alwaysRaised=yes,modal=yes,dialog=yes"

	var sURL
//	pNt='send it by royal mail';
	sURL = "inputbox.html?cd=" + escape(pCd) + "&nt=" + pNt;
	obj_noteWindow = window.open(sURL, "AddNote",sFeatures);

	obj_noteWindow.opener = window;
	document.getElementById("fItemCd").value = pCd;
	document.getElementById("fItemNm").value = pNm;
	document.getElementById("fOpt1").value = pOpt;
	if (window.focus) {obj_noteWindow.focus()}
	return false;
}

function validateEmail(addr,man,db) 
	{
	if (addr == '' && man) 
	{
	  if (db) alert('Please enter a valid email address');
	  return false;
	}
		                                
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|&';
		                                
	for (i=0; i<invalidChars.length; i++) 
	{
	  if (addr.indexOf(invalidChars.charAt(i),0) > -1) 
	  {
	    if (db) alert('Email address contains invalid characters');
	      return false;
	  }
	}
		                                
	for (i=0; i<addr.length; i++) 
	{
	  if (addr.charCodeAt(i)>127) 
	  {
	    if (db) alert("Email address contains non ascii characters.");
	      return false;
	  }
	}

	var atPos = addr.indexOf('@',0);
		                                
	if (atPos == -1) 
	{
	  if (db) alert('Email address must contain an @');
	    return false;
	}
	if (atPos == 0) 
	{
	  if (db) alert('Email address must not start with @');
	    return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) 
	{
	  if (db) alert('Email address must contain only one @');
	    return false;
	}

	if (addr.indexOf('.', atPos) == -1) 
	{
	  if (db) alert('Email address must contain a period in the domain name');
	    return false;
	}
	if (addr.indexOf('@.',0) != -1) 
	{
	  if (db) alert('Period must not immediately follow @ in email address');
	    return false;
	}
	if (addr.indexOf('.@',0) != -1)
	{
	  if (db) alert('Period must not immediately precede @ in email address');
	    return false;
	}
	if (addr.indexOf('..',0) != -1) 
	{
	  if (db) alert('Two periods must not be adjacent in email address');
	    return false;
	}

	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') 
	{
	  if (db) alert('Invalid primary domain in email address');
	    return false;
	}
	return true;
	}

function validateform() {
  var error = '';
  if (document.form1.fPaymentMthd.value == ''){
  error = 'Please select a payment method.';
  document.form1.fPaymentMthd.focus();
  }
  if (!validateEmail(document.form1.fEmail.value,1,0)){
  error = 'Please enter a valid email address';
  document.form1.fEmail.focus();
  }
  if (document.form1.fPhone.value == ''){
  error = 'Please enter your Telephone Number.';
  document.form1.fPhone.focus();
  }
  if (document.form1.fCity.value == ''){
  error = 'Please enter your Town/City.';
  document.form1.fCity.focus();
  }
  if (document.form1.fAddr1.value == ''){
  error = 'Please enter your Invoice Address.';
  document.form1.fAddr1.focus();
  }
  if (document.form1.fContactLastNm.value == ''){
  error = 'Please enter your Last Name.';
  document.form1.fContactLastNm.focus();
  }
  if (document.form1.fContactFirstNm.value == ''){
  error = 'Please enter your Contact First Name.';
  document.form1.fContactFirstNm.focus();
  }
  if (document.form1.fCompanyNm.value == ''){
  error = 'Please enter your Company Name.';
  document.form1.fCompanyNm.focus();
  }  
  if (document.form1.fPCode.value == ''){
  error = 'Please enter your Post Code.';
  document.form1.fPCode.focus();
  }
  if (error == '')
  { return true; }
  else
  {
  alert(error);
  return false;
  }
}
