

/*
 *	Cookie handler stuff.
 *
 *	hmmm Cookie,....C is for Cookie, Cookie is for me.
 *
 */
 
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


function getCookieVal(offset) 
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
	endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
	
function getCookie(name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) 
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
				return getCookieVal (j);    
				i = document.cookie.indexOf(" ", i) + 1;    
				if (i == 0) break;   
			}  
			return null;
	}
	
function setCookie (name, value) 
{  
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}
	
function deleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	// This cookie is history  
	var cval = detCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}




function noteswindow (name, imagename) 
{
	//the actual HTML object name.
	this.mName = name;
	this.TitleBarHgt = 50;
	
	this.mCloseXPos = 269;
	this.mCloseYPos = 7;
	this.mCloseWid = 17;
	this.mCloseHgt = 17;
	
	this.mMinXPos = 269;
	this.mMinYPos = 26;
	this.mMinWid = 17;
	this.mMinHgt = 17;
	
	this.mTitleXPos = 12;
	this.mTitleYPos = 7;
	this.mTitleWid = 253;
	this.mTitleHgt = 37;
	
	this.mTitleDrag = false;
	this.mDoingMin = false;
	this.mDoingMax = false;
	
	
	this.mXPos = 690;
	this.mYPos = 100;
	this.mWid = 300;
	this.mHgt = 400;
	this.mBgColour="#F0F8FF";
	
	this.mLastMouseX = 0;
	this.mLastMouseY = 0;
	this.mIsMinimize = false;
	this.mOldHgt = this.mHgt;
	this.mText ='adam smells like old cheese';
	
	this.mMinMaxChange = Math.round((this.mHgt)/5);

    // initialize the member function references
    // for the class prototype
    if (typeof(_person_prototype_called) == 'undefined')
    {
		_person_prototype_called = true;
		this.setOpacity = _setOpacity ;
		this.move = _move;
		this.show = _show;
		this.OnMouseMove = _OnMouseMove;
		this.OnMouseDown = _OnMouseDown;
		this.OnMouseUp = _OnMouseUp;
		this.OnMouseLeave = _OnMouseLeave;
		this.OnMouseEnter = _OnMouseEnter;
		this.OnClick = _OnClick;
		this.setSize = _setSize;
		this.setBgImage = _setBgImage;
		this.setText = _setText;
		this.minimize = _minimize;
		this.DoMinimize = _DoMinimize;
		this.DoMaximize = _DoMaximize;
		this.showText = _showText;
		this.setHeight = _setHeight;
		
		document.write('<table width="100%" height="100%" border="0" cellpadding="10" cellspacing="0" bordercolor="#000000" style="z-index:102;position:absolute;top:105px;left:5px;width:232px;height:143px;z-index:3;filter:alpha(opacity=100);-moz-opacity:1;z-index:100;"'); 
		document.write('id="'+name+'" background="'+imagename+'" onSelectStart="return false;"');
		document.write('onMouseMove="'+name+'.OnMouseMove()" onMouseDown="'+name+'.OnMouseDown()" OnMouseUp="'+name+'.OnMouseUp()" OnMouseOut="'+name+'.OnMouseLeave()" onMouseOver="'+name+'.OnMouseEnter()" onclick="'+name+'.OnClick()">');
		
		document.write('<tr id="title" height="'+this.TitleBarHgt+'">');
		document.write('<td>');
		document.write('</td>');
		document.write('</tr>');
		
		document.write('<tr>'); 
		document.write('<td>');
		document.write('<div id="text" class="notesscrollbar">');
		document.write('</div>');
		document.write('</td>');
		document.write('</tr>');
		document.write('</table>');

		if (document.all)
		{
			this.Window = document.all(this.mName);
		} else if (!document.all && document.getElementById) {		
			this.Window = document.getElementById(this.mName);
		}
		
		this.setOpacity(92);
		this.setText(this.mText);
		
		var show = getCookie('show');
		if(show == null) {
			setCookie('show',"true");
			show = "true";
		}
		
		if(show == "true")
			this.show(true);
		else
			this.show(false);
		
		var x = getCookie('XPos');
		if(x == null) {
			setCookie('XPos',this.mXPos);
		}
		else
			this.mXPos = parseInt(x);
		
		var y = getCookie('YPos');
		if(y == null) {
			setCookie('YPos',this.mYPos);
		}
		else
			this.mYPos = parseInt(y);
		
		this.setSize(this.mXPos, this.mYPos, this.mWid, this.mHgt);
		//this.show(true);
	}

	function _setOpacity(objectOpacity) 
	{
		if (document.all){
			document.all(this.mName).filters.alpha.opacity = objectOpacity
		} else if (!document.all && document.getElementById) {		
			document.getElementById(this.mName).style.MozOpacity = objectOpacity/100
		}
	}
	
	function _move(x, y)
	{
		if(x < 0)
			x = 0;
		if(y < 0)
			y = 0;
		
		this.Window.style.left = x;
		this.Window.style.top = y;
		this.mXPos = x;
		this.mYPos = y;
		
		//setCookie('XPos',this.mXPos);
		//setCookie('YPos',this.mYPos);
	}
	
	function _setSize(x, y, wid, hgt)
	{
		this.move(x,y);
		
		this.Window.style.width = wid;
		this.Window.style.height = hgt;
		this.mWid = wid;
		this.mHgt = hgt;
	}
	
	function _setHeight(hgt)
	{
		this.Window.style.height = hgt;
		this.mHgt = hgt;
	}
	
	function _show(val)
	{
		if(val)
		{
			if(this.mIsMinimize == true)
			{
				this.DoMaximize();
				this.mIsMinimize = false;
			}
			this.Window.style.visibility='visible';
			setCookie('show',"true");
		}
		else
		{
			this.Window.style.visibility='hidden'
			setCookie('show',"false");
		}
	}
	
	function _minimize(val)
	{
		if(this.mIsMinimize == false)
		{
			this.DoMinimize();
			this.mIsMinimize = true;
		}
		else
		{
			this.DoMaximize();
			this.mIsMinimize = false;
		}
	}
	
	function _setBgImage(imge)
	{
		this.Window.background = imge;
	}
	
	function _setText(text)
	{
		document.getElementById('text').innerHTML = text
		this.mText = text
	}
	
	function _showText(val)
	{
		if(val && this.mIsMinimize == false)
		{
			document.getElementById('text').innerHTML = this.mText;
			document.getElementById('text').style.width = '100%';
			document.getElementById('text').style.height = '97%';
			document.getElementById('title').style.height = this.TitleBarHgt;
			document.getElementById('text').style.overflow="auto";
		}
		else
		{
			document.getElementById('text').innerHTML = ''
			document.getElementById('text').style.width = '0%';
			document.getElementById('text').style.height = '0%';
			document.getElementById('title').style.height = 0;
			document.getElementById('text').style.overflow='';
		}
	}
	
	
	function _OnMouseMove(evnt)
	{
		if(this.mTitleDrag)
		{
			if(document.getElementById("text").innerHTML != "")
				document.getElementById("text").innerHTML = ""
			//then we are dragging the window.
			var dx = this.mXPos + event.x - this.mLastMouseX;
			var dy = this.mYPos + event.y - this.mLastMouseY;
			this.move(dx,dy);
			//this.setSize(dx, dy, this.mWid, this.mHgt);
		}
		
		var x = event.x - this.mXPos;
		var y = event.y - this.mYPos;
		
		if((this.mCloseXPos < x) && (this.mCloseYPos < y)&&
			(this.mCloseXPos + this.mCloseWid > x) && (this.mCloseYPos + this.mCloseHgt > y))
		{
			this.Window.style.cursor = "hand";
		}
		else
		if((this.mMinXPos < x) && (this.mMinYPos < y)&&
			(this.mMinXPos + this.mMinWid > x) && (this.mMinYPos + this.mMinHgt > y))
		{
			this.Window.style.cursor = "hand";
		}
		else
		if((this.mTitleXPos < x) && (this.mTitleYPos < y)&&
			(this.mTitleXPos + this.mTitleWid > x) && (this.mTitleYPos + this.mTitleHgt > y))
		{
			this.Window.style.cursor = "hand";
		}
		else
			this.Window.style.cursor = "auto";
		
		this.mLastMouseX = event.x;
		this.mLastMouseY = event.y;
	}
	
	function _OnMouseDown(evnt)
	{
		var x = event.x - this.mXPos;
		var y = event.y - this.mYPos;
		
		if((this.mTitleXPos < x) && (this.mTitleYPos < y)&&
			(this.mTitleXPos + this.mTitleWid > x) && (this.mTitleYPos + this.mTitleHgt > y))
		{
			this.mTitleDrag = true;
		}
	}
	
	function _OnMouseUp(evnt)
	{
		if(this.mTitleDrag)
			this.showText(true);
		this.mTitleDrag = false;
		setCookie('XPos',this.mXPos);
		setCookie('YPos',this.mYPos);
	}
	
	function _OnMouseLeave(evnt)
	{
		if(this.mTitleDrag)
			this.showText(true);
		this.mTitleDrag = false;
		setCookie('XPos',this.mXPos);
		setCookie('YPos',this.mYPos);
	}
	
	function _OnMouseEnter(evnt)
	{
		if(this.mTitleDrag)
			this.showText(true);
		this.mTitleDrag = false;
		setCookie('XPos',this.mXPos);
		setCookie('YPos',this.mYPos);
	}
	
	function _OnClick(evnt)
	{
		var x = event.x - this.mXPos;
		var y = event.y - this.mYPos;
		if((this.mCloseXPos < x) && (this.mCloseYPos < y)&&
			(this.mCloseXPos + this.mCloseWid > x) && (this.mCloseYPos + this.mCloseHgt > y))
		{
			this.show(false);
			return;
		}
		
		if((this.mMinXPos < x) && (this.mMinYPos < y)&&
			(this.mMinXPos + this.mMinWid > x) && (this.mMinYPos + this.mMinHgt > y))
		{
			this.minimize(true);
			return;
		}
	}
	
	function _DoMinimize()
	{
		var resTest = false;
		var d1h = this.mHgt - this.mMinMaxChange;
	
		if (d1h > this.TitleBarHgt) 
		{
			this.showText(false);
			this.setHeight(d1h);
			resTest = true
		}
		else
		{
			this.showText(false);
			this.setHeight(this.TitleBarHgt);
		}
		
		if (resTest) {
			var name = this.mName+".DoMinimize()"
			setTimeout(name,1)
		}
	}
	
	function _DoMaximize()
	{
		var resTest = false;
		var d1h = this.mHgt + this.mMinMaxChange;
	
		if (d1h < this.mOldHgt) 
		{
			this.setHeight(d1h);
			resTest = true
		}
		else
		{
			this.setHeight(this.mOldHgt);
			this.showText(true);
		}
		
		if (resTest) {
			var name = this.mName+".DoMaximize()"
			setTimeout(name,1)
		}
	}
}
