var bxlst = 1;
var bxtmp = 0;
var bxarr = new Array();
var bxreq = false;
var popupel = document.getElementById('popUpDiv');
var popupbl = document.getElementById('pblanket');
///////////////////////////////



// Page Size and View Port Dimension Tools
// http://stevenbenner.com/2010/04/calculate-page-size-and-view-port-position-in-javascript/
if (!sb_windowTools) { var sb_windowTools = new Object(); };
 
sb_windowTools = {
    scrollBarPadding: 17, // padding to assume for scroll bars
 
    // EXAMPLE METHODS
 
    // center an element in the viewport
    centerElementOnScreen: function(element) {
        var pageDimensions = this.updateDimensions();
        element.style.position = 'absolute';
        element.style.top = ((this.pageDimensions.verticalOffset() + this.pageDimensions.windowHeight() / 2) - (this.scrollBarPadding + element.offsetHeight / 2)) + 'px';
        element.style.left = ((this.pageDimensions.windowWidth() / 2) - (this.scrollBarPadding + element.offsetWidth / 2)) + 'px';

    },
 
    // INFORMATION GETTERS
 
    // load the page size, view port position and vertical scroll offset
    updateDimensions: function() {
        this.updatePageSize();
        this.updateWindowSize();
        this.updateScrollOffset();
    },
 
    // load page size information
    updatePageSize: function() {
        // document dimensions
        var viewportWidth, viewportHeight;
        if (window.innerHeight && window.scrollMaxY) {
            viewportWidth = document.body.scrollWidth;
            viewportHeight = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            // all but explorer mac
            viewportWidth = document.body.scrollWidth;
            viewportHeight = document.body.scrollHeight;
        } else {
            // explorer mac...would also work in explorer 6 strict, mozilla and safari
            viewportWidth = document.body.offsetWidth;
            viewportHeight = document.body.offsetHeight;
        };
        this.pageSize = {
            viewportWidth: viewportWidth,
            viewportHeight: viewportHeight
        };
    },
 
    // load window size information
    updateWindowSize: function() {
        // view port dimensions
        var windowWidth, windowHeight;
        if (self.innerHeight) {
            // all except explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            // explorer 6 strict mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            // other explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        };
        this.windowSize = {
            windowWidth: windowWidth,
            windowHeight: windowHeight
        };
    },
 
    // load scroll offset information
    updateScrollOffset: function() {
        // viewport vertical scroll offset
        var horizontalOffset, verticalOffset;
        if (self.pageYOffset) {
            horizontalOffset = self.pageXOffset;
            verticalOffset = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            // Explorer 6 Strict
            horizontalOffset = document.documentElement.scrollLeft;
            verticalOffset = document.documentElement.scrollTop;
        } else if (document.body) {
            // all other Explorers
            horizontalOffset = document.body.scrollLeft;
            verticalOffset = document.body.scrollTop;
        };
        this.scrollOffset = {
            horizontalOffset: horizontalOffset,
            verticalOffset: verticalOffset
        };
    },
 
    // INFORMATION CONTAINERS
 
    // raw data containers
    pageSize: {},
    windowSize: {},
    scrollOffset: {},
 
    // combined dimensions object with bounding logic
    pageDimensions: {
        pageWidth: function() {
            return sb_windowTools.pageSize.viewportWidth > sb_windowTools.windowSize.windowWidth ?
                sb_windowTools.pageSize.viewportWidth :
                sb_windowTools.windowSize.windowWidth;
        },
        pageHeight: function() {
            return sb_windowTools.pageSize.viewportHeight > sb_windowTools.windowSize.windowHeight ?
                sb_windowTools.pageSize.viewportHeight :
                sb_windowTools.windowSize.windowHeight;
        },
        windowWidth: function() {
            return sb_windowTools.windowSize.windowWidth;
        },
        windowHeight: function() {
            return sb_windowTools.windowSize.windowHeight;
        },
        horizontalOffset: function() {
            return sb_windowTools.scrollOffset.horizontalOffset;
        },
        verticalOffset: function() {
            return sb_windowTools.scrollOffset.verticalOffset;
        }
    }
};









////////////////////////////////////
function bxwinOLD(data) {
 var imgfiln = '/items/' + imgfila;
 window.open(imgfiln,'','width=620,height=620,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no');
 return true;
}

function bxwin(imgfila, imgplin, imglink) {

 //var imgfiln = '/items/' + imgfila;
 //window.open(imgfiln,'','width=620,height=620,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no');


 if (!( bxreq )) {
	 bxreq = true;
   	 if (!(popupel)) popupel = document.getElementById('popUpDiv');
   	 if (!(popupbl)) popupbl = document.getElementById('pblanket');
	 if (popupel) {
		popupel.style.display = 'none';
		popupel.style.textAlign  = "center";
		popupel.innerHTML = "<img src='/styles/loading.gif' alt='loading...'> "; 
		//popupel.style.width  = "80px";
		//popupel.style.height = "40px"; 
		bxsethw(popupel,80,40);
		if (typeof document.body.style.minHeight !== "undefined") popupel.style.minHeight = "40px";
		//var popUpSrc = document.getElementById(imgfila + "_jpg");
		sb_windowTools.centerElementOnScreen(popupel);	
//alert("OK0");
		popupel.style.display = 'block';
		sb_windowTools.centerElementOnScreen(popupel);	
	 }
//alert("OK1");

//alert("OK2");

	var getimgparam = "imgfila=" + imgfila + "&imgplin=" + imgplin + "&imglink=" + escape(imglink);
	var getimgajax = getCORSreq('GET', 'http://www.anchorlineproducts.com/prodprice.php', 'http://www.anchorlineproducts.com/prodprice.php',"", getimgparam, function(data){ bxwinshow(data, imgfila);bxreq = false;},function(data){bxreq = false; alert("Error " + data);}, null );

	//Show Loading Screen
 }
 return true;
}


function bxsethw(bxe, bxw, bxh) {


   if (typeof document.body.style.maxHeight !== "undefined") {
	bxe.style.width  = "auto";
	if (isNaN(parseFloat(bxw))) { //non-numeric
		bxe.style.maxWidth  = bxw;
	}else{ //numeric
		bxe.style.maxWidth  = bxw + 'px';
	}

	bxe.style.height  = "auto";
	if (isNaN(parseFloat(bxh))) { //non-numeric
		bxe.style.maxHeight  = bxh;
	}else{ //numeric
		bxe.style.maxHeight = bxh + 'px';
	}
   }else{
 	if (isNaN(parseFloat(bxw))) { //non-numeric
		bxe.style.width  = bxw;
	}else{ //numeric
		bxe.style.width  = bxw + 'px';
	}

	if (isNaN(parseFloat(bxh))) { //non-numeric
		bxe.style.height  = bxh;
	}else{ //numeric
		bxe.style.height = bxh + 'px';
	}
   }
}



function bxwinshow(itemdata, imgfila) {
   if (!(popupel)) popupel = document.getElementById('popUpDiv');
   if (!(popupbl)) popupbl = document.getElementById('pblanket');
   if (popupel) {
	popupel.style.display = 'none';
	popupel.style.top  = "0px";
	popupel.style.left = "0px";
	if (typeof document.body.style.minHeight !== "undefined") popupel.style.minHeight = "500px";
	//popupel.style.width  = popupw + 'px';
	//popupel.style.height = popuph + 'px';
	popupel.innerHTML = itemdata; 
	bxsethw(popupel,popupw,popuph);

	//var popUpSrc = document.getElementById(imgfila + "_jpg");
	//popup('popUpDiv');
	popup();
	//popupel.innerHTML = itemdata;
	//popupel.style.display = 'block';
	//popupbl.style.display = 'block';
   }
}


function togglel(elnam) {
	var el = document.getElementById(elnam);
	if ( (el) && (el.style)) {
		if (el.style.display == "none") {
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//////////////////////////////////////////////
//// http://webdesignandsuch.com/how-to-create-a-popup-with-css-and-javascript/
var popupw = 700;
var popuph = 500;
function popupclose() {
	if (!(popupel)) popupel = document.getElementById('popUpDiv');
	if (!(popupbl)) popupbl = document.getElementById('pblanket');
	popupbl.style.height = '0px';

	popupel.style.display = 'none';
	popupbl.style.display = 'none';


}

function popup() {
	//var nnn = document.createTextNode(' ');

	if (!(popupel)) popupel = document.getElementById('popUpDiv');
	if (!(popupbl)) popupbl = document.getElementById('pblanket');


	var pblanket_height =  (sb_windowTools.pageDimensions.pageHeight() ) * 1;
	popupbl.style.height = pblanket_height + 'px';
	popupbl.style.visibility = 'hidden';
	popupbl.style.display = 'none';

	popupbl.style.display = 'block';
	popupbl.style.visibility = 'visible';
	


	//popupel.style.width  = popupw + 'px';
	//popupel.style.height = popuph + 'px';
	popupel.style.visibility = 'hidden';	
	bxsethw(popupel,popupw,popuph); 
	popupel.style.display = 'block';
	//sb_windowTools.centerElementOnScreen(popupel);
	popupel.style.visibility = 'visible';
	//sb_windowTools.centerElementOnScreen(popupel);
	//popupel.style.display = 'block';
	//popupel.style.width  = (popupw + 1) + 'px';
	//setTimeout("popupel.style.display = 'none';",100); 
	//setTimeout("popupel.style.display = 'block';",1000); 
	//setTimeout("popupel.style.visibility = 'hidden';",300); 
	//setTimeout("popupel.style.visibility = 'visible';",400); 

	//Force redraw
	//document.body.appendChild(document.createTextNode('dude!'));
	//setTimeout("document.body.appendChild(document.createTextNode('<BR>'));",50); 
	//style.display = 'none';
	popupbl.style.display = 'none';	
	popupbl.offsetHeight;   
	popupbl.style.display = 'block';

	//popupbl.appendChild(nnn)  ;
	//setTimeout("sb_windowTools.centerElementOnScreen(popupel);",120); 

	setTimeout("showdistpric(0);",777); 

 

	//setTimeout("popupel.style.display = 'none'; popupel.style.display = 'block';",100); 
	setTimeout("sb_windowTools.centerElementOnScreen(popupel);",100); 
	setTimeout("sb_windowTools.centerElementOnScreen(popupel);",250); 
	setTimeout("sb_windowTools.centerElementOnScreen(popupel);",500); 
	setTimeout("sb_windowTools.centerElementOnScreen(popupel);",1000); 

	//sb_windowTools.centerElementOnScreen(popUpDiv);	
}
//////////////////////////////////////////////

/////////////////========================//////////////


function itembx(bxnum) {
	var itembxa;
	var itembxb;

	var linkbxa;
	var linkbxb;

	if (bxtmp == 0)
        {
		bxtmp = bxlst;
		bxlst = 0;


		if (linkbxa = document.getElementById("linkbx" + bxtmp)) {
			linkbxa.style.fontWeight = 'normal';
		}	
		if (linkbxb = document.getElementById("linkbx" + bxnum)) {
			linkbxb.style.fontWeight = 'bold';
		}


		if (itembxa = document.getElementById("itembx" + bxtmp)) {
			itembxa.style.visibility = 'hidden';
			itembxa.style.display = 'none';
		}
	
		if (itembxb = document.getElementById("itembx" + bxnum)) {
			itembxb.style.visibility = 'visible';
			itembxb.style.display = 'inline';
			itembxshow(bxnum);
		}
	
		bxlst = bxnum;
		bxtmp = 0;
	} else { 
		//wait
		setTimeout("itembx(bxnum);",500);
		//alert("Stop Poking Me!");
	}

	
}


function itembxshow(bxnum) {
	var itembxc;

	if ( !( (bxarr[bxnum]) && (bxarr[bxnum] == 1) ) )
	{
	    if (itembxc = document.getElementById("itembx" + bxnum))
            {
		//if (itembxc.getElementsByClassName) {
			//var bximgs = itembxc.getElementsByClassName("bximg");
			var bximgs = getElementsByClassName(itembxc, "bximg");
			for (var bxi=0; bxi<bximgs.length;bxi++) {
				bxtmp1 = bximgs[bxi].id;
				bxtmp1 = "/items_icon/" + bxtmp1.replace("_jpg", ".jpg");
				bximgs[bxi].src = bxtmp1;
			}
		//}
	
		bxarr[bxnum] = 1;
            }
	}

}


