// Validate Form

function validateForm2(){


var formfill="";

if( document.getElementById('Name').value =="")
{formfill += '\r\nName ';}

if( document.getElementById('Address').value =="")
{formfill += '\r\nAddress ';}

if( document.getElementById('Postcode').value =="")
{formfill += '\r\nPostcode ';}

if( document.getElementById('TelephoneNumber').value =="")
{formfill += '\r\nTelephoneNumber ';}

if( document.getElementById('Mobile').value =="")
{formfill += '\r\nMobile ';}

 if( document.getElementById('Email').value =="")
{formfill += '\r\nEmail';}


if(formfill=="")
{
  return true;
}
else{
alert("The Required fields are: \r\n"+formfill);
  return false;
}
}







function validateForm(form, requiredFields){
	
	invalidFields = new Array();
	
	for(i = 0; i < requiredFields.length; i++){
		currentValue = form[requiredFields[i]].value;
		
		if(currentValue == ""){
			invalidFields.push(requiredFields[i]);
		}
	}
	
	if(invalidFields.length == 0){
		return true;
	}else{
		errorString = "These fields are required: ";
		
		for(j = 0; j < invalidFields.length; j++){
			if(j==0){
				errorString += requiredFields[j];
			}
			else{
				errorString += ", " + requiredFields[j];
			}
		}	
					
		alert(errorString);
		return false;
	}
}

// Gallery
function showPic(whichpic)
{
	if(document.getElementById)
	{
		var largepic = document.getElementById('placeholder');
		largepic.src = whichpic.href;
		
		if (whichpic.title) {
			largepic.alt = whichpic.title;
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
		}
		else
		{
			largepic.alt = whichpic.childNodes[0].nodeValue;
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	}
	else
	{
		return true;
	}
}

// Rollovers

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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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];}
}

// Get Object

function getObj(name){
	if (document.getElementById){
		return document.getElementById(name);
	}else if (document.all){
		return document.all[name];
	}else if (document.layers){
		return document.layers[name];
	}
}

// Pop up window

    function popitup(url,w,h) {
        var newwindow = '';
        var features = 'width=' + w + ',height=' + h + ',top=' + 200 + ',left=' + 200 ;
        newwindow = window.open(url,'name', features );
        if(window.focus){newwindow.focus()}
        return false;
    }
    
//Add Onload Event

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

//Booking Form

//Javascript for Booking Component//

function updateStart(cal)
{
    var date = document.getElementById("DateIn");
    var arr = date.value.split("/");
    var selectedYear = "";
    
    document.getElementById('month').selectedIndex = arr[0]-1;
    document.getElementById('day').selectedIndex = arr[1]-1;
  
    for(i=0; i<2; i++){
    if(document.getElementById('year').options[i].text == arr[2]){
           
          document.getElementById('year').selectedIndex = i;
      }
   }
}

function assembleDate() {
         var theMonth= document.getElementById('month')[document.getElementById('month').selectedIndex].value;
         var theDay= document.getElementById('day')[document.getElementById('day').selectedIndex].value;
         var theYear= document.checkaressrch.year[document.checkaressrch.year.selectedIndex].text;

         document.getElementById('DateIn').value = theMonth + "/" + theDay + "/" + theYear;

}

//set todays date

Now = new Date();

NowDay = Now.getDate();

NowMonth = Now.getMonth();

NowYear = Now.getYear();

if (NowYear < 2000) NowYear += 1900; //for Netscape



// set tomorrows date

var tomorrow = new Date(Now.getTime() + (1 * 86400000));

tDay = tomorrow.getDate();

tMonth = tomorrow.getMonth();

tYear = tomorrow.getYear();

if (tYear < 2000) tYear += 1900; //for Netscape



//function for returning how many days there are in a month including leap years

function DaysInMonth(WhichMonth, WhichYear)

{

var DaysInMonth = 31;

if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;

if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))DaysInMonth = 28;

if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))DaysInMonth = 29;

return DaysInMonth;

}



//function to change the available days in a months

function ChangeOptionDays()

{

DaysObject = eval("document.checkaressrch.day");

MonthObject = eval("document.checkaressrch.month");

YearObject = eval("document.checkaressrch.year");


Month = MonthObject[MonthObject.selectedIndex].text;

Year = YearObject[YearObject.selectedIndex].text;

DaysForThisSelection = DaysInMonth(Month, Year);

CurrentDaysInSelection = DaysObject.length;

if (CurrentDaysInSelection > DaysForThisSelection)

{

for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)

{

DaysObject.options[DaysObject.options.length - 1] = null

}

}

if (DaysForThisSelection > CurrentDaysInSelection)

{

for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)

{

NewOption = new Option(DaysObject.options.length + 1);

DaysObject.options.add(NewOption);

}

}

if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;


assembleDate();
}



//function to set options to tomorrow

function SetToToday()
{

DaysObject = eval("document.checkaressrch.day");

MonthObject = eval("document.checkaressrch.month");

YearObject = eval("document.checkaressrch.year");



YearObject[0].selected = true;

MonthObject[tMonth].selected = true;

ChangeOptionDays();

DaysObject[tDay-1].selected = true;

assembleDate();
}



//function to write option years plus x

function WriteYearOptions(YearsAhead)

{

line = "";

for (i=0; i<YearsAhead; i++)

{

line += "<OPTION>";

line += NowYear + i;

line += "</OPTION>";

}

return line;

}
