ROLLOVER_KEY = "-over";

function separateFilename(url){
	var ret = new Array();
	var lastDotIndex = url.lastIndexOf(".");
	ret['base'] = url.substr(0,lastDotIndex);
	ret['extension'] = url.substring(lastDotIndex+1);
	return ret;
}

function getRollOverURL(url){
	var F = separateFilename(url);
	var ret = F['base']+ROLLOVER_KEY+"."+F['extension'];
	return ret;
}

function getRollOutURL(url){
	var F = separateFilename(url);
	var base = F['base'];
	var clippedBase = base.substr(0,base.length-ROLLOVER_KEY.length);
	var ret = clippedBase+"."+F['extension'];
	return ret;
}

function rollOver(el){
	var linkImage = el.firstChild;
	var linkImageURL = linkImage.src;
	linkImage.src = getRollOverURL(linkImageURL);
}

function rollOut(el){
	var linkImage = el.firstChild;
	var linkImageURL = linkImage.src;
	linkImage.src = getRollOutURL(linkImageURL);
}

function initializeRollovers(){
	var allTheLinks = document.getElementsByTagName('a');
	for(var i=0; i<allTheLinks.length; i++){
		var aLink = allTheLinks[i];
		if(aLink.rel == "rollover"){
			aLink.onmouseover = function() {rollOver(this); return false;};
			aLink.onmouseout = function() {rollOut(this); return false;};
		}
	}
}

function cancelImpendingHide(){
	if(document.hideTimeout){
		clearTimeout(document.hideTimeout);
	}	
}
 
function displaySubnav(section){
	if(document.subnav && document.subnav != section){
		hideSubnav(document.subnav);
	}
	$("UL:animated").stop(false, true);
	var id = "#Subnav_"+section;
	var el = $(id);
	el.slideDown();
	document.subnav = section;
}

function hideAfterPause(section){
	document.hideTimeout = setTimeout("hideSubnav('"+section+"')", 333);
}

function hideSubnav(section){
	if(document.hideTimeout){
		clearTimeout(document.hideTimeout);
	}
	var id = "#Subnav_"+section;
	var el = $(id);
	el.slideUp();
}

			
function runSearch(page){
	if(!page){
		page = 1;
	}
	var category = $("#TypeSelect").val();
	var subcategory = $("#PlatformSelect").val();
	var arrange = $("#ArrangeSelect").val();
	var name = null;
	var custom = 0;
	if(document.getElementById("NameText")){
		name = $("#NameText").val();
		custom = 1;
	}
	
	$("#Products").html("");
	$("#Products").css({
		'height': '300px',
		'background-image': "url('/images/wait-big-spin.gif')",
		'background-repeat': "no-repeat",
		'background-position': "50% 50%"
	});
	
	$.ajax({
		url: "/AJAX.php?query=ProductList",
		data: {
			'Category': category,
			'Subcategory': subcategory,
			'Arrange': arrange,
			'Name': name,
			'Custom': custom,
			'p': page
		},
		type: 'post',
		complete: function(response){
			$("#Products").html(response.responseText);
			$("#Products").css({
				'height': 'auto',
				'background': 'none'
			});
		}
	});
}
			

$(document).ready(function(){
	initializeRollovers();
});


function displayProductModal(id){
	$.ajax({
		type: 'post',
		url: '/AJAX.php?query=ProductDetails',
		data: 'id='+id,
		complete: function(response){
			$.colorbox({
				html: response.responseText
			});
		}					
	});				
}	
			
function changeProductType(){
	var type = $("#TypeSelect").val();
	switch(type){
		case "Accessories":
			runSearch();
			break;
		case "Air Transport Rack":
			window.location = "/en/products/atr.php";
			break;
		case "Backplanes":
			window.location = "/en/products/backplanes.php";
			break;
		case "Enclosures":
			window.location = "/en/products/enclosures.php";
			break;
		case "Serial I/O & Fabrics":
			window.location = "/en/products/serial_i_o.php";
			break;
		case "System Expansion":
			window.location = "/en/products/expansion.php";
			break;
	}
}	
			
function changeProductPlatform(){
	var type = $("#PlatformSelect").val();
	switch(type){
		case "VXS":
			window.location = "/en/platforms/vxs.php";
			break;
		case "VPX":
			window.location = "/en/platforms/vpx.php";
			break;
		case "VME":
			window.location = "/en/platforms/vme.php";
			break;
		case "PXI":
			window.location = "/en/platforms/pxi.php";
			break;
		case "AdvancedTCA":
			window.location = "/en/platforms/advanced_tca.php";
			break;
		case "Micro TCA":
			window.location = "/en/platforms/micro_tca.php";
			break;
		case "CompactPCI":
			window.location = "/en/platforms/compact_pci.php";
			break;
	}
}	

function displayCategoryFullText(s, v){
	$.ajax({
		type: 'post',
		url: '/AJAX.php?query=ExpandProductContent',
		data: {
			sec: s,
			val: v
		},
		complete: function(response){
			$.colorbox({
				html: response.responseText,
				width: '600px',
				height: '500px'
			});
		}					
	});				
}

/* Check for Return for Form Submit */
function rsubmit(val,funct)
{
	if(val == 13)
	{
		eval(funct);
	}
}


