// --------------------------------------
// Javascript functions for new website
// --------------------------------------

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();

}


// Disable right click on mouse
function disableRightClick(e)
{
	var message = "Right click disabled";

	if(!document.rightClickDisabled) // initialize
	{
		if(document.layers) 
		{
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown = disableRightClick;
		}
		else document.oncontextmenu = disableRightClick;

		return document.rightClickDisabled = true;
	}

	if(document.layers || (document.getElementById && !document.all))
	{
		if (e.which==2 || e.which==3)
		{
			alert(message);
			return false;
		}
	}
	else
	{
		alert(message);
		return false;
	}

}


// Toggle items expanded stage
//function Toggle(item) 
//{
//   obj=document.getElementById(item);
//   visible=(obj.style.display!="none")
//
//   if (visible) {
//     obj.style.display="none";
//   } else {
//      obj.style.display="block";
//   }
//}



function TogglePreviousItem(item) 
{
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   
   if (visible) {
     obj.style.display="none";
   } else {
      obj.style.display="block";
   }
}



// Toggle items expanded stage
var previousItem=null;
var expand=false;
var topic;

function Toggle(item) 
{


	if(previousItem!=null) 
	{
		if(previousItem!=item) 
		{
			//MsgBox("Previous Item != item");
			TogglePreviousItem(previousItem);
		}
		
	}
   
	if(previousItem!=item) 
	{
		previousItem=item;
	} 
	else 
	{
		//MsgBox("Previous item must be NULL");
        previousItem = null;
	}
   
	obj=document.getElementById(item);
	visible=(obj.style.display!="none")
   
	if (visible) 
	{
		//MsgBox("display is set to NONE");
		obj.style.display="none";
	}
	else 
	{
		//MsgBox("display is set to BLOCK");
		obj.style.display="block";
		setCookie("openMenu",item,1);
		//expand = true;
	}
	//topic=item;
	//MsgBox(topic);

}




// Expand items
//function Expand() 
//{
//   divs=document.getElementsByTagName("DIV");
//   for (i=0; i < divs.length; i++) {
//     divs[i].style.display="block";
//     key=document.getElementById("x" + divs[i].id);
//     key.innerHTML="<img src='./icons/document_plain.ico' width='16' height='16' hspace='0' vspace='0' border='0'>";
//   }
//}


// Collapse items
//function Collapse() 
//{
//   divs=document.getElementsByTagName("DIV");
//   for (i=0; i < divs.length; i++) {
//     divs[i].style.display="none";
//     key=document.getElementById("x" + divs[i].id);
//     key.innerHTML="<img src='./icons/document_plain.ico' width='16' height='16' hspace='0' vspace='0' border='0'>";
//   }
//}


// Get the browser type
function getBrowserType()
{
	if(navigator.appName.indexOf("Microsoft") == -1)
	{
  		document.writeln("<LINK rel='stylesheet' type='text/css' href='netscape.css'>");
	}
	else
	{
  		document.writeln("<LINK rel='stylesheet' type='text/css' href='ie-layout.css'>");
  		document.writeln("<LINK rel='stylesheet' type='text/css' href='ie-presentation.css'>");
	}
}


//Expand the last expanded menu
function ExpandLastSelectedMenuItem()
{
    var cookieItem = getCookie("openMenu");
    if(cookieItem == "" || cookieItem == null)
    {
        cookieItem = "Home";
    }
    	obj=document.getElementById(cookieItem);
		obj.style.display="block";
		previousItem=cookieItem;
}

// =====================================
// Cookie functions
// =====================================

// getCookie Function
function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{ 
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length + 1 
			c_end = document.cookie.indexOf(";",c_start)
			if (c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
}

// setCookie function
function setCookie(c_name,value,expiredays)
{
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value)+
	((expiredays==null) ? "" : "; expires = " + exdate.toGMTString())
}

// checkCookie function
function checkCookie()
{
	username = getCookie('username')
	if (username != null && username != "")
	{
		//alert('Welcome again '+username+'!')
	} else {
		username = prompt('Please enter your name:',"")
		if (username != null && username != "")
		{
			setCookie('username',username,365)
		}
	}
}



// disable the right click button
disableRightClick();

// Get browser type user is running
getBrowserType();


//function messageWindow(title, msg)
//{
//  	var width="300", height="125";
//  	var left = (screen.width/2) - width/2;
//  	var top = (screen.height/2) - height/2;
//  	var styleStr = 'toolbar=no, 
//  		location=no, 
//		directories=no,
//		status=no,
//		menubar=no,
//		scrollbar=no,
//		resizable=no,
// 		copyhistory=yes,
//		width='+width+',
//		height='+height+',
//		left='+left+',
//		top='+top+',
//		screenX='+left+',
//		screenY='+top;

//	var msgWindow = window.open("","msgWindow", styleStr);
//  	var head = '<head><title>'+title+'</title></head>';
//  	var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';
//  	msgWindow.document.write(head + body);
//}

function MsgBox(textString) {
	alert (textString);
	}
	


