function removeHTMLTags(strInputCode){
	/* 
	 	This line is optional, it replaces escaped brackets with real ones, 
	 	i.e. < is replaced with < and > is replaced with >
	*/	
	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
		return (p1 == "lt")? "<" : ">";
	});
	
	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
	return strTagStrippedText;		
}

function replaceAll(string, token, newtoken) {
	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
	return string;
}

var waitALittle = function() {
	window.scrollTo(0,0);
    jQuery.blockUI({ 
    	css: { backgroundColor: '#f5f5f5', color: '#000', padding: '5px' }, 
    	message: "<div><img src='http://www.followscience.net/followscience/images/ajax-loader.gif' width='128' height='15' /><br /><h2>"+lang_list[25]+"</h2></div>"
    });
}

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function clearMenus(){jQuery('#submenu-friends, .catdropm').hide();hideBuryMenus();jQuery('#friends-alink').removeClass('current');}
function hideBuryMenus(){for(var i=0;i<14;i++){jQuery('#div'+i).css('display','none');jQuery('#tooltoggle'+i).css('display','none');}}
function handleHover(){jQuery("body").bind("click",function(event){if(!jQuery(event.target).is('.catdrop, #friends-activity')&&(!jQuery(event.target).attr("id")||jQuery(event.target).attr("id").substring(0,10)!='tooltoggle')){clearMenus();}});jQuery('.catdrop').click(function(){var m=jQuery(this).parents('li.h-drop').children('.catdropm');m.toggle();jQuery('.catdropm:visible, #submenu-friends').not(m).hide();jQuery('#friends-alink').removeClass('current');return false;});jQuery('#catdrop').click(function(){var m=jQuery(this).parents('li.h-drop').children('.catdropm');m.toggle();jQuery('.catdropm:visible, #submenu-friends').not(m).hide();jQuery('#friends-alink').removeClass('current');return false;});}

function vote_event(count, id_event, id_user) {
    jQuery.ajax({
        type: "POST",
        url: BASE_URL+"event/vote",
        data: "id_event="+id_event+"&id_user="+id_user,
        success: function(msg){
        	switch (msg) {
		    	case 'not-logged-in' : {
		    		show_cant_vote();
		    		break;
		    	}        	
        		case 'own_event' : {
        			own_event();
        			break;
        		}
        		case 'take_a_time' : {
        			show_take_a_time();
        			break;
        		}        		
        		default : {
		            jQuery("#diglink-event"+count).html("<span>"+lang_list['vote_done']+"</span>");
		            jQuery("#ezm-strong-event"+count).html(msg);        		
        		}
        	}
        }
    }); 
}

function vote_article(count, id_article, id_user) {
    jQuery.ajax({
        type: "POST",
        url: BASE_URL+"account/blog/vote",
        data: "id_article="+id_article+"&id_user="+id_user,
        success: function(msg){
        	switch (msg) {
		    	case 'not-logged-in' : {
		    		show_cant_vote();
		    		break;
		    	}          	
        		case 'own_article' : {
        			own_article();
        			break;
        		}
        		case 'take_a_time' : {
        			show_take_a_time();
        			break;
        		}        		
        		default : {
					jQuery("#diglink-article"+count).html("<span>"+lang_list['vote_done']+"</span>");
		            jQuery("#ezm-strong-article"+count).html(msg);	                 		
        		}
        	}    
        }
    }); 
}

function vote_publication(count, id_library, id_user) {
    jQuery.ajax({
        type: "POST",
        url: BASE_URL+"account/library/vote",
        data: "id_library="+id_library+"&id_user="+id_user,
        success: function(msg){
        	switch (msg) {
		    	case 'not-logged-in' : {
		    		show_cant_vote();
		    		break;
		    	}          	
        		case 'own_article' : {
        			own_article();
        			break;
        		}
        		case 'take_a_time' : {
        			show_take_a_time();
        			break;
        		}        		
        		default : {
					jQuery("#diglink-library"+count).html("<span>"+lang_list['vote_done']+"</span>");
		            jQuery("#ezm-strong-library"+count).html(msg);	                 		
        		}
        	}    
        }
    }); 
}

function show_cant_vote() {
    jQuery.blockUI({ css: { backgroundColor: "#f5f5f5", color: "#000", padding: "5px"}, message: "<h2>"+lang_list['header_action_retriction']+"</h2>" });
    setTimeout(jQuery.unblockUI, 2000);
}

function show_take_a_time() {
    jQuery.blockUI({ css: { backgroundColor: "#f5f5f5", color: "#000", padding: "5px"}, message: "<h2>"+lang_list['header_vote_retriction_2']+"</h2>" });
    setTimeout(jQuery.unblockUI, 2000);
}

function own_event() {
    jQuery.blockUI({ css: { backgroundColor: "#f5f5f5", color: "#000", padding: "5px"}, message: "<h2>"+lang_list['header_vote_retriction_3']+"</h2>" });
    setTimeout(jQuery.unblockUI, 2000);
}

function own_article() {
    jQuery.blockUI({ css: { backgroundColor: "#f5f5f5", color: "#000", padding: "5px"}, message: "<h2>"+lang_list['header_vote_retriction_4']+"</h2>" });
    setTimeout(jQuery.unblockUI, 2000);
}

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode;
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;
   
   return true;
}

function bookmark_event(count, id_event) {
    jQuery.ajax({
        type: "POST",
        url: BASE_URL+"account/bookmarks/bookmark",
        data: "id_event="+id_event,
        success: function(msg){
        	switch (msg) {
		    	case 'not-logged-in' : {
		    		show_cant_vote();
		    		break;
		    	}
        		default : {
        			if (msg=="add") {
            			jQuery('#bookmark'+count).removeClass('bookmark');
            			jQuery('#bookmark'+count).addClass('bookmarked');  				
        			} else if (msg=="delete") {
            			jQuery('#bookmark'+count).removeClass('bookmarked');
        				jQuery('#bookmark'+count).addClass('bookmark');
        			}                		
        		}
        	}    
        }
    }); 
}

function event_attendance(count, id_event) {
    jQuery.ajax({
        type: "POST",
        url: BASE_URL+"account/event/attendance",
        data: "id_event="+id_event,
        success: function(msg){
        	switch (msg) {
		    	case 'not-logged-in' : {
		    		show_cant_vote();
		    		break;
		    	}
        		default : {
        			if (msg=="add") {
            			jQuery('#attendance'+count).removeClass('attendance-not-confirmed');
            			jQuery('#attendance'+count).addClass('attendance-confirmed');    
            			
            			jQuery('#bookmark'+count).removeClass('bookmark');
            			jQuery('#bookmark'+count).addClass('bookmarked');              			
        			} else if (msg=="delete") {
            			jQuery('#attendance'+count).removeClass('attendance-confirmed');
        				jQuery('#attendance'+count).addClass('attendance-not-confirmed');        				
        			}                		
        		}
        	}    
        }
    }); 
}