// JavaScript Document

var goodchars="abcdefghijklmnopqrstuvwxyzüåäößABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÜ1234567890!¡?%&/()'[]=,.+-@*´`ñâêîôûáéíóúýàèìòùÂÊÎÔÛÁÉÍÓÚÝÀÈÌÒÙØøÆæëË: ";


var print_colour = new Array();

print_colour[1] = new Object();
print_colour[1] = 5;

print_colour[2] = new Object();
print_colour[2] = 1;

print_colour[3] = new Object();
print_colour[3] = 3;

print_colour[4] = new Object();
print_colour[4] = 3;

print_colour[5] = new Object();
print_colour[5] = 1;




var menu_letter = new Array();

menu_letter["inquery_type"]	= new Object();
menu_letter["inquery_type"]["form"] = "inquery_type";
menu_letter["inquery_type"]["type"] = "radio";

menu_letter["inquery_amount"]	= new Object();
menu_letter["inquery_amount"]["form"] = "inquery_amount";
menu_letter["inquery_amount"]["type"] = "text";

menu_letter["inquery_size"]	= new Object();
menu_letter["inquery_size"]["form"] = "inquery_size";
menu_letter["inquery_size"]["type"] = "text";

menu_letter["inquery_numbercolor"]	= new Object();
menu_letter["inquery_numbercolor"]["form"] = "inquery_numbercolor";
menu_letter["inquery_numbercolor"]["type"] = "radio";

menu_letter["inquery_tapecolor"]	= new Object();
menu_letter["inquery_tapecolor"]["form"] = "inquery_tapecolor";
menu_letter["inquery_tapecolor"]["type"] = "text";

menu_letter["inquery_textcolor"]	= new Object();
menu_letter["inquery_textcolor"]["form"] = "inquery_textcolor";
menu_letter["inquery_textcolor"]["type"] = "text";

menu_letter["inquery_form"]	= new Object();
menu_letter["inquery_form"]["form"] = "inquery_form";
menu_letter["inquery_form"]["type"] = "radio";

menu_letter["inquery_text"]	= new Object();
menu_letter["inquery_text"]["form"] = "inquery_text";
menu_letter["inquery_text"]["type"] = "text";

menu_letter["inquery_message"]	= new Object();
menu_letter["inquery_message"]["form"] = "inquery_message";
menu_letter["inquery_message"]["type"] = "textarea";

menu_letter["inquery_ribbontype"]	= new Object();
menu_letter["inquery_ribbontype"]["form"] = "inquery_ribbontype";
menu_letter["inquery_ribbontype"]["type"] = "radio";

menu_letter["inquery_ribbonwidth"]	= new Object();
menu_letter["inquery_ribbonwidth"]["form"] = "inquery_ribbonwidth";
menu_letter["inquery_ribbonwidth"]["type"] = "radio";


var no_change = 0;
var tempos = 0;

$(document).ready(function() {

clean();
first_load();



$(".configbox_fold_2").click(function() { window.temp = 1; });

$(".lank_button_grey").click(function() { window.temp = 0; });

$(".first_box").click(function() {
							   
	id = $(this).parent().attr("id");
	
	div_height = 0;							   
	
	div_height = $('#'+id+" div.configbox_fold_2").css("display");
	
	
	if(div_height == 'none')
		window.temp = 0;
	
	if(window.temp == 0)
		{
		folder_up();
	
		for(i = 0 ; i < menu_row.length ; i++)
			{
			if(menu_row[i] == $(this).parent().attr("id"))
				open_and_show(menu_row[i]);
				else
				close_and_save(menu_row[i]);
			}
		}
	});


$("div.color_box").click(function() {
	if($(this).attr("class") == 'color_box')
		{
		id = $(this).parents('div.configbox').attr("id");						   
	
		$("#"+id+" .color_box").removeClass('color_box_choosen');

		tmp = $(this).attr('id').split("-");
		id_box = tmp[2];

		$('input[name="'+menu_letter[id]['form']+'"]').val(id_box);
		close_and_save(id , this);
		folder_up();	
	
	
		}
	});



$(".getvalue").click(function()
	{
	id = $(this).parents('div.configbox').attr("id");
	close_and_save(id , this);
	//sfolder_up();
	//$("#"+id+" div.configbox_fold_2").slideUp('fast', function () {$("#"+id+" div.choise").show();});
	});

$('.color_box img').tooltip({
	track: false,
	delay: 200,
	showURL: false,
	showBody: " - ",
	//opacity: 0.85,
	fixPNG: true, 
	top: -79,
	left: 3
});

$('.symbols_link').click(function()
	{
	
	var temp_symbol_id = $(this).attr("id");
	$("#symbol_box div.f1").slideUp();
	$("#symbol_box div.symbols_link").css("font-weight","normal")
	
		$.post(base_url+"namensbaender/get_symbols", { symbol_id: $(this).attr('id') , type: $('input[name="type"]').val() } , 
		function(data) { 
		
		$("#"+temp_symbol_id).css("font-weight","bold").next().html(data).slideDown(); 

		});
	
	});

$('.symbols_link_top').click(function()
	{
	
	var temp_symbol_id = $(this).attr("id");
	$("#symbol_box div.f1").slideUp();
	$("#symbol_box div.symbols_link").css("font-weight","normal")
	
		$.post(base_url+"namensbaender/get_symbols", { symbol_id: $(this).attr('id') , type: $('input[name="type"]').val() } , 
		function(data) { 
		
		$("#"+temp_symbol_id).css("font-weight","bold").next().html(data).slideDown(); 

		});
	
	});







$('.lank_button_info').toggle(
      function () {
        $('#info_box').slideDown();
      },
      function () {
        $('#info_box').slideUp();
      }
    );


	
});

