// JavaScript Document
// FILENAME: locator.js
// HISTORY:
// 	01/17/2008 - Victor Solanoy - Advanced Search for IP code re-written - brute force removed and optimized
// 	01/21/2008 - Victor Solanoy - File header and function header for buildSubcategory added

<!-- hide from old browsers
function loadCannedValue()
{
	var cannedvalue = "";
	var url = window.location.href;
	if(url.indexOf("canned=")>0)
	{
		cannedvalue = url.charAt(url.indexOf("canned=")+7);
		document.srchform.canned.value = cannedvalue;
	}
	
}

function iploadSelectList(choice,subCatPick){

	// Clear out the Subcategory list.
	numOptions = document.srchform._IPSubcategory.length;		// Get the number of Options in the select list
	for(l=1; l<numOptions; l++){
		document.srchform._IPSubcategory.options[l].text = "";
	}

	document.srchform._IPSubcategory.selectedIndex=0;	// Reset the sub category when a new Category is chosen.

	// FUNCTION: buildSubcategory
	// AUTHOR: Victor Solanoy
	// PURPOSE: Function to build subcategory dropdown box for Advanced Search for IP
	// PARAMETERS:
	//	array: array containing subcategory informations
	// HISTORY:
	//	01/16/2008 - Created function.
	function buildSubcategory (array) {
		var arrayindex=1;
		var splitvalue;

		// Options 0 is always "All Function Subcategories"
		document.srchform._IPSubcategory.options[0].text = "All subcategories";
		document.srchform._IPSubcategory.options[0].value = "";
		document.srchform._IPSubcategory.options[0].selected = true;
		
		for (arrayindex=0; arrayindex < array.length; arrayindex++) {
				// Split | delimited data pair. splitvalue[0] contains the form text value, splitvalue[1] contains the form value
				splitvalue = array[arrayindex].split("|");
				document.srchform._IPSubcategory.options[arrayindex+1].text = splitvalue[0];
				document.srchform._IPSubcategory.options[arrayindex+1].value = splitvalue[1];
			}		
	}

	// Subcategory options
	// Each array value: "text|value"
	var audiovideo = new Array ("音频和语音|Audio and Speech", "压缩|Compression", "格式转换器|Format Converter", "串行数字接口|Serial Digital Interface", "其他|Other");
	var automotive = new Array ("");
	var basiclogic = new Array ("比较器|Comparator", "计数器|Counter", "编码器和解码器|Encoder and Decoder", "逻辑门和缓冲器|Logic Gate and Buffer", "多路复用器|Multiplexer", "寄存器、移位器和流水线|Register Shifter and Pipelining");
	var businterface = new Array ("汽车和工业|Automotive and Industrial", "CoreConnect|CoreConnect", "HyperTransport|HyperTransport", "I2C|I2C", "并行 IO|Parallel IO", "PCI|PCI", "PCI-Express|PCI-Express", "PCI-X|PCI-X", "处理器总线|Processor Bus", "串行 IO|Serial IO", "RapidIO|RapidIO", "USB|USB", "其他|Other", "CAN|CAN");
	var communicationnetworking = new Array ("异步传输模式|Asynchronous Transfer Mode", "加密 - 解密|Encryption Decryption", "纠错|Error Correction", "以太网|Ethernet", "并行接口|Parallel Interface", "SONET - SDH|SONET SDH","串行接口|Serial Interface","存储区域网络|Storage Area Networking", "电信|Telecommunications", "无线|Wireless", "其他|Other");
	var digitalsignalprocessing = new Array ("算术|Arithmetic", "相关器|Correlator", "DSP 处理器|DSP Processor", "DSP 原型硬件|DSP Prototyping Hardware","纠错|Error Correction","滤波器|Filter","调制器 - 解调器|Modulation Demodulation","变换|Transform","三角函数|Trig Function","其他|Other");	
	var mathsubcat = new Array ("累加器|Accumulator", "加法器和减法器|Adder and Subtractor", "比较器|Comparator", "除法器和互反函数|Divider and Reciprocal Function", "F浮点|Floating Point", "格式转换器|Format Converter", "乘法器|Multiplier", "平方根|Square Root", "变换|Transform", "三角函数|Trig Function");
	var memorystorage = new Array ("CAM|CAM", "FIFO|FIFO", "存储器接口和控制器|Memory Interface and Controller", "RAM 和 ROM|RAM and ROM", "寄存器、移位器和流水线|Register Shifter and Pipelining");
	var embeddedprocessing = new Array ("CoreConnect|CoreConnect", "存储器接口|Memory Interface", "处理器核|Processor Core", "处理器接口|Processor Interface", "外设 (PCI)|Peripheral (PCI)", "外设 (网络)|Peripheral (Networking)", "外设 (UART、SPI、IIC、GPIO、其他)|Peripheral (UART, SPI, IIC, GPIO, Other)", "外设 (视频)|Peripheral (Video)", "外设 (加速器)|Peripheral (Accelerator)");
	var storagenassan = new Array ("存储区域网络|Storage Area Networking");
	var fpgafeatures = new Array ("功耗和热性能|Power and Thermal");

	// Figure out which dropdown to build based on the original logic
	switch (choice.selectedIndex)
	{
		case 1: // Audio, Video, Image Processing
			buildSubcategory (audiovideo);
			break;
		case 2: // Automotive
			buildSubcategory (automotive);
			break;
		case 3: // Basic Logic
			buildSubcategory (basiclogic);
			break;
		case 4: // Bus Interface and IO
			buildSubcategory (businterface);
			break;
		case 5: // Communication and Networking
			buildSubcategory (communicationnetworking);
			break;
		case 6: // Digital Signal Processing
			buildSubcategory (digitalsignalprocessing);
			break;
		case 7: // FPGA Features and Design
			buildSubcategory (fpgafeatures);
			break;
		case 8: // Math
			buildSubcategory (mathsubcat);
			break;
		case 9: // Memory Interface and Storage Element
			buildSubcategory (memorystorage);
			break;
		case 10: // Embedded Processing
			buildSubcategory (embeddedprocessing);
			break;
		case 11: // Storage, NAS and SAN
			buildSubcategory (storagenassan);
			break;
		default:
			break;
	}
				
	if(subCatPick != null && subCatPick != 0){
		document.srchform._IPSubcategory.selectedIndex = subCatPick;
	}				
}

