function jsTextBanner() {
 var bannerText = '&nbsp;';
// var bannerText = '<div style="display:inline;color:red;font-size:8pt;font-weight:bold;">&bull;&bull; ######### &bull;&bull;</div>';
// var bannerText = '<div style="display:inline;color:red;font-size:8pt;font-weight:bold;">&bull;&bull; We are experiencing an unusually high call volume. We apologize for any delay in response. &bull;&bull;</div>';
 document.write(bannerText);}

function AddOnloadFunction(func) {
	if(window.onload) {
		var oldfunc = window.onload;
		window.onload = function() { 
			oldfunc(); 
			func(); 
		};
	}
	else {
		window.onload = func;
	}
}

function owImageCheck(img) {
	if (!img.complete) {
		return false;
	}
	if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
		return false;
	}
	return true;
}

function pnaReplace() {
	var badImage = new Image();
	var pnaLarge = location.protocol + '//store.officeworld.com/productimages/pnastandard.jpg';
	var pnaSmall = location.protocol + '//store.officeworld.com/productimages/pnathumbnail.jpg';
	for (var i=0; i < document.images.length; i++) {
		if (!owImageCheck(document.images[i])) {
			var imageSrc = document.images[i].src.toLowerCase();
			if (imageSrc.indexOf('productimages/united/standard/') > 0) {badImage.src = pnaLarge;}
			else if (imageSrc.indexOf('productimages/') > 0) {badImage.src = pnaSmall;}
			else {continue;}
			document.images[i].src = badImage.src;
		}
	}
}

function jsRenderManufacturerList(first_opt,type) {
 if (type == 'advsearch') {document.write('<SELECT NAME="Manufacturer"><OPTION VALUE="">'+first_opt+'</OPTION>');}
 else {document.write('<SELECT NAME="ManufacturerDropDown" ONCHANGE="if(this.value!=\'\'){jsAction(\'Search.asp?SearchCommand=AdvancedSearch\')}"><OPTION VALUE="">'+first_opt+'</OPTION>');}
 for (var i=0;i<manufacturers.length-1;i++) {var opt_str = '<OPTION VALUE="'+manufacturers[i]+'">'+manufacturers[i]+'</OPTION>'; document.write(opt_str);}
 document.write('</SELECT>');}

function jsRenderCategoryList(first_opt,type) {
 if (type == 'advsearch') {document.write('<SELECT NAME="ProductGroupID"><OPTION VALUE="">'+first_opt+'</OPTION>');}
 else {document.write('<SELECT NAME="category" ONCHANGE="javascript:jsProductGroup2ndLevel(document.rootform.category.options[document.rootform.category.selectedIndex].value, \'False\',\'\',\'\')"><OPTION VALUE="">'+first_opt+'</OPTION>');}
 for (var i=0;i<categories.length-1;i++) {
  var opt_value = categories[i].split(":")[0];
  var opt_text = categories[i].split(":")[1];
  var opt_str = '<OPTION VALUE="'+opt_value+'">'+opt_text+'</OPTION>'; document.write(opt_str);}
 document.write('</SELECT>');}

function jsRenderFooter() {
 document.write(''+
 '<div align=center class=footer>'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=siteuse\')" CLASS=small>Site Terms of Use</A>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=privacy\')" CLASS=small>Privacy Policy</A>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=terms\')" CLASS=small>Terms and Conditions</A>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=copyright\')" CLASS=small>Copyright Notice</A>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=corporate\')" CLASS=small>Corporate Information</A>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;'+
 '<A HREF="javascript:jsAction(\'support.asp?supporttype=security\')" CLASS=small>Site Security Information</A>'+
 '</div>');}

function jsChatLink(cssClass,linkText) {document.write('<a class="'+cssClass+'" href="http://server.iad.liveperson.net/hc/LPofficeworld/?SESSIONVAR!skill=General&cmd=file&file=visitorWantsToChat&site=LPofficeworld&byhref=1" TARGET="chatLPofficeworld" ONCLICK="window.open(\'http://server.iad.liveperson.net/hc/LPofficeworld/?SESSIONVAR!skill=General&cmd=file&file=visitorWantsToChat&site=LPofficeworld\',\'chatLPofficeworld\',\'width=472,height=320\');return false;">'+linkText+'</a>');}


