// show-hide block
    function show(id) {
        document.getElementById(id).style.display = 'inline';
    }
    function hide(id) {
        document.getElementById(id).style.display = 'none';
    }
    
    function show_and_hide(id) {
    	show(id)
    	hide(id.slice(0,-1)+'s')
    }
    
    function hide_and_show(id) {
    	hide(id)
    	show(id.slice(0,-1)+'s')
    }
    
    function setcursor(el,st,end) {
    	if(el.setSelectionRange) {
    		el.focus();
    		el.setSelectionRange(st,end);
    	}
    	else {
    		if(el.createTextRange) {
    			range=el.createTextRange();
    			range.collapse(true);
    			range.moveEnd('character',end);
    			range.moveStart('character',st);
    			range.select();
    		}
    	}
    }	
    
    function flag_problem(node,page) {
    	var form = document.createElement("form");
    	form.method = "post";
    	form.action = "/contact";
  	    var input = document.createElement("input");
	    input.setAttribute("name", "text");
	    input.setAttribute("value", node+page);
	    form.appendChild(input);
  	    var input = document.createElement("input");
	    input.setAttribute("name", "referer");
	    input.setAttribute("value", node);
	    form.appendChild(input);
  	    var select = document.createElement("select");
	    select.setAttribute("name", "type");
	    var option = document.createElement("option");
	    option.setAttribute("value", "fl");
	    select.appendChild(option)
	    form.appendChild(select);
	    document.body.appendChild(form);
	    form.submit();
	    document.body.removeChild(form);
	}
    	
    function PopupCenter(url, name, w, h) {
    	var left = (screen.width/2)-(w/2);
    	var top = (screen.height/2)-(h/2);
//    	var new_name = name + Math.floor(Math.random()*99999);
    	w = window.popup = window.open (url, name, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
    	w.focus()
    }
    	
function appendid(byid, value) {
    document.getElementById(byid).innerHTML += value;
}
function clean_js(val){
 return val.toLowerCase().replace(',','').replace('(','').replace(')','');
}
var spellchecksucks = function (data) {
	var found = false;
        var url='';
	var text = data [0];
	found = false;
	appendid('listdid','<ul>')
	for (i=0; i<data [1].length; i++) {
	    ite = data[1][i];
	    if (!(text.toLowerCase () == clean_js(ite))) {
             url ='http://amplicate.com/{{ node.get_pol_txt }}/' + ite;
	     appendid('listdid','<li><a href="/{{ node.get_pol_txt }}/'+clean_js(ite)+'">'+ite+' {{ node.get_pol_txt }}</a></li>');
	    }
	}
};
var spellcheckrocks = function (data) {
	var found = false;
        var url='';
	var text = data [0];
	typ='rocks';
	found = false;
	appendid('listdid','<ul>')
	for (i=0; i<data [1].length; i++) {
	    ite = data[1][i];
	    if (!(text.toLowerCase () == clean_js(ite))) {
             url ='http://amplicate.com/'+typ+'/' + ite;
	     appendid('listdid','<li><a href="/'+typ+'/'+clean_js(ite)+'">'+ite+' '+typ+'</a></li>');
	    }
	}
};
var spellchecksucks = function (data) {
	var found = false;
        var url='';
	var text = data [0];
	typ='sucks';
	found = false;
	appendid('listdid','<ul>')
	for (i=0; i<data [1].length; i++) {
	    ite = data[1][i];
	    if (!(text.toLowerCase () == clean_js(ite))) {
             url ='http://amplicate.com/'+typ+'/' + ite;
	     appendid('listdid','<li><a href="/'+typ+'/'+clean_js(ite)+'">'+ite+' '+typ+'</a></li>');
	    }
	}
};
var getjs = function (value,pol) {
	if (! value)
		return;
	url = 'http://en.wikipedia.org/w/api.php?action=opensearch&search='+value+'&format=json&callback=spellcheck'+pol;

	//document.getElementById ('listdid').innerHTML = '';
	var elem = document.createElement ('script');
	elem.setAttribute ('src', url);
	elem.setAttribute ('type','text/javascript');
	document.getElementsByTagName ('head') [0].appendChild (elem);
};
function show_grey() {
	document.getElementById('badge-i').className='badge-grey';
	document.getElementById('link-to-red').style.display = 'inline';
	document.getElementById('link-to-grey').style.display = 'none';
	document.getElementById('widget-input-i-grey').style.display = 'inline';
	document.getElementById('widget-input-i-red').style.display = 'none';
}

function show_red() {
	document.getElementById('badge-i').className='badge-red';
	document.getElementById('link-to-grey').style.display = 'inline';
	document.getElementById('link-to-red').style.display = 'none';
	document.getElementById('widget-input-i-red').style.display = 'inline';
	document.getElementById('widget-input-i-grey').style.display = 'none';
}

function input_focus(elem_id) {
	document.getElementById(elem_id).focus();
	document.getElementById(elem_id).select()
}

function f_throbber_src() {
    if ( (typeof(throbber_src) != 'undefined') && throbber_src){
        return throbber_src
    } else {
        return "http://amplicate.com/media/11090901/amplicate-throbber.gif";
    }
}

function validate_not_empty(field_id){
	value = $('#'+field_id).val();
	if (value==null||value==""|| (typeof(txtpre_area) != 'undefined' && value==txtpre_area) )
    {
        $('#validation-error-message').show();
        return false;
    }
	else
		return true;
}

function focus_txtarea(txtpre) {
 $("#add-story-btn-wrapper").show().css("width","600px");
 $("#id_story_text").css("height","100px");
 $("#tags-input").show();
 if ($('#id_story_text').val()==txtpre) {
    $('#id_story_text').val("").css("color","black");
 }
 if ($("#your-opinion-alt")) {
    $("#your-opinion-alt").show();
    $("#your-opinion").hide();
 }
}
function blur_txtarea(txtpre) {
 if ($('#id_story_text').val()=="") {
    $('#id_story_text').val(txtpre).css("color","gray");
 }
}

//fix broken imgs
$(window).bind('load', function() {
	$('img').each(function() {
		if((typeof this.naturalWidth != "undefined" &&
			this.naturalWidth == 0 ) 
			|| this.readyState == 'uninitialized' ) {
			if($(this).attr('id') == 'video'){
				$(this).attr('src', '/media/video.png');
			} else if ($(this).attr('id') == 'image'){
				$(this).attr('src', '/media/image.png');
			} else{
				$(this).attr('src', '/media/silhouette-amplicate.png');
			}
		}
	});
})

function show_login_popup(type){
	div_content = "<div style='margin-top:40px;'> <span style='margin-right:10px;'> <a href='#' title='Sign with twitter' onclick='show_login_twpopup_sw();  return false;'> <img src='" + twitter_signin_src + "' alt='Sign in with Twitter'/></a> </span> <span class='chevron'>OR</span> <span style='margin-left:10px;'> <a href='#' onclick='show_login_fbpopup_sw(); return false;'> <img id='fb_login_image'  src='" + fb_signin_src  + "' alt='Connect' /> </a></span></div>";
	title = 'Please sign in to continue';
	width = 500;
	height = 170;
	if (type == 'post'){
		title = 'Select one method to publish your opinion...'
		height = 280;
		div_content = "<div style='margin-top:10px;'><div><p style='text-align:left'>Sign in with:</p><span style='margin-right:10px;'><a href='#' title='Sign with twitter' onclick='show_login_twpopup_sw(); return false;'><img src='" + twitter_signin_src + "' alt='Sign in with Twitter'/></a></span><span style='margin-left:10px;'><a href='#' onclick='show_login_fbpopup_sw(); return false;'><img id='fb_login_image' src='" + fb_signin_src  + "' alt='Connect' /></a></span></div>  <div style='margin-top:20px;'><p style='text-align:left;'><span style='float:left;margin-left:220px;'>OR</span><br/>Confirm by email:<br/><form id='email-form' style='text-align:left; margin-left:75px; font-size:80%;' onsubmit='submit_email(\"p\"); return false;'><label for='email'>Email</label> <input style='margin-right:5px;' type='text' name='email' id='email-input' /><input type='submit' value='Confirm' onclick='submit_email(\"p\"); return false;'/><div style='color:#999; font-size:80%'>Your email will not be published or shared with third parties.</div></form></p></div></div>";	
	 } else if (type == 'signature'){
		 div_content = div_content.replace("show_login_twpopup_sw", 'show_login_twpopup_signature');
		 div_content = div_content.replace("show_login_fbpopup_sw", 'show_login_fbpopup_signature');
	 } else if (type == 'error'){
		 div_content = '<div style="margin-top:20px;">There was a problem<br/><span style="font-size:80%;">Please try again<br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'; 
		 title = 'Error';
	 } else if (type =='email-thanks'){
		 div_content = '<div style="margin-top:20px; color:#999999;">Please check your email to confirm the opinion.<a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'; 
		 title = 'Almost Done!';
		 height=150;
	 }
	
	$('#dialog-login div').replaceWith(div_content);
    $("#dialog-login").dialog({
        bgiframe: true,
        modal: true,
        width: width,
        close: function(){ $('#share-form').show();
        				   $("#add-story-btn-wrapper").hide();
        				   $("#suggest-tags").val('');
        				   $("#tags-input").hide();
        				   $("#validation-error-message").hide();
        				   $('#id_story_text').val(txtpre_area);
        				   $('#id_story_text').css("color","gray");
        				   $("#id_story_text").css("height","35px");
        				   $("#your-opinion-alt").hide();
        				   $("#your-opinion").show();
        				}
    });
    $("#dialog-login").data('height.dialog', height);
    $("#dialog-login").data('title.dialog', title);
    $("#dialog-login").dialog('open');
}

function publish_cb(post_id, exception){
	if ( (typeof(fbreload) != 'undefined') && fbreload){
		fbreload = false;
		location.reload();
	}
}

function show_login_fbpopup(user_type){
	window.fbshare = true;
	FB.Connect.requireSession(); 
}

function show_login_fbpopup_sw(){
	window.fbshare_sw = true;
	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Facebook<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_fbpopup_sw(); return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	FB.Connect.requireSession(); 
}

function show_login_fbpopup_post(){
	window.fbshare_post = true;
	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Facebook<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_fbpopup_post(); return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	FB.Connect.requireSession(); 
}

function show_login_fbpopup_signature(){
	window.fbshare_signature = true;
	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Facebook<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_fbpopup_signature();  return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	FB.Connect.requireSession(); 
}

function show_login_popup_signature(){
	show_login_popup('signature');
}

function logoutFb(){
	window.login_refresh = true;
	FB.Connect.logout(); 
}

function loginFb(){
	window.login_refresh = true
	FB.Connect.requireSession(); 
}

function check_status(){
    if ( (typeof(fbshare) != 'undefined') && fbshare){
        window.fbreload = true;
        fbshare = false;
        show_fbshare_popup('fb');
    }
    if ( (typeof(fbshare_sw) != 'undefined') && fbshare_sw){
        window.fbreload = true;
        fbshare_sw = false;
        show_fbshare_popup('sw');
    }
    if ( (typeof(fbshare_post) != 'undefined') && fbshare_post){
        window.fbreload = true;
        fbshare_post = false;
        show_fbshare_popup('post');
    }
    if ( (typeof(fbshare_signature) != 'undefined') && fbshare_signature){
        window.fbreload = true;
        fbshare_signature = false;
        add_signature('fb');
    }
    if ( (typeof(login_refresh) != 'undefined') && login_refresh){
         login_refresh = false;
        location.reload();
    }
}

function show_message_popup(user_type){
	if (user_type === 'tw'){
		show_retweet_popup('sw');
	}
	else if (user_type === 'fb'){
		show_fbshare_popup('sw')
	}
}

function show_fbshare_popup(type){
	if ( (typeof(fbshare_txt) == 'undefined') || (typeof(fbshare_attachment) == 'undefined') ){
		// default text when global vars are undefined
		fbshare_txt = 'Text';
		fbshare_attachment = {}
	}
	if (type == 'sw'){
		FB.Connect.streamPublish(swfb_txt, swfb_attachment, null, null, 'Your message', publish_cb);
	} else if (type == 'post') {
		FB.Connect.streamPublish(fbpost_txt, fbpost_attachment, null, null, 'DONE! Your opinion has been posted', publish_cb);
	} else if (type == 'signature'){
		FB.Connect.streamPublish(fbsignature_txt, fbsignature_attachment, null, null, 'DONE! Your signature has been added', publish_cb);
	} else {
		FB.Connect.streamPublish(fbshare_txt, fbshare_attachment, null, null, 'Your message', publish_cb);
	}
}

function show_retweet_popup(type){
	// RT
	if ((type === 'tw') && typeof(retweet) != 'undefined'){
		$('#popup-textarea').val(retweet);
		title = 'Please Confirm';
	}
	// share with friends
	if ( (type === 'sw') && (typeof(swtweet) != 'undefined') ){
		$('#popup-textarea').val(swtweet);
		title = 'Please Confirm';
	}
	
	// after posting
	if ( (type === 'post') && (typeof(post_tweet) != 'undefined') ){
		$('#popup-textarea').val(post_tweet);
		title = "DONE! Your opinion has been posted";
	}
	
	// after signature
	if ( (type === 'signature') && (typeof(signature_tweet) != 'undefined') ){
		$('#popup-textarea').val(signature_tweet);
		title = "DONE! Your signature has been added";
	}
    $("#dialog").dialog({
        bgiframe: true,
        modal: true,
        width: 500,
        height: 170,
        close: check_popup_close
    });
    $("#dialog").data('title.dialog', title);
    $("#dialog").dialog('open');
}

function check_popup_close(){
	if ( (typeof(refresh_update) != 'undefined') && refresh_update){
	    if ( (typeof(redirection_opol_required) != 'undefined') && redirection_opol_required ){
	        window.location=redirection_opol_required;
	    } else {
	        location.reload();
	    }
	}
}

function send_tweet(){
	var data = new Object;
	data.text = $('#popup-textarea').val();
	if ( (typeof(refresh_update) != 'undefined') && refresh_update){
		reload_after = true;
		refresh_update = false;
	}
    $.ajax({
		type:	'POST',
		url:	'api/send-message',
		timeout:	5000,
		data: data,
		cache: false,
		success: function(d,s){
    		if ( (typeof(reload_after) != 'undefined') && reload_after){
    			location.reload();
    			}
    		},
    	error: function(a,b,c){
			   show_login_popup('error');
			   }
		});
    $('#dialog').dialog('close');
}

function hide_dialog_login(){
	$('#dialog-login').dialog('close');
	$("#id_story_text").css("height","35px");
	$("#tags-input").hide();
	$("#add-story-btn-wrapper").hide();
	$("#your-opinion-alt").hide();
	$("#your-opinion").show();
}

function show_login_twpopup(user_type){
	PopupCenter("/twitter/auth?reload_parent=true&action=retweet", "signintw", 900, 700); 
}


function show_login_twpopup_sw(user_type){
    	if ( (typeof(redirection_opol_required) != 'undefined') && redirection_opol_required){
	    redir=redirection_opol_required
	} else {
	    redir = 0
	}

	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Twitter<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_twpopup_sw(); return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	PopupCenter("/twitter/auth?reload_parent=true&action=sw&rediropol="+redir, "signintw", 900, 700); 
}

function show_login_twpopup_post(user_type){
	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Twitter<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_twpopup_post(); return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	PopupCenter("/twitter/auth?reload_parent=true&action=po", "signintw", 900, 700); 
}

function show_login_twpopup_signature(user_type){
	$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Connecting to Twitter<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img><br/><span style="font-size:80%;">Please follow instructions in the <a href="#" onclick="show_login_twpopup_signature(); return false;">window</a><br/><a href="#" onclick="hide_dialog_login(); return false;" class="popup-cancel-lnk" style="margin-right:0px;">Close X</a></span></div>'); 
	PopupCenter("/twitter/auth?reload_parent=true&action=sig", "signintw", 900, 700); 
}

function isLoggedIn(onLoggedIn, onLoggedOut, requiredType) {
	FB.ensureInit(function() { 
	    FB.Connect.get_status().waitUntilReady( function( status ) {
	        if (status == FB.ConnectState.connected) {
	        	if (requiredType != 'tw'){//fb or any
	        		onLoggedIn('fb');
	        		return false;
	        	}
	        }
	        else{
	        	if (requiredType == 'fb'){
	        		onLoggedOut();
	        		return false;
	        	}
	        }
	        //twitter
	        $.ajax({
				type:	'GET',
				url:	'/api/isloggedin',
				timeout:	5000,
				dataType: 'json',
				async: false,
				cache: false,
				success: function(dict,s){ 
		        		if (dict.tw==true) {
		        			onLoggedIn('tw');
		        		} else {
		        			onLoggedOut();
		        		}
	        		},
	        	error: function(a,b,c){
	        			show_login_popup('error');
	        		}
				});
	   });
	});
}

function submit_share_form(){
	if (validate_not_empty('id_story_text')){
		$('#share-form').hide();
		var data = new Object;
		data.text = $('#id_story_text').val();
		data.tags = $("#suggest-tags").val();
		var ajax_url = '/api/send-opinion';
		if ( (typeof(node_ref) != 'undefined') && node_ref){
			data.ref = node_ref;
		} else {
			pathl = window.location.pathname.split('/');
			data.ref = pathl[2] + '-' + pathl[1];
			ajax_url += '?extrainfo=1';
		}
		data.type=$('#opinion-type').val();
	    $.ajax({
			type:	'POST',
			url:	ajax_url,
			timeout:	5000,
			data: data,
			dataType: 'json',
			cache: false,
			success: function(dict,s){
	    			if (dict.login_required){
    					window.redirection_opol_required = false;
					if (dict.redirection_opol_required) {
					    window.redirection_opol_required=dict.redirection_opol_required;
					    }
	    				show_login_popup('post');
	    			} else if (dict.fb){
	    				window.fbreload = true;
					window.redirection_opol_required = false;
					if (dict.redirection_opol_required) {
					    window.redirection_opol_required=dict.redirection_opol_required;
					    }
	    				show_fbshare_popup('post');
					
	    			} else if (dict.tw){
	    				window.refresh_update = true;
					window.redirection_opol_required = false;
					if (dict.redirection_opol_required) {
					    window.redirection_opol_required=dict.redirection_opol_required;
					    }
	    				show_retweet_popup('post');
	    			}
	    		},
	    	error: function(a,b,c){
    			show_login_popup('error');
	    		}	
			});
	}
}

function add_signature(user_type){
	var data = new Object;
	data.ref = node_ref;
	$.ajax({
		type:	'POST',
		url:	'/api/send-signature',
		timeout:	5000,
		data: data,
		cache: false,
		success: function(d,s){
			if (user_type == 'tw'){
				window.refresh_update = true;
				show_retweet_popup('signature');
			} else if (user_type == 'fb'){
				window.fbreload = true;
				show_fbshare_popup('signature');
			}
		},
		error: function(a,b,c){
			show_login_popup('error');
    		}
	});
}

function vote(value, obj_id, vote_type, onresponse){
	var data = new Object;
	data.value = value;
	data.obj_id = obj_id;
	data.vote_type = vote_type;
	$.ajax({
		type:	'POST',
		url:	'/api/send-vote',
		timeout:	5000,
		data: data,
		cache: false,
		success: function(d,s){
			onresponse(obj_id, vote_type);
		},
		error: function(a,b,c){
			onresponse(obj_id, vote_type);
    		}
	});
}

function useful_vote_thanks(obj_id, vote_type){
	$("#useful-vote-"+obj_id).hide();
	$("#useful-vote-"+obj_id+"-thanks").show();
	$("#useful-vote-"+obj_id+"-more").hide();
	$("#useful-vote-"+obj_id+"-thanks-more").show();
}

function report_this(obj_id, obj_type){
	if(typeof(tip_previous) != 'undefined'){
		try{
		$(tip_previous).btOff();
		} catch(err){}
	}
	if (obj_type == 'm'){
		link_id = '#report-msg-'+obj_id;
	}
	if (obj_type == 'p'){
		link_id = '#report-post-'+obj_id;
	}
	$(link_id).bt('Reason?<br/><a href="#" title="Report Spam" onclick="vote(\'s\',\''+obj_id+'\',\''+obj_type+'\', hide_tip); return false">Spam</a><br/><a href="#" title="Report Inappropriate Message" onclick="vote(\'i\',\''+obj_id+'\',\''+obj_type+'\', hide_tip); return false">Inappropriate</a><br/><a href="#" title="Report Error" onclick="vote(\'e\',\''+obj_id+'\',\''+obj_type+'\', hide_tip); return false">Error</a>',
			  {
			    fill: '#FFF',
			    strokeStyle: '#999', 
			    strokeWidth: 1,
			    positions: ['right', 'top'],
			    trigger: 'none',
			    width: '100px',
			    cssClass: 'report-this-tip'
			  });
	$(link_id).btOn();
	window.tip_previous = link_id;
}

function hide_tip(obj_id, vote_type){
	if (vote_type == 'm'){
		link_id = '#report-msg-'+obj_id;
	}
	if (vote_type == 'p'){
		link_id = '#report-post-'+obj_id;
	}
	try{
		$(link_id).btOff();
	} catch(err){}
	$(link_id).after('<span style="color:#999999 !important;">Thank you!</span>').remove();
}

function redirect_contact(text){
	window.location = "/contact?text=" + text
}

function submit_home(type){
	if (type == 'rocks'){
		text = $('#q_rocks').val()
		if (text == ''){
			//window.location='/search'
		} else{
			window.location='/rocks/'+text;
		}
	} else 	if (type == 'sucks'){
		text = $('#q_sucks').val()
		if (text == ''){
			//window.location='/search'
		} else{
			window.location='/sucks/'+text;
		}
	}
}

function submit_email(obj_type){
	if (($('#email-input').val().search('@') != -1)){
		var data = new Object;
		data.email = $('#email-input').val();
		data.obj_type = obj_type;
		$('#dialog-login div').replaceWith('<div style="margin-top:20px;">Sending...<img style="padding-left: 10px;" src="'+ f_throbber_src() +'"></img></div>'); 
		$.ajax({
			type:	'POST',
			url:	'/api/send-email',
			timeout:	5000,
			data: data,
			cache: false,
			success: function(d,s){
				$('#id_story_text').val(txtpre_area);
				show_login_popup('email-thanks');
			},
			error: function(a,b,c){
				show_login_popup('error');
	    		}
		});
	}
}

function update_topic(value, obj_id, onSuccess){
	var data = new Object;
	data.value = value;
	data.obj_id = obj_id;
	$.ajax({
		type:	'POST',
		url:	'/api/update-node',
		timeout:	5000,
		data: data,
		async: false,
		cache: false,
		success: function(d,s){
			if (onSuccess){
				onSuccess();
			}
			$('#actions-done').show();
		},
		error: function(a,b,c){
			alert(a+' '+b+'  '+c);
		}
	});
}

function get_node_list(list_type){
	var data = new Object;
	data.list_type = list_type;
	$("#dropdown-wait").show()
	$.ajax({
	        type:   'GET',
	        url:    '/api/list-nodes',
	        timeout:    10000,
	        data: data,
	        cache: false,
	        success: function(d,s){
				$("#links-list").replaceWith(d);
				$("#dropdown-wait").hide();
	            },
	        error: function(a,b,c){
	    	     alert(a+' '+b+'  '+c);
	    	     $("#dropdown-wait").hide();
	               }
	        });
}

function draw_sparkline(obj_id, obj_id2, obj_id3, polarity){
	var data = new Object;
	data.obj_id = obj_id;
	data.obj_id2 = obj_id2;
	data.obj_id3 = obj_id3;
	data.polarity = polarity;
	$.ajax({
        type:   'GET',
        url:    '/api/get-sparkline',
        timeout:    5000,
        data: data,
        dataType: 'json',
        success: function(d,s){
			$.plot($("#sparkline"), d, {
	            grid: {show: false},
	            series: {lines: {lineWidth: 1} }
	           }
	         );
        },
        error: function(a,b,c){
    	     return false;
               }
        });
}