# Surgeweb plain HTML interface
# Main javascript file

var sw={};

function do_init()
{
	browser_id();
	do_resize()
	if(window.send_type){
		x_ac_pageload();
	}
}


function compose_init(as_text)
{
	do_init();
	if (send_type=='redirect'){
		dge('msg_body').innerHTML=the_message;
	} else if (as_text){
		dge('msg_body').value=the_message;
	} else {
		var tb=dge('etbar')
		tb.eframe=dge('eframe');
		tb.field_switch=dge('editor_switch_button');
		sw.ew = init_editor('eframe');
		fill_out_msg();
	}
}




function do_show_cc_bcc(show)
{
	msg_from_editor();	
	var f=document.main;	
	f.show_cc_bcc.value=show;	
	set_compose_refresh();	
	simple_submit('show','edit.htm');
}


function qqq()
{
	alert('fee');
}

function msg_from_editor()
{
	var txt;
	var ew=sw.ew;
	if(ew){
		txt = sw.ew.document.body.innerHTML;
	}else{
		txt = dge('msg_body').value;
	}

	document.main.msg_body.value = txt;	
}


function fill_out_msg()
{
	xdoc=sw.ew.document;

	xdoc.open();
	xdoc.write('<html><head>');
	xdoc.write('<style>');
	xdoc.write(' .sw_message P{margin:0px;padding:0px;}');
	xdoc.write(' .sw_message {FONT-SIZE: ||message_font_size||pt;FONT-FAMILY:Arial,Helvetica,sans-serif;background:white;}');
	xdoc.write('</style>');
	xdoc.write('<body class="sw_message">');

	xdoc.write(the_message);

	xdoc.write('</body></html>')
	xdoc.close();
}	

function set_compose_refresh(){
	document.main.compose_refresh.value='true';	
}

function do_allow_images(type)
{
	var f=document.main;	
	f.allow_images.value=type;	
	simple_submit('show','msg.htm');
}

function x_ac_pageload(){
	var x;
	x=dge('to'); 
	if (x) ac_register_ctl(x, "default source");	
	x=dge('cc'); 
	if (x) ac_register_ctl(x, "default source");	
	x=dge('bcc'); 
	if (x) ac_register_ctl(x, "default source");	
	autocomplete.selected=0;	
}


function attach_done()
{
#	document.main.msg_body.value=the_message;
	set_compose_refresh();	
	simple_submit('show','edit.htm');
}

function dbg(){}


function px(value){
	if (value<=0) return "1px";
	return value+"px";
}


function switch_to(type){
	document.main.interface_ex.value=type;
	simple_submit('show','sw.htm');
}

function check_folder_name(name)
{
	if (name.indexOf('/')==-1 && name.indexOf('\\')==-1) return true;
	alert('$$st_fldmng_fldname_bad$$');
	return false;
}


function do_folder_create()
{

	var new_name;
	var s=document.main.folder_new_under.value;
	var new_name=(s.length>0)?s+'/':'';
	if(!check_folder_name(document.main.folder_new_name.value)) return;
	new_name+=document.main.folder_new_name.value;
	document.main.new_name.value=new_name;
	simple_submit('folder_create,show','folders.htm');
}

function delete_folder(name)
{
	if (!confirm($('$$st_fldmng_deletefld$$',name))) return;
	document.main.delete_name.value=name;
	simple_submit('folder_delete,show','folders.htm');
}

function rename_folder(name,short_name)
{
	val=prompt($('$$st_fldmng_renameto$$',short_name),'');	
	if(!val || val.length==0) return;
	document.main.folder_rename_src.value=name;
	document.main.folder_rename_dst.value=val;
	simple_submit('folder_rename,show','folders.htm');
}

function move_folder(name,short_name)
{
	val=prompt($('$$st_fldmng_moveto$$',short_name),'$$st_ftree_more_fld$$');	
	if(!val || val.length==0) return;
	document.main.folder_move_src.value=name;
	document.main.folder_move_dst.value=val;
	simple_submit('folder_move,show','folders.htm');
}
document.onclick=function(e){
	if (!e) e = window.event
	if (!e) return;
	
	if (global_active_menu)
		menu_hide2(global_active_menu);
}
var enc1=/&/g, enc2=/</g, enc3=/>/g;
function xencode(a){
    return a.replace(enc1,"&amp;").replace(enc2,"&lt;").replace(enc3,"&gt;")
}
function xdecode(a){
    return a.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">");
}

var ignore_folderFF=false;
function FF(e)
{
#	try and fix better sometime...
	if(ignore_folderFF) return;
	var t=target(e);
	var el=ancestor_by_tag(t,'li');
	dge('msg_id').value='';
	FolderShow(el.getAttribute('fld_id'),el.getAttribute('fld_type'));	
}

function hcheck_trigger()
{
	
}