// JavaScript Document

function mapinit(){
if (GBrowserIsCompatible()) {
 var map = new GMap2(document.getElementById("map"));
 map.setCenter(new GLatLng(53.821527, -1.972112), 5);
 var point = new GLatLng(53.821527, -1.972112);

 var info = "<DIV style='font-size: 0.7em;'>Westfield Lodge Apartments<BR>New West Field Farm<BR>Upper Marsh Lane<BR>Oxenhope<BR>Keighley<BR>West Yorkshire<BR>BD22 9RH</DIV>";
 var marker= new GMarker(point);
 GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(info);});
 map.addOverlay(marker);

 map.addControl(new GLargeMapControl());
 map.addControl(new GMapTypeControl());

}
else
{
 document.getElementById("map").innerHTML = "<img src='images/map.jpg'>";
 document.getElementById("map").style.width="250px";
 document.getElementById("map").style.height="300px";  
}
init();
}

doonce=0;
function init()
{
 doonce++;
 bodywidth = document.getElementById('mybody').offsetWidth;
 navwidth = document.getElementById('navs').offsetWidth;
 leftmargin=parseInt((bodywidth-navwidth)/2)-5;
 if (leftmargin<0){
 leftmargin=0;
 }
 document.getElementById("navs").style.left=leftmargin+"px";
 
 if (document.getElementById("imagebot"))
 {
  whitespace=findPos(document.getElementById("imagebot"))-findPos(document.getElementById("copybot"));
 }
 else
 {
  whitespace=0;
 }
 if (whitespace<0)
 {
  whitespace=0;
 }

 if (whitespace>0 && document.getElementById("rhbottomtext"))
 {
  repos=whitespace-document.getElementById("rhbottomtext").offsetHeight;
  document.getElementById("rhbottomtext").style.top=repos+"px";
 }

 difference = document.getElementById("lhcol").offsetHeight - document.getElementById("rhcol").offsetHeight;

 if (difference>0)
 {
  document.getElementById("rhcol").style.height=document.getElementById("lhcol").offsetHeight+"px";
 }
 else
 {
  difference=0;  
 }
 
 
 
 if (doonce==1)
 {
  if(difference+whitespace>150)
  {
   document.getElementById("rhcol").style.backgroundImage="url(images/wlviewrear.jpg)";
  }
  else if(difference+whitespace>70)
  {
   document.getElementById("rhcol").style.backgroundImage="url(images/thevalley.jpg)";
  }
 }

 if (document.getElementById("innercalendara"))
 {
  displayCalendar(month, year, "a");
  displayCalendarb()
  setDepartDate();
 } 
 externalLinks();
 //findAccessKeys();
 dyn = leftmargin;
 setDynamics(dyn);
 
 if (goingToPay==1)
 {
  document.PayForm.submit();
 } 
}

function findPos(obj)
{
 toppos=0;
 if (obj.offsetParent)
 {
  do
  {
	 toppos += obj.offsetTop;
  }while (obj = obj.offsetParent);
 }
 return[toppos];
}

function displayCalendarb(){
 if (document.getElementById("innercalendarb"))
 {
  var monthb = month*1 + 1;
  var yearb = year;
  if (monthb==13)
  {
   monthb=1;
   yearb=yearb*1 + 1;
  }
  displayCalendar(monthb, yearb, "b");
 } 
}

function displayCalendar(month, year, calendar) { 
month = parseInt(month-1);
year = parseInt(year);
var i = 0;
var day = 0;
var days = getDaysInMonth(month+1,year);
var firstOfMonth = new Date (year, month, 1);
var startingPos = firstOfMonth.getDay();
days += startingPos;
for (i = 1; i < 43; i++) {
slot="slot"+calendar+i;
nd = document.getElementById(slot);
//nd.firstChild.nodeValue="-";
nd.innerHTML="-";
nd.className="calendar-week";
nd.parentNode.className="calendar-week";
}
for (i = startingPos; i < days; i++) {
 j=i+1;
 slot="slot"+calendar+j;
 nd = document.getElementById(slot);
 //nd.firstChild.nodeValue=i-startingPos+1;
 nd.innerHTML=i-startingPos+1;
 nd.className="realday";
 nd.title="Click to select your arrival date";
 if (nd.parentNode)
 {
  nd.parentNode.className="realday";
 } 
}
}

