/*
 "group" attributes on html elements which run on the server
 allow each group to be passed to the client with the clientID so it can be accessed by client side javascript

 "manditory" attributes are used for validation of manditory controls
 they are passed to the client in the same way 
 and their value tells the client side code how they are validated
 i.e. <input type="checked" group="theCheckBox" manditory="checked" />
	the list of options are: NonEmpty, Checked, etc...
 
 "validation" attributes will allow the submit function of each control
 to be validated in the OnSubmit() event
	the list of parameters are a*/
// AddElement function adds the value of any html element on the page to the request for processing in the code behind
// need function to get the value of any item in the request and put in any html element on the page
function FindGroup(id)
{
    var ControlList = Controls.split('|');

      var Control;

      for(i = 0; i < ControlList.length-1; i++)

            {

                  Control = ControlList[i].split('/');

                  if(Control[1] == id)

                  {

                        return Control[0];

                  }

            }

      return "";

}



function GetRequestValue(Path)
{
  var Value = '';
  var Index = 0;
  var obj = GetElement("RequestField");
  Value = obj.value;
  // the format is  [[field id='Arrival' value='20050125' ]]
  // get the last pos of the Path param in the string - such as Arrival
  Index = Value.lastIndexOf('[[field id=\'' + Path.toUpperCase());

  if (Index == -1)
  {
    Index = Value.lastIndexOf('[[field id=\'' + Path);
  }
  
  if (Index != -1)
  {  
	// get the rest of the string
	Value = Value.substring(Index, Value.length);
	  
	// get the next position of 'value' in the string
	Index = Value.indexOf('value=') + 7;

	// get the rest again
	Value = Value.substring(Index, Value.length);

	// get the next position of  "']]"
	Index = Value.indexOf('\']]');

	// get the rest again
	Value = Value.substring(0, Index);

    return Value;
  }

  return '';
}



// get an element
function GetElement(id)
{
	var elm = null;
	if (document.getElementById)
	{
		// browser implements part of W3C DOM HTML
		// Gecko, Internet Explorer 5+, Opera 5+
		elm = document.getElementById(id);
	}
	else if (document.all)
	{
		// Internet Explorer 4 or Opera with IE user agent
		elm = document.all[id];
	}
	else if (document.layers)
	{
		// Navigator 4
		elm = document.layers[id];
	}
	return elm;
}


// add an value to the request
function AddElement(Path, Value)
{
	if(Value != null)
	{
	Value = Value.toString().replace('[[', '').replace(']]', '');
	Value = XmlEncode(Value);
	var obj = GetElement("RequestField");
	obj.value = obj.value + "[[field id='" + Path + "' value='" + Value + "']]";
	}
}


// - this is called before all fields are added to the request
// provides xml encoding for '<', '>', '&', '\'', '"'
function XmlEncode(Value)
{
	Value = Value.replace(/&/g, '&amp;');
	Value = Value.replace(/\'/g, '&apos;');
	Value = Value.replace(/"/g, '&quot;');
	Value = Value.replace(/</g, '&lt;');
	Value = Value.replace(/>/g, '&gt;');
	
	// return encoded string
	return Value;
}


/* the following functions handle groups of controls on a page */
// set the .value property of all controls in a group to the parameter object
// - handles multiple controls on a page
function UpdateValueControls(obj)
{
	var Group = FindGroup(obj.id);
	
	if(Group.length > 0)
	{
		SetGroupValue(Group, obj.value);
	}
}

// update all controls with selected index of the parameter control
// - handles multiple controls on a page
function UpdateSelectControls(obj)
{
	var Group = FindGroup(obj.id);
	
	if(Group.length > 0)
	{
		SetGroupSelectedIndex(Group, obj.selectedIndex);
	}
}


// The follwoing functions handle value controls only
// get the value of a group
function GetGroupValue(group)
{
	var value = "";
	var ControlList = Controls.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			value = GetElement(Control[1]).value;
			return value;
		}
	}
	return value;
}

// set the value of a group
function SetGroupValue(group, value)
{
	var ControlList = Controls.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			GetElement(Control[1]).value = value;
		}
	}
}


// The following functions handle dropdown lists only
// get the seleced index of a group
function GetGroupSelectedIndex(group)
{
	var value = 0;
	var ControlList = Controls.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			value = GetElement(Control[1]).selectedIndex;
			return value;
		}
	}
	return value;
}

