if(!window.saveInnerWidth) {
  window.onresize = resize;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resize() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        //window.history.go(0);
    }
}


// begin render functions
var aMenu = new Array()

function oConstruct(iPermission,iParent,iID,sText,sURL,sTarget) {
	this.sText = sText
	this.sURL = sURL
	this.iID = iID
	this.iParent = iParent
	this.iPermission = iPermission
	this.sTarget = sTarget
}

function oMenu(iPermission,iParent,iID,sText,sURL,sTarget) {
  var currentEntry = aMenu.length
  aMenu[currentEntry] = new oConstruct(iPermission,iParent,iID,sText,sURL,sTarget)
}

var MenuContent = ''	

var iIndention = 0
function constructMenu(icheckID){
	for (var i in aMenu){
		if (aMenu[i].iParent == icheckID){
			
			writeMenuString(i,icheckID,iIndention)
			
			iNextcheckID = aMenu[i].iID

			for (var j in aMenu){
				if (aMenu[j].iParent == iNextcheckID){
					iIndention += 1
					constructMenu(iNextcheckID)
					iIndention -= 1
				}
				
			}
		}
	}
}

var iPageExpansionID = null

function writeMenuString(i,icheckID,iIndent2){
var iIndent = new String(aMenu[i].iParent)
var sIndent = ''
	if (icheckID==null){
		sClass = 'main'
		iIndent = 0
	}
	else {
		sClass = 'main'
		for (k=0; k < iIndent2; k++){
			sIndent += '<td valign="top" width="5"><img src="' + dBack + 'images/pixel.gif" width="7" height="1" alt="" border="0"></td>'		
		}
	}
	
	if (aMenu[i].sURL!=''){
		var sTestURL = new String(aMenu[i].sURL)
			//sTestURL = sTestURL.substring(0,3)
	
		if (sTestURL.indexOf('../')!=-1){
			aMenu[i].sURL = sTestURL.substring(3,aMenu[i].sURL.length)
		}
		
		if (checkPageURL(i)){
			//var sLinkClass ='linkMenuTarget'
			iPageExpansionID = aMenu[i].iParent
			var sLinkClass ='linkMenu'
		}
		else{
			var sLinkClass ='linkMenu'
		}
		
	iTotalColspan = (isNaN(iIndent2))?3:(iIndent2 + 3);
	sURL = (aMenu[i].sURL)?dBack + '' + aMenu[i].sURL:'javascript: expand(\'' + aMenu[i].iID + '\');'
	sTarget = (aMenu[i].sURL)?'_top':'_self'
	sArrow = (aMenu[i].sURL)?'pixel':'arrow_blue'
	sImageName = (aMenu[i].sURL)?'pixel':'exArrow'
	
	if (aMenu[i].sTarget){
		
		if (aMenu[i].sTarget=='popup'){
			sURL = 'javascript: openNewWindow(\'' +dBack + '' + aMenu[i].sURL + '\');'
		}
		else {
			sTarget = aMenu[i].sTarget
		}
	}
	
			MenuContent += '<div class="' + sClass + '" id="exMenu' + aMenu[i].iID + '">'
			MenuContent += '<table border="0" cellpadding="0" cellspacing="0" width="155">'
			MenuContent += '<tr>'
			MenuContent += '<td valign="top" class="tdbgColor" rowspan="2"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
			MenuContent += '<td valign="top" align="center" width="155" colspan="' + iTotalColspan + '"><img src="' + dBack + 'images/GUI/dotted_line_menu.gif" width="145" height="1" alt="" border="0" vspace="2"></td>'
			MenuContent += '<td valign="top" class="tdbgColor" rowspan="2"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
			MenuContent += '</tr>'
			MenuContent += '<tr>'
			MenuContent += '<td valign="top" width="5"><img src="' + dBack + 'images/pixel.gif" width="5" height="1" alt="" border="0"></td>'
			MenuContent += sIndent
			MenuContent += '<td valign="top" width="5"><a href="' + sURL + '" onFocus="blur();" target="_top"><img src="' + dBack + 'images/GUI/' + sArrow + '.gif" width="7" height="7" alt="" name="' + sImageName + '' + aMenu[i].iID + '" border="0" hspace="2" vspace="2"></a></td>'
			MenuContent += '<td valign="top" width="155"><a href="' + sURL + '" class="' + sLinkClass + '" onFocus="blur();" target="' + sTarget + '">' + aMenu[i].sText + '</a></td>'
			MenuContent += '</tr>'
			MenuContent += '</table>'
			MenuContent += '</div>'
	}
	else {
		MenuContent += '<div class="' + sClass + '" id="exMenu' + aMenu[i].iID + '">'
		MenuContent += aMenu[i].sText
		MenuContent += '</div>'
	}
}

