/*********Detect user device and adjust presentation************/

function setBodyStyle()
{
  var cWidth    = document.documentElement.clientWidth;
  var bodyClass = '';
  if ( cWidth < 800 ) bodyClass += 'small';
  if ( cWidth < 480 ) bodyClass += ' smaller';
  document.body.className = bodyClass;
}

window.onload   = setBodyStyle;
window.onresize = setBodyStyle;

/*********Feedback form date picker************/

monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
	
		function populateDays(monthChosen) {
			monthStr = monthChosen.options[monthChosen.selectedIndex].value
			if (monthStr != "") {
				theMonth=parseInt(monthStr)
							
				document.getElementById('responseForm').days.options.length = 0
				for(i=0;i<monthDays[theMonth];i++) {
					document.getElementById('responseForm').days.options[i] = new Option(i+1)
				}
			}
		}

/***************************************************************************
 * Function: loadSlideFunctions(), setSlideNumber(), preLoadSlideImages()  *
 * Purpose:  Provide user controlled image slide show                      *
 *                                                                         *
 * Author:   Adapted from existing code by Chris Reeve                     *
 * Date:     25 March 2007                                                 *
 *                                                                         *
 * Notes:    This script was adapted from a combination of Negrino, T      *
 *           and Smith, D (2004). "Javascript for the World Wide Web:      *
 *           Fifth Edition." pp 92. Peachpit Press, USA, and               *
 *           http://www.ricocheting.com/js/slide2.html                     *
 *           [site accessed 25 March 2007]                                 *
 *                                                                         *
 **************************************************************************/

//create array to hold image locations and description
accomimage = new Array();
accomimage[0]=["images/living-area.jpg", "Living area - Spacious, air conditioned living area with two comfortable sofas, one of which converts to double bed. TV with Sky, DVD player, books, games and magazines. Patio doors lead to large terrace."];
accomimage[1]=["images/dining-area.jpg", "Dining area - Tastefully decorated dining area with eight comfortable upholstered chairs conveniently located adjacent to an archway leading from the fully equipped kitchen."];
accomimage[2]=["images/kitchen.jpg", "Kitchen - Modern kitchen with halogen lighting.  Fully equipped with oven, ceramic hob, large fridge/freezer, dishwasher, microwave, washing machine, electric kettle and toaster."];
accomimage[3]=["images/ground-floor-terrace.jpg", "Ground floor terrace - Spacious outdoor sun terrace catching the sun from early morning to late evening. Furnished for eight people for al fresco dining or simply relaxing in the sunshine on the reclining chairs. The terrace is accessed via patio doors from the living room and ground floor bedroom."];
accomimage[4]=["images/terrace.jpg", "First floor terrace - Leading from first floor double bedroom with table and chairs and lovely sea views."];
accomimage[5]=["images/roof-terrace.jpg", "Roof terrace - A spiral staircase leads to the private roof terrace with dining facilities, BBQ, sunbeds, brollies and stunning views to the mountains and sea. The terrace enjoys sunshine from early morning until sunset."];
accomimage[6]=["images/bedroom1.jpg", "Bedroom 1 - Double bedroom located on the ground floor with patio doors to terrace. There is air conditioning, large double wardrobes and plenty of drawer space and hairdryer. Ensuite bathroom with full size bath, shower, WC, basin and heated towel rail for cooler winter evenings."];
accomimage[7]=["images/bedroom2.jpg", "Bedroom 2 - First floor double bedroom with patio doors leading to upper terrace. There is air conditioning, large wardrobes and plenty of drawer space and hairdryer. Ensuite bathroom with full size bath, shower, WC, basin and heated towel rail for cooler winter evenings."];
accomimage[8]=["images/bedroom3.jpg", "Bedroom 3 - First floor twin bedroom  with juliet balconi and sea views. There is air conditioning, large double wardrobes and plenty of drawer space and hairdryer. Ensuite bathroom with full size bath, shower, WC, basin and heated towel rail for cooler winter evenings."];
accomimage[9]=["images/bathroom.jpg", "Bathroom - All bedrooms have en suite bathrooms each with bath, shower, WC and heated towel rail"];
accomimage[10]=["images/landing.jpg", "Landing - Marble stairs lead to a spacious landing. A safety gate is provided with fittings for the top or bottom of the staircase. In addition to the bedrooms, the landing area may be used to locate the large travel cot available."];
accomimage[11]=["images/garage.jpg", "Basement garage - A private lockable garage is available for the sole use of our guests and is located in the basement area under the villa. Road access is via two remote operated doors in the community grounds."];
accomimage[12]=["images/access.jpg", "A pedestrian gate gives level access to the pathway which leads to rear entrance door of the property. As there are no steps to climb the property is suitable for small children and those with limited mobility."];

function loadSlideFunctions()
{
	//preload all pan images into browser
	preLoadSlideImages();

	//set the first pan slide
	setSlideNumber(0);
}

//function to preload all the pan images by creating new instance of image object for each slide
function preLoadSlideImages()
{
  if (document.images)  //check browser supports images object
	for(var counter=0;counter<accomimage.length;counter++)
	{
	  accomimage[counter][0]=new Image().src=accomimage[counter][0];
	}
}

var imageCounter=0;

function setSlideNumber(num)
{
 	if (document.getElementById);  //check browser for DOM support
	imageCounter=num;

	//change the accommodation image
	document.images.imgslide.src=accomimage[imageCounter][0];

	//change the accommodation description to match the slide
	document.getElementById('slidebox').innerHTML=accomimage[imageCounter][1];
}

