// BEGIN platform/browser/version check
Win = false;
Mac = false;
IE = false;
NS = false;
version = false;
browser = false;

ua = navigator.userAgent;

var before_parentheses = "";
var in_parentheses = "";

i = ua.indexOf("(");
if (i >= 0) {
	before_parentheses = stringTrim(ua.substring(0,i));
	in_parentheses = ua.substring(i+1, ua.length);
	j = in_parentheses.indexOf(")");
	if (j >= 0) {
       	in_parentheses = in_parentheses.substring(0, j);
	}
} else {
	before_parentheses = ua;
}

var browser = before_parentheses;

var parts = in_parentheses.split(";");
var part = "";
for (var i=0; i < parts.length; i++) {
	part = stringTrim(parts[i]);
	if (part.indexOf("MSIE") >= 0) {
		browser = part;
	} else if (part.indexOf("Win") >= 0) {
		Win = true;
	} else if ((part.indexOf("Mac") >= 0) || (part.indexOf("PPC") >= 0)) {
		Mac = true;
	}
}

var IE_index = browser.indexOf("MSIE");
if (IE_index >= 0) {
	browser = browser.substring(IE_index, browser.length);
}

var leftover = "";
if (browser.substring(0, "Mozilla".length) == "Mozilla") {
	NS = true;
	leftover = browser.substring("Mozilla".length+1, browser.length);
} else if (browser.substring(0, "MSIE".length) == "MSIE") {
	IE = true;
	leftover = browser.substring("MSIE".length+1, browser.length);
} else if (browser.substring(0, "Microsoft Internet Explorer".length) ==
"Microsoft Internet Explorer") {
	IE = true;
	leftover = browser.substring("Microsoft Internet Explorer".length+1,
browser.length);
}

leftover = stringTrim(leftover);
i = leftover.indexOf(" ");
if (i >= 0) {
	version = parseInt(leftover.substring(0, i));
} else {
	version = parseInt(leftover);
}
/*if ((NS || IE) && (Mac || Win) && (version >= 4)) browser = true;
else { 
	top.document.location = '/error.html';
	browser = false;
}
*/
// END platform/browser/version check

function getStyle() {
	if (Mac && IE) 
		return 'mac_ie';
		
	if (Mac) 
		return 'mac_ns';
		
	if (IE) 
		return 'win_ie';
		
	return 'win_ns';
}

var show = 'show';
var hide = 'hide';

if (IE) { // Internet Explorer

	show = 'visible'; // layer surrogates
	hide = 'hidden';
		
} else { // Netscape

	// correct various resizing bugs in Netscape
	function fixNS() {
		if (document.fix.initWindowWidth != window.innerWidth || document.fix.initWindowHeight != window.innerHeight) {
			document.location = document.location;
		}
	}

	function fixNSCheck() {
		if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
		    if (typeof document.fix == 'undefined'){
				document.fix = new Object;
			}
			document.fix.initWindowWidth = window.innerWidth;
			document.fix.initWindowHeight = window.innerHeight;
			window.onresize = fixNS;
		}
	}
	fixNSCheck();
}

// get rid of evil frames
if (top != self) { 
	top.location = self.location; 
}

function checkPath(which) {
	if (typeof which != "undefined" && which.indexOf(".") < 0) return true;
	else return false
}
	
// trim spaces from both ends of a string
function stringTrim(it) {
	var return_value = "";
	var start = 0;
	while ((start < it.length) && (it.charAt(start) == ' ')) {
		++start;
	}
	var end = it.length;
	while ((end > 0) && (it.charAt(end - 1) == ' ')) {
		--end;
	}
	return_value = it.substring(start, end);
	return return_value;
}

// define the current section based on the page's URL
current_location = window.location.pathname;
current_page = current_location.substring((current_location.lastIndexOf("/") + 1),current_location.lastIndexOf(".html")); // current_page 
current_path = new Array();
current_path = current_location.split('/');
current_header = "home";
current_section = current_page;
current_subsection = false;
if (checkPath(current_path[1])) {
	current_header = current_path[1]; // current_header
}
if (current_page.indexOf('_') > -1) {
	current_section = current_page.substring(0,current_page.indexOf('_'));
	current_subsection = current_page;
}

