// JavaScript Document
doonce=0;

function mapinit(){
if (typeof loadimage!="undefined")
{
 if (loadimage==1)
 {
  return;
 }
}
split=0;
init();
if (GBrowserIsCompatible() && split!=4) //ie6 too hard
{
 leftelementwidth=198;
 mapWidth=Math.round(document.getElementById("midcontainer").offsetWidth-leftelementwidth-10);
 document.getElementById("map").style.width=mapWidth+"px";

 var map = new GMap2(document.getElementById("map"));
 map.setCenter(new GLatLng(28.931200, -13.6205), 6);
 var point = new GLatLng(28.931200, -13.6205);
 var customIcon = new GIcon(); 
 customIcon.image = "images/glanzalogo.png";
 customIcon.shadow = "images/glogoshadow.png"; 
 customIcon.iconSize = new GSize(25, 26);
 customIcon.shadowSize = new GSize(40, 26);
 customIcon.iconAnchor = new GPoint(-6, 6);
 customIcon.infoWindowAnchor = new GPoint(5, 1);
 markerOptions = { icon:customIcon }; 
 var marker= new GMarker(point, markerOptions); 
 var info = "<DIV style='font-size: 0.8em;'>Matagorda<br>Lanzarote<br>Canary Islands</DIV>";
 GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(info);});
 map.addOverlay(marker);
 map.addControl(new GLargeMapControl());
 map.addControl(new GMapTypeControl());

}
else
{
 if(document.getElementById("map").innerHTML=="&nbsp;" || document.getElementById("map").innerHTML.length==1)
 {
  document.getElementById("map").innerHTML = "<img src='images/lanzamap.jpg' id='lanzamap'>";
  document.getElementById("map").style.width="270px";
 }
 leftelementwidth=198;
 crm=Math.round((document.getElementById("midcontainer").offsetWidth-document.getElementById("rightcontainer").offsetWidth-leftelementwidth)/split);
 document.getElementById("rightcontainer").style.marginRight=crm+"px";
}
}

function localmapinit(){
if (typeof loadimage!="undefined")
{
 if (loadimage==1)
 {
  return;
 }
}
split=0;
init();

if (GBrowserIsCompatible() && split!=4) //ie6 too hard
{
 leftelementwidth=198;
 mapWidth=Math.round(document.getElementById("midcontainer").offsetWidth-leftelementwidth-8);
 document.getElementById("mapl").style.width=mapWidth+"px";

 var map = new GMap2(document.getElementById("mapl"));
 map.setCenter(new GLatLng(28.927, -13.65), 13);
 var point = new GLatLng(28.931190, -13.6205);
 var customIcon = new GIcon(); 
 customIcon.image = "images/gmatarrow.png";
 customIcon.shadow = "images/gmatshadow.png";
 customIcon.iconSize = new GSize(50, 30);
 customIcon.shadowSize = new GSize(22, 20); 
 customIcon.iconAnchor = new GPoint(6, 0);
 customIcon.infoWindowAnchor = new GPoint(-100, 0); 
 markerOptions = { icon:customIcon }; 
 var marker= new GMarker(point, markerOptions); 
 map.addOverlay(marker);
 map.addControl(new GSmallMapControl());
 var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(2,12));
 map.addControl(new GMapTypeControl(), bottomRight);
}
else
{
 if(document.getElementById("mapl").innerHTML=="&nbsp;" || document.getElementById("mapl").innerHTML.length==1)
 {
  document.getElementById("mapl").innerHTML = "<img src='images/pdcmap.jpg' id='pdcmap'>";
  document.getElementById("mapl").style.width="270px";
 }
 leftelementwidth=198;
 crm=Math.round((document.getElementById("midcontainer").offsetWidth-document.getElementById("rightcontainer").offsetWidth-leftelementwidth)/split);
 document.getElementById("rightcontainer").style.marginRight=crm+"px";
}
}