// set the selected index of a group of drop downs
function SetGroupSelectedIndex(group, value)
{

	var ControlList = Controls.split('|');
	var Control;

	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');

		
		if(Control[0] == group)
		{
			GetElement(Control[1]).selectedIndex = value;
		}
	}
}




// set the style.display of a group / groups of elements
// accepts a \'\ delimited string of groups
function SetGroupDisplay(groupList, display)
{
	// get groups to display
	var groups = groupList.split('|');
	
	var ControlList = Controls.split('|');
	var Control;
	// set display of each group
	for (k = 0; k < groups.length; k++)
	{
		// set display of each
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
			if(Control[0] == groups[k])
		{
				GetElement(Control[1]).style.display = display;
			}
		}
	}
}

// return the syle.display property of a group of elements
function GetGroupDisplay(group)
{
	var Display = "";
	var ControlList = Controls.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			Display = GetElement(Control[1]).style.display;
			return Display;
		}
	}
	return Display;
}

//*****************************//
// code to handle dates on specials and search pages
// sets initial dates to 20 dats time
// called on the onload event
function SetInitialDates()
{

	// if date controls not rendered on the page - exit here
	if (FindId('SEARCHFORM2_ArrivalDay') == '')
	{
		return;
	}
	

	// use the last dates the client chose if they exist in the request
	var ArrivalDate = GetRequestValue('SEARCHFORM2_Arrival');
	var DepartureDate = GetRequestValue('SEARCHFORM2_Departure');
	// otherwise get the  default dates from hidden fields added by the server
	if (ArrivalDate == '' || DepartureDate == '')
	{

		var Dates = GetElement('selDates');
		if (Dates != null)
		{
			var arrDates = Dates.value.split(',');
			if (arrDates[0] != null)
				ArrivalDate = arrDates[0];
			if (arrDates[1] != null)
				DepartureDate = arrDates[1];
		}
	}
	// if we have dates - use them	
	if (ArrivalDate != '' && DepartureDate != '')
	{
		gArrivalYear = parseInt(ArrivalDate.substr(0, 4), 10);

		SetGroupSelectedIndex('SEARCHFORM2_ArrivalMonth', parseInt(ArrivalDate.substr(4, 2), 10) - 1);
		SetGroupSelectedIndex('SEARCHFORM2_ArrivalDay', parseInt(ArrivalDate.substr(6, 2), 10) - 1);

		SetGroupSelectedIndex('SEARCHFORM2_DepartureMonth', parseInt(DepartureDate.substr(4, 2), 10) - 1);
		SetGroupSelectedIndex('SEARCHFORM2_DepartureDay', parseInt(DepartureDate.substr(6, 2), 10) - 1);
	}
	// otherwise calculate them
	else
	{
		// 19 days ahead
		//var NumDaysAhead = 19;
		var NumDaysAhead = 1;
	
		// get todays date
		var theDate = new Date();

		// add 20 days
		theDate.setTime(theDate.getTime() + (1000 * 60 * 60 * 24 * NumDaysAhead));

		// set the arrival dates from theDate
		gArrivalYear = theDate.getFullYear();

		SetGroupSelectedIndex('SEARCHFORM2_ArrivalMonth', theDate.getMonth());
		SetGroupSelectedIndex('SEARCHFORM2_ArrivalDay', theDate.getDate() - 1);
	}
	// set the departure dates from arrival dates
	ChangeArrivalDate('true');
	//if(GetGroupValue('NoOfNights') != null){
	//	SetGroupValue('NoOfNights','1');
	//}
}



// return the id of the first element in a group
function FindId(group)
{
	var ControlList = Controls.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
    {
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			return Control[1];
		}
	}
	return "";
}


