var search_params = new Array();
var disable_form = false;
var disable_results = true;
var sample_items = new Array();
var chips = new Array();
var dropdowns = new Array();
var checkboxes = new Array();
var timer;
var current_dropdown_selected = new Array();
var search_string = new String();

dropdowns.push(new Array("grade", "Any grade", "Any grade"));	
dropdowns.push(new Array("finish", "Any finish", "Any finish"));
dropdowns.push(new Array("shade", "Any shade", "Any shade"));
dropdowns.push(new Array("bwgsm", "Any basis weight/gsm", "Any basis weight/gsm"));
dropdowns.push(new Array("percent_cotton", "Any % cotton", "Any % cotton"));
dropdowns.push(new Array("watermark", "Any watermark", "Any watermark"));
dropdowns.push(new Array("percent_pcw", "Any % PCW", "Any"));
dropdowns.push(new Array("acid_free", "Any Acid Free and Archival", "Any Acid Free and Archival"));
dropdowns.push(new Array("brightness", "Brightness", "Any"));
dropdowns.push(new Array("opacity", "Opacity", "Any"));
dropdowns.push(new Array("sheffield", "Sheffield", "Any"));
dropdowns.push(new Array("caliper", "Caliper", "Any"));
dropdowns.push(new Array("ppi", "PPI", "Any"));
dropdowns.push(new Array("size", "Any size: sheet and envelopes", "Any size: sheet and envelopes"));
dropdowns.push(new Array("roll", "Any size: rolls", "Any size: rolls"));
//dropdowns.push(new Array("digital_printing", "Any digital equipment", "Any digital equipment"));

checkboxes.push('watermark');
checkboxes.push('carbon_neutral');
checkboxes.push('fsc_certified');
checkboxes.push('green_seal_certified');
//checkboxes.push('green_e_certified');
checkboxes.push('ecf');
checkboxes.push('pcf');
checkboxes.push('digitalmark');
checkboxes.push('private_mark');
checkboxes.push('inxwell');
checkboxes.push('i_tone');
checkboxes.push('digital_imaging_surface');
checkboxes.push('watermark');
checkboxes.push('acid_free');
checkboxes.push('electronic_print_guarantee');
checkboxes.push('deckle_edge');
checkboxes.push('windpower');

