
//to get an element when you only know part of its ID
//sPartEleId - part of elements id
//sTag - Name of the Tag to search in
function getElementId(sPartEleId, sTag){
    var aTag=window.document.body.getElementsByTagName(sTag);
    for(i=0;i<aTag.length;i++)    {
        if(aTag[i].id.indexOf(sPartEleId)!=-1){
            return aTag[i].id;
            break;
        }
    }
    return '';
}

var nSpeedShow=60;
var nSpeedHide=0;
var nSpeed=0;
sTagChildName='LI';
sTagParentName='LI';
var oEle;
var sPrevNavCode='';
var sEleChildId=null;
var nEleChildId=0;
var oChildLinkTimeOut;
var sDisplayMode;
var nCnt=0;
function showlinks(sMenu){
	if(typeof(document.getElementById(sMenu))=='object'){
		showhidelinks(document.getElementById(sMenu));
	}
}
function showhidelinks(othis){
    sNavCode=(typeof(othis)=='string')?othis:othis.id;
    if(sPrevNavCode!=sNavCode||sPrevNavCode==''){
        showhidereset();
        sPrevNavCode=sNavCode;
    }
    sEleId=getElementId(sNavCode,sTagParentName);
    oEle=document.getElementById(sEleId);
    showhidechildlinks();
}
function showhidechildlinks(){
    var oEleChild;
    var sEleId;
    var sDisplay='';
    while(sEleChildId!=''){
        if(nCnt>1000){
            nCnt=0;
            break;
        }
        if(nEleChildId!=0){
            oEleChild=document.getElementById(sEleChildId);
            sDisplay=oEleChild.style.display;
            if(sDisplay=='none'){
                if(nEleChildId!=0){
                    sDisplayMode='block';
                    nSpeed=nSpeedShow;
                }
            }
            else{
				if(nEleChildId!=0){
                    sDisplayMode='none';
                    nSpeed=nSpeedHide;
                }                
            }
            oEleChild.style.display=sDisplayMode;
            if(sDisplayMode=='none')closechildren(oEleChild.id);
        }
			findNextSibling();
			//nEleChildId+=1;
			//sPad=(nEleChildId.toString().length==1)?'00':'0';
			//sEleChildId=oEle.id+sPad+nEleChildId;
			sEleChildId=concatEleChildId();
			nCnt++;
			if(sEleChildId!=''){
				if(typeof(oChildLinkTimeOut)=='number')window.clearTimeout(oChildLinkTimeOut);
				oChildLinkTimeOut=(window.setTimeout('showhidechildlinks()',nSpeed));
				break;        
			}
    }
    if(sEleChildId==''){
        showhidereset();
    }
}
function concatEleChildId(){
	var sPad=(nEleChildId.toString().length==1)?'00':'0';
	sEleChildId=oEle.id+sPad+nEleChildId;
	sEleChildId=getElementId(sEleChildId, sTagChildName);
	return sEleChildId;
}

function findNextSibling()
{
	if(nEleChildId==0){
		nEleChildId+=1;
		if(concatEleChildId()==''){
			var aTag=window.document.body.getElementsByTagName(sTagChildName);
			var nSiblingCnt=0;
			var sSibling='';
			for(i=0;i<aTag.length;i++)    {
				if(aTag[i].id.indexOf(oEle.id)!=-1){
					if(nSiblingCnt==1){
						sSibling=aTag[i].id.substr(aTag[i].id.length-3);
						while(sSibling.substr(0,1)=='0'){
							sSibling=sSibling.substr(1);
						}
						nEleChildId=parseInt(sSibling);
						break;					
					}
					nSiblingCnt+=1;
				}
			}
		}
	}
	else{
		nEleChildId+=1;
	}
}
function showhidereset(){
    if(typeof(oChildLinkTimeOut)=='number')window.clearTimeout(oChildLinkTimeOut);
    sEleChildId=null;
    nEleChildId=0;
    nCnt=0;
}
function closechildren(sParentId){
	var nCnt=0;
	var bChildrenExist=false;
    var aTag=window.document.body.getElementsByTagName(sTagChildName);
	for(i=0;i<aTag.length;i++)    {
        if(aTag[i].id.indexOf(sParentId)!=-1){
			if(nCnt>0){
				aTag[i].style.display='none';
				bChildrenExist=true;
			}
			nCnt++;
        }
    }
    nCnt=0;
	if(bChildrenExist){
		for(i=0;i<aTag.length;i++)    {
			if(aTag[i].id.indexOf(sParentId)!=-1){
				if(nCnt>0){
					closechildren(aTag[i].id);
				}
				nCnt++;
			}
		}
	}
}