// sets the departure date to one day after the arrival date
// called by onchange event of arrivaldate dropdown boxes
function ChangeArrivalDate()
{
	// store the current date
	var todayDate = new Date();

	// group names for date dropdowns
	var ArrivalDay = 'SEARCHFORM2_ArrivalDay';
	var ArrivalMonth = 'SEARCHFORM2_ArrivalMonth';
	var DepartureDay = 'SEARCHFORM2_DepartureDay';
	var DepartureMonth = 'SEARCHFORM2_DepartureMonth';

/*
	// if id passed in - update selected indices of all controls
	if (arguments[0] != null)
	{
		// set all date dropdowns to the index selected
		SetGroupSelectedIndex(FindGroup(arguments[0]), GetElement(arguments[0]).selectedIndex);
	}*/
	
	// create a new date object with arrival year, month and day
//	var theDate = new Date(gArrivalYear, GetGroupSelectedIndex(ArrivalMonth), GetGroupValue(ArrivalDay));
	var theDate = new Date(todayDate.getFullYear(), GetGroupSelectedIndex(ArrivalMonth), GetGroupValue(ArrivalDay));

	// make sure invalid dates like feb30, apr31 has not been selected
	// - check if date has wrapped around to next month (30feb wraps to 3mar)
	// -- so date will be 1 and selectedValue will be 30
	var DateError = theDate.getDate() - GetGroupValue(ArrivalDay);
	// loop until difference is 0
	while (DateError != 0)
	{
		// decrement the selected index
		SetGroupSelectedIndex(ArrivalDay, GetGroupSelectedIndex(ArrivalDay) - 1);
		// decrement the date
		theDate.setTime(theDate.getTime() - (1000 * 60 * 60 * 24))
		// re calculate the difference
		DateError = theDate.getDate() - GetGroupValue(ArrivalDay);
	}

	// check if the arrival date is in the past
	if ((theDate.getFullYear() < todayDate.getFullYear())
		|| (theDate.getFullYear() == todayDate.getFullYear() && theDate.getMonth() < todayDate.getMonth())
		|| (theDate.getFullYear() == todayDate.getFullYear() && theDate.getMonth() == todayDate.getMonth() && theDate.getDate() < todayDate.getDate()))
	{
		// set year to next year
		theDate.setFullYear(todayDate.getFullYear() + 1)
		gArrivalYear = theDate.getFullYear();
	}
	// date is not in the past - so we are searching for this year
	else
	{
		theDate.setFullYear(todayDate.getFullYear())
		gArrivalYear = theDate.getFullYear();
	}


	
	if (arguments[0] == 'true') // set a 2 day gap
	{
        // increment theDate by one day
	    theDate.setTime(theDate.getTime() + (1000 * 60 * 60 * 48));

	    // set departure date from new date
	    gDepartureYear = theDate.getFullYear();
	    
	}
	else
	{
		 // set a 1 day gap
	    //theDate.setTime(theDate.getTime() + (1000 * 60 * 60 * 24));
	    theDate.setTime(theDate.getTime() + (1000 * 60 * 60 * 28));

	    // set departure date from new date
	    gDepartureYear = theDate.getFullYear();
	    
	}
	 SetGroupSelectedIndex(DepartureMonth, theDate.getMonth());
	SetGroupSelectedIndex(DepartureDay, theDate.getDate()-1);// 2 days gap



	// add dates to the request
	AddElement('SEARCHFORM2_Arrival', gArrivalYear + GetGroupValue(ArrivalMonth) + GetGroupValue(ArrivalDay));
	AddElement('SEARCHFORM2_Departure', gDepartureYear + GetGroupValue(DepartureMonth) + GetGroupValue(DepartureDay));

}



