//Array of Resorts
function resortRecord(country_c, country_name, resort_c, resort_name)
{
  this.country_c = country_c
  this.country_name = country_name
  this.resort_c = resort_c
  this.resort_name = resort_name
}

function resortRecordLD(country_c, country_name, resort_c, resort_name, weeks)
{
  this.country_c = country_c
  this.country_name = country_name
  this.resort_c = resort_c
  this.resort_name = resort_name
  this.weeks = weeks
}

function countryRecordLD(country_c, country_name, weeks)
{
  this.country_c = country_c
  this.country_name = country_name
  this.weeks = weeks
}

function weekRecord(week_c, week_desc)
{
  this.week_c = week_c
  this.week_desc = week_desc
}

function soGroupsRecord(country_c, resort_c, so_c, so_desc, so_peak, so_exclusive)
{
  this.country_c = country_c	
  this.resort_c = resort_c
  this.so_c = so_c
  this.so_desc = so_desc
  this.so_peak = so_peak
  this.so_exclusive = so_exclusive
}

function resorts(resort_c, resort_name)
{
  this.resort_c = resort_c
  this.resort_name = resort_name
}

function countries(country_c, country_name)
{
  this.country_c = country_c
  this.country_name = country_name
}

//Create Resort main array
var resortList = Array()
var countryListLD = Array()
var resortListLD = Array()
var weekList = Array()
var soGroupsList = Array()
var justResorts = Array()
var justCountries = Array()

//Create Resort pointer
var resortPoint
var countryPointLD
var weekPoint
var resortPointLD
var justresortsPoint
var justcountriesPoint


