//browser detection

var isNN=0,isIE=0,isN6=0,isIE8=0;
var strShow,strHide;
if (document.all) {isIE=1;strShow="visible";strHide="hidden";}//ie
else if (document.getElementById){isN6=1;strShow="";strHide="hidden";}//ns6
//Initialize variables used in displaySubMenu function
rightX = 0;
leftY = 0;
leftX = 0;
var lastMenu=null;
var movingMenu;

var isMac =(navigator.platform.indexOf("Mac") != - 1) ? 1  : 0;
var strPicName="";
var strCurPic="";


function showPic(thePic,theObject)//initiates rollover pic and menu
{	
	if(strCurPic != thePic)
	{
		if(strCurPic.length)
			doShow(strCurPic,strHide);	
		doShow(thePic,strShow);
		strCurPic = thePic;
	}
	if(theObject!=null)
	{
		doDrop(theObject);
		
	}
	
}
function doShow(strPic,strState)
{
		document.images[strPic].style.visibility = strState;
	
}
function killPic(thePic)
{	
	if(strCurPic != strPicName)
	{
		doShow(strCurPic,strHide)
		if(strPicName.length)
			doShow(strPicName,strShow);	
		strCurPic = strPicName;
	}
}
function setPic(picName)
{
	strCurPic = strPicName = picName;
	doShow(picName,strShow);
}
function getOK(strMsg)
{
	var bCan = confirm(strMsg);
	if(bCan==false)
	{	
		
			return false;
	}
}
var curMen = null;
var colHeight,galHeight,xoff,yoff,parentMen;
var bTrack = 0;
var nMenY = 180;
var bRoll = 1;
	function setSub(theMen,y2)
	{		
		if(curMen!=null)hdeMen(curMen);
	}
	function showMen(theMen,y2)
	{	
		if(isIE)
		{
		
			document.all[theMen].style.posTop = document.all[parentMen].offsetTop + y2;
			document.all[theMen].style.posLeft = document.all[parentMen].offsetLeft +65
			if(curMen!=null)document.all[curMen].style.visibility = "hidden";	
			document.all[theMen].style.visibility = "visible";
		}
		else if(isN6)
		{	
			var n6men;
			if(curMen!=null)
			{	
				n6men = document.getElementById(curMen);
				n6men.style.visibility = strHide;
			}
			n6men = document.getElementById(theMen);		
			n6men.style.visibility = strShow;
		}
		curMen = theMen;
	}
	function hdeMen(theMen)
	{
		if(theMen == parentMen)return;
		var MyMenu;
		if(isIE)
		{
		   MyMenu = document.all[theMen];
		    if(ieOut(window.event.clientX,window.event.clientY,MyMenu))
			    MyMenu.style.visibility = "hidden";
		}
		else 
		{
		   MyMenu = document.getElementById(theMen);  
		    if(OtherOut(x,y,MyMenu))
			    MyMenu.style.visibility = "hidden";
		}
		curMen = null;
	}
function OtherOut(myx,myy,theMen)
{	
	var subLeftX,subLeftY, subRightX;
	subLeftX  = theMen.offsetLeft;
	subRightX = subLeftX + theMen.offsetWidth;
	subLeftY  = theMen.offsetTop+theMen.offsetHeight + 4;
	if (myx+10 > subRightX || myx-1 < subLeftX) 
	    return true;
	else if (myy+5 > subLeftY) 
	    return true;
	else return false;
}	
function ieOut(myx,myy,theMen)
{	
	var subLeftX,subLeftY, subRightX;
	subLeftX  = theMen.style.posLeft;
	subRightX = subLeftX + theMen.offsetWidth;
	subLeftY  = theMen.style.posTop+theMen.offsetHeight + 4;
	if (myx > subRightX || myx < subLeftX) return true;
	else if (myy > subLeftY) return true;
	else return false;
}

