
function doLogin(){
    $('.pLoginLoader').show();
    $.ajax({
        type: 'POST',
        url: 'user.php',
        dataType: 'json',
        data: $('#formLogin').formSerialize(),
        success: function(data){
            if ( data['url'] != undefined ) {
                window.location = data['url'];
            } else {
                $('.pError ul').html( errorMsg(data) );
                $('.pError').slideDown();
                $('.pLoginLoader').hide();
            }
        }
    });
    return false;
}


function errorMsg(aMsgs){
    sMsgs = '';
    for( var i in aMsgs ){
        sMsgs += '<li>' + aMsgs[i] + '</li>';
    }
    return sMsgs
}









		/*  FUNCTION FOR OPEN NEW WINDOWS WITH LARGE PICTURE  */

		function showPicture( documentID, pictureID ) {
			window.open( '/showPicture.php?iDocumentID=' + documentID + "&iPictureID=" + pictureID, 'foto', 'width=400,height=300,left=50,top=50,scrollbars=1' );
			return false;
		}
		
		
		/*  FUNCTION FOR OPEN NEW WINDOWS WITH LARGE PICTURE  */
		
		function showPictureForVideo( picturePreview ) {
			window.open( '/showPictureForVideo.php?iPicturePreview=' + picturePreview, 'foto', 'width=400,height=300,left=50,top=50,scrollbars=1' );			
		}
		
		function showFlashVideo( flashVideo ) {
			window.open( '/showFlashVideo.php?iflashVideo=' + flashVideo, 'flashVideo', 'width=675, height=675, left=20, top=20' );			
		}



		/*  FUNCTION FOR ADDING URL TO FAVORITE LINKS  */

		function AddFavorite( linkObj, addUrl, addTitle ) {
			if ( document.all && !window.opera ) {
				window.external.AddFavorite( addUrl, addTitle );
				return false;
			} else if ( window.opera && window.print ) {
				linkObj.title = addTitle;
				return true;
			} else if ( ( typeof window.sidebar == 'object') && ( typeof window.sidebar.addPanel == 'function' ) ) {
				if ( window.confirm( 'Přidat oblíbenou stránku jako nový panel?' ) ) {
					window.sidebar.addPanel( addTitle, addUrl, '' );
					return false;
				}
			}
			window.alert( 'Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.' );
			return false;
		}



		/*  FUNCTION FOR SHOWING CLOCKS  */

		function showClocks() {

			defNow	= new Date();

			with( defNow ) {
				defHours	= getHours();
				defMinutes	= getMinutes();
				defSeconds	= getSeconds();
			}

			defTime	 = ( ( defHours < 10 ) ? "0" : ""  ) + defHours;
			defTime	+= ( ( defMinutes < 10 ) ? ":0" : ":" ) + defMinutes;
			defTime	+= ( ( defSeconds < 10 ) ? ":0" : ":" ) + defSeconds;

			document.getElementById('pageClocks').innerHTML = defTime;
			window.setTimeout( "showClocks()", 1000 );

		}



		/*  FUNCTION: FOR LINK CONFIRMATION  */

		function confirmLink( theLink, theMessage ) {

			if ( typeof( window.opera ) != 'undefined' ) {
				return true;
			}

			var is_confirmed = confirm( theMessage );
			if ( is_confirmed ) {
				theLink.href += '&is_js_confirmed=1';
			}
			return is_confirmed;

		}


		/*  FUNCTION: FOR LINK CONFIRMATION  */

		function voteGallery( documentID, defVote ) {

			window.location = "/document.php?doAction=documentVote&iDocumentID=" + documentID + "&doVote=" + defVote;

		}


		/*  FUNCTION: FOR SHOWING FAQ ANSWER  */

		function showFaqAnswer( questionID, answerID ) {

			defQuestion		= document.getElementById( questionID );
			defAnswer		= document.getElementById( answerID );

			if ( defAnswer.style.display == "none" ) {
				defQuestion.className	= "questionActive";
				defAnswer.style.display	= "block";
			} else {
				defQuestion.className	= "";
				defAnswer.style.display	= "none";
			}

			return false;

		}



		function addForm( defURL ) {
			window.open( defURL, 'addForm', 'width=800,height=500,left=50,top=50,scrollbars=1' );
			return false;
		}



        function showBox( boxID ) {

            document.getElementById('picture_1').style.display = 'none';
            document.getElementById('picture_2').style.display = 'none';
            document.getElementById('picture_3').style.display = 'none';
            document.getElementById('picture_4').style.display = 'none';
            document.getElementById('picture_5').style.display = 'none';
            document.getElementById('picture_6').style.display = 'none';
            document.getElementById('title_1').style.display = 'none';
            document.getElementById('title_2').style.display = 'none';
            document.getElementById('title_3').style.display = 'none';
            document.getElementById('title_4').style.display = 'none';
            document.getElementById('title_5').style.display = 'none';
            document.getElementById('title_6').style.display = 'none';

            document.getElementById('picture_'+boxID).style.display = 'block';
            document.getElementById('title_'+boxID).style.display = 'block';

        }


    function documentRating(item)
    {
        $.getJSON($(item).attr('href'), function(data){
            $('#' + data['element']).text(data['rating']);
            $('#' + data['element_voters']).text(data['voters']);
        });
    }


    $(document).ready(function() {
        $('#formLogin').bind('submit',function(){return doLogin();});
        $(".lightbox").lightbox();
        $("a[rel*='lightbox']").lightbox();
        $("a[href*='upload']").lightbox();
        $("a[rel='linkExternal']").addClass('linkExternal');
        $("a[rel='linkExternal']").click( function() {
            window.open( $(this).attr('href') );
            return false;
        });
        $('#pBanner').jcarousel({
            auto: 3,
            scroll: 1,
            wrap: 'last'
        });
        $('.rate').bind('click', function(){
            documentRating(this);
            return false;
        });
    });