// called by the onchange event of the departure date dropdown boxes
// sets the departure date dates in the request
function ChangeDepartureDate()
{
	// store the current date
	var todayDate = new Date();
	
	// make sure years are within one year of this year
	if(gArrivalYear > todayDate.getFullYear() + 1)
		gArrivalYear = todayDate.getFullYear() + 1
	if(gDepartureYear > todayDate.getFullYear() + 1)
		gDepartureYear = todayDate.getFullYear() + 1

	// group names for date dropdowns
	var ArrivalDay = 'SEARCHFORM2_ArrivalDay';
	var ArrivalMonth = 'SEARCHFORM2_ArrivalMonth';
	var DepartureDay = 'SEARCHFORM2_DepartureDay';
	var DepartureMonth = 'SEARCHFORM2_DepartureMonth';

	// if id passed in - update selected indices of all controls
	if (arguments[0] != null)
	{
		// set all date dropdowns to the index selected
		SetGroupSelectedIndex(FindGroup(arguments[0]), GetElement(arguments[0]).selectedIndex);
	}

	// create a new date object with arrival dates
	var theArrivalDate = new Date(gArrivalYear, GetGroupSelectedIndex(ArrivalMonth), GetGroupValue(ArrivalDay));

	// create a new date object with departure dates - use arrival year
	var theDepartureDate = new Date(gArrivalYear, GetGroupSelectedIndex(DepartureMonth), GetGroupValue(DepartureDay));

	// make sure invalid dates like feb30, apr31 has not been selected
	// - check if date has wrapped around to next month (30feb wraps to 3mar)
	// -- so date will be 1 and selectedValue will be 30
	var DateError = theDepartureDate.getDate() - GetGroupValue(DepartureDay);
	// loop until difference is 0
	while (DateError != 0)
	{
		// decrement the selected index
		SetGroupSelectedIndex(DepartureDay, GetGroupSelectedIndex(DepartureDay) - 1);
		// decrement the date
		theDepartureDate.setTime(theDepartureDate.getTime() - (1000 * 60 * 60 * 24))
		// re calculate the difference
		DateError = theDepartureDate.getDate() - GetGroupValue(DepartureDay);
	}

	// calculate the departure year from the arrival year
	if (theDepartureDate < theArrivalDate)
		gDepartureYear = gArrivalYear + 1;
	else
		gDepartureYear = gArrivalYear;
		
	theDepartureDate.setFullYear(gDepartureYear)

	// if departure date = arrival date
	if (theDepartureDate.getFullYear() == theArrivalDate.getFullYear() && theDepartureDate.getMonth() == theArrivalDate.getMonth() && theDepartureDate.getDate() == theArrivalDate.getDate())
	{
		// add one to the departure date
		theDepartureDate.setTime(theDepartureDate.getTime() + (1000 * 60 * 60 * 24));

		// set departure date from new date
		gDepartureYear = theDepartureDate.getFullYear();
		SetGroupSelectedIndex(DepartureMonth, theDepartureDate.getMonth());
		SetGroupSelectedIndex(DepartureDay, theDepartureDate.getDate() - 1);
	}
	
	// add the departure date to the request
	AddElement('Departure', gDepartureYear + GetGroupValue(DepartureMonth) + GetGroupValue(DepartureDay));
}
//*************************************//

// go to link
function NavigateTo(url)
{
	location.href = url;
}

// change class name of an element
function SetClassName(obj, NewClass)
{
	if (obj == null) return;
	obj.className = NewClass;
}




//calendar
/* NOTE: the following functions are for the dhtml calendar */
/* the calendar is fully cross browser compatible */
// The parameters are as follows:
// dir:		direction: 'in' for arrivalDate; 'out' for departureDate
// m:		the month to be displayed (1 - 12)
// y:		the year to be displayed  (xxxx)
// cM:		Main class: class applied to outer div and table
// cH:		Header class: class applied to month and year on top of calendar
// cDW:		Days of Week class: class applied to day of week: S M T W T F S
// cD:		Days class: class applied to week days
// brdr:	Border applied to main table
// selDay:		the day which is selected before the cal is shown
// selMonth:	the month which is selected before the cal is shown
function buildCal(dir, m, y, cPN, cM, cH, cDW, cD, brdr, selDayIn, selMonthIn, selDayOut, selMonthOut, callerId)
{

	// make sure all numeric parameters are integers, instead of strings
	m = parseInt(m, 10);
	y = parseInt(y, 10);
	selDayIn = parseInt(selDayIn, 10);
	selMonthIn = parseInt(selMonthIn, 10);
	selMonthOut = parseInt(selMonthOut, 10);

	var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
//	var mn=['<%= rm.GetString("January") %>','<%= rm.GetString("February") %>','<%= rm.GetString("March") %>','<%= rm.GetString("April") %>','<%= rm.GetString("May") %>','<%= rm.GetString("June") %>','<%= rm.GetString("July") %>','<%= rm.GetString("August") %>','<%= rm.GetString("September") %>','<%= rm.GetString("October") %>','<%= rm.GetString("November") %>','<%= rm.GetString("December") %>'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

	var oD = new Date(y, m - 1, 1);	//DD replaced line to fix date bug when current day is 31st
	oD.od = oD.getDay() + 1;		//DD replaced line to fix date bug when current day is 31st

	var todaydate=new Date() //DD added
	var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth()+1) ? todaydate.getDate() : 0	//DD added

	// set number of days in february (check for leap year)
	dim[1]=(((oD.getFullYear()%100 != 0) && (oD.getFullYear()%4 == 0)) || (oD.getFullYear()%400 == 0)) ? 29:28;

	//build "t": html stream to return as calendar
	// open table element
	var t = '<div class="' + cM + '" id="outerDiv" style="width: 170;"><table id="theTable" class="' + cM + '" cols="7" cellpadding="0" bordercolor="#FFCC66" border="' + brdr + '" cellspacing="0"><tr align="left">';

	// add in the title bar
	t += '<td colspan="6" class="calendarTitle">';
	
	// arrive or depart
	t += (dir == 'in') ? 'Arrival' : 'Departure';
