//SELECT * FROM `ecom_prod` WHERE `name` `prodnum` `regprice` `descshort` `desclong`
//U-XPV86-MPLAB-X-kernel-PIC32-DD5
var activeAjaxGets = 0;
var activeAjaxPosts = 0;
var prod = new Array();
prod["microchip"] = ["PIC24", "dsPIC33", "PIC32"];
prod["renesas"] = ["R32C", "SH2A"];
prod["st"] = ["STM32"];
prod["ti"] = ["TI Stellaris","TI ARMCM3","TI ARM EABI"];

var ssIDE = new Array();
ssIDE['microchip'] = "MPLAB";
ssIDE['renesas'] = "HEW";
ssIDE['st'] = "CS_ARM";
ssIDE['ti'] = "dynamically generated";

var selection = new Array();
selection['manuf'] = [];
selection['prod'] = [];
selection['license'] = [];
selection['architecture'] = [];
selection['ide'] = [];
selection['core'] = [];
selection['servers'] = [];
selection['iolib'] = [];
selection['docs'] = [];
selection['tools'] = [];
selection['support'] = [];
//var bundle = "";
var prodId = new Array();
var prodnum = new Array();
//DspNano should be disabled when unavailable

var achoice = new Array();
achoice['dspnano'] = ['PIC24-Free','PIC24-Trial','PIC24-DD5','dsPIC33-Free','dsPIC33-Trial','dsPIC33-DD5'];
achoice['nounison'] = ['PIC24-Free','PIC24-Trial','dsPIC33-Free','dsPIC33-Trial','TI_Stellaris-Free','TI_Stellaris-Trial','TI_ARMCM3-Free','TI_ARM_EABI-Trial'];
//achoice['nounison'] = ['PIC24-Free','PIC24-Trial','dsPIC33-Free','dsPIC33-Trial','STM32-Trial','STM32-Free','TI_Stellaris-Trial','TI_ARMCM3-CS_ARM-Free','TI_ARMCM3-CS_Stellaris-Free','TI_ARMCM3-CS_Stellaris-Trial','TI_ARMCM3-IAR-Free','TI_ARMCM3-IAR-Trial','TI_ARM_EABI-CS_ARM_EABI-Trial'];

var ichoice = new Array();
ichoice['TI_Stellaris-Free'] = ['CS_Stellaris'];
ichoice['TI_Stellaris-DD5'] = ['CS_ARM','CS_Stellaris'];
ichoice['TI_ARMCM3-Trial'] = ['CS_ARM'];
ichoice['TI_ARMCM3-DD5'] = ['CS_ARM','CS_Stellaris','IAR'];
ichoice['TI_ARM_EABI-Free'] = ['CS_ARM'];
ichoice['TI_ARM_EABI-DD5'] = ['CS_ARM'];

var idechoice = new Array();
idechoice['TI_Stellaris'] = ['CS_ARM', 'CS_Stellaris'];
idechoice['TI_ARMCM3'] = ['CS_ARM', 'CS_Stellaris', 'IAR'];
idechoice['TI_ARM_EABI'] = ['CS_ARM'];
idechoice['PIC32'] = ['MPLAB'];
idechoice['dsPIC33'] = ['MPLAB'];
idechoice['PIC24'] = ['MPLAB'];
idechoice['STM32'] = ['CS_ARM'];
idechoice['R32C'] = ['HEW'];
idechoice['SH2A'] = ['HEW'];


var tchoice = new Array();
tchoice['tut_guide'] = [];
tchoice['prog_guide'] = [];
tchoice['viewer'] = ['PIC24-D','dsPIC33-D','PIC32-U'];

