// JavaScript Document
// soundManager.url = '/swf/';
// soundManager.waitForWindowLoad = true;
// soundManager.onload = function() {
//   var mySound = soundManager.createSound({
//     id: 'aSound',
//     url: 'jihoceska_hp.mp3'
//     // onload: [ event handler function object ],
//     // other options here,
//   });
//   mySound.play();
// }

function stopMusic() {
	var d = document.getElementById('pisnickaDiv');
	if(document.getElementById('pisnickaEmbed')) {
		var pisnicka = document.getElementById('pisnickaEmbed');
		d.removeChild(pisnicka);
	}
	if(document.getElementById('pisnickaObject')) {
		var pisnicka = document.getElementById('pisnickaObject');
		d.removeChild(pisnicka);
	}
	var stopMusic = document.getElementById('stopMusic');
	stopMusic.style.display = 'none';
}

function addToCart(typ, id, pocetElementId, medium) {
	var pocetInput = document.getElementById(''+pocetElementId);
	$.ajax({
	   type: "POST",
	   dataType: "json",
	   url: _SERVER_PATH+"inc/ajax/cart.php?action=addToCart",
	   data: "&typ="+typ+"&id="+id+"&pocet="+pocetInput.value,
	   success: function(msg) {
	   	var kosikLink = document.getElementById('kosikLink');
	   	kosikLink.innerHTML = msg.celkem;
	   	var dialogDiv = document.createElement('div');
			var divID = Math.round(Math.random() * 1235);
			var dialogDivID = 'dialog_'+divID;
			dialogDiv.id = dialogDivID;
	   	dialogDiv.innerHTML = '<p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>'+msg.message+'</p>';
			document.body.appendChild(dialogDiv);
			$("#"+dialogDivID).dialog({
				bgiframe: true,
				modal: true,
				title: _MESSAGE,
				buttons: {
					'Ok': function() {
						$(this).dialog('close');
					}
				}
			});
	   }
	});
}

function confirm_dialog(text, url) {
	var vratit = false;
	var dialogDiv = document.createElement('div');
	var divID = Math.round(Math.random() * 1235);
	dialogDivID = 'dialog_'+divID;
	dialogDiv.id = dialogDivID;
	dialogDiv.innerHTML = '<p>'+text+'</p>';
	document.body.appendChild(dialogDiv);
	
		  if(_CONST_MUTACE == 'cz') {
		    $("#"+dialogDivID).dialog({
      		bgiframe: true,
      		modal: true,
      		title: _CONFIRM_DELETE,
      		buttons: {
            Ano: function() {
      				vratit = true;
      				$(this).dialog('close');
      				window.location.href = url;
      				return true;
      			},
      			Ne: function() {
      				vratit = false;
      				$(this).dialog('close');
      				return false;
      			}
    			}
	       });
      }
			if(_CONST_MUTACE == 'en') {
          $("#"+dialogDivID).dialog({
      		bgiframe: true,
      		modal: true,
      		title: _CONFIRM_DELETE,
      		buttons: {
            Yes: function() {
      				vratit = true;
      				$(this).dialog('close');
      				window.location.href = url;
      				return true;
      			},
      			No: function() {
      				vratit = false;
      				$(this).dialog('close');
      				return false;
      			}
    			}
	       });
      }
      if(_CONST_MUTACE == 'de') {
          $("#"+dialogDivID).dialog({
      		bgiframe: true,
      		modal: true,
      		title: _CONFIRM_DELETE,
      		buttons: {
            Ja: function() {
      				vratit = true;
      				$(this).dialog('close');
      				window.location.href = url;
      				return true;
      			},
      			Nein: function() {
      				vratit = false;
      				$(this).dialog('close');
      				return false;
      			}
    			}
	       });
      }
		
	return vratit;
}

function getNotyContent(id) {
	$.ajax({
	   type: "POST",
	   dataType: "json",
	   url: _SERVER_PATH+"inc/ajax/noty.php?action=getDetail",
	   data: "&id="+id,
	   success: function(msg) {
	   	$("#noty").attr("innerHTML", msg);
	   	$("#noty").overlay();
	   }
	});
}

function setActualNotes(id) {
	$("#noty_id").attr("innerHTML", id);
}

function setActualAudio(id) {
	$("#audio_id").attr("innerHTML", id);
}

