// JavaScript Document
function CheckId(id){
	var hod = document.getElementById(id).value;
	if(hod==''){
		return false;
	}else{
		return true;	
	}
}
function CheckForm(){
	var ret = CheckId('jmeno');
	ret = CheckId('kontakt') && ret;
	ret = CheckId('dotaz') && ret;
	return ret;
}

function GetId(id){
	return document.getElementById(id);
}
function InzCount(){
	/*Hodnoty*/
	cena_obyc = 0;
	cena_tucne = 20;
	cena_ramecek = 40;
	cena_tucne_ramecek = 60;
	cena_inverzne = 80;
	cena_fototip1 = 100;
	cena_fototip2 = 120;
	var hodnota = GetId('form_text').value;
	var re = new RegExp('/','g');;
	hodnota = hodnota.replace(re,'');
	var delka = hodnota.length;
	GetId('pocet_znaku').innerHTML = delka;
	var priplatek = 0;
	if(GetId('soukroma').checked){
		var priplatek = 0;
	}
	if(GetId('firemni').checked){
		if(GetId('tucny_text').className=='tucny_text_aktivni'){
			priplatek += 30;
		}
		if(GetId('barva_podkladu').className=='barva_podkladu_aktivni'){
			priplatek += 70;
		}
		if(GetId('foto_inzerce').className=='foto_inzerce_aktivni'){
			priplatek += 500;
		}
	}
	GetId('z_cena').value=delka;
	GetId('priplatky').value=priplatek;
	GetId('cena').value = delka+priplatek;
	if(GetId('pocet').value<1){
		GetId('pocet').value= 1;
	}
	GetId('cena_celk_bez_dph').value = GetId('pocet').value * GetId('cena').value;
	GetId('dph').value = Math.round(GetId('cena_celk_bez_dph').value * 0.20);
	GetId('cena_celk_s_dph').value = GetId('cena_celk_bez_dph').value*1 + GetId('dph').value*1;
}
function BezZvyrazneni(obj){
	clas = 'bez_zvyrazneni';
		obj.className= clas+'_aktivni';
		Deaktivovat('tucny_text');
		Deaktivovat('barva_podkladu');
		Skryt('barva_podkladu_value');
		Deaktivovat('foto_inzerce');
		Skryt('foto_inzerce_value');
		//Nastavit('tucne_zvyrazneni');
		OdNastavit('tucne_zvyrazneni');
		//Nastavit('barevne_zvyrazneni');
		OdNastavit('barevne_zvyrazneni');
		//Nastavit('foto_zvyrazneni');
		OdNastavit('foto_zvyrazneni');
}
function Nastavit(id){
	GetId(id).value = '1';
}
function OdNastavit(id){
	GetId(id).value = '';
}
function Skryt(id){
	GetId(id).style.display = 'none';	
}
function Deaktivovat(id){
	GetId(id).className = id;
}
function TucnyText(obj){
	clas = 'tucny_text';
	if(obj.className==clas){
		obj.className= clas+'_aktivni';
		Deaktivovat('bez_zvyrazneni');
		alert('Text, ktery chce tucne oznacit ohranicte lomitkem (napr. /Tucny text/).');
		Nastavit('tucne_zvyrazneni');
	}else{
		obj.className= clas;
		OdNastavit('tucne_zvyrazneni');
	}
}
function BarvaPodkladu(obj){
	clas = 'barva_podkladu';
	if(obj.className==clas){
		obj.className= clas+'_aktivni';
		Deaktivovat('bez_zvyrazneni');
		GetId(clas+'_value').style.display='block';
		Nastavit('barevne_zvyrazneni');
	}else{
		obj.className= clas;
		GetId(clas+'_value').style.display='none';
		OdNastavit('barevne_zvyrazneni');
	}
}
function FotoInzerce(obj){
	clas = 'foto_inzerce';
	if(obj.className==clas){
		obj.className= clas+'_aktivni';
		Deaktivovat('bez_zvyrazneni');
		GetId(clas+'_value').style.display='block';
		Nastavit('foto_zvyrazneni');		
	}else{
		obj.className= clas;
		GetId(clas+'_value').style.display='none';
		OdNastavit('foto_zvyrazneni');
	}
}
function HideFotos(){
	GetId('foto1').style.display = 'none';
	GetId('foto2').style.display = 'none';
}
function ShowFoto1(){
	GetId('foto1').style.display = 'block';
	GetId('foto2').style.display = 'none';
}
function ShowFoto2(){
	GetId('foto1').style.display = 'none';
	GetId('foto2').style.display = 'block';
}

