function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		$("#countdown").html( (limitNum - limitField.value.length ).toString() );
	}
}

function toggle_faq(faqid) {
	
	$("#" + faqid).slideToggle("fast");
	$("#q" + faqid).toggleClass("open");
}

function toggle_faq_pomoc() {
		
	$("#a1").slideToggle("fast", function()
			{
				window.location = "#pomoc";								 
			}
	);
	$("#qa1").toggleClass("open");
}

function bon_step3()
{
	$("#slide1").hide();
	$("#slide2").hide();
	$("#slide3").fadeIn(500);
	
	$("#step2").removeClass("active");
	$("#step3").addClass("active");
}

function get_bon_type()
{
    return $('#bon_type').val();
}

function bon_step2()
{
	var step2_title = {
		1: "Odabrali ste <em><strong>e-mail</strong></em> bona! Odaberite vrijednost bona!",
		2: "Odabrali ste <em><strong>vlastiti isprint</strong></em> bona! Odaberite vrijednost bona!",
		3: "Odabrali ste <em><strong>slanje bona poštom!</strong></em> Odaberite vrijednost bona!<br /><span>Za slanje poštom vrijednosnog pisma obračunava se dodatna poštarina naznačena ispod svakog bona.</span>"
	};
	
	$("#slide1").hide();
	$("#slide2").fadeIn(500);
	
	$("#step2_title").html( step2_title[get_bon_type()] );
	
	$("#step1").removeClass("active");
	$("#step2").addClass("active");
}

function bon_step1()
{
	$("#slide0").fadeOut(500, function ()
	{
		$("#slide1").fadeIn(500);
		$("#step1").addClass("active");
	}
	);
}



function set_bon_type( $p_type )
{
    $('#bon_type').val( $p_type );
	
	bon_step2();
}

function set_bon_value( $p_value )
{
    $('#bon_value').val( $p_value );
	
	if ( get_bon_type() == 1 ){
		bon_step3();
	}
	else {
		bon_cart_add();
	}
}

function get_bon_value()
{
    return $('#bon_value').val();
}

function bon_cart_add()
{
	//check
	var tip_bona = $('#bon_type').val();
	var ime = '';
	var email = '';
	if( ! tip_bona ){ alert('Morate odabrati tip bona!'); return false; }
	
	if( tip_bona == 1 )
	{
		ime = $('#bon_to_ime').val();
		email = $('#bon_to_email').val();
	
		if( ime.length < 3 ){ alert('Molimo upišite ime primatelja bona'); return false; }
		if( email.length < 5 ){ alert('Molimo upišite e-mail adresu primatelja'); return false; }
	}
	
	var url = APP_REWRITE_BASE + 'index.php?cmd=show_shopping_cart&action=ajax_add_item';
	var sc_input_data = {
		type: tip_bona,
		to_name: ime + ' ' + $('#bon_to_prezime').val(),
		to_email: email,
		message: $('#bon_message').val()
	};
	
    $.get( url, { proizvod_id: get_bon_value(), arr_item_data: $.toJSON(sc_input_data) }, function( data )
    {
        window.location.replace(APP_REWRITE_BASE + 'index.php?cmd=show_shopping_cart');
	}
	);
}