function showhideminimenu(othis){
	var sDivHeaderPart='miniMenuHeader';
	var sNavCode=othis.id.substring(othis.id.indexOf(sDivHeaderPart)+sDivHeaderPart.length);
	
	
	/*	
			oEle.style.position='absolute';
		oEle.style.left=objX(oEle)+'px';
		oEle.style.top=objY(oEle)+'px';
*/
	//othis.style.width='500px';
/*
		alert('id:'+othis.id
			+'\n x:'+objX(othis)
			+'\n y:'+objY(othis)
			+'\n offsetLeft:'+othis.offsetLeft
			+'\n offsetTop:'+othis.offsetTop
			+'\n x:'+othis.x
			+'\n y:'+othis.y
			+'\n width:'+othis.style.width
			+'\n clientHeight:'+othis.clientHeight
			+'\n clientWidth:'+othis.clientWidth
			+'\n offsetWidth:'+othis.offsetWidth
			+'\n parent id:'+othis.parentNode.id
			+'\n parent width:'+othis.parentNode.style.width
			+'\n parent parent id:'+othis.parentNode.parentNode.id
			+'\n parent parent width:'+othis.parentNode.parentNode.style.width
			+'\n parent parent parent id:'+othis.parentNode.parentNode.parentNode.id
			);
*/
/*
	theX=othis.offsetLeft+othis.offsetWidth;
	theY=othis.offsetTop;
	if(document.all){
		if(sNavCode.length==3){
			//alert(objX(othis));
			theX-=objX(othis);
			theY-=104;
		}
	}
*/
/*
	theX=objX(othis)+othis.offsetWidth;
	theY=objY(othis);
		alert('theX:'+theX
			+'\n theY:'+theY
			);
*/	
	
	
	
	showhidelinks_new(sNavCode);
}

var sLink='miniMenuItem';
var sTagInnerName='A';
var sTagOuterName='DIV';
sTagInnerName='LI';
sTagOuterName='UL';
var oInnerLinkTimeOut;
var oInnerLink;
var sDisplayModeNew;

var oEle;
function showhidelinks_drop(sNavCode){
	showhidelinks_new(sNavCode,'drop');
}
function showhidelinks_slide(sNavCode){
	showhidelinks_new(sNavCode,'slide');
}

//function showhidelinks_new(sNavCode,strTagOuterName,strTagInnerName){
//	if(typeof(strTagOuterName)=='string')sTagOuterName=strTagOuterName;
//	if(typeof(strTagInnerName)=='string')sTagInnerName=strTagInnerName;
function showhidelinks_new(sNavCode,sType){
	var sEleId=getElementId(sLink+sNavCode,sTagOuterName);
	if(sEleId==''&&sTagOuterName=='DIV'){
		sTagInnerName='LI';
		sTagOuterName='UL';
	}
	else{
		sTagInnerName='A';
		sTagOuterName='DIV';
	}
	sEleId=getElementId(sLink+sNavCode,sTagOuterName);
	if(sEleId=='')return false;
	
	oEle=document.getElementById(sEleId);
	var sDisplay=oEle.style.display;
	if(sDisplay==''||sDisplay=='block'){
		sDisplay='none';
		nSpeed=nSpeedHide;
	}
	else if(sDisplay=='none'){
		sDisplay='block';
		nSpeed=nSpeedShow;
	}
	if(sDisplay=='block'){
		oEle.style.display=sDisplay;
		if(sType=='slide'){
		
		}
/*
        //oEle.style.top='-1000px';
		oEle.style.position='absolute';
		//oEle.style.left=objX(oEle)+'px';
		oEle.style.left=theX+'px';
		oEle.style.top=theY+'px';
*/
/*		alert(oEle.id
			+'\n'+objX(oEle)
			+'\n'+oEle.offsetLeft
			+'\n'+oEle.size
			);
*/		
	}
	oInnerLink=oEle.childNodes;
	sDisplayModeNew=sDisplay;
	showhideinnerlinks_new();
}
function showhideinnerlinks_new(){
	var sDisplay;
	var blnChanged=false;
	try{
		for (var i=oInnerLink.length-1;i>-1;i--) {
			if((oInnerLink[i].tagName)==sTagInnerName){
				sDisplay=oInnerLink[i].style.display;
				if(sDisplayModeNew!=sDisplay){
					oInnerLink[i].style.display=sDisplayModeNew;
						blnChanged=true;
						break;
				}
			}
			if(i==0){oEle.style.display=sDisplayModeNew}
		}
		if(!blnChanged&&sDisplayModeNew=='block'){
			window.clearTimeout(oInnerLinkTimeOut);
		}
		else{
			window.clearTimeout(oInnerLinkTimeOut);
			oInnerLinkTimeOut=(window.setTimeout('showhideinnerlinks_new()',nSpeed));
		}
	}
	catch(err){}
}