function grab_picture(id_box)
	{
	parent_id = $('#'+id_box).parents('div.configbox').attr("id");	
	$("#"+parent_id+" .color_box").removeClass('color_box_choosen');
	
	$('input[name="'+menu_letter[parent_id]['form']+'"]').val(id_box);
		
	close_and_save(parent_id , $('#'+id_box));
	folder_up();	

	}

function update_symbols_show(data)
	{

	$('#symbols_show').html(data);
	}





function change_color(tmp ,id)
	{
	tmp_color = tmp.split("#");
	for(i = 1 ; i < tmp_color.length ; i++)
		{
		tmp_color_split = tmp_color[i].split(":");
		if(tmp_color_split[1] == 0)
			{
			$('#picture-'+id+'-'+i).removeClass("color_box").addClass("color_box_no_choise");
			}
			else
			{
			$('#picture-'+id+'-'+i).removeClass("color_box_no_choise").addClass("color_box");
			}
		}
	}


function folder_up()
	{
	
	$(".configbox_fold_2").hide("fast");	
	}

function close_and_save(id ,temp_this , command)
	{
	close_and_save
	$('#'+id+' div.configbox_fold').hide("fast");	
	
	status_ = $('#'+id+' div.lank_button_grey').html();

	type = menu_letter[id]['type'];
	form_temp = menu_letter[id]['form'];
	
	if(status_ == save || command == 'clean')
		{
		if(command == 'clean')
			temp_this = this;
			
		if(type == 'radio')
			{
			value =   $('input[name="'+form_temp+'"]:checked').val();
			
			if(value == undefined)
				{
		
				$(temp_this).children('input[type="radio"]').attr("checked", "checked");
				value =   $('input[name="'+form_temp+'"]:checked').val();
				}
	
	
			if(command == 'clean')
				{
				$('#'+id+" div.choise").html($('#option-'+id+'-'+value+'-text').html());
				}
				else
				$('#'+id+" div.choise").html($(temp_this).next().html());
			
			
			if(form_temp == 'inquery_type' && command != 'clean')
				{
				
				temp_type = $('input[name="temp_type"]').val();
			
				if(temp_type != String(value))
					{
				
					$('input[name="command"]').val('product_change');
					document.form.submit();
					
					}
					
				}
				
			if(form_temp == 'inquery_ribbontype' && command != 'clean')
				{
				value = $('input[name="inquery_ribbontype"]:checked').val();
				
				inquery_numbercolor_tmp = $('input[name="inquery_numbercolor"]:checked').val();
				
				calc_minimum_length();
				
				//if(value == undefined)
				//	value = 1;
					
				max_colours = print_colour[value];
				
				if(inquery_numbercolor_tmp == undefined)
					inquery_numbercolor_tmp = 1;
				
				for(i = 1 ; i <= 5 ; i++)
					{
					if(i <= max_colours)
						$('#inquery_numbercolor_show'+i).css("display", "block");
						else
						$('#inquery_numbercolor_show'+i).css("display", "none");
						
				
					}
				if(inquery_numbercolor_tmp > max_colours)
					{
	
					
					
					
					}
				//alert(max_colours+" "+inquery_numbercolor);
				}
			
			}
	
		if(type == 'text')
			{
			tmp_text = '';
			value =  $('input[name="'+form_temp+'"]').val();
			//alert(form_temp+" "+value)
	
			if(form_temp == 'inquery_amount')
				{
				value_type =  $('input[name="inquery_type"]:checked').val();

				if(value_type == 3)
					{
					tmp_text = amount_ribbon
					}
					else
					{
					tmp_text = amount_label
					}
				}
				
			if(form_temp == 'inquery_size')
				{
				value = $('input[name="height"]').val();
				value_width = $('input[name="width"]').val();
				
				tmp_text = ' * ' + value_width +' mm';
			
				}
			
			if(value == '')
				tmp_text = '';
				
			$('#'+id+" div.choise").html(value+" "+tmp_text);
			}
			
		if(type == 'textarea')
			{
			value =  $('textarea[name="'+form_temp+'"]').val();
				
			$('#'+id+" div.choise").html(value);
			}
	
			
	
		for(i_temp = 0 ; i_temp < menu_row.length ; i_temp++)
			{
			if(menu_row[i_temp] == id)
				position = i_temp +1;
			}
	
			
		if(value == undefined || value == '') 
			{
			$('#'+id+" div.lank_button_grey").html(start).removeClass("lank_button_green").addClass("lank_button_grey");
			$('#'+id+" div.icon").removeClass('icon_no'+position+'_green').addClass('icon_no'+position);
			}
			else
			{
			$('#'+id+" div.lank_button_grey").html(change).addClass("lank_button_green");
			$('#'+id+" div.icon").addClass('icon_no'+position+'_green');
			}

	
		window.temp = 0;
			$("#"+id+" div.configbox_fold_2").slideUp('fast', function () {$("#"+id+" div.choise").show();});
		}
	
	}
	