function jsFilterKeyWord(s)
{
	s = s.replace(/[^ a-z0-9.:'$%\-\/]+/gi," ");
	//--------------------------------------------------
	var re1, re2;
	re1 = /\b[a-z]{3}-[a-z0-9\-]{1,12}\b/i;
	re2 = /[0-9]/;
	if (re1.test(s)) {
		var str1, str2;
		str1 = s.match(re1)[0];
		if (re2.test(str1)) {
			str2 = str1.replace(/-/g,"");
			s = s.replace(str1,str2);
		}
	}
	//--------------------------------------------------
	s = s.replace(/ +/gi," ");
	s = s.replace(/(^\s*|\s*$)/gi,"");
	//--------------------------------------------------
	return s;
}

function jsChooseProduct(prod, idx, subIdx, isSub)
{
	var form = 'document.rootform';

	if(isSub)	//replace the fields with sub fields
	{
		form.elements['ProductID' + String(idx)].value = form.elements['SubProductID' + subIdx].value;
		form.elements['VendorID' + String(idx)].value = form.elements['SubVendorID' + subIdx].value;
		form.elements['ContractFlag' + String(idx)].value = form.elements['SubContractFlag' + subIdx].value;
		form.elements['ContractID' + String(idx)].value = form.elements['SubContractID' + subIdx].value;
		form.elements['PriceSource' + String(idx)].value = form.elements['SubPriceSource' + subIdx].value;
		form.elements['CustomerProductID' + String(idx)].value = form.elements['SubCustomerProductID' + subIdx].value;
		form.elements['UOM' + String(idx)].value = form.elements['SubUOM' + subIdx].value;
		form.elements['Price' + String(idx)].value = form.elements['SubPrice' + subIdx].value;
		form.elements['UniquenessID' + String(idx)].value = form.elements['SubUniquenessID' + subIdx].value;
		form.elements['FromUniquenessID' + String(idx)].value = form.elements['SubFromUniquenessID' + subIdx].value;
		form.elements['FromProductID' + String(idx)].value = form.elements['SubFromProductID' + subIdx].value;
	}
	else		//restore the fields from the original copy
	{
		form.elements['ProductID' + String(idx)].value = form.elements['_ProductID' + idx].value;
		form.elements['VendorID' + String(idx)].value = form.elements['_VendorID' + idx].value;
		form.elements['ContractFlag' + String(idx)].value = form.elements['_ContractFlag' + idx].value;
		form.elements['ContractID' + String(idx)].value = form.elements['_ContractID' + idx].value;
		form.elements['PriceSource' + String(idx)].value = form.elements['_PriceSource' + idx].value;
		form.elements['CustomerProductID' + String(idx)].value = form.elements['_CustomerProductID' + idx].value;
		form.elements['UOM' + String(idx)].value = form.elements['_UOM' + idx].value;		
		form.elements['Price' + String(idx)].value = form.elements['_Price' + idx].value;
		form.elements['UniquenessID' + String(idx)].value = form.elements['_UniquenessID' + idx].value;
		form.elements['FromUniquenessID' + String(idx)].value = form.elements['_FromUniquenessID' + idx].value;
		form.elements['FromProductID' + String(idx)].value = form.elements['_FromProductID' + idx].value;
	}
}

function jsValidateQuantity(idx)
{
	var quantity
	quantity = eval("document.rootform.Quantity" + idx.toString()).value 

	if (quantity.toString()!='')
	{
		if(isNaN(quantity)||quantity != parseInt(quantity) || quantity < 1 )
		{
			eval("document.rootform.Quantity" + idx.toString()).value = ""
			eval("document.rootform.Quantity" + idx.toString()).focus()
		}
	}
}

function jsAddToShoppingList(ProductId, VendorId, Qidx)
{
	if (document.rootform.owIsGuest)
	{
		alert('To add this item to a shopping list, please [ login ] or [ register ] as a new user.');
		return;
	}

	var Quantity = eval("document.rootform.Quantity" + Qidx.toString()).value

	win = window.open("", "", "height=250, width=300")

	win.document.open('text/html')
	win.document.write("<html><head><scr"+"ipt type='text/javascript' src='//store.officeworld.com/js/globalFx.js'></scr"+"ipt></head><body style='margin:15px;text-align:left;'>")
	win.document.write("<LINK REL=STYLESHEET TYPE=\"text/css\" HREF=\"" + document.rootform.owStyleSheet.value + "\">");
	win.document.write("<form action = \"AddToList.asp\" method = \"post\" name=MainForm>");
	win.document.write("<div style='font-weight:bold;font-size:10pt;'>Select the list to add this product to:</div><br>");
	win.document.write("<Select Name = \"ShoppingList\" onChange=\"document.MainForm.submit()\">");
	win.document.write("<Option value=\"\" Selected>Please Choose</Option>");

	var iLen
	iLen =  document.rootform.ShoppingList.options.length;
	
	for (i = 1; i < iLen; ++i)
	{
		if (document.rootform.ShoppingList.options[i].value!=''&& document.rootform.ShoppingList.options[i].value!='NewList')		
		{
			win.document.write("<Option value=\"" + document.rootform.ShoppingList.options[i].value + "\">"  + document.rootform.ShoppingList.options[i].text + "</OPTION>");
		}
	}
	win.document.write("</Select><br><br><br>")
	win.document.write("<div style='font-weight:bold;font-size:10pt;'>Or, add this product to a <i>new</i> list:</div><br>")
	win.document.write("<input name=\"NewListName\">&nbsp;&nbsp;<a class=framehyperlink href='javascript:void(0)' onclick=\"jsAddToNewList();\">[ create list ]</a>")
	win.document.write("<input type=\"hidden\" value=\"" + document.rootform.ShellID.value + "\" name=\"ShellId\">")
	win.document.write("<input type=\"hidden\" value=\"" + ProductId + "\" name=\"ProductId\">")
	win.document.write("<input type=\"hidden\" value=\"" + VendorId + "\" name=\"VendorId\">")
	win.document.write("<input type=\"hidden\" value=\"" + Quantity + "\" name=\"Quantity\">")	
	win.document.write("</form>")
	win.document.write("<div style='border-top:#ccccff 1px solid;padding-top:2px;margin-top:10px;'><a class=framehyperlink href=\"javascript:window.close()\">[ close window ]</a></div>")
	win.document.write("</body></html>")
	win.document.close()
}

function jsAddToNewList()
{
	var listname = document.MainForm.NewListName.value;
	listname = listname.replace(/[^ a-z0-9,\.\&]*/gi,"");
	listname = listname.replace(/\s+/gi," ");
	listname = listname.replace(/(^\s*)|(\s*$)/gi,"");
	document.MainForm.NewListName.value = listname;
	if (listname == "")
	{
		alert('Please enter a name for the shopping list you want to create.');
		document.MainForm.NewListName.focus();
		return false;
	}
	window.opener.document.rootform.action='/newshoppinglist.asp?NewListName=' + escape(listname) + '&owAddProductID=' + document.MainForm.ProductId.value;
	window.opener.document.rootform.submit();
	window.close();
}

function jsGoToShoppingList()
{ 
	if(document.rootform.ShoppingList.options[document.rootform.ShoppingList.selectedIndex].value == "")
	{
		return	
	}
	if(document.rootform.ShoppingList.options[document.rootform.ShoppingList.selectedIndex].value == "NewList")
	{
		jsAction("NewShoppingList.asp");
	}
	else
	{	
		jsAction("ShoppingList.asp?owListName=" + escape(document.rootform.ShoppingList.options[document.rootform.ShoppingList.selectedIndex].text));
	}
}

function jsSearchEnter(e)
{
	var eventInstance = window.event ? event : e;
	var unicode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;
	if (unicode == 13)
	{
		jsSearch();
	}
}

function jsSearchNew()
{
	if (document.rootform.keyword.value == 'Type SEARCH here...')
	{
		alert('1. Click in box where it reads \"Type SEARCH here...\"\n2. Type desired keyword(s)\n3. Click GO button or press enter');
		return;
	}
	jsSearch();
}

function jsSearch()
{
	var FilteredKeyWord = jsFilterKeyWord(document.rootform.keyword.value);
	document.rootform.keyword.value = FilteredKeyWord;
	jsAction("search.asp?q=" + escape(FilteredKeyWord));
}

function jsProductGroup2ndLevel(groupID, productLevelFlag, beyondValue1, beyondValue2)
{	
	jsAction('catalog.asp?' + 'ProductGroupID=' + groupID + '&ProductLevelFlag=' + productLevelFlag);
}

function jsOWPopup(theLocation,theName,theFeatures)
{
	window.open(theLocation,theName,theFeatures);
}

function jsTimeRemaining()
{
	T = new Date();
	hr = T.getHours();
	dy = T.getDay();

	if (dy > 0 && dy < 6 && hr > 12 && hr < 16) {start_counter(16,0,0,'owCDcb',' minutes left','',1,0);}
}

function jsProduct(productID, vendorID, fromUniquenessId)
{
	if (fromUniquenessId == null) {fromUniquenessId = "";}
	jsAction("product.asp?ProductID=" + productID + "&VendorID=" + vendorID + "&FromUniquenessID=" + fromUniquenessId);	
}

function jsSpecialProduct(productID, vendorID)
{
	jsAction("specialadmin.asp?ProductID=" + productID + "&VendorID=" + vendorID);	
}

function jsLookup(options, shellID)
{
	window.open("Lookup.asp?ShellID=" + shellID + "&" + options, "Lookup", "width=400,height=400,resizable=yes");
}

function jsChangeCSS(theClass,element,value)
{
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	}
	else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText.toLowerCase() == theClass.toLowerCase()) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}
}