$(document).ready(function() {

	$("#grade").click(function () { toggle_data("#grade_data", "#grade_title", true); }, function() { toggle_data("#grade_data", "#grade_title", false); });
	$("#grade").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#grade_title') clearTimeout(timer); }, function() { toggle_data("#grade_data", "#grade_title", false); });
	
	$("#finish").click(function () { toggle_data("#finish_data", "#finish_title", true); }, function() { toggle_data("#finish_data", "#finish_title", false); });	
	$("#finish").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#finish_title') clearTimeout(timer); }, function() { toggle_data("#finish_data", "#finish_title", false); });	
	
	$("#shade").click(function () { toggle_data("#shade_data", "#shade_title", true); },  function() { toggle_data("#shade_data", "#shade_title", false); });	
	$("#shade").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#shade_title') clearTimeout(timer); },  function() { toggle_data("#shade_data", "#shade_title", false); });	

	$("#bwgsm").click(function () { toggle_data("#bwgsm_data", "#bwgsm_title", true); },  function() { toggle_data("#bwgsm_data", "#bwgsm_title", false); });	
	$("#bwgsm").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#bwgsm_title') clearTimeout(timer); },  function() { toggle_data("#bwgsm_data", "#bwgsm_title", false); });	

	$("#percent_cotton").click(function () { toggle_data("#percent_cotton_data", "#percent_cotton_title", true); },  function() { toggle_data("#percent_cotton_data", "#percent_cotton_title", false); });	
	$("#percent_cotton").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#percent_cotton_title') clearTimeout(timer); },  function() { toggle_data("#percent_cotton_data", "#percent_cotton_title", false); });	

	$("#percent_pcw").click(function () { toggle_data("#percent_pcw_data", "#percent_pcw_title", true); },  function() { toggle_data("#percent_pcw_data", "#percent_pcw_title", false); });	
	$("#percent_pcw").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#percent_pcw_title') clearTimeout(timer); },  function() { toggle_data("#percent_pcw_data", "#percent_pcw_title", false); });	

	$("#brightness").click(function () { toggle_data("#brightness_data", "#brightness_title", true); },  function() { toggle_data("#brightness_data", "#brightness_title", false); });	
	$("#brightness").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#brightness_title') clearTimeout(timer); },  function() { toggle_data("#brightness_data", "#brightness_title", false); });	

	$("#opacity").click(function () { toggle_data("#opacity_data", "#opacity_title", true); },  function() { toggle_data("#opacity_data", "#opacity_title", false); });	
	$("#opacity").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#opacity_title') clearTimeout(timer); },  function() { toggle_data("#opacity_data", "#opacity_title", false); });	

	$("#sheffield").click(function () { toggle_data("#sheffield_data", "#sheffield_title", true); },  function() { toggle_data("#sheffield_data", "#sheffield_title", false); });	
	$("#sheffield").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#sheffield_title') clearTimeout(timer); },  function() { toggle_data("#sheffield_data", "#sheffield_title", false); });	

	$("#caliper").click(function () { toggle_data("#caliper_data", "#caliper_title", true); },  function() { toggle_data("#caliper_data", "#caliper_title", false); });	
	$("#caliper").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#caliper_title') clearTimeout(timer); },  function() { toggle_data("#caliper_data", "#caliper_title", false); });	

	$("#ppi").click(function () { toggle_data("#ppi_data", "#ppi_title", true); },  function() { toggle_data("#ppi_data", "#ppi_title", false); });	
	$("#ppi").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#ppi_title') clearTimeout(timer); },  function() { toggle_data("#ppi_data", "#ppi_title", false); });	

	$("#size").click(function () { toggle_data("#size_data", "#size_title", true); },  function() { toggle_data("#size_data", "#size_title", false); });	
	$("#size").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#size_title') clearTimeout(timer); },  function() { toggle_data("#size_data", "#size_title", false); });	

	$("#roll").click(function () { toggle_data("#roll_data", "#roll_title", true); },  function() { toggle_data("#roll_data", "#roll_title", false); });	
	$("#roll").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#roll_title') clearTimeout(timer); },  function() { toggle_data("#roll_data", "#roll_title", false); });	

	$("#digital_printing").click(function () { toggle_data("#digital_printing_data", "#digital_printing_title", true); },  function() { toggle_data("#digital_printing_data", "#digital_printing_title", false); });	
	$("#digital_printing").hover(function () { if (timer != undefined && current_dropdown_selected[1] == '#digital_printing_title') clearTimeout(timer); },  function() { toggle_data("#digital_printing_data", "#digital_printing_title", false); });

	//checkboxes
	$("#carbon_neutral").click(function () { set_check_var('#carbon_neutral', 'carbon_neutral'); });
	$("#windpower").click(function () { set_check_var('#windpower', 'windpower'); });
	$("#fsc_certified").click(function () { set_check_var('#fsc_certified', 'fsc_certified'); });
	$("#green_seal_certified").click(function () { set_check_var('#green_seal_certified', 'green_seal_certified'); });
	//$("#green_e_certified").click(function () { set_check_var('#green_e_certified', 'green_e_certified'); });
	$("#ecf").click(function () { set_check_var('#ecf', 'ecf'); });
	$("#pcf").click(function () { set_check_var('#pcf', 'pcf'); });
	$("#digitalmark").click(function () { set_check_var('#digitalmark', 'digitalmark'); });
	$("#private_mark").click(function () { set_check_var('#private_mark', 'private_mark'); });
	$("#inxwell").click(function () { set_check_var('#inxwell', 'inxwell'); });
	$("#i_tone").click(function () { set_check_var('#i_tone', 'i_tone'); });
	$("#digital_imaging_surface").click(function () { set_check_var('#digital_imaging_surface', 'digital_imaging_surface'); });
	$("#watermark").click(function () { set_check_var('#watermark', 'watermark'); });
	$("#acid_free").click(function () { set_check_var('#acid_free', 'acid_free'); });
	$("#electronic_print_guarantee").click(function () { set_check_var('#electronic_print_guarantee', 'electronic_print_guarantee'); });
	$("#deckle_edge").click(function () { set_check_var('#deckle_edge', 'deckle_edge'); });
	$("#include_digital_equipment").click(function () {
		if ($('#include_digital_equipment').attr("src") == 'images/check.gif') {
			$('#include_digital_equipment').attr("src","images/uncheck.gif");
			$('#digital_printing').hide("fast");
		}
		
		else {
			$('#include_digital_equipment').attr("src","images/check.gif");
			$('#digital_printing').show("fast");
		}
	});
	
	$('a.tips').cluetip({
		cluetipClass: 'tips',
		sticky: true, 
		width: 225,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});
	
	$("#find_paper_img").hover(function() { $(this).attr("src","images/find_paper_hi.gif"); }, function() { $(this).attr("src","images/find_paper.gif"); });
	
	$("#find_paper_item_number").hover(function() { $(this).attr("src","images/find_paper_small_hi.gif"); }, function() { $(this).attr("src","images/find_paper_small.gif"); });

	$("#find_paper_digital").hover(function() { $(this).attr("src","images/find_paper_small_hi.gif"); }, function() { $(this).attr("src","images/find_paper_small.gif"); });
	
	$("#clear_item_number_image").hover(function() { $(this).attr("src","images/reset_small_hi.gif"); }, function() { $(this).attr("src","images/reset_small.gif"); });
	
	$("#clear_digital_printing_image").hover(function() { $(this).attr("src","images/reset_small_hi.gif"); }, function() { $(this).attr("src","images/reset_small.gif"); });
	
	$("#reset_attributes_img").hover(function() { $("#reset_attributes_img").attr("src","images/bu_reset_attributes_hi.gif"); }, function() { $("#reset_attributes_img").attr("src","images/bu_reset_attributes.gif"); });

	$('#error_search_params').cluetip({
		positionBy: 'fixed',
		topOffset: 7,
		leftOffset: 0,
		cluetipClass: 'tips',
		sticky: true, 
		width: 150,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});
	
	$('#no_results').cluetip({
		positionBy: 'fixed',
		topOffset: 7,
		leftOffset: 0,
		cluetipClass: 'tips',
		sticky: true, 
		width: 225,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});	

	$('#error_samples').cluetip({
		positionBy: 'fixed',
		topOffset: -75,
		leftOffset: 150,
		cluetipClass: 'tips',
		sticky: true, 
		width: 200,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});	
	
	$('#no_merchant_login').cluetip({
		positionBy: 'fixed',
		topOffset: -45,
		leftOffset: 320,
		cluetipClass: 'tips',
		sticky: true, 
		width: 200,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});		
	
	$('#error_item_number').cluetip({
		positionBy: 'fixed',
		topOffset: 7,
		leftOffset: 0,
		cluetipClass: 'tips',
		sticky: true, 
		width: 225,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});	
	
	$('#error_item_number_results').cluetip({
		positionBy: 'fixed',
		topOffset: 7,
		leftOffset: 0,
		cluetipClass: 'tips',
		sticky: true, 
		width: 225,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});		

	$('#error_digital_printing').cluetip({
		positionBy: 'fixed',
		topOffset: 7,
		leftOffset: 0,
		cluetipClass: 'tips',
		sticky: true, 
		width: 225,
		local: true,
		closePosition: 'top',
		splitTitle: '|',
		closeText: '<img src="images/tip_close.gif">',
		waitImage: false,
		showTitle: false,
		activation: 'click'
	});	
	
	$('#digital_printing_data').css("height", "250px");
	$('#digital_printing_data div').css("width", "auto");
	($.browser.msie == false) ? $('#digital_printing_data').css("width", "445px") : $('#digital_printing_data').css("width", "447px");

	//if there is a get var i_tone = 1 load the menus with i-tone checked
	if (init_i_tone == 1) {
		init_i_tone = 0;
		set_check_var('#i_tone', 'i_tone');
	}
	else if (init_digital_imaging_surface == 1) {
		init_digital_imaging_service = 0;
		set_check_var('#digital_imaging_surface', 'digital_imaging_surface');
	}
	else if (init_inxwell == 1) {
		init_inxwell = 0;
		set_check_var('#inxwell', 'inxwell');
	}
	else {
		refresh_menus();
	}
	
});

