function showLists() {

	UnTip();
    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'showlists_left'}
    });
}

function deleteList(id,name) {

	if( confirm("Die Liste \""+name+"\" wirklich loeschen?") ) {

	    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
        	 method: 'get',
        	 evalScripts: true,
        	 parameters: {act: 'deletelist', id: id}
    	});
	}
}

function deleteListEntry(urlid,listid,type) {
    
    UnTip();
    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'deleteListEntry', listid: listid, urlid: urlid, type: type}
    });
}

function showListContent(lid) {

    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'showlistcontent_left', id: lid}
    });
}

function newListAdd() {

    if( document.newlistform.type[0].checked == true )  type = 1;
    else                                                type = 2;

    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'addnewlist', name: $('newlistname').getValue(), type: type}
    });    
}

function newList() {

    new Ajax.Updater('lists','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'listform'}
    });  
} 

function delComment(cid) {

	if( confirm('Kommentar wirklich loeschen?') )	{
		
		new Ajax.Request('http://tagmarks.de/ajax.php', {
  			method: 'get',
  			parameters: {act: 'delcomment', id: cid}
  		});
		
		document.getElementById('row_'+cid).style.display='none';
	}
}

function commentForm(urlid,divid) {

    if(!divid)  divname = 'comments';
    else        divname = divid;
            
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'commentform', urlid: urlid}
    });  
}

function dummy() {

	return true;
}

function latestNext(start) {

	UnTip();
    divname = 'snap_main';
   
	new Ajax.Request('http://tagmarks.de/ajax.php?act=latest',
  	{
  		parameters: {start: start},
    	method: 'get',
    	onSuccess: function(transport){
      		response = transport.responseText;
      		$(divname).style.display='none';
      		$(divname).innerHTML = response;
      		new Effect.Appear(divname)
    	}
  	});
}

function nextSuggs(start, ids, urlid) {

    UnTip();
    divname = 'next_suggs';

    document.getElementById(divname).innerHTML="<td height='90'><img src='http://tagmarks.de/img/load1.gif'></td>";

    new Ajax.Request('http://tagmarks.de/ajax.php?act=nextsuggs',
    {
        parameters: {start: start, ids: ids, urlid: urlid},
        method: 'get',
        onSuccess: function(transport){
            response = transport.responseText;
            $(divname).style.display='none';
            $(divname).innerHTML = response;
            new Effect.Appear(divname)
        }
    });
}

function recommend(urlid,step,to,from) {

    if(!step)   step = 1;
    if(!to && step == 2)    to   = document.getElementById('to').value;
    if(!from && step == 3)  from = document.getElementById('from').value; 

    divname = 'rec_'+urlid;
    document.getElementById(divname).innerHTML="<img src='http://tagmarks.de/img/load1.gif'>";
    
    if(step == 1)    { 
      	
    	new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         	method: 'get',
         	parameters: {act: 'recommend', urlid: urlid}
    	});    	
    } 
    
    if(step == 2)  {
         
    	new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         	method: 'get',
         	parameters: {act: 'recommend', urlid: urlid, to: to, step: '2'}
    	});   
    }
    
    if(step == 3) {
    
    	new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         	method: 'get',
         	parameters: {act: 'recommend', urlid: urlid, to: to, step: '3', from: from}
    	});        
    }
 }

function deleteTagMark(urlid,external) {

    if( confirm('TagMark wirklich entfernen?')  ) {

        if(external != 1) {

            document.getElementById('td1_'+urlid).innerHTML="<img src='http://tagmarks.de/img/load1.gif'>";
            document.getElementById('td2_'+urlid).innerHTML="";
            document.getElementById('editBtn'+urlid).innerHTML="";
            document.getElementById('tags'+urlid).innerHTML="";
            document.getElementById('drag_'+urlid).style.display='none';
        }

 		new Ajax.Request('http://tagmarks.de/ajax.php', {
  			method: 'get',
  			parameters: {act: 'delurl', urlid: urlid}
  		}); 

        if(external != 1)  {
            
            document.getElementById('td1_'+urlid).innerHTML="";
        
        } else {
            
            document.getElementById('err'+urlid).style.display='none';
            alert("TagMark wurde entfernt!");
        }
    } 
}

function permaLink(link,listid) {

	UnTip();
    new Ajax.Updater('recommend','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'permalink', link: link, id: listid}
    });
}

function embedList(listid) {

    UnTip();
    new Ajax.Updater('recommend','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'embedlist',  id: listid}
    });
}       

function listrecommend(id) {

	UnTip();
    new Ajax.Updater('recommend','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'recommendlist', id: id}
    });
}

function sendListRecommend(id) {

	new Ajax.Updater('recommend','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'recommend_send', id: id, from: $('from').getValue(), to: $('to').getValue(), msg: $('msg').getValue() }
    });
}

function closeListRecommend(id) {

    new Ajax.Updater('recommend','http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'recommendlistclose', id: id}
    });
}

function setPrivate(urlid) {

    divname = 'privimg_'+urlid;

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'lock', urlid: urlid}
    });
}

function setPublic(urlid) {

    divname = 'privimg_'+urlid;

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'unlock', urlid: urlid}
    });
}

function TagSuggs() {

    if( document.addform.url.value == "" )  return false;

    new Ajax.Updater('tagsuggs','ajax.php', {
         method: 'get',
         parameters: {act: 'tagsuggs', uri:  $('inputurl').getValue()},
         onLoading: function(req) { 
         	$('tagsuggs').innerHTML = "<br /><br /><img src='img/load1.gif'>";
         }
    });
}

