// JavaScript Document

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





var menu_letter = new Array();



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

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

menu_letter["tape_color"]	= new Object();
menu_letter["tape_color"]["form"] = "tape_color";
menu_letter["tape_color"]["type"] = "picture";

menu_letter["text_color"]	= new Object();
menu_letter["text_color"]["form"] = "text_color";
menu_letter["text_color"]["type"] = "picture";

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

menu_letter["font"]	= new Object();
menu_letter["font"]["form"] = "font";
menu_letter["font"]["type"] = "picture";

menu_letter["symbol_1"]	= new Object();
menu_letter["symbol_1"]["form"] = "symbol_1";
menu_letter["symbol_1"]["type"] = "picture_ajax";

menu_letter["symbol_1_reset"]	= new Object();
menu_letter["symbol_1_reset"]["form"] = "symbol_1";
menu_letter["symbol_1_reset"]["type"] = "picture";

menu_letter["symbollaundry_1"]	= new Object();
menu_letter["symbollaundry_1"]["form"] = "symbollaundry_1";
menu_letter["symbollaundry_1"]["type"] = "picture";

menu_letter["symbollaundry_2"]	= new Object();
menu_letter["symbollaundry_2"]["form"] = "symbollaundry_2";
menu_letter["symbollaundry_2"]["type"] = "picture";

menu_letter["symbollaundry_3"]	= new Object();
menu_letter["symbollaundry_3"]["form"] = "symbollaundry_3";
menu_letter["symbollaundry_3"]["type"] = "picture";

menu_letter["symbollaundry_4"]	= new Object();
menu_letter["symbollaundry_4"]["form"] = "symbollaundry_4";
menu_letter["symbollaundry_4"]["type"] = "picture";

menu_letter["symbollaundry_5"]	= new Object();
menu_letter["symbollaundry_5"]["form"] = "symbollaundry_5";
menu_letter["symbollaundry_5"]["type"] = "picture";

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



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

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

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



$(document).ready(function() {

clean();

$(".first_box").click(function() {

	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);
	//check_frame();
	check_iron();
	folder_up();	
	});


$('.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(); 

		});
	
	});



$('.input').change(function()
	{
		value_input = $(this).val();
		
		for (i =0; i <= value_input.length-1; i++)
			{
		if (goodchars.indexOf(value_input.charAt(i))== -1)
			{
			j = value_input.charAt(i)
			l='';
			for (k=0; k<i; k++)
			{
				l = l + value_input.charAt(k);
			}
			for (k = i+1 ; k<=value_input.length-1; k++)
			{
				l = l + value_input.charAt(k)
			}
			i--;
			value_input = l;
			}
		}
	$(this).val(value_input);
	});

$('.input2').change(function()
	{
		value_input = $(this).val();
		
		for (i =0; i <= value_input.length-1; i++)
			{
	
		if (goodchars.indexOf(value_input.charAt(i))== -1 && value_input.charAt(i) != "\n")
			{
			j = value_input.charAt(i)
			l='';
			for (k=0; k<i; k++)
			{
				l = l + value_input.charAt(k);
			}
			for (k = i+1 ; k<=value_input.length-1; k++)
			{
				l = l + value_input.charAt(k)
			}
			i--;
			value_input = l;
			}
		}
	$(this).val(value_input);
	});

$('#add_to_cart').click(function()
	{
	$.post(base_url+"namensbaender/check", $("form").serialize(), check_done); 
	});

$('.lank_button_info').click(
      function () {
        $('#info_box').slideDown();
      });

$('#show_examples').click(function()
	{
	$.post(base_url+"namensbaender/examples",$("form").serialize(), update_examples_now);
	});

$('#text_3').change(function()
	{
	text = $(this).val();
	
	//alert(text);
	});
	
	
	
});


function update_examples_now(data)
	{
	$('#examples').show().html(data);	

	}

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 check_done(data)
	{
	if(data == '')
		{
		document.form.submit();
		}
		else
		{
		$('#error_text').html(data);	
		$('#error').slideDown();
		}
	}