preload_flag = false;

// this function creates a new image and returns its number
function nameImage(path) {
	result = new Image();
	result.src = path;
	return result;
}

var last_img = false, last_nav = false;

// this function deals with an onMouseOver event	
function imgOver(which) { 
	if (preload_flag) {
		if (eval('document.' + which)) {
			if (last_img) {
				imgOut(last_img); 
			}
			eval('document.' + which).src = eval('img_' + which + '_over').src;
			last_img = which;
		}
	}
}

// this function deals with an onMouseOut event	
function imgOut(which) {
	if (preload_flag) {
		if (eval('document.' + which)) {
			if (which != current_header && which != current_section && which != current_subsection) {
				eval('document.' + which).src = eval('img_' + which).src;
			}
			last_img = false;
		}
	}
}

lay_top = new Array();
layer_number = 0;

// initialize a surrogate name for referencing a layer
function nameLayer(which) {
	if (IE) {
		for (i = 0; i < document.styleSheets[0].rules.length; i++) {
			if (document.styleSheets[0].rules[i].selectorText == '#' + which) {
				which = document.styleSheets[0].rules[i].style;
			}
		}
	} else {
		which = document.layers[which];
	}
	lay_top[layer_number++] = which.top;
	return which;
}	

// set up surrogate names for all layers and create the "eyes front" variable

layer_flag = false;
function setupLayers() {
	lay_ag = nameLayer('AGHEAD');
	lay_ag_over = nameLayer ('AGOVER');
	lay_ag_ff = nameLayer('AGFF');
	lay_ag_bw = nameLayer('AGBW');
	lay_ag_hfs = nameLayer('AGHFS');
	lay_ag_pp = nameLayer('AGPP');
	lay_ag_swp = nameLayer('AGSWP');
	lay_ag_wwf = nameLayer('AGWWF');
	lay_bp = nameLayer('BPHEAD');
	lay_bp_over = nameLayer('BPOVER');
	lay_bp_bp = nameLayer('BPBP');
	lay_bp_dwc = nameLayer('BPDWC');
	lay_bp_llw = nameLayer('BPLLW');
	lay_bp_sn = nameLayer('BPSN');
	lay_bp_wwfl = nameLayer('BPWWFL');
	lay_iw = nameLayer('IWHEAD');
	lay_iw_over = nameLayer('IWOVER');
	lay_iw_sw = nameLayer('IWSW');
	lay_iw_ww = nameLayer('IWWW');
	lay_rp = nameLayer('RPHEAD');
	lay_rp_over = nameLayer('RP');
	lay_rem = nameLayer('REMHEAD');
	lay_rem_over = nameLayer('REM');
	lay_grad = nameLayer('GRAD');
	ag_height = 87;
	bp_height = 74;
	iw_height = 35;
	rp_height = 0;
	rem_height = 0;
	lays = new Array('ag', 'ag_ff', 'ag_bw', 'ag_hfs', 'ag_pp', 'ag_swp', 'ag_wwf', 'ag_over', 'bp', 'bp_bp', 'bp_dwc', 'bp_llw', 'bp_sn', 'bp_wwfl', 'bp_over', 'iw', 'iw_sw', 'iw_ww', 'iw_over', 'rp', 'rp_over', 'rem', 'rem_over', 'grad')
	layer_flag = true;
}

last_lay = false;
function layOver(which) {
	if (layer_flag) {
		if (last_lay) {
			layOut(last_lay);
		}
		eval('lay_' + which + '_over').visibility = show;
		layMove(which,eval(which + '_height'));
		last_lay = which;
		timerCheck();
	}
}

function layOut(which) {
	if (layer_flag) {
		if (which != current_section) {
			if (last_nav && last_nav != current_subsection) {
				navOut(last_nav);
			}
			eval('lay_' + which + '_over').visibility = hide;
			layMove(which,-eval(which + '_height'));
			last_lay = false;
		}
	}
}

