// add an value to the request
function transfer()
{
	document.reservation.submit();
}

// add an value to the request
function setElement(Path, Value)
{
	if(Value != null)
	{
		Value = Value.toString().replace('[[', '').replace(']]', '');
		Value = XmlEncode(Value);
		//alert("Value: " + Value);
		for(i=0;i<document.forms.length;++i) {
			if (document.forms[i].name == "reservation") {
				//alert("Found Reservation ");
				for(j=0;j<document.forms[i].elements.length;++j) {
					//alert("Found " + document.forms[i].elements[j].name + " field");
					if (document.forms[i].elements[j].name == Path){
						//alert("Found match field");
						document.forms[i].elements[j].value = Value;
						//alert("Value set ");
					}
				}
			}
		}
	}
}


/*

 "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 
  
*/

var timeout_id;

function Animate(img,path){
GetElement(img).src = path;
// Increment the frame counter
// Display the next frame in imageDelay milliseconds
//this.timeout_id = setTimeout(Animate(img,path), 1000);
}

function StopAnimate()
{
 this.timeout_id = null;
}

var Amenities = "";


// sumit the form
function SubmitMe()
{
	var TargetSite = GetElement("ThisSite").value;
	var TargetPage = GetElement("TargetPage").value;
	var SubmitToCng = GetElement('SubmitToCng').value;
	var SecurePage = false;
	
	// flag if target page is secure
	if(TargetPage == "ReservationRequest" || TargetPage == "ReserveConfirm" || TargetPage == "CancellationRequest" || TargetPage == "CancellationConfirm") {
		SecurePage = true;
	}
	if(TargetPage == "ReservationRequest") 
		SubmitToCng = 'true';
		
	//alert ("hi1" + TargetPage);
	// check if default domain to be used for secure pages (https://www.cnghotels.com)
	// - if so set target site to default site
	if (SecurePage) {
		if (SubmitToCng == 'true') {
			if(TargetPage == "ReservationRequest") {
				TargetSite = 'http://www.cnghotels.com/';				
			} else {
				TargetSite = GetElement("DefaultSite").value;
			}
		}
	}
	// first ensure there is no htts already in url - we do not want httpss:// after replace is done
	TargetSite = TargetSite.replace("https", "http");
	
	// set https for required pages
	if (SecurePage)
	{
		// use SSL
		TargetSite = TargetSite.replace("http", "https");
		var SslPort = GetElement('SslPort');
		if (SslPort != null)
		{
			// get the next '/' after http(s)://
			var Start = TargetSite.indexOf('://') + 3;
			var str = TargetSite.substr(Start, TargetSite.length - Start);
			Start = str.indexOf('/') + Start;
			// append the port number to the domain
			TargetSite = TargetSite.substring(0, Start) + ':' + SslPort.value + TargetSite.substring(Start, TargetSite.length);
		}
	}

	// build the action of the page
	var Target = TargetSite + TargetPage + '.aspx?AffiliateId=' + HiddenAffiliateId;

	// submit the page
	if(TargetPage == "Self")
	{
		GetElement('Form').submit();
	}
	else
	{
		// set the target of form before submitting if required
		var FormTarget = GetElement('FormTarget');
		if (FormTarget != null)
			GetElement('Form').target = FormTarget.value;
		GetElement('Form').action = Target;
		GetElement('Form').submit();
	}
	
	// if please wait image exists - reset the source
	if (GetElement('PleaseWait0001') != null)
	{
		var img = GetElement('PleaseWaitImg')
		if (img != null)
			img.src = img.src;
	}
}

