// ----- browsercheck

// function popUp(){return}; 
// function popDown(){return};

function checkOS() {
  if(navigator.userAgent.indexOf('Linux') != -1)
    { var OpSys = "Linux"; }
  else if((navigator.userAgent.indexOf('Win') != -1) &&
  (navigator.userAgent.indexOf('95') != -1))
    { var OpSys = "Windows95"; }
  else if(navigator.userAgent.indexOf('Win') != -1)
    { var OpSys = "Windows3.1 or NT"; }
  else if(navigator.userAgent.indexOf('Mac') != -1)
    { var OpSys = "Macintosh"; }
  else { var OpSys = "other"; }
  return OpSys;
}

var OpSys = checkOS();
// alert(OpSys);


beginRollover = false;// This handles a bug in Nav4.0x that executes the code too quickly.

// convert all characters to lowercase to simplify testing 
var agt=navigator.userAgent.toLowerCase(); 

// *** BROWSER VERSION *** 
// Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 

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_nav5 = (is_nav && (is_major == 5)); 
var is_nav5up = (is_nav && (is_major >= 5)); 

var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) ); 
var is_ie4up  = (is_ie  && (is_major >= 4)); 
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4); 
var isIE4, isIE4PC, isNav4PC, isNav4, isNav3;

if (is_ie4 || is_ie4up || is_nav5 || is_nav5up) {
	isIE4 = true;
	if (OpSys != "Macintosh") {
		isIE4PC = true;
	} 
} else if (is_nav4) {
	isNav4 = true;
	if (OpSys != "Macintosh") {
		isNav4PC = true;
	} 
} else if  (is_nav) {
	isNav3 = true;	
}


isMenu = (isIE4 || isIE4PC || isNav4 || isNav4PC) ? 1 : 0; 



// ----- menuparams
if (isMenu) { 
	// alert("Loading Menu Params");
	menuWidth = 180; 
	borWid = 1; 
	fntCol = "black"; 
	fntSiz = "10px"; 
	fntWgh = "normal"; 
	fntSty = "normal"; 
	fntFam = "verdana"; 
	borCol = "black";
	borSty = "outset"; 
	linHgt = "normal"; 
	backCol = "#E9A12E"; 
	overCol = "#9FB2CB"; 
	overFnt = "#ffffff"; 
	imgSrc = "triangle.gif"; 
	imgSiz = 10; 
	childOverlap = 0; 
	childOffset = 3; 
	perCentOver = null; 
	secondsVisible = .5; 
	} 

/*hierMenus.js - Contains the generating codes for the Pop-up Menus - Cross-browser*/

if (perCentOver != null) {
	childOverlap = (perCentOver/100) * menuWidth
}
mSecsVis = secondsVisible*1000;

/*
A CSS stylesheet, defining a class named .items, is created dynamically, using our several of our parameter variables: 
*/

semi = ";";
styleTyp = "<STYLE TYPE='text/css'>"
styleTyp += ".items {"
styleTyp += "width:" + menuWidth + semi
styleTyp += "color:"+ fntCol + semi
styleTyp += "font-size:"+ fntSiz + semi
styleTyp += "font-weight:"+ fntWgh + semi
styleTyp += "font-style:"+ fntSty + semi
styleTyp += "font-family:"+ fntFam + semi
styleTyp += "border-width:" + borWid + semi
styleTyp += "border-color:" + borCol + semi
styleTyp += "border-style:" + borSty + semi
styleTyp += "line-height:" + linHgt + semi
styleTyp += "}"
styleTyp += "</STYLE>";
 
document.write(styleTyp);

// Global variables, image arrow pointer

imgStr = "<IMG SRC=" + imgSrc + " WIDTH=" + imgSiz + " HEIGHT=" + imgSiz +" BORDER=0 VSPACE=2 ALIGN=RIGHT>"

menuCount = 1;
isCreated = false;
isOverMenu = false;
currMenu = null;
allTimer = null;

// Control is passed to the loadmenus() function on Page Load.