function toggle_chart_grades() {
	
	if ($("#charts").is(":hidden")) {
	
		if ($("#charts").children().length == 0) {
			
			$.getJSON("ajax-charts-list.php?"+get_string, function(data) {
				var html = new String();
				
				html += '<table border="0" class="chart_list" width="100%"><tr>';
				
				i = 0;
				
				for(var brand in data) {
					html += '<td>';
					
					for(var grade in data[brand]) {
						
						html += '<div class="grade" id="c_1" onClick="toggle_chart_types(\'#ct_'+i+'\');">'+grade+'</div>';
						
						html += '<ul id="ct_'+i+'">'

						for(var type in data[brand][grade]) {
							html += '<li><a href="chart.php?grade='+grade+'&type='+data[brand][grade][type]+'" target="_blank">'+data[brand][grade][type]+'</a></li>';
						}

						html += '</ul>';
						
						i++;

					}
					
					html += '</td>';
				}
				
				html += '</table></tr>';
				
				$('#charts').append(html);
				
				$("#charts").show("fast");
				
			});
			
		}
		else {
			$("#charts").show("fast");
		}
	}
	else {
		 $("#charts").hide("fast");
	}
}

function toggle_chart_types(id) {

	if ($(id).is(":hidden")) {
		 $(id).slideDown("fast");
	}
	else {
		 $(id).slideUp("fast");
	}
	
}

