//------------------------------------------------------------------------------
function dispResponse(responseText)
{
	//alert(responseText);

	var doc		= new Array(); 
	var content	= new Array();
	var sel;

	content		= responseText.split("@#@#");
	//alert(content);
	if(flag1	== "country")
	{
		document.searchForm.city.options.length = 0;
		//document.searchForm.city.options[0] = new Option("Hotel by City/Atoll",""); 
		document.searchForm.city.options[0] = new Option("All Cities / Atolls","all"); 
	}
	else
	{
		document.searchForm.name.options.length = 0;
		document.searchForm.name.options[0] = new Option("Hotel by Name",""); 
	}
	var recs = (flag1 == "country") ? content.length : content.length;
	var begin = (flag1 == "country") ? 1 : 1;
	for (var x = begin; x < recs; x++)
	{ 
		doc		= content[x-1].split("##");
		//alert(doc[1]);return false;
		if(flag1 == "country")
		{
			//document.searchForm.city.options.length = 0;
			document.searchForm.city.options[x] = new Option(doc[1],doc[0]); 	
		}
		else
		{
			document.searchForm.name.options[x] = new Option(doc[1],doc[0]); 	
		}
	}
	if(flag1 == "country")
	{
		process_order	+=	1;
		updateCityAndHotel(form1);
	}
	else
	{
		process_order	=	0;
	}
	
	
	/*
	arrContent	=	responseText.split("@#@#");
	document.getElementById("cart_items").innerHTML = arrContent[0];
	document.getElementById("products_container").innerHTML = arrContent[1];
	*/
}
//------------------------------------------------------------------------------
function getRecords(form, flag)
{
	output		=	'text';
	url			=	document.location.href;
	x			=	url.indexOf(".");
    x			=	url.indexOf("/",x);
	url			=	url.substring(0,x)+"/quick_search.php";
	fields		=	new Array();

	country		=	encodeURI(form.country.value);
	
	fields.push("country="+country);	
	
	if(flag != "country")
	{
		city	=	encodeURI(form.city.value);
		fields.push("city="+city);
	}
	else
	{
		city	=	"";
	}
	fields.push("country="+country);

	qs	=	fields.join('&');
	//alert(qs);
	submitForm(url,qs,flag);
	return false;
}
//------------------------------------------------------------------------------
function qsChk(form, fld, flag)
{
	if(fld.value == "") { alert("Please select a "+flag); fld.focus(); return false; }
	getRecords(form, flag);
	return false;
}
//------------------------------------------------------------------------------
var process_order	=	0;
var form1;
function updateCityAndHotel(form)
{
	form1	=	form;
	switch(process_order)
	{
		case 0:
			qsChk(form, form.country, 'country');
			break;
		case 1:
			qsChk(form, form.city, 'City/Atoll');
			break;
	}
}
//------------------------------------------------------------------------------
function doAction(form,obj)
{
	var url;
	url			=	document.location.href;
	x			=	url.indexOf(".");
    x			=	url.indexOf("/",x);
	url			=	url.substring(0,x);
	id			=	obj.options[obj.selectedIndex].value;

	if(form.country.value == "MALDIVES")
	{
		url	=	url+"/maldives/travel/traveldetail/"+id;
	}
	else if(form.country.value == "DUBAI")
	{
		url	=	url+"/dubai/travel/traveldetail/"+id;
	}
	else
	{
		url	=	url+"/travel/traveldetail/"+id;
	}
	document.location.href	=	url;
	return true;
}
//------------------------------------------------------------------------------
function validate_qs(form)
{
	if(form.country.value == "") { alert('Please select Country'); return false; }
	//if(form.city.value == "") { alert('Please select City / Atoll'); return false; }
}
//------------------------------------------------------------------------------

function onLoadProcess()
{
	if(typeof(document.searchForm) == 'object')
	{
		var locn = document.location.href;
		if(locn.indexOf("dubai") != -1 || locn.indexOf("DUBAI") != -1)
		{
			document.searchForm.country.value = 'DUBAI';
			document.searchFormBudget.country.value = 'DUBAI';
		}
		else if(locn.indexOf("maldives") != -1 || locn.indexOf("MALDIVES") != -1)
		{
			document.searchForm.country.value = 'MALDIVES';
			document.searchFormBudget.country.value = 'MALDIVES';
		}
		else
		{
			document.searchForm.country.value = 'SRILANKA';
			document.searchFormBudget.country.value = 'SRILANKA';
		}
		updateCityAndHotel(document.searchForm);
	}
}

window.onload	=	onLoadProcess;