function calc_minimum_length()
	{
	value_material = 1;
	value_type = $('input[name="inquery_type"]:checked').val();
	
	value = $('input[name="inquery_ribbontype"]:checked').val();
	
	value_inquery_amount = $('input[name="inquery_amount"]').val();
	
	if(value_type == undefined)
		value_type = 1;
		
	if(value == undefined)
		value = 1;
		
	if(value_inquery_amount == undefined || value_inquery_amount == '')
		value_inquery_amount = 0;
	
	
	
	if(value_type == 3)
		{
		
		
		if(value_inquery_amount < minimum_length[value][value_material])
			{

			$('input[name="inquery_amount"]').val(minimum_length[value][value_material]);
			
			if(value_inquery_amount != 0)
				$("#inquery_amount div.choise").html(minimum_length[value][value_material] + ' ' +amount_ribbon);
			}
	
		temp_string = minimum_order_length1 + minimum_length[value][value_material] + minimum_order_length2 + inquery_ribbontype[value] + minimum_order_length3 +inquery_material+ '.';

		$("#info_minimum_length").html(temp_string);
		}
	
	}
	
	
function open_and_show(id)
	{
	status_ = $('#'+id+" div.lank_button_grey").html();

	
	if(status_ == save)
		{
		close_and_save(id)
		}
		else
		{
		$("#"+id+" div.choise").hide();
		$("#"+id+" div.lank_button_grey").html(save);
		$("#"+id+" div.configbox_fold_2").slideDown();
		$("#"+id+" div.configbox_fold").slideDown();
		}
	}

function check_frame()
	{
	frame_value = $('input[name="'+menu_letter[7]["form"]+'"]:checked').val();

		if(frame_value == 2)
		{
		$('#text_3').val('');
		$('#text_row_3').css("display", "block");
		$('#text_row_3_info').css("display", "none");
		}
		else
		{
		$('#text_row_3').css("display", "none");
		$('#text_row_3_info').css("display", "block");
		
		}
	}
	

function clean()
	{
	for(i_clean = 0 ; i_clean < menu_row.length ; i_clean++)
		{
		close_and_save(menu_row[i_clean] ,this , 'clean');
		}
	//check_frame();
	//check_iron();
		
	}

function first_load()
	{

	if($('input[name="inquery_type"]:checked').val() == undefined)	
		{
		open_and_show('inquery_type');	
		}
	}

function open_window()
	{
	$('#wait_until_loaded').show();
	}
