var appPath='stackfree'


//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){}
}

// __________________________________________________________________________________________________________________


// -----START - functions create ul treeview html via from text -----
/* -- string to create ul treeview --
var ulTreeView = new String
ulTreeView='001'
				+'\n--001.001'
				+'\n----001.001.001'
				+'\n--001.002'
				+'\n----001.002.001'
				+'\n----001.002.002'
				+'\n------001.002.002.001'
				+'\n------001.002.002.002'
				+'\n----001.002.003'
*/








// -----START - functions to add tree view elements into ul html -----
/* -- html ul structure required --
<ul>
	<li>
		<a href="#" title="Lorem Ipsum">Lorem Ipsum</a>
		<ul>
			<li>
				<a href="#" title="Dolor Sit Amet">Dolor Sit Amet</a>
				<ul>
					<li>
						<a href="#" title="Consectetur Adipiscing Elit">Consectetur Adipiscing Elit</a>
					</li>
				</ul>
			</li>
			<li>
				<a href="#" title="Fusce Nec Nibh">Fusce Nec Nibh</a>
			</li>
		</ul>
	</li>
	<li>
		<a href="#" title="Ac Mauris">Ac Mauris</a>
		<ul>
			<li>
				<a href="#" title="Convallis Auctor Sit Amet">Convallis Auctor Sit Amet</a>
			</li>
		</ul>
	</li>
</ul>

*/
//note: each li should only have maximum two child elements, not including textNodes
//either "anchorNode<A> by itself" or "anchorNode<A> followed by an unorderedListNode<UL>"
var ulTreeViewClass='ulsitemap';
function ulTreeView(oUL,ulClass){
	//alert('ulTreeView');
	if(!ulClass)ulClass=ulTreeViewClass;
	//add class to initial ul
	oUL.className=ulClass;
	//get all anchors for initial ul
	var oAs=oUL.getElementsByTagName('A');
	var oLastChild;
	var oFirstChild;
	var imgType;
	var i;
	for(i=0;oAs[i];i++){
		//if(i>1000)break;
		if(i>0&&i%1000==0){
			if(!confirm('List conversion to tree view is still processing.\nClick \'OK\' to continue or \'Cancel\' to stop processing.')){
				break;
			}
		}
		oFirstChild=oAs[i].parentNode.firstChild;
		oLastChild=oAs[i].parentNode.lastChild;
		//get previousSibling of lastChild if lastChild is text
		if(oLastChild.nodeName=='#text')oLastChild=oLastChild.previousSibling;
		//add class to ul
		if(oLastChild.nodeName=='UL')oLastChild.className=ulClass;
		//when anchor is lastChild then it does not have any children
		imgType=(oAs[i]==oLastChild)?'BLANK':'MINUS';
		//add some text before anchor if it is the firstChild
		if(oAs[i]==oFirstChild)oAs[i].parentNode.insertBefore(document.createTextNode(' '),oAs[i]);
		//add image before anchor and text
		oAs[i].parentNode.insertBefore(imgForTreeView(imgType),oAs[i].previousSibling);
	}
}
var pathHostPrefix=document.location.protocol+'//'+document.location.hostname
pathHostPrefix+=(document.location.href.indexOf('/'+appPath+'/')>0)?'/'+appPath:'';
function imgForTreeView(imgType){
	//get image path location
	var pathPrefix=pathHostPrefix+'/images/site/';
	//pathPrefix='';
	var oImg=document.createElement('IMG');
	//assign onclick event to image - browser dependant
	if (window.attachEvent){
		oImg.onclick=function(){list_showhidechildren(this.parentNode)};
	}
	else{
        oImg.setAttribute('onclick', 'javascript:list_showhidechildren(this.parentNode);');
	}
	//assign src to image
	switch(imgType){
		case 'PLUS':
	        oImg.setAttribute('src', pathPrefix+'menu_plus02.gif');
	        oImg.setAttribute('alt', ' + ');
			break;
		case 'MINUS':
	        oImg.setAttribute('src', pathPrefix+'menu_minus02.gif');
	        oImg.setAttribute('alt', ' -- ');
			break;
		case 'BLANK':
	        oImg.setAttribute('src', pathPrefix+'blank.gif');
	        oImg.setAttribute('alt', '..');
			break;
	}
	return oImg;
}