function airmapinit(){
if (typeof loadimage!="undefined")
{
 if (loadimage==1)
 {
  return;
 }
}
split=0;
init();

if (GBrowserIsCompatible() && split!=4) //ie6 too hard
{
 var map = new GMap2(document.getElementById("mapa"));
 map.setCenter(new GLatLng(28.936, -13.61), 13);
 var point = new GLatLng(28.931190, -13.6205);
 var customIcon = new GIcon(); 
 customIcon.image = "images/gmatarrow.png";
 customIcon.shadow = "images/gmatshadow.png";
 customIcon.iconSize = new GSize(50, 30);
 customIcon.shadowSize = new GSize(22, 20); 
 customIcon.iconAnchor = new GPoint(6, 0);
 customIcon.infoWindowAnchor = new GPoint(-100, 0); 
 markerOptions = { icon:customIcon }; 
 var marker= new GMarker(point, markerOptions); 
 map.addOverlay(marker);
 map.addControl(new GSmallMapControl());
 var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(2,30));
 map.addControl(new GMapTypeControl(), bottomRight);
}
else
{
 if(document.getElementById("mapa").innerHTML=="&nbsp;" || document.getElementById("mapa").innerHTML.length==1)
 {
  document.getElementById("mapa").innerHTML = "<img src='images/airportmap.jpg' id='pdcmap'>";
  document.getElementById("mapa").style.height="158px";
 }
}
}


dolog=0;
function init()
{
 if (typeof loadimage!="undefined")
 {
  if (loadimage==1)
  {
   return;
  }
 }


 dolog++;
 if (dolog==1)
 {
  myheight=document.getElementById("mybody").offsetHeight;
  mywidth=document.getElementById("mybody").offsetWidth;
  writeLog(myheight,mywidth,httpaccept);
 }

 if (typeof xrate=="undefined")
 {
  getXrate();
 }

 doonce++;
 mywidth=document.getElementById("mybody").offsetWidth;
 if (mywidth>995)
 {
  setouter=940;
  setlmargin="auto";  
 }
 else if (mywidth<785)
 {
  setouter=710;
  setlmargin="30px";
 }
 else
 {
  setouter=mywidth-65;
  setlmargin="auto";  
 }
 document.getElementById("outer").style.width=setouter+"px";
 document.getElementById("outer").style.marginLeft=setlmargin;   

 ie6markw=document.getElementById("ie6marker").offsetWidth;
 ie6boj=0;
 if (ie6markw==2)
 {
  ie6boj=2; //4 if midcontainer has a border
  if (thisPage=="booking.php" || thisPage=="bookingthanks.php")
  {
   ie6boj=4; //selectpanel has a border so add 2
  }
 }
 
 midwidth=setouter-100-112-8-ie6boj; //lcol; rcol; mid padding; tweak;

 if (thisPage=="cars.php" || thisPage=="flights.php" || thisPage=="insurance.php")
 {
  midwidth=midwidth-8;
 }
 document.getElementById("midcol").style.width=midwidth+"px";
 
 if (document.getElementById("flightstats"))
 {
  document.getElementById("flightstats").style.width=midwidth+"px";
 }
 
 if (document.getElementById("bookingform"))
 {
  bfw=midwidth-22;
  document.getElementById("bookingform").style.width=bfw+"px";
 }
 
 if (document.getElementById("innercalendara"))
 {
  if (thisPage!="bookingthanks.php")
  {
   setDepartDate();
  }
  displayCalendar(month, year, "a");
  displayCalendarb()
 } 
 if (document.getElementById("midcontainer"))
 { 
  if (thisPage!="booking.php" && thisPage!="bookingthanks.php")
  {
    if (document.getElementById("midcontainer").offsetHeight=="150" && document.getElementById("selectpanel").offsetHeight<150)
    {
    document.getElementById("selectpanel").style.height="148px";
    }
    if (doonce==1)
    {
    selectheight=document.getElementById("innercalendara").offsetHeight;
    if (document.getElementById("selectform").offsetHeight<selectheight)
    {
     selectheight=selectheight-2;
     document.getElementById("selectform").style.height=selectheight+"px";
    }
  }
  document.getElementById("selectpanel").style.marginRight="0px";

  document.getElementById("selectpanel").style.width="314px";
  document.getElementById("selectpanel").style.paddingLeft="0px";   
  
  }
 }

 if (document.getElementById("outerwideflash"))
 {
  document.getElementById("outerwideflash").style.marginLeft="0px";
  document.getElementById("outerwideflash").style.marginBottom="0px"; 
 }

 if (ie6markw==2)
 {
  split=4;
 }
 else
 {
  split=2;
 }

 if (document.getElementById("midcontainer"))
 {
  if (document.getElementById("midcontainer").offsetHeight>200 && thisPage!="booking.php" && thisPage!="bookingthanks.php")
  {
   if (ie6markw==2)
   {
    document.getElementById("innercalendara").style.marginLeft="5px";
   }
   //flm=Math.round((document.getElementById("midcontainer").offsetWidth-400)/split);
   flm=Math.round((document.getElementById("midcontainer").offsetWidth-350)/split);
   document.getElementById("outerwideflash").style.marginLeft=flm+"px";
   document.getElementById("outerwideflash").style.marginBottom="5px";
   srm=Math.round((document.getElementById("midcontainer").offsetWidth-document.getElementById("selectpanel").offsetWidth)/split);
   document.getElementById("selectpanel").style.marginRight=srm+"px";
  }
  else if (document.getElementById("midcontainer").offsetHeight<=200 && thisPage!="booking.php" && thisPage!="bookingthanks.php")
  {
   if (ie6markw==2)
   {
    document.getElementById("innercalendara").style.marginLeft="5px";
   }
   spw=document.getElementById("midcontainer").offsetWidth-356;
   if (spw>314)
   {
    sppl=(spw-314)/2;
    spw=spw-sppl;
    document.getElementById("selectpanel").style.width=spw+"px";
    document.getElementById("selectpanel").style.paddingLeft=sppl+"px";
   }
  
  }
 }
  
 if (thisPage=="booking.php" && document.getElementById("selectform"))
 {
  if (ie6markw!=2)
  {
   document.getElementById("selectform").style.marginLeft="3px"; //upsets IE6 selectcot
  }
  else
  {
   document.getElementById("selectform").style.left=0;  
  }
  
  document.getElementById("outerkey").style.marginRight="4px";
  document.getElementById("selectinfo").style.marginRight="0"
  document.getElementById("selectinfo").style.width="300px";    
  
  mcw=document.getElementById("midcontainer").offsetWidth;
  cw=document.getElementById("outercalendars").offsetWidth;
  ew=document.getElementById("selectform").offsetWidth+cw;
  if (mcw<(ew+10))
  {
   sw=document.getElementById("selectform").offsetWidth;
   siw=sw-10;
   document.getElementById("selectinfo").style.width=siw+"px";
   slm=Math.round((mcw-(sw*2))/split);
   if (ie6markw!=2)
   {
    document.getElementById("selectform").style.marginLeft=slm+"px";
   }
   else
   {
    document.getElementById("selectform").style.left=slm+"px";
   }
   sirm=slm-3;
   document.getElementById("selectinfo").style.marginRight=sirm+"px";
   crm=Math.round((mcw-document.getElementById("outercalendars").offsetWidth)/split);
   document.getElementById("outerkey").style.marginRight=crm+"px";
  }
  else
  {
   siw=cw-10;
   document.getElementById("selectinfo").style.width=siw+"px";
   
  }
 }

 posProp=findPos(document.getElementById("propb"));
 posFoot=findPos(document.getElementById("footer"));
 posBot=findPos(document.getElementById("bottommarker"));
 space=posFoot-posProp;
 minSpace=backMin-(posBot-posFoot);
 if (ie6markw==2)
 {
  minSpace=minSpace-2;
 }  
 document.getElementById("propb").style.height=minSpace+"px";

 dyn = setouter+" "+setlmargin+" "+midwidth;
 setDynamics(dyn);

 externalLinks();
} 

