    var popupPanel = new YAHOO.widget.Panel("popupPanel",
    {
      width:    "645px",
      //context: ["main_body", "tl", "tl", null, [-12,-12]],
      constraintoviewport: false,
      close:     true,
      fixedcenter: false,
      visible:   false,
      zIndex:   105,
      underlay: "matte",
      draggable: true,
      dragOnly: true
    });


//    listen for the close/hide event to reset the size by removing class
//    popupPanel.subscribe("hide", function() { DOM.removeClass("popupPanel", 'popup_panel_availsearch'); })

    // work around IE 6/7 rendering race condition
    // see http://www.technovelty.org/code/web/yui-rendering.html
    renderPopup = function() {
      popupPanel.render(document.body);
    }
    if (navigator.appName == "Microsoft Internet Explorer")
      YAHOO.util.Event.addListener(window, "load",  renderPopup);
    else
      popupPanel.render(document.body);

    var handleSuccess = function(o)
    {
      if (o.responseText !== undefined)
      {
        var response = YAHOO.lang.JSON.parse(o.responseText);
        var headerDiv = new ELM(DOM.get('popupPanel_h'));
        headerDiv.addClass("rounded_top");
        headerDiv.addClass("divhead");
        headerDiv.addClass(themeClass);
        tl = document.createElement('div');
        tl.className = "tl";
        tr = document.createElement('div');
        tr.className = "tr";
        popupPanel.setHeader(response['h3'] + thePrintLink);
				headerDiv.appendChild(tl);
        headerDiv.appendChild(tr);
        theText = response['body'];
        popupPanel.setBody(theText);
        popupPanel.setFooter("<a href=\"javascript:void(0)\" onclick=\"popupPanel.hide();\">&nbsp;Close&nbsp;</a>");
        popupPanel.show();
      }
    }
    var handleFailure = function(o)
    {
      if (o.responseText !== undefined)
      {
        var errorDiv = document.getElementById('errorDiv');
        errorDiv.innerHTML += "<p>The database query to get the required content failed.</p>";
      }
    }
    var callback =
    {
    	success:handleSuccess,
    	failure:handleFailure
    };

  function popupPage(url)
  {
    shorturl = url;
    var cRegion = DOM.getClientRegion();
    var elmwidth  = 665;
    var elmheight = 550;
    var x_coord = (cRegion.right  - elmwidth)/2;
    var y_coord = cRegion.top + ((cRegion.bottom - cRegion.top - elmheight) / 2);
    popupPanel.moveTo(x_coord, y_coord);
    var fullUrl = "/getArticle.php?article="+url;
    var request = YCM.asyncRequest('GET', fullUrl, callback);
  }

    var handleSuccess2 = function(o)
    {
      if (o.responseText !== undefined)
      {
        var headerDiv = new ELM(DOM.get('popupPanel_h'));
        headerDiv.addClass("rounded_top");
        headerDiv.addClass("divhead");
        headerDiv.addClass(themeClass);
        tl = document.createElement('div');
        tl.className = "tl";
        tr = document.createElement('div');
        tr.className = "tr";
        popupPanel.setHeader(myHeader);
        headerDiv.appendChild(tl);
        headerDiv.appendChild(tr);
        popupPanel.setBody(o.responseText);
        popupPanel.setFooter("<a href=\"javascript:void(0)\" onclick=\"popupPanel.hide();\">&nbsp;Close&nbsp;</a>");
        popupPanel.show();
      }
    }
    var handleFailure2 = function(o)
    {
      if (o.responseText !== undefined)
      {
        var errorDiv = document.getElementById('errorDiv');
        errorDiv.innerHTML += "<p>The database query to get the required content failed.</p>";
      }
    }
    var callback2 =
    {
    	success:handleSuccess2,
    	failure:handleFailure2
    };

  function popupPage2(url, headerText)
  {
    var cRegion = DOM.getClientRegion();
    var elmwidth  = 665;
    var elmheight = 550;
    var x_coord = (cRegion.right  - elmwidth)/2;
    var y_coord = cRegion.top + ((cRegion.bottom - cRegion.top - elmheight) / 2);
    popupPanel.moveTo(x_coord, y_coord);
		if(headerText) myHeader = '<h3>'+headerText+'</h3>';
		var request = YCM.asyncRequest('GET', url, callback2);
  }

  /**
   * gather form data
   * send to navis (processEnqGen.php)
   * save to db (processEnqGen.php)
   * email to DL (processEnqGen.php)
   * show thanks/successful submission (innerHTML)
   *
   */
  processGeneralEnquiryForm = function()
  {
//    DOM.get('enquiry_popup').style.cursor='wait';
    errors_default = 'There is at least one error in the form:\n\n';
    errors = errors_default;
    name_first_default = 'First'; name_last_default = 'Last';

    ret = DOM.get('enquiry_keyword');
    if(ret) enq_keyword = ret.value;

    ret = DOM.get('enquiry_name_first');
    if(ret) enq_name_first = ret.value;

    ret = DOM.get('enquiry_name_last');
    if(ret) enq_name_last = ret.value;

    ret = DOM.get('enquiry_email');
    if(ret) enq_email = ret.value;

    ret = DOM.get('enquiry_email_confirm');
    if(ret) enq_email_confirm = ret.value; else enq_email_confirm = "";

    ret = DOM.get('enquiry_phone');
    if(ret) enq_phone = ret.value;

    ret = DOM.get('enquiry_adults');
    if(ret) enq_adults = ret.value;

    ret = DOM.get('enquiry_children');
    if(ret) enq_children = ret.value;

    ret = DOM.get('enquiry_arrival');
    if(ret) enq_arrival = ret.value;

    ret = DOM.get('enquiry_departure');
    if(ret) enq_departure = ret.value;

    ret = DOM.get('enquiry_budget_from');
    if(ret) enq_budget_from = ret.value;

    ret = DOM.get('enquiry_budget_to');
    if(ret) enq_budget_to = ret.value;

    ret = DOM.get('enquiry_comments');
    if(ret) enq_comments = ret.value;


    if( enq_name_first == '' || enq_name_first.length < 2 || enq_name_first == name_first_default) errors += 'First name is required and must be at least 2 characters \n';
    if( enq_name_last == '' || enq_name_last.length < 2 || enq_name_last == name_last_default) errors += 'Last name is required and must be at least 2 characters \n';
    if( ! validateEmail(enq_email)) errors += 'Invalid email address. Email is required and must be proper email address \n';
    if( enq_email != enq_email_confirm ) errors += 'Email address and confirm email address do not match. \n';
    if( enq_adults != '' ) { if( ! isNumber(enq_adults) ) errors += 'Adults must be a number \n'; }
    if( enq_children != '' ) { if( ! isNumber(enq_children) ) errors += 'Children must be a number \n'; }
    if( enq_budget_from != '' ) { if( ! isNumber(enq_budget_from) ) errors += 'Budget from must be a number \n'; }
    if( enq_budget_to != '' ) { if( ! isNumber(enq_budget_to) ) errors += 'Budget to must be a number \n'; }
//DOM.get('enquiry_popup').style.cursor = 'default';
    if(errors != errors_default) { alert(errors); return false; }

//  JSON format
    var data_setup =
        {
        KEYWORD: enq_keyword,
        NAMEFIRST: enq_name_first,
        NAMELAST: enq_name_last,
        EMAIL: enq_email,
        PHONE: enq_phone,
        ADULTS: enq_adults,
        CHILD: enq_children,
        ARRIVE: enq_arrival,
        DEPART: enq_departure,
        BUDGETFROM: enq_budget_from,
        BUDGETTO: enq_budget_to,
        COMMENTS: enq_comments
        }
    data = JSON.stringify(data_setup);

    fullUrl = "/utilities/enquiry_general_handler.php?data=" + data;
    new Ajax.Request(fullUrl, {
        'method':'post',
        asynchronous:true,
        onFailure: function() {alert('Transport error')},
        onSuccess: function(transport){
            el = DOM.get('enquiry_popup_msg');
            if(el) el.innerHTML = transport.responseText;
            el = DOM.get('enquiry_popup_msg_wrapper');
            if(el) el.style.display = 'block';
            el = DOM.get('enquiry_popup_bd');
            if(el) el.style.display = 'none';
        }
    });

//    DOM.get('enquiry_popup').style.cursor = 'default';
  }



  //http://www.marketingtechblog.com/programming/javascript-regex-emailaddress/#ixzz1Ieei9h3C
  validateEmail = function(email)
  {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;

    return emailPattern.test(email);
  }


    enquiryGotFocus = function(id)
    {
      obj = DOM.get(id);
      obj.style.color="#52555A";
      if(obj.value == 'First' || obj.value == 'Last') obj.value='';
    }//enquiryGotFocus

    enquiryLostFocus = function(id)
    {
      obj = DOM.get(id);
      switch(id)
      {
        case "enquiry_name_first":
          if(obj.value == '')
          {
            obj.value='First';
            obj.style.color="#ACABC4";
          }
          break;
        case "enquiry_name_last":
          if(obj.value == '')
          {
            obj.value='Last';
            obj.style.color="#ACABC4";
          }
          break;
      }

    }//enquiryLostFocus