// fuction to show hide children lists
// using image method
// call by using <img src="~/images/menu_minus01.gif" onclick="javascript:list_showhidechildren(this.parentNode);" alt="name"/>
function list_showhidechildren(othis){
	var oChildren = new Array();
	oChildren = othis.childNodes;
	var undefined;
	var oImg;
	for(var i=0;oChildren[i]; i++ ){
		if(oChildren[i].tagName=='IMG')oImg=oChildren[i];
		if(oChildren[i].tagName=='LI'||oChildren[i].tagName=='UL'){
			list_showhide(oChildren[i],oImg);
		}
	}
}
function list_showhide(oEle,oImg){
	var sDisplay=oEle.style.display;
	oEle.style.display=(sDisplay==''||sDisplay=='block')?'none':'block';
	var sImgPathPrefix=oImg.src.substring(0,oImg.src.indexOf("images/"))
	oImg.src=(oEle.style.display=='none')?sImgPathPrefix+'images/menu_plus01.gif':sImgPathPrefix+'images/menu_minus01.gif';
	oImg.alt=(oEle.style.display=='none')?' + ':' -- ';
}






// -----START ------ functions for menu - child menu open to right
/* -- html nav example setup -
<div id="holder_link">
	<div id="link001" onmouseover="javascript:doNav(this,'O');" onmouseout="javascript:doNav(this,'C');">
		<a>Link 001</a>
	</div>
	<div id="link002" onmouseover="javascript:doNav(this,'O');" onmouseout="javascript:doNav(this,'C');">
		<a>Link 002</a>
	</div>
</div>
<div id="holder_link002" style="display:none;">
	<div id="link002001" onmouseover="javascript:doNav(this,'O');" onmouseout="javascript:doNav(this,'C');">
		<a>Link 002001</a>
	</div>
	<div id="link002002" onmouseover="javascript:doNav(this,'O');" onmouseout="javascript:doNav(this,'C');">
		<a>Link 002002</a>
	</div>
</div>
<div id="holder_link002001" style="display:none;">
	<div id="link002001001" onmouseover="javascript:doNav(this,'O');" onmouseout="javascript:doNav(this,'C');">
		<a>Link 002001001</a>
	</div>
</div>
*/
var holdTextName='holder';
var linkItemTextName='link';
var textNameJoiner='_';
var VMenuOverlap=0;
var HMenuOverlap=5;
var MenuCloseTimeMS=350;
var CloseAllMenuItem='nn';
var CurrentMenuItem='';
var sOverColor='#006600';
var sOutColor='#009900';
var bSetNavAncestorColor=true;

