//
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan 010329
// see
// http://www.webreference.com/ for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
// please send any improvements to aking@internet.com and we'll
// roll the best ones in
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when Nav5 and IE5 (or later) are released, so
// in conditional code forks, use is_nav4up ("Nav4 or greater")
// and is_ie4up ("IE4 or greater") instead of is_nav4 or is_ie4
// to check version in code which you want to work on future
// versions.
//

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***

    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string

    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
       is_major = parseInt(is_minor);
    }

    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    var nav6Pos = agt.indexOf('netscape6');
    if (nav6Pos !=-1) {
       is_minor = parseFloat(agt.substring(nav6Pos+10))
       is_major = parseInt(is_minor)
    }

    var is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
    var is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
    //var is_nav2 = (is_nav && (is_major == 2));
    //var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

/*	var is_nav6 = (is_nav && (agt.indexOf('netscape6') != -1)); // new 001120 - abk
	var is_nav6up = (is_nav && is_getElementById);              // new 001121 - abk
*/
	var is_nav6   = (is_nav && is_major==6);    // new 010118 mhp
	var is_nav6up = (is_nav && is_minor >= 6) // new 010118 mhp

    var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
    var is_nav5up = (is_nav && is_minor >= 5);

    var is_ie   = (iePos!=-1);
    //var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);


    var is_mac    = (agt.indexOf("mac")!=-1);
    
    var is_all = (document.all) ? "true":"false";
    
    var is_java = (navigator.javaEnabled());


//******************************
//**  Scripts from dynamicpos **
//******************************
function blockHassles(evt)
{
	
	var shiftPressed = false;
	var altPressed = false;
	var ctrlPressed = false;
	var metaPressed = false;
	var rhButtonPressed = false;
	if (is_ie4up)
	{
		if (event.button==2)
		{
			rhButtonPressed = true;
		}
		//shiftPressed = event.shiftKey;
		altPressed = event.altKey;
		ctrlPressed = event.ctrlKey;
		metaPressed = ((event.keyCode >=112) && (event.keyCode<=123) && (event.type=="keydown"))

	}
	else if (is_nav4up)
	{
		if (evt.which==3)
		{
			rhButtonPressed = true;
		}
		if (is_nav5up)
		{
			//shiftPressed = evt.shiftKey;
			altPressed = evt.altKey;
			ctrlPressed = evt.ctrlKey;
			metaPressed = ((evt.which >=112) && (evt.which<=123) && (evt.type=="keydown"))
		}
		else
		{
			//shiftPressed = evt.modifiers & Event.SHIFT_MASK;
			altPressed = evt.modifiers & Event.ALT_MASK;
			ctrlPressed = evt.modifiers & Event.CONTROL_MASK;
			metaPressed = evt.modifiers & Event.META_MASK;
		}
	}
	if ((shiftPressed) || (altPressed) || (ctrlPressed) || (metaPressed) || (rhButtonPressed))
	{
		window.alert("Feature disabled");
		if (is_nav5up)
		{
		//need to focus back on field
			var theForm = document.getparentElement(evt.target.name);
			window.alert(theForm);
		}
		return false;
	}
	else
	{


		return true;
	}
}

function winHeight()
{
	if (is_ie4up)
		{
			return(document.body.clientHeight);
		}
	else if (is_nav4up)
		{
			return(window.innerHeight);
		}
	else return 600;

}

function winWidth()
{
	if (is_ie4up)
	{

		return(document.body.clientWidth);
	}
	else if (is_nav4up)
	{
		return(window.innerWidth);
	}
	else return 800;
}

function setWinSize()
{
	if (winWidth() > 800)
	{
		if (is_ie4up)
		{
			top.resizeTo(1000,720);
		}
		else if (is_nav4up)
		{
			window.innerWidth = 1000;
			window.innerHeight = 720;
		}
	}
}


/* Updated 4/4/2001 to ensure all browsers prompt for printing */

function printPage()
{
  if ((is_nav4up) || (is_ie5up)) // NS4, IE5
  {
    window.print();
  }  
  else // other browsers
  {
    alert("Sorry, your browser doesn't support this feature.");
  }  
}

//******************************
//**  Scripts from dynamicmenus **
//******************************



//******************************
//**  Scripts from commondyn  **
//******************************

function makeCurrent(linkName)
	{
		if ((is_ie5up) || (is_nav5up))
		{
			var temp = document.getElementById(linkName);
		}

		else if (is_ie4up)
		{
			var temp = eval("document.all." + linkName);
		}
		var temp1=temp.className;
		var temp2=temp1.substring(temp1.length-4,temp1.length);
		if (temp2!="Over")
		{
			temp.className=temp1+"Over";
		}
	}

	function makeNonCurrent(linkName)
	{

		if ((is_ie5up) || (is_nav5up))
		{
			var temp = document.getElementById(linkName);
			var temp1=temp.className;
			var temp2=temp1.substring(temp1.length-4,temp1.length);
			if (temp2=="Over")
			{
				temp.className=temp1.substring(0,(temp1.length)-4);
			}
		}
		else if (is_ie4up)
		{
			var temp = eval("document.all." + linkName);
			var temp1=temp.className;
			var temp2=temp1.substring(temp1.length-4,temp1.length);
			if (temp2=="Over")
			{
				temp.className=temp1.substring(0,(temp1.length)-4);
			}

		}
	}