function layMove(which,much) {
	if (which != 'rp' && which != 'rem') {
		for (i = 0; i < lays.length; i++) {
			if (lays[i] == which + '_over') {
				for (j = i + 1; j < lays.length; j++) {
					lay = eval('lay_' + lays[j]);
					lay.top = parseInt(lay.top) + much;
				}
				break;
			}
		}
	}
}

navs = new Array('ag_ff', 'ag_bw', 'ag_hfs', 'ag_pp', 'ag_swp', 'ag_wwf', 'bp_bp', 'bp_llw', 'bp_dwc', 'bp_sn', 'bp_wwfl', 'iw_sw', 'iw_ww');
function navClear() {
	for (i = 0; i < navs.length; i++) {
		navOut(navs[i]);
	}			
}

function layCheck() {
	navClear();
	if (last_lay) {
		layOut(last_lay);
	}
}

check = false;
function timerCheck() {
	clearTimeout(check);
	check = setTimeout("layCheck(); timerCheck();",5000);
}

function navOver(which) {
	if (layer_flag) {
		if (last_lay) {
			if (last_nav) {
				navOut(last_nav);
			}
			eval('lay_' + which).visibility = show;
			last_nav = which;
			timerCheck();
		}
	}
}
	
function navOut(which) {
	if (layer_flag) {
		if (which != current_subsection) {
			eval('lay_' + which).visibility = hide;
		}
		last_nav = false;
	}
}

function layGet(what) {
	if (what == 'rem' || what == 'rp') {
		what = false;
	} else if (what.indexOf('_') > -1) {
		what = what.substring(0,what.indexOf('_'));
	}
	return what;
}

function makeDesc(title,desc,imgs) {
	document.write('<TABLE border=0 cellspacing=0 cellpadding=2 width=414>');
	if (desc) {
		document.write('<TR><TD valign="top" class="text" width=414>');
		if (imgs) {
			img = imgs.split('|');
			for (i = 0; i < img.length; i++) {
				document.write('<IMG src="/images/products/' + img[i] + '.jpg" hspace=5 vspace=0 border=0 align="right" alt="">');
			}
			document.write('<IMG src="/images/shim.gif" width=20 height=97 border=0 align="right" alt="">');
		}
		if (title) {
			document.write('<B class="head2">' + title + '</B><BR><IMG src="/images/shim.gif" border=0 alt="" width=414 height=6><BR>');
		}
		document.write(desc + '</TD></TR>');
		document.write('<TR><TD><IMG src="/images/shim.gif" border=0 alt="" width=414 height=6></TD></TR>');
	}
	document.write('</TABLE>');
}

function makeTable(title,buylink,cols,rows,aside) {
	for (i = 0, col = ""; i < cols.length; i++) {
		if (cols.charAt(i) == " ") {
			col = col + "&nbsp;";
		} else {
			col = col + cols.charAt(i);
		}
	}
	cols = col.split("|");
	document.write('<TABLE border=0 cellspacing=0 cellpadding=2 width=414>');
	if (title) {
		document.write('<TR><TD colspan=' + (cols.length - 1) + ' align="left" valign="top" class="thead1">' + title + '</TD></TR>');
	}
	document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
	document.write('<TR>');
	for (i = 0; i < cols.length; i++) {
		document.write('<TD class="thead2" align="' + (i == 0 ? 'left' : 'center') + '" valign="bottom">' + cols[i] + '</TD>');
	}
	rows = rows.split('+');
	for (i = 0, m = 0; i < rows.length; i++, m++) {
		if (rows[i].charAt(0) == '!') {
			m = -1;
			document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
			document.write('<TR><TD class="ttext" align="center" valign="top" colspan=' + cols.length + '"><B>' + rows[i].substring(1,rows[i].length) + '</B></TD></TR>');
			document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
		} else {
			if (m == 0) {
				document.write('<TR bgcolor="#FEFED6">');
				m = -2;
			} else {
				document.write('<TR>');
			}
			row = rows[i].split('|');
			for (j = 0; j < row.length; j++) {
				document.write('<TD class="ttext" align="' + (j == 0 ? 'left' : 'center') + '" valign="top">' + row[j] + '</TD>');
			}
			document.write('</TR>');
		}
	}
	if (aside) {
		document.write('<TR><TD colspan=' + cols.length + '><IMG src="/images/shim.gif" border=0 alt="" width=414 height=6></TD></TR>');
		document.write('<TR><TD colspan=' + cols.length + '><I class="ttext">' + aside + '</I></TD></TR>');
	}
	document.write('<TR><TD colspan=' + cols.length + '><IMG src="/images/shim.gif" border=0 alt="" width=414 height=12></TD></TR>');
	document.write('</TABLE>');
}

