

	function printThis()
	{
		if (window.print) window.print()
		void (null)
	}


	function setAction(action)
	{
		var el = document.getElementById('action');
		el.value = action;
	}


	function saveForm(URL)
	{
		var f = document.getElementById('f');
		var url = document.getElementById('url');

		url.value = URL;	// set the target URL into a hidden field
		f.submit();	// submit the form
	}


	function qtyCheck(element, stock)
	{
		if (element.value > stock)
		{
			var msg = "You are about to order more tyres than are in stock.\nThe remainder will be placed on backorder.";
			alert (msg);
		}

	}


	function stockWarning(code, name, dealer_user_id, number)
	{
		var URL = 'b2b-stockwarning.php?code=' + code + '&name=' + name + '&dealer_user_id=' + dealer_user_id + '&number=' + number;
		window.open(URL, 'stockwarn', 'status=no, resizable=yes, scrollbars=yes, width=400, height=475');
	}


	function locateDealer()
	{
		var URL = 'http://www.multimap.com/clients/places.cgi?client=toyo1&fitter=Y';
		window.open(URL, 'dealers', 'status=no, resizable=yes, scrollbars=yes, width=425, height=475');
	}


	function populateDealer(address)
	{
		var el = document.getElementById('dealeraddress');
		el.value = address;
	}


	function confirmCancellation(url)
	{
		var strMsg = 'Are you sure you want to cancel this order?';

		if (confirm(strMsg))
		{
			window.location = url;
		}
	}

	function confirmRemove(url)
	{
		if (confirm('Are you sure you want to remove this item?'))
		{
			window.location = url;  	
		}
	}
	
	function confirmEmpty()
	{
		return confirm('Are you sure you want to empty your shopping basket?');
	}


	function popPage(URL)
	{
		window.open(URL, 'page', 'status=no, resizable=yes, scrollbars=yes, width=425, height=475');
	}


	function validateSearch(form)
	{
		if (form.words.value == '') {
			alert ('Please enter some search words first');
			return false;
		}
		else {
			return true;
		}
	}


	function validateMembershipForm(form)
	{
		if (form.Firstname.value == '' || form.Surname.value == '' || form.Address.value == '' || form.Postcode.value == '' || form.Telephone.value == '' || form.Email.value == '')
		{
			alert ('Please complete all mandatory fields');
			return false;
		}
		else {

			var cbox = "Read Data Protection";
			if (form[cbox].checked == true)
			{
				return true;
			}
			else {
				alert ('Please confirm you have read the data protection statement by ticking the box');
				return false;
			}

		}

	}


	function popMap(id)
	{
		var URL = 'map.php?id=' + id;	// portfolio_id
		window.open(URL, 'map','status=yes,resizable=yes,scrollbars=yes,width=370,height=480');
	}


	function popImage(filename)
	{
		window.open('showimage.php?filename=' + filename, 'Image','status=yes,resizable=yes,scrollbars=yes,width=370,height=480');
	}


	function swapImage(imgId, imgNewSrc)
	{
		document.images[imgId].src = imgNewSrc;	// swaps the src of id to a new source
	}


	function print_win(url)
	{
		window.open(url,'print_window','status=yes,resizable=yes,scrollbars=yes,width=450,height=550');
	}

	function contact_win(url)
	{
		window.open(url,'contact_window','status=yes,resizable=yes,scrollbars=yes,width=475,height=550');
	}

	function print_this()
	{
		if (window.print) window.print()
		void (null)
	}
	
	function initArray()
	{
		for(i=0;i<initArray.arguments.length; i++)
		this[i] = initArray.arguments[i];
	}

	function getFullYear(d)
	{
		yr = d.getYear();
			if (yr < 1000)
			yr+=1900;
		return yr;
	} // ef


	function clock()
	{
		var isnMonths = new initArray("January","February","March","April","May","June","July","August","September","October","November","December");
		var isnDays = new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
		today = new Date();

		document.write(isnDays[today.getDay()] + " " + today.getDate() + " " + isnMonths[today.getMonth()] + " " + getFullYear(today));
	} //ef


	function check_email(form)
	{

		if (is_email(form.email.value)) {
			return true;
		}
		else {
			alert ('You must provide a valid email address');
			return false;
		}

	} // -- ef




	/* begin validation library */

	function is_email(str)
	{
		if (str.indexOf("@") == -1) {
		return false;
		} else {
		return true;
		}
	}


	function is_string(str, min_length, max_length)
	{
		if (str.length >= min_length && str.length <= max_length) {
		return true;
		} else {
		return false;
		}	
	}


	function checkOptions(form)
	{
	          for (var e = 0; e < form.elements.length; e++)
	          {
	               var el = form.elements[e];
	               if (el.type == 'radio')
	          {
	          var group = form[el.name];
	          var checked = false;
	          if (!group.length)
	               checked = el.checked;
	          else
	          for (var r = 0; r < group.length; r++)
	               if ((checked = group[r].checked))
	                    break;
	               if (!checked)
	               {
	                    alert('Please select options for this product');
	                    el.focus();
	                    return false;
	               }
	          }
	          else if (el.type == 'checkbox')
	          {
	               var group = form[el.name];
	               if (!group.length)
	                    checked = el.checked;
	               else
	                    for (var r = 0; r < group.length; r++)
	                         if ((checked = group[r].checked))
	                              break;
	                         if (!checked)
	                         {
	                              alert('Please select options for this product');
	                              el.focus();
	                              return false;
	                         }
	                    }
	               else
	               {
	                    if (el.value == "" || el.value == null || el.value == "")
	                    {
	                         alert('Please select options for this product');
	                         el.focus();
	                         return false;
	                    }
	               }
	
	     }
	     return true;
	} // ef