// function to show hide children lists
// using image method
// call by using <img src="menu_minus02.gif" onclick="javascript:list_showhidechildren(this.parentNode);" alt="name"/>
function list_showhidechildren(oEleListItem){
	var oChildren = new Array();
	oChildren = oEleListItem.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){
	//get image path location
	var pathPrefix=pathHostPrefix+'/images/site/';
	//pathPrefix='';

	var sDisplay=oEle.style.display;
	oEle.style.display=(sDisplay==''||sDisplay=='block')?'none':'block';
	oImg.src=(oEle.style.display=='none')?pathPrefix+'menu_plus02.gif':pathPrefix+'menu_minus02.gif';
	oImg.alt=(oEle.style.display=='none')?' + ':' -- ';
}
// -----END - functions to add tree view elements into ul html -----



// -----START ------ Side Menu - functions for menu - child menu open to right
/* -- html side menu example setup
<div class="SideNavContainer">
	<div class="SideNav" style="display:block">
		<a id="link_1" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#"><img src="menu_arrow_right.gif">Lorem Ipsum</a>
		<a id="link_2" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#"><img src="menu_arrow_right.gif">Ac Mauris</a>
	</div>
	<div id="holder_link_1" class="SideNav" style="display:none;">
		<a id="link_1_1" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#"><img src="menu_arrow_right.gif">Dolor Sit Amet</a>
		<a id="link_1_2" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#">Fusce Nec Nibh</a>
	</div>
	<div id="holder_link_1_1" class="SideNav" style="display:none;">
		<a id="link_1_1_1" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#">Consectetur Adipiscing Elit</a>
	</div>
	<div id="holder_link_2" class="SideNav" style="display:none;">
		<a id="link_2_1" onmouseout="javascript:sideNavOpenClose(this,'C');" onmouseover="javascript:sideNavOpenClose(this,'O');" href="#">Convallis Auctor Sit Amet</a>
	</div>
</div>
*/
var holdTextName='holder';
var linkItemTextName='link';
var textNameJoiner='_';
var VMenuOverlap=-1;
var HMenuOverlap=3;
var MenuCloseTimeMS=350;
var CloseAllMenuItem='nn';
var CurrentMenuItem='';
var sOverColor='#660088';
var sOutColor='#9900CC';
var bSetNavAncestorColor=true;

function sideNavOpenClose(oEleLink,OpenClose){
	//if(OpenClose=='O'){oDEBUG.innerHTML='sideNavOpenClose<br/>';}
	var sEleId=oEleLink.id;
	var oMenuItemHolder=document.getElementById(holdTextName+textNameJoiner+sEleId);
	if(OpenClose=='O'){
		//-----set nav item color when mouse over --------
		oEleLink.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=findElePos(oEleLink);
					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 --------
		oEleLink.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.lastIndexOf('_'));
		oTempEle=document.getElementById(tempEleId);
		if(typeof(oTempEle)=='object'&&oTempEle!=null){
			oTempEle.style.backgroundColor=sColor;
		}
	}
}
//close all nav holder offspring of curentMenuItem - Side Menu
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 findElePos(Ele){
	var left=0;
	var top=0;
	if(Ele.offsetParent){
		left=Ele.offsetLeft;
		top=Ele.offsetTop;
		while(Ele=Ele.offsetParent){
			left+=Ele.offsetLeft;
			top+=Ele.offsetTop;
		}
	}
	return [left,top];
}
// -----END ------ Side Menu - functions for menu - child menu open to right



