// 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;
}




// JavaScript Document

sfHover = function() {
	//ensure that the element is on the page, if so ... run function
	var navone = document.getElementById("tpnv");
	if (navone){
		var tpnvli = document.getElementById("tpnv").getElementsByTagName("LI");

		for (var i=0; i<tpnvli.length; i++) {
			tpnvli[i].onmouseover=function() {
				this.className+=" sfhover";
				//selectsVisibility('hidden');
				//hideselects('hidden');

			}
			tpnvli[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				//selectsVisibility('visible');
				//hideselects('visible');
			}
		}
	}
}


sfHover1 = function() {
	//ensure that the element is on the page, if so ... run function
	var navtwo = document.getElementById("cnv");
	if (navtwo){
		var sfEls1 = document.getElementById("cnv").getElementsByTagName("LI");
		for (var i=0; i<sfEls1.length; i++) {
			sfEls1[i].onmouseover=function() {
				this.className+=" sfhover";
				//selectsVisibility('hidden');
				//hideselects('hidden');
			}
			sfEls1[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				//selectsVisibility('visible');
				//hideselects('visible');
			}
		}
	}
}

sfHover2 = function() {
	//ensure that the element is on the page, if so ... run function
	var navthree = document.getElementById("lnv");
	if (navthree){
		var sfEls2 = document.getElementById("lnv").getElementsByTagName("LI");
		for (var i=0; i<sfEls2.length; i++) {
			sfEls2[i].onmouseover=function() {
				this.className+=" sfhover";
				//selectsVisibility('hidden');
				//hideselects('hidden');
			}
			sfEls2[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				//selectsVisibility('visible');
				//hideselects('visible');
			}
		}
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", sfHover);
	window.attachEvent("onload", sfHover1);
	window.attachEvent("onload", sfHover2);
}
function selectsVisibility(state){
	 for(i=0;i<document.forms.length;i++){ // if there are forms on the page
		 frm = document.forms[i];
		 var inputs = frm.getElementsByTagName("SELECT");
		 for (j=0;j<inputs.length;j++){
			inputs[j].style.visibility = state;
		 }
	 }
}



if (navigator.appVersion.substr(22,3) > "6.0") {
	sfHover = function() {
		var sfEls = document.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	
} else {

	sfHover = function() {
		// Support the standard nav without a class of nav.
		var el = document.getElementById("cnv");
		if(!/\bnav\b/.test(el.className) && el.tagName == "UL")
			setHover(el);

		// Find all unordered lists.
		var ieNavs = document.getElementsByTagName('ul');
		for(i=0; i<ieNavs.length; i++) {
			var ul = ieNavs[i];
			// If they have a class of nav add the menu hover.
			if(/\bnav\b/.test(ul.className)){					
				setHover(ul);
			}
		}
	}

	function setHover(nav) {
		var ieULs = nav.getElementsByTagName('ul');
		if (navigator.appVersion.substr(22,3)!="5.0") {
			// IE script to cover <select> elements with <iframe>s
			
			for (j=0; j<ieULs.length; j++) {
				var ieMat=document.createElement('iframe');
				if(document.location.protocol == "https:"){
					ieMat.src="";					
				}else if(window.opera != "undefined"){
					ieMat.src="";
					
				}else{
					ieMat.src="javascript:false";
				}
				ieMat.scrolling="no";
				ieMat.frameBorder="0";
				
				ieMat.style.width=ieULs[j].offsetWidth+"px";
				ieMat.style.height=ieULs[j].offsetHeight+"px";
				ieMat.style.zIndex="-1";
				ieULs[j].insertBefore(ieMat, ieULs[j].childNodes[0]);
				ieULs[j].style.zIndex="101";
			}
			
			// IE script to change class on mouseover
			var ieLIs = nav.getElementsByTagName('li');
			for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
				// Add a sfhover class to the li.
				ieLIs[i].onmouseover=function() {
					if(!/\bsfhover\b/.test(this.className))
						this.className+=" sfhover";
				}
				ieLIs[i].onmouseout=function() {
					if(!this.contains(event.toElement))
						this.className=this.className.replace(' sfhover', '');
				}
			}
		} else {
			// IE 5.0 doesn't support iframes so hide the select statements on hover and show on mouse out.
			// IE script to change class on mouseover
			var ieLIs = document.getElementById('nav').getElementsByTagName('li');
			for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
				ieLIs[i].onmouseover=function() {this.className+=" sfhover";hideSelects();}
				ieLIs[i].onmouseout=function() {this.className=this.className.replace(' sfhover', '');showSelects()}
			}
		}
	}

	// If IE 5.0 hide and show the select statements.
	function hideSelects(){
		var oSelects=document.getElementsByTagName("select");
		for(var i=0;i<oSelects.length;i++)
			oSelects[i].className+=" hide";
	}

	function showSelects(){
		var oSelects=document.getElementsByTagName("select");
		for(var i=0;i<oSelects.length;i++)
			oSelects[i].className=oSelects[i].className.replace(" hide","");
	}

	// Run this only for IE.
	if (window.attachEvent){  window.attachEvent('onload', sfHover);
	}
}
// end
// End of file