function addtag(){
	new Insertion.Before('addnew','<input type="text" id="add_tag" name="add_tag" class="smallish" size="10" /><div id="indicator_4" class="wait" style="display: none;"><img src="Resources/spinner.gif" width="16" height="16" /></div><div id="hint4" class="autocomplete"><!-- --></div><script type="text/javascript">var search4 = new Ajax.Autocompleter("add_tag","hint4","tag_suggest.php",{indicator: \'indicator_4\',method: \'get\'});</script>');
	document.getElementById('add_tag').focus();
	return document.getElementById('addnew').style.display = 'none';
	//return Element.update('addnew','<input type="text" id="add_tag" name="add_tag" class="smallish" size="10" /><div id="indicator_4" class="wait" style="display: none;"><img src="Resources/spinner.gif" width="16" height="16" /></div><div id="hint4" class="autocomplete"><!-- --></div><script type="text/javascript">var search4 = new Ajax.Autocompleter("add_tag","hint4","autocompleter.php?c=tags&f=tag&p=add_tag&s=tag",{indicator: \'indicator_4\',method: \'get\'});</script>');
}

function replacetag(tagId){
	new Insertion.Before('replace_' + tagId,'<div id="indicator_' + tagId + '" class="wait" style="display: none;"><img src="Resources/spinner.gif" width="16" height="16" /></div><input type="text" id="replace_tag_' + tagId + '" name="add_tag[' + tagId + ']" class="smallish" size="10" /><input type="submit" id="submit_' + tagId + '" value="ok" /><div id="hint' + tagId + '" class="autocomplete"><!-- --></div><script type="text/javascript">var search' + tagId + ' = new Ajax.Autocompleter("replace_tag_' + tagId + '","hint' + tagId + '","tag_suggest.php",{indicator: \'indicator_' + tagId + '\',method: \'get\'});</script>');
	document.getElementById('replace_tag_' + tagId).focus();
	return document.getElementById('replace_' + tagId).style.display = 'none';
	//return Element.update('addnew','<input type="text" id="add_tag" name="add_tag" class="smallish" size="10" /><div id="indicator_4" class="wait" style="display: none;"><img src="Resources/spinner.gif" width="16" height="16" /></div><div id="hint4" class="autocomplete"><!-- --></div><script type="text/javascript">var search4 = new Ajax.Autocompleter("add_tag","hint4","autocompleter.php?c=tags&f=tag&p=add_tag&s=tag",{indicator: \'indicator_4\',method: \'get\'});</script>');
}

function deletetag(tagId){
	if(confirm('Are you sure you want to delete this tag? There is no Undo.')){
		new Insertion.Before('replace_' + tagId,'<input type="hidden" name="delete_tag[' + tagId + ']" value="1" />');
		return $('formedit').submit();
	}
	return false;
}

var DEF_VAL   = "Search..."; // Default Value
var isSafari = (navigator.userAgent.indexOf("AppleWebKit") !=-1); // Detecting not only Safari but WebKit-based browsers

function searchFields() {
	if(document.getElementById('homeheader')){
		$$('.tabs').each(function(tabs){
			var defTab = (Cookie.get('gsgtab'))?Cookie.get('gsgtab'):'san_francisco';
			new Control.Tabs(tabs,{
				afterChange: function(control_tabs_instance,new_container){
					Cookie.set('gsgtab',new_container.id);
				},
				defaultTab: defTab
		    });
		});
	}
    var theSearchFields = document.getElementsByClassName('search');
	for (var i = theSearchFields.length - 1; i >= 0; i--){
	    if (isSafari) {
	        // Changing type to 'search' from 'text'
	        // and inserting 'autosave,' 'results,' 'placeholder' values for Safari and WebKit-based browsers
	        theSearchFields[i].setAttribute('type', 'search');
	        theSearchFields[i].setAttribute('autosave', 'saved.data');
	        theSearchFields[i].setAttribute('results', '5');
	        theSearchFields[i].setAttribute('placeholder', DEF_VAL);
	    } else {
	        // Doing the 'Live Search'-displaying-&-hiding-stuff for non-WebKit-based browsers
	        if(theSearchFields[i]){
				theSearchFields[i].onfocus    = focusSearch;
	        	theSearchFields[i].onblur     = blurSearch;
	        	if (theSearchFields[i].value=='') theSearchFields[i].value = DEF_VAL;
			}
	    }
	};
}

function focusSearch() {
    if (this.value==DEF_VAL) {
        this.value = '';
    }
}

function blurSearch() {
    if (this.value=='') {
        this.value = DEF_VAL;
    }
}

Event.observe(window,'load',searchFields);