//--START object for TreeStructure - no HTML strutures
function TreeStructure(){
	//work around - this.construtor.name only works for moz
	this.ConstructorName='TreeStructure';

	this.Init=new Boolean;
	this.RootNode=new Boolean;
	this.SortCode=new String;
	this.Level=new Number;
	this.TreeParentNode;
	this.HasChildren=new Boolean;
	//this.ChildSortCodes=new Array;
	this.TreeChildNodes=new Array;
	
	this.Init=false;
	this.RootNode=false;
	this.TreeParentNode=null;//do not specify as new TreeStructure at this stage - will cause continuous loop when new object created
	this.HasChildren=false;
}
TreeStructure.prototype.CreateTreeNodeByCurrentNode=function(CurrentTreeNode, NewTreeNodeText){
	this.Init=true;
	this.SortCode='';
	this.Level=(NewTreeNodeText.length)-(NewTreeNodeText.replace(/>/g,'').length)+1;
	this.TreeParentNode=new TreeStructure

	//populate title and href
	this.Title=new String;
	this.Href=new String;
	var TitleHref=new String;
	TitleHref=NewTreeNodeText.replace(/>/g,'');
	if(TitleHref!=''){
		this.Title=TitleHref.substr(0,TitleHref.indexOf('~'));
		this.Href=TitleHref.substr(TitleHref.indexOf('~')+1);
	}
	else{
		this.Title='';
		this.Href='#';
	}

	if(!CurrentTreeNode.Init){
		//should only occur for the root node
		this.TreeParentNode=null;
		this.RootNode=true;
		this.Level=0;
	}
	else{
		//assign tree parent node for new node - dependant on CurrentTreeNode
		if(CurrentTreeNode.Level==this.Level-1){
			this.TreeParentNode=CurrentTreeNode;
		}
		else if(CurrentTreeNode.Level==this.Level){
			this.TreeParentNode=CurrentTreeNode.TreeParentNode;
		}
		else{
			var stopLoop=0;
			this.TreeParentNode=CurrentTreeNode;
			while(this.TreeParentNode.Level>=this.Level){
				if(stopLoop>250)break;
				this.TreeParentNode=this.TreeParentNode.TreeParentNode;
				stopLoop++;
			}
		}
	}

	//add TreeChildNodes to TreeParentNode only if TreeParentNode exists and is initilized
	if(this.TreeParentNode!=null&&this.TreeParentNode.Init){
		var cntChildNode=new Number;

		if(!this.TreeParentNode.HasChildren){
			this.TreeParentNode.HasChildren=true;
			cntChildNode=0;
		}
		else{
			//cntChildNode=this.TreeParentNode.ChildSortCodes.length;
			cntChildNode=this.TreeParentNode.TreeChildNodes.length;
		}
		this.SortCode=this.TreeParentNode.SortCode+'.'+(cntChildNode+1);
		//this.TreeParentNode.ChildSortCodes.push(this.SortCode);
		this.TreeParentNode.TreeChildNodes.push(this);
	}


	//this.Title=this.SortCode+' - '+this.Title
}
TreeStructure.prototype.GenerateTreeView=function (ListTreeText){
	var oListTreeView=ListTreeText.split('#~#');
	var oCurrentTreeView=eval('new '+this.ConstructorName);
	this.CreateTreeNodeByCurrentNode(oCurrentTreeView,'')
	oCurrentTreeView=this;
	//loop though ListTreeText to create new tree nodes where parentnode dependant on current node
	for(var i=0;oListTreeView[i];i++){
		//required to use eval to create new object - dependant on constructor type
		//if not and just set to new TreeStructure - when being used by object which inherits from 
		//TreeStructure will not call new object prototypes (etc) only TreeStructure prototypes
		var oTreeStructure=eval('new '+this.ConstructorName);
		oTreeStructure.CreateTreeNodeByCurrentNode(oCurrentTreeView,oListTreeView[i]);
		oCurrentTreeView=oTreeStructure;
	}
}
TreeStructure.prototype.getTreeNodeBySortCode=function(sortCode){
	if(this.SortCode==sortCode)return this;
	if(!this.HasChildren)return null;
	var oTS;
	var i=0;
	for(i=0;this.TreeChildNodes[i];i++){
		oTS=this.TreeChildNodes[i].getTreeNodeBySortCode(sortCode);
		if(oTS!=null){
			return oTS;
			break;
		}
	}
	return null;
}
TreeStructure.prototype.resetSortCode=function(resetFromRootNode){
	var oTS=this;
	if(resetFromRootNode){
		while(!oTS.RootNode){
			oTS=oTS.TreeParentNode;
		}
		//oTS.SortCode='';
	}
	if(!oTS.HasChildren)return;
	var i=0;
	for(i=0;oTS.TreeChildNodes[i];i++){
		oTS.TreeChildNodes[i].SortCode=oTS.SortCode+'.'+(i+1);
		oTS.TreeChildNodes[i].resetSortCode(false);
	}
}



