var loading_html='<p style="text-align:center"><img src="/img/loading.gif" /> <b>Loading....</b></p>';

// Toggle visability of element
function toggle_visibility(id) {
	var el = document.getElementById(id);

	if(navigator.appName.indexOf("Microsoft") > -1){ 
		el.style.display = (el.style.display == 'none')? 'block' : 'none'; 
	} else { 
		el.style.display = (el.style.display == 'table-row')? 'none' : 'table-row'; 
	} 

}

// Toggles the rows in the catalog for both IE and mozilla.
function toggle_row(row_id, item_id) {
	var item_el = document.getElementById(item_id);
	var row_el = document.getElementById(row_id);
	row_el.className = (row_el.className == 'highlighted_row')? 'normal_row' : 'highlighted_row';

	if(navigator.appName.indexOf("Microsoft") > -1){ 
		item_el.style.display = (item_el.style.display == 'none')? 'block' : 'none';
	} else { 
		item_el.style.display = (item_el.style.display == 'table-row')? 'none' : 'table-row'; 
	} 

}

/* ########################### */
/* ##### re-init thickbox elements ##### */
/* ########################### */
function init_ThickBox() {
	$('.thickbox').each(function(i) {
		$(this).unbind('click');
	});
	
	tb_init('a.thickbox, area.thickbox, input.thickbox');
}

/* ######################## */
/* ###### fsg Tool Select  ####### */
/* ######################## */
function fsg_SelectModels() {
	var manuf = $("#select_manufactures").val();
	if(!manuf) {
		$('#fsg_results').html('');
		$('#select_models').children().remove().end();
		$('#select_models').attr("disabled", true);
		$('#select_submit').attr("disabled", true);
		return;
	}

	$('#select_loading').html(loading_html);
	$('#select_models').removeAttr("disabled");
	$('#select_models').children().remove().end().append('<option value="" selected="selected">Select Model</option>');
	
	$.get("./ajax/fsg_SelectModels.php?manuf="+manuf+"&"+Math.random(), function(data) {
		var obj = document.getElementById('select_models');
		eval(data);
		$('#select_loading').html('');
	});
	
}
function fsg_SearchTools() {
	var model = $("#tool_model").val();
	if(!model) {
		$('#fsg_results').html('');
		init_ThickBox();
	}
	
	$('#fsg_results').html(loading_html);

	$.get("./ajax/fsg_SearchTools.php?model="+model+"&"+Math.random(), function(data) {
		$('#fsg_results').html(data);
		init_ThickBox();
	});
}

function fsg_FastenerInterchange(sku) {
	
	if(!sku) {
		var sku = $("#select_models").val();
	}

	if(!sku) {
		$('#fsg_results').html('');
		return;
	}
	
	$('#fsg_results').html(loading_html);

	$.get("./ajax/fsg_FastenerInterchange.php?sku="+sku+"&"+Math.random(), function(data) {
		$('#fsg_results').html(data);
		init_ThickBox();
	});
}

function fsg_SearchCrossRef() {
	var model = $("#fastener_model").val();
	
	if(!model) {
		$('#fsg_results').html('');
		return;
	}
	
	$('#fsg_results').html(loading_html);

	$.get("./ajax/fsg_SearchCrossRef.php?model="+model+"&"+Math.random(), function(data) {
		$('#fsg_results').html(data);
		init_ThickBox();
	});
}

function fsg_GetCrossRefFastener(id) {
	var model = $("#fastener_model").val();
	
	$('#fsg_results').html(loading_html);

	$.get("./ajax/fsg_GetCrossRefFastener.php?id="+id+"&"+Math.random(), function(data) {
		$('#fsg_results').html(data);
		init_ThickBox();
	});
}

/* ######################## */
/* ######### Catalog ######## */
/* ######################## */
function catalog_FastenerInterchange(sku, id) {
	var el = document.getElementById(id);
	
	$(el).html(loading_html);

	$.get("./ajax/catalog_FastenerInterchange.php?sku="+sku+"&"+Math.random(), function(data) {
		$(el).html(data);
		init_ThickBox();
	});
}


function catalog_FastenerDetails(sku, id) {
	var el = document.getElementById(id);
	
	$(el).html(loading_html);

	$.get("./ajax/catalog_FastenerDetails.php?sku="+sku+"&"+Math.random(), function(data) {
		$(el).html(data);
		init_ThickBox();
	});
}


function catalog_ToolInterchange(sku, id) {
	var el = document.getElementById(id);
	
	toggle_visibility(id);
	
	$(el).html(loading_html);

	$.get("./ajax/catalog_ToolInterchange.php?sku="+sku+"&"+Math.random(), function(data) {
		$(el).html(data);
		init_ThickBox();
	});
}