function findPos(obj)
{
 toppos=0;
 if (obj.offsetParent)
 {
  do
  {
	 toppos += obj.offsetTop;
  }while (obj = obj.offsetParent);
 }
 return[toppos];
}


function displayCalendar(month, year, calendar) {
var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
stringMonth = allMonthString.split(",");
var nummonth=0;
while (nummonth<nummonths){
thisMonth=MonthString[nummonth].split(",");
if (thisMonth[0]==year){
 if (thisMonth[1]==stringMonth[month-1])
     displayMonth=nummonth;
}
nummonth=nummonth+1;
}

month = parseInt(month-1);
year = parseInt(year);
var i = 0;
var day = 1;
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.innerHTML="-";
nd.className="calendar-week";
nd.parentNode.className="calendar-week";
nd.parentNode.style.backgroundImage="url(images/noday.jpg)"; 
nd.style.textDecoration="none";
}

//status of last day of previous month
if (typeof MonthString[displayMonth-1]!="undefined")
{
 previousDay=MonthString[displayMonth-1].split(",");
 previousDay=previousDay[2].substring((previousDay[2].length)-1);
}
else{
previousDay="";
}

availabilityString=MonthString[displayMonth].split(",");
availabilityString=availabilityString[2];

for (i = startingPos; i < days; i++) {
 j=i+1;
 slot="slot"+calendar+j;
 nd = document.getElementById(slot);
 nd.innerHTML=i-startingPos+1;
  
 if (availabilityString.charAt(i-startingPos)=="b")
 {
  nd.className="bookedday";
  nd.style.textDecoration="line-through";
  if (previousDay=="f")
  {
   nd.title="This day is already Booked but you can Depart on this day";
  }
  else
  {
   nd.title="This day is already Booked";
  }
 }
 else if (availabilityString.charAt(i-startingPos)=="h")
 {
  nd.className="heldday";
  if (previousDay=="f")
  {
   nd.title="This day is On Hold but you can Depart on this day";
  }
  else
  {
   nd.title="This day is On Hold";
  }
 }  
 else
 {
  thisDate=new Date(year,month,day);
  for (k=0; k<=numweeks-1; k++)  //-1 added 18/6/2009
  {
   fdmy = WeekString[k+1].substring( 0, 10).split("/");
   fdate= new Date(fdmy[2],fdmy[1]-1,fdmy[0]);
   if (thisDate<fdate)
   {
    thisPrice=WeekString[k].split("|");
    thisPrice=thisPrice[3];
    break;
   }         
  }
  
  nd.className="freeday"; 
  nd.title="Weekly guide price is £"+thisPrice+" for 4 people. Click to select.";
 }

 if (nd.parentNode)
 {
 if (availabilityString.charAt(i-startingPos)=="b")
 {
  nd.parentNode.className="bookedday";
  nd.parentNode.style.backgroundImage="url(images/booked.jpg)";
  if (previousDay=="f")
  {
   nd.parentNode.style.backgroundImage="url(images/changeover.jpg)";
  }  
 }
 else if (availabilityString.charAt(i-startingPos)=="h")
 {
  nd.parentNode.style.backgroundImage="url(images/held.jpg)";
  nd.parentNode.className="heldday";
  if (previousDay=="f")
  {
   nd.parentNode.style.backgroundImage="url(images/changeoverp.jpg)";
  }  
 }  
 else
 {
  nd.parentNode.className="freeday";
  nd.parentNode.style.backgroundImage="url(images/free.jpg)";  
 }

 }
 previousDay=availabilityString.charAt(i-startingPos);
 day=day+1; 
}
}