function TestMe()
{
	var TargetSite = GetElement("ThisSite").value;
	var TargetPage = GetElement("TargetPage").value;
	var SubmitToCng = GetElement('SubmitToCng').value;
	var SecurePage = false;
	
	// flag if target page is secure
	if(TargetPage == "ReservationRequest" || TargetPage == "ReserveConfirm" || TargetPage == "CancellationRequest" || TargetPage == "CancellationConfirm") {
		SecurePage = true;
	}
	if(TargetPage == "ReservationRequest") 
		SubmitToCng = 'true';
		
	//alert ("hi1" + TargetPage);
	// check if default domain to be used for secure pages (https://www.cnghotels.com)
	// - if so set target site to default site
	if (SecurePage) {
		if (SubmitToCng == 'true') {
			if(TargetPage == "ReservationRequest") {
				TargetSite = 'http://staging.cnghotels.com/';				
			} else {
				TargetSite = GetElement("DefaultSite").value;
			}
		}
	}
	// first ensure there is no htts already in url - we do not want httpss:// after replace is done
	TargetSite = TargetSite.replace("https", "http");
	
	// set https for required pages
	if (SecurePage)
	{
		// use SSL
		TargetSite = TargetSite.replace("http", "https");
		var SslPort = GetElement('SslPort');
		if (SslPort != null)
		{
			// get the next '/' after http(s)://
			var Start = TargetSite.indexOf('://') + 3;
			var str = TargetSite.substr(Start, TargetSite.length - Start);
			Start = str.indexOf('/') + Start;
			// append the port number to the domain
			TargetSite = TargetSite.substring(0, Start) + ':' + SslPort.value + TargetSite.substring(Start, TargetSite.length);
		}
	}

	// build the action of the page
	var Target = TargetSite + TargetPage + '.aspx?AffiliateId=' + HiddenAffiliateId;
	alert (Target);
	// submit the page
	if(TargetPage == "Self")
	{
		GetElement('Form').submit();
	}
	else
	{
		// set the target of form before submitting if required
		var FormTarget = GetElement('FormTarget');
		if (FormTarget != null)
			GetElement('Form').target = FormTarget.value;
		GetElement('Form').action = Target;
		GetElement('Form').submit();
	}
	
	// if please wait image exists - reset the source
	if (GetElement('PleaseWait0001') != null)
	{
		var img = GetElement('PleaseWaitImg')
		if (img != null)
			img.src = img.src;
	}
}

// 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 + "']]";
	}
}

// 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 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 '';
}


// - 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;
}

function RemovePopUpElements()
{
	if(GetElement("PopUpRequestField") == null) {
		
	} else {
		GetElement("PopUpRequestField").value = "";
	}
}

// add an value to the request
function AddPopUpElement(Path, Value)
{
	//alert("value " + Value + " Path " + Path);
	Value = Value.toString().replace('[[', '').replace(']]', '');
	//alert("finieshed1");
	Value = XmlEncode(Value);
	//alert("finieshed2");	
	var obj = GetElement("PopUpRequestField");
	//alert("finieshed3");
	obj.value = obj.value + "[[field id='" + Path + "' value='" + Value + "']]";
	//alert("finieshed4");
}

// sets the target of a page
function SetTransfer(Value)
{
	var obj = GetElement("TargetPage");
	obj.value = 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;
		}
	}
}

// disable a group of elements
function DisableGroup(group)
{
	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]).disabled = true;
		}
	}
}

// enable a group of elements
function EnableGroup(group)
{
	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]).disabled = false;
		}
	}
}

// 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;
}

// return the group name containing the element with the parameter id
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 "";
}

// 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 "";
}

// set the focus of the page on the element in the group passed in
function SetGroupFocus(group)
{
	// check if group exists
	var id = FindId(group);
	var elm = null;
	if (id != '')
	{
		// jump to the control	
		location.href = '#' + group;

		// set the focus on the control
		elm = GetElement(id)
		if (elm != null)
			elm.focus();
	}
}