function stopMove()
{
	hideAllex();
	if(bTrack)
	{
		nMenY = event.y;
		bTrack=0;
	}
}
function trackMouse(myMen)
{	
	movingMenu = (myMen)? myMen:parentMen
		
	if(bTrack)
	{	
		document.all[movingMenu].style.posTop=event.y-yoff;
		document.all[movingMenu].style.posLeft=event.x-xoff;
	}
	updateIt(event);
}
function moveMen(myMen)
{	
	
	bTrack=1;
	xoff = event.x-document.all[movingMenu].offsetLeft;
	yoff = event.y-document.all[movingMenu].offsetTop;
}
function posMen()
{	
	hideAllex();
	if(!parentMen)return;
	if(bRoll)
	{
		bRoll = 0;
		if(document.all[parentMen].style.posTop - (nMenY + document.body.scrollTop)>0)
			rollUp(); else 	rollDown();
	}
}
function rollUp()
{
	var nOffset;
	nOffset = document.all[parentMen].style.posTop-(document.body.scrollTop + nMenY);
	if(nOffset>100)
	{ 	
		document.all[parentMen].style.posTop -=20;
		setTimeout(rollUp,60);
	}
	else if(nOffset>20)
	{ 	
		document.all[parentMen].style.posTop -=5;
		setTimeout(rollUp,80);
	}
	else if(nOffset>0)
	{ 	
		document.all[parentMen].style.posTop -=2;
		setTimeout(rollUp,100);
	}
	else
		bRoll=1;
}
function rollDown()
{	
	var nOffset;
	nOffset = document.all[parentMen].style.posTop-(document.body.scrollTop + nMenY);
	
	if(nOffset<-100)
	{ 	
		document.all[parentMen].style.posTop +=20;
		setTimeout(rollDown,60);
	}
	else if(nOffset<-20)
	{ 	
		document.all[parentMen].style.posTop +=5;
		setTimeout(rollDown,80);
	}
	else if(nOffset<0)
	{ 	
		document.all[parentMen].style.posTop +=2;
		setTimeout(rollDown,100);
	}
	else
		bRoll=1;
}
function doRoll(theImage,theSrc)
{
	document.images[theImage].src = eval(theSrc+".src");
}
function valForm(theForm,nEnd)
{
	
	if(nEnd == -1)nEnd=theForm.length;
	var strMsg ="";
	for(var i=0;i<nEnd;i++)
		if(theForm.elements[i].value.length < 2)
		{
			strMsg= "Please enter something for "+ theForm.elements[i].name;
			break;
		}
	if(strMsg.length>0)
	{
		alert(strMsg);
		
			window.event.returnValue = false;
	}
	else
		return true; 
}



function doDrop(idMainMenu){
	var menu;
	var submenu;
	var mySource = "pics/"+doDrop.arguments[1]+".gif";
	if (isNN){	
		submenu = document[idMainMenu+"submenu"];
		
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.images[idMainMenu+"pic"].x;
		submenu.top  = document.images[idMainMenu+"pic"].y + 12;
		submenu.zIndex = 10;
		submenu.visibility = strShow;
		leftX  = submenu.left;
		rightX = leftX + submenu.clip.width;
		leftY  = submenu.top+submenu.clip.height;
	} else if (isN6) {
		menu = document.getElementById(idMainMenu);		
		submenu = document.getElementById(idMainMenu+"submenu");
		if (lastMenu != null && lastMenu != submenu) 
			hideAll();
		
		submenu.style.left = calculateSumOffset(menu, 'offsetLeft') + 'px';
		submenu.style.top  = (calculateSumOffset(menu,'offsetTop')+15)+'px';
		submenu.style.visibility = "visible";
		
		leftX  = calculateSumOffset(menu, 'offsetLeft');
		rightX =leftX + submenu.offsetWidth;
		leftY  = calculateSumOffset(menu,'offsetTop') + submenu.offsetHeight + 20;	
		//document.images["pnplogo"].src.style.visibility = "hidden";
		var myPic = document.getElementById("pnplogo");
		if(myPic != null)
		{
		    myPic.style.visibility = strHide;
		    myPic.src = mySource;
		    myPic.style.visibility = strShow;
		}
		//document.images["pnplogo"].src = mySource;
		//document.images["pnplogo"].src.style.visibility = "visible";
	} else if (isIE) { 
		menu = eval(idMainMenu);
		submenu = eval(idMainMenu+"submenu.style");
		if (lastMenu != null && lastMenu != submenu) hideAll();			
		submenu.left = calculateSumOffset(menu, "offsetLeft");
		submenu.top  = calculateSumOffset(menu,'offsetTop')+23;
		submenu.visibility = strShow;
		leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
		rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth;
		leftY  = document.all[idMainMenu+"submenu"].style.posTop+document.all[idMainMenu+"submenu"].offsetHeight + 4;
		if(document.images["pnplogo"])
		    document.images["pnplogo"].src = mySource;
		}
	
	
	lastMenuHead = doDrop.arguments[1];
	lastMenu = submenu;
	
	
}

