
var map = null;
var geocoder = null;
var batch = [];

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(50.13, 14.4208), 6);
map.enableScrollWheelZoom();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

geocoder = new GClientGeocoder();
}
}

function showAddress(address, profil) {
if (geocoder) {
geocoder.getLatLng(
  address,
  function(point) {
    if (!point) {
      
    } else {
     // map.setCenter(point, 13);
      var marker = new GMarker(point);
      map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() {
	  if (profil == '') {
		marker.openInfoWindowHtml("Tady bydlím...");
	  } else {
		marker.openInfoWindowHtml(profil);
	  }
       });

    }
  }
);
}
}

function findDog(region) {
    initialize();
    showAddress(region, '');
}


function showAddRaceIn(id)
{	
	if(id == 999)
	{
		$('#raceAddition').show();
	}
	else
	{
		$('#raceAddition').hide();
	}
}

function controlVoteClick()
{

}

//left col calendar ajax

function change_month(month, year)
{

    $.post('/ajax/kalendar.php', 'ajax=1&month='+month+'&year='+year, function(response){
		$("#calendar_div").html(response).hide().fadeIn(1000);
	});
    return false;
}

function change_month_x(month, year)
{

    $.post('/ajax/kalendar.php', 'ajax=1&center=1&month='+month+'&year='+year, function(response){
	    $("#calendar_divx").html(response).hide().fadeIn(1000);
	});
    $.post('/ajax/akce.php', 'month='+month+'&year='+year, function(response){
	    $("#actionList").html(response).hide().fadeIn(1000);
	});
    return false;
}


function sendGift(pets_id, pet_gifts_id, gift_name, bonus_points_price)
{
	if (confirm('Opravdu chcete poslat dárek '+gift_name+'? Bude Vám odečteno '+bonus_points_price+' bodů.')){
		$.post('/ajax/darek.php', 'pets_id='+pets_id+'&pet_gifts_id='+pet_gifts_id, function(response){
			if (response == 'ok') {
				alert('Dárek byl odeslán');
				window.location.reload(true);
			} else if (response == 'credits') {
				alert('Nemáte dostatek bodů');
			} else {
				alert(response);
			}
		});
	}
}