// Function to make the last table on products/iw_sw.htlm.  Needed non-centered input in main table cell.

function makeLastTable(title,buylink,cols,rows,aside) {
	for (i = 0, col = ""; i < cols.length; i++) {
		if (cols.charAt(i) == " ") {
			col = col + "&nbsp;";
		} else {
			col = col + cols.charAt(i);
		}
	}
	cols = col.split("|");
	document.write('<TABLE border=0 cellspacing=0 cellpadding=2 width=414>');
	if (title) {
		document.write('<TR><TD colspan=' + (cols.length - 1) + ' align="left" valign="top" class="thead1">' + title + '</TD><TD align="right" valign="top"><A href="/catalog/catalog.php' + buylink + '"><IMG src="/images/buy_now.gif" width=67 height=13 border=0 alt="Buy Now"></A></TD></TR>');
	}
	document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
	document.write('<TR>');
	for (i = 0; i < cols.length; i++) {
		document.write('<TD class="thead2" align="' + (i == 0 ? 'left' : 'center') + '" valign="bottom">' + cols[i] + '</TD>');
	}
	rows = rows.split('+');
	for (i = 0, m = 0; i < rows.length; i++, m++) {
		if (rows[i].charAt(0) == '!') {
			m = -1;
			document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
			document.write('<TR><TD class="ttext" align="center" valign="top" colspan=' + cols.length + '"><B>' + rows[i].substring(1,rows[i].length) + '</B></TD></TR>');
			document.write('<TR><TD colspan=' + cols.length + ' valign="top" height=1><IMG src="/images/black.gif" border=0 alt="" width=414 height=1></TD></TR>')
		} else {
			if (m == 0) {
				document.write('<TR bgcolor="#FEFED6">');
				m = -2;
			} else {
				document.write('<TR>');
			}
			row = rows[i].split('|');
			for (j = 0; j < row.length; j++) {
				document.write('<TD class="ttext" align="' + (j == 0 ? 'left' : 'left') + '" valign="top">' + row[j] + '</TD>');
			}
			document.write('</TR>');
		}
	}
	if (aside) {
		document.write('<TR><TD colspan=' + cols.length + '><IMG src="/images/shim.gif" border=0 alt="" width=414 height=6></TD></TR>');
		document.write('<TR><TD colspan=' + cols.length + '><I class="ttext">' + aside + '</I></TD></TR>');
	}
	document.write('<TR><TD colspan=' + cols.length + '><IMG src="/images/shim.gif" border=0 alt="" width=414 height=12></TD></TR>');
	document.write('</TABLE>');
}
function makeMap(title,tlink,subtitles) {
	document.write('<TR><TD colspan=2 class="thead2"><A href="' + current_section + '_' + tlink + '.html">'+ title + '</A></TD></TR>');
	if (subtitles) {
		subt = subtitles.split('|');
		for (i = 0; i < subt.length; i++) {
			document.write('<TR><TD width=10><IMG src="/images/shim.gif" border=0 alt="" width=10 height=1></TD><TD align="left" valign="top" class="ttext">' + subt[i] + '</TD></TR>');
		}
	}
	document.write('<TR><TD colspan=2><IMG src="/images/shim.gif" border=0 alt="" height=6></TD></TR>');
}

// this function deals with opening the pop window onClick of the Order Request
function newWindow() {

window.open('../catalog/catalogpop.asp', 'newWin', 'toolbar=yes,location=yes,top=80,left=80,scrollbars=yes,menubar=yes,resizable=no,width=420,height=320')

}
