

function fillResultListPopular(id, link, title, photo, name, city, country, state, style, theme, content, total, query_url, list_page, list_title)
{
	elem = document.getElementById(id);
	var num = content.length;
	var htmlcontent = '<table><tr><td width="210" colspan="2" style="vertical-align:top; text-align:left;">';
	htmlcontent +='<h3>'+list_title+'</h3></td></tr><tr>';
	for (i=0; i<num; i++)
	{
		var href = link.shift();
		var temp = ''; //<tr><td class="item_photo_cell">';
//		temp += '<img class="item_photo" src="' + photo.shift() + '" />';
		var t = title.shift();
		temp += '<tr><td colspan="2"><span class="popular_title"><a href="' + href + '" title="'+ t +'">' + t + '</a></span></td></tr>';
		temp += '<tr><td style="vertical-align:top; text-align:left; padding-top:0;">';//'</td><td class="item_desc_cell">';
		temp += '<a href="' + href + '"><img class="item_photo" src="' + photo.shift() + '" style="width:64px; height:48px;" alt="" /></a></td><td style="vertical-align:top; text-align:left; border-bottom:1px dashed #000000; padding-bottom:5px; padding-top:0;">';
			temp += '<span class="popular_content">' + style.shift() + ', ' + theme.shift() + '<br />';
		temp += city.shift() + ', ' + country.shift() + '</span>';		
		temp += '</td></tr>';
		htmlcontent += temp;
	}
	htmlcontent += '</tr></table>';
	try{
		elem.innerHTML = htmlcontent;
	}
	catch(err)
	{}
}

function fillResultListDynamic(id, link, title, photo, name, city, country, state, style, theme, content, total, query_url, list_page)
{
	elem = document.getElementById(id);
	var num = content.length;
	var pages = Math.ceil(total/10);
	var htmlcontent = '';
	var pagination = '<div class="pagination"><span>';
	
	if (pages > 1)
	{
		var page = parseInt(list_page, 10);
		if (page > 2) pagination += ' <a href="javascript:go(\''+query_url+'&p=1\')">' + multilang['first'] + '</a> - ';
		if (page > 1) pagination += ' <a href="javascript:go(\''+query_url+'&p='+(page-1)+'\')">'+multilang['previous']+'</a> - ';
	    pagination += multilang['page'] + ' ' + list_page + ' ' + multilang['of'] + ' ' + pages;
		if (page < pages) pagination += ' - <a href="javascript:go(\''+query_url+'&p='+(page+1)+'\')">'+multilang['next']+'</a>';
		if (page < (parseInt(pages, 10)-1) ) pagination += ' - <a href="javascript:go(\''+query_url+'&p='+pages+'\')">'+multilang['last']+'</a>';
		pagination += '</span></div>';
	}
	else
	{
		pagination = '';
	}
	htmlcontent += pagination;
	htmlcontent += '<table><tr><td width="180" rowspan="11" style="vertical-align:top; text-align:center;">';
/*		
	htmlcontent += '<h2>Search options</h2>';

	htmlcontent += '<div class="tabs"><span class="top"></span><div class="tabs_content">';
	htmlcontent += '<span class="item_title">Theme</span>';
	htmlcontent += '<input type="checkbox">Creative<br />';
	htmlcontent += '<input type="checkbox">Culinary<br />';
	htmlcontent += '<input type="checkbox">Gallery<br />';
	htmlcontent += '<input type="checkbox">Nature<br />';
	htmlcontent += '<input type="checkbox">Sportive<br />';
	htmlcontent += '<input type="checkbox">Spiritual<br />';
	htmlcontent += '<input type="checkbox">Wellness<br />';
	htmlcontent += '<input type="checkbox">Wedding<br />';
	htmlcontent += '<input type="checkbox">Vineyard<br />';
	htmlcontent += '<input type="checkbox">Other<br />';
	htmlcontent += '</div><div class="bottom"><span> </span></div></div>';	

	
	htmlcontent += '<div class="tabs"><span class="top"></span><div class="tabs_content">';
	htmlcontent += '<span class="item_title">Features</span>';
	htmlcontent += '<input type="checkbox">Swimming Pool<br />';
	htmlcontent += '<input type="checkbox">Hot Tub / Sauna<br />';
	htmlcontent += '<input type="checkbox">Waterfront<br />';
	htmlcontent += '<input type="checkbox">Water View<br />';
	htmlcontent += '<input type="checkbox">TV<br />';
	htmlcontent += '<input type="checkbox">Non-Smoking<br />';
	htmlcontent += '<input type="checkbox">Handicapped Access<br />';
	htmlcontent += '<input type="checkbox">Pets Allowed<br />';
	htmlcontent += '</div><div class="bottom"><span> </span></div></div>';	
*/
	htmlcontent += '</td><td colspan="2"></td></tr>';
	for (i=0; i<num; i++)
	{

		var href = link.shift();
		var temp = '<tr><td class="item_photo_cell">';
		temp += '<a href="' + href + '"><img class="item_photo" src="' + photo.shift() + '" alt="" /></a>';
		temp += '</td><td class="item_desc_cell">';
		temp += '<span class="item_title">' + title.shift() + '</span>';		
		temp += '<span class="item_city">' + city.shift() + '</span>';		
		temp += '<span class="item_country">' + country.shift() + '</span>';		
		temp += '<span class="item_content">' + content.shift() + '</span>';
		temp += '<span class="item_link"><a href="' + href + '" class="readmore">'+multilang['read_more']+'</a></span><br />';		
		temp += '</td></tr>';
		htmlcontent += temp;

	}
	htmlcontent += '</table>';
	htmlcontent += pagination;
	elem.innerHTML = htmlcontent;
	document.getElementById('dynamic').style.display='none';
	
	try{
		elem.style.display='block';
	}
	catch(err)
	{}
}