// opena pop up window
function PopMe(target)
{
	var Day = new Date();
	var Id = Day.getTime();

	var TopPop = screen.height - 900;
	var LeftPop = screen.width - 950;
	var PopWidth = 300;
	var PopHeight = 400;
	
	if(target == 'BigMap')
	{
		PopWidth = 760;
		PopHeight = 520;
	}

	if(target == 'CurrencyConversion')
	{
		PopWidth = 350;
		PopHeight = 550;
	}
	
	if(target == 'Map')
	{
		PopWidth = 590;
		PopHeight = 430;
	}
	
	if(target == 'PopTermsAndConditions')
	{
		PopWidth = 800;
		PopHeight = 520;
	}

	if(target == 'CSC')
	{
		PopWidth = 760;
		PopHeight = 520;
	}

	// add original request to popup request - pop up will now have all the info in the original request
	//GetElement('PopUpRequestField').value += GetElement('RequestField').value;
	//GetElement('OriginalRequestField').value = GetElement('RequestField').value;

	//var Target = target + '.aspx?AffiliateId=' + HiddenAffiliateId + '&culture=' + GetRequestValue('Locale');
	var Target = 'http://www.cnghotels.com/' + target + '.aspx?AffiliateId=74675';
	var PopName = 'Map';

	var PopWin = window.open(Target, PopName, 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=' + PopWidth + ', height=' + PopHeight + ', top=' + TopPop + ', left=' + LeftPop);

	GetElement('PopUpForm').target = PopName;
	GetElement('PopUpForm').action = Target;
	GetElement('PopUpForm').submit();

	PopWin.focus();
}


/*
Code used for global validation - can be used by all pages
*/

/* global validation type - these are the function names for validation */
/* ValidateMe function accepts a '|' separated list of these paramaters */
/* the functions are validated in the order they are passed in  */
/* to add a validation function
   - add the name here and apply to the onchange event of a page element */
var vXmlity = 'ValidateXmlity(obj)';
var vNumeric = 'ValidateIsNumeric(obj)';
var vAlphaNumberic = 'ValidateIsAlphaNumeric(obj)';
var vText = 'ValidateText(obj)';
var vEmail = 'ValidateEmail(obj)';
var vCompareEmail = 'CompareEmail(obj)';


// test required for manditory fields - passed back from server in "Manditory" string
var NonZeroSelected = 'NonZeroSelected';
var NonEmpty = 'NonEmpty';
var NonUnchecked = 'NonUnchecked';

// This is a list of element ids which have failed validation as the user types
var InvalidControls = '';

// controls the display of the error control div
var ShowErrorControl = false;

// calls all validation functions for each element 
function ValidateMe(obj, ValidationString)
{
	// get list of validations to perform
	Validations = new String(ValidationString);
	var ValidationTypes = Validations.split('|');

	// evaluate each validation function
	var i = 0;
	for (i=0; i<ValidationTypes.length; i++)
	{
		// insert failed validations into validation control string
		if(eval(ValidationTypes[i]) == false)
		{
			InvalidControls = InsertId(InvalidControls, obj.id);
		}
		// remove successful validations from validation control string
		else
		{
			InvalidControls = RemoveId(InvalidControls, obj.id);
		}
	}
	
	// if there are errors disable the reserval button
	if(InvalidControls.length == 0)
		EnableGroup('SubmitButton');
	else
		DisableGroup('SubmitButton');

}

// functions to insert and remove object ids from InvalidControls string
function InsertId(s, id)
{
	// remove id from the string if already there
	s = s.replace(id, '');

	// add the id in once
	s += '|' + id;
	
	// trim '|' off ends of string
	s = Trim(s, '|');
	
	return s;
}

function RemoveId(s, id)
{
	// remove id from the string if already there
	s = s.replace(id, '');

	// trim '|' off ends of string
	s = Trim(s, '|');

	return s;
}

// return true for alpha umeric chars
function isAlphaNumeric(ch)
{
	if (ch >= 0 && ch <= 9) return true;
	if (ch >= '0' && ch <= '9') return true;
	if (ch >= 'a' && ch <= 'z') return true;
	if (ch >= 'A' && ch <= 'Z') return true;
	return false;
}

// return true for numberic chars
// - accepts both integers and string characters
function isNumeric(ch)
{
	if (ch >= 0 && ch <= 9) return true;
	if (ch >= '0' && ch <= '9') return true;
	return false;
}

// return true for alpha chars
function isAlpha(ch)
{
	if (ch >= 'a' && ch <= 'z') return true;
	if (ch >= 'A' && ch <= 'Z') return true;
	return false;
}

function isInvalidCharacter(ch)
{
	var BadChars = "";
	if (BadChars.indexOf(ch) == -1) return false;
	return true;
}

// Trim whitespace.
function Trim(s, trimChar) 
{
	while (s.substring(0,1) == trimChar) 
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == trimChar) 
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

// count the number of occurrances of a substring in a string
function CountInstances(string, substring) 
{
	var substrings = string.split(substring);
	return substrings.length - 1;
}

// handle control error lablels
function HandleErrors(id, IsValid)
{
	// get the error message associated with this element
	var errorObj = GetElement(id + '_Error');
	if (errorObj != null)
	{
		if (IsValid)
		{
			// if the control is valid hide the error
			errorObj.style.display = "none";
		}
		else
		{
			// if the control fails validation display the error
			errorObj.style.display = "block";
			// - and set the focus of the page to the invalid element
			SetGroupFocus(FindGroup(id));
		}
	}
}

// returns the clent id of an element with ManditoryField attribute = client id of parameter
function GetManditoryErrorId(ManditoryField)
{
	// get group with the client id of manditory field passed in
	var group = FindGroup(ManditoryField);

	// return the client id of the maditory field with this group
	var value = "";
	var ControlList = ManditoryFields.split('|');
	var Control;
	for(i = 0; i < ControlList.length-1; i++)
	{
		Control = ControlList[i].split('/');
		if(Control[0] == group)
		{
			 value = Control[1];
		}
	}
	return value;
}

// handle mnditory error lablels
// params:
//  id: the client id of the manditory field
//  IsValid: whether the data in the contrl is valid or not
function HandleManditoryErrors(id, IsValid)
{
	// get the client id of the manditory error label which has same group as manditory field
	var ClientId = GetManditoryErrorId(id);
	var errorObj = GetElement(ClientId);

	if (errorObj != null)
	{
		// show error div if not already displayed
		if (!IsValid) SetGroupDisplay('ErrorMessages', 'inline');
		
		// show or hide message
		if (IsValid)
		{
			errorObj.style.display = "none";
		}
		else
		{
			errorObj.style.display = "block";
		}
	}
}

function CheckManditoryFields()
{
	var IsValid = true;
	var ControlList = Manditory.split('|');
	var Control;
	for(j=0; j < ControlList.length-1; j++)
	{
		Control = ControlList[j].split('/');
		if (Control[0] == NonUnchecked)
		{
			if (GetElement(Control[1]).checked == false && GetGroupDisplay(FindGroup(Control[1])).toLowerCase() != 'none')
			{
				IsValid = false;
				HandleManditoryErrors(Control[1], false);
			}
			else
			{
				HandleManditoryErrors(Control[1], true);
			}
		}
		if (Control[0] == NonZeroSelected)
		{
			if (GetElement(Control[1]).selectedIndex == 0 && GetGroupDisplay(FindGroup(Control[1])).toLowerCase() != 'none')
			{
				IsValid = false;
				HandleManditoryErrors(Control[1], false);
			}
			else
			{
				HandleManditoryErrors(Control[1], true);
			}
		}
		if (Control[0] == NonEmpty)
		{
			if (GetElement(Control[1]).value == '' && GetGroupDisplay(FindGroup(Control[1])).toLowerCase() != 'none')
			{
				IsValid = false;
				HandleManditoryErrors(Control[1], false);
			}
			else
			{
				HandleManditoryErrors(Control[1], true);
			}
		}
	}

	return IsValid;
}

// specific validation types
function CompareEmail(obj)
{
	// check if object exists
	if(obj == null)
		return false;

	var IsValid = true;
	var Value = obj.value;

	// test each charadter the same (string1 == string2)
	return true;
}

function ValidateIsNumeric(obj)
{
	// check if object exists
	if(obj == null)
		return false;

	var IsValid = true;
	var Value = obj.value;

	// loop thru string testing each character
	var i = 0;
	for (i=0; i<Value.length; i++)
	{
		if(!isNumeric(Value.charAt(i))) IsValid = false;
	}
	
	// show or hide error labels
	HandleErrors(obj.id, IsValid)

	// retunr false if failed test
	if (IsValid == false)
		return false;
		
	// return true if all tests passed
	return true;
}

function ValidateIsAlphaNumeric(obj)
{
	// check if object exists
	if(obj == null)
		return false;

	var IsValid = true;
	var Value = obj.value;

	// loop thru string testing each character
	var i = 0;
	for (i=0; i<Value.length; i++)
	{
		if(!isAlphaNumeric(Value.charAt(i))) IsValid = false;
	}

	// show or hide error labels
	HandleErrors(obj.id, IsValid)

	// retunr false if failed test
	if (IsValid == false)
		return false;
		
	// return true if all tests passed
	return true;
}

function ValidateText(obj)
{
	// check if object exists
	if(obj == null)
		return false;

	var IsValid = true;
	var Value = obj.value;

	// loop thru string testing each character
	var i = 0;
	for (i=0; i<Value.length; i++)
	{
		if (isInvalidCharacter(Value.charAt(i))) IsValid = false;
	}

	// show or hide error labels
	HandleErrors(obj.id, IsValid)

	// retunr false if failed test
	if (IsValid == false)
		return false;
		
	// return true if all tests passed
	return true;
}

// check if email is in valid format
// used the ".value" property of the emelent passed in
function ValidateEmail(obj)
{
	// check if object exists
	if(obj == null)
		return false;

	var IsValid = true;
	var Value = obj.value;
	var InitialValue = Value;
	
//	// Check that the email is not empty or a string of spaces.
//	if (Trim(Value, ' ') == '') IsValid = false;

	// only one '@'
	if (CountInstances(Value, '@') != 1) IsValid = false
	
	// at least one alpha numeric (start of address)
	if (!isAlphaNumeric(Value.charAt(0))) IsValid = false

	// one '@'
	Value = Value.substring(1, Value.length);
	if (Value.indexOf('@') == -1) IsValid = false;

	// at least one alpha numeric
	Value = Value.substring(Value.indexOf('@') + 1, Value.length);
	if (!isAlphaNumeric(Value.charAt(0))) IsValid = false
	
	// at least one '.'
	Value = Value.substring(1, Value.length);
	if (Value.indexOf('.') == -1) IsValid = false;

	// at least one alpha numeric
	Value = Value.substring(Value.indexOf('.') + 1, Value.length);
	if (!isAlphaNumeric(Value.charAt(0))) IsValid = false

	// if empty string - retrun true - field may not be manditory
	if (InitialValue == '') IsValid = true

	// show or hide error labels
	HandleErrors(obj.id, IsValid)

	// return false if failed test
	if (IsValid == false)
		return false;
	
	// return true if all tests passed
	return true;
}


//*****************************//
// 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('ArrivalDay') == '')
		return;

	// use the last dates the client chose if they exist in the request
	var ArrivalDate = GetRequestValue('Arrival');
	var DepartureDate = GetRequestValue('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('ArrivalMonth', parseInt(ArrivalDate.substr(4, 2), 10) - 1);
		SetGroupSelectedIndex('ArrivalDay', parseInt(ArrivalDate.substr(6, 2), 10) - 1);

		SetGroupSelectedIndex('DepartureMonth', parseInt(DepartureDate.substr(4, 2), 10) - 1);
		SetGroupSelectedIndex('DepartureDay', parseInt(DepartureDate.substr(6, 2), 10) - 1);
	}
	// otherwise calculate them
	else
	{
		// 19 days ahead
		var NumDaysAhead = 19;
	
		// 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('ArrivalMonth', theDate.getMonth());
		SetGroupSelectedIndex('ArrivalDay', theDate.getDate() - 1);
	}
	// set the departure dates from arrival dates
	ChangeArrivalDate();
	
	if(GetGroupValue('NoOfNights') != null){
		SetGroupValue('NoOfNights','1');
	}
}