function toggle_data(data, title, show) {
	if (disable_form == false) {
		if ($(data).children().length > 0) {
			if (show == true) {
				if (current_dropdown_selected[0] != data && current_dropdown_selected[0] != undefined) {
					$(current_dropdown_selected[1]).css("border", "1px solid #B8C7C5");
					$(current_dropdown_selected[1]).css("background-color", "#E1E7E6");
					$(current_dropdown_selected[1]).css("background-image", "url('images/dropdown_bg.jpg')");
					$(current_dropdown_selected[1]).css("color", "#646464");
					if ($.browser.safari) {
						$(current_dropdown_selected[0]).css("overflow", "visible");
					}
					$(current_dropdown_selected[0]).hide();
				}
				
				$(title).css("border", "1px solid #949494");
				$(title).css("background-color", "#FFFFFF");
				$(title).css("background-image", "none");
				$(title).css("color", "#000000");
				$(data).css("overflow", "auto");
				$(data).show();
				
				current_dropdown_selected = new Array();
				current_dropdown_selected.push(data);
				current_dropdown_selected.push(title);
			}
			else {
				if ($(data).is(":hidden") == false) {
						timer = setTimeout( 
							function() {
								$(title).css("border", "1px solid #B8C7C5");
								$(title).css("background-color", "#E1E7E6");
								$(title).css("background-image", "url('images/dropdown_bg.jpg')");
								$(title).css("color", "#646464");
								if ($.browser.safari) {
									$(data).css("overflow", "visible");
								}
								$(data).hide();
							},
							500
						);
				}
			}
		}
	}
}

function clear_item_number() {
	$('#item_number').val('');
	clear_result_area();
}

function reset_digital_printing() {
	$('#digital_printing_title').html('Choose a digital printing equipment');
	clear_result_area();
}

function reset_search_var(key) {
}

