function eCheck(str) 
{	
	 var at="@";
	 var dot=".";
	 var lat=str.indexOf(at);
	 var lstr=str.length;
	 var ldot=str.indexOf(dot);
	 
	 if (str.indexOf(at)==-1) {
	    return false;
	 }
	 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
	    return false;
	 }
	 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
	     return false;
	 }
	 if (str.indexOf(at,(lat+1))!=-1) {
	    return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
	    return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1) {
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1) {
	    return false;
	 }
	 
	 return true;					
}

function Validate()
{
	var form = document.getElementById('ownercontact');
	var err = "";
	
	for(i=0; i<form.elements.length; i++)
	{
		if(form.elements[i].getAttribute("required") == "true")
		{
			if(form.elements[i].value == "")
			{
				err += form.elements[i].getAttribute("info") + "\n";
			}
			
			if(form.elements[i].name.match("email"))
			{
				if(!eCheck(form.elements[i].value))
				{
					err += form.elements[i].name + " is not valid\n";
				}
			}
			
			if(form.elements[i].getAttribute("type") == "checkbox")
			{
				if(!form.elements[i].checked)
				{
					err += form.elements[i].getAttribute("info") + "\n";
				}
			}
		}
	}
	
	return err;
}


function ValidateForm()
{
	var result = Validate();
	
	if(result != "")
	{
		alert(result);
	}
	else
	{
		document.ownercontact.submit();
	}
}

function bookingFormValidate()
{
	var oForm = document.booking_form;
	var strMessage = "";
	var jsCrLf;
	jsCrLf = String.fromCharCode(10,13);
	
	if (oForm.property_code.value == "")
	{
		strMessage = strMessage + "Please enter the property code of your property" + jsCrLf;
	}

	if (oForm.from_date.value == "")
	{
		strMessage = strMessage + "Please enter arrival date of your holiday" + jsCrLf;
	}

	if (oForm.to_date.value == "")
	{
		strMessage = strMessage + "Please enter departure date of your holiday" + jsCrLf;
	}
	
	if (oForm.adults.value == "-")
	{
		strMessage = strMessage + "Please enter the amount of adults that are going on your hoilday" + jsCrLf;
	}
	
	if(oForm.children.value != "-")
	{
		if(oForm.children_ages.value = "")
		{
			strMessage = strMessage + "Please enter the ages of children that are going" + jsCrLf;
		}
	}
	
	if (oForm.Name.value == "")
	{
		strMessage = strMessage + "Please enter your name" + jsCrLf;
	}	
	
	if (oForm.address.value == "")
	{
		strMessage = strMessage + "Please enter your address" + jsCrLf;
	}	
	
	if (oForm.telephone.value == "")
	{
		strMessage = strMessage + "Please enter your telephone" + jsCrLf;
	}	
	
	if (oForm.email.value == "")
	{
		strMessage = strMessage + "Please enter your email" + jsCrLf;
	}	
	
	if (oForm.Referral.value == "None Selected")
	{
		strMessage = strMessage + "Please could you choose an option about where you heard us." + jsCrLf;
	}	
	
	if(oForm.paymentchoice[3].checked == true)
	{
		if(oForm.cardtype.value == "please select")
		{
			strMessage = strMessage + "Please select a card type" + jsCrLf;
		}
		
		if(oForm.cardnumber.value == "")
		{
			strMessage = strMessage + "Please enter your card number" + jsCrLf;
		}
		
		if(oForm.security.value == "")
		{
			strMessage = strMessage + "Please select your security number" + jsCrLf;
		}
		
		if(oForm.cardholdername.value == "")
		{
			strMessage = strMessage + "Please select enter the name of the card holder" + jsCrLf;
		}
		
		if(oForm.charge.value == "")
		{
			strMessage = strMessage + "Please enter the value (in UK Sterling) of your holiday" + jsCrLf;
		}
	}
	
	if(oForm.cancchoice[2].checked == true)
	{
		if(oForm.alternatecanc.value == "")
		{
			strMessage = strMessage + "Please could you give some details about your alternative cancellation scheme." + jsCrLf;
		}
	}
	
	if(oForm.radiobutton[0].checked != true)
	{
		strMessage = strMessage + "Please could you take a moment to read our terms and conditions" + jsCrLf;
	}
	
	if(strMessage == "")
	{
		oForm.submit();
	}
	else
	{
		alert(strMessage);
	}
}

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_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 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 toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function setBoldById(id, type)
{
	var style2 = document.getElementById(id).style;
	style2.fontWeight = type;
}

