function Clear_Dates2()
{
	xmlHttp1 = GetXmlHttpObject();
	var url = "Clear_Dates_Session.asp";
	xmlHttp1.open("GET", url, true);
	xmlHttp1.send(null);			
	document.callingform.startdate.value = "";
	document.callingform.enddate.value = "";
}

function validate_dest()	
{
	if (document.callingform.Dest_Num.value > 1)
	{
		if (document.callingform.Destination.value == "")
		{
			return ! alert("Please select a destination.");
		}
	}		
	
	if (document.callingform.Dest_Num.value > 0)
	{
		if (document.callingform.Destination.value != "")
		{
			xmlHttp1 = GetXmlHttpObject();
			var url = "get_Destination_url.asp?Territory_ID=" + document.callingform.Destination.value;

			xmlHttp1.onreadystatechange = function() 
									{ 
										if (xmlHttp1.readyState == 4)
										{											
											var Dest_url = xmlHttp1.responseText;	
											document.callingform.action = Dest_url;
											document.callingform.submit();													
										}
									}
			xmlHttp1.open("GET", url, true);
			xmlHttp1.send(null);			
		}
	}
}

function validate_autosuggest_res()
{
	if (document.callingform.autoSuggest.value == "")
	{		
		return ! alert("Please enter a Destination or Resort.");
	}		

	var x = new Date(document.callingform.startdate.value);
	var y = new Date(document.callingform.enddate.value);
	
	if (document.callingform.startdate.value == "" && document.callingform.enddate.value != "")
	{
		return ! alert("Please enter an arrival date.");
	}
	if (document.callingform.startdate.value != "" && document.callingform.enddate.value == "")
	{
		return ! alert("Please enter a departure date.");
	}
	if (x > y)
	{
		return ! alert("Departure date cannot be less than arrival date");
	}
	if (document.callingform.startdate.value != "" && document.callingform.enddate.value != "")
	{
		if (document.callingform.startdate.value == document.callingform.enddate.value)
		{
			return ! alert("Departure date cannot be same arrival date");
		}
	}
	
//			if (document.callingform.client.value != "All")			
//			{
//			xmlHttp1 = GetXmlHttpObject();
//			var url = "reservation_Profile_Session_Create.asp?Client_ID=" + document.callingform.client.value;		
//			xmlHttp1.open("GET", url, true);
//			xmlHttp1.send(null);			
//			}			

	if (document.callingform.autoSuggest.value != "")
	{
		if ( '<%=session("portal_client_id")%>' != "")
		{
			var res_page_url;
			var autoSuggest_entity;
			var autoSuggest_ID;
			var autoSuggest = document.callingform.autoSuggest.value;
			var split_array = autoSuggest.split(',');
			autoSuggest = split_array[0];
	
			xmlHttp1 = GetXmlHttpObject();
			var url = "get_res_page_url.asp?autoSuggest=" + autoSuggest + "&start_date=" + document.callingform.startdate.value + "&end_date=" + document.callingform.enddate.value;
			
			xmlHttp1.onreadystatechange = function() 
									{ 
										if (xmlHttp1.readyState == 4)
										{											
											var xmlDoc = xmlHttp1.responseXML.documentElement;
											var x = xmlDoc.getElementsByTagName("autoSuggest_Detail");
	
											for (var i=0;i<x.length;i++)
											{	
												res_page_url = x[i].getElementsByTagName("res_page_url")[0].childNodes[0].nodeValue;
												autoSuggest_entity = x[i].getElementsByTagName("autoSuggest_entity")[0].childNodes[0].nodeValue;										
												autoSuggest_ID = x[i].getElementsByTagName("autoSuggest_ID")[0].childNodes[0].nodeValue;																				
											}
											
											if (x.length > 0)
											{
												if ( autoSuggest_entity == "Client_ID" )
												{
													// New - Arrival Window Validation
													var ajaxurl = "Check_Arrival_Window.asp?start_date="+window.document.callingform.startdate.value+"&end_date="+window.document.callingform.enddate.value+"&client_id="+autoSuggest_ID;
													
													xmlHttp=GetXmlHttpObject();	  
													xmlHttp.open("GET",ajaxurl,false);
													xmlHttp.send(null);		
													var Result = xmlHttp.responseText;
													if ( Result != "1" && Result != ""  )
													{
														return ! alert(Result);
													}														
													// New - Arrival Window Validation
												}
												document.callingform.autoSuggestEntity.value = autoSuggest_entity;
												document.callingform.autoSuggestID.value = autoSuggest_ID;
												document.callingform.action = res_page_url;										
												document.callingform.submit();													
											}
											else
											{
												return ! alert("There are no results for your search. Please try a different search.");
											}
										}
									}
			xmlHttp1.open("GET", url, true);
			xmlHttp1.send(null);			
		}
		else
		{
			alert('Your session has expired. Please refresh.');
		}
	}
}


