﻿// JScript File
function CheckEmail(address) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(address)){
	return (true)
	}
	return (false)
}

function CheckFormContactUs(form){
		if (form.name.value=='') {alert('Please fill in your first name'); form.name.focus(); return false}
		if (form.surname.value=='') {alert('Please fill in your surname'); form.surname.focus(); return false}
		if (form.email.value=='') {alert('Please fill in your email address'); form.email.focus(); return false}
		if (!CheckEmail(form.email.value)) {alert('Invalid email address'); form.email.focus(); return false}
		if (form.telephonenumber.value=='') {alert('Please fill in your contact telephone number'); form.telephonenumber.focus(); return false}
		if (form.wherehearedus.value=='') {alert('Please tell us how you found our website'); form.wherehearedus.focus(); return false}
		if (form.message.value=='') {alert('Please enter your message'); form.message.focus(); return false}
		return true;
}

function isNumberKey(evt)
   {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 32 && (charCode < 48 || charCode > 57))
            return false;

         return true;
   }






function popImage(imageURL,imageTitle){
	openPopup(imageURL,imageTitle);
}

function openPopup (imageURL, caption) {

/*
This routine creates a pop-up window, and ensures that it takes focus. It is 
intended to be called from an anchor tag. The new window will resize itself to 
the optimum size, so we make it as large as the largest required window to
overcome bugs in various manifestations of various browsers.
  
Author:   John Gardner
Written:  8th November 2003
Updated:  27th January 2004

Calling sequence: <a href="a.jpg" onClick="return openLargeImage('a.jpg','Caption');">

The first parameter is the URL of the image to be opened, and the second 
parameter is the caption for the image which is displayed in the window title
and in the alt property of the image tag.

Note that the calling sequence will simply open the image in the main window if
JavaScript isn't enabled.
  
*/

  // Constants - change these to suit your requirements Note that the defaultWidth
  // and defaultHeight variables should be set to more than your largest image to
  // overcome a bug in Mozilla (at least up to Firefox 0.9).

  var windowTop = 50;                // Top position of popup
  var windowLeft = 100                // Left position of popup
  var defaultWidth = 730;             // Default width (for browsers that cannot resize)
  var defaultHeight = 532;            // Default height (for browsers that cannot resize)
  var onLoseFocusExit = true;         // Set if window to exit when it loses focus
  var undefined;

  // Set up the window open options
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",scrollbars=yes,resizable"
  
  // Now write the HTML markup to the new window, ensuring that we insert the 
  // parameter URL of the image and the parameter description of the image in 
  // the right place.
  var myScript = "<html>\n" + 
    "<head>\n" + 
	"<title>" + caption + "\</title>\n" +
	"<link href=/css/style.css rel=StyleSheet type=text/css>\n" +     
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" + 
    "  var height = document.myimage.height;\n";
  
  // Netscape  
  if (navigator.appName.indexOf("Netscape") != -1) {  
    myScript = myScript +  "  window.innerHeight = height+30;\n  window.innerWidth = width+20;\n"
  }
   
  // Opera 
  else if (navigator.appName.indexOf("Opera") != -1) {
    myScript = myScript +  "  window.resizeTo (width+20, height+60);\n"
  }
  
  // Microsoft 
  else if (navigator.appName.indexOf("Microsoft") != -1) { 
    //alert(imageURL);
	var img = new Image();
	
	img.src = imageURL;
	//alert(img.src);
	var height = img.height;
	height = img.height;
	//alert(height);
	
	if (height<=500) {
		 myScript = myScript + "  window.resizeTo (width+50, height+75);\n" 
	 } else {
		 myScript = myScript + "  window.resizeTo (width+50, height+75);\n" 
	}
	
  }
  
  // Assume a frig factor for any other browsers
  else {
    myScript = myScript + "  window.resizeTo (width+20, height+30);\n"
  }
      
  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";
    
  // If the window is required to close when it loses focus.
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}
    
  myScript = myScript + "style=\"margin: 5px; padding-right: 5px; padding-bottom: 5px; margin-bottom: 5px;\">\n" +  
	"<p align=center>\n" + 
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\" style=\"border: solid 1px #3f3f3f\">\n" + 
    "</p></body>\n" +  "</html>\n";
        
  // Diagnostic - uncomment the next line if you wish to see the script generated.   
  //alert (myScript);
  
  // Create the popup window
  var imageWindow = window.open ("","",Options);
  //alert(myScript);
  imageWindow.document.write (myScript)
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
  return false;
  
}

function CheckSearchForm(form){
		if ((form.search.value=='') ||(form.search.value=='')) {alert('Please fill in search keywords'); form.search.focus(); return false}
		return true;
}


function CheckSearchNew(form){
		if (form.search.value==''){alert('Please fill in search keywords'); form.search.focus(); return false}
		return true;
}


function CheckRecipe(){
        if (document.getElementById('rc').value==''){alert('Please fill in search keywords');document.getElementById('rc').focus(); return false}
		return true;
}