// JavaScript Document
function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function f_popup(url,param_width,param_height, param_x, param_y)
{
	var newwindow = randomString();
	var name = randomString();
	var param = '';
	if (param_width !=''){param += 'width='+param_width;}
	if (param_height && param !=''){param += ',';} if(param_height){param += 'height='+param_height;}
	if (param_x && param !=''){param += ',';} if (param_x){param += 'screenX='+param_x;}
	if (param_y && param !=''){param += ',';} if (param_y){param += 'screenY='+param_y;}
	newwindow=window.open(url,name,param);
	if (window.focus) {newwindow.focus()}

}
function go_right(left,right)
{
	var box1 = document.forms['form_document'].elements[left];
	if (box1.selectedIndex >=0)	
	{
		var change = 'yes';
		var selected_value = box1.options[box1.selectedIndex].value;
		var selected_text = box1.options[box1.selectedIndex].text;
		
		var box2 = document.forms['form_document'].elements[right];
		
		for (i=0;i<box2.options.length;i+=1)
		{
			if (box2.options[i].value == selected_value) {var change='no'; break;}
		}
		if (change=='yes')
		{
			box2.options[box2.options.length] = new Option(selected_text, selected_value);
		}
	}
}
function go_left(right)
{
	var box2 = document.forms['form_document'].elements[right];	
	if (box2.selectedIndex >=0)
	{
		var selected_value = box2.selectedIndex;
		box2.options[selected_value] = null;	
	}	
}

function go_up(box_name)
{
	var box2 = document.forms['form_document'].elements[box_name];	
	if (box2.selectedIndex >0 & box2.options.length >= 2)
	{
		if (box2.options[box2.selectedIndex-1])
		{
		var previous_text = box2.options[box2.selectedIndex-1].text;
		var previous_value = box2.options[box2.selectedIndex-1].value;
		
		box2.options[box2.selectedIndex-1].text = box2.options[box2.selectedIndex].text;
		box2.options[box2.selectedIndex-1].value = box2.options[box2.selectedIndex].value;
		box2.options[box2.selectedIndex].text = previous_text;
		box2.options[box2.selectedIndex].value = previous_value;
		box2.options[box2.selectedIndex-1].selected = true;
		}
	}	
}

function go_down(box_name)
{
	var box2 = document.forms['form_document'].elements[box_name];	
	if (box2.selectedIndex >=0 & box2.selectedIndex <box2.options.length-1 & box2.options.length >= 2)
	{
		if (box2.options[box2.selectedIndex+1])
		{
		var next_text = box2.options[box2.selectedIndex+1].text;
		var next_value = box2.options[box2.selectedIndex+1].value;
		
		box2.options[box2.selectedIndex+1].text = box2.options[box2.selectedIndex].text;
		box2.options[box2.selectedIndex+1].value = box2.options[box2.selectedIndex].value;
		box2.options[box2.selectedIndex].text = next_text;
		box2.options[box2.selectedIndex].value = next_value;
		box2.options[box2.selectedIndex+1].selected = true;
		}
	}	

}

function save() {
		// data treatment for the indexterms:
		var box1 = document.forms['form_document'].indexterm_select;
		var box1_content = '';
		for (i=0;i<box1.length;i+=1)
		{
			box1_content += box1.options[i].value+',';
		}
		if(box1_content.length>0){box1_content = box1_content.substr(0,box1_content.length-1);}
		document.forms['form_document'].indexterm_after.value = box1_content;
		
		//save
		document.forms['form_document'].submit();

}
function add_element(box,nvl_elmt_text,nvl_elmt_index)
{
	var nv_elmnt = new Option(nvl_elmt_text,nvl_elmt_index);
	var nb = box.options.length;
	box.options[nb] = nv_elmnt ;
}

function close_doc_FCKissue() 
{
			FCKEditorAPI = null;
			__FCKeditorNS = null;
			oChildNode = document.body.firstChild;
			while(oChildNode != null)
			{
				if(oChildNode.nodeType == 1 && oChildNode.nodeName == 'IFRAME')
				{
					iFrame = oChildNode;
					oChildNode = oChildNode.nextSibling;
					document.body.removeChild(iFrame);
				}
				else
				{
				oChildNode = oChildNode.nextSibling;
				}
			};
}