function destination_sel()
{ 
	if (document.callingform.Destination.value != '')
	{
		$('#country').getSetSSValue('Search by country');
		$('#State').getSetSSValue('Search by state');
		//document.getElementById('StateDiv').style.display = 'none';		
		document.getElementById('CityDiv').style.display = 'none';					
		document.getElementById('destBtnDiv').style.display = 'block';
		document.getElementById('DatesDiv').style.display = 'none';
		//document.getElementById('TeeTimesDiv').style.display = 'none';
	}
	else
	{
		document.getElementById('destBtnDiv').style.display = 'none';
		document.getElementById('SearchBtnDiv').style.display = 'none';
	}
}

function search_type_sel(search_type)
{ 
	if (search_type != 'Tee')
	{
		document.getElementById('DatesDiv').style.display = 'block';
		//document.getElementById('TeeTimesDiv').style.display = 'none';		
	}
	else
	{
		document.getElementById('DatesDiv').style.display = 'none';
		//document.getElementById('TeeTimesDiv').style.display = 'block';		
	}
}

function Get_Selected_Country()
{
	var mySelect = document.getElementById('country');
	for (var i=0; i<mySelect.length; i++)
	{
		if (mySelect.options[i].selected)
		{
			return mySelect.options[i].innerHTML;
		}
	}
}

//fetching and displaying states based on country
function country_sel()
{ 
	xmlHttp1 = GetXmlHttpObject();
	var url = "get_States.asp?Country_Name=" + Get_Selected_Country();

	xmlHttp1.onreadystatechange = function() 
							{ 
								if (xmlHttp1.readyState == 4)
								{	
									document.getElementById("State").length = 0;												
									$('#State').append('<option value="">Search by state</option>').resetSS();													
									
									var xmlDoc = xmlHttp1.responseXML.documentElement;
									var x = xmlDoc.getElementsByTagName("State");

									if ( x.length > 0 )
										document.getElementById('StateDiv').style.display = 'block';
									
									for (var i=0;i<x.length;i++)
									{
										var state_name = x[i].getElementsByTagName("State_Name")[0].childNodes[0].nodeValue;
										$('#State').append('<option value="' + state_name + '">' + state_name + '</option>').resetSS({ddMaxHeight: '200px'});													
									}														
								}
							}
	xmlHttp1.open("GET", url, true);
	xmlHttp1.send(null);

	document.getElementById("City").length = 0;												
	$('#City').append('<option value="">Search by city</option>').resetSS();																

	if (document.callingform.country.value != '')
	{	
		$('#Destination').getSetSSValue('Top Destinations');
		document.getElementById('SearchBtnDiv').style.display = 'block';
		document.getElementById('destBtnDiv').style.display = 'none';
		//document.getElementById('tripPlannerOptions').style.display = 'block';		
		document.getElementById('DatesDiv').style.display = 'block';				
	}
	else
	{
		document.getElementById('SearchBtnDiv').style.display = 'none';
		//document.getElementById('tripPlannerOptions').style.display = 'none';			
	}
}

function client_sel()
{
	if (document.callingform.client.value != '')
	{	
		document.getElementById('SearchBtnDiv').style.display = 'block';
		document.getElementById('DatesDiv').style.display = 'block';				
	}
	else
	{
		document.getElementById('SearchBtnDiv').style.display = 'none';
	}
}

function Get_Selected_State()
{
	var mySelect = document.getElementById('State');
	for (var i=0; i<mySelect.length; i++)
	{
		if (mySelect.options[i].selected)
		{
			return mySelect.options[i].innerHTML;
		}
	}
}

//fetching and displaying states based on country
function state_sel()
{ 	
	xmlHttp1 = GetXmlHttpObject();
	var url = "get_Cities.asp?State_Name=" + Get_Selected_State();

	xmlHttp1.onreadystatechange = function() 
							{ 
								if (xmlHttp1.readyState == 4)
								{		
									document.getElementById("City").length = 0;												
									$('#City').append('<option value="">Search by city</option>').resetSS();													
									
									var xmlDoc = xmlHttp1.responseXML.documentElement;
									var x = xmlDoc.getElementsByTagName("City");

									if ( x.length > 0 )
										document.getElementById('CityDiv').style.display = 'block';
									
									for (var i=0;i<x.length;i++)
									{
										var city_name = x[i].getElementsByTagName("City_Name")[0].childNodes[0].nodeValue;
										$('#City').append('<option value="' + city_name + '">' + city_name + '</option>').resetSS({ddMaxHeight: '200px'});													
									}									
								}
							}
	xmlHttp1.open("GET", url, true);
	xmlHttp1.send(null);
	
	if (document.callingform.State.value != '')
	{	
		$('#Destination').getSetSSValue('Top Destinations');
		document.getElementById('SearchBtnDiv').style.display = 'block';
		document.getElementById('destBtnDiv').style.display = 'none';
		//document.getElementById('tripPlannerOptions').style.display = 'block';		
		document.getElementById('DatesDiv').style.display = 'block';				
		if (document.callingform.State.value == 'British Columbia')
			$('#country').getSetSSValue('Canada');
		else
			$('#country').getSetSSValue('United States');
	}
	else
	{
		document.getElementById('SearchBtnDiv').style.display = 'none';
		//document.getElementById('tripPlannerOptions').style.display = 'none';			
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
	  try
	  {
	  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e)
	  {
	  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  }
	return xmlHttp;
}