function jsAdvancedCartLink() {
 var doAdv = jsGetCookie('ow_AdvCart');
 if (doAdv == 1) {
  document.write("<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsAdvancedCart(0);return false;\">[ hide advanced features ]</a>");
 }
 else {
  document.write("<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsAdvancedCart(1);return false;\">[ show advanced features ]</a>");
 }
}

function jsAdvancedCart(doAdv) {
 var today = new Date();
 today.setTime(today.getTime());
 var expires_date = new Date(today.getTime() + 315360000000);
 if (doAdv == 1) {
  document.cookie = "ow_AdvCart=1;path=/;domain=.officeworld.com;expires=" + expires_date;
  jsChangeCSS('.ADVANCEDCART','display','inline');
  document.getElementById('AdvCartTextButton').innerHTML = "<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsAdvancedCart(0);return false;\">[ hide advanced features ]</a>";
 }
 else {
  document.cookie = "ow_AdvCart=0;path=/;domain=.officeworld.com;expires=" + expires_date;
  jsChangeCSS('.ADVANCEDCART','display','none');
  document.getElementById('AdvCartTextButton').innerHTML = "<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsAdvancedCart(1);return false;\">[ show advanced features ]</a>";
 }
}

function jsCSImageHideLink() {
 var doHide = jsGetCookie('ow_csCartImageHide');
 if (doHide == 1) {
  document.write("<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsCSImageHide(0);return false;\">[ show product images ]</a>");
 }
 else {
  document.write("<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsCSImageHide(1);return false;\">[ hide product images ]</a>");
 }
}

