
var STICKY = 1;

// Our layer
var over = null;

var o3_frame = self;
var o3_text = "";
var o3_cap = "";
var o3_width1=250;
var o3_width2=250;
var o3_height=-1;
var o3_x = 0;
var o3_y = 0;
var o3_allowmove = 0;
var o3_sticky = 0;
var o3_bgcolor="#AAAA77";
var o3_fgcolor="#333344";
var sent = 0;
var last_x;
var last_y;

// Decide browser version
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var ie5 = false;


// Special for frame support, over must be reset...
if ( (ns4) || (ie4) ) {
	o3_frame = self;
	if (ns4) over = o3_frame.document.sendmail
	if (ie4) over = o3_frame.sendmail.style
}

// Microsoft Stupidity Check(tm).
if (ie4) {
	if (navigator.userAgent.indexOf('MSIE 5')>0) {
		ie5 = true;
	}
}


// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) ) {
	document.onmousemove = mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
} else {
	overlib  = no_overlib;
	nd       = no_overlib;
	ver3fix  = true;
}


// Fake function for 3.0 users.
function no_overlib() {
	return true;
}


function overlib() {
	if (o3_sticky == 1 && sent == 0)
		return false;
	
	o3_text = arguments[0];
	for (i = 1; i < arguments.length; i++) {
		if (arguments[i] == STICKY) { i++; o3_cap = arguments[i]; o3_sticky = 1; }
	}

	var layerhtml;
	if (o3_sticky == 0) {
		// Plain
		layerhtml = ol_content_simple(o3_text);
	} else {
		layerhtml = ol_content_caption(o3_text, o3_cap, "Close");
	}
	layerWrite(layerhtml);

	o3_allowmove = 0;
	disp();

	if (o3_sticky == 0) {
		return true;
	} else {
		o3_allowmove = 0;
		return false;
	}
}

// Makes simple table without caption
function ol_content_simple(text) {
	txt = "<TABLE WIDTH="+o3_width1+" BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+o3_bgcolor+" HEIGHT="+o3_height+"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+o3_fgcolor+" HEIGHT="+o3_height+"><TR><TD VALIGN=TOP><FONT FACE=\"verdana,arial\" SIZE=1 COLOR=#AAAA77>"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
	set_background("");
	return txt;
}

// Makes table with caption and optional close link
function ol_content_caption(text, title, close) {
	form = "";
	if (sent == 0) {
		form = "<form action=Sendmail name=toto method=put target=emptyframe onSubmit=\"return messageSent ();\">";
//		form = "<form action=Sendmail name=toto method=put target=emptyframe>";
	}

	closing = "";
	if (close != "") {
		closing = "<TD ALIGN=RIGHT><A HREF=\"\" onMouseDown=\"return cClick();\"><B><FONT COLOR=\"#000000\" FACE=\"verdana,arial\" SIZE=1>"+close+"</FONT></B></A></TD>";
	}
	txt = "<TABLE WIDTH="+o3_width2+" BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+o3_bgcolor+" HEIGHT="+o3_height+"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><B><FONT COLOR=\"#000000\" FACE=\"verdana,arial\" SIZE=1>"+title+"</FONT></B></TD>"+closing+"</TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+o3_fgcolor+" HEIGHT="+o3_height+"><TR><TD VALIGN=TOP><FONT COLOR=\"#AAAA77\" FACE=\"verdana,arial\" SIZE=1>"+form+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
	set_background("");
	return txt;
}

function messageSent () {
	hideObject(over); 
	sent = 1; 
	return true;
}	

function set_background(pic) {
	if (ns4) {
		over.background.src = pic;
	} else if(ie4) {
		over.backgroundImage = "url("+pic+")";
	}
}


// Clears popups if appropriate
function nd() {
	if (o3_sticky == 0) {
		o3_allowmove = 0;
		hideObject(over);
	}
	
	return true;
}


// Displays the popup
function disp() {
    if ( (ns4) || (ie4) ) {
	if (o3_allowmove == 0) {
	    if (o3_sticky > 0)
		if (sent == 1) {
			moveTo (over, last_x-50, last_y-80);
		} else {
			moveTo (over, o3_x-50, o3_y-80);
			last_x = o3_x;
			last_y = o3_y;
		}
	    else
		moveTo (over, o3_x+15, o3_y-15);

	    showObject(over);

	    if (o3_sticky > 0 && sent == 1) {
		sent = 0;
	    }	

	    o3_allowmove = 1;
	}
    }
    return true;
}


// Moves the layer
function mouseMove(e) {
	if (sent == 1) {
		// first mouse move after send
		overlib ('<BR><b> Message sent</b><BR><BR>', STICKY, '');
	}

	if (ns4) {o3_x=e.pageX; o3_y=e.pageY;}
	if (ie4) {o3_x=event.x; o3_y=event.y;}
	if (ie5) {o3_x=event.x+o3_frame.document.body.scrollLeft; o3_y=event.y+o3_frame.document.body.scrollTop;}
	
	if (o3_allowmove) {
		moveTo (over, o3_x+15, o3_y-15);
	}
}

// The Close onMouseOver function for stickies
function cClick() {
	hideObject(over);
	o3_sticky = 0;
	return false;
}


////////////////////////////////////////////////////////////////////////////////////
// LAYER FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


// Writes to a layer
function layerWrite(txt) {
        if (ns4) {
                var lyr = o3_frame.document.sendmail.document

                lyr.write(txt)
                lyr.close()
        }
        else if (ie4) o3_frame.document.all["sendmail"].innerHTML = txt
}

// Make an object visible
function showObject(obj) {
        if (ns4) obj.visibility = "show"
        else if (ie4) obj.visibility = "visible"
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide"
        else if (ie4) obj.visibility = "hidden"
}

// Move a layer
function moveTo(obj,xL,yL) {
        obj.left = xL
        obj.top = yL
}



