
var globalId=0;


function checkMouseOverLt(id){
	document.getElementById("b"+id).className="catalogtopNavBtnMiOver";
}

function checkMouseOverRt(id){
	if(subMenuList[id].length>0){
		document.getElementById("c"+id).className="topNavBtnRtOver";
	}

}
function checkMouseOutRt(id){
		document.getElementById("c"+id).className="catalogtopNavBtnRt";
		document.getElementById("myDiv").style.display="none";
}

function checkMouseOutLt(id){
		document.getElementById("b"+id).className="catalogtopNavBtnMi";
		document.getElementById("myDiv").style.display="none";
}
function checkMouseActiveTds(id){

	document.getElementById("b"+id).className="catalogtopNavBtnMi";
	document.getElementById("c"+id).className="topNavBtnRtActive";

}
function checkMouseActive(id,divId){
	if(subMenuList[id].length!=0)	{
	globalId=id;
	var pos =getPosition(divId);
	var width=document.getElementById(divId).offsetWidth;

	var tableHead='<table cellpadding="0" cellspacing="0" border="0" bordercolor="green" width="100%" valign="top">';
	var tableFoot="</table>";
	var tableBody="";
	for(var i=0; i<subMenuList[id].length;i++){
		tableBody=tableBody+'<tr ><td width="5px"></td><td class="menuList"  id="td'+id+i+'" onmouseover="CallOver(\'td'+id+i+'\')" onmouseout= "CallOut(\'td'+id+i+'\')" onclick="javascript:goToLinkURL(\''+id+'\','+i+',true);">'+subMenuList[id][i].title+'</td><td width="5px"></td></tr>';
	}
	document.getElementById("mainMenuBody").innerHTML=tableHead+tableBody+tableFoot;
		checkMouseActiveTds(id);
		document.getElementById("myDiv").style.display="";
		document.getElementById("myDiv").style.top=pos.x+42;
		document.getElementById("myDiv").style.left=pos.y;
		document.getElementById("buttonMatchTd").style.width=width;
		document.getElementById("divRightBgTD").style.width=(210-(width+4))+"px";
	}
}


function checkMouseActiveTdsOpt(id){

	document.getElementById("bOpt"+id).className="catalogtopNavBtnMi";
	document.getElementById("cOpt"+id).className="topNavBtnRtActive";

}
function checkMouseOverLtOpt(id){
	document.getElementById("bOpt"+id).className="catalogtopNavBtnMiOver";
}

function checkMouseOverRtOpt(id){
	if(optSubMenuList[id].length>0){
		document.getElementById("cOpt"+id).className="topNavBtnRtOver";
	}

}
function checkMouseOutRtOpt(id){
		document.getElementById("cOpt"+id).className="catalogtopNavBtnRt";
		document.getElementById("myDivOpt").style.display="none";
}

function checkMouseOutLtOpt(id){
		document.getElementById("bOpt"+id).className="catalogtopNavBtnMi";
		document.getElementById("myDivOpt").style.display="none";
}

function checkMouseActiveOpt(id,divId){
	//alert('ID = '+id+"  divId = "+divId);
	if(optSubMenuList[id].length!=0)	{
	globalId=id;
	//alert('checkMouseActiveOpt = '+divId);
	var pos =getPosition(divId);
	//alert('X = '+pos.x+' & Y = '+pos.y);
	var width=document.getElementById(divId).offsetWidth;

	var tableHead='<table cellpadding="0" cellspacing="0" border="0" bordercolor="green" width="100%" valign="top">';
	var tableFoot="</table>";
	var tableBody="";
	for(var i=0; i<optSubMenuList[id].length;i++){
		tableBody=tableBody+'<tr ><td width="5px"></td><td class="menuList"  id="td'+id+i+'" onmouseover="CallOver(\'td'+id+i+'\')" onmouseout= "CallOut(\'td'+id+i+'\')" onclick="javascript:goToLinkURL(\''+id+'\','+i+',false);">'+optSubMenuList[id][i].title+'</td><td width="5px"></td></tr>';
	}
	document.getElementById("mainMenuBodyOpt").innerHTML=tableHead+tableBody+tableFoot;
		checkMouseActiveTdsOpt(id);
		document.getElementById("myDivOpt").style.display="";
		document.getElementById("myDivOpt").style.top=pos.x+42;
		document.getElementById("myDivOpt").style.left=pos.y;
		document.getElementById("buttonMatchTdOpt").style.width=width;
		document.getElementById("divRightBgTDOpt").style.width=(210-(width+4))+"px";
	}
}



function CallOver(objId){
	//alert("OVer : "+objId);
	var obj = document.getElementById(objId);
	obj.className = "menuList1";
	obj.style.cursor="pointer";
}
function CallOut(objId)
{
	//alert("Out : "+objId);
	var obj = document.getElementById(objId);
	obj.className = "menuList";
	obj.style.cursor="pointer";
}
function goToLinkURL(id,i,isSubMenuList){
	var url;
	if(isSubMenuList){
		url = subMenuList[id][i].linkURL;
	}else{
		url = optSubMenuList[id][i].linkURL;
	}
	//alert(url);
	document.location.href=url;
}

function openPage(operation, action)
{
	var m_form= document.forms["menuform"];

	m_form.operation.value = operation;
	m_form.action = action;
	m_form.status.value="active";

	m_form.submit();

}

function getPosition(objId){
	var obj = document.getElementById(objId);
	var top  = 0;
	var left  = 0;
	while (obj.offsetParent){
		top  += obj.offsetTop;
		left  += obj.offsetLeft;
		obj     = obj.offsetParent;
	}
	top  += obj.offsetTop;
	left  += obj.offsetLeft;

	return {x:top,y:left};
}