function SelectAllDeviceSupport(thing){
        var srch_form = document.srchform;
        for (i=0; i<srch_form.elements.length; ++i) {
           if(srch_form.elements[i].type=="checkbox") {
               var index = (srch_form.elements[i].name).search("_DeviceSupport_");
               if (index != -1) {
                   srch_form.elements[i].checked=true;
               }
           }
        }
}	// End the function 

function UnSelectAllDeviceSupport(thing) {
        var srch_form = document.srchform;
        for (i=0; i<srch_form.elements.length; ++i) {
           if(srch_form.elements[i].type=="checkbox") {
               var index = (srch_form.elements[i].name).search("_DeviceSupport_");
               if (index != -1) {
                   srch_form.elements[i].checked=false;
               }
           }
        }
}	// End the function 

var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;


var lists = new Array();
// ====================================================================
// Drop Down List -- Default Element
// ====================================================================
lists[""]    = new Array();
lists[""][0] = new Array("");
lists[""][1] = new Array("");



// ====================================================================
// Drop Down List -- Array of TEXT for Country
// ====================================================================
lists["Asia Pacific"] = new Array();
lists["Asia Pacific"][0] = new Array(
"Select Country",
"Australia",
"China, People's Republic",
"Korea (South), Republic Of",
"Singapore",
"Taiwan",
"Thailand"
);


lists["Europe"] = new Array();
lists["Europe"][0] = new Array(
"Select Country",
"Austria",
"Belgium",
"Croatia",
"Czech Republic",
"Denmark",
"Estonia",
"Finland",
"France",
"Germany",
"Ireland",
"Italy",
"Netherlands",
"Norway",
"Poland",
"Portugal",
"Spain",
"Sweden",
"Switzerland",
"United Kingdom"
);


lists["India"] = new Array();
lists["India"][0] = new Array(
"Select Country",
"India"
);


lists["Japan"] = new Array();
lists["Japan"][0] = new Array(
"Select Country",
"Japan"
);


lists["Latin America"] = new Array();
lists["Latin America"][0] = new Array(
"Select Country",
"Brazil"
);


lists["Middle East"] = new Array();
lists["Middle East"][0] = new Array(
"Select Country",
"Israel",
"Turkey"
);


lists["North America"] = new Array();
lists["North America"][0] = new Array(
"Select Country",
"Canada",
"United States"
);





// ====================================================================
// Drop Down List -- Array of VALUES for Country
// ====================================================================
lists["Asia Pacific"][1] = new Array(
"",
"Australia",
"China",
"South Korea",
"Singapore",
"Taiwan",
"Thailand"
);


