var JSON = JSON || {};  
JSON.stringify = JSON.stringify || function (obj) {  
    var t = typeof (obj);  
    if (t != "object" || obj === null) {  
        // simple data type
        if (t == "string") obj = '"'+obj+'"';  
        return String(obj);  
    }  
    else {  
        // recurse array or object
        var n, v, json = [], arr = (obj && obj.constructor == Array);  
        for (n in obj) {  
            v = obj[n]; t = typeof(v);  
            if (t == "string") v = '"'+v+'"';  
            else if (t == "object" && v !== null) v = JSON.stringify(v);  
            json.push((arr ? "" : '"' + n + '":') + String(v));  
        }  
        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");  
    }  
};  

function switchUserProperty(checkbox,property){
	var c=checkbox.attr('checked');
    
	$.ajax({
        type: 'POST',
        url: homelink + "/other/switchUserProperty",
        data: 'property=' + property + '&value='+c,
        success: function(msg){
                
        }
    });
}


function SetCookie( name, value, expires, path, domain, secure )
{
	path="/workspaces/";
deleteCookie(name,path,domain);
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

if ( expires ){
  expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function GetCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no =
			// sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null
			// is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function deleteCookie( name, path, domain ) {
if ( GetCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

$(document).ready(function(){
  // $('#shop_odkaz').animate({fontWeight:"bold"},1000);
  
  $('.green_button').mousedown(function(){
      $(this).css('border-style','inset');
    }).mouseup(function(){
      $(this).css('border-style','outset');
    });

    
    $('a.slovnik').livequery(function(){
        $(this).hover(function(e){
      
        $('#slovnik_div').css('display','block').animate({opacity: '1'},200).css('left',e.pageX-200).css('top',e.pageY+30);
        $.ajax({
            type: 'POST',
            url: homelink + "/slovnik/slovo",
            data: 'word=' + $(this).text(),
            success: function(msg){
                    $('#slovnik').html(msg);
                   $('#slovnik_div').css('width','383').css('height','auto').css('font-size','8pt');
            }
        });
      },
      function() {
        var topp=$('#slovnik_div').position().top;
        topp=topp-20;
        // document.write(topp);
        $('#slovnik_div').animate({top: topp,opacity: '0'},200,function(){ $('#slovnik').html("<img src='./graphics/loading.gif' alt='loadin' />");}).css('display','none');
        
        
      }
    );
    });
    
    $('div.bocny_nazov').each( function() { 
        var row = $(this); 
        if(!row.hasClass('static')){
        row.hover( 
            function() { setTimeout( function() { row.animate({paddingLeft: '18px'},200)});}, 
            function() { setTimeout( function() { row.animate({paddingLeft: '10px'},100)});} 
        );
        } 
    }); 
});




function replaceAll(text, strA, strB)
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}

function zmazat_nieco(co,id){
  $.ajax({
          type: "POST",
          url: "small_scripts.php?script=zmazat_nieco",
          data: "co="+co+"&id="+id,
          success: function(msg){
                     // alert(msg);
                     if(co=="seminare") window.location.href="seminare.php";
                     if(co=="aktuality") window.location.href="aktuality.php";
                   }
   });
}




function get_img_comments(name){
	var req = new dataRequest('obtain/img_comments');
	req.addParam('src', name);
	req.onSuccess(function(msg){
		$('#add_comments_table').html(msg.data.input);
        $('#comments_table').prepend(msg.data.comments);
        
        $('.pp_content').css('height', $('.pp_content').height()+200+'px');
	});
	req.send();
}

function add_comment(id,co){
  var text=$('#comment_input').val();
  // document.write(text);
  if(text!=""){
  $.ajax({
          type: "POST",
          url: homelink + "/save/comment",
          data: "text="+text+"&id="+id+"&co="+co,
          success: function(msg){
                     // alert(msg);
                      $('#comments_table').prepend(msg);
                      $('#comment_input').val("");
                   }
     });
  }
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).GPRG6-H3WBB-WJK6G-XX2C7-QGWQ9
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
// document.write(getInternetExplorerVersion());

function anketa(odpoved) {
	$.ajax({
        type: "POST",
        url: homelink + "/save/poll",
        data: "odpoved="+odpoved,
        success: function(msg){
                   alert(msg);
                 }
   });
	
}

function prihlaska(co,id){
if(confirm('Skutočne odoslať prihlášku?')){
  var meno=$('#meno').val();
  var priezvisko=$('#priezvisko').val();
  var email=$('#email').val();
  var mesto=$('#mesto').val();
  var poznamky=$('#poznamky').val();
  var errors="";
  if(meno=="") errors+="Nezadané meno<br>";
  if(priezvisko=="") errors+="Nezadané priezvisko<br>";
  if(email=="") errors+="Nezadaný e-mail<br>";
  else if(!email.match(/.*?@.*?\..*?/)) errors+="Neplatný formát e-mailu<br>"
  if(mesto=="") errors+="Nezadané mesto<br>";
  
  if(errors!="") $('#error_div').html(errors).fadeIn('medium');
  else{
    $('#error_div').html("").fadeOut('medium');
    $.ajax({
          type: "POST",
          url: homelink + "/save/prihlaska",
          data: "meno="+meno+"&priezvisko="+priezvisko+"&email="+email+"&mesto="+mesto+"&poznamky="+poznamky+"&co="+co+"&id="+id,
          success: function(msg){
                    //alert(msg);
                      if(msg!="") $('#ok_div').html("<span style='color:red'>Vyskytla sa chyba pri odoslaní prihlášky</span>").fadeIn('medium'); 
                      else {
                        $('#ok_div').html("<span style='color:green'>Prihláška úspešne odoslaná</span>").fadeIn('medium');
                        $('#meno').val("");$('#priezvisko').val("");$('#email').val("");$('#poznamky').val("");$('#mesto').val("");
                      }
                   }
     });
  
  }
}
}


function search(){
// if(trim(document.getElementById("search_input")value)!="")
var word=trim($('#search_input').val());
// var word=$('#search_input').value;
if(word!=''){
// document.write(word);
    $('#search_form').submit();

}
}


function highlight(id){
    /*
	 * switch(id){ case "a_deti": $('#bojove_sub').css('display','block');break;
	 * case "a_zeny": $('#bojove_sub').css('display','block');break; case
	 * "a_Dojokun_bsk": $('#dojokun_bsk_sub').css('display','block');
	 * $('#dokun_sub').css('display','block');
	 * $('#Budostudienkreis').css('display','block'); break; }
	 */
    
    var what=$('#'+id);
    if(what.hasClass('link_white')){
    }
    else{
      $('.link_white').removeClass('link_white').css('color','rgb(239,164,57)').css('font-weight','normal');
      what.addClass('link_white').css('color','white').css('font-weight','bold');
    }
    // document.write()
      /*
		 * if(what.hasClass('link_white'))
		 * what.css('color','rgb(239,164,57)').css('font-weight','normal').removeClass('link_white');
		 * else {
		 * $('.link_white').removeClass('link_white').css('color','rgb(239,164,57)').css('font-weight','normal');
		 * what.css('color','white').css('font-weight','bold').addClass('link_white'); }
		 */
        
}
    
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function generate_calendar(m,y){
    // document.write(m);
     $.ajax({
          type: "POST",
          url: homelink + "/other/generate_calendar",
          data: "m="+m+"&y="+y,
          success: function(msg){
                     // alert( "Data Saved: " + msg );
                     $('#calendar_place').html(msg);
                   }
     });
}
    
    
function add_post(){
  var val=document.getElementById('input').value.replace(/(\r\n)+/,"").replace(/(\r\n)$/,"").replace(/^\s+|\s+$/g,"");
  
  if(val!="") document.getElementById('form_row').submit();

}

function zmaz_clanok(id){
    if(confirm("Naozaj zmazat?")){ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    }
    url="small_scripts.php?script=zmazClanok&id_clanok="+id;
    // document.write(url);
    xmlHttp.onreadystatechange=function(){
      if (xmlHttp.readyState==4) 
        window.location.reload(true);
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    }
}


function reload_img(){


    $.ajax({
          type: "GET",
          url: homelink + "/other/reload_img",
          success: function(msg){
                     // alert( "Data Saved: " + msg );
                     $('#calendar_place').html(msg);
                     document.valid_img.src = document.valid_img.src+ '?' + (new Date()).getTime();;
                   }
     });
     
     
   
}

function toggle_display(id,menuTreeId){
ids=id.split(",");
for(var i in ids){
  // document.write(ids[i]);
  what=$('#'+ids[i]);
  if(what.hasClass('bocne_menu')){
    // what.css('width','20%');
    if(what.hasClass('menu_opened')){
    }
    else{
      if(!what.hasClass('menuTree'+menuTreeId) )$('.menu_opened').removeClass('menu_opened').toggle('fast');
      what.toggle('fast').addClass('menu_opened');
    }
  }
  else what.toggle('fast');
}
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){
  cX = e.pageX;
  cY = e.pageY;
  
}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = cX + "px";
d.style.top = cY + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
function logout(){
var form=document.getElementById('logout_form');
form.submit();
}

function uploadPicture(myForm){
var w = window.open('about:blank','Popup_Window','directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=yes, width=550, height=300');
myForm.target = 'Popup_Window';
return true;
}

  
  function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function change_foto(akcia,user_id){
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Your browser does not support AJAX!");
        return;
    }
    url="foto.php?akcia="+akcia+"&user_id="+user_id;
    // document.write(url);
    xmlHttp.onreadystatechange=ukaz_fotky;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);

}

