
var vMode = document.documentMode; 
var rMode = 'Unknown';
/*
var vMode = document.documentMode;
var rMode = 'IE5 Quirks Mode';
if(vMode == 8){
  rMode = 'IE8 Standards Mode';
} else if(vMode == 7){
  rMode = 'IE7 Strict Mode';
}
alert('Rendering in: ' + rMode);
*/
/*alert('Page was rendered in (' + vMode + ') ' + ((document.compatMode == 'CSS1Compat') ? 'Standards' : 'Quirks') + ' Mode.');*/



var minPage = 0
var maxPage = 0
var curPage = 0
var pageList
var gotControls = false
var curZoom = 'view=FitH'
var inVideo = false

var curTab = 1
var lastDisplayedTabPage = "0,0".split(',')
var lastDisplayedTabVideo = "nope,nope".split(',')

var loadedFully = false

function ajaxSync($url, $vars){
    if (window.XMLHttpRequest){ var $class = new XMLHttpRequest(); } else { var $class = new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
    $class.open("POST", $url, false);
    $class.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    $class.send($vars);
    return $class.responseText;
}

function switchTab(){
	var pg = ",menuf,menuf_felo".split(',')[curTab]
	window.top.frames['menuF'].location.href = pg + '.htm'
}

function configPage(){
	var pgList = ",fetchPages,fetchPages_felo".split(',')[curTab]
	var v = ajaxSync('db/' + pgList + '.asp','')
	pageList = v.split('!')
	for (var i=0; i<pageList.length; i++){ pageList[i] = pageList[i].toString().toLowerCase() }
	minPage = 1
	maxPage = pageList.length - 1
	if (!loadedFully){
		if (gotControls){ ML(pageList[0],0,0) }
		loadedFully = true
	} else {
		if (lastDisplayedTabVideo[curTab-1] != 'nope'){
			videoPage(lastDisplayedTabVideo[curTab-1],2,0)
		} else {
			if (lastDisplayedTabPage[curTab-1].toString() == '0'){
				ML(pageList[0],0,0)
			} else {
				ML(lastDisplayedTabPage[curTab-1],0,0)
			}
		}
	}
}

function controlsPage(){
	gotControls = true
	if (minPage > 0){ ML(pageList[0],0,0) }
}

function prevPage(){
	if (curPage == 0){return true}
	if (curPage > minPage){
		curPage--
		navPage(pageList[curPage-1])
	}
}

function nextPage(){
	if (curPage == 0){return true}
	if (curPage < maxPage){
		curPage++
		navPage(pageList[curPage-1])
	}
}

function reloadCurrentPage(){
	navPage(pageList[curPage-1])
}

function changeMag(e){
	curZoom = e.value
	window.top.frames['contentF'].location.href = 'blank.htm'
}

function setPrevNext(){
	var d = window.top.frames['menuC'].document.getElementById('pageBack')
	var s = d.src.toString().toLowerCase()
	if ((curPage == minPage) || (curPage == 0)){
		if (s.indexOf('larrow.') > -1){ d.src = 'graphics/larrowg.gif'; d.className = 'grayImg'; }
	} else {
		if (s.indexOf('larrowg.') > -1){ d.src = 'graphics/larrow.gif'; d.className = 'arrowImg'; }
	}
	d = window.top.frames['menuC'].document.getElementById('pageForward')
	s = d.src.toString().toLowerCase()
	if ((curPage == maxPage) || (curPage == 0)){
		if (s.indexOf('rarrow.') > -1){ d.src = 'graphics/rarrowg.gif'; d.className = 'grayImg'; }
	} else {
		if (s.indexOf('rarrowg.') > -1){ d.src = 'graphics/rarrow.gif'; d.className = 'arrowImg'; }
	}
	if (curPage == 0){
		window.top.frames['menuC'].document.getElementById('pgCounter').innerHTML = ''
	} else {
		window.top.frames['menuC'].document.getElementById('pgCounter').innerHTML = 'Page ' + curPage.toString() + ' of ' + maxPage.toString()
	}
}

function navPage(n){
//	curPage = n
	lastDisplayedTabVideo[curTab-1] = 'nope'
	lastDisplayedTabPage[curTab-1] = n
	var pdfPath = ",catalog_pgs,catalog_felo".split(',')[curTab]
	var pdfString = pdfPath + '/' + n.toString() + '.pdf#toolbar=0&statusbar=0&messages=0&navpanes=0&pagemode=none&scrollbar=1&' + curZoom
	window.top.frames['contentF'].location.href = pdfString
	setPrevNext()
	window.top.frames['menuC'].document.getElementById('menuCTable').style.visibility = 'visible'
}

function highlightMenu(theSection, theSubmenu){
	var d = window.top.frames['menuF'].document
	var s
	for (var i=0; i<20; i++){
		try {
			s = d.getElementById('prod' + i.toString())
			if (i==theSection){
				if (document.all){s.style.display = 'block'} else {s.style.display = 'table-row'}
			} else {
				s.style.display = 'none'
			}
		} catch(e) {}
	}
	
	s = d.getElementsByTagName('img')
	for (var i=0; i<s.length; i++){
		if (s[i].src.toString().indexOf('mared.gif') > -1){ s[i].src = 'graphics/mablue.gif' }
	}
	
	s = d.getElementsByTagName('a')
	for (var i=0; i<s.length; i++){
		if (s[i].className.toString() == 'leftMenuAH'){ s[i].className = 'leftMenuA' }
	}
	
	if (theSubmenu == 0){
		d.getElementById('leftMenu' + theSection.toString()).src = 'graphics/mared.gif'
		d.getElementById('leftMenu' + theSection.toString() + 'A').className = 'leftMenuAH'
	} else {
		d.getElementById('prod' + theSection.toString() + 's' + theSubmenu.toString()).src = 'graphics/mared.gif'
		d.getElementById('prod' + theSection.toString() + 's' + theSubmenu.toString() + 'A').className = 'leftMenuAH'
	}

}

function videoPage(theVid, theSection, theSubmenu){
	lastDisplayedTabVideo[curTab-1] = theVid
	highlightMenu(theSection, theSubmenu)
	window.top.frames['menuC'].document.getElementById('menuCTable').style.visibility = 'hidden'
	var vString = 'vpage.asp?v=' + theVid
	window.top.frames['contentF'].location.href = vString
	inVideo = true
}

function locateCurPage(thePage){
	var rv = 0
	for (var i=0; i<pageList.length-1; i++){ if (thePage.toString().toLowerCase() == pageList[i]){rv=i+1} }
	return rv
}

function ML(thePage, theSection, theSubmenu){
	highlightMenu(theSection, theSubmenu)
	curPage = locateCurPage(thePage)
	if (inVideo){ 
		inVideo = false
		window.top.frames['contentF'].location.href = 'blank.htm'
	} else { navPage(thePage) }	
}

function fetchInnerSize(){
	var frameWidth = 0
	var frameHeight = 0
	if (self.innerWidth){
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else return "0,0";
	return frameWidth.toString() + ',' + frameHeight.toString()
}

function centerWindow(){
	if (loadedFully){ return true }
	var s = fetchInnerSize().split(',')
	parent.window.resizeTo(300,400)
	var c = fetchInnerSize().split(',')
	var newW = parseInt(s[0],10) + (300 - parseInt(c[0],10))
	var newH = parseInt(s[1],10) + (400 - parseInt(c[1],10))
	parent.window.resizeTo(newW,newH)
	var locX = Math.round((self.screen.width - newW) / 2)
	var locY = Math.round((self.screen.height - newH) / 2)
	parent.window.moveTo(locX, locY);
	window.focus()
}

function lookupPart(){
	var d = window.top.frames['pnLU'].document.getElementById('pnField')
	var v = parseInt(d.value,10)
	var pn = ajaxSync('db/pnlookup.asp','pn=' + escape(v.toString().toLowerCase()))
	if (pn == 'nope'){
		pn = ajaxSync('db/pnlookup_felo.asp','pn=' + escape(v.toString().toLowerCase()))
		if (pn == 'nope'){
		} else {
			if (curTab == 2){
				curPage = locateCurPage(pn)
				navPage(pn)
			} else {
				lastDisplayedTabPage[1] = pn
				lastDisplayedTabVideo[1] = 'nope'
				clickFeloTab()
			}
		}
	} else {
		if (curTab == 1){
			curPage = locateCurPage(pn)
			navPage(pn)
		} else {
			lastDisplayedTabPage[0] = pn
			lastDisplayedTabVideo[0] = 'nope'
			clickBondhusTab()
		}
	}
	d.focus()
}

function highlightTab(w){
	var tabSrcG = 'bondhus,felo'.split(',')
	var refItem
	for (var i=1; i<3; i++){
		refItem = window.top.frames['menuT'].document.getElementById('tab' + i.toString())
		if (w==i){
			refItem.style.zIndex = 2
			refItem.src = 'graphics/tab_' + tabSrcG[i-1] + '.gif'
		} else {
			refItem.style.zIndex = 1
			refItem.src = 'graphics/tab_' + tabSrcG[i-1] + '_un.gif'
		}
	}
}

function clickBondhusTab(){
	if (curTab != 1){
		inVideo = false
		curTab = 1
		highlightTab(1)
		switchTab()
	}
}

function clickFeloTab(){
	if (curTab != 2){
		inVideo = false
		curTab = 2
		highlightTab(2)
		switchTab()
	}
}