lists["Europe"][1] = new Array(
"",
"Austria",
"Belgium",
"Croatia",
"Czech Republic",
"Denmark",
"Estonia",
"Finland",
"France",
"Germany",
"Ireland",
"Italy",
"Netherlands",
"Norway",
"Poland",
"Portugal",
"Spain",
"Sweden",
"Switzerland",
"United Kingdom"
);


lists["India"][1] = new Array(
"",
"India"
);


lists["Japan"][1] = new Array(
"",
"Japan"
);


lists["Latin America"][1] = new Array(
"",
"Brazil"
);


lists["Middle East"][1] = new Array(
"",
"Israel",
"Turkey"
);


lists["North America"][1] = new Array(
"",
"Canada",
"United States"
);





// ====================================================================
// Drop Down List -- Array of TEXT for State
// ====================================================================
lists["Canada"] = new Array();
lists["Canada"][0] = new Array(
"Select State",
"British Columbia",
"Manitoba",
"Newfoundland",
"Nova Scotia",
"Ontario",
"Quebec"
);


lists["United States"] = new Array();
lists["United States"][0] = new Array(
"Select State",
"AL",
"AZ",
"CA",
"CO",
"CT",
"FL",
"GA",
"IL",
"IN",
"MA",
"MD",
"MI",
"MN",
"MT",
"NC",
"NH",
"NJ",
"NM",
"NV",
"NY",
"OH",
"OR",
"PA",
"RI",
"TN",
"TX",
"UT",
"VA",
"VT",
"WA",
"WI"
);





// ====================================================================
// Drop Down List -- Array of VALUES for State
// ====================================================================
lists["Canada"][1] = new Array(
"",
"British Columbia",
"Manitoba",
"Newfoundland",
"Nova Scotia",
"Ontario",
"Quebec"
);


lists["United States"][1] = new Array(
"",
"AL",
"AZ",
"CA",
"CO",
"CT",
"FL",
"GA",
"IL",
"IN",
"MA",
"MD",
"MI",
"MN",
"MT",
"NC",
"NH",
"NJ",
"NM",
"NV",
"NY",
"OH",
"OR",
"PA",
"RI",
"TN",
"TX",
"UT",
"VA",
"VT",
"WA",
"WI"
);

// ====================================================================
//  FUNCTIONS USED FOR MEMBER LOCATOR
// ====================================================================
function hidelay(lay) 
{
    if (ie4) {document.all[lay].style.visibility = "hidden";}
    if (ns4) {document.layers[lay].visibility = "hide";}
    if (ns6) {document.getElementById([lay]).style.display = "none";}
}

function showlay(lay) 
{
    if (ie4) {document.all[lay].style.visibility = "visible";}
    if (ns4) {document.layers[lay].visibility = "show";}
    if (ns6) {document.getElementById([lay]).style.display = "block";}
}

function writetolay(c_lay,s_lay,value) 
{
    if (value == "" || value == "Japan" || value == "India") {
        hidelay(c_lay);
        hidelay(s_lay);

    } else {
        showlay(c_lay);
        showlay(s_lay);
    }
    return; 
}


function emptyList(dropdownbox)  
{
    while (dropdownbox.options.length) dropdownbox.options[0] = null;
}


// fillList - assigns new drop down options to the given
// drop down box from the list of lists specified
function fillList(dropdownbox,arr,selectedValue) 
{
    var indexSelected = false; 
    // arr[0] holds the option text
    // arr[1] holds the option values
    if (arr == null) { return; }
    for (i=0; i < arr[0].length; i++) {
        option = new Option(arr[0][i], arr[1][i]);
        if (arr[1][i] == selectedValue) { option.selected = true;  indexSelected = true; } 
        dropdownbox.options[dropdownbox.length] = option;
    }

    if (!indexSelected) {
        // If index is not selected, pre-select it to option 0
        dropdownbox.selectedIndex=0;
    }
}


// changeList - performs a drop down list option change by first
// emptying the existing option list and then assigning a new set
function changeListItem(dropdownbox,sFieldName,selectedValue) 
{
    //Empty List[s] 
    emptyList(dropdownbox.form.elements[sFieldName]);
    emptyList(dropdownbox.form.elements['_State']); 

    var list = lists[dropdownbox.options[dropdownbox.selectedIndex].value];
    if (list == null) { return; }

    writetolay('country_layer','state_layer', document.srchform._Region.options[document.srchform._Region.selectedIndex].value); 

    //Fill the List
    fillList(dropdownbox.form.elements[sFieldName], list,selectedValue);
}
// end hide -->



