var url = window.location.href;var dbPos = url.indexOf(thisDB);url = url.substring(0, dbPos );isIE=document.all;isNN=!document.all&&document.getElementById;isN4=document.layers;isOp = (window.top.navigator.userAgent.indexOf('Opera') >= 0) ? 1 : 0;var jdebug;if (jdebug == '') {jdebug = false}function doAddToCart(doc, quick) {if (getCookie('ShopCust') == '') setShopCookie();showSection("ProcessingBox");var theitems = docvar qtext = '';if (quick) qtext = '&quick=true';var addurl = thisDB + '/Add+to+Basket+by+Id?OpenAgent&id=' + theitems + qtext + '&Ref=' + path + '-closeme';//alert(addurl);//if (jdebug) alert(addurl);window.document.getElementById('addtocart').src = addurl;}function directAddToCart(doc) {if (getCookie('ShopCust') == '') setShopCookie();var theitems = docvar qtext = '';var addurl = thisDB + '/Add+to+Basket+by+Id?OpenAgent&id=' + theitems  + qtext + '&Ref=' + path;window.location.href = addurl;}function addToCart(doc) {doAddToCart(doc, false);}function addToCartQuick(doc) {doAddToCart(doc, true);}function removeFromCart() {showSection("RemoveBox");var removeurl = thisDB + '/Remove+from+Basket?OpenAgent&UNID=' + docunid + shopcookie + '&Ref=' + path;window.document.getElementById('addtocart').src = removeurl;//hideSection("ProcessingBox")//window.location.reload();}function reloadMe() {//window.location.reload();//window.document.forms[0].BasketClick.click();window.location.href = 'http://www3.best-in-class.com/bestp/domrep.nsf/Basket?OpenForm&ref=' + window.location.href;}function sectionIsHidden(sectionid) { if (isIE||isNN) {alert(window.document.getElementById(sectionid).style.display);}  else if (isN4) {alert(window.document.getElementById(sectionid).display);}}function showSection(section){ if (isIE||isNN) {window.document.getElementById(section).style.display="block";}  else if (isN4) {window.document.getElementById(section).display="block";}}function hideSection(section){  if (isIE||isNN) window.document.getElementById(section).style.display="none";  else if (isN4) window.document.getElementById(section).display="none";}function Login() {var url = window.location.href + '&Login';window.location.href = url}function dLink(id) {//isMember is computed on the SubjectBrowse formif (isMember) {//return link for member to test agentreturn url + thisDB + '/Content/' + id + '!OpenDocument&Login=1';//return url + thisDB + '/Test!OpenAgent&Exp=' + id + '&Login=1';}else if (thisDB == "/bestpsub/domrep2.nsf"){return url + thisDB + '/Content/' + id + '!OpenDocument';//return url + thisDB + '/Test!OpenAgent&Exp=' + id;}else if (window.location.href.toLowerCase().indexOf('itemlookup')>0) {return url + thisDB + '/ItemLookup/' + id + '!OpenDocument';}else{//return link for nonmemberreturn url + thisDB + '/Non-Member/' + id + '!OpenDocument';}}var cartEdit;cartEdit = '';var hideCartAndCheckbox;if (hideCartAndCheckbox == '') 	hideCartAndCheckbox = false;function showCartCheckbox(itemNumber) {if (itemInCart(itemNumber) || isMember || hideCartAndCheckbox) {return '"display:none; visibility:hidden"">'; }else{ return '>'; }}function showCartIcon(itemNumber) {if (!itemInCart(itemNumber) || isMember || hideCartAndCheckbox) {return '"display:none; visibility:hidden"">';}else{ return '>'; }}function checkRolesMatch(roles) {match = false;//alert(jdebug);for (i=0; i<roles.length; i++) {	for (r=0; r<curRoles.length; r++) {		if (roles[i] == curRoles[r]) {			match = true;			break;		}	}	if (match == true) break;}return match;}function showCartCheckboxRoles(itemNumber, roles) {eval('var rolearray = new Array("' + replaceSubstring(roles, ' ', '" "') + '")');rolesMatch = checkRolesMatch(rolearray);//alert(itemNumber + " " + rolesMatch);if (itemInCart(itemNumber) || rolesMatch || hideCartAndCheckbox) {return '"display:none; visibility:hidden"">'; }else{ return '>'; }}function showCartIconRoles(itemNumber, roles) {eval('var rolearray = new Array("' + replaceSubstring(roles, ' ', '" "') + '")');rolesMatch = checkRolesMatch(rolearray);if (!itemInCart(itemNumber) || rolesMatch || hideCartAndCheckbox) {return '"display:none; visibility:hidden"">';}else{ return '>'; }}function cartCheck(isChecked, itemNumber) { if (!isChecked) { 	itemRemove(itemNumber); }else{ 	itemAdd(itemNumber); }}function itemInCart(itemNumber) { if (cartItems.indexOf(itemNumber + ",") >=0){ 	return true; }else{ 	return false; }}function itemRemove(removeItem) {	if (cartEdit.indexOf(',') == -1){		cartEdit = '' ;	}else{		cartEdit += ',';		cartEdit = replaceSubstring(cartEdit, removeItem + ',', '');		cartEdit = cartEdit.substring(0, cartEdit.length -1 );	}}function itemAdd(addItem) {	if (cartEdit.indexOf(addItem) == -1){		if (cartEdit == '') {			cartEdit = addItem;		}else{			cartEdit += ',' + addItem;		}	}else{		//do nothing -- the item is already in the cart	}}function replaceSubstring(inputString, fromString, toString) {   // Goes through the inputString and replaces every occurrence of fromString with toString   var temp = inputString;   if (fromString == "") {      return inputString;   }   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)      while (temp.indexOf(fromString) != -1) {         var toTheLeft = temp.substring(0, temp.indexOf(fromString));        var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);         temp = toTheLeft + toString + toTheRight;      }   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop      var midStrings = new Array("~", "`", "_", "^", "#");      var midStringLen = 1;      var midString = "";      // Find a string that doesn't exist in the inputString to be used      // as an "inbetween" string      while (midString == "") {         for (var i=0; i < midStrings.length; i++) {            var tempMidString = "";            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }            if (fromString.indexOf(tempMidString) == -1) {               midString = tempMidString;               i = midStrings.length + 1;            }         }      } // Keep on going until we build an "inbetween" string that doesn't exist      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string      while (temp.indexOf(fromString) != -1) {         var toTheLeft = temp.substring(0, temp.indexOf(fromString));         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);         temp = toTheLeft + midString + toTheRight;      }      // Next, replace the "inbetween" string with the "toString"      while (temp.indexOf(midString) != -1) {         var toTheLeft = temp.substring(0, temp.indexOf(midString));         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);         temp = toTheLeft + toString + toTheRight;      }   } // Ends the check to see if the string being replaced is part of the replacement string or not   return temp; // Send the updated string back to the user} // Ends the "replaceSubstring" functionfunction Trim(str){  if (str == null )  {   return ""  }   var first =0   while(str.charAt(first)==" ")    {       first++    }    var last=str.length    if(first==last)    {       return ""    }    while(str.charAt(last-1)==" ")     {       last--     }     return str.substring(first,last)   //f.DepartmentName.value=f.DepartmentName.value.substring(first,last)}