//	t += (dir == 'in') ? '<%= rm.GetString("Arrival") %>' : '<%= rm.GetString("Departure") %>';
	
	// and close button
	t += '</td><td id="closeButton" align="center" class="closeButton"><a target="_self" onmouseover="changeCell(\'closeButton\');" onmouseout="changeCell(\'closeButton\');" onclick="HideCal();">X</a></td></tr><tr align="center">'

	// first test if back button is required
	if (y == todaydate.getFullYear() && m == (todaydate.getMonth() + 1))
	{
		// if not disply an empty cell
		t += '<td class="' + cH + '">&nbsp;</td>';
	}
	// add the back button
	else
	{
		// add the link to the previous month
		t += '<td class="' + cPN + '" id="prevbutton"><a target="_self" onclick="ShowCal(\'' + callerId + '\', ';

		// test for january - wraps arount to december
		if (m <= 1)
		{
			t += 12;
			t += ',';
			t += parseInt(y, 10) - 1;
		}
		else
		{
			t += (m - 1)
			t += ',';
			t += parseInt(y, 10);
		}
			
		// close the link to previous month
		t += ')" onmouseover="changeCell(\'prevbutton\')" onmouseout="changeCell(\'prevbutton\')">&lt;</a></td>';
	}
		
	// add title row - month and year
	t += '<td colspan="5" align="center" class="' + cH + '">' + mn[m-1] + ' ' + y + '</td>';

	// test if the forward button is required
	if (y == (todaydate.getFullYear() + 1) && m == (todaydate.getMonth() + 1))
	{
		// if not write an empty cell
		t += '<td class="' + cH + '">&nbsp;</td>';
	}
	// add the forward button
	else
	{
		// add the button to next month
		t += '<td class="' + cPN + '" id="nextbutton"><a target="_self" onclick="ShowCal(\'' + callerId + '\', ';
		
		// test for december - wraps around to january
		if (m >= 12)
		{
			t += 1;
			t += ',';
			t += parseInt(y, 10) + 1;
		}
		else
		{
			t += (parseInt(m, 10) + 1)
			t += ',';
			t += parseInt(y, 10);
		}
			
		// close link to next month
		t += ')" onmouseover="changeCell(\'nextbutton\')" onmouseout="changeCell(\'nextbutton\')">&gt;</a></td>';
	}
	
	t += '</tr><tr align="center">';


	// write days of week S M T W T F S
	for(s = 0; s < 7; s++) t += '<td width="10.25%" class="' + cDW + '">' + "SMTWTFS".substr(s,1) + '</td>';

	// new row
	t += '</tr><tr align="center">';

	//loop thru cells on page 6*7=42
	for(i = 1; i <= 42; i++)
	{
		// write spaces for cells not in this month, otherwise write the date of month (x is the value written)
		var x = ((i-oD.od >= 0) && (i-oD.od < dim[m-1])) ? i-oD.od+1 : '&nbsp;';

		if (x != '&nbsp;')
		{
			var cellId = 'cell' + i;

			// if date is not bookable
			// we can only book for today or after
				// if year is this year, and month is this month, and date less than today
			if ((y == todaydate.getFullYear() && m == (todaydate.getMonth() + 1) && x < todaydate.getDate()) 
				|| (y == (todaydate.getFullYear() + 1) && m == (todaydate.getMonth() + 1) && x >= todaydate.getDate()))
			{
				// day is greyed out
				t += '<td class="daysGreyedOut">' + x + '</td>';
			}
			// otherwise display link
			else
			{
				// write each day to the string
				t += '<td id="' + cellId + '" class="' + cD + '"><a target="_self" onclick="SelectDates(\'' + dir + '\', ' + x + ', ' + m + ',' + y + '); HideCal();" onmouseover="changeCell(\'' + cellId + '\')" onmouseout="changeCell(\'' + cellId + '\')">';
				
				// test for todays date - its displayed in different stlye
				if (x == scanfortoday)
				{
					t += '<span id="today">' + x + '</span>'
				}
				// test for selected date
				else if ((x == selDayIn && m == selMonthIn) || (x == selDayOut && m == selMonthOut))
				{
					t += '<b>' + x + '</b>';
				}
				else
				{
					t += x;
				}

				// end of link and column
				t += '</a></td>';
			}
		}
		else
		{
			t += '<td class="daysBlank">' + x + '</td>';
		}

		// new row for every week
		if (((i)%7 == 0) && (i < 36)) t += '</tr><tr align="center">';
	}

	// return the html stream (closing the table first)
	return t += '</tr></table></div>';

}