function setDepartDate(){
if(document.getElementById('selectArriveMY').value == document.getElementById('selectDepartMY').value && document.getElementById('selectArriveD').value == document.getElementById('selectDepartD').value)
{
 thisSelection = document.getElementById("selectArriveMY").value.split(" ");
 aMonth = thisSelection[0];
 aYear = thisSelection[1];
 adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);
 departOneWeek();
}
}

function changeCalendarMonth(){
newMonth=document.getElementById('calendarMonth').value;
document.getElementById('selectArriveMY').value=newMonth; //Why does this work??
setSession("selectArriveMY", newMonth);
newMonth=newMonth.split(" ");
displayCalendar(newMonth[0], newMonth[1], "a");
 
thisSelection = document.getElementById("selectArriveMY").value.split(" ");
aMonth = thisSelection[0];
aYear = thisSelection[1];
adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);

thisSelection = document.getElementById("selectDepartMY").value.split(" ");
dMonth = thisSelection[0];
dYear = thisSelection[1];
ddate=new Date(dYear,dMonth-1,document.getElementById('selectDepartD').value);

if (ddate<adate)
{
 departOneWeek();
}

}
function changeArrivalMonth(){
newMonth=document.getElementById('selectArriveMY').value;
setSession("selectArriveMY", newMonth);
setSession("selectArriveD", document.getElementById('selectArriveD').value);
newMonth=newMonth.split(" ");
displayCalendar(newMonth[0], newMonth[1], "a");

if (document.getElementById('calendarMonth'))
{
 numOpts=(document.SelectForm.calendarMonth.options.length);
 for (i=0; i<numOpts; i++)
 {
  if (document.SelectForm.calendarMonth.options[i].value==newMonth[0]+" "+newMonth[1])
  {
   document.SelectForm.calendarMonth.selectedIndex = i;  
  }
 } 
}
else
{
 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 document.getElementById("calendarheada").innerHTML = stringMonth[newMonth[0]-1]+" "+ newMonth[1];
 freshYear=newMonth[1];
 freshMonth = (newMonth[0]*1)+1;
 if (freshMonth==13)
 {
  freshYear=(freshYear*1)+1
  freshMonth=1;
 }
 document.getElementById("calendarheadb").innerHTML = stringMonth[freshMonth-1]+" "+freshYear;  
 displayCalendar(freshMonth, freshYear, "b");
}

aMonth = newMonth[0];
aYear = newMonth[1];
adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);

thisSelection = document.getElementById("selectDepartMY").value.split(" ");
dMonth = thisSelection[0];
dYear = thisSelection[1];
ddate=new Date(dYear,dMonth-1,document.getElementById('selectDepartD').value);

if (ddate<adate)
{
 departOneWeek();
}

}

function clickDate(here){

if (document.getElementById(here).value=="-"){
 return(true);
}
thisslot=here.substring(5,here.length);
newWeek= here.charAt(4);
newDay=document.getElementById("slot"+newWeek+thisslot).innerHTML;
var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
stringMonth = allMonthString.split(",");
if (!document.getElementById("calendarheada"))
{
thisSelection = document.getElementById("selectArriveMY").value.split(" ");
newMonth = thisSelection[0];
}
else
{
 if (newWeek=="a")
 {
  thisSelection = document.getElementById("calendarheada").innerHTML.split(" ");
 }
 else
 {
  thisSelection = document.getElementById("calendarheadb").innerHTML.split(" ");
 }
 for (var i=1; i<13; i++)
 {
  if (stringMonth[i-1]==thisSelection[0])
  {
   newMonth = i;
   break;
  }
 }
}
newYear = thisSelection[1];
adate=new Date(newYear,newMonth-1,newDay);
numOpts=(document.SelectForm.selectArriveD.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.SelectForm.selectArriveD.options[i].value==newDay)
 {
  document.SelectForm.selectArriveD.selectedIndex = i;
 }
}
arrivalString = newMonth+" "+newYear;
numOpts=(document.SelectForm.selectArriveMY.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.SelectForm.selectArriveMY.options[i].value==arrivalString)
 {
  document.SelectForm.selectArriveMY.selectedIndex = i;
 }
}
setSession("selectArriveMY", document.getElementById('selectArriveMY').value);
setSession("selectArriveD", document.getElementById('selectArriveD').value);
departOneWeek();
}