//--END object for TreeStructure - no HTML strutures


//--START object for UL type menu 
//inherits from TreeStructure
ULMenu.prototype=new TreeStructure();
ULMenu.prototype.constructor=ULMenu;
function ULMenu(){
	TreeStructure.call(this);
	this.ConstructorName='ULMenu';
}
ULMenu.prototype.CreateTreeNodeByCurrentNode=function(CurrentTreeNode, NewTreeNodeText){
	TreeStructure.prototype.CreateTreeNodeByCurrentNode.call(this, CurrentTreeNode, NewTreeNodeText);
	
	var linkHref=this.Href.substr(0,this.Href.lastIndexOf('_'));
	var linkTarget=this.Href.substring(this.Href.lastIndexOf('_'));

	//ul html elements	
	this.EleBranch=null;
	this.EleLink=document.createElement('A');
	this.EleLink.setAttribute('title',this.Title);
	this.EleLink.setAttribute('href',linkHref);
	this.EleLink.setAttribute('target',linkTarget);
	this.EleLink.innerHTML=this.Title;

	var oUL=document.createElement('UL');
	var oLI=document.createElement('LI');
	oLI.appendChild(this.EleLink);
	if(this.RootNode){
		this.EleBranch=oUL;
	}
	if(this.TreeParentNode!=null&&this.TreeParentNode.Init){
		if(this.TreeParentNode.RootNode){
			this.TreeParentNode.EleBranch.appendChild(oLI)
		}
		else{
			if(this.TreeParentNode.EleBranch==null){
				oUL.appendChild(oLI)
				this.TreeParentNode.EleBranch=oUL;
				this.TreeParentNode.EleLink.parentNode.appendChild(oUL);
			}
			else{
				this.TreeParentNode.EleBranch.appendChild(oLI);
			}
		}
	}
}
ULMenu.prototype.GenerateTreeView=function(ListTreeText){
	TreeStructure.prototype.GenerateTreeView.call(this, ListTreeText);
}
ULMenu.prototype.getTreeNodeBySortCode=function(sortCode){
//oDEBUG.innerHTML+='START - ULMenu.prototype.getTreeNodeBySortCode:'+this.SortCode+'<br/>'
	var oTS=null;
	oTS=TreeStructure.prototype.getTreeNodeBySortCode.call(this, sortCode);
	if(oTS!=null){
//		oDEBUG.innerHTML+='oTS.SortCode:'+oTS.SortCode+'<br/>';
		return oTS;
	}
//oDEBUG.innerHTML+='END - ULMenu.prototype.getTreeNodeBySortCode:'+this.SortCode+'<br/>'
}
ULMenu.prototype.resetSortCode=function(resetFromRootNode){
	TreeStructure.prototype.resetSortCode.call(this, resetFromRootNode);
//oDEBUG.innerHTML+='this.SortCode:'+this.SortCode+'<br/>';
}
//--END object for UL type menu


