function SetProductCookie() {
   if(document.quicksearchProduct.qs_scope[0].checked) {
    SetCookie( "productSearchCookie", document.quicksearchProduct.qs_scope[0].value);
}
else {
    SetCookie( "productSearchCookie", document.quicksearchProduct.qs_scope[1].value);
}
}


function quickSearchFormByProduct() {
   var keywd;
   first_part = "/IMD_WASWeb/jsp/search/Results_nav.jsp?";
        keywd = strip1(document.quicksearchProduct.productSearch.value);
   SetProductCookie();
   if((keywd=="") || (keywd=='\"\"')){
      if(document.quicksearchSKU.skuSearch.value!="")
      {
         alert("Enter text on left and click Find! for Product Search or enter text on right and click View! for Fast Check");
      }
      else {
         alert("Please enter a search criteria");
      }
   return;
   }
   if((document.quicksearchSKU.skuSearch.value!=""))
   {
   alert("You entered text for both the Product Search and Fast Check.  Only text for the Product Search will be processed");
   }
   if(keywd!="") {
      if (keywd.length == 1) {
                alert("Please enter a keyword which is more than one character");
                return;
        }
      scp = document.quicksearchProduct.qs_scope[0].value;
      if(document.quicksearchProduct.qs_scope[0].checked){
         winLoc = first_part + "keywords="+keywd+"&scope=1";
      }  //search on Product
      if(document.quicksearchProduct.qs_scope[1].checked){
         winLoc = first_part + "keywords="+keywd+"&scope=3";
      }
   }
        parent.location.href = winLoc;      
}

function SetSKUCookie() {

   if(document.quicksearchSKU.qc[0].checked) {
       SetCookie( "fastCheckCookie", document.quicksearchSKU.qc[0].value);
   }
   else {
       SetCookie( "fastCheckCookie", document.quicksearchSKU.qc[1].value);
   }
}

function quickSearchFormByNumber() {
   var keywd;
   var winLoc ="";
   first_part = "/IMD_WASWeb/jsp/search/Results_nav.jsp?";
   keywd = strip1(document.quicksearchSKU.skuSearch.value);
   SetSKUCookie();
   if((keywd=="") || (keywd=='\"\"')){
      if(document.quicksearchProduct.productSearch.value!="")
      {
         alert("Enter text on left and click Find! for Product Search or enter text on right and click View! for Fast Check");
      }
      else {
         alert("Please enter a search criteria");
      }
   return;
   }


   if((document.quicksearchProduct.productSearch.value!=""))
   {
      alert("To find products, enter keywords in the left text box and click Find! \nTo check price or view TechNotes, enter SKUs in the right text box and click View!");
   
   }
   scp = document.quicksearchSKU.qc.value;
   if(document.quicksearchSKU.qc[0].checked){
   keywd = StripSpace4(keywd)
   winLoc = "/IMD_WASWeb/jsp/order/panda_nav.jsp?skus=" + keywd;
   }


   if(document.quicksearchSKU.qc[1].checked){


   // Check if 2 nd Radio Button is selected then User enters numeric value:

   var strint =  document.quicksearchSKU.skuSearch.value  ;
   var flagint =  true ;
 
         for (var i = 0; i < strint.length ; i++) {
                        
                if (((strint.charAt(i) > '9') || (strint.charAt(i) < '0')) && strint.charAt(i) != ' ')
                        flagint = false;

         }

    if (flagint == false)
    {
     trint = strint.toUpperCase();
     //alert("To search for a TechNote, please enter the Ingram Micro SKU for the product.\n If you don't know the SKU, use Product Search to locate the product by keyword.") ;
    //  return;      
    }

   quickNotesHdr(document.quicksearchSKU.skuSearch.value);
  
   return;      
   }   
        parent.location.href = winLoc;

}

function StripSpace4(inStr) {
   var outStr = "";
   for(var idx =0; idx<inStr.length;idx++) {
                var oneChar = inStr.charAt(idx);

                if (oneChar == "+") outStr += "\',\'";
                else if (oneChar != " ") outStr += oneChar; 
   }
      if (outStr != "") outStr = "\'" + outStr + "\'";
        return outStr;
}

function stripSpace3(inStr) {
        var outStr = "";
        var aSpace = false;

        for (var idx = 0; idx< inStr.length; idx++) {
                var oneChar = inStr.charAt(idx);

                if (oneChar == " ") outStr += "','";
                else if (oneChar != " ") outStr += oneChar;

                else {
                        alert("I can't find this");
                        return "";
                        }
                }
        if (outStr != "") outStr = "'" + outStr + "'";
        return outStr;
}

function strip1(inval) {
        retval = "";
        for (idx = 0; idx < inval.length; idx++) {
                var oneChar = inval.charAt(idx);

                if ((oneChar == " ") || (oneChar==",")) {
          retval = retval + "+";
                } 
                else if (oneChar == "+") {
          retval = retval + "%2B";
                } 
                else if (oneChar == "#") {
          retval = retval + "%23";
                } 
      else retval = retval + oneChar;
                }
        return retval;
}

function replaceSubstring(inputString, fromString, toString) {
var tempString = inputString;
for(var i=0;i<inputString.length;i++) {tempString = tempString.replace(fromString,toString);}
return tempString;
} 


function quickNotesHdr(inStr) {
         if (inStr == "") return;        
           //jumpTo = "/WP/TARGET/1,,,00.html?webpub_path=/webpub.iw?" +escape("$Product=ECTest&$Request=notes&doNotes=Y&$Lookup=" + inStr.substring(0,6));
  jumpTo = "/IMD_WASWeb/jsp/technote/displaytechnote.jsp?sku=" + inStr.substring(0,6).toUpperCase();;
           //jumpTo = "/technote/ext/1,,0,00.html?incjsp=displaytechnote.jsp&sku=" + replaceSubstring(inStr, " ", ",");;
          // if (inStr.length > 7) jumpTo += "%26moreSkus=" + escape(inStr);
                location.href = jumpTo;
}

function searchBarFormSubmit() {
  var keyword=searchBarForm.searchKeyword.value;
  if(isEmpty(keyword) || keyword == 'Keywords or Sku/Mfg#' || trim(keyword).length == 0) {
    alert('Please provide non empty keyword(s) to search the catalog.');
    return false;
  } else {
    document.searchBarForm.submit();
  }
}

function isEmpty (text) {
  if (text) return !/\S/.test(text);
  return true;
}

function trim(s) {
  // Trim whitespace from left and right sides of s.
  return s.replace(/^\s*/,'').replace(/\s*$/,'');
}