function getCookie(name) 
{
    var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
		return null;
	}
	if (start == -1) {
	    return null;
	}
	var end = document.cookie.indexOf(";", len);
	if (end == -1) {
	    end = document.cookie.length;
	}
	return decodeURI(document.cookie.substring(len, end));
}
	
function setCookie(name, value) 
{
	var expiry = new Date();
        expiry.setTime(expiry.getTime() + 24 * 60 * 60 * 1000 * 10000);
        document.cookie = name + '=' + encodeURI(value) + '; path=/; expires=' + expiry.toGMTString();
	/*if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") + //expires.toGMTString()
		((path)    ? ";path=" + path : "") +
		((domain)  ? ";domain=" + domain : "") +
		((secure)  ? ";secure" : "");*/
}

function deleteCookie(name) 
{
	if (getCookie(name)) {
	    document.cookie = name + '=;path=/; expires=expires=Thu, 01-Jan-1970 00:00:01 GMT';	    
	}
}

function MenuOver(obj, img)
{   
    var icon = document.getElementById( 'icon_' + img );
    var path = new String();
    
    obj.style.backgroundColor = '#EEF0FF';
    obj.style.borderWidth     = '1px';
    obj.style.borderColor     = '#A3BBFF';
    obj.style.borderStyle     = 'solid';
    
    if ( icon ) {
        path = icon.src;
        path = path.replace( 'menu_icon.gif', 'menu_icon_h.gif' );
        
        icon.src = path;
    }
}

function MenuOut(obj, img)
{
    var icon = document.getElementById( 'icon_' + img );
    var path = new String();
    
    obj.style.backgroundColor = '#FFFFFF';
    obj.style.borderWidth     = '1px';
    obj.style.borderColor     = '#FFFFFF';
    obj.style.borderStyle     = 'solid';
    
    if ( icon ) {
        path = icon.src;
        path = path.replace( 'menu_icon_h.gif', 'menu_icon.gif' );
        
        icon.src = path;
    }
}

function ShowIcon( icon )
{
    var icon = document.getElementById( icon );
    var path = new String();
    
    if ( icon ) {
        path = icon.src;
        path = path.replace( '.gif', '_h.gif' );
        
        icon.src = path;
    }
}

function HideIcon( icon )
{
    var icon = document.getElementById( icon );
    var path = new String();
    
    if ( icon ) {
        path = icon.src;
        path = path.replace( '_h.gif', '.gif' );
        
        icon.src = path;
    }
}

function CreateMessage() 
{
	message = document.createElement('DIV');
	message.setAttribute('id', 'message');

	messageHeader = document.createElement('DIV');
	messageHeader.setAttribute('id', 'messageHeader');
	messageHeader.setAttribute('class', 'direct');

	messageBody   = document.createElement('DIV');
	messageBody.setAttribute('id', 'messageBody');

	messageFooter = document.createElement('DIV');
	messageFooter.setAttribute('id', 'messageFooter');

	messageBody.innerText = 'message';

	message.appendChild(messageHeader);
	message.appendChild(messageBody);
	message.appendChild(messageFooter);

	message.onmouseover   = function(e) { this.style.filter = "Alpha(Opacity='70')"; this.style.cursor = 'pointer'; this.style.MozOpacity = '0.70';}
	message.onmouseout    = function(e) { this.style.filter = "Alpha(Opacity='70')";  this.style.cursor = 'auto'; this.style.MozOpacity = '0.70'; }
	message.onselectstart = function(e) { return false; }
	message.onclick       = function(e) { this.style.display = 'none'; }

	document.body.appendChild(message);

	window.onresize = function(e) { document.getElementById('message').style.display = 'none'; }
}

function ShowMessage(element, mssg)
{
	message = document.getElementById('message');

	document.getElementById('messageBody').innerHTML = mssg;
	message.style.display = 'block';
	message.style.textAlign = 'justify';
	var xleft = 0;
	var xtop = 0;
	obj = element;
	do {
	    xleft += obj.offsetLeft;
		xtop  += obj.offsetTop;
	} while (obj = obj.offsetParent);
	
	xwidth  = element.offsetWidth  ? element.offsetWidth  : element.style.pixelWidth;
	xheight = element.offsetHeight ? element.offsetHeight : element.style.pixelHeight;
	
	bwidth =  message.offsetWidth  ? message.offsetWidth  : message.style.pixelWidth;
	
	win = window;
	
	xbody  = document.compatMode=='CSS1Compat' ? win.document.documentElement : win.document.body;
	dwidth = xbody.clientWidth  ? xbody.clientWidth   : win.innerWidth;
	bwidth = message.offsetWidth ? message.offsetWidth  : message.style.pixelWidth;
	
	flip = !(xwidth - 10 + xleft + bwidth < dwidth);
	
	message.style.top  = xheight - 10 + xtop + 'px';
	message.style.left = (xleft + xwidth - (flip ? bwidth : 0)  - 25) + 'px';
	
	document.getElementById('messageHeader').className = flip ? 'messageHeaderFlip' : 'messageHeaderDirect';
	
	element.focus();
	return false;
}

function HideMessage() 
{
    message = document.getElementById('message');	
	message.style.display = 'none';
}