var choice = new Array();
//choice[prod-os-license] = [];
choice['PIC24-D-Free'] = ['kernel','fsyssd','networking'];
choice['PIC24-D-Trial'] = ['kernel'];
choice['PIC24-D-DD5'] = ['networking'];
choice['PIC24-U-Free'] = [];
choice['PIC24-U-Trial'] = [];
choice['PIC24-U-DD5'] = ['fatflfs'];
choice['dsPIC33-D-Free'] = ['kernel','fsyssd','networking'];
choice['dsPIC33-D-Trial'] = ['kernel'];
choice['dsPIC33-D-DD5'] = ['kernel','adnet'];
choice['dsPIC33-U-Free'] = [];
choice['dsPIC33-U-Trial'] = [];
choice['dsPIC33-U-DD5'] = ['fatflfs'];
choice['PIC32-U-Free'] = ['kernel','fsyssd','networking','tut_guide'];
choice['PIC32-U-Trial'] = ['kernel'];
choice['PIC32-U-DD5'] = ['kernel','adnet','fatflfs','networking','posh','thttpd'];
choice['R32C-U-Free'] = ['kernel','networking','tut_guide'];
choice['R32C-U-Trial'] = ['kernel'];
choice['R32C-U-DD5'] = ['kernel','adnet','networking','posh','thttpd'];
choice['SH2A-U-Free'] = ['kernel','networking','tut_guide'];
choice['SH2A-U-Trial'] = ['kernel'];
choice['SH2A-U-DD5'] = ['kernel','adnet','networking','posh','thttpd'];
choice['STM32-U-Free'] = ['kernel','networking','tut_guide'];
choice['STM32-U-Trial'] = ['kernel'];
choice['STM32-U-DD5'] = ['kernel','adnet','networking','posh','thttpd','fatflfs'];
choice['TI_Stellaris-CS_ARM-U-Free'] = ['tut_guide'];
choice['TI_Stellaris-CS_ARM-U-Trial'] = [];
choice['TI_Stellaris-CS_ARM-U-DD5'] = ['adnet','posh','thttpd','fatflfs'];
choice['TI_Stellaris-CS_Stellaris-U-Free'] = ['kernel','networking'];
choice['TI_Stellaris-CS_Stellaris-U-Trial'] = [];
choice['TI_Stellaris-CS_Stellaris-U-DD5'] = ['adnet','posh','thttpd','fatflfs','networking'];
choice['TI_ARMCM3-CS_ARM-U-Free'] = [];
choice['TI_ARMCM3-CS_ARM-U-Trial'] = ['kernel'];
choice['TI_ARMCM3-CS_ARM-U-DD5'] = ['kernel','special'];
choice['TI_ARMCM3-CS_Stellaris-U-Free'] = [];
choice['TI_ARMCM3-CS_Stellaris-U-Trial'] = [];
choice['TI_ARMCM3-CS_Stellaris-U-DD5'] = ['kernel'];
choice['TI_ARMCM3-IAR-U-Free'] = [];
choice['TI_ARMCM3-IAR-U-Trial'] = [];
choice['TI_ARMCM3-IAR-U-DD5'] = ['kernel'];
choice['TI_ARM_EABI-CS_ARM-U-Free'] = ['kernel','networking'];
choice['TI_ARM_EABI-CS_ARM-U-Trial'] = [];
choice['TI_ARM_EABI-CS_ARM-U-DD5'] = ['networking'];