function reset_search_param(key, val) {
	$('#'+key+'_data').empty();
	$('#'+key+'_data').hide();
	search_params[key] = '';
	$('#'+key+'_title').html(val);
	refresh_menus();
}

function set_search_var(key, val, title, data, attrib) {
	
	disable_form = true;
	
	$('#item_number').val('');

	$(data).css("overflow", "");
	$(title).css("border", "1px solid #B8C7C5");
	$(title).css("background-color", "#E1E7E6");
	$(title).css("background-image", "url('images/dropdown_bg.jpg')");
	$(title).css("color", "#646464");

	search_params[attrib] = val;
	
	if (attrib == 'percent_pcw' || key == 'percent_cotton') {
		$(title).html(val+'%');
	}
	else {
		$(title).html(val);
	}
	
	$(data).hide();
	$(data).empty();

	refresh_menus();
}

function set_check_var(key, attrib) {

	$('#item_number').val('');

	if ($(key).attr('src') != 'images/graycheck.gif') {
	
		if ($(key).attr("src") == 'images/check.gif') {
			search_params[attrib] = 0;
			$(key).attr("src","images/uncheck.gif");
		}
		
		else {
			search_params[attrib] = 1;
			$(key).attr("src","images/check.gif");
		}
		
		refresh_menus();
	}
}


function set_search_vars() {
	
	disable_results = true;
	
	var tmp = new String();


	for(var key in search_params) {
		if (search_params[key] != '' && key != 'digital_printing') {
			tmp += '&'+key+'='+escape(search_params[key]);
			disable_results = false;
		}
	}

	return tmp;
}

function refresh_digital_menu() {
	
}

function set_digital_search_var(key, val, title, data, attrib) {
	

	clear_result_area();
	
	$.each($(data).children(), function() {
		if (val == this.firstChild.innerHTML) {
			$(title).css("border", "1px solid #B8C7C5");
			$(title).css("background-color", "#E1E7E6");
			$(title).css("background-image", "url('images/dropdown_bg.jpg')");
			$(title).css("color", "#646464");		
			$(title).html(val);
		}
	});

	timer = setTimeout( 
		function() {
			$(title).css("border", "1px solid #B8C7C5");
			$(title).css("background-color", "#E1E7E6");
			$(title).css("background-image", "url('images/dropdown_bg.jpg')");
			$(title).css("color", "#646464");
			if ($.browser.safari) {
				$(data).css("overflow", "visible");
			}
			$(data).hide();
		},
		1
	);
	$(data).hide();	
	
	
	
}