// select the value of the dropdown from the date clicked
function SelectDates(dir, SelectedDay, SelectedMonth, selectedYear)
{
	// group names for date dropdowns
	var ArrivalDay = 'SEARCHFORM2_ArrivalDay';
	var ArrivalMonth = 'SEARCHFORM2_ArrivalMonth';
	var DepartureDay = 'SEARCHFORM2_DepartureDay';
	var DepartureMonth = 'SEARCHFORM2_DepartureMonth';
	
	
	// check the direction of the date (arr or dept)				
	if (dir == 'in')
	{
		// set the day
		SetGroupSelectedIndex(ArrivalDay, SelectedDay - 1);
		// set the month
		SetGroupSelectedIndex(ArrivalMonth, SelectedMonth - 1);
		// set the year
		gArrivalYear = selectedYear;
		// add the arrival date to the request
		ChangeArrivalDate('false');
		CheckDateOneDay() ;
	}
	if (dir == 'out')
	{
		// set the day
		SetGroupSelectedIndex(DepartureDay, SelectedDay - 1);
		// set the month
		SetGroupSelectedIndex(DepartureMonth, SelectedMonth - 1);
		// set the year
		gDepartureYear = selectedYear;
		// add the departure date to the request
		ChangeDepartureDate();
		CheckDateOneDay() ;
	}
	
}

function HideCal()
{
	// get the div containing the calendar
	var elm = GetElement("CalendarPlace");
	var shadow = GetElement("CalendarShadow");
	var shadow2 = GetElement("CalendarShadow2");
	
	// get the visibility style of the div
	var visibility = elm.style.visibility;

	// hide the div with the calendar
	if (visibility == "visible")
	{
		elm.style.visibility = "hidden";
		shadow.style.visibility = "hidden";
		shadow2.style.visibility = "hidden";

	}
}

// used to emphasise a cell when hovering
// called by onmouseover and onmouseout events
function changeCell(id)
{
	// get the element with the id passed in
	var Cell = GetElement(id);

	if (id == 'nextbutton' || id == 'prevbutton')
	{
		if (Cell.className == "daysHovered")
			Cell.className = "PrevNextButtons"
		else
			Cell.className = "daysHovered";
	}
	else if (id == 'closeButton')
	{
		if (Cell.className == "closeButtonHovered")
			Cell.className = "closeButton"
		else
			Cell.className = "closeButtonHovered"
	}
	else
	{
		if (Cell.className == "daysHovered")
			Cell.className = "days"
		else
			Cell.className = "daysHovered";
	}				
}
			