function loadmenus() {
	while(eval("window.arrayMenu" + menuCount)) {
		topArray = eval("arrayMenu" + menuCount);
		topName = "dispMenu" + menuCount;
//		alert(topName);
// -------------------------------------------
		if ((isNav4) || (isNav4PC)) {
//		if ((NS4) && !(NS4M)) {
			topMenu = makeItem(topName,window);
		}
		else {
			topMenu = makeItem(topName);
		}
// -------------------------------------------
    		topMenu.setup = menuSetup;

		menuItemCount = 0;
		for (i=0; i<topArray.length; i+=3) {
			menuItemCount++;
			// status = "Creating Popup Menus: " + menuCount + " / " + menuItemCount;
			topItemName = "item" + menuCount + "_" + menuItemCount;
			topItem = makeItem(topItemName,topMenu);
			if (menuItemCount >1)
				topItem.prevItem = eval("item" + menuCount + "_" + (menuItemCount-1));
			topItem.setup = itemSetup;
			topItem.setup(i,topArray);

			if (topItem.hasMore) makeSecond();
		}
		
		topMenu.setup(false,topItem);
		menuCount++
	}

	// status = (menuCount-1) + " Heirarchical Menu Trees Created";
	
	defaultStatus = "Welcome to MTech India Pvt. Ltd.";
	status = "Welcome to MTech India Pvt. Ltd.";

	isCreated = true;
}

// menuSetup() defines the custom menu properties and methods 

function menuSetup(hasParent,lastItem,openCont,openItem) {

	this.menuOver = menuOver;
	this.menuOut = menuOut;

	this.onmouseover = this.menuOver;
	this.onmouseout = this.menuOut;

	this.showIt = showIt;
	this.keepInWindow = keepInWindow;

	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	
	this.hasChildVisible = false;
	this.isOn = false;
	
	this.hideTimer = null;

	if (hasParent) {
		this.hasParent = true;
		this.parentMenu = openCont;
		this.parentItem = openItem;
		this.parentItem.child = this;
	}
	else {
		this.hasParent = false;
		this.hideSelf = hideSelf;
	}

	if ((isNav4) || (isNav4PC)) {
//	if (NS4) {
		this.fullHeight = lastItem.top + lastItem.document.height;
		this.clip.bottom = this.fullHeight;
	}
	else {
	    this.fullHeight = lastItem.style.pixelTop + lastItem.offsetHeight;
		this.showIt(false);
		this.onselectstart = cancelSelect;
		this.moveTo = moveTo;
		this.moveTo(0,0);
	}
}

/*
The itemsetup() method builds the item and styles it.
*/
function itemSetup(arrayPointer,whichArray) {
	this.itemOver = itemOver;
	this.itemOut = itemOut;
	this.onmouseover = this.itemOver;
	this.onmouseout = this.itemOut;

	this.linkText = whichArray[arrayPointer];
	this.linkURL = whichArray[arrayPointer + 1];
	this.hasMore = whichArray[arrayPointer + 2];

	if (this.linkURL.length > 0) {
		this.linkIt = linkIt;
		if ((isNav4) || (isNav4PC)) {
//		if (NS4) {
			this.onfocus = this.linkIt;
		}
		else {
			this.onclick = this.linkIt;
			this.style.cursor = "hand";
		}
	}
      
	if (this.hasMore) {
		htmStr = imgStr + this.linkText;
	}
	else {
		htmStr = this.linkText;
	}

	if ((isNav4) || (isNav4PC)) {
//	if (NS4) {
		layStr = "<SPAN CLASS=items>" + htmStr+ "</SPAN>";
		this.document.write(layStr);
		this.document.close();

		this.bgColor = backCol;
		this.clip.right = menuWidth;
		this.visibility = "inherit";
		this.container = this.parentLayer;

		if (arrayPointer == 0) {
			this.top = 0;
		}
		else {
			this.top = this.prevItem.top + this.prevItem.document.height - borWid;
		}
		this.left = 0;
	}
	else {
		this.className = "items";
		this.style.padding = 2;
		this.innerHTML = htmStr;

		this.style.backgroundColor = backCol; 
		this.container = this.offsetParent;

		if (arrayPointer == 0) {
			this.style.pixelTop = 0;
		}
		else {
			this.style.pixelTop = this.prevItem.style.pixelTop + this.prevItem.offsetHeight - borWid;
		}
		this.style.pixelLeft = 0;
	}
}

function makeItem(whichMenu,whichContainer) {
//	alert(arguments.length);

	if (arguments.length==1){
		whichContainer = ((isNav4) || (isNav4PC)) ? window : document.body;
	}

	if ((isNav4) || (isNav4PC)) {
//	if (NS4) {
		eval(whichMenu + "= new Layer(menuWidth,whichContainer)");
		return eval(whichMenu);
	}
	else {
		elStr = "<DIV ID=" + whichMenu + " STYLE='position:absolute'></DIV>";
		whichContainer.insertAdjacentHTML("BeforeEnd",elStr);
	}
	return eval(whichMenu);
}