function refresh_menus() {
	
	clear_result_area();
	
	show_loading_animation(true);
	
	disable_form = true;
	
	var get_string = new String();
	
	get_string = set_search_vars();

	$.ajax({
	
		url: "ajax-menus.php",
		dataType: "json",
		type: 'get',
		async: true,
		cache: true,
		data: get_string,
		success: function(data) {
		
			if (data == 0) {
				alert('nothing found');
			}
			else {
				for(var key in data) {
					if (key == 'id') {
						$('#id').val(data[key]);
					}
					else {
						if (jQuery.inArray(key, checkboxes) != -1) {
						//if (key == 'carbon_neutral' || key == 'windpower' || key =='fsc_certified' || key == 'green_seal_certified' || key == 'green_e_certified' || key == 'ecf' || key == 'pcf' || key == 'digitalmark' || key == 'private_mark' || key == 'inxwell' || key == 'i_tone' || key == 'digital_imaging_surface' || key == 'watermark' || key == 'acid_free' || key == 'ecf' || 'key' == 'pcf') {
							if (data[key].length == 1) {
								if (data[key][0] == 0) {
									$('#'+key).attr('src', 'images/graycheck.gif');
									$('#'+key).addClass("no_hand");
									$('#'+key).click(function () { return false; });
								}
								else if (data[key][0] == 1) {
									$('#'+key).attr('src', 'images/check.gif');
									$('#'+key).removeClass("no_hand");
									$('#'+key).click(function () { return false; });							
								}
							}
							else {
								$('#'+key).removeClass("no_hand");
								$('#'+key).attr('src', 'images/uncheck.gif');
							}							
						}

						else {

							$('#'+key+'_data').empty();					
							
							if (data[key].length == 0) {
								$('#'+key+'_title').css("border", "1px solid #B9C8C5");
								$('#'+key+'_title').css("background-color", "#D0DDD4");
								$('#'+key+'_title').css("background-image", "none");
								$('#'+key+'_title').css("cursor", "default");
								$('#'+key+'_title').html('');
							}
							else {
							
								if (data[key].length > 0 || data[key].length == undefined) {
									$('#'+key+'_title').css("border", "1px solid #B8C7C5");
									$('#'+key+'_title').css("background-color", "#E1E7E6");
									$('#'+key+'_title').css("background-image", "url('images/dropdown_bg.jpg')");
									$('#'+key+'_title').css("color", "#646464");		
									$('#'+key+'_title').css("cursor", "pointer");								
					
									for(var val in data[key]) {
										if (key == 'percent_pcw' || key == 'percent_cotton') {
											$('#'+key+'_data').append('<div onclick=\'set_search_var("#'+key+'", "'+data[key][val]+'", "#'+key+'_title", "#'+key+'_data", "'+key+'");\'><span>'+data[key][val]+'%</span></div>');
										}
										else {
											$('#'+key+'_data').append('<div onclick=\'set_search_var("#'+key+'", "'+data[key][val]+'", "#'+key+'_title", "#'+key+'_data", "'+key+'");\'><span>'+data[key][val]+'</span></div>');
										}
									}

									$('#'+key+'_data div').css("width", "auto");

									if ($('#'+key+'_data').children().length > 12) {
										$('#'+key+'_data').css("height", "250px");
									}
									else {
										if ($.browser.safari == false) {
											$('#'+key+'_data').css("overflow", "hidden");
										}
										$('#'+key+'_data').css("height", "auto");									
									}
										
									if ($.browser.msie == false) {
										if (key == 'brightness') {
											$('#'+key+'_data').css("width", "91px");
										}
										else if (key == 'opacity') {
											$('#'+key+'_data').css("width", "83px");
										}
										else if (key == 'sheffield') {
											$('#'+key+'_data').css("width", "87px");
										}
										else if (key == 'caliper') {
											$('#'+key+'_data').css("width", "76px");
										}
										else if (key == 'ppi') {
											$('#'+key+'_data').css("width", "59px");
										}
										else if (key == 'percent_pcw') {
											$('#'+key+'_data').css("width", "113px");
										}
										else {
											$('#'+key+'_data').css("width", "445px");
										}
									}
									else {
										if (key == 'brightness') {
											$('#'+key+'_data').css("width", "93px");
										}
										else if (key == 'opacity') {
											$('#'+key+'_data').css("width", "85px");
										}
										else if (key == 'sheffield') {
											$('#'+key+'_data').css("width", "89px");
										}
										else if (key == 'caliper') {
											$('#'+key+'_data').css("width", "78px");
										}
										else if (key == 'ppi') {
											$('#'+key+'_data').css("width", "61px");
										}
										else if (key == 'percent_pcw') {
											$('#'+key+'_data').css("width", "115px");
										}											
										else {
											$('#'+key+'_data').css("width", "447px");
										}
									}
								}
							}
						}
					}
				}
			}
			for(var index in dropdowns) {
				if (search_params[dropdowns[index][0]] != '' && search_params[dropdowns[index][0]] != undefined) {
					$('#'+dropdowns[index][0]+'_data').append('<div onclick=\'reset_search_param("'+dropdowns[index][0]+'", "'+dropdowns[index][1]+'");\'><span>'+dropdowns[index][2]+'</span></div>');
				}
				//if the title of the dropdown is blank make it the default title
				if ($('#'+dropdowns[index][0]+'_title').html() == '' && data[dropdowns[index][0]].length != 0) {
					$('#'+dropdowns[index][0]+'_title').html(dropdowns[index][1]);
				}
			}
			
			show_loading_animation(false);
		}
	});
	
	disable_form = false;
	
}