// 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 = 'ArrivalDay';
	var ArrivalMonth = 'ArrivalMonth';
	var DepartureDay = 'DepartureDay';
	var DepartureMonth = '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();
	}

	// increment theDate by one day
	theDate.setTime(theDate.getTime() + (1000 * 60 * 60 * 24));

	// set departure date from new date
	gDepartureYear = theDate.getFullYear();
	SetGroupSelectedIndex(DepartureMonth, theDate.getMonth());
	SetGroupSelectedIndex(DepartureDay, theDate.getDate() - 1);

	// add dates to the request
	AddElement('Arrival', gArrivalYear + GetGroupValue(ArrivalMonth) + GetGroupValue(ArrivalDay));
	AddElement('Departure', gDepartureYear + GetGroupValue(DepartureMonth) + GetGroupValue(DepartureDay));

// temp dubugging code	
//SetGroupValue('HotelNameFilter', gArrivalYear + GetGroupValue(ArrivalMonth) + GetGroupValue(ArrivalDay) + ', ' + 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 = 'ArrivalDay';
	var ArrivalMonth = 'ArrivalMonth';
	var DepartureDay = 'DepartureDay';
	var DepartureMonth = '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;
}

function HideForPrinting(){

if(GetElement('Menu0001Home') != null){
	GetElement('Menu0001Home').style.display = "none";
}

if(GetElement('PrintButton') != null){
	GetElement('PrintButton').style.display = "none";
}

}

function ShowAfterPrinting(){

if(GetElement('Menu0001Home') != null){
	GetElement('Menu0001Home').style.display = "block";
}

if(GetElement('PrintButton') != null){
	GetElement('PrintButton').style.display = "block";
}

}