function ukaz_fotky(){
  if (xmlHttp.readyState==4) 
  document.getElementById("premenlive").innerHTML=xmlHttp.responseText;
  // document.write("<html>"+xmlHttp.responseText+"</html>");
}

function forgot_pswd(){
window.open('http://dokan.sk/other/zabudnute_heslo','_new','directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=300');
}


function show_foto_form(){
document.getElementById('foto_form_place').style.display='inline';
}


function show_form(){
// document.getElementById('new_hudba_input').value=document.getElementById('old_hudba').innerHTML;
// document.getElementById('new_hudba').style.display='inline';
// document.getElementById('old_hudba').style.display='none';
document.getElementById('new_icq_input').value=document.getElementById('old_icq').innerHTML;
document.getElementById('new_icq').style.display='inline';
document.getElementById('old_icq').style.display='none';
document.getElementById('new_skype_input').value=document.getElementById('old_skype').innerHTML;
document.getElementById('new_skype').style.display='inline';
document.getElementById('old_skype').style.display='none'
/*
 * document.getElementById('new_film_input').value=document.getElementById('old_film').innerHTML;
 * document.getElementById('new_film').style.display='inline';
 * document.getElementById('old_film').style.display='none';
 * document.getElementById('new_technika_input').value=document.getElementById('old_technika').innerHTML;
 * document.getElementById('new_technika').style.display='inline';
 * document.getElementById('old_technika').style.display='none';
 * document.getElementById('new_znamenie_input').value=document.getElementById('old_znamenie').innerHTML;
 * document.getElementById('new_znamenie').style.display='inline';
 * document.getElementById('old_znamenie').style.display='none';
 * document.getElementById('new_cin_znamenie_input').value=document.getElementById('old_cin_znamenie').innerHTML;
 * document.getElementById('new_cin_znamenie').style.display='inline';
 * document.getElementById('old_cin_znamenie').style.display='none';
 * document.getElementById('new_kniha_input').value=document.getElementById('old_kniha').innerHTML;
 * document.getElementById('new_kniha').style.display='inline';
 * document.getElementById('old_kniha').style.display='none';
 */
document.getElementById('new_vek_input').value=document.getElementById('old_vek').innerHTML;
document.getElementById('new_vek').style.display='inline';
document.getElementById('old_vek').style.display='none';
// document.getElementById('new_stav_input').value=document.getElementById('old_stav').innerHTML;
// document.getElementById('new_stav').style.display='inline';
// document.getElementById('old_stav').style.display='none';
document.getElementById('new_mobil_input').value=document.getElementById('old_mobil').innerHTML;
document.getElementById('new_mobil').style.display='inline';
document.getElementById('old_mobil').style.display='none';
document.getElementById('new_mesto_input').value=document.getElementById('old_mesto').innerHTML;
document.getElementById('new_mesto').style.display='inline';
document.getElementById('old_mesto').style.display='none';
document.getElementById('new_email_input').value=document.getElementById('old_email').innerHTML;
document.getElementById('new_email').style.display='inline';
document.getElementById('old_email').style.display='none';
// document.getElementById('new_telocvicna_input').value=document.getElementById('old_telocvicna').innerHTML;
document.getElementById('new_telocvicna').style.display='inline';
document.getElementById('old_telocvicna').style.display='none';

document.getElementById('submit_button').style.display='inline';
}




function check_login_data(){
  /*
	 * var e=''; var pwd=document.getElementById('heslo').value; var
	 * nick=document.getElementById('nick').value; if(nick!="" && pwd!=""){
	 * if(nick.match(/[!@#\$%\^&\*\(\)-=\+\[\]\{\}'";:\\\|/?.>,<`~]/)) e+="nick
	 * moze obsahovat iba pismena, cisla,medzeru a znak "_"\n";
	 * if(pwd.match(/\s/)) e+="Heslo nem“ze obsahovat medzeru\n"; if(e=="")
	 * document.getElementById('login_form').submit(); else alert(e); }
	 */
  document.getElementById('login_form').submit()
}



