/*********Detect user device and adjust presentation************************
* Function:  setBodyStyle()                                                *
* Purpose:   Set body style based on width of client device                *
* Author:    From .net magazine article                                    *
***************************************************************************/

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;

/***************************************************************************
* Function:  populateDays(monthChosen)                                     *
* Parameter: monthChosen                                                   *
* Purpose:   Populate form select field with number of days of month       *
*                                                                          *
* Author:    Chris Reeve                                                   *
* Date:      November 2007                                                 *
*                                                                          *
* Notes:     Function called from customer feedback form when month        *
*            selected from drop down list                                  *
***************************************************************************/

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:  load()                                                        *
* Purpose:   Load google map                                               *
* Author:    Google                                                        *
***************************************************************************/
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.8037, -3.9334), 11);
  var point = (new GLatLng(36.8037, -3.9334));
  map.addOverlay(new GMarker(point));
  map.addControl(new GSmallMapControl(),bottomRight);
  }
}

/***************************************************************************
* Function:  validateForm(pasval), surname(passval), Email(passval),       *
*            Phone(passval), Enquiry(passval)                              *
* Parameter: passval (value of corresponding form field)                   *
* Purpose:   Validate user form fields against regular expressions and     *
*            provide error feedback                                        *
*                                                                          *
* Author:    Chris Reeve                                                   *
* Date:      July 2007                                                     *
***************************************************************************/

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(pasval), name(passval), email(passval),      *
*            date(passval), feedback(passval)                              *
* Parameter: passval (value of corresponding form field)                   *
* Purpose:   Validate user form fields against regular expressions and     *
*            provide error feedback                                        *
*                                                                          *
* Author:    Chris Reeve                                                   *
* Date:      July 2007                                                     *
***************************************************************************/
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";
}