function divMouseOver(){
	document.getElementById("myDiv").style.display="";
	checkMouseActiveTds(globalId);
}

function divMouseOut(){
		document.getElementById("myDiv").style.display="none";
		checkMouseOutLt(globalId);
		checkMouseOutRt(globalId);

}

function divMouseOverOpt(){
	document.getElementById("myDivOpt").style.display="";
	checkMouseActiveTdsOpt(globalId);
}

function divMouseOutOpt(){
		document.getElementById("myDivOpt").style.display="none";
		checkMouseOutLtOpt(globalId);
		checkMouseOutRtOpt(globalId);

}
function menuBar (flag) {

	document.getElementById("menuform").style.display="none";

	var navibar='<table valign="top" cellpadding=0 cellspacing=0 border="0" height="0px" bordercolor="blue"><tr>';

	for(var i=1; i<menuList.length; i++) {

		var menuListName = splitChecker(menuList[i].title);

		var lastTDHTML ;
		var paddingRt;
		if(subMenuList[i].length>0){
			lastTDHTML='<td onmouseover= "checkMouseOverRt('+i+')" onmouseout="checkMouseOutRt('+i+')"><div class="catalogtopNavBtnRt" id = "c'+i+'"><a id="link"'+i+'" href="#" onclick= "checkMouseActive('+i+',\'div'+i+'\')"></a></div></td>';
			paddingRt="7px;"
		}else{
			lastTDHTML='<td><div class="catalogtopNavBtnRtNoSubMenu" ></div></td>';
			paddingRt="3px;"
		}

		navibar = navibar+'<td height="0px"><div id="div'+i+'" >'+
		'<table cellpadding="0" cellspacing="0" valign="top" height="0px" border="0"  bordercolor="Green"  >'+
			'<tr valign="top"><td height="0px" valign="top"><div class="catalogtopNavBtnLt" id = "a'+i+'" ><a href="#">&nbsp;</a></div></td>'+
				'<td  id="centerTD'+i+'" align="left" onmouseover= "checkMouseOverLt('+i+')" onmouseout="checkMouseOutLt('+i+')"> <div  class="catalogtopNavBtnMi" id = "b'+i+'" ><a href="'+menuList[i].linkURL+'" style="padding-left:3px;padding-right:'+paddingRt+'" >'+menuListName+'</a></div></td>'+
				lastTDHTML+
			'</tr></table></div></td><td width="1px"></td>';
	}
	var tdLength = menuList.length;

	if(flag){
			var second = optionalMenu();
			navibar = navibar+second;
			tdLength = tdLength + optMenuList.length;
	}



	navibar = navibar +'</tr>';

	if(navigator.appName.indexOf("Microsoft")>-1){

		navibar = navibar +'<tr ><td style="height:8px;" colspan="'+tdLength+'" valign="top"></td></tr>';
	}

	navibar = navibar +'</table>';

	document.getElementById("menuId").innerHTML = navibar;

}

 function optionalMenu ()	{

	var navibar="";

	for(var i=1; i<optMenuList.length; i++) {

		var menuListName = splitChecker(optMenuList[i].title);
		var lastTDHTML ;
		var paddingRt;

			// Following piece of code is to determine whether to show the arro
		if(optSubMenuList[i].length>0){
			lastTDHTML='<td onmouseover= "checkMouseOverRtOpt('+i+')" onmouseout="checkMouseOutRtOpt('+i+')"><div class="catalogtopNavBtnRt" id = "cOpt'+i+'"><a id="link"'+i+'" href="#" onclick= "checkMouseActiveOpt('+i+',\'divOpt'+i+'\')"></a></div></td>';
			paddingRt="7px;"
		}else{
			lastTDHTML='<td><div class="catalogtopNavBtnRtNoSubMenu" ></div></td>';
			paddingRt="3px;"
		}
		navibar = navibar+'<td height="47px" valign="top"><div id="divOpt'+i+'" >'+
		'<table cellpadding="0" cellspacing="0" valign="top" height="47px" border="0"  bordercolor="Green"  >'+
			'<tr valign="top"><td height="47px" valign="top"><div class="catalogtopNavBtnLt" id = "aOpt'+i+'" ><a href="#">&nbsp;</a></div></td>'+
				'<td  id="centerTD'+i+'" align="left" onmouseover= "checkMouseOverLtOpt('+i+')" onmouseout="checkMouseOutLtOpt('+i+')"> <div class="catalogtopNavBtnMi" id = "bOpt'+i+'"><a href="'+optMenuList[i].linkURL+'" style="padding-left:3px;padding-right:'+paddingRt+'" >'+menuListName+'</a></div></td>'+
				lastTDHTML+
			'</tr></table></div></td><td width="1px"></td>';
	}

 return navibar;
 }
function splitChecker(text){

	if(text.length>12){
		var halfLen = parseInt(text.length/2, 10);
		var spacePos=-1;

		for(i=halfLen;i>-1;i--){
			if(text.charAt(i)==" "){
				spacePos=i;
				break;
			}
		}
		if(spacePos!=-1){
			text = text.substring(0,spacePos)+"<br>"+text.substring(spacePos+1);
		}
	}
	return text;

}



function openStaticPage(operation, action)
{
	var m_form= document.forms["menuform"];

	m_form.operation.value = operation;
	m_form.action = action;
	m_form.status.value="active";

	m_form.submit();

}