YAHOO.namespace("enquiry.calendar");
//	var month=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var today = new Date();
var minDate = (today.getMonth()+1) + "/" + (today.getDate()+1) + "/" + today.getFullYear();
var navConfig = {
        strings:{
                 month:"Select Month",
                 year:"Enter Year",
                 submit:"OK",
                 cancel:"Cancel",
                 invalidYear:"Please enter a valid year"
        },
        initialFocus:"year"
};

  YAHOO.enquiry.calendar.init = function()
  {
      YAHOO.enquiry.calendar.enquiryArCal = new YAHOO.widget.CalendarGroup(
        "enquiryArCalendarContainer", { //AR DATE CALENDAR
        pages:2,
        title:"Choose an arrival date:",
        close:true,
        navigator:navConfig,
        mindate: minDate //later we may want to check the time of day. and if it is after x time we will make the min date tomorrow
    //maxdate: some date
    } );
    YAHOO.enquiry.calendar.enquiryArCal.render();

    YAHOO.enquiry.calendar.enquiryDpCal = new YAHOO.widget.CalendarGroup
    (
      "enquiryDpCalendarContainer", { //DP DATE CALENDAR
        pages:2,
        title:"Choose a departure date:",
        close:true,
        navigator:navConfig,
        mindate: minDate
    } );

    YAHOO.enquiry.calendar.enquiryDpCal.render();

    enquiryHandlerAr = function(type,args,obj)
    {
      var selected = args[0];
      var selDate = this.toDate(selected[0]);
      YAHOO.enquiry.calendar.enquiryArCal.hide();
      document.enquiry_general.enquiry_arrival.value = (selDate.getMonth()+1) + "/" + selDate.getDate() + "/" + selDate.getFullYear();

      if(YAHOO.enquiry.calendar.enquiryDpCal)
      {
        //TODO use a query to determine minimum no of nites based on selected ar date or something
        YAHOO.enquiry.calendar.enquiryDpCal.cfg.setProperty( "mindate", (selDate.getMonth()+1) + "/" + (selDate.getDate()+ 0) + "/" + selDate.getFullYear() );

        //make a date of the new setting then check if it is into next month
        myDate = new Date( (selDate.getMonth()+1) + "/" + (selDate.getDate()+ 4) + "/" + selDate.getFullYear() );
        if( myDate.getMonth() > selDate.getMonth() )
        {
          YAHOO.enquiry.calendar.enquiryDpCal.cfg.setProperty( "pagedate", (selDate.getMonth()+2) + "/" + selDate.getFullYear() );
        } else {
          YAHOO.enquiry.calendar.enquiryDpCal.cfg.setProperty( "pagedate", (selDate.getMonth()+1) + "/" + selDate.getFullYear() );
        }
        YAHOO.enquiry.calendar.enquiryDpCal.render();
      }};

    enquiryHandlerDp = function(type,args,obj)
    {
      var selected = args[0];
      var selDate = this.toDate(selected[0]);
      YAHOO.enquiry.calendar.enquiryDpCal.hide();
      document.enquiry_general.enquiry_departure.value = (selDate.getMonth()+1) + "/" + selDate.getDate() + "/" + selDate.getFullYear();
    };

    YAHOO.enquiry.calendar.enquiryArCal.selectEvent.subscribe(enquiryHandlerAr, YAHOO.enquiry.calendar.enquiryArCal, true);
    YAHOO.enquiry.calendar.enquiryDpCal.selectEvent.subscribe(enquiryHandlerDp, YAHOO.enquiry.calendar.enquiryDpCal, true);

    if(document.getElementById("enquiry_arrival").value != "")
    {
      var arDate = document.getElementById("enquiry_arrival").value.split("/");
      YAHOO.enquiry.calendar.enquiryArCal.cfg.setProperty( "pagedate", arDate[0] + "/" + arDate[2] );
      YAHOO.enquiry.calendar.enquiryArCal.render();
    }

    if(document.getElementById("enquiry_departure").value != "")
    {
      var dpDate = document.getElementById("enquiry_departure").value.split("/");
      YAHOO.enquiry.calendar.enquiryDpCal.cfg.setProperty( "pagedate", dpDate[0] + "/" + dpDate[2] );
      YAHOO.enquiry.calendar.enquiryDpCal.render();
    }
}//init

