function changeVisibility(id)
{
	quest = document.getElementById(id);
	//alert(quest.className);
	quest.className = (quest.className == 'visible') ? 'invisible' : 'visible'; 
	//alert(quest.className);
}

/**
	used by copyquestionnaire
*/
function showHideLDAPGroup(mode)
{
	tf = document.getElementById('ldap_group');
	tf.className = (mode == 'LDAP') ? 'visible' : 'invisible'; 
}

/* 
	Find out all ids of the checkboxes (without prefix) and implode them with a '_' as separator 
*/
function collectSelectedIds()
{
	var idsStr = "";
	var SEP = "_";
	selChbs = getSelCheckBoxesStartingWith('sel_');	
	for (i=0; i < selChbs.length;i++)
	{
		var id = selChbs[i].split('_')[1];		
		idsStr += id.toString();
		if (i != selChbs.length-1) //last item
		{
			idsStr += SEP;
		}
	}		
	return idsStr;
}

/* 
	Append all selected ids and the target id to the existing url 
	param a the anchor element where href should be modified
*/
function appendIdSelections(a)
{	
	url = a.href;
	ids = collectSelectedIds();	
	
	targetx = document.getElementById('target').value;	
	url += "&ids=" + ids + "&target=" + targetx;
	a.href = url;

}


/**
only makes sense for closedended questions
*/
function sendAskReason(event, id, itemId, reason)
{
	var isSet = false;
	if (reason!= "") isSet = true;
	if (event == null || event.keyCode == 13)
	{
		makeAjaxCall('itemcreatemodify.qsys?cmd=setaskreason&id=' + id +'&itemId=' + itemId + "&askReason=" + isSet +'&reasonText=' + escape(reason));
	}
}

function sendsemDiffTextsAjax(id, itemId, sub, min, max)
{
	tinyMCE.triggerSave(); //thx to: http://www.crossedconnections.org/w/?p=88 (slightly modified)
	makeAjaxCall('itemcreatemodify.qsys?cmd=setsemdiffitems&id=' + id +'&itemId=' + itemId + "&subQLabel=" + escape(sub.value) + "&minLabel=" + escape(min.value) + "&maxLabel=" + escape(max.value));
}

function sendMatrixTextsAjax(id, cmd, itemId, row, param, tfId)
{
	tinyMCE.triggerSave(); //thx to: http://www.crossedconnections.org/w/?p=88 (slightly modified)
	var tfValue = escape(document.getElementById(tfId).value);
	makeAjaxCall('itemcreatemodify.qsys?cmd=' + cmd + '&id=' + id +'&itemId=' + itemId + "&row=" + row +'&' + param + '=' + tfValue);
}

function sendTextsAjax(id, cmd, tfId)
{
	tinyMCE.triggerSave(); //thx to: http://www.crossedconnections.org/w/?p=88 (slightly modified)
	var tfValue = escape(document.getElementById(tfId).value);
	makeAjaxCall('itemcreatemodify.qsys?cmd=' + cmd + '&id=' + id +'&' + tfId + '=' + tfValue);
}

function sendMainTextAjax(id, cmd, tfId)
{
	tinyMCE.triggerSave(); //thx to: http://www.crossedconnections.org/w/?p=88 (slightly modified)
	tf = document.getElementById(tfId).value;
	var tfValue = escape(tf);
	makeAjaxCall('itemcreatemodify.qsys?cmd=' + cmd + '&id=' + id +'&' + tfId + '=' + tfValue);
	sel = document.getElementById('selected');
	sel.innerHTML  = tf;
}