// end render functions

function expandParents(){
	for (var i in aMenu){
		if (aMenu[i].iParent == null){
			if (i==0){
			alignToImg("imgMenu","exMenu" + aMenu[i].iID,3,0)
			sTopLayer = "exMenu" + aMenu[i].iID
			showLayer("exMenu" + aMenu[i].iID)
			rotateArrowUp(aMenu[i].iID)
			}
			else {
				moveLayerTo("exMenu" + aMenu[i].iID, getLayerLeft(sTopLayer), getLayerBottom(sTopLayer))
			 	showLayer("exMenu" + aMenu[i].iID)
				sTopLayer = "exMenu" + aMenu[i].iID
				rotateArrowUp(aMenu[i].iID)
			}
		}
		else {
		hideLayer("exMenu" + aMenu[i].iID)
		
		}
	
		if (aMenu[i].iID == icurrentcheckID){
			var icurrentcheckParent = aMenu[i].iParent
		}
	}
	
	if (!bCheckURL && iPageExpansionID!=null){
		//alert(iPageExpansionID)
		
		//setTimeout('expand('+iPageExpansionID+')',1000)
		/*icurrentcheckID = iPageExpansionID
		bCheckURL = true
		*/
	}
	
}

var icurrentcheckID = null

function expand(icheckID){
		if (icurrentcheckID!=null){
			if (icheckID == icurrentcheckID){
				//rotateArrowUp(icurrentcheckID)
				expandParents()
			}
			else {
				rotateArrowUp(icurrentcheckID)
				expandParents()
			}
		}
		if (icheckID==null){
			if (aExpansionSet==''){expandParents()}
			stepIn()
		}
		else {
			for (var i in aMenu){
				if (aMenu[i].iID == icheckID){
				createExpansionSet(i)
				break
				}
			}
		}
		
	rotateArrowDown(icheckID)
				
 	icurrentcheckID = icheckID
	
}


var aExpansionSet = new Array()

function createExpansionSet(iSelectedID){
		aExpansionSet[aExpansionSet.length] = iSelectedID
		expand(aMenu[iSelectedID].iParent)
}

function stepIn(){
var iHeight = 0
var iLeft = 0
var iNextStart = 0
	for (j = aExpansionSet.length-1; j >= 0; j--){
		sTopLayer = "exMenu" + aMenu[aExpansionSet[j]].iID
		iSiblings = aMenu[aExpansionSet[j]].iParent		
		// move children
		for (var i in aMenu){
			
			if (aMenu[i].iParent == aMenu[aExpansionSet[j]].iID){				
				if (i==0){
					alignToImg("imgMenu","exMenu" + aMenu[i].iID,3,0)
					sTopLayer = "exMenu" + aMenu[i].iID
					showLayer("exMenu" + aMenu[i].iID)
					//iHeight += getLayerHeight(sTopLayer)
				}
				else {
					moveLayerTo("exMenu" + aMenu[i].iID, getLayerLeft(sTopLayer), getLayerBottom(sTopLayer))
				 	showLayer("exMenu" + aMenu[i].iID)
					sTopLayer = "exMenu" + aMenu[i].iID
					iNextStart = i
					//iHeight += getLayerHeight(sTopLayer)
				}
			}
		}
		//alert(iHeight)
		for (i=iNextStart; i < aMenu.length; i++){
			if (aMenu[i].iParent == iSiblings){
				//moveLayerBy("exMenu" + aMenu[i].iID, 0, iHeight)
				moveLayerTo("exMenu" + aMenu[i].iID, getLayerLeft(sTopLayer), getLayerBottom(sTopLayer))
				showLayer("exMenu" + aMenu[i].iID)
				sTopLayer = "exMenu" + aMenu[i].iID
				
			}
			else {
			 //if not top parent move parent's siblings again
				if (j != aExpansionSet.length-1 && aMenu[i].iParent == aMenu[aExpansionSet[j+1]].iParent){
					//moveLayerBy("exMenu" + aMenu[i].iID, 0, iHeight)
					moveLayerTo("exMenu" + aMenu[i].iID, getLayerLeft(sTopLayer), getLayerBottom(sTopLayer))
					showLayer("exMenu" + aMenu[i].iID)
					sTopLayer = "exMenu" + aMenu[i].iID
					//jCount ++
				}
			}
		}
	}
	checkHeight()
	
	aExpansionSet.length = 0
}