function earlier(){
doit=1;
if (year == yearFirst){
 if (month == monthFirst){
  doit=0;
  }
 }
if (doit==1)
{
 month = month*1 - 1;
 if (month==0) {
  month=12;
  year=year*1 - 1;
 }
 displayCalendar(month, year, "a");
 displayCalendarb();  
 document.getElementById("calendarheadb").innerHTML = document.getElementById("calendarheada").innerHTML;

 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 aMonth = document.getElementById("calendarheada").innerHTML.split(" ");
 for (var i=1; i<13; i++)
 {
  if (stringMonth[i-1]==aMonth[0])
  {
   break;
  }
 }
 i=i-2;
 freshYear=aMonth[1];
 if (i<0)
 {
  freshYear=(freshYear*1)-1
  i=11;
 }
 document.getElementById("calendarheada").innerHTML = stringMonth[i]+" "+freshYear;    
}
}

function later(){
doit=1;
if (year == yearLast){
 if (month == monthLast){
  doit=0;
  }
 }
if (doit==1)
{
 month = month*1 + 1;
 if (month==13) {
  month=1;
  year=year*1 + 1;
 }
 displayCalendar(month, year, "a");
 displayCalendarb();  
 document.getElementById("calendarheada").innerHTML = document.getElementById("calendarheadb").innerHTML;

 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 bMonth = document.getElementById("calendarheadb").innerHTML.split(" ");
 for (var i=1; i<13; i++)
 {
  if (stringMonth[i-1]==bMonth[0])
  {
   break;
  }
 }
 freshYear=bMonth[1];
 if (i==12)
 {
  freshYear=(freshYear*1)+1
  i=0;
 }
 document.getElementById("calendarheadb").innerHTML = stringMonth[i]+" "+freshYear;
}
}

function earliera(here){
earlier();
setNewMonth(here);
}

function latera(here){
later();
setNewMonth(here);
}

function earlierstyle(style){
doit=1;
if (year == yearFirst){
 if (month == monthFirst){
  doit=0;
  }
 }
if (doit==1)
{
 month = month*1 - 1;
 if (month==0) {
  month=12;
  year=year*1 - 1;
 }
 displayCalendar(month, year, "a");
 numOpts=(document.SelectForm.calendarMonth.options.length);
 for (i=0; i<numOpts; i++)
 {
  if (document.SelectForm.calendarMonth.options[i].value==month+" "+year)
  {
   document.SelectForm.calendarMonth.selectedIndex = i;
   document.SelectForm.selectArriveMY.selectedIndex = i;
   thisSelection = document.getElementById("selectArriveMY").value.split(" ");
   aMonth = thisSelection[0];
   aYear = thisSelection[1];
   adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);
   departOneWeek();  //includes setsession which won't always work - no matter
   style=style.toLowerCase();
   document.SelectForm.action = style+".php";
   document.SelectForm.submit();
  }
 }
} 
}

function laterstyle(style){
doit=1;
if (year == yearLast){
 if (month == monthLast){
  doit=0;
  }
 }
if (doit==1)
{
 month = month*1 + 1;
 if (month==13) {
  month=1;
  year=year*1 + 1;
 }
 displayCalendar(month, year, "a");
 numOpts=(document.SelectForm.calendarMonth.options.length);
 for (i=0; i<numOpts; i++)
 {
  if (document.SelectForm.calendarMonth.options[i].value==month+" "+year)
  {
   document.SelectForm.calendarMonth.selectedIndex = i;
   document.SelectForm.selectArriveMY.selectedIndex = i;
   thisSelection = document.getElementById("selectArriveMY").value.split(" ");
   aMonth = thisSelection[0];
   aYear = thisSelection[1];
   adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);
   departOneWeek();  //includes setsession which won't always work - no matter
   style=style.toLowerCase();
   document.SelectForm.action = style+".php";
   document.SelectForm.submit();
  }
 }
}
}

