function addItem(theSel, vId, vText){
	theSel[theSel.length] = new Option(vText,vId);
}		
function removeItem(theSel, vId, isIndex) {
	if (isIndex) {
		theSel.options[vId] = null;
	} else {
		for(var i=0;i<theSel.length;i++){
			if (theSel.options[i].value == vId) {
				theSel.options[i] = null;
			}
		}
	}
}
function removeAllItems(theSel) {
	for (var i=0;i<theSel.options.length;i++) {
		if (theSel.options[i].selected) {
			removeItem(theSel, theSel.options[i].value, false);
			i--;
		}
	}
	if (theSel.options.length == 0){
		return true;
	} else {
		removeAllItems(theSel);
		return false;
	}
}
function updateSubFamily() {
	var selectedVal = document.getElementById("ddFamily").value;
	var ddSubFamily = document.getElementById("ddSubFamily");	
	if (selectedVal != "") {
		removeAllItems(ddSubFamily);
		selectedVal = "," + selectedVal + ",";
		addItem(ddSubFamily, '', '- Select a Family -');
		for (var i=0;i<arySubFamilies.length;i++){
			if (selectedVal.indexOf(","+arySubFamilies[i][0]+",") != -1) {
				addItem(ddSubFamily, arySubFamilies[i][1], arySubFamilies[i][1]);
			}
		}
		if(ddSubFamily.length == 1){
			for (var i=0;i<arySubFamilies.length;i++){
				addItem(ddSubFamily, arySubFamilies[i][1], arySubFamilies[i][1]);
			}
		}
	} else {
		removeAllItems(ddSubFamily);
		addItem(ddSubFamily, '', '- Select a Family -');
		for (var i=0;i<arySubFamilies.length;i++){
			addItem(ddSubFamily, arySubFamilies[i][1], arySubFamilies[i][1]);
		}
	}
}

function setDefaultDDVals(strOptionLbl){
	var ddFamily = document.getElementById("ddFamily");	
	var ddSubFamily = document.getElementById("ddSubFamily");	
	var tmpStrA = "";
	var tmpStrB = "";
	// find out which option id should be selected
	for (var i=0;i<arySubFamilies.length;i++){
		if (strOptionLbl.toLowerCase() == arySubFamilies[i][1].toLowerCase()) {
			tmpStrA = arySubFamilies[i][0];
			tmpStrB = arySubFamilies[i][1];
			
		}
	}
	// mark the correct selection 
	for (var i=0;i<ddFamily.options.length;i++){
		if (tmpStrA == ddFamily.options[i].value) {
			ddFamily.selectedIndex = i;
		}
	}
	updateSubFamily();
	for (var i=0;i<ddSubFamily.options.length;i++){
		if (tmpStrB == ddSubFamily.options[i].value) {
			ddSubFamily.selectedIndex = i;		}
	}
}

function formSubmit() {
	var selectedVal = "," + document.getElementById("ddFamily").value + ",";
	var ddSubFamily = document.getElementById("ddSubFamily");
	var theURL = "";
	for (var i=0;i<arySubFamilies.length;i++){
		if (ddSubFamily.value.toLowerCase() == arySubFamilies[i][1].toLowerCase()) {
			theURL = arySubFamilies[i][2];			
		}
	}
	if (theURL != "") {
		window.location = theURL;
	}
	return false;
}

// we need two arrays here
// 1. to store the family names
// 2. to store the sub family items
var aryFamilies = new Array();
var arySubFamilies = new Array();

aryFamilies[aryFamilies.length] = ["1,2,3,7,8,10","Texas Instruments Processors"];
aryFamilies[aryFamilies.length] = ["1","- DaVinci Processors"];
aryFamilies[aryFamilies.length] = ["7","- OMAP Processors"];
aryFamilies[aryFamilies.length] = ["2","- C6000 DSPs"];
aryFamilies[aryFamilies.length] = ["8","- MSP430 Microcontrollers"];
aryFamilies[aryFamilies.length] = ["3","- C2000 Digital Signal Controllers"];
aryFamilies[aryFamilies.length] = ["10","- LM3S Stellaris Microcontrollers"];