function hideAll()
{
	if(isN6)
	{
		lastMenu.style.visibility = strHide;
		var myImage = document.images[lastMenuHead];
		if(myImage != null)
		{
		    myImage.style.visibility = strHide;
		    myImage.src = "menubarimages/"+lastMenuHead+".gif";
		    myImage.style.visibility = strShow;
		}
	}
	else
	{
		if(lastMenu != null)
		{
			lastMenu.visibility = strHide;
			if(document.images[lastMenuHead])
			    document.images[lastMenuHead].src = "menubarimages/"+lastMenuHead+".gif";
		}
	}
	//if(pnplogo)
	if(document.images["pnplogo"])
	    document.images["pnplogo"].src = "images2/Pnplogo3.gif"
	lastMenu = null;
	lastMenuHead=null;
}


function hideAllex()
{  
	if(lastMenu != null) 
	{
		killPic();
		hideAll();
	}
}
//used to calculate position of a submenu
function calculateSumOffset(idItem, offsetName){
	var totalOffset = 0;
	var item = eval('idItem');
	do{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}
var x;
var y;
//close menu on mouse out of menu containor
function updateIt(e)
{  
   if(lastMenu == null)
       return; 
       
	if (isN6){
	
		x = e.pageX;
		y = e.pageY;
		//x = e.clientY;
		//y = e.clientX;
		if (x > rightX || x < leftX){ hideAllex();}
		else if (y > leftY) hideAllex();
	}
	 else if (isIE){
		x = window.event.clientX;
		y = window.event.clientY;
		if (x > rightX || x < leftX) hideAllex();
		else if (y > leftY) hideAllex();
	}
	
		
}
function showIndex(theIndex)
{
	var myIndex;
	
	{
		
		if(isIE)myIndex = eval(theIndex+".style");
		else  myIndex = (document.getElementById(theIndex)).style;
		
		if(myIndex.visibility==strShow)
		{
			myIndex.visibility = strHide;
			setSource(ndxo,ndxu);
		}
		else
		{
			myIndex.visibility = strShow;
			setSource(hndxo,hndxu);
		}
	}
	
}
function showOld()
{
	oldPorts.style.display = "inline";
	more.style.display = "none";
}

//set page to hide menus on a mouse click or on mouseout of menu containor
if (isN6)
{
    document.addEventListener('mousemove', updateIt, true);
    document.addEventListener('click', hideAllex, true);
	//document.body.onclick=hideAllex;
	//document.onmousemove=updateIt;
}


else{
if(document.body)
{
document.body.onmousemove = trackMouse;
document.body.onmouseup = stopMove;
}
//document.body.onscroll = posMen;
}
function showComments(CommentID,myButton)
{
	var myCommentsStyle = (isIE)? document.all[CommentID].style : (document.getElementById(CommentID)).style;
	flipComments(myCommentsStyle,myButton);

}
function flipComments(myCommentsStyle,myButton)
{
	if(myCommentsStyle.display == "inline")
		{	
			myCommentsStyle.display = "none"
			myButton.value = "Show Comments";
		}
		else
		{
			myCommentsStyle.display = "inline"
			myButton.value = "Hide Comments";
		}
}

function menucolor(theRow,myRowFlag)
{
	if(myRowFlag)
	{
		theRow.style.backgroundColor="#FFE4B5";
		theRow.cells[0].style.backgroundColor="#D2B48C";
	}
	else
	{
		theRow.style.backgroundColor="#F5F5DC";
		theRow.cells[0].style.backgroundColor="#F5F5DC";
	}
}