function displayCalendarb(){
 if (document.getElementById("innercalendarb"))
 {
  monthb = month*1 + 1;
  yearb = year;
  if (monthb==13)
  {
   monthb=1;
   yearb=yearb*1 + 1;
  }
  displayCalendar(monthb, yearb, "b");
  if (thisPage!="bookingthanks.php")
  {
   showDays();
  }
 } 
}

function setDepartDate(){
if(document.getElementById('selectArriveMY').value == document.getElementById('selectDepartMY').value && document.getElementById('selectArriveD').value == document.getElementById('selectDepartD').value) //initial values
{
 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(" ");
month=newMonth[0];
year=newMonth[1];
displayCalendar(month, year, "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 changeCalendarMonthBF(){
newMonth=document.getElementById('calendarMonth').value;
newMonth=newMonth.split(" ");
month=newMonth[0];
year=newMonth[1];
displayCalendar(month, year, "a");
displayCalendarb();
var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
stringMonth = allMonthString.split(",");
document.getElementById("month2").innerHTML = stringMonth[monthb-1]+" "+yearb;
}

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();  

 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 
 aMonth=document.getElementById("CalendarForm").calendarMonth.options[document.getElementById("CalendarForm").calendarMonth.selectedIndex].value;
 aMonth=aMonth.split(" ");
 amonthIndex=(aMonth[0]*1)-1;
 document.getElementById("month2").innerHTML = stringMonth[amonthIndex]+" "+aMonth[1];

 freshYear=aMonth[1];
 if (amonthIndex==0) 
 {
  freshYear=(freshYear*1)-1
  amonthIndex=12
 }

 numOpts=(document.getElementById("CalendarForm").calendarMonth.options.length);
 for (i=0; i<numOpts; i++)
 {
  if (document.getElementById("CalendarForm").calendarMonth.options[i].value==amonthIndex+" "+freshYear)
  {
   document.getElementById("CalendarForm").calendarMonth.selectedIndex = i;
   break;   
  }
}
    
}
}
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();

 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 bMonth = document.getElementById("month2").innerHTML.split(" ");
 for (var i=1; i<13; i++)
 {
  if (stringMonth[i-1]==bMonth[0])
  {
   break;
  }
 }
 amonthIndex=i;

 numOpts=(document.getElementById("CalendarForm").calendarMonth.options.length);
 for (i=0; i<numOpts; i++)
 {
  if (document.getElementById("CalendarForm").calendarMonth.options[i].value==amonthIndex+" "+bMonth[1])
  {
   document.getElementById("CalendarForm").calendarMonth.selectedIndex = i;
   break;
  }
 }
 
 i=amonthIndex;
 freshYear=bMonth[1];
 if (i==12)
 {
  freshYear=(freshYear*1)+1
  i=0;
 }
 document.getElementById("month2").innerHTML = stringMonth[i]+" "+freshYear;
}
}