function reset_all_attributes() {

	for(var d in dropdowns) {
		$('#'+dropdowns[d][0]+'_title').html(dropdowns[d][1]);
	}
	
	for(var c in checkboxes) {
		$('#'+checkboxes[c]).attr("src","images/uncheck.gif");
	}
	
	//$('#item_number').val('');

	search_params = new Array();
	
	get_string = new String();
	
	clear_result_area();
	
	refresh_menus();
	
}

function add_sample_item(key, item_id) {
	if ($(key).attr("src") == 'images/check.gif') {
		var tmp = new Array();
		tmp = sample_items;
		sample_items = new Array();
		for(var val in tmp) {
			if (tmp[val] != item_id) {
				sample_items.push(tmp[val]);
			}
		}
		$(key).attr("src","images/uncheck.gif");
	}
	else {
		if (jQuery.inArray(item_id, sample_items) == -1) {
			sample_items.push(item_id);
			$(key).attr("src","images/check.gif");
		}
	}
}

function add_sample_items(check_image, item_id) {
	
	var new_items = new Array();
	new_items = item_id.split(",");
	
	if ($(check_image).attr("src") == 'images/check.gif') {

		var tmp = new Array();
		tmp = sample_items;
		sample_items = new Array();

		for(var key in new_items) {
			$('#id_'+new_items[key]).attr("src", "images/uncheck.gif");
		}
		
		for(var key in tmp) {
			if (jQuery.inArray(tmp[key], new_items) == -1) {
				sample_items.push(tmp[key]);
			}
		}
		
		$(check_image).attr("src","images/uncheck.gif");
		
	}
	
	else {
		
		for(var key in new_items) {
			if (jQuery.inArray(new_items[key], sample_items) == -1) {
				sample_items.push(new_items[key]);
			}
			$('#id_'+new_items[key]).attr("src", "images/check.gif");
		}
		
		$(check_image).attr("src","images/check.gif");
	}
}

function show_sample_items() {
	if (sample_items.length == 0) {
		$('#error_samples').trigger("click");
	}
	else {
		str = '&other='+sample_items.toString();
		//window.open('/samples/order-samples/login?'+str+'&hash='+hex_md5(str+'krusty'), "samples");
    window.open('/searchpaper/mohawkpaperstore_redirect.php?'+str, "mohawkpaperstore");
	}
}

function buy_store_items(user_type) {
	if (sample_items.length == 0) {
		$('#error_samples').trigger("click");
	}
	else {
		str = '&other='+sample_items.toString();
    str += '&user_type='+user_type;
		//window.open('/samples/order-samples/login?'+str+'&hash='+hex_md5(str+'krusty'), "samples");
    window.open('/searchpaper/mohawkpaperstore_redirect.php?'+str, "mohawkpaperstore");
	}
}

function show_loading_animation(on) {
	(on == true) ? $('#loading').show() :  $('#loading').fadeOut("fast");
}

function display_code_book_form() {
	$("#code_book_form").toggle("fast");
}

function check_merchant_login() {
	$.ajax({
	
		url: "ajax-check-merchant-login.php",
		dataType: "json",
		type: 'get',
		async: true,
		data: 'merchant_login='+$('#merchant_login').val(),
		
		success: function(data) {
			if (data == 0) {
				$('#cluetip').hide();
				$('#no_merchant_login').trigger("click");			
			}
			else {
				var html = '<span><a href="code_book.php">Click here to download the code book</a></span>';
				$('#code_book_form').hide("fast", function() {
					$('#code_book_form').empty();
					$('#code_book_form').css("width", "240px");
					$('#code_book_form').append(html);
					$('#code_book_form').show();
				});
			}
		}
	});
	
}

function clear_result_area() {
  sample_items = new Array();
	$('#rows').fadeOut("slow", function() {
		$('#results').css('width', '720px');
		$('#results_title').html('');
	});
}