$(document).ready(function() {
	
		
	//
	 
	    refillInputs('input[type=text]');
	    refillInputs('input[type=password]');
	    refillCheckbox('input[type=checkbox]');
	    refillTextarea();
	 
	var clickCounter = false;
	    	    
	    
	    
	    
    /* VALIDACE */
	 
	
	/* upravit mazlicka - pridat foto */
	
	$('form#foto_form').submit(function(){
		
		if($('#foto_file_update').css('display') == 'none')
		{
			if($('input.addFotoPlused').val() == '')
			{
				alert('Vložte prosím první soubor k nahrání, nelze uložit prázdný formulář.');
				return false;
			}
		}
		
		
			
	})
	
	
	
	
	
	
	/* search */
	 
	 $('form#main-search-form').submit(function(){
	 
		 if($('#search_what').val() == '')
		 {
			 alert('Zadejte frázi pro výhledání');
			 return false;
		 }
		 
		 var strSearch = $('#search_what').val();

		 if(strSearch.length < 3)
		 {
			 alert('Zadejte minimálně 3 znaky.');
			 return false;
		 }
		 
	 })
	 
	
	/* registration form */

	$('form#registration-form').submit(function(){
	    
        var inLogin = $('input#user_login');
        var inPass1 = $('input#user_pass');
        var inPass2 = $('input#user_pass2');
        var inName = $('input#user_name');
        var inSurname = $('input#user_surname');
		var inEmail = $('input#user_email');
		var inTermsAgree = $('input#user_terms_agree');
        var inCaptcha = $('input#captcha');

        validateEmpty(inLogin, 'login', true);
        validateEmpty(inPass1, 'heslo', true);
        validateEmpty(inPass2, 'heslo', true);
        validateEmpty(inName, 'jméno', true);
        validateEmpty(inSurname, 'přijmení', true);
        validateEmpty(inEmail, 'e-mail', true);
        validateEmpty(inCaptcha, 'ochranný kód', false);
        
        validateInputString(inLogin, 'Obsahuje nestandartní znaky', true);
        validateInputString(inName, 'Obsahuje nestandartní znaky', true);
        validateInputString(inSurname, 'Obsahuje nestandartní znaky', true);
                
		validateMail(inEmail, true);
        validateCompareSamePass(inPass1, inPass2);
        validateCheckbox(inTermsAgree, 'Zaškrtněte souhlas se zpracováním os. údajů.');
                

		if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
                     
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}
	})
	
	/* komentare k detailu profilu validace */
        
	$('form#pet-detail-comments-form').submit(function(){
		
		if($('#comment_textarea_id').val() == '')
		{
			alert('Nebyl vyplněn komentář!');
			return false;
		}
		
	})
	
	/* vlozeni foto k mazlickovi */
        
	var addFotoCounter = 1;
	
	$('#addFotoInput').click(function(){
		
		if(addFotoCounter < 7)
		{
			$('#addFotoArea').append('<input type="file" name="file[]" /><br />');		
			addFotoCounter++;
		}
		
		
		
	})
	
	
	if($('p').hasClass('fotoExist'))
	{
		
	}
	else
	{
		$('#foto_main_1').attr('checked', 'checked');
	}
	
    /* edit user form */
        
    $('form#user-edit-form').submit(function(){
	    
        var inName = $('input#user_name');
        var inSurname = $('input#user_surname');
        var inEmail = $('input#user_email');
        
        validateInputString(inName, 'Obsahuje nestandartní znaky', false);
        validateInputString(inSurname, 'Obsahuje nestandartní znaky', false);
        
        validateMail(inEmail, false);
        
        if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
                     
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}

        
    })
    
    /* pridat recpet - ingredience */
    
    maxInputCount = 11;
    inputCount = 1;
    
    $('#cookbook_button').click(function(){
    	
    	if(inputCount <= maxInputCount)
    	{
    		$('#cookbook_perex_row_' + inputCount).show();
        	inputCount++;
    	}
    	else
    	{
    		$('#cookbook_button').css('visibility', 'hidden');
    	}
    	
    })
    
    /* add pet form */    
    
    $('form#add-pet-form').submit(function(){
    	
    	errCounter = 0;
    	
    	$('span.error-msg').html('');
    	
    	newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
    	
    	
	    
        var inName = $('input#pet_name');
        var inSex = $('select#pet_sex');
        var inBirth = $('input#pet_birth');
        var inRace = $('select#pet_race');
	
	var inRaceSpecial = $('input#race_addition');
	
	if(inRace.val() == 999)
	{
		validateEmpty(inRaceSpecial, 'popis plemene', true);
	}
        
	
        
        
        inBirth.removeClass('notValid');
        inRace.removeClass('notValid');
        
        validateEmpty(inName, 'jméno', true, 3);     
        
        validateEmpty(inRace, 'plemeno', true);        
        validateEmpty(inSex, 'pohlaví', true);
        
        validateEmpty(inBirth, 'datum narození', true);
        validateInputString(inName, 'Obsahuje nestandartní znaky', true);


        if(errCounter > 0)
        {
        	$('#errCounterArea').html('Bylo nalezeno '+errCounter+' chyb!');
        }
        
        if($('input').hasClass('notValid')){
        	location.href=newURL + '#pet_name'
        	
		    return false;
		
		} else {
			
			if(inBirth.hasClass('notValid'))
			{
				return false;				
			}
			if(inRace.hasClass('notValid'))
			{
				return false;				
			}
			if(inName.val() == '')
	        {
				return false;
	        }
			if(inBirth.val() == '')
	        {
				return false;
	        }
			
            return true;
		    
		}

        
        
        
    })

    /* add recipe form */
        
    $('form#add-recipe-form').submit(function(){
	    
        var inRecipeName = $('input#cookbook_name');
        var inFirstIngredience = $('input#cookbook_perex_1');
        var inEventLongDesc = $('textarea#comment_textarea_id');
        
        validateEmpty(inRecipeName, 'název', true);
        validateEmpty(inFirstIngredience, 'ingredienci', true);
        validateEmptyTextArea(inEventLongDesc, 'popis');
        
        
        if(inRecipeName.val() == '')
        {
        	return false;
        }	
        
        if(inFirstIngredience.val() == '')
        {
        	return false;
        }	
        
        
        if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
			
					
					
                     
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}

        
    })
    
        /* add event form */
        
    $('form#add-event-form').submit(function(){
	    
        var inEventName = $('input#action_name');
        var inEventAuthor = $('input#action_autor');
        var inEventShortDesc = $('input#action_perex');
        var inEventLongDesc = $('textarea#comment_textarea_id');
        
        validateEmpty(inEventName, 'název', true);
        validateEmpty(inEventAuthor, 'autora', true);
        validateEmpty(inEventShortDesc, 'krátký popis', true);
        validateEmptyTextArea(inEventLongDesc, 'popis');
        
        
        if(inEventName.val() == '')
		{
			return false;
		}
		
		if(inEventShortDesc.val() == '')
		{
			return false;
		}
        
        
        
        if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
                     
			
			
			
			
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}

        
    })


        /* add quiestion form */
        
    $('form#add-question-form').submit(function(){
	    
        var inTitle = $('input#phorum_message_title');
        var inQuestion = $('textarea#textarea');
        var inAutor = $('input#phorum_message_autor');
        var inEmail = $('input#phorum_message_email');
        
        validateEmpty(inTitle, 'titulek problému', true);
        validateEmpty(inAutor, 'autora', true);
        validateMail(inEmail, true);
        validateEmpty(inEmail, 'e-mail', true);
        validateEmptyTextArea(inQuestion, 'popis problému');
        
        
        
        if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
			
					if(inTitle.val() == '') return false;
					if(inAutor.val() == '') return false;
					if(inEmail.val() == '') return false;
			
                     
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}

        
    })
    
    
            /* add forum topic form 
        
    $('form#add-forum-topic').submit(function(){
	    
        var inAuthor = $('input#phorum_message_autor');
        var inTopic = $('input#phorum_thread');
        var inMessage = $('textarea#comment_textarea_id');
        var inMessage2 = $('textarea#comment_textarea_id2');
        
        validateEmpty(inAuthor, 'autora', false);
        validateEmpty(inTopic, 'název', false);
        validateEmptyTextArea(inMessage, 'zprávu');
        
        if($('input').hasClass('notValid')){
		    
		    return false;
		
		} else {
                     
                     if($('textarea').hasClass('notValid')){
                            
                            return false;
                     
                     } else {
                            
                           return true; 
                     }
		    
		}

        
    })

*/


