function expandCats()	{
	changecss("#directory .categories-block .category-expand", "display", "none");
	changecss("#directory .categories-full", "border", "none");
	changecss("#directory .categories-full", "height", "100%" );
	changecss("#directory .categories-full", "overflow", "none");
}
function setReservation( name, id )	{
	document.getElementById( 'reservation-name' ).innerHTML = name;
	document.getElementById( 'txt_reserve_title' ).value = name;
	document.getElementById( 'txt_reserve_id' ).value = id;
	document.getElementById( 'txt_reserve_security2' ).value = "amsec";
}
function setQuote( name, id )	{
	document.getElementById( 'quote-name' ).innerHTML = name;
	document.getElementById( 'txt_quote_title' ).value = name;
	document.getElementById( 'txt_quote_id' ).value = id;
	document.getElementById( 'txt_quote_security2' ).value = "amsec";
}
function setContact( name, id )	{
	document.getElementById( 'contact-name' ).innerHTML = name;
	document.getElementById( 'txt_contact_title' ).value = name;
	document.getElementById( 'txt_contact_id' ).value = id;
	document.getElementById( 'txt_contact_security2' ).value = "amsec";
}
function changeCategory( obj ) {
	var id = obj.options[obj.selectedIndex].value;
	document.location = '?category=' + id;
}
function changeRegion(category, obj ) {
	document.location = '?category=' + category + '&region=' + obj.options[obj.selectedIndex].value;
}


function GetXMLHttpRequest()
{
	try {
		return ( new ActiveXObject("Msxml2.XMLHTTP2") ) ; 
	} catch (e) {}
	try {
		return ( new ActiveXObject("Microsoft.XMLHTTP") ); 
	} catch (e) {}
	try	{
		return (new XMLHttpRequest());
	} catch (e) {}
	return (null);
}
function addToFavorites( id, title )
{
	var str_guid = addFavourite(id);
	
	var fav_img = document.getElementById("img_fav_" + id );
	var fav_href = document.getElementById("href_fav_" + id );
	
	fav_img.src = "/images/icon-star-on.gif";
	fav_href.href = "?view=favorites";
	fav_href.innerHTML = "Favorite";
	
	var xhttpobject = GetXMLHttpRequest();
	if( xhttpobject == null ) return ;
	xhttpobject.open("GET" , "?view=favorite&id=" + id  + "&guid=" + str_guid , true );
	xhttpobject.send(null);		
	alert( "The listing has been added to your favourites." );
	return;
}
function removeFromFavorites( id, title )
{
	if( confirm( "Are you sure you want to remove this favorite?" ) )
	{
		var str_guid = removeFavourite(id);
		
		var fav_img = document.getElementById("img_fav_" + id );
		var fav_href = document.getElementById("href_fav_" + id );
		
		fav_img.src = "/images/icon-star.gif";
		fav_href.href = "javascript:addToFavorites( " + id + ", '" + title.replace("'","\\'") + "' );";
		fav_href.innerHTML = "Add to Favorites";
		
		document.getElementById( "removefavorite_" + id ).style.display = "none";
		
		if( str_guid != "" )
		{
			var xhttpobject = GetXMLHttpRequest();
			if( xhttpobject == null ) return ;
			xhttpobject.open("GET" , "?view=favorite&action=remove&id=" + id + "&guid=" + str_guid , true );
			xhttpobject.send(null);		
		}			
	}
	return;
}
function addFavourite(id){
	var str_guid = generateGuid();
	if( readCookie("favourites_guid") == null )
		createCookie("favourites_guid",str_guid,365);
	else
		str_guid = readCookie("favourites_guid");
	if( readCookie("favourites") == null )
		createCookie("favourites",":" + id + ":" ,365);
	else
	{
		var contains_cookie = false;
		var str_cookie = readCookie("favourites").split(":");
		var str_newcookie = ":";
		for( var i = 0; i < str_cookie.length; i++ )
		{
			if( str_cookie[i] != null && str_cookie[i] != "" && str_cookie[i] == id )
				contains_cookie = true;
		}
		if( !contains_cookie )
			createCookie("favourites",readCookie("favourites")+id+":",365);
	}
	return str_guid;
}
function removeFavourite(id){
	var str_guid = "";
	var str_cookie = readCookie("favourites");
	
	if( readCookie("favourites_guid") != null )
		str_guid = readCookie("favourites_guid");
	if( str_cookie != null && str_cookie != "" ) {
		str_cookie = str_cookie.split(":");
		var str_newcookie = ":";
		for( var i = 0; i < str_cookie.length; i++ )
		{
			if( str_cookie[i] != null && str_cookie[i] != "" && str_cookie[i] != id )
				str_newcookie += str_cookie[i] + ":";
		}
		createCookie("favourites", str_newcookie, 365);
	}
	//alert('This listing has been removed from your Favourites.');
	return str_guid;
}
function generateGuid()
{
	var result, i, j;
	result = '';
	for( j = 0; j < 32; j++ )
	{
		if( j == 8 || j == 12|| j == 16|| j == 20 )
			result = result + '-';
		i = Math.floor(Math.random()*16).toString(16).toUpperCase();
		result = result + i;
	}
	return result;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
