// General Search Functions


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/////////////////////////////////
// Strips spaces from a string //
////////////////////////////////
function strip(inval) {
    retval = "";
    for (idx = 0; idx < inval.length; idx++) {
      var oneChar = inval.charAt(idx);
      if (oneChar != " ") retval = retval + oneChar;
      else retval = retval + "";
    }
    return retval;
}



function replace_commaspace_with_plus(skulist) {

 var new_skulist = "";
 for (ix = 0; ix < skulist.length; ix++) {

    if (skulist.charAt(ix) == ",") {
      new_skulist = new_skulist + '+';
    } else {
      new_skulist = new_skulist + skulist.charAt(ix);
    }
 }
 return new_skulist;
}



function replace_comma_with_nothing(skulist) {

 var new_skulist = "";

 

 for (ix = 0; ix < skulist.length; ix++) {

    if (skulist.charAt(ix) == ",") {

      new_skulist = new_skulist + '';

    } else {

      new_skulist = new_skulist + skulist.charAt(ix);

    }

 }

 return new_skulist;

}





function multisku(sku_num) {
  sku(sku_num);
}

//////////////////////////////
// Scope Searches 1-5
/////////////////////////////
// function sku(sku) {
      // Scope 5 not working as of June 29, 2005
//    winLoc = "/IMD_WASWeb/jsp/search/Results_nav.jsp?keywords="+strip(sku)+"&scope=3&kw_wc=0";
//    location.href = winLoc;
// }
function mfr(sku) {
  winLoc = "/IMD_WASWeb/jsp/search/Results_nav.jsp?keywords="+strip(sku)+"&scope=3";
  location.href = winLoc;
}
function technote(sku) {
  winLoc = "/IMD_WASWeb/jsp/search/Results_nav.jsp?keywords="+strip(sku)+"&scope=2";
  location.href = winLoc;
}
function keyword(sku) {
  winLoc = "/IMD_WASWeb/jsp/search/Results_nav.jsp?keywords="+strip(sku)+"&scope=1";
  location.href = winLoc;
}



//////////////////////////////////
// New sku() Search Function   //
// Aug. 20, 2007               //
/////////////////////////////////
function sku(sku,catalog,vendor,category,subcat) {

  if (sku == null) { sku = ""; }
  if (catalog == "itna" || catalog == "aidc") {
  } else {
    catalog = "itna";
  }
  if (vendor != null) { vendor = "&vendorId="+vendor; } else { vendor = ""; }
  if (category != null) { category = "&imCatCode="+category; } else { category = ""; }
  if (subcat != null) { subcat = "&imSubCatCode="+subcat; } else { subcat = ""; }

  winLoc = "/ims/search/productSearch?searchKeyword="+strip(sku)+vendor+category+subcat+"&mode=keywordSearchMode&catalog="+catalog;
  location.href = winLoc;
  
}



function allSearch(inStr, fields, callFrom) {



        //alert("in allSearch!");

        if (inStr == "") return;        



        if (callFrom=="V")

        {

                    

            var strVendorCode ="";

            inStr = unescape(inStr);

 

             for (ix = 0; ix < inStr.length; ix++) {

                if (inStr.charAt(ix) == '\"') {

                    strVendorCode = strVendorCode;

                } else {

                  strVendorCode = strVendorCode + inStr.charAt(ix);

                }

             }



            strVendorCode= replace_comma_with_nothing(strVendorCode);

            jumpto = "?svendor="+  strVendorCode;

            location.href = "/IMD_WASWeb/jsp/search/Results_nav.jsp"+ jumpto;   

        

        }

        else

        {           

            inStr= strip(replace_commaspace_with_plus(inStr));

            jumpto = "?keywords="+  inStr+"&scope=3" ;

            location.href = "/IMD_WASWeb/jsp/search/Results_nav.jsp"+ jumpto;

        }       

}









function openPage(cma0,cma1,cma2,cma3) {

  // Get the current URL
  var current_url = location.href;

  // A regular expression to check if we're in the reseller/content template
  var reseller_content = new RegExp ("reseller/content");

  // A pattern to check if we're in the maufacturer details
  var mfr_content = new RegExp("manufacturer/details");

  // Check to see if the function is requesting anchor links
  var see_anchor = new RegExp ("#");
  for (i=0; i < openPage.arguments.length; i++) {
    if (see_anchor.exec(openPage.arguments[i])) {
      var current_anchor = openPage.arguments[i];
      openPage.arguments[i] = null;
      openPage.arguments.length -= 1;
    } else {
      var current_anchor = "";
    }
  }

  // If the function requests only one CMA ID
  // AND we're not in the manufacturer details template
  // it's an easy swap ...
  if ( openPage.arguments.length < 2 && mfr_content.test(current_url) == null ) {

    new_href= current_url.replace(/([^,]*),.*,([0-9]*)([,_].*)/, '$1,,' + cma0 + '$3');

  // other wise you gotta check for multiple CMA IDs and swap out what you will ...
  } else {

    // a pattern to check multiple CMA IDs
    var content_path = new RegExp ("(.*[^,]),.*,([0-9]*)(_[0-9]*)?(_[0-9]*)?(_[0-9]*)?(,00\.html)");
    // template elemenet will store the path, whether that be /reseller/content or /us/ or whatever
    var template_element = "$1";
    // if we're in the manufacturer details template, we'll open pages into reseller/content
    if (mfr_content.exec(current_url)) {
        template_element = "/reseller/content/0";
    }
    // last_element will store the ,00.html info
    var last_element = "$6";

    // Chunk out the current URL into a pattern with multiple elements and store them within an array
    var myreg = content_path.exec (current_url);

    // Check to see if the current URL has multiple CMA IDs
    if (!(myreg[3])) { myreg[3] = ""; }
    if (!(myreg[4])) { myreg[4] = ""; }
    if (!(myreg[5])) { myreg[5] = ""; }

    // Check to see if the function call is loading multiple CMA IDs
    if (cma1) { cma1 = "_" + cma1; } else { cma1 = myreg[3]; }
    if (cma2) { cma2 = "_" + cma2; } else { cma2 = myreg[4]; }
    if (cma3) { cma3 = "_" + cma3; } else { cma3 = myreg[5]; }

    // Check to see if the function call desires blank/none template elements
    if (cma0 == "none") { cma0 = "_"; }
    if (cma1 == "_none") { cma1 = "_"; }
    if (cma2 == "_none") { cma2 = "_"; }
    if (cma3 == "_none") { cma3 = "_"; }

    // Check to see if the function call is loading the same CMA IDs
    if (cma0 == "same") { cma0 = myreg[2]; }
    if (cma1 == "_same") { cma1 = myreg[3]; }
    if (cma2 == "_same") { cma2 = myreg[4]; }
    if (cma3 == "_same") { cma3 = myreg[5]; }

    // Create a new URL based on the above
    new_href= current_url.replace(content_path, template_element + ',,' + cma0 + cma1 + cma2 + cma3 + last_element);
  }

  // Drop the mfr_code variable if we came out of manufacturer/details
  new_href = new_href.replace (/(.*)\?.*/, '$1');

  // Add the anchor to the URL
  new_href = new_href.replace (/(.*)#.*/, '$1') + current_anchor;

  // Load the new URL
  location.href = new_href;
}

// End of file