var cartText;
var showcart = false;
var listitems_page;
var myurl;
	
	myurl = window.location.href;
	if (myurl.indexOf("/secure/") > -1) 
		listitems_page = '/frames/secure/listitems.asp'
	else
		listitems_page = '/frames/listitems.asp';
		
function addCart(x) {
var objXMLHTTP;
var embr = "";
	if (document.getElementById('chkEmbroidery'))
		embr = document.getElementById('chkEmbroidery').checked;
	if (document.getElementById("frmQty").value > 0)
		document.getElementById("frameItems").contentWindow.location.replace('/frames/cartoperations.asp?dummy=' + (new Date()).getTime() + '&embr=' + embr + '&code=' + x + '&qty=' + document.getElementById("frmQty").value);
		//document.getElementById("frameItems").src = '/frames/cartoperations.asp?dummy=' + (new Date()).getTime() + '&embr=' + embr + '&code=' + x + '&qty=' + document.getElementById("frmQty").value;
	setTimeout('document.getElementById("frameItems").contentWindow.location.replace("' + listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=' + showcart + '");', 3000);
	//setTimeout('document.getElementById("frameItems").src = "' + listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=' + showcart + '";', 3000);
	return false;
}

function hideCart2() {
	showcart = false;
	document.getElementById("frameItems").contentWindow.location.replace(listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=' + showcart);
	//document.getElementById("frameItems").src = listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=' + showcart;
	return false;
}

function showCart2(showbutton) {
	showcart = true;
	//document.getElementById("frameItems").src = listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=true';
	document.getElementById("frameItems").contentWindow.location.replace(listitems_page + '?dummy=' + (new Date()).getTime() + '&showcart=true');
	return false;
}

function updMinicartHeader(tab) {
var el;
	if (el = document.getElementById("minicartheader"))
		el.innerHTML = tab;
}

function adjustIFrameSize(iframeWindow, show) {
var maxHeight;
var frameWidth = 246;
var iframeElement;
var divElement;
var bbarElement;
var posX = 754;
var k;
k = getElementAbsolutePos("toptable");    
//window.alert("Element's left: " + k.x + " and top: " + k.y);
posX = (k.x + 737);
//alert(posX);

	maxHeight = Math.max(getSize()[1] - 250, 100);
	if (document.getElementById("frameItems")) {
		iframeElement = document.getElementById ("frameItems");
		divElement = document.getElementById ("cart2");
		bbarElement = document.getElementById ("bottombar");
	} else if (document.all) {
		iframeElement = document.all["frameItems"];
		divElement = document.all["cart2"];
		bbarElement = document.all["bottombar"];
	} else {
		return;
	}
	iframeElement.style.width = frameWidth + 'px';
	if (iframeWindow.document.height) {
	//alert('a' + iframeWindow.document.height );
		//if (iframeWindow.document.height < 50) {
		if (!show) {
			bbarElement.style.visibility = "hidden";
			iframeElement.style.visibility = "hidden";
			iframeElement.style.height = '';
		} else {
			bbarElement.style.visibility = "visible";
 			iframeElement.style.visibility = "visible";
			if (iframeWindow.document.height > maxHeight) {
				divElement.style.left = posX - 18 + 'px';
				iframeElement.style.height = maxHeight + 'px';
				iframeElement.style.width = frameWidth + 18 + 'px';
				iframeElement.setAttribute('scrolling','auto');
			} else {
				iframeElement.style.height = iframeWindow.document.height + 'px';
				iframeElement.style.width = frameWidth + 'px';
				iframeElement.setAttribute('scrolling','off');
				divElement.style.left = posX + 'px';
			}
		}
	} else if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') {
	//alert('b' + iframeWindow.document.documentElement.scrollHeight );
		//if (iframeWindow.document.documentElement.scrollHeight < 50) {
		if (!show) {
			bbarElement.style.visibility = "hidden";
			iframeElement.style.visibility = "hidden";
			iframeElement.style.height = '';
		} else {
			bbarElement.style.visibility = "visible";
 			iframeElement.style.visibility = "visible";
			if (iframeWindow.document.documentElement.scrollHeight > maxHeight) {
				divElement.style.left = posX - 18 + 'px';
				iframeElement.style.height = maxHeight + 'px';
				iframeElement.style.width = frameWidth + 18 + 'px';
				iframeElement.setAttribute('scrolling','on');
			} else {
				iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
				iframeElement.style.width = frameWidth + 'px';
				iframeElement.setAttribute('scrolling','off');
				divElement.style.left = posX + 'px';
			}	
			//alert('bend');
		}
	} else if (document.all) {
	//alert('c' + iframeWindow.document.body.scrollHeight);
		//if (iframeWindow.document.body.scrollHeight < 50) {
		if (!show) {
			bbarElement.style.visibility = "hidden";
			iframeElement.style.visibility = "hidden";
			iframeElement.style.height = '';
		} else {
			bbarElement.style.visibility = "visible";
 			iframeElement.style.visibility = "visible";
			//alert('cmiddle');
			if (iframeWindow.document.body.scrollHeight > maxHeight) {
				divElement.style.left = posX - 18 + 'px';
				iframeElement.style.height = maxHeight + 'px';
				iframeElement.style.width = frameWidth + 18 + 'px';
				iframeElement.setAttribute('scrolling','auto');
			} else {
				iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';
				iframeElement.style.width = frameWidth + 'px';
				iframeElement.setAttribute('scrolling','off');
				divElement.style.left = posX + 'px';
			}
			//alert('cend');
		}
	} else if (iframeElement.document) {
	//alert(iframeWindow.document.body.offsetHeight);
		//if (iframeWindow.document.body.offsetHeight < 50) {
		if (!show) {
			//alert('f0');
			bbarElement.style.visibility = "hidden";
			iframeElement.style.visibility = "hidden";
			iframeElement.style.height = '';
		} else {
			bbarElement.style.visibility = "visible";
 			iframeElement.style.visibility = "visible";
			if (iframeWindow.document.body.offsetHeight > maxHeight) {
				//alert('f1');
				divElement.style.left = posX - 15 + 'px';
				iframeElement.style.height = maxHeight + 'px';
				iframeElement.style.width = frameWidth + 15 + 'px';
				iframeElement.setAttribute('scrolling','auto');
			} else {
				//alert('f2');
				iframeElement.style.height = iframeWindow.document.body.offsetHeight + 'px';
				iframeElement.style.width = frameWidth + 'px';
				iframeElement.setAttribute('scrolling','off');
				divElement.style.left = posX + 'px';
			}
		}
	} else {
	//alert('d' );
		bbarElement.style.visibility = "hidden";
	}
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}



function __getIEVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function __getOperaVersion() {
    var rv = 0; // Default value
    if (window.opera) {
        var sver = window.opera.version();
        rv = parseFloat(sver);
    }
    return rv;
}

var __userAgent = navigator.userAgent;
var __isIE =  navigator.appVersion.match(/MSIE/) != null;
var __IEVersion = __getIEVersion();
var __isIENew = __isIE && __IEVersion >= 8;
var __isIEOld = __isIE && !__isIENew;

var __isFireFox = __userAgent.match(/firefox/i) != null;
var __isFireFoxOld = __isFireFox && ((__userAgent.match(/firefox\/2./i) != null) || (__userAgent.match(/firefox\/1./i) != null));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

var __isWebKit =  navigator.appVersion.match(/WebKit/) != null;
var __isChrome =  navigator.appVersion.match(/Chrome/) != null;
var __isOpera =  window.opera != null;
var __operaVersion = __getOperaVersion();
var __isOperaOld = __isOpera && (__operaVersion < 10);

function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
     		//do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now
    		//so just set the width to 1 pixel
            res = 1; 
        }
    }
    return res;
}