var tNotes = new Array();
tNotes['Free'] = '<b>FREE License</b>&nbsp;does not include source code';
tNotes['Trial'] = '<b>TRIAL License</b>&nbsp;gives you an opportunity to try the OS with the option of complete refund';
tNotes['DD5'] = '<b>Commercial License</b>&nbsp;is the thing to get';
tNotes['DSPnano'] = '<b>DSPnano</b> is 8/16 Bit Architecture';
tNotes['Unison'] = '<b>Unison</b> is 32 Bit Architecture';
tNotes['MPLAB'] = '<b>MPLAB IDE</b>';
tNotes['HEW'] = '<b>HEW IDE</b>';
tNotes['CS_ARM'] = '<b>CodeSourcery ARM IDE</b>';
tNotes['CS_Stellaris'] = '<b>CodeSourcery Stellaris IDE</b>';
tNotes['IAR'] = '<b>IAR Systems IDE</b>';
tNotes['kernel'] = '<b>Kernel</b> is part of the CORE package (kernel, fsys, tty, io).<br><br>It includes basic kernel, documentation, binary libraries, development source code, example programs, file system and serial I/O servers.';
tNotes['fsys'] = '<b>File System</b> is part of the CORE package (kernel, fsys, tty, io).<br><br>It includes basic kernel, documentation, binary libraries, development source code, example programs, file system and serial I/O servers.';
tNotes['fatflfs'] = '<b>FAT16 File System</b> with FAT32 software user recompile option. Full documentation, binary libraries, all source code, and 2+ demonstration programs are included. Completely integrated and tested to POSIX interface standards with Unison 5.0 kernel and I/O subsystem.';
tNotes['fsyssd'] = '<b>SD File Server</b> supports uSD &amp; SD cards with the pictail SD/MMC.';
tNotes['tty'] = '<b>Serial Communication Server</b> is part of the CORE package (kernel, fsys, tty, io).<br><br>It includes basic kernel, documentation, binary libraries, development source code, example programs, file system and serial I/O servers.';
tNotes['networking'] = '<b>TCP/DHCP</b> includes TCP Protocol Stack (BSD with Extensive Modifications), DHCP client, documentation, binary libraries, all source code, demonstration programs.';
tNotes['thttpd'] = '<b>Tiny HTTP Server</b> includes full documentation, binary libraries, all source code, and demonstration programs are included. Completely integrated and tested to POSIX and BSD interface standards with Unison 5.0 kernel and I/O subsystem. ';
tNotes['posh'] = '<b>Posh Server</b> works with command shell and telnet. It includes full documentation, binary libraries, all source code, and demonstration programs are included.';
tNotes['adnet'] = '<b>Advanced Networking Package</b> includes TFTP Protocol Stack , DHCP server, Telnet (posh required), NAT and ppp. Full documentation, binary libraries, all source code, and 8+ demonstration programs are included.';
tNotes['io'] = '<b>I/O</b> is part of the CORE package (kernel, fsys, tty, io).<br><br>It includes basic kernel, documentation, binary libraries, development source code, example programs, file system and serial I/O servers.';
tNotes['graphics'] = '';
tNotes['tut_guide'] = '';
tNotes['prog_guide'] = '';
tNotes['idetool'] = '';
tNotes['viewer'] = '<b>RTOS Viewer</b> allows easy debugging by letting you see threads, semaphores, message queues, mutex, barrier, rendezvous, memory and servers.<br><span style=\"color:#FF6600;font-weight:bold\">$99.00</span>';
tNotes['timing'] = '';
tNotes['Silver'] = '<b>Silver Support for 10hrs</b> includes:<ul><li>48hr status response</li><li>Email support Mon-Fri, excl. holidays</li><li>Free upgrades for all minor versions</li><li>Any MCU type, any locations, any questions of any kind and any tools</li></ul>';
tNotes['Gold'] = '<b>Gold Support for 10hrs</b> includes:<ul><li>24hr status response</li><li>Email, chat &amp; Skype support Mon-Fri 9am-5pm EST, excl. holidays</li><li>Free upgrades for all minor versions</li><li>Any MCU type, any locations, any questions of any kind and any tools</li></ul>';
tNotes['Platinum'] = '<b>Platinum Support for 10hrs</b> includes:<ul><li>24hr status response</li><li>Email, chat &amp; telephone support Mon-Fri 8am-6pm EST, excl. holidays</li><li>Free upgrades for all minor versions</li><li>Any MCU type, any locations, any questions of any kind and any tools</li></ul>';
tNotes['microchip'] = tNotes['renesas'] = tNotes['st'] = tNotes['ti'] = 'Click to select manufacturer';

var prodPrice = new Array();

