/* MAIN JAVASCRIPT FUNCTIONS */

// figure out which browser the user has
var xVersion='3.10', xOp7=false, xOp5or6=false, xIE4Up=false, xNN4=false, xUA=navigator.userAgent.toLowerCase();
if (window.opera) {
	xOp7 = (xUA.indexOf('opera 7') != -1 || xUA.indexOf('opera/7') != -1);
	if (!xOp7) xOp5or6 = (xUA.indexOf('opera 5') != -1 || xUA.indexOf('opera/5') != -1 || xUA.indexOf('opera 6') != -1 || xUA.indexOf('opera/6') != -1);
	}
else if (document.layers) xNN4 = true;
else { 
	xIE4Up = document.all && xUA.indexOf('msie') != -1 && parseInt(navigator.appVersion) >= 4;
	}
	
// function to determine visibility
function xShow(e) {
	if (!(e=xGetElementById(e))) return;
	if (e.style && xDef(e.style.visibility)) e.style.visibility = 'inherit';
	else if (xDef(e.visibility)) e.visibility = 'show';
	}
	
// internal function to get the current styles
function xGetCS(ele, sP) {
	return parseInt(document.defaultView.getComputedStyle(ele,"").getPropertyValue(sP));
	}
	
// internal function to figure out the CSS after resizing
function xSetCH(ele, uH){
	if (uH<0) return;
	var pt=0, pb=0, bt=0, bb=0;
	if (xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)) {
		pt = xGetCS(ele, "padding-top");
		pb = xGetCS(ele, "padding-bottom");
		bt = xGetCS(ele, "border-top-width");
		bb = xGetCS(ele, "border-bottom-width");
		}
	else if (xDef(ele.currentStyle,document.compatMode)) {
		if (document.compatMode == "CSS1Compat"){
			pt = parseInt(ele.currentStyle.paddingTop);
			pb = parseInt(ele.currentStyle.paddingBottom);
			bt = parseInt(ele.currentStyle.borderTopWidth);
			bb = parseInt(ele.currentStyle.borderBottomWidth);
			}
		}
	else if (xDef(ele.offsetHeight,ele.style.height)) {
		ele.style.height = uH+"px";
		pt = ele.offsetHeight-uH;
		}
	if (isNaN(pt)) pt = 0; 
	if (isNaN(pb)) pb = 0; 
	if (isNaN(bt)) bt = 0; 
	if (isNaN(bb)) bb = 0;
	var cssH = uH-(pt+pb+bt+bb);
	if (isNaN(cssH) || cssH<0) return;
	else ele.style.height = cssH + "px";
	}

	
// function to figure out the height of columns on the page
function xHeight(e, uH) {
	if (!(e=xGetElementById(e)) || (uH && uH<0)) return 0;
	uH = Math.round(uH);
	var css = xDef(e.style);
	if (css && xDef(e.style.height,e.offsetHeight) && typeof(e.style.height) == "string") {
		if (arguments.length>1) xSetCH(e, uH);
		uH = e.offsetHeight;
		}
	else if (css && xDef(e.style.pixelHeight)) {
		if (arguments.length>1) e.style.pixelHeight = uH;
		uH = e.style.pixelHeight;
		}
	else if (xDef(e.clip) && xDef(e.clip.bottom)) {
		if (arguments.length>1) e.clip.bottom = uH;
		uH = e.clip.bottom;
		}
	return uH;
	}
	
// used to find elements in Netscape 4 only
function xLayer(id, root) { 
	var i, layer, found=null;
	if (!root) root = window;
	for (i=0; i<root.document.layers.length; i++) {
		layer = root.document.layers[i];
		if (layer.id == id) return layer;
		if (layer.document.layers.length) found = xLayer(id,layer);
		if (found) return found;
		}
	return null;
	}
	
// internal function to get the element by its ID
function xGetElementById(e) {
	if (typeof(e) != "string") return e;
	if (document.getElementById) e = document.getElementById(e);
	else if (document.all) e = document.all[e];
	else if (document.layers) e = xLayer(e);
	else e = null;
	return e;
	}
	
// internal function to get width of object
function xClientWidth() {
	var w=0;
	if (xOp5or6) w = window.innerWidth;
	else if (xIE4Up && document.documentElement && document.documentElement.clientWidth)
		w = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		w = document.body.clientWidth;
	else if (xDef(window.innerWidth, window.innerHeight, document.height)) {
		w = window.innerWidth;
		if (document.height > window.innerHeight) w-=16;
		}
	return w;
	}