function changeStyleMonth(style){
newMonth=document.getElementById('styleMonth').value;
newMonth=newMonth.split(" ");
displayCalendar(newMonth[0], newMonth[1], "a");
numOpts=(document.SelectForm.calendarMonth.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.SelectForm.calendarMonth.options[i].value==newMonth[0]+" "+newMonth[1])
 {
  document.SelectForm.calendarMonth.selectedIndex = i;
  document.SelectForm.selectArriveMY.selectedIndex = i;
  thisSelection = document.getElementById("selectArriveMY").value.split(" ");
  aMonth = thisSelection[0];
  aYear = thisSelection[1];
  adate=new Date(aYear,aMonth-1,document.getElementById('selectArriveD').value);
  departOneWeek();  //includes setsession which won't always work - no matter
  style=style.toLowerCase();
  document.SelectForm.action = style+".php";
  document.SelectForm.submit();
 }
}
}


function setNewMonth(here){
thisSelection = document.getElementById("calendarheada").innerHTML.split(" ");
var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
stringMonth = allMonthString.split(",");
for (var i=1; i<13; i++)
{
 if (stringMonth[i-1]==thisSelection[0])
 {
  newMonth = i;
  break;
 }
}
newYear = thisSelection[1];
adate=new Date(newYear,newMonth-1,"1");
document.getElementById('selectArriveMY').value = newMonth+" "+newYear;
document.getElementById('selectArriveD').value = "1";
setSession("selectArriveMY", newMonth+" "+newYear);
setSession("selectArriveD", "1");
departOneWeek();
checkAvail(here);
}

function clickTableDay(here){
here=here.split(" ");
here[1]=here[1]*1+1;
here=here[0]+" "+here[1]+" "+here[2]+" "+here[3]
document.location.href="booking.php?selectTableDay="+here;
}

function overDay(here, book)
{
 thisDay=here.id.split("-");
 thd=document.getElementById(here.id);
 if (thd.innerHTML!="&nbsp;")
 {
  thd.title="Available as an arrival date: Click to select";
 }
 thisDay[0]=thisDay[0].substr(1);
 htmlID="sum"+thisDay[0];
 if (!document.getElementById(htmlID))
 {
  htmlID="sumx";
 }
 thisDate=thisDay[1];
 dateString=thisDay[3]+" "+thisDay[2];
 for (i=0; i<dpApart.length; i++)
 {
  if (dpApart[i]==thisDay[0] && dpMonth[i]==dateString)
  {
   priceString=dpPrices[i].split(",");
   dailyString=priceString[thisDate];
   dailyString=dailyString*1;
   if (dailyString.toFixed(2))
   {
    dailyString = dailyString.toFixed(2);
   }
  } 
 }
 for (i=0; i<wpApart.length; i++)
 {
  if (wpApart[i]==thisDay[0] && wpMonth[i]==dateString)
  {
   priceString=wpPrices[i].split(",");
   weeklyString=priceString[thisDate];
   weeklyString=weeklyString*1;
   if (weeklyString.toFixed(2))
   {
    weeklyString = weeklyString.toFixed(2);
   }   
  } 
 }
 for (i=0; i<minApart.length; i++)
 {
  if (minApart[i]==thisDay[0] && minMonth[i]==dateString)
  {
   minimumStr=minDays[i].split(",");
   minimumString=minimumStr[thisDate];
   if (minimumString*1>1)
   {
    minimumString="Minimum stay "+minimumString+" nights.";
   }
   else
   {
    minimumString="";
   }
  } 
 }
 
 for (i=0; i<offerApart.length; i++)
 {
  if (offerApart[i]==thisDay[0] && offerMonth[i]==dateString)
  {
   offerStr=offerDays[i].split("!");
   offerString=offerStr[thisDate];
   offerStr=offerString.split(",");
   offerString=offerStr[1];
   if (offerString*1>1)
   {$d=thisDay[1]*1+1;
    offerString=$d+" "+thisDay[2]+" - Special Extra Night Offer: £"+offerString;
    offerID="offer"+thisDay[0];
    if (document.getElementById(offerID))
    {
     document.getElementById(offerID).innerHTML = offerString;
     document.getElementById(offerID).style.backgroundColor="#AA0000";
    }
    else
    {
     document.getElementById('sumy').innerHTML = offerString;
     document.getElementById('sumy').style.backgroundColor="#AA0000";
    } 
   }
  } 
 }
 
 if (book=="book")
 {
  document.getElementById(htmlID).innerHTML = "Price: &pound;"+weeklyString+" per week.&nbsp; Daily guide: &pound;"+dailyString+" per night. "+minimumString;
 }
}