function check_iron()
	{
	pieces_value = $('input[name="'+menu_letter["pieces"]["form"]+'"]:checked').val();
	iron_on_value = $('input[name="'+menu_letter["iron_on"]["form"]+'"]:checked').val();
	//alert(pieces_value);
	if(iron_on_value == 1)
		{
		$('#pieces-1').show();
		$('#pieces-5').show();
		$('#info_pieces_iron_on').hide();
		}
	
	if(iron_on_value == 2)
		{
		$('#pieces-1').hide();
		$('#pieces-5').hide();
		$('#info_pieces_iron_on').show();
		}
	
	
	if((pieces_value >= 2 && pieces_value != 5) || pieces_value == undefined)
		{
		$('#ironon-2').fadeTo('slow',1)
		$('#ironon-2').show();
		$('#iron_show').show();	
		$('#iron_show_info').hide();
		}
		else
		{
		$('#ironon-2').fadeTo('slow',0)
	$('#ironon-2').hide();
		$('#iron_show').hide();
		$('#iron_show_info').show();
		//$('#iron_show_info').css("height", "auto");
		
		
		
		}
	}
	
function update_price()
	{
	$("#working").show();

	$.post(base_url+"namensbaender/price",$("form").serialize(), update_price_now);
	}
	
function update_price_now(data)
	{
	$("#price").html(data);
	$("#base_price").html(data);
	$("#working").hide();
	}
	
function update_picture()
	{
	$(".working").show();
	type =   $('input[name="type"]').val();
	
	check_frame();

	$.post(base_url+"namensbaender/preview",$("form").serialize(), update_picture_now);
	}

function update_picture_now(data)
	{
	//alert(data);
	tmp = data.split("||");
	
	html_code				= tmp[0];
	price_tmp				= tmp[1];
	permitted_text_color	= tmp[2];
	permitted_tape_color	= tmp[3];
	tmp_file				= tmp[4];
	tmp_base_price				= tmp[5];
	tmp_tape_color_price		= tmp[6];
	tmp_iron_on_price			= tmp[7];
	tmp_frame_price				= tmp[8];
	tmp_symbol_price			= tmp[9];
	tmp_text_price				= tmp[10];
	
	change_color(permitted_text_color , "text_color");
	change_color(permitted_tape_color , "tape_color");
	
	$("#picture").val(tmp_file);
	$("#preview").html(html_code);
	
	
	//$("#preview").css("background-image" , "url("+base_url+html_code+")");
	
	$("#price").html(price_tmp);
	$("#base_price").html(tmp_base_price);
	

	
	if(tmp_tape_color_price != '0,00')
		{
		$('#tape_color_price_show').slideDown();
		$('#tape_color_price').html(tmp_tape_color_price);
		}
		else
		$('#tape_color_price_show').slideUp();

	if(tmp_iron_on_price != '0,00')
		{
		$('#iron_on_price_show').slideDown();
		$('#iron_on_price').html(tmp_iron_on_price);
		}
		else
		$('#iron_on_price_show').slideUp();

	if(tmp_frame_price != '0,00')
		{
		$('#frame_price_show').slideDown();
		$('#frame_price').html(tmp_frame_price);
		}
		else
		$('#frame_price_show').slideUp();

	if(tmp_symbol_price != '0,00')
		{
		$('#symbol_price_show').slideDown();
		$('#symbol_price').html(tmp_symbol_price);
		}
		else
		$('#symbol_price_show').slideUp();
		
	if(tmp_text_price != '0,00')
		{
		$('#text_price_show').slideDown();
		$('#text_price').html(tmp_text_price);
		}
		else
		$('#text_price_show').slideUp();

		
	$(".working").hide();
	}

function change_color(tmp ,id)
	{
	//alert(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)
			{
		
			$('#hidepicture-'+id+'-'+tmp_color_split[0]).show();
			$('#picture-'+id+'-'+tmp_color_split[0]).removeClass("color_box").addClass("color_box_no_choise");
			}
			else
			{
			$('#hidepicture-'+id+'-'+tmp_color_split[0]).hide();
			$('#picture-'+id+'-'+tmp_color_split[0]).removeClass("color_box_no_choise").addClass("color_box");
			}
		}
	}


function folder_up()
	{
	$(".configbox_fold").slideUp("fast");
	$("#info_box").slideUp("fast");
	
	}