// internal function to get height of object
function xClientHeight() {
	var h=0;
	if (xOp5or6) h = window.innerHeight;
	else if (xIE4Up && document.documentElement && document.documentElement.clientHeight)
		h = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		h = document.body.clientHeight;
	else if (xDef(window.innerWidth, window.innerHeight, document.width)) {
		h = window.innerHeight;
		if (document.width>window.innerWidth) h-=16;
		}
	return h;
	}
	
// internal function to scroll to the left
function xScrollLeft() {
	var offset = 0;
	if (xDef(window.pageXOffset)) 
		offset = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft) 
		offset = document.documentElement.scrollLeft;
	else if (document.body && xDef(document.body.scrollLeft)) 
		offset = document.body.scrollLeft;
	return offset;
	}
	
// internal function to scroll up
function xScrollTop() {
	var offset = 0;
	if (xDef(window.pageYOffset)) 
		offset = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) 
		offset = document.documentElement.scrollTop;
	else if (document.body && xDef(document.body.scrollTop)) 
		offset = document.body.scrollTop;
	return offset;
	}
	
// internal function to resize window
function xResizeEvent() { 
	if (window.xREL) setTimeout("xResizeEvent()", 250);
	var cw = xClientWidth(), ch = xClientHeight();
	if (window.xPCW != cw || window.xPCH != ch) { 
		window.xPCW = cw; 
		window.xPCH = ch; 
		if (window.xREL) window.xREL(); 
		}
	}
	
// internal function to scroll window
function xScrollEvent() { 
	if (window.xSEL) setTimeout("xScrollEvent()", 250);
	var sl = xScrollLeft(), st = xScrollTop();
	if (window.xPSL != sl || window.xPST != st) { 
		window.xPSL = sl; 
		window.xPST = st; 
		if (window.xSEL) window.xSEL(); 
		}
	}
	
// determines arguments
function xDef() {
	for (var i=0; i<arguments.length; ++i) {
		if (typeof(arguments[i]) == "" || typeof(arguments[i]) == "undefined") return false;
		}
	return true;
	}

	
// function to kick off other functions above
function xAddEventListener(e, eventType, eventListener, useCapture) {
	if (!(e = xGetElementById(e))) return;
	eventType = eventType.toLowerCase();
	if ((!xIE4Up && !xOp7) && e == window) {
		if (eventType == 'resize') { 
			window.xPCW = xClientWidth(); 
			window.xPCH = xClientHeight(); 
			window.xREL = eventListener; 
			xResizeEvent(); 
			return; 
			}
		if (eventType == 'scroll') { 
			window.xPSL = xScrollLeft(); 
			window.xPST = xScrollTop(); 
			window.xSEL = eventListener; 
			xScrollEvent(); 
			return; 
			}
		}
	var eh = "e.on" + eventType + "=eventListener";
	if (e.addEventListener) e.addEventListener(eventType, eventListener, useCapture);
	else if (e.attachEvent) e.attachEvent("on"+eventType, eventListener);
	else if (e.captureEvents) {
		if (useCapture || (eventType.indexOf('mousemove') != -1)) { 
			e.captureEvents(eval("Event."+eventType.toUpperCase())); 
			}
		eval(eh);
		}
	else eval(eh);
	}

// function to pop the product image window
function prodPop(prod_id, color) {
	var atts = "width=375,height=525,resize";
	var prodWin = window.open("product_detail.php?id=" + prod_id + "&img=" + color, "prodWin", atts);
	prodWin.focus();
	}


	

 	
		
	

	
		
// POP-UP for close up view
function popUp(URL) {
var view_width = 420;
var view_height = 565;
var look='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+view_width+',height='+view_height+','
popwin=window.open("","",look)
popwin.document.open()
popwin.document.write('<title>Close-up View - Bestop</title><head> <meta name="robots" content="ALL, INDEX, FOLLOW" />')
popwin.document.write('<!--#include virtual="/includes/headtracker.txt"--></head>')
popwin.document.write('<body bgcolor="#F3EBD5" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginheight=0 marginwidth=0>')
popwin.document.write('<table cellpadding=0 cellspacing=0 border=0 width="100%" height="100%" ><tr><td align="center">')
popwin.document.write('<center><br>')
popwin.document.write('<table cellpadding=0 cellspacing=0 border=1 bordercolor="666666"><tr><td>')
popwin.document.write('<img src="'+URL+'">')
popwin.document.write('</td></tr></table>')
popwin.document.write('</td></tr><tr><td valign="bottom" align="center">')
popwin.document.write('<br><form><input type=submit value="Close" class="button-popups" onClick=\'self.close()\'></form><br>')
popwin.document.write('</center>')
popwin.document.write('</td></tr></table>')
popwin.document.write('</body>')
popwin.document.close()
}
		