function addToMy(urlid) {

	UnTip();
    divname = 'addbtn_'+urlid;

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'addtomy', urlid: urlid},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });       
}

function allTags(urlid) {

    divname = 'tags_'+urlid;

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'alltags', urlid: urlid},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });        
}

function showMoreUser(p,i,name) {

	UnTip();
	divname = "mainlist";
	
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'showmore', p: p, i: i, userpage: 1, name: name},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });    
}


function showMore(p,i) {

	UnTip();
	divname = "mainlist";
	
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'showmore', p: p, i: i},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });    
}

function searchSuggestTimeout() {

    if (window.save_timeout) {
           clearTimeout(window.save_timeout);
    }
    save_timeout = window.setTimeout("searchSuggest()", 500);
}

function searchSuggest() {

    // tooooo short?
    if(document.getElementById("search_home").value.length <= 2) return true;
    
    divname = "mainlist";
    
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         evalScripts: true,
         parameters: {act: 'searchsuggs', q: $('search_home').getValue()},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<br><br><img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });
}

function closeSuggest() {

    divname = "mainlist";

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'searchsuggs', 'default': 1},
         onLoading: function(req) { 
         	$(divname).innerHTML = "<br><br><img src='http://tagmarks.de/img/load1.gif'>";
         }       
    });    
    
	document.getElementById('search_home').value = '';
}

function saveEdited(urlid) {

    divname = "tags"+urlid;
    document.getElementById('okBtn'+urlid).src = "http://tagmarks.de/img/load1.gif";
    newdata = document.getElementById('tagsbox'+urlid).value;
    
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'saveEditedTags', tags: newdata, urlid: urlid}     
    });   
}

function editTags(urlid) {

    divname = "tags"+urlid;
    document.getElementById(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";
    
    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'tagedit', urlid: urlid}
    });   
}

function delete_twitter_connect() {

    if( confirm( "Die Verknüpfung wirklich aufheben?" ) ) {

        divname = 'twitter';
        document.getElementById(divname).innerHTML = "<img src='http://tagmarks.de/img/load1.gif'>";

        new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
            method: 'get',
            parameters: {act: 'delete_twitter_connect'}
        });
    }
}

function save_twitter_connect() {

    divname = "inputfields";
    username = document.getElementById('username').value;
    password = document.getElementById('password').value;

    if( username == "" )  {

        alert("Bitte den Twitter-Benutzernamen angeben!");
        return;
    }

    document.getElementById(divname).innerHTML = "<br><br><img src='http://tagmarks.de/img/load1.gif'>";

    new Ajax.Updater(divname,'http://tagmarks.de/ajax.php', {
         method: 'get',
         parameters: {act: 'save_twitter_connect', username: username, password: password }
    });
}

function reScaleTags() {

    actlen = document.addform.tags.value.length;

    if(actlen > 15)  {
        
        nwidth = ((actlen - 15) * 12 ) + 500;  // ++
        if(nwidth > (screen.width - 300))    nwidth = screen.width - 300;
        document.addform.tags.style.width = nwidth+"px"; // td up
        document.getElementById("tblmain").style.width = nwidth+"px"; // input up

        // new font size
        fsize = 35 - (nwidth / 100);
        if(fsize < 14)  fsize = 14;
        document.addform.tags.style.fontSize = fsize+"px";

    } else {

        document.addform.tags.style.width = "500px";
        document.addform.tags.style.fontSize = "30px";
        document.getElementById("tblmain").style.width = "500px";
    }
}

function reScaleURI() {

    actlen = document.addform.url.value.length;

    if(actlen > 30)  {

         nwidth = ((actlen - 30) * 5 ) + 500;  // je um $_ vergroessern
         document.addform.url.style.width = nwidth+"px"; // td up
         document.getElementById("tblmain").style.width = nwidth+"px"; // input up

         // new font size
         fsize = nwidth / 100 * 2.8;
         document.addform.url.style.fontSize = fsize+"px";
         document.addform.url.value =  actlen = document.addform.url.value + " ";

    } else {

        document.addform.url.style.width = "500px";
        document.addform.url.style.fontSize = "30px";
        document.getElementById("tblmain").style.width = "500px";
    }   

}


function addTag(tag) {

    if(document.addform.tags.value != "")  document.addform.tags.value = document.addform.tags.value + " " + tag;
    else                                   document.addform.tags.value = tag;
}

function LogOut() {

    if( confirm("Bitte beachte, dass das Suchplugin im Browser danach NICHT mehr funktioniert!\n\nTrotzdem ausloggen?") )   {

        window.location = "http://tagmarks.de/index.php?header=logout";
    }
}

function showMenu(das) {

    if(document.getElementById(das).style.display=='none')     {
        
        document.getElementById(das).style.display='inline'; 
        document.getElementById('usernav_bullet').src = 'http://tagmarks.de/img/bullet_up.gif';

    } else {
        
        document.getElementById(das).style.display='none';
        document.getElementById('usernav_bullet').src = 'http://tagmarks.de/img/bullet.gif';
    }
}

function searchGo() {

    term = $('searchforminput').value;

    if( term.length < 3)   alert("Bitte einen Suchbegriff mit mind. 3 Zeichen angeben!");
    else                   window.location = "http://tagmarks.de/tag/"+term+"/";

}