function makeSecond() {
	secondCount = menuCount + "_" + menuItemCount;
	
	secondArray = eval("arrayMenu" + secondCount);
	secondName = "elChild" + secondCount;
	
	secondMenu = makeItem(secondName);
	secondMenu.setup = menuSetup;

	secondItemCount=0;
	for (j=0; j<secondArray.length; j+=3) {
		secondItemCount++;
		secondItemName = "item" + secondCount +"_" + secondItemCount;

		secondItem = makeItem(secondItemName,secondMenu)		
		
		if (secondItemCount >1)
			secondItem.prevItem = eval("item" + secondCount  + "_" + (secondItemCount-1));

		secondItem.setup = itemSetup;
		secondItem.setup(j,secondArray);

		if (secondItem.hasMore) makeThird();
	}

	secondMenu.setup(true,secondItem,topMenu,topItem);
}

function makeThird() {
	thirdCounter = secondCount + "_" + secondItemCount 
	
	thirdArray = eval("arrayMenu" + thirdCounter);
	thirdName = "elGrandChild" + thirdCounter;
	thirdMenu = makeItem(thirdName)
	
	thirdMenu.setup = menuSetup;

	thirdItemCount=0;
	for (k=0; k<thirdArray.length; k+=3) {
		thirdItemCount++;
		thirdItemName = "item" + thirdCounter + "_" + thirdItemCount;
		thirdItem = makeItem(thirdItemName,thirdMenu);

		if (thirdItemCount >1)
			thirdItem.prevItem = eval("item" + thirdCounter + "_" +(thirdItemCount-1));

		thirdItem.setup = itemSetup;
		thirdItem.setup(k,thirdArray);

	}

	thirdMenu.setup(true,thirdItem,secondMenu,secondItem);
}

function linkIt() {
	location.href = this.linkURL;
}

/* 
Since the elements are dynamically created, Navigator insists on show/hide values for its visibility property. Explorer accepts the CSS-compliant visible/hidden values.
*/
function showIt(on) {
//	if (NS4) {this.visibility = (on) ? "show" : "hide"}
	if ((isNav4) || (isNav4PC)) {
		{this.visibility = (on) ? "show" : "hide"};
	}
	else {
		{this.style.visibility = (on) ? "visible" : "hidden"};
	}
}

/*
The keepInWindow() function is primarily concerned with element and window measurement, and element positioning. Unfortunately, the two browsers don't agree on the properties used. The logic is exactly the same, just the property names differ.
*/
function keepInWindow() {
	scrBars = 20;

	if ((isNav4) || (isNav4PC)) {
//	if (NS4) {
		winRight = (window.pageXOffset + window.innerWidth) - scrBars;
		rightPos = this.left + menuWidth;
   
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft-menuWidth) + childOverlap);
				this.left = newLeft;
			}
			else {
				dif = rightPos - winRight;
				this.left -= dif;
			}
		}

		winBot = (window.pageYOffset + window.innerHeight) - scrBars;
		botPos = this.top + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.top -= dif;
		}
	}
	else {
    	winRight = (document.body.scrollLeft + document.body.clientWidth) - scrBars;
		rightPos = this.style.pixelLeft + menuWidth;
	
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.style.pixelLeft;
				newLeft = ((parentLeft - menuWidth) + childOverlap);
				this.style.pixelLeft = newLeft;
			}
			else {
				dif = rightPos - winRight;
				this.style.pixelLeft -= dif;
			}
		}

		winBot = (document.body.scrollTop + document.body.clientHeight) - scrBars;
		botPos = this.style.pixelTop + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.style.pixelTop -= dif;
		}
	}
}

function showmenu(menuName){

	if (!isCreated) return;

	hideAll();
	currMenu = eval(menuName);
	currMenuCount = menuName.substring(menuName.length-1);
	xPos = 163;
	yPos = 100 + (currMenuCount-1.4)*25;
	currMenu.moveTo(xPos,yPos);

	currMenu.keepInWindow()
	currMenu.isOn = true;
	currMenu.showIt(true);
}

function showmenuTop(menuName){

	if (!isCreated) return;

	hideAll();
	currMenu = eval(menuName);
	currMenuCount = menuName.substring(menuName.length-1);
	//yPos = 97;
	//xPos = 86 + (-1.4)*25
	if(currMenuCount==5){
	yPos = 95;
	xPos = 168
	}
	if(currMenuCount==6){
	yPos = 95;
	xPos = 260
	}
	if(currMenuCount==7){
	yPos = 95;
	xPos = 670
	}
	

	currMenu.moveTo(xPos,yPos);

	currMenu.keepInWindow()
	currMenu.isOn = true;
	currMenu.showIt(true);
}