function changeArrivalMonth(){
newMonth=document.getElementById('selectArriveMY').value;
setSession("selectArriveMY", newMonth);
setSession("selectArriveD", document.getElementById('selectArriveD').value);
newMonth=newMonth.split(" ");
month=newMonth[0];
year=newMonth[1];
displayCalendar(month, year, "a");

numOpts=(document.getElementById("CalendarForm").calendarMonth.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.getElementById("CalendarForm").calendarMonth.options[i].value==newMonth[0]+" "+newMonth[1])
 {
  document.getElementById("CalendarForm").calendarMonth.selectedIndex = i;  
 }
}

if (thisPage=="booking.php")
{
 var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
 stringMonth = allMonthString.split(",");
 freshYear=newMonth[1];
 freshMonth = (newMonth[0]*1)+1;
 if (freshMonth==13)
 {
  freshYear=(freshYear*1)+1
  freshMonth=1;
 }
 document.getElementById("month2").innerHTML = stringMonth[freshMonth-1]+" "+freshYear;  
 displayCalendar(freshMonth, freshYear, "b");
 showDays();
}

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();
}
displayCalendarb();
var allMonthString="January,February,March,April,May,June,July,August,September,October,November,December";
stringMonth = allMonthString.split(",");
document.getElementById("month2").innerHTML = stringMonth[monthb-1]+" "+yearb;
}

function changeSelectedDate(fieldName, fieldValue){
setSession(fieldName, fieldValue);
showDays();
}

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.getElementById("selectform").selectDepartD.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.getElementById("selectform").selectDepartD.options[i].value==departDs)
 {
  document.getElementById("selectform").selectDepartD.selectedIndex = i;
 }
}
numOpts=(document.getElementById("selectform").selectDepartMY.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.getElementById("selectform").selectDepartMY.options[i].value==departMY)
 {
  document.getElementById("selectform").selectDepartMY.selectedIndex = i;
 }
}
setSession("selectDepartMY", departMY);
setSession("selectDepartD", departDs);
}

function clickDate(here){
if (document.getElementById(here).value=="-")
{
 return(true);
}
if(thisPage!="bookingthanks.php")
{

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("calendarMonth").value.split(" ");
  newMonth = thisSelection[0];
 }
 else
 {
  thisSelection = document.getElementById("month2").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.getElementById("selectform").selectArriveD.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.getElementById("selectform").selectArriveD.options[i].value==newDay)
 {
  document.getElementById("selectform").selectArriveD.selectedIndex = i;
 }
}
arrivalString = newMonth+" "+newYear;
numOpts=(document.getElementById("selectform").selectArriveMY.options.length);
for (i=0; i<numOpts; i++)
{
 if (document.getElementById("selectform").selectArriveMY.options[i].value==arrivalString)
 {
  document.getElementById("selectform").selectArriveMY.selectedIndex = i;
 }
}
setSession("selectArriveMY", document.getElementById('selectArriveMY').value);
setSession("selectArriveD", document.getElementById('selectArriveD').value);
departOneWeek();
if (thisPage=="booking.php")
{
 showDays();
 document.getElementById("fadera").src="images/nofade.gif";
 document.getElementById("faderd").src="images/nofade.gif";
 document.getElementById("fadera").src="images/fade.gif";
 document.getElementById("faderd").src="images/fade.gif";
}
}
}