function overDayOff(here)
{
 thisDay=here.id.split("-");
 thisDay[0]=thisDay[0].substr(1); 
 htmlID="sum"+thisDay[0];
 if (!document.getElementById(htmlID))
 {
  htmlID="sumx";
 }
 document.getElementById(htmlID).innerHTML = "";
 offerID="offer"+thisDay[0];
 if (document.getElementById(offerID))
 {
  document.getElementById(offerID).innerHTML = "&nbsp;";
  document.getElementById(offerID).style.backgroundColor="#FFFFFF"  
 }
 else
 {
  document.getElementById('sumy').innerHTML = "&nbsp;";
  document.getElementById('sumy').style.backgroundColor="#FFFFFF"  
 }     
}

function changeDepartureDate(){
cday=document.getElementById('Departure').value;
document.location.href="booking.php?changeDeparture="+cday;
}
function changeArrivalDate(){
cday=document.getElementById('Arrival').value;
document.location.href="booking.php?changeArrival="+cday;
}
function changeExtraBeds(here){
document.location.href="booking.php?changeBeds="+here.id+" "+here.value;
}
function changeExtraBedsNights(here){
document.location.href="booking.php?changeBedsNights="+here.id+" "+here.value;
}


function departOneWeek(){
ddate=adate;
ddate.setDate(adate.getDate()+7);
departD= ddate.getDate();
departDs = new String(departD);
departMY = ddate.getMonth()+1;
departMY = String(departMY);
departMY = departMY +" "+ddate.getFullYear();
numOpts=(document.SelectForm.selectDepartD.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.SelectForm.selectDepartD.options[i].value==departDs)
 {
  document.SelectForm.selectDepartD.selectedIndex = i;
 }
}
numOpts=(document.SelectForm.selectDepartMY.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.SelectForm.selectDepartMY.options[i].value==departMY)
 {
  document.SelectForm.selectDepartMY.selectedIndex = i;
 }
}
setSession("selectDepartMY", departMY);
setSession("selectDepartD", departDs);
}

function checkAvail(apart){
party=parseInt(document.getElementById('selectParty').value, 10)*1;
if (party<=0 || isNaN(party))
{
 document.getElementById('selectParty').value="";
}
else
{
 document.getElementById('selectParty').value=party;
}
if (apart)
{
 document.SelectForm.action = "booking.php#"+apart;
}
else
{
 document.SelectForm.action = "booking.php";
}
document.SelectForm.submit();
}

function addApartment(apartfield){
document.getElementById('addapart').value=apartfield;
document.BookingForm.action="booking.php";
document.BookingForm.submit();
}

function removeFromList(item){
document.getElementById('removeItem').value=item;
document.ShortList.action=thisPage;
document.ShortList.submit();
}

function changeListDates(item){
document.getElementById('changeItem').value=item;
//document.getElementById('gotoBook').value="yes";
document.ShortList.action="booking.php";
document.ShortList.submit();
}

function gotoBookBut(){
document.getElementById('gotoBook').value="yes";
document.ShortList.action="booking.php";
document.ShortList.submit();
}


function getDaysInMonth(month,year)  {
var days;
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)  days=31;
else if (month==4 || month==6 || month==9 || month==11) days=30;
else if (month==2)  {
if (isLeapYear(year)) { days=29; }
else { days=28; }
}
return (days);
}
function isLeapYear (Year) {
if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
return (true);
} else
  { 
   return (false);
  }
}


