function findValue(li) {
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
}
function selectItem(li) {
	findValue(li);
}
function formatItem(row) {
	return row[0] + " (" + row[1] + ")";
}
function lookupAjax(){
	var oSuggest = $("#CityAjax")[0].autocompleter;
	oSuggest.findValue();
	return false;
}

function quick_start(){
	$('body').append('<div class="ui-widget-overlay" style="z-index:999; height:'+$('#wrapper').css('height')+';"></div>');
	setTimeout("$('#qs').css('display', 'block');", 500);
	setTimeout("$('#qs_loading').css('display', 'none');", 3000);
}
function qs_close(){
	parent.location.href = '/user/dashboard/';
}
function qs_logout(){
	parent.location.href = '/user/logout/';
}
function qs_profile(username){
	parent.location.href = '/profile/'+username;
}

function home_switch(type){
	if(type == 'jobs'){
		$('#showJobs').css('display', 'block');
		$('#showServices').css('display', 'none');
		$('#link_jobs').removeClass("not-active").addClass("active");
		$('#link_services').removeClass("active").addClass("not-active");
	}
	if(type == 'services'){
		$('#showJobs').css('display', 'none');
		$('#showServices').css('display', 'block');
		$('#link_services').removeClass("not-active").addClass("active");
		$('#link_jobs').removeClass("active").addClass("not-active");
	}
}

var tagit = {
	max_element_id: "assigned-length",
	element_id: "assigned-tags",
	max_add: 5,
	used_color: "#ccc",
	used_cursor: "pointer",
	default_color: "#ffffff",
	default_cursor: "pointer",
	form_id: "form",
	init: function(){
		var source = document.getElementById(this.max_element_id);
		source.innerHTML = "0/"+this.max_add;
	},
	update_counter: function(){
		count = document.getElementById(this.max_element_id);
		count.innerHTML = document.getElementById(this.element_id).childNodes.length+"/"+this.max_add;
	},
	add_tag: function (item){
		var source = document.getElementById(this.element_id);
		if(source.childNodes.length < this.max_add){
			var new_element = source.appendChild(document.createElement('li'));
			new_element.id = "added-"+item;
			var tag = document.getElementById(item);
			tag.style.fontWeight = 'bold';
			tag.style.cursor = this.used_cursor;
			tag.onclick = function() {tagit.remove_tag(item); return false;};
			tag.href = "#";
			new_element.innerHTML = item+'<input type="hidden" name="tags[]" value="'+item+'" />';
			this.update_counter();
		}
	},
	remove_tag:function (item){
		var tag = document.getElementById(item);
		tag.onclick = function() {tagit.add_tag(item); return false;};
		tag.style.background = "#fff";
		tag.style.fontWeight = 'normal';
		var source = document.getElementById(this.element_id);
		source.removeChild(document.getElementById("added-"+item));
		this.update_counter();
	}
};

facebook = {
	init: function(api_key, channel_path, redirect){
		FB_RequireFeatures(["Api"], function(){
			FB.Facebook.init(api_key, channel_path);
			var api = FB.Facebook.apiClient;
			api.requireLogin(function(exception){
				if(redirect){
					location.href = redirect;
				}
				else{
					location.href = '/user/transfer-facebook/';
				}
			});
		});
	}
};