function init(){

	$('manuf').addEvent('mouseleave', function() {
		lowlightlayer($('manuf'));
	});
	$('license').addEvent('mouseleave', function() {
		lowlightlayer($('license'));
	});
	$('architecture').addEvent('mouseleave', function() {
		lowlightlayer($('architecture'));
	});
	$('ide').addEvent('mouseleave', function() {
		lowlightlayer($('ide'));
	});
	$('os').addEvent('mouseleave', function() {
		lowlightlayer($('os'));
	});
	$('docs').addEvent('mouseleave', function() {
		lowlightlayer($('docs'));
	});
	$('tools').addEvent('mouseleave', function() {
		lowlightlayer($('tools'));
	});
	$('support').addEvent('mouseleave', function() {
		lowlightlayer($('support'));
	});
}
function select(d) {
	p = d.parentNode;
	var bundle = "";
	var singleselection = false;
	switch (p.id) {
		case "manuf":
			singleselection = true;
			selection["prod"].length = 0;
			document.getElementById("prod").innerHTML = '<div class="layer_heading"><span class="layer_heading_select">Select</span><br />Product</div>';
			for(i=0;i<prod[d.id].length;i++) {
				document.getElementById("prod").innerHTML += '<div id="'+(prod[d.id][i]).replace(/\s/g,'_')+'" class="option" onclick="select(this);" onmouseover="hilight(this);" onmouseout="lowlight(this);">'+prod[d.id][i]+'</div>';
			}
			break;
		case "prod":
			singleselection = true;
			break;
		case "ide":
			singleselection = true;
			break;
		case "license":
			singleselection = true;
			break;
		case "architecture":
			singleselection = true;
			break;
		case "core":
			bundle = "core";
			break;
		case "servers":
			if(d.id == "fsys" || d.id == "tty") bundle = "core";
		case "iolib":
			if(d.id == "io") bundle = "core";
		case "docs":
			break;
		case "tools":
			break;
		case "support":
			singleselection = true;
			break;
	}
	if(singleselection) {							//SINGLE SELECTION (deselect previously selected)
		if(selection[p.id].length) {
			if(d.id!=selection[p.id][0])document.getElementById(selection[p.id][0]).className = "option";
			selection[p.id].length = 0;
		}
	}
	//debug helper
	var slimOption = false;
	if(d.className == "option optionSlim") {
		slimOption = true;
		d.className = "option";
	} else if(d.className == "option_selected optionSlim") {
		slimOption = true;
		d.className = "option_selected";
	}
	
	if(d.className == "option") { 					//SELECT
		selection[p.id].push(d.id);
		d.style.background = "";
		d.className = "option_selected";
		if(slimOption) d.className = "option_selected optionSlim";
		if(bundle == "core") {
			removeFromArray(d.id,selection[p.id]);
			selection['core'].push('kernel');
			$('kernel').style.background = '';
			$('tty').style.background = '';
			$('fsys').style.background = '';
			$('io').style.background = '';
			document.getElementById("kernel").className = "option_selected optionSlim";
			document.getElementById("tty").className = "option_selected optionSlim";
			document.getElementById("fsys").className = "option_selected optionSlim";
			document.getElementById("io").className = "option_selected optionSlim";
		}
		switch(p.id) {
			case "manuf":
				selection['prod'].length = 0;
				selection['ide'].length = 0;
				selection['license'].length = 0;
				selection['architecture'].length = 0;
				selection['core'].length = 0;
				selection['servers'].length = 0;
				selection['iolib'].length = 0;
				var oldSelections = $$('.option_selected').filter(function(item, index){
					return (item.parentNode.id != 'manuf');
				});
				oldSelections.each(function(item,index){
					item.className = "option";
					if(item.parentNode.parentNode.id=="os") item.className = "option optionSlim";
				});
				$('prod').reveal();
				$('ide').dissolve();
				$('step2').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "prod":
				selection['ide'].length = 0;
				selection['license'].length = 0;
				selection['architecture'].length = 0;
				selection['core'].length = 0;
				selection['servers'].length = 0;
				selection['iolib'].length = 0;
				var oldSelections = $$('.option_selected').filter(function(item, index){
					return (item.parentNode.id != 'manuf' && item.parentNode.id != 'prod');
				});
				oldSelections.each(function(item,index){
					item.className = "option";
					if(item.parentNode.parentNode.id=="os") item.className = "option optionSlim";
				});
				setIDEChoices();
				$('ide').reveal();
				$('step2').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "ide":
				selection['license'].length = 0;
				selection['architecture'].length = 0;
				selection['core'].length = 0;
				selection['servers'].length = 0;
				selection['iolib'].length = 0;
				var oldSelections = $$('.option_selected').filter(function(item, index){
					return (item.parentNode.id != 'manuf' && item.parentNode.id != 'prod' && item.parentNode.id != 'ide');
				});
				oldSelections.each(function(item,index){
					item.className = "option";
					if(item.parentNode.parentNode.id=="os") item.className = "option optionSlim";
				});
				$('step2').reveal();
				$('license').reveal();
				$('architecture').dissolve();
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				/*$('os').reveal();
				$('step3').reveal();
				$('docs').dissolve();
				$('idetool').style.display = 'none';
				$('timing').style.display = 'none';
				$('btnAdd2Cart').style.visibility = 'visible';
				setOSChoices();
				setToolsChoices();*/
				break;
			case "license":
				selection['architecture'].length = 0;
				selection['core'].length = 0;
				selection['servers'].length = 0;
				selection['iolib'].length = 0;
				var oldSelections = $$('.option_selected').filter(function(item, index){
					return (item.parentNode.id != 'manuf' && item.parentNode.id != 'prod' && item.parentNode.id != 'ide' && item.parentNode.id != 'license');
				});
				oldSelections.each(function(item,index){
					item.className = "option";
					if(item.parentNode.parentNode.id=="os") item.className = "option optionSlim";
				});
				$('architecture').reveal();
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				setArchitectureChoices();
				break;
			case "architecture":
				selection['core'].length = 0;
				selection['servers'].length = 0;
				selection['iolib'].length = 0;
				var oldSelections = $$('.option_selected').filter(function(item, index){
					return (item.parentNode.id != 'manuf' && item.parentNode.id != 'prod' && item.parentNode.id != 'ide' && item.parentNode.id != 'license' && item.parentNode.id != 'architecture');
				});
				oldSelections.each(function(item,index){
					item.className = "option";
					if(item.parentNode.parentNode.id=="os") item.className = "option optionSlim";
				});
				setOSChoices();
			break;
		}
	} else { 										//DESELECT
		removeFromArray(d.id,selection[p.id]);
		d.className = "option";
		if(slimOption) d.className = "option optionSlim";
		if(bundle == "core") {
			removeFromArray("kernel",selection['core']);
			document.getElementById("kernel").className = "option optionSlim";
			document.getElementById("tty").className = "option optionSlim";
			document.getElementById("fsys").className = "option optionSlim";
			document.getElementById("io").className = "option optionSlim";
		}
		switch(p.id) {
			case "manuf":
				$('prod').dissolve();
				$('ide').dissolve();
				$('step2').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "prod":
				$('ide').dissolve();
				$('step2').dissolve();
				$('license').dissolve();
				$('architecture').dissolve();
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "ide":
				$('step2').dissolve();
				$('license').dissolve();
				$('architecture').dissolve();
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "license":
				$('architecture').dissolve();
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
				break;
			case "architecture":
				$('os').dissolve();
				$('step3').dissolve();
				$('btnAdd2Cart').style.visibility = 'hidden';
			break;
		}
	}
}
function setIDEChoices() {
	var ichoicekey = selection['prod'][0];
	for(var i=1;i<$('ide').children.length-1;i++){
		if(idechoice[ichoicekey].contains($('ide').children[i].id)) {
			$('ide').children[i].style.display = 'block';
		} else {
			$('ide').children[i].style.display = 'none';
		}
	}
}
function setIDEChoices1() {
	var ichoicekey = selection['prod'][0] +'-'+ selection['license'][0];
	//document.getElementById("ide").innerHTML = '';
	$('CS_ARM').style.display = 'none';
	$('CS_Stellaris').style.display = 'none';
	$('IAR').style.display = 'none';
	for(i=0;i<ichoice[ichoicekey].length;i++) {
		$(ichoice[ichoicekey][i]).style.display = 'block';
		//document.getElementById("ide").innerHTML += '<div id="'+ichoice[ichoicekey][i]+'" class="option" onclick="select(this);" onmouseover="hilight(this);" onmouseout="lowlight(this);">'+ichoice[ichoicekey][i]+'</div>';
	}
}
function setToolsChoices() {
	var tchoicekey = selection['prod'][0] + '-' + selection['architecture'][0].substr(0,1);
	if(tchoice['tut_guide'].contains(tchoicekey)){
		$('tut_guide').style.display = 'block';
	} else {
		$('tut_guide').style.display = 'none';
	}
	if(tchoice['prog_guide'].contains(tchoicekey)){
		$('prog_guide').style.display = 'block';
	} else {
		$('prog_guide').style.display = 'none';
	}
	if(tchoice['viewer'].contains(tchoicekey)){
		$('viewer').style.display = 'block';
	} else {
		$('viewer').style.display = 'none';
	}
	$('idetool').style.display = 'none';
	$('timing').style.display = 'none';
}
function setArchitectureChoices() {
	/*var prod_ide;
	if(selection['manuf'][0]=='ti') {
		prod_ide = selection['prod'][0] +"-"+ selection['ide'][0];
	} else {
		prod_ide = selection['prod'][0];
	}*/
	var countHidden = 0;
	var achoicekey = selection['prod'][0] +'-'+ selection['license'][0];
	if(achoice['dspnano'].contains(achoicekey)){
		$('DSPnano').style.display = 'block';
	} else {
		$('DSPnano').style.display = 'none';
		countHidden++;
	}
	if(achoice['nounison'].contains(achoicekey)){
		$('Unison').style.display = 'none';
		countHidden++;
	} else {
		$('Unison').style.display = 'block';
	}
	if(countHidden>=2) {
		$('architecture').dissolve();
		//$('architecture_tooltip').reveal();
		$('license_tooltip').innerHTML = '<b style="color:red">Sorry, ' + selection['license'][0] + ' license is currently not available for this product. Select a different license or contact us</b>';
	}
}
function setOSChoices(){
	resetOSOptions();
	var prod_ide;
	if(selection['manuf'][0]=='ti') {
		prod_ide = selection['prod'][0] +"-"+ selection['ide'][0];
	} else {
		prod_ide = selection['prod'][0];
	}
	
	var choicekey = prod_ide + '-' + selection['architecture'][0].substr(0,1) + '-' + selection['license'][0];
	//os elements
	var options = $$('.optionSlim');
	var hiddenCount = 0;
	for(i=0;i<options.length;i++) {
		if(choice[choicekey].contains(options[i].id)) {
			$(options[i].id).style.display = 'block';
		} else {
			$(options[i].id).style.display = 'none';
			hiddenCount++;
		}
	}
	//kernel
	if(choice[choicekey].contains('kernel')) {
		$('kernel').style.display = 'block';
		$('fsys').style.display = 'block';
		$('tty').style.display = 'block';
		$('io').style.display = 'block';
		$('core').style.display = 'block';
		$('iolib').style.display = 'block';
	} else {
		$('kernel').style.display = 'none';
		$('fsys').style.display = 'none';
		$('tty').style.display = 'none';
		$('io').style.display = 'none';
		$('core').style.display = 'none';
		$('iolib').style.display = 'none';
	}
	if(hiddenCount==options.length) {
		$('os').dissolve();
		$('ide_tooltip').innerHTML = '<b style="color:red">Sorry, we currently do not have downloads setup for ' + selection['ide'][0] + ' with '+selection['prod'][0] + '. Select a different IDE or contact us</b>';
	} else {
		$('os').reveal();
		setToolsChoices();
		$('step3').reveal();
		$('btnAdd2Cart').style.visibility = 'visible';
		var myFx = new Fx.Scroll(window).toElement('architecture');
	}
}
function removeFromArray(item,aarray) {
	for(i=0;i<aarray.length;i++) {
		if(aarray[i]==item) {
			aarray.splice(i,1); 
			break;
		}//index = i;//aarray[i]=null;
	}
}
function buildProdnum() {
	$('btnAdd2Cart').innerHTML = 'Please Wait...';
	prodnum.length = 0;
	//var prodnum = new Array();
	//var ssLicense;
	/*if(selection['prod'][0]=='STM32'){
		ssIDE[selection['manuf'][0]] += '_EABI';
	}*/
	if(selection['manuf'][0]=='ti'){
		ssIDE['ti'] = selection['ide'][0];
	}
	/*if(selection['prod'][0]=='TI_Stellaris'){
		if(selection['license'][0]=='Free' && selection['ide'][0]=='CS_Stellaris') {
			//skip it
		} else {
			ssIDE[selection['manuf'][0]] += '_EABI';
		}
	}*/
	var ssPOS = '';
	if(selection['license'][0]=="Free") {
		ssPOS = 'POS-';
		if(selection['architecture']=="Unison") {
			selection['license'][0] = "N40";
		} else {
			selection['license'][0] = "N20";
		}
	}
	
	if (selection['core'].length) {
		prodnum.push(ssPOS + selection['architecture'][0].substr(0,1)+"-XPV86-" + ssIDE[selection['manuf'][0]] + "-X-kernel-" + selection['prod'][0] + "-" + selection['license'][0]);	
	}
	if (selection['servers'].length) {
		for(i=0;i<selection['servers'].length;i++) {
			prodnum.push(ssPOS + selection['architecture'][0].substr(0,1)+"-XPV86-" + ssIDE[selection['manuf'][0]] + "-X-" + selection['servers'][i] + "-" + selection['prod'][0] + "-" + selection['license'][0]);	
		}
	}
	if (selection['docs'].length) {
		for(i=0;i<selection['docs'].length;i++) {
			prodnum.push(selection['architecture'][0].substr(0,1)+"-XPV86-" + ssIDE[selection['manuf'][0]] + "-X-" + selection['docs'][i] + "-" + selection['prod'][0] + "-" + selection['license'][0]);	
		}
	}
	if (selection['tools'].length) {
		for(i=0;i<selection['tools'].length;i++) {
			if(selection['tools'][i]=='viewer') {
				if (selection['prod'][0] == 'PIC24' || selection['prod'][0] == 'dsPIC33') {
					prodnum.push('D-XPV86-MPLAB-X-viewer-xxPICxx--D3');
					continue;
				} else if (selection['prod'][0] == 'PIC32') {
					prodnum.push('U-XPV86-MPLAB-X-viewer-PIC32-Dev');
					continue;
				}
			}
			prodnum.push(selection['architecture'][0].substr(0,1)+"-XPV86-" + ssIDE[selection['manuf'][0]] + "-X-" + selection['tools'][i] + "-" + selection['prod'][0] + "-" + selection['license'][0]);	
		}
	}
	if (selection['support'].length) {
		for(i=0;i<selection['support'].length;i++) {
			// S-G-10
			prodnum.push('S-'+selection['support'][0].substr(0,1)+'-10');	
		}
	}
	if(selection['license'][0].substr(0,1)=="N") {
		selection['license'][0] = "Free";
	}
	//ssIDE['st'] = "CS_ARM";
	
	//document.getElementById("result").innerHTML = prodnum;
	ajaxGetProdIds();
	
}
function printPrice(opt) {
	var hoverProdId;
	var tooltipLayer = 'os';
	if(opt.parentNode.id=='support') {
		tooltipLayer = opt.parentNode.id;
		hoverProdId = 'S-'+opt.id.substr(0,1)+'-10';
	} else {
		if(selection['manuf'][0]=='ti'){
			ssIDE['ti'] = selection['ide'][0];
		}
		var ssPOS = '';
		var hoverOptId;
		if(selection['license'][0]=="Free") {
			ssPOS = 'POS-';
			if(selection['architecture']=="Unison") {
				selection['license'][0] = "N40";
			} else {
				selection['license'][0] = "N20";
			}
		}
		if(opt.id == 'io' || opt.id == 'fsys' || opt.id == 'tty') {
			hoverOptId = 'kernel';
		} else {
			hoverOptId = opt.id;
		}
		hoverProdId = ssPOS + selection['architecture'][0].substr(0,1)+"-XPV86-" + ssIDE[selection['manuf'][0]] + "-X-" + hoverOptId + "-" + selection['prod'][0] + "-" + selection['license'][0];	
		
		if(selection['license'][0].substr(0,1)=="N") {
			selection['license'][0] = "Free";
		}
	}
	if(hoverProdId in prodPrice){
		$(tooltipLayer + '_tooltip').innerHTML += prodPrice[hoverProdId];
	} else {
		var cbfn = function(responseText) {
				prodPrice[hoverProdId] = responseText;
				$(tooltipLayer + '_tooltip').innerHTML += responseText;
		}
		ajaxHandler("GET","http://www.rowebots.com/shopper/getprice.php","prodnum="+hoverProdId,cbfn);
	}
	//document.getElementById("result").innerHTML = hoverProdId;
	//ajaxGetPrice();
}
function ajaxHandler(method,url,params,cb_fn) {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4) {
			//alert("Alhamdulillah");
			cb_fn(xmlhttp.responseText);
			//prodId[xmlhttp.responseText.substring(0,xmlhttp.responseText.indexOf(':'))] = xmlhttp.responseText.substr(xmlhttp.responseText.indexOf(':')+1);
		}
	}
	if (method == "GET") {
		xmlhttp.open("GET",url +'?'+ params,true);
		//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(null);
	} else if (method == "POST") {
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(params);
	}
}
function ajaxGetProdIds() {
	//show hour glass
	var cbfn = function(responseText) {
			prodId[responseText.substring(0,responseText.indexOf(':'))] = responseText.substr(responseText.indexOf(':')+1);
			activeAjaxGets--;
			if(0==activeAjaxGets) { //all ajax get prod id calls done :)
				//alert('Gets done');
				ajaxAdd2Cart();
			}
	}
	for(i=0;i<prodnum.length;i++) {
		activeAjaxGets++;
		ajaxHandler("GET","http://www.rowebots.com/shopper/getprodid.php","prodnum="+prodnum[i],cbfn);
	}
}
function ajaxAdd2Cart() {
	var cbfn = function(responseText) {
			//document.getElementById("result").innerHTML = responseText;
			activeAjaxPosts--;
			if(0==activeAjaxPosts) { //all ajax get prod id calls done :)
				alert('You should not see this message. To fix, make ajaxPOST synchronous');
				//hide hourglass
				//redirect to shopping cart
			}
	}
	var url = "http://www.rowebots.com/khxc/index.php";
	var params;
	for(i=0;i<prodnum.length;i++) {
		params = "prodall[]="+ prodId[prodnum[i]] +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--referref="+ prodId[prodnum[i]] +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--referns="+ "prodshow" +
				"&sid="+ "alhamdulillah"+i +
				"&app="+ "ecom" +
				"&ns="+ "addcart" +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--quantity=1";
		//activeAjaxPosts++;
		ajaxHandler("POST",url,params,cbfn);
	}
	//alert('all done');
	//hide hour glass
	//redirect to shopping cart
	window.location = 'http://www.rowebots.com/khxc/ecom-viewcart/COREseo.html';
}
function resetOSOptions() {
	$('kernel').style.display = 'none';
	$('fsys').style.display = 'none';
	$('fatflfs').style.display = 'none';
	$('fsyssd').style.display = 'none';
	$('tty').style.display = 'none';
	$('networking').style.display = 'none';
	$('posh').style.display = 'none';
	$('thttpd').style.display = 'none';
	$('adnet').style.display = 'none';
	$('io').style.display = 'none';
	$('graphics').style.display = 'none';
}
function hilight(opt) {
	if(opt.className.indexOf("option_selected")==-1) {
		opt.style.background = "#CCC";
	}
	if($(opt.parentNode.id+'_tooltip'))	{
		$(opt.parentNode.id+'_tooltip').innerHTML = tNotes[opt.id];
		$(opt.parentNode.id+'_tooltip').reveal();
	} else if (opt.parentNode.parentNode.id=='os'){
		$('os_tooltip').innerHTML = tNotes[opt.id];
		$('os_tooltip').reveal();
		printPrice(opt);
	}
	if(opt.parentNode.id == 'support') {
		printPrice(opt);
	}
	
}
function lowlight(opt) {
	if(opt.className.indexOf("option_selected")==-1) {
		opt.style.background = "#EEE";
	}
}
function lowlightlayer(lyr) {
	if($(lyr.id+'_tooltip'))	{
		$(lyr.id+'_tooltip').dissolve();
	} else if (lyr.parentNode.id=="os") {
		$('os_tooltip').dissolve();
	}
}