YAHOO.util.Event.onDOMReady(YAHOO.enquiry.calendar.init);

    var enquiryShowArCal = function(e)
    {
      arCal = document.getElementById("enquiryArCalendarContainer");
      if(arCal)
      {
        mouse = YAHOO.util.Event.getXY(e);
        arCal.style.display = "block";
      }
    }
    var enquiryShowDpCal = function(e)
    {
      arval = document.getElementById('enquiry_arrival').value;
      if( ! arval || arval == '')
      {
         availSearchShowValidationError("<ul><li>Please select a Check in Date before selecting a Check out Date.</li></ul>", e);
         return;
      }

      dpCal = document.getElementById("enquiryDpCalendarContainer");
      if(dpCal){ dpCal.style.display = "block"; }
    }

  /**
   * show the enquiry popup by calling the toggle function
   */
  popupEnquiry = function(e)
  {
    toggle_enquiry_popup();
  }

  /**
   * is the enquiry popup visible?
   */
  enquiry_popup_in_viewport = function()
  {
    ret = false;
    pos = DOM.getXY('enquiry_popup_wrapper'); //0=x, 1=y
    //DOM.getViewportWidth();
    if(pos[0] > 0) ret = true;

    return ret;
  }

  /**
   * show or dont show the
   */
  toggle_enquiry_popup = function()
  {
    var cRegion = DOM.getClientRegion();
    var elmwidth  = 310;
    var elmheight = 350;
    var x_coord = (cRegion.right  - elmwidth)/2;
    var y_coord = cRegion.top + ((cRegion.bottom - cRegion.top - elmheight) / 2);

    el = document.getElementById("enquiry_popup_wrapper");
    if( ! enquiry_popup_in_viewport() ) new Effect.Move(el, {x:x_coord,y:y_coord,duration:.5,mode:'absolute'});
    else new Effect.Move(el, {x:-9999,y:100,duration:.5,mode:'absolute'});
  }

  close_enquiry_popup_msg = function()
  {
    el = DOM.get('enquiry_popup_msg_wrapper');
    el.style.display='none';

    el = DOM.get('enquiry_popup_bd');
    el.style.display = 'block';
  }