function showDays(){
var SelectedD=document.getElementById("selectform").selectArriveD.options[document.getElementById("selectform").selectArriveD.selectedIndex].value;
var SelectedMY=document.getElementById("selectform").selectArriveMY.options[document.getElementById("selectform").selectArriveMY.selectedIndex].value;
thisDay=getDayString(SelectedD, SelectedMY);
thisSelection=thisDay.split(",");
document.getElementById("selectform").arriveString.value=thisSelection[0];

stringMY = SelectedMY.split(" ");
ad = new Date(stringMY[1], stringMY[0]-1, SelectedD).getTime();

SelectedD=document.getElementById("selectform").selectDepartD.options[document.getElementById("selectform").selectDepartD.selectedIndex].value;
SelectedMY=document.getElementById("selectform").selectDepartMY.options[document.getElementById("selectform").selectDepartMY.selectedIndex].value;
thisDay=getDayString(SelectedD, SelectedMY);
thisSelection=thisDay.split(",");
document.getElementById("selectform").departString.value=thisSelection[0];

stringMY = SelectedMY.split(" ");
dd = new Date(stringMY[1], stringMY[0]-1, SelectedD).getTime();

numDaysString=Math.floor((dd-ad)/86400000);
numDaysString="("+numDaysString+" days";
if (((dd-ad)/86400000)<=0)
{
 document.getElementById("selectform").numDaysString.style.color="#A00000";
 numDaysString=numDaysString+"!!)";
}
else
{
  document.getElementById("selectform").numDaysString.style.color="#535352";
  numDaysString=numDaysString+")";
}
document.getElementById("selectform").numDaysString.value=numDaysString;
}

function getDayString(SelectedD, SelectedMY){
var allDayString = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
stringMY = SelectedMY.split(" ");
var SelectedDate=new Date();
howmany=getDaysInMonth(stringMY[0],stringMY[1]);
if (SelectedD>howmany){
 SelectedD=howmany;
}
SelectedDate.setFullYear(stringMY[1],stringMY[0]-1,SelectedD)
SelectedDay = allDayString[SelectedDate.getDay()];
return(SelectedDay+","+SelectedD);
}   


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 sendEntryK(e)
{
 var keycode;
 if (window.event){
  keycode = window.event.keyCode;
 }
 else if (e && e.which){
  keycode = e.which;
 }
 else {
  return true;
 }
 if (keycode==13){
  sendAbuse();
 }
}

function sendEntry()
{
 if (document.getElementById("EntryForm").turing.value=="" || document.getElementById("EntryForm").entryname.value=="" || document.getElementById("EntryForm").entryemail.value=="")
 {
 
  alert("All fields are required.  Please complete the form and copy the turing code into the box.")
  return;
 }
 else
 {
  document.getElementById("EntryForm").action = "comments.php";
  document.getElementById("EntryForm").submit();
 }
}

function sendEditK(e)
{
 var keycode;
 if (window.event){
  keycode = window.event.keyCode;
 }
 else if (e && e.which){
  keycode = e.which;
 }
 else {
  return true;
 }
 if (keycode==13){
  sendAbuse();
 }
}

function sendEdit()
{
 if (document.getElementById("EntryForm").entryname.value=="" || document.getElementById("EntryForm").entryemail.value=="")
 {
 
  alert("All fields are required.  Please complete the form.")
  return;
 }
 else
 {
  document.getElementById("EntryForm").action = "comments.php";
  document.getElementById("EntryForm").submit();
 }
}

function confirmDelete(question, where)
{
 temp = window.confirm(question);
 if (temp) //delete
 {
  document.location.href=where;  
 }
}

function fieldchange1(id){
value=document.getElementById(id).value;
setSession(id,value);
}
function fieldchange(name,value){
setSession(name,value);
}

function changeUnder5(){
under5s=document.getElementById("selectform").childUnder5.options[document.getElementById("selectform").childUnder5.selectedIndex].value;
if (under5s>0)
{
 document.getElementById("selectcot").style.display="block";
 document.getElementById("selectform").cot.options.length = 0;
 cotoption="";
 j=(under5s*1)+1;
 for (i=0; i<j; i++)
 {
  document.getElementById("selectform").cot.options[i] = new Option(i, i);
 }
 setSession("childUnder5", under5s);
 setSession("cot", "0");
}
else
{
 document.getElementById("selectcot").style.display="none";
}
}

