/**
 * Global array of known mobile agents. Recommended method of detecting mobile user by iHotelier.
 * TODO: The downside of detecting mobile browser by user agent is that technology changes rapidly and this list
 * is growing quickly. This list will constantly need to be maintained. If a better method of detecting a mobile
 * user agent is found, it should be implemented here instead of detecting by user agent.
 */
var aMobileAgents = ['palm', 'palmos', 'webos', 'palmsource', 'iphone', 'blackberry', 'nokia', 'phone', 'midp', 'mobi', 'pda', 'wap', 'java', 'nokia', 'hand', 'symbian', 'chtml', 'wml', 'ericsson', 'lg', 'audiovox', 'motorola', 'samsung', 'sanyo', 'sharp', 'telit', 'tsm', 'mobile', 'mini', 'windows ce', 'smartphone', '240x320', '320x320', 'mobileexplorer', 'j2me', 'sgh', 'portable', 'sprint', 'vodafone', 'docomo', 'kddi', 'softbank', 'pdxgw', 'j-phone', 'astel', 'minimo', 'plucker', 'netfront', 'xiino', 'mot-v', 'mot-e', 'portalmmm', 'sagem', 'sie-s', 'sie-m', 'android', 'ipod'];

// global variables for the two different URL's for iHotelier booking pages
var g_strIHotelierStandard = 'https://booking.ihotelier.com/istay/istay.jsp?hotelid=6263';
var g_strIHotelierMobile = 'https://mobile.ihotelier.com/mbe/mobile/6263';

/**
 * Returns true or false depending on whether the user agent string is recognizable as a mobile user agent from the
 * list above.
 * @return boolean true if current user agent is a recognized mobile device, false otherwise
 */
function isMobileAgent() {
   var strAgent = navigator.userAgent.toLowerCase();
   var bIsMobile = false;
   if(strAgent.indexOf('ipad')) return false;
   for(var i=0;i<aMobileAgents.length;i++) {
      if(strAgent.indexOf(aMobileAgents[i]) > -1) {
         bIsMobile = true;
         break;
      }
   }
   return bIsMobile;
}
    if(isMobileAgent()) {
       top.document.location.href=g_strIHotelierMobile;
    }

/**
 * Sets the booking action of the given form to the mobile iHotelier site depending on whether
 * the current user agent is a recognized mobile device.
 * @param frm - DOM reference to the booking mask form.
 * @return true so the form can be submitted. This function is called in the form's onSubmit event.
 */
function setBookingAction(frm) {
   if(isMobileAgent()) {
      window.location = g_strIHotelierMobile;
   } else {
      frm.action = g_strIHotelierStandard;
      frm.submit();
   }
}


