function storeProduct() {
	var prodName = document.productVars.prodName.value;
	var theDate = new Date();
	theDate.setDate(theDate.getDate()+14);
	var expireDate = theDate.toGMTString();
	
	if (document.cookie.indexOf("storedProduct") >= 0){			//check if storedProducts cookie exists
		if (document.cookie.indexOf(prodName) >= 0) {			//check for duplicate items in storedProducts
			//do nothing
		}
		else {													//ammend to storedProducts cookie
			var startPoint = document.cookie.indexOf("storedProduct=") + 14;
			var endPoint = document.cookie.indexOf(";",startPoint);
			
			if (endPoint == -1) { // IF storedProducts= is that the end of the cookie
				productList = document.cookie.substring(startPoint);
				productList += prodName + ",";
				document.cookie = 'storedProduct=' + productList + '; expires=' + expireDate + '; path=/;';
			}
			else if (endPoint >= 0){ //IF storedProducts= is in the front or middle of the cookie
				productList = document.cookie.substring(startPoint, endPoint);
				productList += prodName + ",";
				document.cookie = 'storedProduct=' + productList + '; expires=' + expireDate + '; path=/;';
			}
		}
	}
	else {
		document.cookie = 'storedProduct=' + prodName + ',; expires=' + expireDate + '; path=/;';
	}
}


function ValidateProduct()
{
	if (document.getElementById('ctrlOrderBox_cboMaterial').value == '0')
	{
		alert('Please select a material from the drop down list.');
		return false;
	}
	else if (document.getElementById('ctrlOrderBox_cboQuantity').value == '0')
	{
		alert('Please select the number of sheets required.');
		return false;
	}
	else if (document.getElementById('ctrlOrderBox_cboQuantity').value == '-2')
	{
		alert('Please call us at 1-888-575-2235 for orders over 20,000 sheets.');
		return false;
	}
	
	return true;
}

function openDetail(page){		
	window.open(page,"thisName", "directories=0,height=300,width=325");
}


var js;

function MaterialChanged(bIsCustom) {
	var cboMaterial = document.getElementById('ctrlOrderBox_cboMaterial');
	var productName = cboMaterial.value;
	
	SetShippingCalcMaterial();
	
	if (productName == '0')
		return;
	
	js = document.createElement('script');
	js.type = 'text/javascript';
	js.src = '/Products/GetPricingJS.aspx?ProductName=' + productName + '&IsCustom=' + bIsCustom;
	
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(js);
}

function SetShippingCalcMaterial() {
    var cboMaterial = document.getElementById('ctrlOrderBox_cboMaterial');
	var productName = cboMaterial.value;
	var shippingCalcProduct = (productName != '0') ? productName : document.getElementById('ctrlProductCategory').value;
   
    var lnkShippingCalculator = document.getElementById('lnkShippingCalculator')
    var url = lnkShippingCalculator.href;
    
	var startIndex = url.indexOf('Product=');
	var endIndex = url.indexOf('&', startIndex);
	
    url = url.substring(0, startIndex) + 
            'Product=' + shippingCalcProduct + 
            url.substring(endIndex, url.length);
            
    lnkShippingCalculator.href = url;
}

function SetShippingCalcQty() {
	var cboQuantity = document.getElementById('ctrlOrderBox_cboQuantity');
	var quantity = cboQuantity.value;
	
    var lnkShippingCalculator = document.getElementById('lnkShippingCalculator')
    var url = lnkShippingCalculator.href;
    
    var startIndex = url.indexOf('Qty=');
	var endIndex = url.indexOf('\'', startIndex);
	
    url = url.substring(0, startIndex) + 
            'Qty=' + quantity + 
            url.substring(endIndex, url.length);
            
    lnkShippingCalculator.href = url;
}

function UpdatePricing(bIsCustom) {
	var cboQuantity = document.getElementById('ctrlOrderBox_cboQuantity');
	
	// don't want the first 2 items
	for (var i=2; i<cboQuantity.options.length; i++) {
		var opt = cboQuantity.options[i];
		
		if (parseInt(opt.value) > 0) {
		    var qty = opt.value;
		    var price = prices[qty];
    		
		    var index = opt.innerHTML.indexOf('$');
		    if (index >= 0) {
			    opt.innerHTML = opt.innerHTML.substring(0, index) + price;
		    }
		    else {
			    opt.innerHTML += ' - ' + price;
		    }
		}
	}
	
	setTimeout('RemovePricingJS();', 0);
	
	if (bIsCustom == '0')
		document.getElementById('ctrlOrderBox_ProductImage').src = '/images/products/' + productCategory + '/' + productImage;
	else
		document.getElementById('ctrlOrderBox_ProductImage').src = '/images/products/nophoto.gif'
		
	var cboMaterial = document.getElementById('ctrlOrderBox_cboMaterial');
	var productName = cboMaterial.value;
	
	var h1 = document.getElementById('ctrlOrderBox_h1');
	var startIndex = h1.innerHTML.indexOf('OL');
	var endIndex = h1.innerHTML.indexOf(' ', startIndex);
	h1.innerHTML = h1.innerHTML.substring(0, startIndex) + productName + h1.innerHTML.substring(endIndex, h1.innerHTML.length);
}

function RemovePricingJS() {
	delete prices;
	
	var head = js.parentNode;
	
	if (head)
	    head.removeChild(js);
	    
	delete js;
}

function SelectMaterialQty(product, qty) {
	document.getElementById('ctrlOrderBox_cboMaterial').value = product;
	document.getElementById('ctrlOrderBox_cboQuantity').value = qty;

	// fixes issue with AJAX not always working
	setTimeout("MaterialChanged(0);", 0);
	setTimeout("Availability();", 0);
	
	window.location.href = "#";
}


var isIE6 = false;
if (typeof document.addEventListener != 'function') { 
	isIE6 = true;	
}

function showPromise(){
	if (isIE6 == true) {
		document.getElementById('ourPromiseIframe').style.top = getScrollY() + 70 +'px';
	    document.getElementById('ourPromiseIframe').style.display = 'block';
	}
	document.getElementById('ourPromisePopup').style.top = getScrollY() + 50 +'px';
    document.getElementById('ourPromisePopup').style.display = 'block';
    document.getElementById('ourPromiseShadow').style.top = getScrollY() + 35 +'px';
    document.getElementById('ourPromiseShadow').style.display = 'block';  
}

function hidePromise() {
	if (isIE6 = true) {
		document.getElementById('ourPromiseIframe').style.display = 'none';
	}
		document.getElementById('ourPromisePopup').style.display = 'none';	
	     document.getElementById('ourPromiseShadow').style.display = 'none';  
}			

function getScrollY()
{
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//NS
		scrOfY = window.pageYOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

function toggleToChart(e) {
	if (e == 'high') {
	    if (document.getElementById('tblSmallQty')) {
	        document.getElementById('tblSmallQty').style.display = 'none';
	    }
	    
	    document.getElementById('tblLowQty').style.display = 'none';
	    document.getElementById('tblHighQty').style.display = 'block';
	}
	else if (e == 'low') {
	    if (document.getElementById('tblSmallQty')) {
	        document.getElementById('tblSmallQty').style.display = 'none';
	    }
	    
	    document.getElementById('tblLowQty').style.display = 'block';
		document.getElementById('tblHighQty').style.display = 'none';
	}
	else if (e == 'small') {
	    if (document.getElementById('tblSmallQty')) {
	        document.getElementById('tblSmallQty').style.display = 'block';
	    }
	    
		document.getElementById('tblLowQty').style.display = 'none';
		document.getElementById('tblHighQty').style.display = 'none';
	}
}

