
//öppnar ett centrerat popup-fönster ---------------------------------------------------------------------

	var popUpWin=0;
	function popup(URL,winName,width,height)
	{
	  if(popUpWin)
	  {
		if(!popUpWin.closed) popUpWin.close();
	  }
	
		if (parseInt(navigator.appVersion) >= 3){
			if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)<5){
				var tools = new Packages.java.awt.Toolkit.getDefaultToolkit();
				screen=tools.getScreenSize();
			}
			x = screen.width;
			y = screen.height;
		}
		popUpWin = open(URL,winName,'top=' + parseInt(y/2-height/2-16) + ',left=' + parseInt(x/2-width/2-5) + 
						',width=' + width + ',height=' + height + ',scrollbars=yes,resizable=yes');
		popUpWin.focus();
	}
	
	
	//funktion för att flytta poster mellan två listmenyer
	function moveSelectedOptions(from,to) {
		// Unselect matching options, if required
		if (arguments.length>3) {
			var regex = arguments[3];
			if (regex != "") {
				unSelectMatchingOptions(from,regex);
				}
			}
		// Move them over
		for (var i=0; i<from.options.length; i++) {
			var o = from.options[i];
			if (o.selected) {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		// Delete them from original
		for (var i=(from.options.length-1); i>=0; i--) {
			var o = from.options[i];
			if (o.selected) {
				from.options[i] = null;
				}
			}
		if ((arguments.length<3) || (arguments[2]==true)) {
			sortSelect(from);
			sortSelect(to);
			}
		from.selectedIndex = -1;
		to.selectedIndex = -1;
		}
	
	function sortSelect(obj) {
		var o = new Array();
		if (obj.options==null) { return; }
		for (var i=0; i<obj.options.length; i++) {
			o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
			}
		if (o.length==0) { return; }
		o = o.sort( 
			function(a,b) { 
				if ((a.text+"") < (b.text+"")) { return -1; }
				if ((a.text+"") > (b.text+"")) { return 1; }
				return 0;
				} 
			);
	
		for (var i=0; i<o.length; i++) {
			obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
			}
		}
	
	function sync(list,field){
		field.value="";
		for(var n=0;n<list.length;n++){
			field.value+=(field.value)?", "+list[n].value:list[n].value;
		}
	}
	
	function selectAllOptions(obj) {
		for (var i=0; i<obj.options.length; i++) {
			obj.options[i].selected = true;
			}
	}
	
	
	//kollar om man valt en fil vid filuppladdning
	function isFile(filename)
	{
		
		//ny fil
		if(!document.getElementById('oldFilename'))
		{	
			if (!filename.length)
			{
				alert("Du har inte valt någon fil!");
				return false;
			}
			
			//if(!filename.match(/(\.gif|\.jpg|\.jpeg|\.jpe|\.png|\.psd|\.doc|\.pdf|\.txt|\.ppt|\.xls)$/i))
			//if(!filename.match(/(\.jpg)$/i))
			//{
			//	alert("Du har ej valt en korrekt fil!");
			//	return false;
			//}
			
			return true;
		}
		
		//uppdaterar fil
		
		
		else
		{
			
			if (filename.length)
			{
				
				//if(!filename.match(/(\.)$/i))
				//{
				//	alert("Du har ej valt en korrekt fil!");
				//	return false;
				//}
				/*
				if(!filename.match(/(\.gif|\.jpg|\.jpeg|\.jpe|\.png|\.psd|\.doc|\.pdf|\.txt|\.ppt|\.xls)$/i))
				{
					alert("Fel filtyp");
					return false;
				}
				*/
				
				return true;
				
			}
			return true;
			
		}
		
	}

	function PostForm(frm)
	{
		if (isFile(document.getElementById("File").value)) 
		{
			//th.form.action = a;
			frm.form.submit();
		}
	}
	
	
	function transfer(action)
	{
		var html = editor.editGetHtmlBody(); 

		document.forms[0].Notes.value = html; 
		document.forms[0].target='';
		document.forms[0].action = action;
 
		document.forms[0].submit();
	}
	
	
	function editBeforeReadOne() {
		document.getElementById("editor_html").value = document.getElementById("editor").contentWindow.editGetHtmlBodyRel();
	}
	
	function editBeforeReadTwo() {
		document.getElementById("editor_preamble_html").value = document.getElementById("editor_preamble").contentWindow.editGetHtmlBodyRel();
		document.getElementById("editor_html").value = document.getElementById("editor").contentWindow.editGetHtmlBodyRel();
	}

	function editBeforeReadOnePopup() {
		window.opener.document.getElementById("editor_html").value = window.opener.document.getElementById("editor").contentWindow.editGetHtmlBodyRel();
	}
	
	function editBeforeReadTwoPopup() {
		window.opener.document.getElementById("editor_preamble_html").value = window.opener.document.getElementById("editor_preamble").contentWindow.editGetHtmlBodyRel();
		window.opener.document.getElementById("editor_html").value = window.opener.document.getElementById("editor").contentWindow.editGetHtmlBodyRel();
	}
	
	
	
	function previewForm(o, action)
	{
		o.form.target = '_blank';
		o.form.action = action;
		o.form.submit();
	}
	
	