//Google map function
function load() {
		  var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,15));
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(36.74346, -3.90535), 11);
				var point = (new GLatLng(36.74346, -3.90535));
				map.addOverlay(new GMarker(point));
				map.addControl(new GSmallMapControl(),bottomRight);
      }
    }


//form validation

function validateForm(passval)
{
  if (!surname(passval)) return false;  //if entered data fails validation, return false and stop submission until corrected
  if (!Email(passval)) return false;
	if (!Phone(passval)) return false;
	if (!Enquiry(passval)) return false;
  return true;
}

function surname(passval)
{
   if (passval.realname.value == '') //if no surname has been entered, flash an alert
   {
      //get the current style of the 'blankname' div and change the display property to block to show error message
     var blankfield = document.getElementById('blankname').style;
     blankfield.display = "block";
		 return false;
   }
   else
   {
	 //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankname').style;
  blankfield.display = "none";
  return true;
   }
}

function Email(passval)
{
  //define regular expression to test for email address abcdef@bleah.co.uk or abcdef@bleah.com
  var validemail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  if (passval.email.value == '') //if no email address has been entered, flash an alert
  {
     //get the current style of the 'blankemail' div and change the display property to block to show error message
     var blankfield = document.getElementById('blankemail').style;
     blankfield.display = "block";
		 return false;
  }
  else
  {
  if (!validemail.test(passval.email.value))//perform email check, if not required format, flash an alert
  {
  //get the current style of the 'blankemail' div and change the display property to none to hide error message
	//display wrongemail div
     var blankfield = document.getElementById('blankemail').style;
  blankfield.display = "none";
		 var blankfield = document.getElementById('wrongemail').style;
     blankfield.display = "block";
		 return false;
  }
  else
  {
	//if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankemail').style;
  blankfield.display = "none";
	var wrongfield = document.getElementById('wrongemail').style;
  wrongfield.display = "none";
  return true;
  }
  }
}

function Phone(passval)
{
  if (passval.phone.value == '') //if no phone number has been entered, flash an alert
  {
     //get the current style of the 'blankemail' div and change the display property to block to show error message
     var blankfield = document.getElementById('blankphone').style;
     blankfield.display = "block";
		 return false;
  }
  else
  {
  return true;
  }
}

function Enquiry(passval)
{
   if (passval.message.value == '') //if no enquiry text has been entered, flash an alert
   {
      //get the current style of the 'blankmessage' div and change the display property to block to show error message
     var blankfield = document.getElementById('blankenquiry').style;
     blankfield.display = "block";
		 return false;
   }
   else
   {
	 //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankenquiry').style;
  blankfield.display = "none";
  return true;
   }
}


function validateFeedback(passval)
{
  if (!name(passval)) return false;  //if entered data fails validation, return false and stop submission until corrected
  if (!email(passval)) return false;
	if (!date(passval)) return false;
	if (!feedback(passval)) return false;
	return true;
}


function name(passval)
{
   if (passval.name.value == '') //if no surname has been entered, flash an alert
   {
      //get the current style of the 'blankname' div and change the display property to block to show error message
     var blankfield = document.getElementById('noname').style;
     blankfield.display = "block";
		 return false;
   }
   else
   {
	 //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('noname').style;
  blankfield.display = "none";
  return true;
   }
}

function email(passval)
{
  //define regular expression to test for email address abcdef@bleah.co.uk or abcdef@bleah.com
  var validemail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  if (passval.email.value == '') //if no email address has been entered, flash an alert
  {
     //get the current style of the 'blankemail' div and change the display property to block to show error message
     var blankfield = document.getElementById('noemail').style;
     blankfield.display = "block";
		 return false;
  }
  else
  {
  if (!validemail.test(passval.email.value))//perform email check, if not required format, flash an alert
  {
  //get the current style of the 'blankemail' div and change the display property to none to hide error message
	//display wrongemail div
     var blankfield = document.getElementById('noemail').style;
  blankfield.display = "none";
		 var blankfield = document.getElementById('bademail').style;
     blankfield.display = "block";
		 return false;
  }
  else
  {
	//if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('noemail').style;
  blankfield.display = "none";
	var wrongfield = document.getElementById('bademail').style;
  wrongfield.display = "none";
  return true;
  }
  }
}

function date(passval)
{
if (passval.months.selectedIndex == 0) //if no month has been selected
  {
   //get the current style of the 'nomonth' div and change the display property to block to show error message
     var blankfield = document.getElementById('nomonth').style;
     blankfield.display = "block";
		 return false;
   }
   else
   {
	 //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('nomonth').style;
  blankfield.display = "none";
  return true;
   }
}

function feedback(passval)
{
   if (passval.feedbacktext.value == '') //if no enquiry text has been entered, flash an alert
   {
      //get the current style of the 'blankmessage' div and change the display property to block to show error message
     var blankfield = document.getElementById('nofeedback').style;
     blankfield.display = "block";
		 return false;
   }
   else
   {
	 //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('nofeedback').style;
  blankfield.display = "none";
  return true;
   }
}

/***************************************************************************
* Function:  showfeedback(val)                                             *
*                                                                          *
* Parameter: val (number to concatenate with div name)                     *
* Purpose:   Change display propery of div to block and reveal full guest  *
*            feedback comments                                             *
*                                                                          *
* Author:    Chris Reeve                                                   *
* Date:      April 2008                                                    *
***************************************************************************/

function showfeedback(val)
{
var ShowDiv = document.getElementById('hiddenfeedback'+val).style;
ShowDiv.display = "block";
}

function visiblefeedback(val)
{
var ShowDiv = document.getElementById('visiblefeedback'+val).style;
ShowDiv.display = "block";
}