function generateTrack(data) {
	if(!data.lastPadding) {
        data.lastPadding=0;
    }

    for(a=0;a<data.count-1;a++) {
		$('#'+data.id+' .track-steps').append('<span style="left:'+(18+Math.floor((562-data.lastPadding)/(data.count-1)*(a+1)))+'px;"></span>');
	}

	countLi=$('#'+data.id+' li').length

	$('#'+data.id+' li').css({'padding-right': Math.floor(((664-data.lastPadding)-102*(countLi))/(countLi-1))+'px'});
	$('#'+data.id+' li.last').css({'padding-right': '0px'});
    if (data.value > 0) {
	    $('#'+data.id+' .track').slider({ step: data.step, min: data.min, max: data.max, value: data.value });
    }
    else {
        $('#'+data.id+' .track').slider({ step: data.step, min: data.min, max: data.max });
    }
    //$('#'+data.id+' .track').bind( "slidestop", function(event, ui) {
    //    xwCart.check_price_cloud();
    //});
    //$( '#'+data.id+' .track' ).bind( "slidecreate", function(event, ui) {
  	//	xwCart.check_price_cloud();
	//});
    $( '#'+data.id+' .track').bind( "slidechange", function(event, ui) {
            xwCart.check_price_cloud();
    });
	$('#'+data.id+' .track').css({'width': (560-data.lastPadding)+'px'});
}