function subshow(thisnav){
 subID="s"+thisnav;
 if (document.getElementById(subID)){
  document.getElementById(subID).style.display="block";
 }
}
function subhide(thisnav){
 subID="s"+thisnav;
 if (document.getElementById(subID))
 {
  document.getElementById(subID).style.display="none";
 }
}

function findAccessKeys() { 
var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
  var fieldspec = fieldspecs[i]; 
  if (fieldspec.getAttribute("accesskey")) {
     highlightAccessKey(fieldspec, fieldspec.getAttribute("accesskey"));
   }
 }
} 
function highlightAccessKey(e, accessKey) {
    if (e.hasChildNodes())
    {
     var childNode, txt;
     //find the first text node that contains the access character
     for (var i = 0; i < e.childNodes.length; i++)
     {
      txt = e.childNodes[i].nodeValue;
      if (e.childNodes[i].nodeType == 3 && txt.toLowerCase().indexOf(accessKey.toLowerCase()) != -1)
      {
       childNode = e.childNodes[i];
       break;
      }
     }
        
     if (!childNode)
     {
      //access character was not found
      return;
     }
 
     var pos = txt.toLowerCase().indexOf(accessKey.toLowerCase());
     var span = document.createElement('span');
     var spanText = document.createTextNode(txt.substr(pos, 1));
     span.className = 'accesskey';
     span.appendChild(spanText);
     //the text before the access key
     var text1 = document.createTextNode(txt.substr(0, pos));
     //the text after the access key
     var text2 = document.createTextNode(txt.substr(pos + 1));
     if (text1.length > 0) e.insertBefore(text1, childNode);
     e.insertBefore(span, childNode);
     if (text2.length > 0) e.insertBefore(text2, childNode);
     e.removeChild(childNode);
    }
}


function externalLinks() { 
 if (!document.getElementsByTagName) return;
  if (document.getElementById("newwindowlinks")){
   document.getElementById("newwindowlinks").style.display="inline"; 
  }
 var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
   var fieldspec = fieldspecs[i]; 
   if (fieldspec.getAttribute("href") && 
       fieldspec.getAttribute("rel") == "external") 
       fieldspec.target = "_blank"; 
 } 
}
function externalLinksOff() { 
 if (!document.getElementsByTagName) return;
 var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
   var fieldspec = fieldspecs[i]; 
   if (fieldspec.getAttribute("href") && 
       fieldspec.getAttribute("rel") == "external") 
       fieldspec.target = "_self"; 
 }
 var images = document.getElementsByTagName("img");
 for (var i=0; i<images.length; i++) { 
   var image = images[i];
   var firstchar = image.getAttribute("src").lastIndexOf("/") + 1;
   var filename = image.getAttribute("src").substring(firstchar,firstchar+6);
   if (filename == "newwin")
     image.style.display = "none";
 }  
} 

function sendEnquiry(){
 required=0;
 document.getElementById("labelname").style.color="#000000";
 document.getElementById("labeltelephone").style.color="#000000"; 
 document.getElementById("labelemail").style.color="#000000";
 document.getElementById("labelenquiry").style.color="#000000"; 
 if (document.EnquiryForm.name.value=="")
 {
  document.getElementById("labelname").style.color="#DD0000";
  required=1;  
 }
 if (document.EnquiryForm.telephone.value=="")
 {
  document.getElementById("labeltelephone").style.color="#DD0000";
  required=1;  
 }
 if (document.EnquiryForm.email.value=="")
 {
  document.getElementById("labelemail").style.color="#DD0000";
  required=1;  
 } 
 if (document.EnquiryForm.enquiry.value=="")
 {
  document.getElementById("labelenquiry").style.color="#DD0000";
  required=1;  
 }
 
 if (required==1)
 {
  alert ("Please complete all the fields marked with a *");
  return;
 }
 else
 {
  document.EnquiryForm.action = "enquirythanks.php";
  document.EnquiryForm.submit();
 }
}