function jsCSImageHide(doHide) {
 var today = new Date();
 today.setTime(today.getTime());
 var expires_date = new Date(today.getTime() + 315360000000);
 if (doHide == 1) {
  document.cookie = "ow_csCartImageHide=1;path=/;domain=.officeworld.com;expires=" + expires_date;
  jsChangeCSS('.CSCARTIMAGE','display','none');
  document.getElementById('csCartImageTextButton').innerHTML = "<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsCSImageHide(0);return false;\">[ show product images ]</a>";
 }
 else {
  document.cookie = "ow_csCartImageHide=0;path=/;domain=.officeworld.com;expires=" + expires_date;
  jsChangeCSS('.CSCARTIMAGE','display','inline');
  document.getElementById('csCartImageTextButton').innerHTML = "<a class='SMALLRED' href=\"javascript:void(0)\" onclick=\"jsCSImageHide(1);return false;\">[ hide product images ]</a>";
 }
}

function jsGetCookie(name) {
 var start = document.cookie.indexOf( name + "=" );
 var len = start + name.length + 1;
 if ((!start) && (name != document.cookie.substring(0,name.length))) {return null;}
 if (start == -1) return null;
 var end = document.cookie.indexOf(";",len);
 if (end == -1) end = document.cookie.length;
 return document.cookie.substring(len,end);
}

function jsOWCartAdd(ProductID,addQty) {
 if (!addQty || addQty == '') {addQty = 1;}
 window.location = "/quickorder.asp?ShellID=" + document.rootform.ShellID.value + "&ProductID1=" + ProductID + "&Quantity1=" + addQty + "&pagecommand=updateview";
}

function jsTrimString(s,scrubType) {
 if (scrubType == 1) {
  s = s.replace(/\s*/gi,"");
 }
 if (scrubType == 2) {
  s = s.replace(/[^a-z0-9]/gi,"");
 }
 else {
  s = s.replace(/(^\s*)|(\s*$)/gi,"");
  s = s.replace(/[ ]{2,}/gi," ");
 }
 return s;
}

AddOnloadFunction( function() { pnaReplace(); } );