function doNav(oThis,OpenClose){
	oDEBUG=document.getElementById('debug');
	var sEleId=oThis.id;
	var oMenuItemHolder=document.getElementById(holdTextName+textNameJoiner+sEleId);
	if(OpenClose=='O'){
		//-----set nav item color when mouse over --------
		oThis.style.backgroundColor=sOverColor;
		if(bSetNavAncestorColor){setNavAncestorColor(sEleId,sOverColor)}
		CloseAllMenuItem='nn';
		CurrentMenuItem=sEleId;
		if(typeof(oMenuItemHolder)=='object'&&oMenuItemHolder!=null){
			var bDisplay=true;
			if(oMenuItemHolder.childNodes.length>0){
				//------check if internal childnode is a literal or tag node-----
				if(oMenuItemHolder.childNodes.length==1){
					bDisplay=(typeof(oMenuItemHolder.childNodes[0].tagName)=='string')?true:false;
				}
				if(bDisplay){
					//-----show child holder and set position-----
					//oMenuItemHolder.style.display='block';
					oMenuItemHolder.style.visibility='visible';
					var aLeftTop=findPos(oThis);
					var parentWidth=document.getElementById(sEleId).parentNode.offsetWidth;
					var nodeWidth=document.getElementById(sEleId).offsetWidth;
					var itemWidth=(parentWidth>=nodeWidth)?parentWidth:nodeWidth;
					oMenuItemHolder.style.left=aLeftTop[0]+itemWidth-HMenuOverlap+'px';
					oMenuItemHolder.style.top=aLeftTop[1]+VMenuOverlap+'px';
				}
			}
		}
	}
	else{
		//-----set nav item color when mouse out --------
		oThis.style.backgroundColor=sOutColor;
		if(bSetNavAncestorColor){setNavAncestorColor(sEleId,sOutColor)}
		CloseAllMenuItem='yy';
		window.setTimeout(closeNavHolder,MenuCloseTimeMS);
	}
}
function setNavAncestorColor(tempEleId,sColor){
	var oTempEle;
	while(tempEleId.length>5){
		tempEleId=tempEleId.substr(0,tempEleId.length-3);
		oTempEle=document.getElementById(tempEleId);
		if(typeof(oTempEle)=='object'&&oTempEle!=null){
			oTempEle.style.backgroundColor=sColor;
		}
	}
}
//close all nav holder offspring of curentMenuItem
function closeNavHolder(){
	if(CloseAllMenuItem=='yy'){CurrentMenuItem='';}
	var aTag=window.document.body.getElementsByTagName('DIV');
	var linkId='';
	for(i=0;i<aTag.length;i++){
		linkId=aTag[i].id;
		if(linkId.indexOf(holdTextName+textNameJoiner+linkItemTextName)!=-1){
			if(CurrentMenuItem.indexOf(linkId.replace(holdTextName+textNameJoiner,''))==-1){
				//aTag[i].style.display='none';
				aTag[i].style.visibility='hidden';
			}
		}
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
// -----END ------ function for menu - child menu open to right
function ralignArrow(event){
	//var aArrow=getElementCol('lblArrow','SPAN');
	var aArrow=getElementCol('arrow','IMG');
	var i;
	var oArrow,oHolderInner,oHolder,oTxt,holderW,holderInnerW,containerW,extraPad;
	var holderInnerL,arrowL,holderInnerR,arrowW;

	for (i in aArrow)
	{
		oArrow=aArrow[i];
		oHolderInner=oArrow.parentNode;
		oHolder=oHolderInner.parentNode;
		oTxt=oArrow.previousSibling;
		//oArrow.style.paddingLeft="0px";
		oTxt.style.paddingRight="0px";

		holderInnerL=findPos(oHolderInner)[0];
		arrowL=findPos(oArrow)[0];
		holderW=oHolder.offsetWidth;
		holderInnerW=oHolderInner.offsetWidth;
		arrowW=oArrow.offsetWidth;
		containerW=(holderW>=holderInnerW)?holderW-10:holderW;
		holderInnerR=holderInnerL+containerW;
		extraPad=(holderInnerR-(arrowL+arrowW))+"px";
		/*alert(''
				+'\n containerW:'+containerW
				+'\n holderInnerR:'+holderInnerR
				+'\n arrowL:'+arrowL
				+'\n arrowW:'+arrowW
				+'\n extraPad:'+extraPad
				+'\n event.type:'+event.type
				);*/
		//oArrow.style.paddingLeft=extraPad;
		try{
			//during login an error occurs
			oTxt.style.paddingRight=extraPad;
		}
		catch(err){}
	}
}
if(window.addEventListener){
	window.addEventListener("load",ralignArrow,true);
}
else if(window.attachEvent){
	window.attachEvent("onload",ralignArrow);
}