function clearBolds()
{
	var i = 0;
	try
	{
		for (i; i<200; i++)
		{
			setBoldById("td"+i, "normal");
		}
	}
	catch(err)
	{

	}
}

function date2string(myDate)
{
	var myDateString;

	var year = String(myDate.getFullYear()).substring(2);
	var month = myDate.getMonth()+1;
	var day = myDate.getDate();

	if (day<10)
	{
		day = "0"+day;
	}
	if (month<10)
	{
		month = "0"+month;
	}

	return day+"/"+month+"/"+year;
}

function clickSeven(id, today)
{
	var temp = id.replace("td", "");
	var i = parseInt(temp);
	var temp2 = i+7;
	var arrTmp = today.split("/");
	var one_day=1000*60*60*24;
	
	var thisDay = new Date ("20"+arrTmp[2],arrTmp[1],arrTmp[0]);
	var thisDayPlusSeven = new Date(thisDay.getTime() + (one_day*7));
	
	if(document.getElementById(id).style.fontWeight == "bold")
	{
		while((document.getElementById("td"+i).style.fontWeight == "bold"))
		{
			setBoldById("td"+i, "normal")
			i++;
		}
		document.reserve.todate.value = date2string(thisDay);
	}
	else
	{
		clearBolds();
		document.reserve.fromdate.value = date2string(thisDay);
		document.reserve.todate.value = date2string(thisDayPlusSeven);
		try
		{
			for (i; i<temp2; i++)
			{
				setBoldById("td"+i, "bold");
			}
		}
		catch(err)
		{
	
		}
	}
}

function brochurerequestvalidateForm()
{
	var strMessage;
	var bRetVal;
	var oForm;
	var jsCrLf;
									
	strMessage = "";
	bRetVal = true;
	oForm = document.brochure;
	jsCrLf = String.fromCharCode(10,13);
	
	if (oForm.Surname.value == "")
	{
		strMessage = strMessage + "Please enter your full name" + jsCrLf;
	}
	
	if (oForm.address1.value == "")
	{
		strMessage = strMessage + "Please enter your Address" + jsCrLf;
	}
									
	if (oForm.postcode.value == "")
	{
		strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
	}
	
	if (oForm.source.value == "none")
	{
		strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
	}
	
	if (oForm.source.value == "")
	{
		if (oForm.which.value == "")
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
	}
	
	if (strMessage != "")
	{
		alert (strMessage);
		bRetVal = false;
	}
										
	if (bRetVal == true)
	{
		oForm.submit()
	}
}		



function window_display(strurl) {
  confirmWin = window.open(strurl,'theconfirmWin','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
  if (confirmWin.opener == null){
    confirmWin.opener = window;
  }
}

function ShowHidePrice(objDiv, strDisplay)
   {
    var strDivID=objDiv.id;
    var arrTmp=strDivID.split("_");
    if (arrTmp.length < 2)
    {
 	  alert("error: invalid object.\nobject id: "+strDivID);
 	  return false;
    }
    var strFaqId=arrTmp[1];
    var strPriceId="price_"+strFaqId;
    var objPrice=document.getElementById(strPriceId);
    if (!objPrice)
    {
 	  alert("error: price object does not exist.\nexpected id: "+strPriceId);
 	  return false;
    }
    objPrice.style.display = strDisplay;
    return true;
   }
   
   function AvailShowPrice(objDiv)
   {
    return ShowHidePrice(objDiv, "block");
   }
   
   function AvailHidePrice(objDiv)
   {
    return ShowHidePrice(objDiv, "none");
   }
   
   function brochurerequestvalidateForm()
	{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.brochure;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.Surname.value == "")
		{
			strMessage = strMessage + "Please enter your full name" + jsCrLf;
		}
		if (oForm.address1.value == "")
		{
			strMessage = strMessage + "Please enter your Address" + jsCrLf;
		}

		if (oForm.postcode.value == "")
		{
			strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
		}
		if (oForm.which.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
		oForm.submit()
		}
	}			

