function deleteStem(stem, fieldName){
	new Effect.Fade(stem+"_tr", 
	    {afterFinish: function(effect){Element.hide(stem+"_tr");
	    $(stem+'_'+fieldName).value='';}});       
}


function walkinCheckboxChanged(){
	if (!$('space_walkins_allowed').checked) 
		$('space_walkin_phrase').value = "";
}

function walkinTextFieldChanged(){
	not_empty = $('space_walkin_phrase').value.length > 0 
	$('space_walkins_allowed').checked = not_empty;
}

function clearAdvancedForm(form){  
	$('article').checked = false
    $('wiki_page').checked = false
	$('task').checked = false
	$('calendar').checked = false
	$('space_file').checked = false
	$('comment').checked = false
}

function setExportOrClone(text){
	$('export_or_clone').value = text
}

var inviteCount = 3;
function addInvite(element){
	inviteTR = "<tr id='invite_###ID###_tr'><td><input class=\"wide smallprint\" id=\"invite_###ID###_email_or_username\" name=\"invite[###ID###][email_or_username]\" type=\"text\" /></td><td><input class=\"wide smallprint\" id=\"invite_###ID###_first_name\" name=\"invite[###ID###][first_name]\" type=\"text\" /></td>  <td><input class=\"wide smallprint\" id=\"invite_###ID###_last_name\" name=\"invite[###ID###][last_name]\" type=\"text\" /></td>  <td><a href=\"javascript:void(0);\" onclick=\"deleteStem('invite_###ID###', 'email_or_username');; return false;\"><img alt=\"Delete\" src=\"http://images.strategy-nets.net/images/shared/delete.gif?1226951770\" /></a></td></tr>";
	html = inviteTR.replace(/###ID###/g, inviteCount);
	$(element).insert({ before: html});
	$("invite_"+inviteCount + "_email_or_username").focus;
	inviteCount += 1;
}   
var ctCount = 1;
function addCustomTab(element){      
	html = tabTR.replace(/###ID###/g, "new_"+ctCount);
	$(element).insert({ before: html});
	$("tab_new_"+ctCount+"_title").focus;
	ctCount += 1;
}
var bmCount = 1;
function addBookmark(element){      
	html = bookmarkTR.replace(/###ID###/g, "new_"+bmCount);
	$(element).insert({ before: html});
	$("bookmark_new_"+bmCount+"_title").focus;
	bmCount += 1;
}         
var catCount = 1;
function addCategory(element){      
	html = categoryTR.replace(/###ID###/g, "new_"+catCount);
	$(element).insert({ before: html});
	$("category_new_"+catCount+"_title").focus;
	catCount += 1;
}
function syncTagRadio(text){
	$('side_pages_tag_recent').checked = text.length == 0;
	$('side_pages_tag_tagged').checked = text.length > 0;
	if (text = '' && $('side_pages_tag').value != '')
		$('side_pages_tag').value = '';
}         
function syncTabFields(popup, url_field){
	area = popup.options[popup.selectedIndex].value
	Element.setVisible(url_field, area=='url//');
}
function updateUrlForSubdomain(){
	$('sd-url').innerHTML = "http://"+$('space_subdomain').value+".strategy-nets.net";    
}
function syncTitleSubdomain(){
	newValue = $('space_title').value.replace(/\s/g, '-');
	if (newValue.indexOf('-') == -1) 
		newValue = newValue + "-space";
	$('space_subdomain').value = newValue;  
	updateUrlForSubdomain();  
}          
function syncTagsRadio(preset){
	if (preset)
		$('space_tags_list').disabled = "";
	else{
		$('space_tags_list').disabled = "disabled";
		$('space_tags_list').value = "";
	}
}
