stopSearch = "no"; //initiate the stop search switch to no (will be switched on by pages that use a page based search such as Pt 1 docs search page)

function validate_search()
{

//alert("validating")


 if(stopSearch == "yes" && document.SearchForm.SearchScope.value != "/")
   {
   alert ("To search this area of the website - Please use the search options within the page below")
   return(false);
   }


 if( document.SearchForm.queryText.value == "")
   {
     return(false);
   }
 else
   {
     return(true);
   }
}

function toggleDiv(showHideDiv, switchTextDiv) 
{
	var ele = document.getElementById(showHideDiv);
	var text = document.getElementById(switchTextDiv);
	if(ele.style.display == "block") 
	{
    ele.style.display = "none";
		text.innerHTML = "See more dates ...";
  }
	else 
	{
		ele.style.display = "block";
		text.innerHTML = "Hide extra dates";
	}
}

function validate_checkbox(emailaddressValue, checkboxValue)
{
  if (checkboxValue == true && emailaddressValue == "")
  {
   alert ("Please enter your email address to use the send copy option")
   return(false);
  }
  else if(checkboxValue == true)
  {
    return validate(emailaddressValue)
  }

/*  else
  {
   return(true);
  }
  */
}

//document.email_enquiry.send_copy.value




function validate(address)  // (form_id,email)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) 
   {
      alert('Please enter a valid email address.');
      return false;
   }
   else
  {
    return true; 
  }
}







/*########## the following are date validation tools ##########*/

/*## function to check if a valid date has been selected from a (selection x3) DD/MM/YYYY drop down ##*/
/*## call format = dateValidate(nn,nn,nnnn) ##*/


 
  function dateValidate(testDay,testMonth,testYear,message)
  {
  var monthMaxNotLeap = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var monthMaxLeap = new Array(31,29,31,30,31,30,31,31,30,31,30,31);

  var monthMax = monthMaxNotLeap;

  for (i=2000; i<=testYear; i=i+4)
   {
     if (testYear == i)
     {
     monthMax = monthMaxLeap;
     }  
   }
  if (testDay > monthMax[testMonth-1])
    {
    alert(message) 
    return false; 
    }
  else
    { 
    return true;
    }
  }

    



/*## function to check if a date value has 2 characters or not, used to create DD/MM/YYYY format when the day or month is less that a value of 10 ##*/
/*## call format = digitAmountCheck(n) or digitAmountCheck(nn) ##*/

  function digitAmountCheck(dateVar)
  {
    if (dateVar < 10)
    {
    dateVar = "0"+dateVar;
    }
    return dateVar; 
  }



/*## function to allow user to confirm thier decision before redirected to another page such as a logout page##*/
/*## call format = confirmIt(url of page, confirm message to display)##*/

function confirmIt(newPage,message)
{
  if (confirm(message))
    {
    document.location.href=newPage;
    }
 }
 
 
 
 
 /*## function to allow user to confirm thier decision before carrying out an action such as deleting a database record##*/
/*## call format = actionOk(action warning message to confirm)##*/
 
 function actionOk (warnMessage)
 	{
 	if (confirm(warnMessage))
 		{
 		return true;
 		}
 		else
 		{
 		return false;
 		}
 	}
  


/*## generic to validate form fields: check a value against a supplied value ##*/
/*## call format = validateField(DOM path to form field,value to check,message if that value is present)##*/

function validateField(formField,valueToCheck,message)
{
  if (formField == valueToCheck)
    {
    alert(message);
    return false; 
    }
  else
    { 
    return true;
    }
}


/*## validate form field has all numbers as characters with option of nothing entered in field ##*/
/*## call format = validateFieldIsNum(DOM path to form field,input manditory or not("yes" or "no"),warn message)##*/
function validateFieldIsNum(formField,ifRequired,message)
{
var digitCheck="true";
	if (ifRequired=="no")
		{
		if (formField=="")
			{
			return true;
			}
	else
		{	
		 
	     for(i=0; i<formField.length; i++)
				{
				if (isNaN(formField.charAt(i)))
					{
	  				digitCheck="false";
				    }
				}
			}
		}
		
		if (digitCheck=="true") 
		{
		return true;	
		}	
		else
		{
		alert (message);
		return false;
		}
}


function toolTip (x,y,w,h,message,display)
{
if(document.form.help.checked==true)
{
  var oPopup = window.createPopup();
  oPopupBody = oPopup.document.body;
  oPopupBody.innerHTML =message;
  oPopupBody.style.backgroundColor = "#dddddd";
  oPopupBody.style.border = "1 solid black";
  oPopupBody.style.margin = "5px";
  oPopupBody.style.fontSize = "11px";
  oPopupBody.style.fontFamily = "arial";
if (display=="show")
  {
  oPopup.show(x,y,w,h)
  }
}
}



// opens new floating browser window from thumbnail image link syntax = openIt('relative path to image','a name for the new window','width, height and toolbar options for new window')  
function openIt(image,name,attributes)
{
window.name = "thiswin";
newwin=open(image,name,attributes);
}

// Last modified 29/07/2002