aryFamilies[aryFamilies.length] = ["4","Freescale Processors"];
aryFamilies[aryFamilies.length] = ["5,6","FPGAs"];
aryFamilies[aryFamilies.length] = ["6","- Altera"];
aryFamilies[aryFamilies.length] = ["5","- Xilinx"];
aryFamilies[aryFamilies.length] = ["9","Intel Processors"];

// Assign processor type from aryFamillies for each processor family. Please order by alphabet
arySubFamilies[arySubFamilies.length] = ["6","Arria II GX: EP2AGX series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=53125"];
arySubFamilies[arySubFamilies.length] = ["9","Atom N270","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=54552"];
arySubFamilies[arySubFamilies.length] = ["9","Atom Z5xx series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=54554"];
arySubFamilies[arySubFamilies.length] = ["5","CoolRunner II: XC2C series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=36576"];
arySubFamilies[arySubFamilies.length] = ["6","Cyclone II: EP2C series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=36465"];
arySubFamilies[arySubFamilies.length] = ["6","Cyclone III: EP3C series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=41593"];
arySubFamilies[arySubFamilies.length] = ["4","iMX27","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=61131"];
arySubFamilies[arySubFamilies.length] = ["4","iMX31","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=35940"];
arySubFamilies[arySubFamilies.length] = ["10","LM3S Stellaris MCUs","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=63874"];
arySubFamilies[arySubFamilies.length] = ["6","MAX II: EPM series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=36463"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP3503","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=37172"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP3515","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=37173"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP3525","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=37174"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP3530","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=37175"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP-L137","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=51802"];
arySubFamilies[arySubFamilies.length] = ["7","OMAP-L138","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=55935"];
arySubFamilies[arySubFamilies.length] = ["5","Spartan-3 / XC3S Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34824"];
arySubFamilies[arySubFamilies.length] = ["5","Spartan-3A / XC3S_A Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34821"];
arySubFamilies[arySubFamilies.length] = ["5","Spartan-3A DSP / XC3SD_A Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34822"];
arySubFamilies[arySubFamilies.length] = ["5","Spartan-3E / XC3S_E Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34823"];
arySubFamilies[arySubFamilies.length] = ["5","Spartan-6 Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=65339"];
arySubFamilies[arySubFamilies.length] = ["6","Stratix II: EP2S series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=36464"];
arySubFamilies[arySubFamilies.length] = ["6","Stratix IV EP4S Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=64248"];
arySubFamilies[arySubFamilies.length] = ["8","MSP430x1xx","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=52978"];
arySubFamilies[arySubFamilies.length] = ["8","MSP430x2xx","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=52979"];
arySubFamilies[arySubFamilies.length] = ["8","MSP430x4xx","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=52981"];
arySubFamilies[arySubFamilies.length] = ["8","MSP430x5xx","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=52980"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C642x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=51379"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C6455","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34201"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C6474","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=51423"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C6742/6746/6748","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=55936"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C6743","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=54482"];
arySubFamilies[arySubFamilies.length] = ["2","TMS320C6745/6747","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=51621"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM335","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=46658"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM355","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=35937"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM357","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=52328"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM365",
"http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=62258"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM64x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=35938"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM643x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=35936"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM644x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34811"];
arySubFamilies[arySubFamilies.length] = ["1","TMS320DM646x",
"http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=35939"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320F280x/F2801x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34813"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320F2802x/F2803x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=54931"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320F281x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34814"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320F2823x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=45228"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320F2833x", 
"http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=45228"];
arySubFamilies[arySubFamilies.length] = ["3","TMS320C2834x","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=62257"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-4 / XC4VFX Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34818"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-4 / XC4VLX Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34819"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-4 / XC4VSX Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34820"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-5 / XC5VLX Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34815"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-5 / XC5VLXT Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34816"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-5 / XC5VSXT Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=34817"];
arySubFamilies[arySubFamilies.length] = ["5","Virtex-6 / XC6V Series","http://focus.ti.com/analog/docs/refdesignovw.tsp?familyId=64&contentType=2&genContentId=65246"];

// populate the dropdowns
for (var i=0;i<aryFamilies.length;i++){
	addItem(document.getElementById("ddFamily"), aryFamilies[i][0], aryFamilies[i][1]);
}
updateSubFamily();