$(document).ready(function(){
	$('a.popup').lightBox();
	$('#scrollUp').click(function(){$('#roller').scrollTo('-=120px', 1000 );}, function(){});
	$('#scrollDown').click(function(){$('#roller').scrollTo('+=120px', 1000 );}, function(){});
	$('#nav').droppy({speed: 10});
	$("#noviny-archiv").accordion({autoHeight: false,collapsible: true});
	/* KALKULACKA */
	$("#resizable").animate({width: row, height: 70}, 800 );
                $(".p_rep").click(function(){
                    calc_final();
                });
                $(".p_page").click(function(){
                    calc_final();
                });
        /* /KALKULACKA */
});

/* KALKULACKA */
var p=new Array();
            p[1]=20;
            p[2]=23;
            p[3]=34;
            var r=new Array();
            r[0]=new Array();
            r[0][1]=0;
            r[0][2]=0;
            r[0][3]=0;
            r[1]=new Array();
            r[1][1]=25;
            r[1][2]=15;
            r[1][3]=15;
            r[2]=new Array();
            r[2][1]=30;
            r[2][2]=20;
            r[2][3]=20;
            r[3]=new Array();
            r[3][1]=35;
            r[3][2]=25;
            r[3][3]=25;
            r[4]=new Array();
            r[4][1]=40;
            r[4][2]=30;
            r[4][3]=30;

            var row = 84;
            $(function() {
		$("#wid").change(function(){
			new_height = ($(this).val()-1) * 2 ;
			var thisPos = $("#resizable").position();
			var boxPos = $("#containment-wrapper").position();
			var diff_bottom = (thisPos.top 	+ new_height) 	- (boxPos.top + $("#containment-wrapper").height());
			if(diff_bottom>0){
				new_height = new_height - diff_bottom - 3;
			}
			$("#resizable").animate({height:new_height},function(){
				$(this).stayInBox($("#containment-wrapper"));
				calc();
				calc_final();
				}
			);

		});
		position = $("#resizable").position();
                $("#resizable").resizable({ maxHeight: 810, height:40, width:row,maxWidth: 589, minHeight: 10,minWidth: row,grid: [row,2]});
                $("#resizable").draggable({ containment: "#containment-wrapper",scroll: false, grid: [row,2] });

                $("#resizable").bind("resize",function(event,ui) {
			/* FUNKCE BRANI RESIZE ABY SE PRVEK ZVETSIL MIMO STANOVENOU OBLAST */
			$(this).stayInBox($("#containment-wrapper"));
                        calc();
                });
                $("#resizable").bind("resizestop",function(event,ui) {
                    //if(($("#resizable").innerWidth()-3)%row!=0) {
			//CHYBA V IE -> reseno pres GRID u resizable()
                        /*wid = ($("#resizable").width()-3)%row;
                        alert(wid);
                        if(wid>row/2) { wid = row-wid; } else { wid = 0-wid; }
                        $("#resizable").animate({width: $("#resizable").innerWidth()+wid}, 500 );*/
			calc();
                        calc_final();
                    //}
                });

            });
	/*
		FUNKCE BRANI RESIZE ABY SE PRVEK ZVETSIL MIMO STANOVENOU OBLAST
	*/
            jQuery.fn.stayInBox = function(box){
			var thisPos 		= this.position();
			var boxPos 			= box.position();
			var diff_right 	= (thisPos.left + this.width()) 	- (boxPos.left + box.width());
			var diff_bottom = (thisPos.top 	+ this.height()) 	- (boxPos.top + box.height());
			var diff_left 	= boxPos.left 	- thisPos.left;
			var diff_top 		= boxPos.top 		- thisPos.top;
			
			if(diff_right > 0){
				var presah = this.width() - diff_right;
				presah_row = Math.floor((presah-3)/row);
				this.width(presah_row * row);
			}
			if(diff_bottom > 0)
				this.height(this.height() - diff_bottom -3 );
				
			if(diff_left > 0)
				this.css("left", thisPos.left + diff_left);
				
			if(diff_top > 0)
				this.css("top", thisPos.top + diff_top);
		}

            function calc() {
                    $("#wid").val($("#resizable").innerHeight()/2);
                    $("#row").val(Math.round($("#resizable").innerWidth()/row));
            }

            function calc_final() {
                    var wid = $("#wid").val();
                    var rw = $("#row").val();

                    var p_page = $(".p_page:checked").val();
                    var p_rep = $(".p_rep:checked").val();

                    var sleva = 100-r[p_rep][p_page];
                    var opak = p_rep*3;
                    if(opak==0){opak = 1;}
                    var cena = p[p_page];

                    var vysledek = (((rw*wid*cena)*opak)/100)*sleva;

                    //alert(sleva+" |�"+opak+" |�"+cena);
                    //alert(vysledek);
                    $("#price").val(Math.round(vysledek));
                    $("#price_inz").val(Math.round(vysledek/opak));
            }
/* KALKULACKA */