function showhelp(newurl,newname) 
{
  apopup=window.open(newurl,newname,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=500,height=350,screenX=10,screenY=10');
}

function doPrint()
{
  window.focus();
  window.print();
}


function FilterDates()
{
	var cmbRsrt = document.getElementById("cmbResort");
	var cmbAva = document.getElementById("cmbAvail");
	var newOpt;
	var str;
	for (var i=cmbAva.options.length-1; i>=0; i--)
		cmbAva.options[i] = null;
	newOpt = new Option("Any Date", "");
	cmbAva.options[cmbAva.options.length] = newOpt;
	
	if (cmbRsrt.options[cmbRsrt.selectedIndex].value == "")
	{
		for (var j=0; j<=weekPoint; j++)
		{
			newOpt = new Option(weekList[j].week_desc, weekList[j].week_c);
			cmbAva.options[cmbAva.options.length] = newOpt;
		}
	}
	else
	{
		for (var i=1; i<=resortPointLD; i++)
		{
			if ('r_'+resortListLD[i].resort_c == cmbRsrt.options[cmbRsrt.selectedIndex].value)
			{
				str = resortListLD[i].weeks;
				for (var j=0; j<=weekPoint; j++)
				{
					if (str.indexOf("#"+weekList[j].week_c+"#") >= 0)
					{
						newOpt = new Option(weekList[j].week_desc, weekList[j].week_c);
						cmbAva.options[cmbAva.options.length] = newOpt;
					}
				}
			}
		}
		for (var m=1; m<=countryPointLD; m++)
		{
			if ('c_'+countryListLD[m].country_c == cmbRsrt.options[cmbRsrt.selectedIndex].value)
			{
				str = countryListLD[m].weeks;
				for (var n=0; n<=weekPoint; n++)
				{
					if (str.indexOf("#"+weekList[n].week_c+"#") >= 0)
					{
						newOpt = new Option(weekList[n].week_desc, weekList[n].week_c);
						cmbAva.options[cmbAva.options.length] = newOpt;
					}
				}
			}
		}
	}
}

//Empty resort list and repopulate with only those corresponding to strCountry
function FilterResortsLD(strCountry)
{
	var cmbRsrt = document.getElementById("cmbResort");
	var newOpt;
	for (var i=cmbRsrt.options.length-1; i>=0; i--)
		cmbRsrt.options[i] = null;
	newOpt = new Option("All Resorts", "");
	cmbRsrt.options[cmbRsrt.options.length] = newOpt;
	for (var i=1; i<=resortPointLD+1; i++)
		if (resortListLD[i].country_c == strCountry || strCountry == "")
		{
			newOpt = new Option(resortListLD[i].resort_name, resortListLD[i].resort_c);
			cmbRsrt.options[cmbRsrt.options.length] = newOpt;
		}

}

//Empty resort list and repopulate with only those corresponding to strCountry
function FilterResorts(strCountry)
{
	var cmbRsrt = document.getElementById("cmbResort");
	var newOpt;
	for (var i=cmbRsrt.options.length-1; i>=0; i--)
		cmbRsrt.options[i] = null;
	newOpt = new Option("All Resorts", "");
	cmbRsrt.options[cmbRsrt.options.length] = newOpt;
	for (var i=0; i<=resortPoint; i++)
		if (resortList[i].country_c == strCountry || strCountry == "")
		{
			newOpt = new Option(resortList[i].resort_name, resortList[i].resort_c);
			cmbRsrt.options[cmbRsrt.options.length] = newOpt;
		}

}

function FilterSetResorts(strCountry,strResort)
{
	var cmbRsrt = document.getElementById("cmbResort");
	var newOpt;
	for (var i=cmbRsrt.options.length-1; i>=0; i--)
		cmbRsrt.options[i] = null;
	newOpt = new Option("All Resorts", "");
	cmbRsrt.options[cmbRsrt.options.length] = newOpt;
	for (var i=0; i<=resortPoint; i++)
		if (resortList[i].country_c == strCountry || strCountry == "")
		{
			newOpt = new Option(resortList[i].resort_name, resortList[i].resort_c);
			if(strResort==resortList[i].resort_c) 
				newOpt.selected = true;
			cmbRsrt.options[cmbRsrt.options.length] = newOpt;
		}

}

function setResorts(strCountry,strResort)
{
	var cmbRsrt = document.getElementById("cmbResort");
	var newOpt;
	for (var i=cmbRsrt.options.length-1; i>=0; i--)
		cmbRsrt.options[i] = null;
	newOpt = new Option("All Resorts", "");
	cmbRsrt.options[cmbRsrt.options.length] = newOpt;
	for (var i=0; i<=resortPoint; i++)
		if (resortList[i].country_c == strCountry || strCountry == "")
		{
			newOpt = new Option(resortList[i].resort_name, resortList[i].resort_c);
			if(resortList[i].resort_c == strResort)
			{
				newOpt.selected = true;
			}
			cmbRsrt.options[cmbRsrt.options.length] = newOpt;
		}

}

function FilterSOGroup(strCountry, strResort)
{
	var cmbSOGrp = document.getElementById("sogroup");
	var newOpt;
	var intPeak;
	var intExclusive;
	var strGroupIds = new String;
	for (var i=cmbSOGrp.options.length-1; i>=0; i--)
		cmbSOGrp.options[i] = null;
	newOpt = new Option("All Offers", "all");
	cmbSOGrp.options[cmbSOGrp.options.length] = newOpt;
	for (var i=0; i<=resortSOGroupsPoint; i++)
	{
			
		if (soGroupsList[i].country_c == strCountry || strCountry == "")
		{
			if (soGroupsList[i].resort_c == strResort || strResort == "")
			{
				if (soGroupsList[i].so_peak == "Y")
					intPeak = 1
				if (soGroupsList[1].so_exclusive == "Y")
					intExclusive = 1
			}
		}
	}
	if (intPeak == 1)
	{
		newOpt = new Option("Peak Dates","peak");
		cmbSOGrp.options[cmbSOGrp.options.length] = newOpt;
	}
	if (intExclusive == 1)
	{
		newOpt = new Option("Exclusive","exclusive");
		cmbSOGrp.options[cmbSOGrp.options.length] = newOpt;
	}
	for (var i=0; i<=resortSOGroupsPoint; i++)
	{
		if (strGroupIds.indexOf('#'+soGroupsList[i].so_c+'#') < 0)
		{
			if (soGroupsList[i].country_c == strCountry || strCountry == "")
			{
				if (soGroupsList[i].resort_c == strResort || strResort == "")
				{
					newOpt = new Option(soGroupsList[i].so_desc, soGroupsList[i].so_c);
					cmbSOGrp.options[cmbSOGrp.options.length] = newOpt;	
					strGroupIds = strGroupIds + '#'+soGroupsList[i].so_c+'#,';
				}
			}
		}
	}	
}

//Set country combo to strResort's country code
function SetCountry(strResort)
{
	var strCtry;
	for (var i=0; i<=resortPoint; i++)
		if (resortList[i].resort_c == strResort)
		{
			strCtry = resortList[i].country_c;
			break;
		}
	var cmbCtry = document.getElementById("cmbCountry");
	for (var i=cmbCtry.options.length-1; i>=0; i--)
		if (cmbCtry.options[i].value == strCtry)
		{
			cmbCtry.options[i].selected=true;
			break;
		}
}

//go to search page
function goSearch(strAdvMode)
{
	parent.parent.parent.right.goSearch(strAdvMode);
}

//go to search results page
function goSearchResults(blnUpdateState)
{
	parent.parent.parent.right.goSearchResults(blnUpdateState);
}

//go to search results page
function goSearchResultsQuick(blnUpdateState)
{
	parent.parent.parent.right.resetSearch();
	parent.parent.parent.right.goSearchResultsQuick(blnUpdateState);
}

//toggle thumbnails on / off
function toggleThumbs(blnState)
{
	parent.parent.parent.right.toggleThumbs(blnState);
}

//go to a given results page
function goPage(intPage)
{
	parent.parent.parent.right.goPage(intPage);
}

//go to comparison page
function goCompare()
{
	parent.parent.parent.right.goCompare();
}

//alter Chalets for comparison list
function changeCompare(intChalet,blnInclude)
{
	return parent.parent.parent.right.changeCompare(intChalet,blnInclude);
}

//alter order by
function changeSort(intValue)
{
	return parent.parent.parent.right.changeSort(intValue);
}

function changeSortButton()
{
	var lstSort = document.getElementById("lstSort");
	return parent.parent.parent.right.changeSort(lstSort.value);
}

function changeSortButton1()
{
	var lstSort1 = document.getElementById("lstSort1");
	return parent.parent.parent.right.changeSort(lstSort1.value);
}

function changeFacilitySort(intValue)
{
	return parent.parent.parent.right.changeFacilitySort(intValue);
}

//email search result list
function email()
{
  var email;
  email=prompt('Enter email address to send these results to','');
  if (email != null)
  {
    var name;
    name=prompt('Enter your name','');
    if (name != null)
        parent.parent.parent.right.email(email,name);
  }
}

//email search result list
function emailSO(soid,countryid,resortid)
{
  var email;
  email=prompt('Enter email address to send these results to','');
  if (email != null)
  {
    var name;
    name=prompt('Enter your name','');
    if (name != null)
        parent.parent.parent.right.emailso(email,name,soid,countryid,resortid);
  }
}

//highlight or dehighlight result rows
function highlight(intRow)
{
	var row = document.getElementById('row_'+intRow);
	if (row)
		row.className='highlighted';
	var row = document.getElementById('row2_'+intRow);
	if (row)
		row.className='highlighted';
}
function dehighlight(intRow)
{
	var row = document.getElementById('row_'+intRow);
	if (row)
		row.className='results';				
	var row = document.getElementById('row2_'+intRow);
	if (row)
		row.className='results';				
}
function checkFacilities(ele)
{
	var numchecked=0;
	if (document.frmSearch.chkTelevision.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkFireplace.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkEnsuite.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkSkiInOut.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkHotTub.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkSauna.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkLaundry.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkParking.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkPool.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkSingleRoom.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkFamilies.checked == true) 
	{numchecked = numchecked+1;}
	if (document.frmSearch.chkShortBreaks.checked == true) 
	{numchecked = numchecked+1;}
	if (numchecked > 4) 
	{ele.checked = false;
	alert('You may only choose up to four facilities per search.');}
}