function ccl_swap_language()
{
s = new String(document.URL);
	
	if (s.indexOf("/en/") != -1)
	{
	s = s.replace("/en/", "/zh/");
	}
	else
	{
	s = s.replace("/zh/", "/en/");
	}

location.href = s;
}

function redirect_login()
{
location.href='/en/users/login/';	
}

function ajax_travel_bag_add(listing_id)
{
	var url = '/en/travel_bag/add/';
	new Ajax.Updater('ccl_travel_bag', url,
	{
	method: 'get',
	parameters: {
	listing_id: listing_id
	}});
	
	ajax_actions_reset();
}

function ajax_travel_bag_remove(listing_id)
{
	var url = '/en/travel_bag/remove/';
	new Ajax.Updater('ccl_travel_bag', url,
	{
	method: 'get',
	parameters: {
	listing_id: listing_id
	}});
	
	ajax_actions_reset();
}

function ajax_travel_bag_empty()
{
	var url = '/en/travel_bag/empty/';
	new Ajax.Updater('ccl_travel_bag', url,
	{method: 'get'});
	
	ajax_actions_reset();
}

function ajax_actions_rate_load(listing_id)
{
	var url = '/en/actions/rate/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts:true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_actions_rate_submit(listing_id)
{
	var url = '/en/actions/rate/save/';
	
	new Ajax.Request(url, {
	parameters: $('ccl_actions_rate').serialize(true)
	});
	
	ajax_actions_reset();
	
	ajax_item_reviews_refresh(listing_id);
}

function ajax_actions_review_load(listing_id)
{
	var url = '/en/actions/review/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts:true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_actions_review_submit(listing_id)
{
	var url = '/en/actions/review/save/';
	
	new Ajax.Request(url, {
	parameters: $('ccl_actions_review').serialize(true)
	});
	
	ajax_actions_reset();
	
	ajax_item_reviews_refresh(listing_id);
}

function ajax_actions_categorize_load(listing_id)
{
	var url = '/en/actions/categorize/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts: true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_action_categorize_add(listing_id, category_id)
{
	var url = '/en/actions/categorize/add/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts: true,
	parameters: {
	category_id: category_id,
	listing_id: listing_id
	}});
}

function ajax_action_categorize_remove(listing_id, category_id)
{
	var url = '/en/actions/categorize/remove/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts: true,
	parameters: {
	category_id: category_id,
	listing_id: listing_id
	}});
}

function ajax_actions_photo_load(listing_id)
{
	var url = '/en/actions/photo/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts: true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_actions_photo_selector_load(listing_id)
{
	var url = '/en/actions/photo_selector/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts: true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_actions_tag_load(listing_id)
{
	var url = '/en/actions/tag/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts:true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_actions_tag_submit(listing_id)
{
	var url = '/en/actions/tag/save/';
	
	new Ajax.Request(url, {
	parameters: $('ccl_actions_tag').serialize(true)
	});
	
	ajax_actions_reset();
	
	//TODO ajax_item_reviews_refresh(listing_id);
}

function ajax_actions_reset()
{
	try
	{
		var url = '/en/actions/reset/';
		new Ajax.Updater('ccl_actions', url,
		{
		method: 'get'
		});
	}
	catch (err)
	{
		
	}
}

function ajax_actions_bookmark_item(listing_id)
{
	var url = '/en/actions/bookmark/item/';
	new Ajax.Updater('ccl_actions', url,
	{
	method: 'get',
	evalScripts:true,
	parameters: {
	listing_id: listing_id
	}});
}

function ajax_item_reviews_refresh(listing_id)
{
	var url = '/en/actions/reviews/refresh/';
	new Ajax.Updater('ccl_item_reviews', url,
	{
	method: 'get',
	parameters: {
	listing_id: listing_id
	}
	});
}

function ajax_login_submit()
{
	var url = '/en/users/login/process/';
	new Ajax.Updater('ccl_login', url,
	{
	parameters: $('ccl_login_form').serialize(true)
	});
}

function ajax_review_vote_submit(review_id, vote)
{
	var url = '/en/actions/review/vote/';
	new Ajax.Updater('ccl_review_votes_' + review_id, url,
	{
	method: 'get',
	parameters: {
	review_id: review_id,
	vote: vote
	}
	});
}

function ajax_add_item_submit()
{
	var url = '/en/actions/item/save/';
	
	new Ajax.Updater('ccl_add_item_form', url,
	{
	evalScripts:true,
	parameters: $('add_item_form').serialize(true)
	});
}

function refresh_add_item_form_phonecode(city_id)
{
	var url = '/en/actions/city/phone_code/';
	
	new Ajax.Updater('ccl_add_item_form_phonecode', url,
	{
	method: 'get',
	parameters: {
	city_id: city_id
	}
	});

}















function ajax_search(parameters)
{
dump(eval(parameters));

	var url = '/en/search/ajax/results.php';
	new Ajax.Updater('search_results', url,
	{
	method: 'get',
	parameters: parameters
	});
	
	var url = '/en/search/ajax/form.php';
	new Ajax.Updater('search_form', url,
	{
	method: 'get',
	parameters: parameters
	});
}

function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
alert(dumped_text);
}

function CCLSearch()
{
	
}

CCLSearch.loadJSON = function(json)
{
this.parameters = eval("(" + json + ")");
}

CCLSearch.addParameter = function(key, value)
{
	//alert(key);
	//alert(value);
eval('this.parameters.' + key + ' = "' + value + '"');
	//alert(this.parameters.city_code);
this.submit();
}

CCLSearch.submit = function()
{
//dump(this.parameters);
new Effect.Opacity('search_results', {from: 1.0, to: 0.3, duration: 0.1});

new Ajax.Updater('search_results', '/en/search/ajax/results.php', {
method: 'get',
parameters: this.parameters,
evalScripts: true
});
}

CCLSearch.resultsLoaded = function()
{
new Effect.Opacity('search_results', {to: 1.0, duration: 0.1});	
}