function checkAvailK(e){
var keycode;
if (window.event){
 keycode = window.event.keyCode;
}
else if (e && e.which){
 keycode = e.which;
}
else {
 return true;
}
if (keycode==13){
 checkAvail();
}
}
function checkAvail(){
var SelectedD=document.getElementById("selectform").selectArriveD.options[document.getElementById("selectform").selectArriveD.selectedIndex].value;
var SelectedMY=document.getElementById("selectform").selectArriveMY.options[document.getElementById("selectform").selectArriveMY.selectedIndex].value;
stringMY = SelectedMY.split(" ");

dim=getDaysInMonth(stringMY[0],stringMY[1])
if (SelectedD>dim)
{
 SelectedD=dim;
 document.getElementById("selectform").selectArriveD.options[document.getElementById("selectform").selectArriveD.selectedIndex].value=dim;
}

ad = new Date(stringMY[1], stringMY[0]-1, SelectedD).getTime();

SelectedD=document.getElementById("selectform").selectDepartD.options[document.getElementById("selectform").selectDepartD.selectedIndex].value;
SelectedMY=document.getElementById("selectform").selectDepartMY.options[document.getElementById("selectform").selectDepartMY.selectedIndex].value;
stringMY = SelectedMY.split(" ");

dim=getDaysInMonth(stringMY[0],stringMY[1])
if (SelectedD>dim)
{
 SelectedD=dim;
 document.getElementById("selectform").selectDepartD.options[document.getElementById("selectform").selectDepartD.selectedIndex].value=dim;
}

dd = new Date(stringMY[1], stringMY[0]-1, SelectedD).getTime();

tomorrow= new Date(servertime).getTime()+86400000;

if (ad<tomorrow)
{
 alert("The arrival date is too early! Please select another date.");
 return
}
if (dd<=ad)
{
 alert("You cannot depart before you arrive! Please select another date.");
 return
}
document.getElementById("selectform").action = "booking.php#selectform";
document.getElementById("selectform").submit();
}

function setToPay()
{
 currency=document.forms['BookingForm'].topay.selectedIndex;
 if (currency==0 || currency == 2)
 {
  currency="GBP";
 }
 else
 {
  currency="EUR";
 }
 setCurrency(currency);
}