function submitBookReq(){
 valid=checkInput();
 if (valid==0)
 {
  alert ("Form error.  Please resubmit.");
  return 
 } 

 required=checkRequired();
 if (required==1)
 {
  alert ("Please complete all the fields marked with a *");
  return
 }
 else
 {
  if (document.getElementById("terms").checked)
  {
   document.BookingForm.action = "requestthanks.php";
   document.BookingForm.submit();
  }
  else
  {
   alert ("Please agree to our Terms and Conditions");
  } 
 }    
}

function finalCheck(){
 valid=checkInput();
 if (valid==0)
 {
  alert ("Form error.  Please resubmit.");
  return 
 } 

 required=checkRequired();
 if (required==1)
 {
  alert ("Please complete all the fields marked with a *");
  return
 }
 else
 {
  if (document.getElementById("terms").checked)
  {
   document.BookingForm.action = "booking.php";
   document.getElementById("finalcheck").value="yes";
   document.BookingForm.submit();
  }
  else
  {
   alert ("Please agree to our Terms and Conditions");
  } 
 }    
}

function checkInput()
{
 valid=1;
 for (i=9;i<11;i++)
 {
  value=document.BookingForm.elements[i].value;
  if (value.indexOf("--")!=-1 || value.indexOf("--")!=-1 || value.indexOf("/*")!=-1 || value.indexOf("*/")!=-1 || value.indexOf("xp_")!=-1)
  {
    document.BookingForm.elements[i].value="";
    valid=0;
  }
 }
  return (valid);
}



function checkRequired()
{
 required=0;
 document.getElementById("labelname").style.color="#000000";
 document.getElementById("labeltelephone").style.color="#000000"; 
 document.getElementById("labelemail").style.color="#000000";
 document.getElementById("labeladdress").style.color="#000000";
 document.getElementById("labelpostcode").style.color="#000000";
 document.getElementById("labelparty").style.color="#000000";  
 if (document.BookingForm.name.value=="")
 {
  document.getElementById("labelname").style.color="#DD0000";
  required=1;  
 }
 if (document.BookingForm.telephone.value=="")
 {
  document.getElementById("labeltelephone").style.color="#DD0000";
  required=1;  
 }
 if (document.BookingForm.email.value=="")
 {
  document.getElementById("labelemail").style.color="#DD0000";
  required=1;  
 } 
 if (document.BookingForm.address.value=="")
 {
  document.getElementById("labeladdress").style.color="#DD0000";
  required=1;  
 }
 if (document.BookingForm.postcode.value=="")
 {
  document.getElementById("labelpostcode").style.color="#DD0000";
  required=1;  
 }
 if (document.BookingForm.party.value=="")
 {
  document.getElementById("labelparty").style.color="#DD0000";
  required=1;  
 } 
 if (document.BookingForm.leads.value=="")
 {
  document.getElementById("labelleads").style.color="#DD0000";
  required=1;  
 } 
 return (required);
}

function showTandC(){
document.getElementById("tandc").style.display="block";
document.getElementById("showtandc").style.display="none";
document.getElementById("linktandc").style.display="none";
}

function testmOn(){
document.getElementById("testimoniallink").style.backgroundImage="url(images/indexquotes1.jpg)";
}

function testmOff(){
document.getElementById("testimoniallink").style.backgroundImage="url(images/indexquotes.jpg)";
}

var dynObject;
function setDynamics(dyn){
 if (dynObject) 
 {
  document.body.removeChild(dynObject);
 }
 dynObject = document.createElement("script");
 dynObject.src = "setdyn.php?dyn="+dyn;
 dynObject.type = "text/javascript";
 document.body.appendChild(dynObject);
}

var fieldObject;
function setSession(fieldspec, value){
value=value.replace(/\n/g, "-*--");
 if (fieldObject) 
 {
  document.body.removeChild(fieldObject);
 }
 fieldObject = document.createElement("script");
 fieldObject.src = "setsession.php?fieldspec="+fieldspec+"&value="+value;
 fieldObject.type = "text/javascript";
 document.body.appendChild(fieldObject);
}