function hidemenuTop(menuName){ 
	if (!isCreated) return;
	whichMenu = eval(menuName);
	whichMenu.isOn = false;
	whichMenu.hideTop();
}




function hidemenu(menuName){ 
	if (!isCreated) return;
	whichMenu = eval(menuName);
	whichMenu.isOn = false;
	whichMenu.hideTop();
}

function menuOver() {
	this.isOn = true;
	isOverMenu = true;
	currMenu = this;
	if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
	if (((isIE4) || (isIE4PC)) && event.srcElement.contains(event.toElement)) return;
//	if (IE4 && event.srcElement.contains(event.toElement)) return;
	this.isOn = false;
	isOverMenu = false;
	if ((isIE4) || (isIE4PC)) allTimer = setTimeout("currMenu.hideTree()",1); 
//	if (IE4) allTimer = setTimeout("currMenu.hideTree()",1); 
}

function itemOver(){
//	if ( IE4&& event.srcElement.tagName == "IMG") return;
	if (((isIE4) || (isIE4PC)) && event.srcElement.tagName == "IMG") return;

//	if (NS4) {
	if ((isNav4) || (isNav4PC)) {
		this.bgColor = overCol;
	}
	else {
		this.style.backgroundColor = overCol;
		this.style.color = overFnt;
	}
	
	if (this.container.hasChildVisible) {
		this.container.hideChildren(this);
	}            

	if(this.hasMore) {
		if ((isNav4) || (isNav4PC)) {
//		if (NS4) {
			this.childX = this.container.left + (menuWidth - childOverlap);
			this.childY = this.pageY + childOffset;
		}
		else {
			this.childX = this.container.style.pixelLeft + (menuWidth - childOverlap);
			this.childY = this.style.pixelTop + this.container.style.pixelTop + childOffset;
		}

		this.child.moveTo(this.childX,this.childY);
		this.child.keepInWindow();
		this.container.hasChildVisible = true;
		this.container.visibleChild = this.child;
		this.child.showIt(true);
	}
}


function itemOut() {
//    if (IE4 && (event.srcElement.contains(event.toElement)
    if (((isIE4) || (isIE4PC)) && (event.srcElement.contains(event.toElement)
     || (event.fromElement.tagName=="IMG" && event.toElement.contains(event.fromElement))))
        return;

	if ((isNav4) || (isNav4PC)) {
//	if (NS4) {
		this.bgColor = backCol;
		if (!isOverMenu) {
			allTimer = setTimeout("currMenu.hideTree()",3);
		}
	}
	else {
		this.style.backgroundColor = backCol;
		this.style.color = fntCol;
	}
}

function hideAll() {
	for(i=1; i<menuCount; i++) {
		temp = eval("dispMenu" + i);
		temp.isOn = false;
		if (temp.hasChildVisible) temp.hideChildren();
		temp.showIt(false);
	}	
}

function hideTree() { 
	allTimer = null;
	if (isOverMenu) return;
	if (this.hasChildVisible) {
		this.hideChildren();
	}
	this.hideParents();
}

function hideChildren(item) {
	if (this.visibleChild.hasChildVisible) {
		this.visibleChild.visibleChild.showIt(false);
		this.visibleChild.hasChildVisible = false;
	}

	if (!this.isOn || !item.hasMore || this.visibleChild != this.child) {
		this.visibleChild.showIt(false);
		this.hasChildVisible = false;
	}
}

function hideParents() {     

	if (this.hasParent) {
		this.showIt(false);
		if (this.parentMenu.hasParent) {
			this.parentMenu.isOn = false;		
			this.parentMenu.showIt(false);
			this.parentMenu.parentMenu.isOn = false;
			whichMenu = this.parentMenu.parentMenu;
		}
		else {
			this.parentMenu.isOn = false;
			whichMenu = this.parentMenu;
		}
	}
	else {
		whichMenu = this;
	}

	whichMenu.hideTop();
}

function hideTop() {
	whichMenu = this;
	this.hideTimer = setTimeout("whichMenu.hideSelf()",mSecsVis);
}

function hideSelf() {
	this.hideTimer = null;
	if (!this.isOn && !isOverMenu) { 
		this.showIt(false);
	}
}

function cancelSelect() {
	return false;
}

function moveTo(xPos,yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

// onload event handler

window.onload = loadmenus;