//--START object for SIDE type menu
//inherits from TreeStructure
SideMenu.prototype=new TreeStructure();
SideMenu.prototype.constructor=SideMenu;
function SideMenu(){
	TreeStructure.call(this);
	this.ConstructorName='SideMenu';
}
SideMenu.prototype.CreateTreeNodeByCurrentNode=function(CurrentTreeNode, NewTreeNodeText){
	TreeStructure.prototype.CreateTreeNodeByCurrentNode.call(this, CurrentTreeNode, NewTreeNodeText);
	//html elements	
	this.EleTrunk=null;
	this.EleBranch=null;

	var oDiv=document.createElement('DIV');
	oDiv.setAttribute('class','SideNav');
	oDiv.className='SideNav';

	this.EleLink=document.createElement('A');;
	this.EleLink.setAttribute('title',this.Title);
	this.EleLink.setAttribute('href',this.Href);
	this.EleLink.setAttribute('id','link'+this.SortCode.replace(/\./g,'_'));
    if (typeof(this.EleLink.onmouseover)=='object'){
		this.EleLink.onmouseover=function(){sideNavOpenClose(this,'O')};
		this.EleLink.onmouseout=function(){sideNavOpenClose(this,'C')};
	}
	else{
        this.EleLink.setAttribute("onmouseover", "javascript:sideNavOpenClose(this,'O');");
        this.EleLink.setAttribute("onmouseout", "javascript:sideNavOpenClose(this,'C');");
	}
	this.EleLink.innerHTML=this.Title;

	if(this.RootNode){
		this.EleBranch=oDiv;
		this.EleTrunk=document.createElement('DIV');
		this.EleTrunk.setAttribute('class','SideNavContainer');
		this.EleTrunk.className='SideNavContainer';
		this.EleTrunk.appendChild(this.EleBranch);
	}
	if(this.TreeParentNode!=null&&this.TreeParentNode.Init){
		this.EleTrunk=this.TreeParentNode.EleTrunk;

		if(this.TreeParentNode.RootNode){
			this.TreeParentNode.EleBranch.appendChild(this.EleLink)
		}
		else{
			if(this.TreeParentNode.EleBranch==null){
				oDiv.setAttribute('id','holder_link'+this.TreeParentNode.SortCode.replace(/\./g,'_'));
				this.TreeParentNode.EleBranch=oDiv;
				this.TreeParentNode.EleBranch.appendChild(this.EleLink);
				this.EleTrunk.appendChild(this.TreeParentNode.EleBranch);

				var oImg=document.createElement('IMG');
				oImg.setAttribute('src', 'menu_arrow_right.gif');
				this.TreeParentNode.EleLink.insertBefore(oImg, this.TreeParentNode.EleLink.firstChild);
			}
			else{
				this.TreeParentNode.EleBranch.appendChild(this.EleLink);
			}
		}
	}
}
SideMenu.prototype.GenerateTreeView=function(ListTreeText){
	TreeStructure.prototype.GenerateTreeView.call(this, ListTreeText);
}
//--END object for SIDE type menu






function showHideULMenuTreeToggle(MenuTreeId){
	var oMenuTree=document.getElementById(MenuTreeId);
	var oImg;
	var bFirstItem=true;
	for(var i=0;oMenuTree.getElementsByTagName('IMG')[i];i++){
		oImg=oMenuTree.getElementsByTagName('IMG')[i];
		if(oImg.src.indexOf('images/site/menu')>0){
			if(!bFirstItem){
				oImg.onclick();
			}
			else{
				//keep first MenuTree item open
				bFirstItem=false;
			}
		}
	}
}
function genULMenuTree(MenuTreeId,MenuTreeText,execShowHide){
	if(typeof(execShowHide)=='undefined')execShowHide=false;
	var oMenuTree=document.getElementById(MenuTreeId);
	oMenuTree.innerHTML='';
	var oTreeStructure=new ULMenu();
	oTreeStructure.GenerateTreeView(MenuTreeText)
	oMenuTree.appendChild(oTreeStructure.EleBranch);
	ulTreeView(oTreeStructure.EleBranch);
	if(execShowHide)showHideULMenuTreeToggle(MenuTreeId);
}




//-----------------------------------------------------------