// params:
// obj:				the calling object - the button which set the onclick event
// monthToDisplay, yearToDisplay:		the month and year to display
function ShowCal(objId, monthToDisplay, yearToDisplay)
{

	// this is the calling object - it is used to position of the calendar on the page
	var obj = GetElement(objId);
	var todaydate = new Date();
	var dir;		// 'in' or 'out': the arrival or departure date
	var Month;
	var Year;

	// calculations for building calendar ...
	Month = monthToDisplay;
	Year = yearToDisplay;

	// choose which dates to change (arrival or departure)
	if (objId == 'ArrivalButton')
	{
		dir = 'in'
	}
	else if (objId == 'DepartureButton')
	{
		dir = 'out'
	}

	// the first time the function is called - by clicking on one of the buttons
	if (monthToDisplay == null && dir == 'in')
	{
		Month =	GetGroupValue('SEARCHFORM2_ArrivalMonth');
		Year = gArrivalYear;
	}
	// otherwise display the month and year provided
	else if (monthToDisplay == null && dir == 'out')
	{
		Month = GetGroupValue('SEARCHFORM2_DepartureMonth');
		Year = gDepartureYear;
	}

	var selDayIn = GetGroupValue('SEARCHFORM2_ArrivalDay');
	var selMonthIn = GetGroupValue('SEARCHFORM2_ArrivalMonth');
	var selDayOut = GetGroupValue('SEARCHFORM2_DepartureDay');
	var selMonthOut = GetGroupValue('SEARCHFORM2_DepartureMonth');

	// building and showing calendar ...
	// get the div containing the calendar
	var elm = GetElement("CalendarPlace");
	
	// get the shadow
	var shadow = GetElement("CalendarShadow");
	var shadow2 = GetElement("CalendarShadow2");
	
	// get the style of the div
	var visibility = elm.style.visibility;

	// get the html for the calendar source - build stream from javascript function
	var HtmlStream = buildCal(dir, Month, Year, "PrevNextButtons", "main", "month", "daysofweek", "days", 1, selDayIn, selMonthIn, selDayOut, selMonthOut, objId);

	// write the html source to the calendar
	elm.innerHTML = HtmlStream;

	// positioning variables
	oLeft = 0;
	oTop = 0;
	// place cal on page
	oParent = GetElement('ArrivalButton');
	while(oParent != null)
	{
		oLeft = oLeft + oParent.offsetLeft;
		oTop = oTop + oParent.offsetTop;
		oParent = oParent.offsetParent;
	}

	var theDiv = GetElement('outerDiv');


	
	// set the position of the calendar shadow
	shadow.style.left = (elm.offsetLeft + 2) + "px";
	shadow.style.top = (elm.offsetTop + 2) + "px";
	shadow.style.height = theDiv.offsetHeight + "px";

	// set the position of the 2nd calendar shadow
	shadow2.style.left = (shadow.offsetLeft + 2) + "px";
	shadow2.style.top = (shadow.offsetTop + 2) + "px";
	shadow2.style.height = theDiv.offsetHeight + "px";
	
	// show calendar
	if (visibility == "hidden")
	{
		
		// show calendar div and shadows
		elm.style.visibility = "visible";
		shadow.style.visibility = "visible";
		shadow2.style.visibility = "visible";
	}
	// if the next or previous month button has been clicked
	else if (monthToDisplay == null)
	{
		// hide calendar
		elm.style.visibility = "hidden";
		shadow.style.visibility = "hidden";
		shadow2.style.visibility = "hidden";
		
		
	}
		
}

/* END calendar functions */





/*determine where is searched for, if its dublin send the browser to the gulliver pages*/ 
function ReadTextBox()
{
	var searchValue;

	searchValue = GetElement('SEARCHFORM2_cityname').value.toLowerCase();
	if (searchValue == 'dublin' || searchValue == 'dubblin' || searchValue == 'dublan' || searchValue == 'dublen' || searchValue == 'dubrin')
	{
		var ele = GetElement('aspnetForm');
		ele.action = "http://reservations.goireland.com/ptsaffiliates/avlSearchResults.asp?AffiliateID=104&provid=68";

		SetHiddenFields();
	}
	else
	{
		var ele = GetElement('aspnetForm');
		ele.action = "/Default.aspx";	
	}
	

	
}