function contract(icheckID){
	if (icheckID!=null){
		for (var i in aMenu){
			if (aMenu[i].iParent == icheckID){
			
			hideLayer("exMenu" + aMenu[i].iID)
			}
		}
		expandParents()
	}
}

function rotateArrowDown(icheckID){
	if (document.layers && document.layers['exMenu' + icheckID]){
		document.layers['exMenu' + icheckID].document.images['exArrow' + icheckID].src = dBack + 'images/GUI/arrow_blue_down.gif'
	}
	if (document.all && document.images['exArrow' + icheckID]){
		document.images['exArrow' + icheckID].src = dBack + 'images/GUI/arrow_blue_down.gif'
	}
}

function rotateArrowUp(icheckID){
	if (document.layers && document.layers['exMenu' + icheckID]){
		if (document.layers['exMenu' + icheckID].document.images['exArrow' + icheckID]){
			document.layers['exMenu' + icheckID].document.images['exArrow' + icheckID].src = dBack + 'images/GUI/arrow_blue.gif'
		}
	}
	if (document.all && document.images['exArrow' + icheckID]){
		document.images['exArrow' + icheckID].src = dBack + 'images/GUI/arrow_blue.gif'
	}
}


function expandAll(){
	for (var i in aMenu){
		if(i!=0) {
			moveLayerTo("exMenu" + aMenu[i].iID, getLayerLeft(sTopLayer), getLayerBottom(sTopLayer))
			showLayer("exMenu" + aMenu[i].iID)
			sTopLayer = "exMenu" + aMenu[i].iID
		}
		else {
			alignToImg("imgMenu","exMenu" + aMenu[i].iID,3,0)
			showLayer("exMenu" + aMenu[i].iID)
			sTopLayer = "exMenu" + aMenu[i].iID
		}
	}
	checkHeight()
}

function checkHeight(){
	if (document.layers){		
		iLayerHeight = (document.layers["exMenu" + aMenu[aMenu.length-1].iID].y + document.layers[aMenu.length-1].document.height)
		if (iLayerHeight > document.height){
			document.height = iLayerHeight + 10
		}
	}
}

var bCheckURL = false

var sPageHref = location.href

if (sPageHref.indexOf('?')!=-1){
	var iEndString = sPageHref.indexOf('?')
	sPageHref = sPageHref.substring(0,iEndString)
}



function checkPageURL(iSelected){	
	var sTestString = new String(aMenu[iSelected].sURL)
	var iTestEndString = sTestString.indexOf('?')
		sTestString = sTestString.substring(0,iTestEndString)
	
	if (sPageHref.indexOf(sTestString)!=-1){
		return true
	}
	else {return false}


/*
	if (!bCheckURL){
	var sPageHref = location.href

	if (sPageHref.indexOf('?')!=-1){
		var iEndString = sPageHref.indexOf('?')
			sPageHref = sPageHref.substring(0,iEndString)
	}

	
	for (i=0; i < aMenu.length; i++){
		var sTestString = new String(aMenu[i].sURL)
		var iTestEndString = sTestString.indexOf('?')
			sTestString = sTestString.substring(0,iTestEndString)
		
		if (sPageHref.indexOf(sTestString)!=-1){
			
			expand(aMenu[i].iParent)
			break
		}
	}
	bCheckURL = true
	}
*/
}