//returns border width for some element
function __getBorderWidth(element) {
	var res = new Object();
	res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
	if (window.getComputedStyle) {
		//for Firefox
		var elStyle = window.getComputedStyle(element, null);
		res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));  
		res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));  
		res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));  
		res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));  
	}
	else {
		//for other browsers
		res.left = __parseBorderWidth(element.style.borderLeftWidth);
		res.top = __parseBorderWidth(element.style.borderTopWidth);
		res.right = __parseBorderWidth(element.style.borderRightWidth);
		res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
	}
   
	return res;
}


//returns the absolute position of some element within document
function getElementAbsolutePos(elemID) {
	var element;
	if (typeof(elemID) == "string")	{
		element = document.getElementById(elemID);
	}
	else {
		element = elemID;
	}

	var res = new Object();
	res.x = 0; res.y = 0;
	if (element !== null) {
        if (__isIENew) {
	    	res.x = element.scrollLeft;
		    res.y = element.scrollTop;
		}
		else {
	    	res.x = element.offsetLeft;
		    res.y = element.offsetTop;
		}
    	
		var offsetParent = element.offsetParent;
		var parentNode = element.parentNode;
		var borderWidth = null;

		while (offsetParent != null) {
			res.x += offsetParent.offsetLeft;
			res.y += offsetParent.offsetTop;
			
			var parentTagName = offsetParent.tagName.toLowerCase();	

			if ((__isIEOld && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {		    
				borderWidth = __getBorderWidth(offsetParent);
				res.x += borderWidth.left;
				res.y += borderWidth.top;
			}
		    
			if (offsetParent != document.body && offsetParent != document.documentElement) {
				res.x -= offsetParent.scrollLeft;
				res.y -= offsetParent.scrollTop;
			}


			//next lines are necessary to support FireFox problem with offsetParent
   			if (!__isIE && !__isOperaOld || __isIENew) {
    			while (offsetParent != parentNode && parentNode !== null) {
					res.x -= parentNode.scrollLeft;
					res.y -= parentNode.scrollTop;
					if (__isFireFoxOld && __isWebKit) {
						borderWidth = __getBorderWidth(parentNode);
						res.x += borderWidth.left;
						res.y += borderWidth.top;
					}
    				parentNode = parentNode.parentNode;
    			}    
			}

   			parentNode = offsetParent.parentNode;
    		offsetParent = offsetParent.offsetParent;
		}
	}
    return res;
}

