function selectCat( catId , catDesc) {
  var form = document.catFormU;
  var formName = form.formName.value;
  var itemName = form.itemName.value;
  var refreshURL = form.refreshURL.value;
  var typefilter = form.typeFilter.value;
  var excludeTree = form.excludeTree.value;
  var descReturn = form.descReturn.value;
  var url;

  if (formName == '') {
    url = refreshURL + "?" + itemName + "=" + catId + "#" + catId;
    opener.document.location = url;
    window.close();
  } else {
    opener.document.forms[formName].elements[itemName].value = catId;
    opener.document.forms[formName].elements[descReturn].value = catDesc;
    window.close();
  }

}
function catSearch(formName, itemName, refreshURL, typeFilter, excludeTree, descReturn) {
  var url = '/cgi-bin/db_client.exe/CATEGORY.SEARCH?formName=' + formName;
  url = url + "&itemName=" + itemName;
  url = url + "&refreshURL=" + refreshURL;
  url = url + "&typeFilter=" + typeFilter;
  url = url + "&excludeTree=" + excludeTree;
  url = url + "&descReturn=" + descReturn;
  var x = window.open(url, 'catSearch','scrollbars=yes,status=no,width=550,height=500');
}
function findProduct() {
  var url = '/cgi-bin/db_client.exe/CWA.PART.LOOKUP';
  var x = window.open(url, 'partSearch','scrollbars=yes,status=no,width=550,height=550');
}
function updateImageFile(productid,checksum) {
  var url = '/adminasp/updateImageFile.asp?productid=' + productid + '&checksum=' + checksum;
  var x = window.open(url, 'imgUploadWindow','scrollbars=yes,status=no,width=400,height=350');
}
function removeLink( whichLink ) {
  if (confirm("Are you sure that you want to remove this link?")) {
    if (document.addProductForm) {
      document.addProductForm.elements['linkTableName' + whichLink].value = '';
      document.addProductForm.elements['linkTableUrl' + whichLink].value = '';
    }
  }
}
function removeImageFile(productid,checksum) {
  var form = document.addProductForm;
  if (confirm("Are you sure that you want to remove the image for this product?")) {
     form.removeFlag.value = "true";
     form.submit();
  }
}
function jSearch() {
  self.location='/cgi-bin/db_client.exe/CATALOG.BROWSE?searchtext=' + document.mainForm.searchtext.value;
  return;
}
function loginUser() {
  var userid = document.loginForm.userid.value;
  var password = document.loginForm.password.value;
  var url = '/cgi-bin/db_client.exe/CUST.LOGIN?userid=' + userid + "&password=" + password;
  if (userid == "") {
    alert("Please enter a valid userid."); 
	document.loginForm.userid.focus();
	return false;
  }
  if (password == "") {
    alert("Please enter a valid password.");
	document.loginForm.password.focus();
	return false;
  }
  //var x = window.open( url, 'loginWindow', 'width=500,height=400,scrollbars=no,');
  return true;
}
function prodjump() {
  var catid = document.jumpForm.jumpcat[document.jumpForm.jumpcat.selectedIndex].value;

  self.location='/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=' + catid;
  return;
}
function topMenu( b_name ) {
  switch (b_name) {
    case 'button1':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002678';
    break;
    case 'button2':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002680';
    break;
    case 'button3':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002782';
    break;
    case 'button4':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002694';
    break;
    case 'button5':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002690';
    break;
    case 'button6':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002692';
    break;
    case 'button7':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002684';
    break;
    case 'button8':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002682';
    break;
    case 'button9':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002688';
    break;
    case 'button10':
      document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=1*002686';
    break;
    case true:
      alert( b_name );
    break;
  }
}
function brands(){
  document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=brands';
}
function servers(){
  document.location = '/cgi-bin/db_client.exe/CATALOG.BROWSE?catid=brands';
}
function validateUSNumber( item ) { 
 var CleanedString=""; 
 var index = 0; 
 var LimitCheck; 
 var InitialString = item.value

 if (item.value == '') return true;

 //Get the length of the inputted string, to know how many characters to check
 LimitCheck = InitialString.length;
 
 //Walk through the inputted string and collect only number characters, appending them to CleanedString
 while (index != LimitCheck) { 
  if (isNaN(parseInt(InitialString.charAt(index)))) { } 
  else { CleanedString = CleanedString + InitialString.charAt(index); } 
  index = index + 1; 
 }
 
 //If CleanedString is exactly 10 digits long, then format it and allow form submission
 if (CleanedString.length == 10) { 
  item.value = CleanedString.substring(0,3) + "-" + CleanedString.substring(3,6) + "-" + CleanedString.substring(6,10); 
 }
 
 //If CleanedString is not 10 digits longs, show an alert and cancel form submission
 else { 
  CleanedString = InitialString; 
  alert("Please enter only your ten digit phone number.");
  if (document.all) { 
    item.focus();
    item.select();
  }
 return false
 } 
} 
function viewOrder( type, options, orderid ) {
  var url='/cgi-bin/db_client.exe/VIEW.ORDER?type=' + type + '&options=' + options + '&orderid=' + orderid;
  var x = window.open( url, 'orderWindow', 'width=600,height=550,scrollbars=yes');
}
function refreshOpener() {
  if (opener) {
    opener.history.go(0);
    window.focus();
  }
  return;
}
function addItemToQuickList( item, qty ) {
  var url='/cgi-bin/db_client.exe/QLIST.ADD?item=' + item + '&qty=' + qty;
  var x = window.open( url, 'QuickWindow', 'width=400,height=400,scrollbars=no');
}
function stext() {
  if (document.mainForm) {
    if (document.mainForm.searchtext) {
      if (document.mainForm.searchtext.value == '') {
        document.mainForm.searchtext.value = 'Keyword, Part #, UPC';
      }
    }
  }
}
function stextCheck() {
      if ( document.mainForm.searchtext.value == 'Keyword, Part #, UPC') {
        document.mainForm.searchtext.value = ''; 
      }
}
function sendSText(val){
  var url = "/cgi-bin/db_client.exe/CATALOG.BROWSE?searchtext=" + escape(val);
  document.location = url;
}
function maintainWebUser( edituser, cid ) {
  var url='/cgi-bin/db_client.exe/WEB.USER.MAINT?edituser=' + edituser + '&cid=' + cid;
  var x = window.open( url, 'userMaintWindow', 'width=400,height=400,scrollbars=no');
}
function registerWindow() {
  newLoc = "/cgi-bin/db_client.exe/CTO.REGISTER?fromcart=1";
  newPop = window.open(newLoc,"newreg","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=560,height=460");
  newPop.focus();
}
function addEditProduct(catid, productid) {
  var url='/adminasp/addEditProduct.asp?catid=' + catid + '&productid=' + productid;
  var x = window.open( url, 'addEditWindow', 'width=550,height=500,scrollbars=yes');
}