function ifx_xmlRequest ()
{
	this.url = '';
	var that = this;
	
	this.init = function ()
	{
		try	{ that.xmlHttpRequest = new XMLHttpRequest(); }
		catch (err)
		{
			try	{ that.xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (err)
			{
				try	{that.xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch (err) { that.xmlHttpRequest = false; }
			}
		}
	}
	
	this.loadData = function ()
	{

		text = that.xmlHttpRequest.responseText;
		//alert(text);

		var xml = '';
		if (typeof DOMParser != "undefined")
		{// Mozilla, Firefox, and related browsers
			var parser=new DOMParser();
			xml=parser.parseFromString(text,"text/xml");
		}
		else if (typeof ActiveXObject != "undefined")
		{// Internet Explorer.          
			xml = new ActiveXObject("Microsoft.XMLDOM");  // Create an empty document
			xml.loadXML(text);// Parse text into it
		}

		// extract SELECT elements
		var selects = xml.getElementsByTagName("SELECT");
		for (var i=0; i<selects.length; i++)
		{
			var select_id = selects.item(i).attributes.getNamedItem("id").nodeValue;	
			var select_sel = selects.item(i).attributes.getNamedItem("selected").nodeValue;			
			var select_elem = document.getElementById(select_id);
			select_elem.options.length=0;		
			var iOpt = 0;
			for (var iChildId = 0; iChildId < selects.item(i).childNodes.length; iChildId++)
			{  
				iChild = selects.item(i).childNodes.item(iChildId);  
				if (iChild.nodeType === 1 && !iChild.prefix)
				{ // nodeType is "Element" (1)  
					var id = iChild.attributes.getNamedItem("id").nodeValue;
					var content = iChild.childNodes[0].nodeValue;	
					if (id != select_sel)
						select_elem.options[iOpt]=new Option(content, id, false, false);
					else
						select_elem.options[iOpt]=new Option(content, id, true, true);

					iOpt++;
				}
			}
		}

		// extract LIST elements
//		alert('Getting result list');
		var list = xml.getElementsByTagName("LIST");
//		alert('number of lists: ' + list.length);
		for (var i=0; i<list.length; i++)
		{
//			alert('list item: ' + i);
//			alert('number of child nodes: '+ list.item(i).childNodes.length);
			var list_id = list.item(i).attributes.getNamedItem("id").nodeValue;	
			var list_total = list.item(i).attributes.getNamedItem("total").nodeValue;			
			var list_title = '';
			try
			{
			  list_title = list.item(i).attributes.getNamedItem("title").nodeValue;	
			}
			catch(err)
			{}
			var list_query = '';
			try
			{
			   list_query = list.item(i).attributes.getNamedItem("request").nodeValue;
			}
			catch(err)
			{ }
			var list_page = '';
			try
			{
			   list_page = list.item(i).attributes.getNamedItem("page").nodeValue;
			}
			catch(err)
			{ }
			var list_elem = document.getElementById(list_id);
			var htmlcontent = '';
			var iOpt = 0;
			var link = Array();
			var title = Array();
			var photo = Array();
			var name = Array();
			var city = Array();
			var country = Array();
			var state = Array();
			var style = Array();
			var theme = Array();
			var content = Array();

			for (var iChildId = 0; iChildId < list.item(i).childNodes.length; iChildId++)
			{  
				iChild = list.item(i).childNodes.item(iChildId);  
				if (iChild.nodeType === 1 && !iChild.prefix)
				{ // nodeType is "Element" (1)  
					link.push(iChild.attributes.getNamedItem("link").nodeValue);
	//				title.push(iChild.attributes.getNamedItem("title").nodeValue);
					y = iChild.getElementsByTagName("TITLE");
					x=y[0].childNodes[0];
					title.push(x.nodeValue);
					photo.push(iChild.attributes.getNamedItem("photo").nodeValue);
	//				name.push(iChild.attributes.getNamedItem("name").nodeValue);
					y=iChild.getElementsByTagName("NAME");
					x=y[0].childNodes[0];
					name.push(x.nodeValue);				
					city.push(iChild.attributes.getNamedItem("city").nodeValue);
					country.push(iChild.attributes.getNamedItem("country").nodeValue);
					state.push(iChild.attributes.getNamedItem("state").nodeValue);
					style.push(iChild.attributes.getNamedItem("style").nodeValue);
					theme.push(iChild.attributes.getNamedItem("theme").nodeValue);
					y = iChild.getElementsByTagName("CONTENT");
					x=y[0].childNodes[0];
					content.push(x.nodeValue);
		//			content.push(iChild.childNodes[0].nodeValue);	
//					alert ('child id: ' + iChildId + ' => ' + content);
					iOpt++;
				}
			}
			if (list_id=='popular')
				fillResultListPopular(list_id, link, title, photo, name, city, country, state, style, theme, content, list_total, list_query, list_page, list_title);
			else
				fillResultListDynamic(list_id, link, title, photo, name, city, country, state, style, theme, content, list_total, list_query, list_page);

		}
		
		// extract TEASER elements
		var teaser = xml.getElementsByTagName("TEASER");
		if (teaser.length > 0)
		{
			var teaser_img = document.getElementById('teaser_image');
			var teaser_text = document.getElementById('teaser_text');
			y = teaser[0].getElementsByTagName("IMAGE");
			x=y[0].childNodes[0];
			teaser_img.src = x.nodeValue;
			y = teaser[0].getElementsByTagName("CONTENT");
			x=y[0].childNodes[0];
			teaser_text.innerHTML = x.nodeValue;
		}

	}
	
	this.response = function ()
	{
		switch (that.xmlHttpRequest.readyState)
		{
		case 1: break;
		case 2:	break;
		case 3:	break;
		case 4:
			if (that.xmlHttpRequest.status == 200) that.loadData();
			else alert ('Error: data not fetched');	
		}
	}

	this.getPage = function (request_url, bRandom)
	{
		if (typeof bRandom == "undefined") bRandom = false;
		this.url = request_url;
		if (bRandom == true) { myRand = parseInt(Math.random()*999999999999); this.url += '&rand=' + myRand; }
		that.xmlHttpRequest.open("GET", this.url, true);
		that.xmlHttpRequest.onreadystatechange = this.response;
		that.xmlHttpRequest.send(null);
	}
	
	this.init();
}

var ajax_obj = new ifx_xmlRequest;
function go(query)
{
	ajax_obj.getPage('ajax.php?' + query );
}