function close_and_save(id ,temp_this , command)
	{
		

	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(id == 'type_temp')
				{
				type_tempas = $('input[name="type"]').val();	
				
				tmp_value = $('input[name="type_temp"]:checked').val();	
				if(type_tempas != tmp_value)
					{
				if(tmp_value == 'GE')
					{
					window.location.href = url_ge;
					}
				
				if(tmp_value == 'GT')
					{
					window.location.href = url_gt;
					}
				
				if(tmp_value == 'GS')
					{
					window.location.href = url_gs;
					}
				
				if(tmp_value == 'GA')
					{
					window.location.href = url_ga;
					}
					}
			
				
				}
			}
	
		if(type == 'text')
			{
				
			value =   $('input[name="'+form_temp+'\[1\]"]').val();
			$('#'+id+" div.choise").html(value);
			}
			
		if(type == 'picture')
			{
						
			value =   $('input[name="'+form_temp+'"]').val();
	
			temp_type = $('input[name="type"]').val();
			
			if(temp_type == 'GA')
				{
				if(form_temp == 'tape_color')
					{
					if(value == 1)
						$('input[name="text_color"]').val(2);
						else
						$('input[name="text_color"]').val(1);
				
					}
				}
			
			tmp_picture = '';
			if(form_temp == 'symbollaundry_1' || form_temp == 'symbollaundry_2' || form_temp == 'symbollaundry_3' || form_temp == 'symbollaundry_4' || form_temp == 'symbollaundry_5')
				{
				if(value != '')
					{
					tmp_picture = '<div class="show_symbol"><img src="'+url+'assets/general/img/symbols/'+value+'.gif" height="20" border="0"></div>';
					}
				}
			
			
				
			temp_text = $("#"+id+" #picture-"+id+"-"+value).attr("title");

			
		
			if(value == "777") /* Remove choise */
				{
				temp_text	= '';
				value		= '';
				$('input[name="'+menu_letter[id]['form']+'"]').val('');
				}
			if(temp_text == undefined)
				temp_text = '';
			
			$('#'+id+" div.choise").html(tmp_picture + temp_text);
			
			
			$(temp_this).addClass("color_box_choosen");
			
			}
	
			
		if(type == 'picture_ajax')
			{
			value =   $('input[name="'+form_temp+'"]').val();
	
			if(value == "777") /* Remove choise */
				{
				temp_text	= '';
				value		= '';
				$('input[name="'+menu_letter[id]['form']+'"]').val('');
				}
			tmp_picture = '';
			if(form_temp == 'symbol_1')
				{
				if(value != '')
					{
					tmp_picture = '<div class="show_symbol"><img src="'+url+'assets/general/img/symbols/'+value+'.gif" height="20" border="0"></div>';
					}
				}

			
			$('#'+id+" div.choise").html(tmp_picture + value);
			
			$(temp_this).addClass("color_box_choosen");
			}
		
	
			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');
			}

		if($('input[name="'+menu_letter["tape_color"]["form"]+'"]').val() != '' || $('input[name="'+menu_letter["text_color"]["form"]+'"]').val() != '')
			{
			//alert($('input[name="'+menu_letter["text_color"]["form"]+'"]').val());
			update_picture();
			}
		
		if($('input[name="type"]').val() == 'GG' && $('input[name="width"]:checked').val() != undefined && $('input[name="pieces"]:checked').val() != undefined && $('input[name="'+menu_letter["tape_color"]["form"]+'"]').val() == '')
			{
				update_price();
			}
		
		}
	check_frame();
	}
	
function open_and_show(id)
	{
	status_ = $('#'+id+" div.lank_button_grey").html();

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

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

	//alert(frame_value);
		if(frame_value == 1)
		{
	//	$('#text_3').val('');
		$('#text_row_3').css("display", "block");
		///$('#text_row_3_info').css("display", "none");
		}
		else
		{
		$('#text_3').val('');
		$('#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');
		}
		
	if($('input[name="type"]').val() == 'GEGT' || $('input[name="type"]').val() == 'GSGA')
		{
		 $('#type_temp div.lank_button_grey').html(save);	
			
		}
	check_frame();
	check_iron();
		
	}


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

jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
     