function show_symbol_key() {
  confirmWin = window.open('http://www.norfolkcottages.co.uk/symbols.htm','symbols','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
  if (confirmWin.opener == null){
    confirmWin.opener = window;
  }
}



function BookingPropertyValidateForm()
{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.bookingform;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.fromdate.value == "")
		{
			strMessage = strMessage + "Please enter a valid Arrival Date" + jsCrLf;
		}
		if (oForm.todate.value == "")
		{
			strMessage = strMessage + "Please enter a valid Departure Date" + jsCrLf;
		}
		if (oForm.adults.value == "")
		{
			strMessage = strMessage + "Please enter the number of Adults on your booking" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
		oForm.submit()
		}
}


function BookingCustomerValidateForm()
{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.bookingform;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.surname.value == "")
		{
			strMessage = strMessage + "Please enter your Surname" + jsCrLf;
		}
		if (oForm.address1.value == "")
		{
			strMessage = strMessage + "Please enter your Address" + jsCrLf;
		}
		if (oForm.postcode.value == "")
		{
			strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
		}
		if (oForm.workphone.value == "" && oForm.homephone.value == "" && oForm.mobile.value == "")
		{
			strMessage = strMessage + "Please enter at least one phone number" + jsCrLf;
		}
		if (oForm.email.value == "")
		{
			strMessage = strMessage + "Please enter your email address" + jsCrLf;
		}
		if (oForm.name1.value == "" || oForm.name2.value == "" || 
			oForm.name3.value == "" || oForm.name4.value == "" || 
			oForm.name5.value == "" || oForm.name6.value == "" || 
			oForm.name7.value == "" || oForm.name8.value == "" || 
			oForm.name9.value == "" || oForm.name10.value == "" || 
			oForm.name11.value == "" || oForm.name12.value == "" || 
			oForm.name13.value == "" || oForm.name14.value == "" ||
			oForm.name15.value == "" || oForm.name16.value == "" ||
			oForm.name17.value == "" || oForm.name18.value == "" || 
			oForm.name19.value == "" || oForm.name20.value == "")
		{
			strMessage = strMessage + "Please enter the name(s) of every member of your party" + jsCrLf;
		}

		if ((oForm.age1.value != "xxx" && IsNumeric(oForm.age1.value)) ||
			(oForm.age2.value != "xxx" && IsNumeric(oForm.age2.value)) ||
			(oForm.age3.value != "xxx" && IsNumeric(oForm.age3.value)) ||
			(oForm.age4.value != "xxx" && IsNumeric(oForm.age4.value)) ||
			(oForm.age5.value != "xxx" && IsNumeric(oForm.age5.value)) ||
			(oForm.age6.value != "xxx" && IsNumeric(oForm.age6.value)) ||
			(oForm.age7.value != "xxx" && IsNumeric(oForm.age7.value)) ||
			(oForm.age8.value != "xxx" && IsNumeric(oForm.age8.value)) ||
			(oForm.age9.value != "xxx" && IsNumeric(oForm.age9.value)) ||
			(oForm.age10.value != "xxx" && IsNumeric(oForm.age10.value)) ||
			(oForm.age11.value != "xxx" && IsNumeric(oForm.age11.value)) ||
			(oForm.age12.value != "xxx" && IsNumeric(oForm.age12.value)) ||
			(oForm.age13.value != "xxx" && IsNumeric(oForm.age13.value)) ||
			(oForm.age14.value != "xxx" && IsNumeric(oForm.age14.value)) ||
			(oForm.age15.value != "xxx" && IsNumeric(oForm.age15.value)) ||
			(oForm.age16.value != "xxx" && IsNumeric(oForm.age16.value)) ||
			(oForm.age17.value != "xxx" && IsNumeric(oForm.age17.value)) ||
			(oForm.age18.value != "xxx" && IsNumeric(oForm.age18.value)) ||
			(oForm.age19.value != "xxx" && IsNumeric(oForm.age19.value)) ||
			(oForm.age20.value != "xxx" && IsNumeric(oForm.age20.value)))
		{
			strMessage = strMessage + "Please make sure that all ages are numbers" + jsCrLf;
		}
		
		if((oForm.chkAge1.checked && oForm.age1.value == "") ||
			(oForm.chkAge2.checked && oForm.age2.value == "") ||
			(oForm.chkAge3.checked && oForm.age3.value == "") ||
			(oForm.chkAge4.checked && oForm.age4.value == "") ||
			(oForm.chkAge5.checked && oForm.age5.value == "") ||
			(oForm.chkAge6.checked && oForm.age6.value == "") ||
			(oForm.chkAge7.checked && oForm.age7.value == "") ||
			(oForm.chkAge8.checked && oForm.age8.value == "") ||
			(oForm.chkAge9.checked && oForm.age9.value == "") ||
			(oForm.chkAge10.checked && oForm.age10.value == "") ||
			(oForm.chkAge11.checked && oForm.age11.value == "") ||
			(oForm.chkAge12.checked && oForm.age12.value == "") ||
			(oForm.chkAge13.checked && oForm.age13.value == "") ||
			(oForm.chkAge14.checked && oForm.age14.value == "") ||
			(oForm.chkAge15.checked && oForm.age15.value == "") ||
			(oForm.chkAge16.checked && oForm.age16.value == "") ||
			(oForm.chkAge17.checked && oForm.age17.value == "") ||
			(oForm.chkAge18.checked && oForm.age18.value == "") ||
			(oForm.chkAge19.checked && oForm.age19.value == "") ||
			(oForm.chkAge20.checked && oForm.age20.value == ""))
		{
			strMessage = strMessage + "Please make sure you have entered the ages of your ticked party members" + jsCrLf;
		} 
		
		if (oForm.which.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
		if (oForm.terms.checked == false)
		{
			strMessage = strMessage + "Please confirm that you agree to our booking terms and conditions" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
		oForm.submit()
		}
}			