$(function(){
	$("#login").watermark();
	$("#password").watermark();
	$("#search").watermark();
	$("#login2").watermark();
	$("#password2").watermark();
	
	if(document.getElementById('vlozitZpravuLink')) {
		$("#vlozitZpravuLink").toggle(function(){
			$("#vlozitZpravuLink").attr("innerHTML", '< '+_CONST_SCHOVAT_FORMULAR);
			$("#vlozitZpravuDiv").animate({ height: 'show', opacity: 'show' }, 'slow');
		},function(){
			$("#vlozitZpravuLink").attr("innerHTML", _CONST_VLOZIT_ZPRAVU+' >');
			$("#vlozitZpravuDiv").animate({ height: 'hide', opacity: 'hide' }, 'slow');
		});
		// validace formuláře na vložení příspěvku do knihy návštěv
		$("#guestBookForm").validate({
			rules: {
				email: {
					required: true,
					email: true
				},
				subject: {
					required: true
				},
				jmeno: {
					required: true
				},
				text_form: {
					required: true
				},
				hncaptcha_private_key: {
					required: true
				}
			},
			messages: {
				subject: {
					required: _SUBJECT_REQUIRED
				},
				jmeno: {
					required: _NAME_REQUIRED
				},
				text_form: {
					required: _MESSAGE_REQUIRED
				},
				email: _INPUT_VALID_EMAIL,
				hncaptcha_private_key: {
					required: _REWRITE_CAPTCHA
				}
			}
		});
	}
	
	if(document.getElementById('registraceForm')) {
		// validate signup form on keyup and submit
		$("#registraceForm").validate({
			rules: {
				jmeno: {
					required: true
				},
				prijmeni: {
					required: true
				},
				login_name: {
					required: true
				},
				heslo1: {
					required: true
				},
				heslo2: {
					required: true,
					equalTo: "#heslo1"
				},
				ulice: {
					required: true
				},
				mesto: {
					required: true
				},
				stat: {
					required: true
				},
				psc: {
					required: true
				},
				email: {
					required: true,
					email: true
				},
				telefon: {
					required: true
				},
				hncaptcha_private_key: {
					required: true
				}
			},
			messages: {
				jmeno: {
					required: _FIRST_NAME_REQUIRED
				},
				prijmeni: {
					required: _SURNAME_REQUIRED
				},
				login_name: {
					required: _LOGIN_REQUIRED
				},
				heslo1: {
					required: _PASSWORD_REQUIRED
				},
				heslo2: {
					required: _CONFIRM_PASSWORD,
					equalTo: _PASSWORDS_NOT_EQUALS
				},
				ulice: {
					required: _STREET_REQUIRED
				},
				mesto: {
					required: _CITY_REQUIRED
				},
				stat: {
					required: _COUNTRY_REQUIRED
				},
				psc: {
					required: _POSTCODE_REQUIRED
				},
				email: _INPUT_VALID_EMAIL,
				telefon: {
					required: _PHONE_REQUIRED
				},
				hncaptcha_private_key: {
					required: _REWRITE_CAPTCHA
				}
			}
		});
	}
	if(document.getElementById('contactForm')) {
		// validate signup form on keyup and submit
		$("#contactForm").validate({
			rules: {
				email: {
					required: true,
					email: true
				},
				adresat: {
					required: true
				},
				jmeno: {
					required: true
				},
				text_form: {
					required: true
				},
				hncaptcha_private_key: {
					required: true
				}
			},
			messages: {
				adresat: {
					required: _CHOOSE_RECEPIENT
				},
				jmeno: {
					required: _NAME_REQUIRED
				},
				text_form: {
					required: _MESSAGE_REQUIRED
				},
				email: _INPUT_VALID_EMAIL,
				hncaptcha_private_key: {
					required: _REWRITE_CAPTCHA
				}
			}
		});
	}
	if(document.getElementById("map_canvas")) {
		initialize();
	}
});

function showAlert(message, title, cl, action, login, pass, submit, reg_url, reg) {
   var dialogDiv = document.createElement('div');
   var divID = Math.round(Math.random() * 1235);
   var dialogDivID = 'dialog_'+divID;
   dialogDiv.id = dialogDivID;
   dialogDiv.innerHTML = '<p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>'+message+'</p><p><form action="'+action+'" method="post" id="login_form"><table class="popup"><tr><td class="label">'+login+':</td><td class="input"><input type="text" name="login" class="login" value="" /></td></tr><tr><td class="label">'+pass+':</td><td class="input"><input type="password" name="password" id="password" value="" /></td></tr><tr><td class="smallFont" style="text-align: center;"><a href="'+reg_url+'" title="'+reg+'">> '+reg+'</a></td><td><input type="submit" name="submit" id="submit" value="'+submit+'" /></td></tr></table></form></p>';
   
   document.body.appendChild(dialogDiv);
   if(_CONST_MUTACE == "cz") {

       $("#"+dialogDivID).dialog({
           bgiframe: true,
           modal: true,
           title: title,
               buttons: {
                       'Zavřít': function() {
                               $(this).dialog('close');
                       }
               }
       });
   }
   if(_CONST_MUTACE == "en") {

       $("#"+dialogDivID).dialog({
           bgiframe: true,
           modal: true,
           title: title,
               buttons: {
                       'Close': function() {
                               $(this).dialog('close');
                       }
               }
       });
   }
   if(_CONST_MUTACE == "de") {

       $("#"+dialogDivID).dialog({
           bgiframe: true,
           modal: true,
           title: title,
               buttons: {
                       'Schließen': function() {
                               $(this).dialog('close');
                       }
               }
       });
   }

}