function finalCheckK(e){
var keycode;
if (window.event){
 keycode = window.event.keyCode;
}
else if (e && e.which){
 keycode = e.which;
}
else {
 return true;
}
if (keycode==13){
finalCheck();
}
}
function finalCheck(){
 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 sendEnquiryK(){
var keycode;
if (window.event){
 keycode = window.event.keyCode;
}
else if (e && e.which){
 keycode = e.which;
}
else {
 return true;
}
if (keycode==13){
 sendEnquiry();
}
}
function sendEnquiry(){
 required=0;
 document.getElementById("labelname").style.color="#0000FF";
 document.getElementById("labelemail").style.color="#0000FF";
 document.getElementById("labelenquiry").style.color="#0000FF";
 if (document.EnquiryForm.Name.value=="")
 {
  document.getElementById("labelname").style.color="#AA0000";
  required=1;  
 }
 if (document.EnquiryForm.email.value=="")
 {
  document.getElementById("labelemail").style.color="#AA0000";
  required=1;  
 } 
 if (document.EnquiryForm.enquiry.value=="")
 {
  document.getElementById("labelenquiry").style.color="#AA0000";
  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 submitBookReqK(e){
var keycode;
if (window.event){
 keycode = window.event.keyCode;
}
else if (e && e.which){
 keycode = e.which;
}
else {
 return true;
}
if (keycode==13){
 submitBookReq();
}
}
function submitBookReq(){
 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 checkRequired()
{
 required=0;
 document.getElementById("labelname").style.color="#0000FF";
 document.getElementById("labelemail").style.color="#0000FF";
 document.getElementById("labeladdress").style.color="#0000FF";
 document.getElementById("labelrelationship").style.color="#0000FF";
 if (document.BookingForm.Name.value=="")
 {
  document.getElementById("labelname").style.color="#AA0000";
  required=1;  
 } 
 if (document.BookingForm.email.value=="")
 {
  document.getElementById("labelemail").style.color="#AA0000";
  required=1;  
 } 
 if (document.BookingForm.Address.value=="")
 {
  document.getElementById("labeladdress").style.color="#AA0000";
  required=1;  
 }
 if (document.BookingForm.Relationship.value=="")
 {
  document.getElementById("labelrelationship").style.color="#AA0000";
  required=1;  
 }
 return (required);
}

function checkBookingErrorStatus()
{
document.location.href="bookingthanks.php";
}


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 leftarrowover(name){
document[name].src="images/leftarrowon.gif";
}
function leftarrowout(name){
document[name].src="images/leftarrow.gif";
}
function rightarrowover(name){
document[name].src="images/rightarrowon.gif";
}
function rightarrowout(name){
document[name].src="images/rightarrow.gif";
}

function showsame(thisone) { 
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
    if (anchors[i].getAttribute("href")==thisone)
    anchors[i].style.backgroundColor = "#FFFF00"; 
 } 
}
function hidesame(thisone) { 
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
    if (anchors[i].getAttribute("href")==thisone)
    anchors[i].style.backgroundColor = "transparent";
 } 
}

function navOn(here){
here.style.backgroundPosition="0 -5px";
//here.style.backgroundColor="#FFFFFF";
//here.style.backgroundImage="url(images/navbackin.jpg)";
}

function navOff(here){
here.style.backgroundPosition="center";
//here.style.backgroundColor="#FCEECC";
//here.style.backgroundImage="url(images/navback.jpg)";
}


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 increase()
{
 size=document.getElementById("main").style.fontSize.replace("em","");
 size=Math.round(size*100)/100;
 if (size<1.8)
 {
  if (size<0.7)
  {
   size=0.75;
  }
  else if (size<1)
  {
   size=Math.round((size+0.1)*100)/100;
  }  
  else if (size<1.15)
  {
   size=Math.round((size+0.05)*100)/100;
  }
  else
  {
   size=Math.round((size+0.1)*100)/100;
  } 
  document.getElementById("main").style.fontSize=size+"em";
 }
 doHeights();
 setSize(size);
}
function decrease()
{
 size=document.getElementById("main").style.fontSize.replace("em","");
 size=Math.round(size*100)/100;
 if (size>0.5)
 {
  size=Math.round((size-0.1)*100)/100;
 } 
 document.getElementById("main").style.fontSize=size+"em";
 setSize(size);
 doHeights();
}
function reset()
{
 document.getElementById("main").style.fontSize="0.8em";
 setSize(0.8);
 doHeights();
}

function doHeights(){
if (thisPage!="booking.php" && thisPage!="bookingthanks.php")
{
 ca=document.getElementById("innercalendara").offsetHeight;
 hh=Math.round(size*25);
 
 if (document.getElementById("selectpanel").offsetHeight<(ca+hh))
 {
  document.getElementById("selectform").style.height=ca+"px";
  sp=ca+hh;
  document.getElementById("selectpanel").style.height=sp+"px";   
 }
 
 

 if (document.getElementById("selectform").offsetHeight>ca+2)
 {
  sf=ca-2;
  document.getElementById("selectform").style.height=sf+"px";
  if (ca<150)
  {
   document.getElementById("selectpanel").style.height="148px";
  }
  else
  {
   sp=ca+hh;
   document.getElementById("selectpanel").style.height=sp+"px";
  }  
 }
 
 if (document.getElementById("selectform").offsetHeight<ca-2)
 {
  sf=ca-2;
  document.getElementById("selectform").style.height=sf+"px";
 }
} 
}

var sizeObject;
function setSize(size){
 if (sizeObject) 
 {
  document.body.removeChild(sizeObject);
 }
 sizeObject = document.createElement("script");
 sizeObject.src = "setsize.php?size="+size;
 sizeObject.type = "text/javascript";
 document.body.appendChild(sizeObject);
}


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);
}

var logObject;
function writeLog(h, w, httpaccept){
 if (logObject) 
 {
  document.body.removeChild(logObject);
 }
 logObject = document.createElement("script");
 logObject.src = "writelog.php?width="+w+"&height="+h+"&httpaccept="+httpaccept;
 logObject.type = "text/javascript";
 document.body.appendChild(logObject);
}

var xrateObject;
function getXrate(){
 if (xrateObject) 
 {
  document.body.removeChild(xrateObject);
 }
 xrateObject = document.createElement("script");
 xrateObject.src = "readrss.php";
 xrateObject.type = "text/javascript";
 document.body.appendChild(xrateObject);
}

var currencyObject;
function setCurrency(currency){
 if (currencyObject) 
 {
  document.body.removeChild(currencyObject);
 }
 currencyObject = document.createElement("script");
 currencyObject.src = "setcurrency.php?currency="+currency;
 currencyObject.type = "text/javascript";
 document.body.appendChild(currencyObject);
}