function ShowHideBookingFormSection(objDiv, strDisplay)
   {
    var strDivID=objDiv;
    var arrTmp=strDivID.split("_");
    if (arrTmp.length < 2)
    {
 	  alert("error: invalid object.\nobject id: "+strDivID);
 	  return false;
    }
    var strFaqId=arrTmp[1];
    var strPriceId="bookform_"+strFaqId;
    var objPrice=document.getElementById(strPriceId);
    if (!objPrice)
    {
 	  alert("error: price object does not exist.\nexpected id: "+strPriceId);
 	  return false;
    }
    objPrice.style.display = strDisplay;
    return true;
   }
   
   function BookingFormShowSection(objDiv)
   {
    return ShowHideBookingFormSection(objDiv, "block");
   }
   
   function BookingFormHideSection(objDiv)
   {
    return ShowHideBookingFormSection(objDiv, "none");
   }

   function ownerpackrequestvalidateForm()
	{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.ownerpack;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.Surname.value == "")
		{
			strMessage = strMessage + "Please enter your Surname" + jsCrLf;
		}
		if (oForm.address1.value == "")
		{
			strMessage = strMessage + "Please enter your Address" + jsCrLf;
		}
		if (oForm.postcode.value == "")
		{
			strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
		}
		if (oForm.telnumber.value == "")
		{
			strMessage = strMessage + "Please enter your Telephone Number" + jsCrLf;
		}
		if (oForm.email.value == "")
		{
			strMessage = strMessage + "Please enter your Email Address" + jsCrLf;
		}
		if (oForm.where.value == "")
		{
			strMessage = strMessage + "Please tell us where your property is" + jsCrLf;
		}
		if (oForm.whichone.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
		oForm.submit()
		}
	}			

	function addToFavoritesOLD() {
		if (window.external) {
			window.external.AddFavorite(location.href, document.title) 
		} else {
			alert("Sorry! Your browser doesn't support this function."); 
		}
	}


function addToFavorites() {
    if (window.sidebar) {
        window.sidebar.addPanel(document.title, location.href,"");
    } else if( document.all ) {
        window.external.AddFavorite( location.href, document.title);
    } else if( window.opera && window.print ) {
        return true;
    }
}
function switchpic(which){
document.mainpic.src=which
}

var bigimages=new Array()    // array for images to be preloaded

function IsNumeric(PossibleNumber)
{
	var PNum = new String(PossibleNumber);
	var regex = /[^0-9]/;
	return regex.test(PNum);
}



function check_length(id, maxchars)
{
	var element = document.getElementById(id);
	var len = element.value.length;
	
	if (len > maxchars)
	{
		element.value = element.value.substr(0,maxchars);
		len = maxchars;
	}
	
	document.getElementById(id).innerHTML = len;
	document.getElementById(id).innerHTML = maxchars - len;
}


function window_display(strurl) {
	window.open(strurl,'theconfirmWin','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
	
	//confirmWin.focus();
	//if (confirmWin.opener == null){
	//	confirmWin.opener = window;
	//}
}