// all lookup function for Champion Crossreference

// create array listing all of the Advance part numbers
// arrays moved to partarrays.js 


// create parallel array listing all the matching values
// that correspond to the  values in the Advance array
// moved to partarrays.js


//array for mill max codes
// moved to partarrays.js

//array for Champion codes matching the mill max codes
// moved to partarrays.js

// **LOOKUP FUNCTIONS**

// ------- function searchall --------------
function searchall()
	{
	document.otherpnumber.matches.value ="Search is being performed ... Please wait. If this message persists for more than one minute, it is possible that no match was found. If you have questions, please contact us at champion@giaspn01.vsnl.net.in . ";
	var search_foundmatch = false;
	search_validmatches = new Array();
	search_validmatches_index = new Array();
	
	 var msgval = document.otherpnumber.foreignparts.value;
	 // for Very Low Profile Open Frame function
	 var begin115 = false;
	 var end001 = false;
	 var end003 = false;
	 if (msgval.charAt(0) + msgval.charAt(1) + msgval.charAt(2) == "115")
	 	{
		var begin115 = true;
		}
	 if (msgval.charAt(msgval.length - 3)+ msgval.charAt(msgval.length - 2) + msgval.charAt(msgval.length - 1) == "001")
	 	{
		end001 = true;
		}
	if (msgval.charAt(msgval.length - 3)+ msgval.charAt(msgval.length - 2) + msgval.charAt(msgval.length - 1) == "003")
		{
		end003 = true;
		}
	 //
	 //alert("msgval is " + msgval);
	 	var lettersend001 = false;
		var lettersend605 = false;
	    var letters110 = msgval.charAt(0) + msgval.charAt(1) + msgval.charAt(2);
		var lettersend = msgval.charAt(msgval.length - 3)+ msgval.charAt(msgval.length - 2) + msgval.charAt(msgval.length - 1);
	
		if (lettersend == "605")
		// Warning! I struggled on this for one hour, not knowing what was wrong!
		// if = is used instead of ==, this will always evaluate to true
			{
			lettersend605 = true;
			}
		if (lettersend == "001")
		// Warning! I struggled on this for one hour, not knowing what was wrong!
		// if = is used instead of ==, this will always evaluate to true
			{
			lettersend001 = true;
			}
	// -------- check for Advance code ---------
	 if ( ( msgval.charAt(0) + msgval.charAt(1) ) == ("LS") )
	 // if we are dealing with an Advance code
	 //alert("Advance code match lookup is being run.");
	 {
		for (var i = 0; i < ofdipadvance.length; i++) 
		{
		 
			if (msgval ==  (ofdipadvance[i]) )
			{
				search_validmatches[i] = ofdipadvance[i] + " | " + ofdipchamp[i] + "\n";
				search_validmatches_index[i] = true;
				search_foundmatch = true;
			}
			else
					{
					document.forms[0].matches.value = "No match found!";
					//searchthree_foundmatch = false;
					}
		 }
		 	document.forms[0].matches.value = ( 'The code you entered belongs to Advance.\n \r Advance Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString() ) );
	  }
	// ------------ check for DIL open frame codes  --------------
	// warning - always use == for comparison, and not = !
	 else if ( (letters110 == "110")  && (lettersend001) )
	 //warning: undefined evaluates to true
	 // cannot test for an and condition, when one of the conditions is false
	 // check to see if it is millmax number 
	 //(first 3 digits are 110 and last 3 are 001 )
	 {
	// alert ("lettersend is " + lettersend);
	// alert("letters110 and lettersend are " + letters110  + "  " + lettersend );
	// alert("Looks like a millmax 110 ... 001  number");
	 var millmaxnote = "\n \r * Note * : For our sockets, the height above board is 4.45mm instead of 4.19mm and tail length is 2.92mm instead of 3.175mm. Also, body thickness is 2.95mm instead of 2.79mm . ";		
																	
	 for (var i = 0; i < millmax.length; i++) 
		{
		 
			if (msgval ==  (millmax[i]) )
			{
				search_validmatches[i] = millmax[i] + " | " + millmaxchamp[i] + "\n";
				search_validmatches_index[i] = true;
				search_foundmatch = true;
			}
			else
					{
					document.forms[0].matches.value = "No match found!";
					//searchthree_foundmatch = false;
					}
		 }
		 	document.forms[0].matches.value = ( 'The code you entered belongs to Mill Max.\n \r Mill Max Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString()) + millmaxnote  );
	 }
	 // ----------- check for Automatic Insertion - Stand Off Sockets  --------
	 else if ((letters110 = "110")  && (lettersend605))
	 {
	 // check to see if it is millmax number 
	 //(first 3 digits are 110 and last 3 are 605 )
	 {
	 //alert("Looks like a millmax 110 ... 605  number");
	 var auto_insert_note = "\n \r * Note * : Height above board is 4.45mm instead of 4.19mm and tail length is 2.92mm instead of 3.20mm .";		
																	
	 for (var i = 0; i < auto_insert_stand_off.length; i++) 
		{
		 
			if (msgval ==  (auto_insert_stand_off[i]) )
			{
				search_validmatches[i] = auto_insert_stand_off[i] + " | " + auto_insert_stand_off_champ[i] + "\n";
				search_validmatches_index[i] = true;
				search_foundmatch = true;
			}
			else
					{
					document.forms[0].matches.value = "No match found!";
					//searchthree_foundmatch = false;
					}
		 }
		 	document.forms[0].matches.value = ( 'The code you entered belongs to Mill Max Automatic Insertion - Stand Off Sockets.\n \r Mill Max Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString()) + auto_insert_note  );
	 }
	 }
	// ------- check for pcbs code -------
	else if ( ( msgval.charAt(0) + msgval.charAt(1) + msgval.charAt(2)  ) == ("111") )
	{
	//alert("Looks like a multi layer pcbs code");
	 var pcbs_note = "\n \r * Note * : Height above board is 4.45mm instead of 4.39mm and tail length 4.50mm instead of 4.39mm . Also, body thickness is 2.95mm instead of 2.79mm . ";		
																	
	 for (var i = 0; i < multilayer_pcbs.length; i++) 
		{
		 
			if (msgval ==  (multilayer_pcbs[i]) )
			{
			    
				search_validmatches[i] = multilayer_pcbs[i] + " | " + multilayer_pcbs_champ[i] + "\n";
				search_validmatches_index[i] = true;
				search_foundmatch = true;
			}
			else
		
					{
					document.forms[0].matches.value = "No match found!";
					}
		  }
			document.forms[0].matches.value = ( 'The code you entered belongs to Mill Max Multi-layer PCBS sockets.\n \r Mill Max Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString()) + pcbs_note );
	}
	
	
	else if (begin115) 
		{ 	
			// -------- check for Very Low Profile Open Frame   --------
			if (end001)
				 
				 {
				 //alert("Looks like a very low  profile open frame code");
				 //
				  var vlprof_note = "\n \r * Note * : Body thickness is 2.95mm instead of of 2.79. ";		
																	
				 for (var i = 0; i < very_low_prof_openf.length; i++) 
					{
		 
						if (msgval ==  (very_low_prof_openf[i]) )
						{
			    
							search_validmatches[i] = very_low_prof_openf[i] + " | " + very_low_prof_openf_champ[i] + "\n";
							search_validmatches_index[i] = true;
							search_foundmatch = true;
						}
						else
		
								{
							document.forms[0].matches.value = "No match found!";
								}
		  				}
						document.forms[0].matches.value = ( 'The code you entered belongs to Mill Max Very Low Profile Open Frame sockets.\n \r Mill Max Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString()) + vlprof_note );
				 }
				 
				 
			// -------- Ultra Low Profile Open Frame   --------
			if (end003)
				 
				 {
				 //alert("Looks like an Ultra Low Profile Open Frame  code");
				  var ulprof_note = "\n \r * Note * :Height above board is 2.41mm instead of 2.38mm and tail length is 2.41mm instead of 2.38mm. Also, body thickness is 2.00mm instead of 2.79mm.  ";		
																	
				 for (var i = 0; i < ultra_low_prof_openf.length; i++) 
					{
		 
						if (msgval ==  (ultra_low_prof_openf[i]) )
						{
			    
							search_validmatches[i] = ultra_low_prof_openf[i] + " | " + ultra_low_prof_openf_champ[i] + "\n";
							search_validmatches_index[i] = true;
							search_foundmatch = true;
						}
						else
		
								{
							document.forms[0].matches.value = "No match found!";
								}
		  				}
						document.forms[0].matches.value = ( 'The code you entered belongs to Mill Max Very Low Profile Open Frame sockets.\n \r Mill Max Code | Champion Code \n \r' + nocommaspleasein(search_validmatches.toString()) + ulprof_note );
			
				 }
				 
				 
				
		}
	
	
	}

//  ----------- comma cleanup function ------------
// This function checks for commas at the beginning of a string
// and removes them. This function will be used to cleanup commas
// which occur at the beginning of a matching part number string.
// These commas exist because the string is converted from an array.
// ------------------------------------------------
function nocommaspleasein(mystring)
//this slicing function assumes that all the commas are at the beginning
// of the string
	{
	var removecommasin = mystring;
	var commafoundat;
	for (i=0; i < (removecommasin.length); i++)
		{
			if (removecommasin.charAt(i) == ",")
			{
			commafoundat = i;
			
			}
			
		}
	 removecommasin = removecommasin.slice( (commafoundat+1), (removecommasin.length) );
	 //alert("removecommasin is " + removecommasin);
	 return removecommasin;
	}

// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 1 for advance parts
function getputadvval()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].advance.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = ofdipadvance[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}
	
// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 2 for mill max parts
function getputadvval2()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].mmax.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = millmax[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}

// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 3 for mill max parts - multilayer_pcbs
function getputadvval3()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].multilayerpcbs.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = multilayer_pcbs[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}

// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 4 for mill max parts - very low profile open frame (verylowprofopenf)
function getputadvval4()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].verylowprofopenf.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = very_low_prof_openf[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}
	
// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 5 for mill max parts - Automatic insertion - stand off sockets (autoinsertstandoff)
function getputadvval5()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].autoinsertstandoff.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = auto_insert_stand_off[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}
	
// ------- function to get and put drop down list value -------
// function to determine code chosen  from drop down list 
// and paste it into the search box
// ------------------------------------------------------------
// function 6 for mill max parts - Ultra Low Profile Open Frame (ultralowprofopenf)
function getputadvval6()

	{
	
	//Tried to store selected value from advance drop down list in variable
	// That did not work for IE and Opera.
	
	//Internet Explorer and Opera seem to be unable to get the value of a selected item
	//Both return an empty string. 
	
	// So, instead, look up the index of the selected item, and get its value from the original 
	// array of parts, ofdipadvance[] (array is at the beginning of the script)
	
	var currentlyselected = document.forms[0].ultralowprofopenf.selectedIndex;
	
	// check to see if no item has been selected
	if (currentlyselected == 0)
	//if so, sound an alert
		{
		alert ("Please choose a part number from the list.");
		//break;
		}
	else
		{
		// replace the text in the search box with that of the selected value,
		// drawn from the array, of course, to prevent IE or Opera from
		// silently failing.
		// Remember, the array is one index behind the drop down list.
		
		document.forms[0].foreignparts.value = ultra_low_prof_openf[currentlyselected-1];
	
		//alert("getputadvval just ran! ");
		}
	}