function goto_nav(othis, sNavIdentifier, sHash, sQry, sWadiOverride){
//alert('goto_nav');
	//-----sNavIdentifier should be the navaka
	if(typeof(sQry)!='string')sQry='';
	if(typeof(sWadiOverride)!='string')sWadiOverride='';
	//alert('in goto_nav');
	sHash=(typeof(sHash)=='string')?'&hash='+sHash:'';
	var sWadi='';
	if(sWadiOverride==''){
		sWadi=document.location.search;
		if(sWadi.length==0){
			sWadi=document.forms[0].action;
			sWadi=sWadi.substring(sWadi.indexOf('?'));
		}
	}
	else{
		sWadi='?wadi='+sWadiOverride;
	}
	//var oCal=document.getElementById('auctRightMenu_auctCalendar_minical');
	//var sMinicaldisplaytype=(oCal.style.display=='block')?'&minicaldisplaytype=block':'';;
	var sPath='http://'+document.location.host
	//if(document.location.href.indexOf('sra.aleppoworld')==-1){sPath+='/adrc_sra'}
	if(document.location.href.indexOf('/'+appPath+'/')>0){sPath+='/'+appPath}
	//sPath+='/page/p13sendto.aspx'+sWadi+'&nav='+sNavIdentifier+sMinicaldisplaytype+sHash;
	//sPath+='/page/p13sendto.aspx'+sWadi+'&nav='+sNavIdentifier+sQry+sHash;
	sPath+='/SiteAccess/SendTo.aspx'+sWadi+'&nav='+sNavIdentifier+sQry+sHash;
//	alert(sPath);
	//document.location.href=sPath;
	othis.href=sPath;
}
// __________________________________________________________________________________________________________________

function goto_nsdisplay(othis, sNSDisplay, sHash){
	//alert('in goto_nsdisplay');
	sHash=(typeof(sHash)=='string')?'&hash='+sHash:'';
	var sWadi='';
	sWadi=document.location.search;
	if(sWadi.length==0){
		sWadi=document.forms[0].action;
		sWadi=sWadi.substring(sWadi.indexOf('?'));
	}
	//var oCal=document.getElementById('auctRightMenu_auctCalendar_minical');
	//var sMinicaldisplaytype=(oCal.style.display=='block')?'&minicaldisplaytype=block':'';;
	var sPath='http://'+document.location.host
	if(document.location.href.indexOf('/'+appPath+'/')>0){sPath+='/'+appPath}
	sPath+=sNSDisplay+sWadi+sHash;
	//alert(sPath);
	//document.location.href=sPath;
	othis.href=sPath;
}
// __________________________________________________________________________________________________________________


//-------------------- START Used For Static Site Navigation --------------------
var siteMapXmlDocLoaded=false;
var siteMapXmlDoc;
function importSiteMapXML(subRoot){
	if(!siteMapXmlDocLoaded){
		var xmlFileName=subRoot+'common/sitemap.xml'
		if (document.implementation&&document.implementation.createDocument){
			siteMapXmlDoc=document.implementation.createDocument("","",null);
			siteMapXmlDoc.onload=siteMapXmlLoaded;
		}
		else if (window.ActiveXObject){
			siteMapXmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			siteMapXmlDoc.onreadystatechange=function () {
				if (siteMapXmlDoc.readyState==4) siteMapXmlLoaded()
			};
		}
		else{
			alert('XML not loaded - browser can not handle loading.');
			return;
		}
		siteMapXmlDoc.load(xmlFileName);
	}
}
// __________________________________________________________________________________________________________________

function siteMapXmlLoaded(){siteMapXmlDocLoaded=true;}
// __________________________________________________________________________________________________________________

function goto_nav_static(subRoot, othis, navaka, hash){
	if(!siteMapXmlDocLoaded){importSiteMapXML(subRoot)}

	var oAka=siteMapXmlDoc.getElementsByTagName('aka');
	var oNSDisplay=siteMapXmlDoc.getElementsByTagName('nsdisplay');

	for(i=0;oAka[i];i++){
		if(oAka[i].firstChild.nodeValue==navaka){
			hash=(typeof(hash)=='string'&&hash!='')?'#'+hash:'';
			//var path=oNSDisplay[i].firstChild.nodeValue+'.htm'
			var path=oNSDisplay[i].firstChild.nodeValue
			othis.href=subRoot+path.substr(1)+hash;
			break;
		}
	}
}
//-------------------- END Used For Static Site Navigation --------------------