function ajaxGetProdIds1() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4) {
			//alert("Alhamdulillah");
			prodId[xmlhttp.responseText.substring(0,xmlhttp.responseText.indexOf(':'))] = xmlhttp.responseText.substr(xmlhttp.responseText.indexOf(':')+1);
		}
	}
	for(i=0;i<prodnum.length;i++) {
		url = "getprodid.php?prodnum="+prodnum[i];
		xmlhttp.open("GET",url,true);
		//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(null);
	}
}
function ajaxAdd2Cart1() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4) {
			/*if(xmlhttp.responseText) {
				li = document.createElement('li');
				li.innerHTML = xmlhttp.responseText;
				document.getElementById("ol"+v).appendChild(li);
				//alert("note: " + xmlhttp.responseText);
			}*/
			//document.getElementById("result").innerHTML = xmlhttp.responseText;
			//window.status = (xmlhttp.responseText);
		}
	}
	for(i=0;i<prodnum.length;i++) {
		params = "prodall[]="+ prodId[prodnum[i]] +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--referref="+ prodId[prodnum[i]] +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--referns="+ "prodshow" +
				"&sid="+ "" +
				"&app="+ "ecom" +
				"&ns="+ "addcart" +
				"&ecom--prodaddtocart--"+prodId[prodnum[i]]+"--quantity=1";
		/*params = "prodall[]=unison-tistellaris-cs-stellariseabi-dd"+
				"&ecom--prodaddtocart--unison-tistellaris-cs-stellariseabi-dd--referref=unison-tistellaris-cs-stellariseabi-dd"+
				"&ecom--prodaddtocart--unison-tistellaris-cs-stellariseabi-dd--referns=prodshow"+
				"&sid=b6389a4h9lu730i0es3yix8ikjd270ly"+
				"&app=ecom"+
				"&ns=addcart"+
				"&ecom--prodaddtocart--unison-tistellaris-cs-stellariseabi-dd--quantity=1";*/
		url = "http://www.rowebots.com/khxc/index.php";
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(params);
	}
}
/*
function DisableSubmit(formname) {
20
21 if(submitted == true) { return; }
22 document.forms[formname].submit();
23 document.forms[formname].SUBMIT.value = 'Please Wait...';
24 document.forms[formname].SUBMIT.disabled = true;
25 submitted = true;
26
27} */