/*  pridani vice fotek  - uprava prfilu mazicku*/ 

$('a#petprofil-add-photo').click(function(){
       
       $('tr#foto_file').after(
              "<tr><td>&nbsp;</td><td><input type=\"file\" name=\"file[]\"></td></tr>"                        
       );       
})

/* registrace ajax username */


/*
$('#user_login').keyup(function(){
       
       var userName = $(this).val();
       
       $.post("nova_registrace/ajax",
              { username: userName },
              function(data){
                   //  alert("Odpověď serveru: " + data);
              }
        );
       
})
          */

/* detail inzeratu - fotky */

$('a#more-pics').click(function(){

      $('tr.hideslide').css('display', 'table-row');
      $('a#more-pics').hide();

})


/* anchor - nastaveni moji mazlicci navigace */

	var urlNow = window.location;
    var anchor = urlNow.hash.substring(1);
	
    if(anchor == 'pridat-foto')
    {
    	changeClassNamePS('pets_setup_butt_2');
    	show('pets_setup_2','block');
    	hide('pets_setup_1'); 
    	hide('pets_setup_3'); 
    	hide('pets_setup_4');
    }
    
    if(anchor == 'pridat-video')
    {
    	changeClassNamePS('pets_setup_butt_3');
    	show('pets_setup_3','block');
    	hide('pets_setup_1');
    	hide('pets_setup_2');
    	hide('pets_setup_4');
    }
    
    if(anchor == 'denicek')
    {
    	changeClassNamePS('pets_setup_butt_4');
    	show('pets_setup_4','block');
    	hide('pets_setup_1');
    	hide('pets_setup_2');
    	hide('pets_setup_3');
    }   

/* validace konec dokumentu*/

	



})