function SetHiddenFields()
{
    var ArrDay;
    var ArrMonth;
    var ArrYear;
    var Arrival;
    var Departure;
    var DeptDay;
    var DeptMonth;
    var DeptYear;
    var Adults;
    var Rooms;
    var iParty;
    var iAdults;
    var iRooms;
    var Sharing;
    var NumNights;
    var StayTimeSpan = 1;
    var OneDay = 1000*60*60*24; // ms * s * m * h
    var _Arrival = new Date();
    var _Departure = new Date();
    
      
    ArrDay = GetGroupValue('SEARCHFORM2_ArrivalDay');
    ArrMonth = GetGroupValue('SEARCHFORM2_ArrivalMonth');
    ArrYear = gArrivalYear;
    _Arrival.setMonth(ArrMonth);
    _Arrival.setFullYear(ArrYear);
    _Arrival.setDate(ArrDay);
     
    DeptDay = GetGroupValue('SEARCHFORM2_DepartureDay');
    DeptMonth = GetGroupValue('SEARCHFORM2_DepartureMonth');
    DeptYear = gDepartureYear;
    
    _Departure.setMonth(DeptMonth);
    _Departure.setFullYear(DeptYear);
    _Departure.setDate(DeptDay);
    
    NumNights = Math.ceil((_Departure.getTime() - _Arrival.getTime()) / OneDay);
    
    Adults = GetElement('SEARCHFORM2_people').value;
    Rooms = GetElement('SEARCHFORM2_rooms').value; 
    iAdults = parseInt(Adults);
    iRooms = parseInt(Rooms);
    iParty = (iAdults * iRooms);
       
    if(Adults == "1")
    {
        Sharing = "3";
    
    }
    else
    {
        Sharing = "1";
    }
    
    

   GetElement("selNumAdults").value = iParty;
   GetElement("selSharing").value = Sharing;
   GetElement("selArriveDay").value = ArrDay;
   GetElement("selArriveMonth").value = ArrMonth;
   GetElement("selArriveYear").value = ArrYear;
   GetElement("selNumNights").value = NumNights;

}


// CheckQuerystring if  strAvailable == "2" then there was no availability

function CheckQueryString () 
{ var elm = GetElement('ctl01_NoHotels0001');
 
  if(elm != null)
  {
 	elm.style.display = 'none';
  	var query = window.location.search.substring(1);
       	query =  unescape(query) ;
  	var vars = query.split("&");

	for (var i=0;i<vars.length;i++) 
	{
    	var pair = vars[i].split("=");
    	if (pair[0] == 'Available')
		{
      		if (pair[1] == '2')
			{ 
			    elm.style.display = 'inline';
			    var searchbox = GetElement('MidArea');
			    if(searchbox != null)
			    {   
			        searchbox.style.display = 'block';
			    }
			    return true;
			}
   		 }
    } 	
  } 
  return false;
}


function CheckDateOneDay() 
{ 
   // var _Departure = new Date();
    var OneDay = 1000*60*60*24; // ms * s * m * h
    var DeptDay ;
    var DeptMonth;
    var DeptYear;


    var _Arrival = new Date();
    var _Departure = new Date();
    
    ArrDay = GetGroupValue('SEARCHFORM2_ArrivalDay');
    ArrMonth = GetGroupValue('SEARCHFORM2_ArrivalMonth');
    ArrYear = gArrivalYear;
    _Arrival.setMonth(ArrMonth);
    _Arrival.setFullYear(ArrYear);
    _Arrival.setDate(ArrDay);

    DeptDay = GetGroupValue('SEARCHFORM2_DepartureDay');
   
    DeptMonth = GetGroupValue('SEARCHFORM2_DepartureMonth');
    DeptYear = gDepartureYear;
    
    _Departure.setMonth(DeptMonth);
    _Departure.setFullYear(DeptYear);
    _Departure.setDate(DeptDay);
    
        var elm = GetElement('dateMessage');
        var endmonth = DeptMonth - ArrMonth;
        var NumNights = Math.ceil((_Departure.getTime() - _Arrival.getTime()) / OneDay);
       // alert("nights" + NumNights + "end month" + endmonth);
        if(NumNights == 1 && endmonth !=1 || endmonth ==1 && (NumNights == 0 || NumNights == -363  || NumNights == 2 ))
        {
            var isWeekendDay =  getTheDay(DeptDay, DeptMonth, DeptYear);
            if (isWeekendDay == 'Saturday' || isWeekendDay == 'Sunday')
            {
               
                if(elm != null)
                {
                    elm.style.display = 'inline';
                    var searchbox = GetElement('MidArea');
                    return true;
                }
                else
                {
                    elm.style.display = 'none';
                    return true;
                }
            }
            else
            {
                elm.style.display = 'none';
                return true;
            }
        }
        else
        {
            elm.style.display = 'none';
            return true;
        }
    return false;
}

function getTheDay(DD,Month,YYYY)
{
    var myDate;
    var myDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
    var months = new Array(13);
    months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
            
    var monthname = months[Month-1];
    myDate= new Date(eval('"' + DD + " " + monthname + " " + YYYY +'"'));
    return myDays[myDate.getDay()];
}

function UpdateLocation(obj) 
{
    
	if (obj.selectedIndex >0)
		
	{
		window.location = obj.value;
	}
    
}