//<script type="text/javascript">

//var ROOT = '/2009/1181/';
var ROOT = '/';

$(function(){
        $("a[rel^='gallery']").prettyPhoto({theme:'dark_square'});

        $('#slideshow').cycle();

        $("#domainChecker button").click(function(){

        	var button = $(this);
        	button.html('<img src="'+ROOT+'admin/img/loading.gif" alt="" style="margin:0 1px -4px 0;" />');


                $("#domainCheckerResult").html('').removeClass('msg').removeClass('err');

        	var domain = $("#domain2").val() + '.' + $("#domain1").val();
                $.post(ROOT + 'admin/front/ajax.php?ajax=domain',{
                	domain: domain
                },function(data){
                	if(data.result == 'false'){
                        	$("#domainCheckerResult").removeClass('msg');
                                $("#domainCheckerResult").addClass('err');
                        	$("#domainCheckerResult").html(_('Doména')+' <b>'+ data.domain +'</b> '+_('nie je voľná.'));
                        }else if(data.result == 'error'){
                                $("#domainCheckerResult").removeClass('msg');
                                $("#domainCheckerResult").addClass('err');
                                if(data.error == 'invalid'){
	                        	$("#domainCheckerResult").html(_('CHYBA! Nesprávny tvar domény (Môže obsahovať iba písmená, čísla a pomlčky).'));
                                }else{
					$("#domainCheckerResult").html(_('CHYBA! Server je nedostupný! Pokúste sa overiť voľnosť domény neskôr.'));
                                }
                        }else{
                        	$("#domainCheckerResult").removeClass('err');
                                $("#domainCheckerResult").addClass('msg');
                        	$("#domainCheckerResult").html(_('Doména')+' <b>' +data.domain +'</b> '+_('je voľná.'));
                        }

                        button.html('OK');
                },'json');
        });

        $("#order-standard, #order-professional").click(function(){
        	var type = $(this).attr('id').split('-')[1];

                var form = $.ajax({
		     method: "get",
		     url: ROOT + 'admin/front/ajax.php?ajax=orderForm&type='+type,
		     async: false
		}).responseText;

        	$("body").append('<div id="dialog">'+form+'</div>');

        	$("#dialog").dialog({
	        	bgiframe: true,
			resizable: false,
                        modal: true,
			height: 500,
			width: 500,
	                dialogClass: 'dialog',
	                close: function(event,ui){
	                       $("#dialog").remove();
	                },
                        open: function(event,ui){
	                       $("#dialog button").click(function(){
                               		var type = $("#dialog input[name='type']").val();
                               		var domain = $("#dialog input[name='domain']").val();
					var firm = $("#dialog input[name='firm']").val();
                                        var address = $("#dialog input[name='address']").val();
                                        var city = $("#dialog input[name='city']").val();
                                        var zip = $("#dialog input[name='zip']").val();
                                        var ico = $("#dialog input[name='ico']").val();
                                        var dic = $("#dialog input[name='dic']").val();
                                        var contactPerson = $("#dialog input[name='contactPerson']").val();
                                        var phone = $("#dialog input[name='phone']").val();
                                        var mail = $("#dialog input[name='mail']").val();
                                        var address2 = $("#dialog input[name='address2']").val();
                                        var city2 = $("#dialog input[name='city2']").val();
                                        var zip2 = $("#dialog input[name='zip2']").val();

                                        if(domain === '' || firm === '' || address === '' || city === '' || zip === '' || ico === '' || dic === '' || mail === ''){
                                        	alert(_('Nevyplnili ste všetky povinné polia označené hviezdičkou!'));
                                                $("#dialog .mandatory").css({
		                                           color: '#494949',
		                                           background: '#fff'
		                                });

                                                $("#dialog .mandatory input").each(function(){
                                                	if($(this).val() === ''){
	                                                        $(this).parent().parent().css({
		                                                	color: '#c5422b',
		                                                        background: '#ffd0d0'
		                                                });
                                                        }
                                                });
                                        }else{
                                                var buttonWidth = $(this).outerWidth();
                                                $(this).css({
                                                	width: buttonWidth+'px',
                                                        'text-align': 'center'
                                                });
                                        	$(this).html('<img src="'+ROOT+'admin/img/loading.gif" alt="" style="margin-bottom:-4px;" />');

                                                $.post(ROOT + 'admin/front/ajax.php?ajax=orderPost',{
                                                	type: type,
				                	domain: domain,
                                                        firm: firm,
                                                        address: address,
                                                        city: city,
                                                        zip: zip,
                                                        ico: ico,
                                                        dic: dic,
                                                        contactPerson: contactPerson,
                                                        phone: phone,
                                                        mail: mail,
                                                        address2: address2,
                                                        city2: city2,
                                                        zip2: zip2
				                },function(data){
                                                	if(data.status == 'true'){
	                                                	$("#dialog").html('<div class="msg">'+_('Objednávka bola úspešne odoslaná! Ďakujeme.')+'</div>');
                                                        }else{
								$("#dialog").html('<div class="err">'+_('Prepáčte, pri odosielaní nastala chyba! Objednávka nebola odoslaná!')+'</div>');
                                                        }
				                },'json');
                                        }
                               });
	                }
		});
        });

        $("#calculation tr").each(function(i){
        	if((i+1) % 2 == 0 && $(this).hasClass('empty') === false){
                	$(this).css('background','#ebebeb');
                }
        });
});

