// JavaScript Document

//GENERAL DW FUNCTIONS

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}



function goToURL(URL, iWidth, iHeight){
iWidth  -= 10; // Subtract Normal border widths.
iHeight -= 20; // Subtract Normal caption bar height.
iX = (screen.width  - iWidth)  / 2;
iY = (screen.height - iHeight) / 2;
if(iX < 0) { iX = 0;  };
if(iY < 0) { iY = 0; };
style="left=" +iX+ ",top=" +iY+ ",width=" +iWidth+ ",height=" +iHeight+ ",scrollbars=1";
window.open(URL,'',style);
}

function RUSure()
{
	return (confirm("Are you sure you want to delete this entry?\nThis action cannot be undone."))
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function loadPopUp(string) 
{
  	var theURL = string
	window.open(theURL,'','scrollbars=yes, width=630, height=500');
}

function accommodationValidator(theForm)
{
  if (theForm.daterange.value == "")
  {
    alert("Please enter a date for the new entry");
    theForm.daterange.focus();
    return (false);
  }

  if (theForm.barnprice.value == "")
  {
    alert("Please enter a price for the Barn - you can, if required, set this to be N/A");
    theForm.barnprice.focus();
    return (false);
  }
  
  if (theForm.barnprice.value == "")
  {
    alert("Please enter a price for the Barn - you can, if required, set this to be N/A");
    theForm.barnprice.focus();
    return (false);
  }

  if (theForm.granaryprice.value == "")
  {
    alert("Please enter a price for the Granary - you can, if required, set this to be N/A");
    theForm.granaryprice.focus();
    return (false);
  }

  if (theForm.stableprice.value == "")
  {
    alert("Please enter a price for the Stable - you can, if required, set this to be N/A");
    theForm.stableprice.focus();
    return (false);
  }
  
  if (theForm.dairyprice.value == "")
  {
    alert("Please enter a price for the Dairy - you can, if required, set this to be N/A");
    theForm.dairyprice.focus();
    return (false);
  }  
}


function PopupFileCentered(file, iWidth, iHeight, sStyle)
{

  iX = (screen.width  - iWidth)  / 2;
  iY = (screen.height - iHeight) / 2;
  if(iX < 0) { iX = 0;  };
  if(iY < 0) { iY = 0; };
  style="left=" +iX+ ",top=" +iY+ ",width=" +iWidth+ ",height=" +iHeight+ sStyle;

NewWindow = window.open(file,'',style);
};

function validateForm(theForm)
{
var checkboxGrp = document.forms[0].property;
var numselected = 0;
for (var i = 0; i < checkboxGrp.length; i++)
	{
		if (checkboxGrp[i].checked == true){
		numselected++;}
	}

	if (numselected < 1){
		alert("Please select at least one property");
		return (false);}
		

	if (theForm.name.value.length == 0)	
	{
		alert("Please enter your name");
		theForm.name.focus();
		return false;
	}
	
	if ((theForm.contactphone.value.length == 0) && (theForm.contactemail.value.length == 0))
	{
		alert("Please enter either an email address or contact telephone\nWe prefer to communicate via email and can often respond quicker via email than telephone\n\nWe only use your email address for the purpose of your enquiry and do not pass on these details to anyone else");
		theForm.contactemail.focus();
		return false;
	}


	  var zToCheck;
	  zToCheck = theForm.contactemail.value;
	  if (zToCheck.length < 7)
	  {
		alert("Please enter a valid email address into the field provided");
		theForm.contactemail.focus();
		return (false);
	  }
	
	  var zRegExp;
	  //zRegExp = "^[A-Za-z0-9_-]+[A-Za-z0-9_.-]*@[A-Za-z0-9]+[A-Za-z0-9_-]+[.][A-Za-z0-9_-]+[A-Za-z0-9_.-]*[A-Za-z0-9]+$";
	  
	  zRegExp = "^[\\w-_\.']*[\\w-_\.']\@[\\w]\.+[\\w]+[\\w]$";
	  if (zToCheck.search(zRegExp) == -1)
	  {
		alert("Please enter a valid email address into the field provided");
		theForm.contactemail.focus();
		return (false);
	  }



	if (theForm.enquiry.value.length == 0)	
	{
		alert("Please enter your enquiry");
		theForm.enquiry.focus();
		return false;
	}

	
	//alert("all done")
return (true);
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}


function validateNewsTicker(theForm) {
	
	if (theForm.newsticker.value == "")
	{
		alert("Please enter some copy to appear on the front page as a news ticker");
		theForm.newsticker.focus();
		return (false);
	}
	
	if (theForm.newstickerurl.value == "")
	{
		alert("Please select where you want the user to go when the ticker is clicked");
		theForm.newstickerurl.focus();		
		return (false);
	}
	
	return (true);
}

function tickerFormValidator(theForm) {
	return (true);
}