$(document).ready(function () {
	if($('.select-line').length>0) { $('.select-line').jqTransform({imgPath:'public/design/frontend/images/'}); }
	
	//$('.x_partner_1').center({horizontal: true});
	//$('.x_partner_2').center({horizontal: true});
	//$('.x_partner_3').center({horizontal: true});
	//$('.x_partner_4').center({horizontal: true});
	//$('.x_partner_5').center({horizontal: true});


	$('#inputSearch').focus(function(){ if(this.value==this.defaultValue){this.value='';} $(this.parentNode.parentNode).addClass('focus'); });
	$('#inputSearch').blur(function(){ if(this.value==''){this.value=this.defaultValue;} $(this.parentNode.parentNode).removeClass('focus'); });

	$('#inputDomain').focus(function(){ $(this.parentNode).addClass('focus'); });
	$('#inputDomain').blur(function(){ $(this.parentNode).removeClass('focus'); });

	$('.help-search .input').focus(function(){ if(this.value==this.defaultValue){this.value='';} });
	$('.help-search .input').blur(function(){ if(this.value==''){this.value=this.defaultValue;} });

	$('.services-list label input').change(function(){
		$('.services-list .show').removeClass('show');
		if(this.checked)
		{
			$(this.parentNode.parentNode).addClass('show');

            if (this.id == 'service1') {
                $('#submit_cart_button').attr('disabled', '');

                xwCart.update_price('domain_'+sessionid());

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                document.getElementById('hosting_items').style.display = 'none';
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });
            }
            else if(this.id == 'service2') {
                $('#submit_cart_button').attr('disabled', '');

                xwCart.update_price('domain_'+sessionid());

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                document.getElementById('hosting_items').style.display = 'none';
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });
            }
            else if(this.id == 'service3') {
                $('#submit_cart_button').attr('disabled', 'disabled');
            }
		}
	});

	$('.client-type').change(function(){
		if(this.checked)
		{
			if(this.id=='clientType1') {
                $('#client-type')[0].className='show1';

                document.getElementById('mail_address').style.display = 'none';
                document.getElementById('contact_details').style.display = 'none';
                document.getElementById('login_details').style.display = 'none';
            }
			else if(this.id=='clientType2') {
                $('#client-type')[0].className='show2';

                document.getElementById('mail_address').style.display = 'none';
                document.getElementById('contact_details').style.display = 'block';
                document.getElementById('login_details').style.display = 'block';
            }
			else if(this.id=='clientType3') {
                $('#client-type')[0].className='show3';

                document.getElementById('mail_address').style.display = 'none';
                document.getElementById('contact_details').style.display = 'block';
                document.getElementById('login_details').style.display = 'block';
            }
		}
	});

    $('.checkOtherAddress').change(function(){
        if (this.checked) {
            document.getElementById('mail_address').style.display = 'block';
        }
        else {
            document.getElementById('mail_address').style.display = 'none';
        }
    });

	if($('.form-order .summary').length>0) {
		heightForm=$('.form-order').height();
		heightSummary=$('.form-order .summary').height();
		scrollTop=$(document).scrollTop();
		offsetSummary=57;
                $('body').scroll(function(){
                        newScroll=$(document).scrollTop();;
                        offsetSummary+=(newScroll-scrollTop);
                        if(offsetSummary<57) { offsetSummary=57; }
                        else if(offsetSummary>heightForm-heightSummary-40) { offsetSummary=heightForm-heightSummary-40; }
                        $('.form-order .summary').css({marginTop: offsetSummary+'px'});
                        scrollTop=newScroll;
                });

		$(document).scroll(function(){
			newScroll=$(document).scrollTop();;
			offsetSummary+=(newScroll-scrollTop);
			if(offsetSummary<57) { offsetSummary=57; }
			else if(offsetSummary>heightForm-heightSummary-40) { offsetSummary=heightForm-heightSummary-40; }
			$('.form-order .summary').css({marginTop: offsetSummary+'px'});
			scrollTop=newScroll;
		});
	}

	$('.nonselectall-table .checkable').change(function(){
		obj=$('.nonselectall-table .checkable');

		for(a=0;a<obj.length;a++)
		{
			if(obj[a].checked) { $(obj[a].parentNode.parentNode).addClass('checked'); }
			else { $(obj[a].parentNode.parentNode).removeClass('checked'); }
		}
	});
	$('.selectall-table .checkable').change(function(){
		if(this.checked) { $(this.parentNode.parentNode).addClass('checked'); }
		else { $(this.parentNode.parentNode).removeClass('checked'); $('#checkAll')[0].checked=false; }
	});

	
	$('#main-banner').widget();

	$('#group-container .name input').change(function(){
		$('#group-container')[0].className='group-content';
		obj=$('#group-container .name input:checked');
		for(a=0;a<obj.length;a++)
		{
			$($('#group-container')[0]).addClass('selected-'+obj[a].id);
		}
	});

	$('.radio-line input').change(function(){
		$('.radio-line .selected').removeClass('selected');
		obj=$('.radio-line input:checked');
		for(a=0;a<obj.length;a++)
		{
			$(obj[a].parentNode.parentNode).addClass('selected');
		}
	});

	$('.radio-line .selected').removeClass('selected');
	obj=$('.radio-line input:checked');
	for(a=0;a<obj.length;a++)
	{
		$(obj[a].parentNode.parentNode).addClass('selected');
	}

    $('.lightbox').lightbox();


    $("#server1text").blur(function() {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox1").removeClass().addClass('messagebox').text('Sprawdzam...').fadeIn("slow");
        //check the username exists or not from ajax
        var hostingname = $(this).val();
        $.post(base_uri("ajax/check_hosting_login"),{ username:$(this).val() }, function(data) {
            if(data=='no') {
                $("#msgbox1").fadeTo(200,0.1,function() {
                    $(this).html('Zajęty').addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
            else if (data == 'yes') {
                $("#msgbox1").fadeTo(200,0.1,function() {
                    $(this).html('Wolny').addClass('messageboxok').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', '');

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });

                document.getElementById('hosting_items').style.display = 'block';
                
                $('<li id="hosting_1">'+hostingname+'</li>').appendTo('#hosting_items ul');
            }
            else {
            	$("#msgbox1").fadeTo(200,0.1,function() {
                    $(this).html(data).addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
        });
    });

    $("#server2text").blur(function() {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox2").removeClass().addClass('messagebox').text('Sprawdzam...').fadeIn("slow");
        //check the username exists or not from ajax
        var hostingname = $(this).val();
        $.post(base_uri("ajax/check_hosting_login"),{ username:$(this).val() }, function(data) {
            if(data=='no') {
                $("#msgbox2").fadeTo(200,0.1,function() {
                    $(this).html('Zajęty').addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
            else if (data == 'yes') {
                $("#msgbox2").fadeTo(200,0.1,function() {
                    $(this).html('Wolny').addClass('messageboxok').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', '');

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });

                document.getElementById('hosting_items').style.display = 'block';

                $('<li id="hosting_1">'+hostingname+'</li>').appendTo('#hosting_items ul');
            }
            else {
            	$("#msgbox2").fadeTo(200,0.1,function() {
                    $(this).html(data).addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
        });
    });

    $("#server3text").blur(function() {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox3").removeClass().addClass('messagebox').text('Sprawdzam...').fadeIn("slow");
        //check the username exists or not from ajax
        var hostingname = $(this).val();
        $.post(base_uri("ajax/check_hosting_login"),{ username:$(this).val() }, function(data) {
            if(data=='no') {
                $("#msgbox3").fadeTo(200,0.1,function() {
                    $(this).html('Zajęty').addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
            else if (data == 'yes') {
                $("#msgbox3").fadeTo(200,0.1,function() {
                    $(this).html('Wolny').addClass('messageboxok').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', '');

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });

                document.getElementById('hosting_items').style.display = 'block';

                $('<li id="hosting_1">'+hostingname+'</li>').appendTo('#hosting_items ul');
            }
            else {
            	$("#msgbox3").fadeTo(200,0.1,function() {
                    $(this).html(data.message).addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
        });
    });

    $("#server4text").blur(function() {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox4").removeClass().addClass('messagebox').text('Sprawdzam...').fadeIn("slow");
        //check the username exists or not from ajax
        var hostingname = $(this).val();
        $.post(base_uri("ajax/check_hosting_login"),{ username:$(this).val() }, function(data) {
            if(data=='no') {
                $("#msgbox4").fadeTo(200,0.1,function() {
                    $(this).html('Zajęty').addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
            else if (data == 'yes') {
                $("#msgbox4").fadeTo(200,0.1,function() {
                    $(this).html('Wolny').addClass('messageboxok').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', '');

                //najpierw trzeba usunac wszystkie elementy hostingu ktore byly dodane wczesniej
                $('#hosting_items ul li').each(function(index) {
                    $(this).remove();
                });

                document.getElementById('hosting_items').style.display = 'block';
                
                $('<li id="hosting_1">'+hostingname+'</li>').appendTo('#hosting_items ul');
            }
            else {
            	$("#msgbox4").fadeTo(200,0.1,function() {
                    $(this).html(data.message).addClass('messageboxerror').fadeTo(900,1);
                });

                $('#submit_cart_button').attr('disabled', 'disabled');
            }
        });
    });
});

$.fn.widget = function () {

	return this.each(function () {
		var open = 0;
		var items = null;
		items = $('.panel-list li', this).hide();

		for(var i=0;i<items.length;i++)
		{
			$('.panel-navigator', this).append('<li'+((i==open)?' class="selected"':'')+'><a href="#" onclick="gotoWidget('+i+');return false">'+i+'</a></li>');
		}

		$(items[open]).show();

		function gotoPage(x)
		{
			if(x!=open)
			{
				$(items[open]).fadeOut(
					function()
					{
						links = $('#main-banner .panel-navigator li');
						y=x;
						if(y>=items.length) { y=0; }
						else if(y<0) { y=items.length-1; }
						open=y;

						$('#main-banner .panel-navigator .selected').removeClass('selected');
						$(links[open]).addClass('selected');
					}
				);
				y=x;
				if(y>=items.length) { y=0; }
				else if(y<0) { y=items.length-1; }
				open=y;
				$(items[open]).fadeIn();
			}
		}

		gotoWidget = function(x) { gotoPage(x); };
		gotoNext = function(x) { gotoPage(open+1); };

		setInterval('gotoNext()', 5000);
	});
};


function dialogDisclaimer() {
    if (!$.cookie('disclaimer')) {
			embeds = document.getElementsByTagName('embed');
			for(i = 0; i < embeds.length; i++) {
				embeds[i].style.visibility = 'hidden';
			}

			objects = document.getElementsByTagName('object');
			for(i = 0; i < objects.length; i++) {
				objects[i].style.visibility = 'hidden';
			}

			iframes = document.getElementsByTagName('iframe');
			for(i = 0; i < iframes.length; i++) {
				iframes[i].style.visibility = 'hidden';
			}

			$("#dialogDisclaimer").dialog({
				bgiframe: true,
				resizable: false,
				draggable: false,
                autoOpen: true,
				height:600,
				width:600,
				closeText: 'hide',
				modal: true,
                closeOnEscape: false,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					 'NIE AKCEPTUJĘ': function() {
						window.location.href = '/';
					},
					'AKCEPTUJĘ': function() {
						$.cookie('disclaimer', '1');
						embeds = document.getElementsByTagName('embed');
						for(i = 0; i < embeds.length; i++) {
							embeds[i].style.visibility = 'visible';
						}

						objects = document.getElementsByTagName('object');
						for(i = 0; i < objects.length; i++) {
							objects[i].style.visibility = 'visible';
						}

						iframes = document.getElementsByTagName('iframe');
						for(i = 0; i < iframes.length; i++) {
							iframes[i].style.visibility = 'visible';
						}
						$(this).dialog('close');
					}
				}
			});

            $('.ui-dialog-titlebar-close').hide();
		}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