var popupWin;

function openWindow() {
  popupWin = window.open('', 'helpWindow', 'dependent, scrollbars,resizable,width=350,height=300,left=400,top=100')
}

// *****************************************************************************
// *** Description:   							 							 ***
// *****************************************************************************

function globalPageStartup()
{
	/*
	if (is_ie4up)
	{
		document.onmousedown=blockHassles;
		document.onkeypress=blockHassles;
		document.onkeydown=blockHassles;
	}

	if (is_nav4up)
	{
		document.captureEvents(Event.KEYPRESS);

		document.onkeydown=blockHassles;
		document.onclick=blockHassles;
		document.onkeypress=blockHassles;
	}
	*/
}

// ***********************************************************************************
// *** Description:   printablePageStartup()		                               ***
// *** Used when a page has a print-friendly format.                               ***
// *** onLoad, set up the page and, based on parameter, optionally call printPage  ***
// ***********************************************************************************
function printablePageStartup(printFlag) 
{
	globalPageStartup();
	if (printFlag == true) {
		printPage();
	}
}

//The following scripts were taken from the ada prototype of servlet approach.

function launch(url)
{
	window.open(url)//, 'helpwindow', 'status,scrollbars,width=800,height=600,left=30,top=30');
}

function goTo(req)
{
	document.pagedata.RequestID.value=req;
	document.pagedata.submit();
}

function goToReflective(req, act)
{
	document.pagedata.RequestID.value=req;
	document.pagedata.action.value=act;
	document.pagedata.submit();
}

function showItem(req,schemeNo)
{
	document.pagedata.SchemeNumber.value=schemeNo;
	document.pagedata.RequestID.value=req;
	document.pagedata.submit();
}

function showItemWithName(req, schemeName, schemeNo)
{
	document.pagedata.SchemeName.value=schemeName;
	showItem(req, schemeNo);
}


function setRequestAndPayrollAndDataStatus(req,payrollDate,status,dueDate,OpraDate, schemeSiteKey, payrollSiteKey)
{
	document.pagedata.RequestID.value=req;
	document.pagedata.PayrollDate.value=payrollDate;
	document.pagedata.Status.value=status;
	document.pagedata.DueDateOfPayment.value=dueDate;
	document.pagedata.OpraDate.value=OpraDate;
	document.pagedata.SchemeSiteKey.value=schemeSiteKey;
	document.pagedata.PayeeSiteKey.value=payrollSiteKey;
	
	document.pagedata.submit();
}

function setupSchemeData(req, schemeNo, schemeName, adminType, teamCode, productCode, productDescription, isMultisite)
{
	// This function builds upon the functionality provided by showItem(req,schemeNo) as defined above.
	// Scheme Name, Administrator Type, Team Code and Product Code are also passed in request.
	// Stephen Catterson 22-Jan-2002
	document.pagedata.SchemeNumber.value=schemeNo;
	document.pagedata.SchemeName.value=schemeName;
	document.pagedata.AdministratorTypeCode.value=adminType;
	document.pagedata.TeamCode.value=teamCode;
	document.pagedata.ProductCode.value=productCode;
	document.pagedata.ProductDescription.value=productDescription;
	document.pagedata.IsMultisite.value=isMultisite;
	document.pagedata.RequestID.value=req;
	document.pagedata.submit();
}

function setRequest(req)
{
	  document.pagedata.RequestID.value=req;
	  document.pagedata.submit();
}
function setRequestAndAction(req,action)
{
	document.pagedata.RequestID.value=req;
	document.pagedata.action.value=action;
	document.pagedata.submit();
}

function setMenuRequest(req)
{
	  document.menuform.RequestID.value=req;
	  document.menuform.submit();
}
function setMenuRequestAndAction(req,action)
{
	document.menuform.RequestID.value=req;
	document.menuform.action.value=action;
	document.menuform.submit();
}

function goToWindowandclose(targetPage, targetWin)
{
	open(targetPage, targetWin);
	window.close() ;
}

function explodeToSelected()
{
	if ((is_ie4up) || (is_nav5up))
	{
		if (document.leftNavForm)
		{
			var tmp = document.leftNavForm.selectedMenu.value;
			if (tmp != "")
			{
				explodeMenu(document.leftNavForm.selectedMenu.value);
			}
		}
	}
}