var sMenuHeader = '<table border="0" cellpadding="0" cellspacing="0" width="155">'
	sMenuHeader += '<tr>'
	sMenuHeader += '<td width="49"><img src="' + dBack + 'images/GUI/upper_left.gif" width="49" height="22" alt="" border="0"></td>'
	sMenuHeader += '<td width="119" class="menuHeader">MENU</td>'
	sMenuHeader += '</tr>'
	sMenuHeader += '</table>'
	sMenuHeader += '<table border="0" cellpadding="0" cellspacing="0" width="155">'
	sMenuHeader += '<tr>'
	sMenuHeader += '<td valign="top" class="tdbgColor"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
	sMenuHeader += '<td><img src="' + dBack + 'images/pixel.gif" width="153" height="6" alt="" border="0"></td>'
	sMenuHeader += '<td valign="top" class="tdbgColor"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
	sMenuHeader += '</tr>'
	sMenuHeader += '</table>'

var sMenuFooter = '<table border="0" cellpadding="0" cellspacing="0" width="155">'
	sMenuFooter += '<tr>'
	sMenuFooter += '<td width="21"><img src="' + dBack + 'images/GUI/bottom_left_diag.gif" width="21" height="20" alt="" border="0"></td>'
	sMenuFooter += '<td width="155"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
	sMenuFooter += '<td class="tdbgColor"><img src="' + dBack + 'images/pixel.gif" width="1" height="1" alt="" border="0"></td>'
	sMenuFooter += '</tr>'
	sMenuFooter += '</table>'
	sMenuFooter += '<table border="0" cellpadding="0" cellspacing="0" width="155">'
	sMenuFooter += '<tr>'
	sMenuFooter += '<td><img src="' + dBack + 'images/pixel.gif" width="21" height="1" alt="" border="0"></td>'
	sMenuFooter += '<td class="tdbgColor"><img src="' + dBack + 'images/pixel.gif" width="134" height="1" alt="" border="0"></td>'
	sMenuFooter += '</tr>'
	sMenuFooter += '</table>'

function OpenWindow(url,iW,iH) {
	var iHeight = (iH)?iH:500
	var iWidth = (iW)?iW:500
	
		popWin = window.open(url,"win","scrollbars,resizable,width="+iWidth+",height="+iHeight+",top=100,left=175");
}

function openNewWindowSized(sURL, iWidth, iHeight) {
	var sLink = sURL
	var objWin = window.open(sLink, "newwin", "toolbars=no,menubar=no,status=no,scrollbars,resizable,width=" + iWidth + ",height=" + iHeight + ",top=100,left=100"); 
	objWin.focus();
}

function pageJump (iResultSet, iMax, iRecordIndex, sDirect, sForm) {
	var iTmp; 
	var iJump = parseInt(document.forms[ sForm ].elements['iPageJump'].value); 
	switch (sDirect) {
		case 'next':
			iTmp = (parseInt(iResultSet) + 1);
			break;
		case 'prev':
			iTmp = iResultSet - 1;
			break;
		case 'jump':
			if (isNaN(iJump)) {
			   //alert('NaN yo, NaN.');
			   //return;
			   iJump = 1;
			}
			else if (iJump <= 0) { 
			   //alert('You must enter a positive integer for a page.');
			   //return;
			   iJump = 1;
			} 
			else if (iJump > iMax) {
			   //alert('You must enter a page number within the proper range.');
			   //return;
			   iJump = iMax;
			} 
			iTmp = iJump;
			break;
	}
	document.forms[ sForm ].elements['iResultSet'+iRecordIndex].value = iTmp; 
	document.forms[ sForm ].submit(); 
}

 function surfto(form) {
	var myindex=form.select1.selectedIndex
	if (form.select1.options[myindex].value != "0") {
	 location=form.select1.options[myindex].value;}
}
