var ajax_script = '/includes/parttable.html';
var ajax_type = 'Part';

var currID = null;
var currTab = 'Elec';
var defaultTab = 'Elec';
var partInfoWin = null;
var PTabs = {	'Part':[{'shortname':'Elec','linkname':'Electrical Characteristics'},{'shortname':'Design','linkname':'Design Support'},{'shortname':'Enviro','linkname':'Environmental Data'},{'shortname':'Ask','linkname':'Ask an Expert'},{'shortname':'Samp','linkname':'Samples'}],
				'Series':[{'shortname':'Elec','linkname':'Electrical Characteristics'},{'shortname':'Design','linkname':'Design Support'},{'shortname':'Enviro','linkname':'Environ. Data'},{'shortname':'Ask','linkname':'Ask an Expert'}]
			}

function buildTabMenu() {
	var tabs = eval('PTabs.' + ajax_type);
	var tab_menu = '<ul>' + "\n";
	tabs.each(function(tab,index) {
		var li_class = (index > 0) ? '' : ' class="focus"';
		tab_menu += '<li id="TabLink' + tab.shortname + '"' + li_class + '><a href="javascript:changePTab(\'' + tab.shortname + '\')">' + tab.linkname + '<\/a><\/li>' + "\n";
	});
	tab_menu += '<\/ul>' + "\n";
	return tab_menu;
}
        
function changePTab(tab) {
	if (tab != currTab) {
		$('PTab'+currTab).hide();
		$('TabLink'+currTab).removeClassName('focus');
		
		$('TabLink'+tab).addClassName('focus');
		if ($('PTab'+tab)) {
			$('PTab'+tab).show();
		} else {
			loadTabData(tab);
		}
		currTab = tab;
	}
}

function getPartContainer() {
	var tabMenu = buildTabMenu();
	var partContainer = '<div class="partInfo"> <div class="partInfoMenu">' + tabMenu + '<\/div> <div id="partInfoContent"><\/div> <div id="partInfoFooter"><\/div> <\/div>';
	//alert(partContainer);
	return partContainer;
}

function loadTabData(tab) {
	//var params = {'ajaxID':currID,'LoadTab':tab};
	var params = ajax_type+'ID='+currID+'&LoadTab='+tab;
	var opts = {method:'get',parameters:params,
		onSuccess: function(resp) {
		new Insertion.Top($('partInfoContent'),resp.responseText);
		//alert(resp.responseText);
		},
		onFailure: function() { alert('Something went wrong...'); }
  	};
  	new Ajax.Request(ajax_script,opts);
}

function popPartInfo(id,tab) {
	if (tab && tab != '') {
		currTab = tab;
	}
	currID = id;
	
	partInfoWin = new Window({id:'additional_info_win','show':true,className:"lfWindow",destroyOnClose:true,width:550,height:400,minimizable: false,maximizable: false,closable: false,resizable: false,draggable: false,showEffectOptions: {duration:.5}});
	partInfoWin.getContent().innerHTML = getPartContainer();
	partInfoWin.setZIndex(9999);
	//partInfoWin.show(true);
	partInfoWin.showCenter(true);
	
	$('TabLink'+currTab).addClassName('focus');
	loadTabData(currTab);
	loadFooterTab('Close');
	
	if (tab && tab != '') {
		$('TabLink'+defaultTab).removeClassName('focus');
	}
}

function closePartInfo() {
	//partInfoWin.close();
	//partInfoWin.show(false);
	Windows.close('additional_info_win');
}

function loadFooterTab(tab) {
	var params = {'LoadTab':tab};
	var opts = {method:'get',parameters:params,
		onSuccess: function(resp) {
			new Insertion.Top($('partInfoFooter'),resp.responseText);
		},
		onFailure: function() { alert('Something went wrong...'); }
  	};
  	new Ajax.Request(ajax_script,opts);
}

function printSeriesInfo() {
	window.open("printSeries/index.html", "printWin", "width=800px, height=600px, resizable, scrollable");
}