
$(document).ready(function() {    
	$('.stridani tr:nth-child(even)').addClass('even');	
}); 


$(document).ready(function(){
   /**
    * najdeme vsechny elementy a, ktere maji class showgallery
    * ty budou odkazovat na set fotografii v lightboxu
    */
   $('a[rev="contents"]').each(function(){
        var id = $(this).attr('id');
        $(this).attr('rel',id);
        $(this).after($('<div>').load('index.php?pg=processdata&save_form=getgalleryset&modul=galerie&id='+id));
   })
   
   ajaxMessages();
});


function ajaxMessages(){
	
	// nacteme a zobrazime pripadne chybove nebo informacni hlasky
	$.ajax({
	    	method: 'get',
	        url : "/index.php?pg=processdata&save_form=loadMessages",
	        dataType : 'xml',
	        success: function (xml) { 
	        	info = $(xml).find('infoMessage').text();
				error = $(xml).find('errorMessage').text();
				report = $(xml).find('report').text();
				
				if (info || error) {
					//$('#box-message',parent.document.body).css({display: 'block', position:'absolute' });
					$('#box-message',top.document).css({display: 'block', width: '600px', position: 'fixed', top: '25%', left: '25%'});
				}
				
				if (info){
					$('#infomessage',top.document).css({display: 'block'});
					$('#infomessage',top.document).html(info);
		
					$('#infomessage',top.document).click(function(){  $(this).hide();	});
					$('body',top.document).click(function(){  $('#infomessage',top.document).hide();	});
										
					$('#infomessage',top.document).delay(1000);
					$('#infomessage',top.document).hide(1000);
				
				}
				else if (error) {
					$('#errormessage').css({display: 'block'});	
					$('#errormessage').html(error);	
		
					$('#errormessage').click(function(){  $(this).hide();	});
					$('body').click(function(){  $('#errormessage').hide();	});
					
					$('#errormessage').delay(5000);
					$('#errormessage').hide(1000);	
				}
			},
			error: function(){  }
	    });
}


function uploadProgressInfoInline (id,name){
	var counter = 0;
	
    $.fsoverlay.show('',function(){},{ 'content': 'fsoverlaybox' });
                
    function callProgress()
	{
		var currTime = new Date();
		ms = currTime.getTime();
	         $.ajax({
               async: 'false',
               method: 'get',
               url : "/admin/scripts/processdata/uploadprogressinfo.php?id="+id+"&ms="+ms,
               dataType : 'xml',
               success: function (xml) { 
			   		   
                    var text = "";
			    	var sirka = 0;
			    	var percent = 0;
			    	text +=  $(xml).find('bytes_total').text()+"<br />";
				    text += $(xml).find('bytes_uploaded').text()+"<br />";
				    text += $(xml).find('bytes_remain').text()+"<br />";
				    text += $(xml).find('filename').text()+"<br />";
				    text += $(xml).find('files_uploaded').text()+"<br />";
				    percent = $(xml).find('percent_number').text();
				    sirka = $(xml).find('sirka').text();
				    
					if (sirka>0) {
						$('#fsoverlaybox').html('');
                        $('#fsoverlaybox').append('<div class="bar"><div class="fill-container"></div></div>');
						width = $('#fsoverlaybox .bar').css('width')/100*percent;
						$('#fsoverlaybox .bar .fill-container').css('width',width);
					}					
			   },
               // zobrazime jen loading image
			   error: function(){
			   	$('#fsoverlaybox').html('<img src="/images/loading.gif" />');
			   }
            });
	
	}	
	var holdTheInterval = setInterval(callProgress, 1000);	
}

function show_photo(text,file,width,height){
	no=window.open("", "zoom", "left=5, top=5, width="+width+", height="+height+", toolbar=no, location=no, status=no, scrollbars=auto");
	with (no.document)
	{
		open();
		writeln('<body style="margin: 0px;"><a href="javascript:void window.close();"><img src="'+file+'" style="border: 0px;" /></a></body>');
		close();
		no.focus();
	}
}

function ShowDialog( theInput,theInput1,theInput2 ) {
	//if (!formik){formik = "vyber";}
	//window.alert(formik);
	theField = eval( "document.getElementById(theInput)");
    //window.alert(theField);
	//theField.value = "";
    theField1 = eval( "document.getElementById(theInput1)");
    //theField1.value = "";
	theField2 = eval( "document.getElementById(theInput2)");
    //theField2.value = "";*/
    dialogWindow=window.open("/admin/kalendar_popup.html","MyDialog",
            "dependent=yes, menubar=no, location=no, resizable=no, width=320, height=205, toolbar=no, screenX=100, screeny=100" );
}

function transferValue (field,val){
	window.top.opener.document.form.idkatalogtree.value=val;
	window.top.close() ;
	
}

function transferFormValues (string){
        prvky = string.split('|');
        for(i = 0; i < prvky.length; i++){
      prvek = prvky[i].split('*');
      nazev_pole = prvek[0];
      hodnota = prvek[1];

          if (window.top.opener.document.getElementById(nazev_pole)) {
            //alert(nazev_pole+' '+hodnota);
                window.top.opener.document.getElementById(nazev_pole).value=hodnota;
          }
        }
        window.top.close() ;

}

function Transfer( theValue ) {
    if( theField != null ) theField.value = theValue;
	theField.focus();
}

function DoubleTransfer( theValue1,theValue2) {
	//window.alert(theField);
	if( theField1 != null ) theField1.value = theValue1;
	if( theField2 != null ) theField2.value = theValue2;
	//document.vyber.datum_od.value = theValue1;
	//document.vyber.datum_do.value = theValue2;
	theField.focus();
	//document.formik.submit();
	//submit();
}
function openWindow(text,file,width,height,type){
	if (type=='img'){
		no=window.open("", "zoom", "left=5, top=5, width="+width+", height="+height+", toolbar=no, location=no, status=no, scrollbars=auto");
		with (no.document)
		{
			open();
			writeln('<body style="margin: 0px;"><a href="javascript:void window.close();"><img src="'+file+'" alt="'+text+'"style="border: 0px;" /></a></body>');
			close();
			no.focus();
		}
	}
	if (type=='file'){
		window.open(file, "zoom", "left=5, top=5, resizable,toolbar=no, location=no, status=no, scrollbars=yes");
		
		
	}
	return false;
}

function changeImage (url,foto) {
	if (document.getElementById) {
    	//window.alert(foto);    
                document.getElementById('mainphoto').src = url;
                document.getElementById('largephoto').href = foto;
               // photo_id = fotka_id;
        }
        return false;
}

function showLargeImage(url,width,height,type) {
	if (screen.height) {
		screenY = screen.height
		screenX = screen.width
	}
	var top = ((screenY/2)-(height/2));
	var left = ((screenX/2)-(width/2));
	window.open(url,'','resizable=no,status=no,scrollbars=no,width='+width+',height='+height+',top=50,left=50');
	return false;
}

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 vycistiPlatby(n){
	oElement = document.getElementsByName(n); 
	if(oElement.length) { 
		for(i = 0; i < oElement.length; i++) 
			oElement[i].disabled = false;
	} 
}

function zakazPlatbu(n){
	if (document.getElementById(n)){
		document.getElementById(n).disabled = true;
		if (document.getElementById(n).checked) document.getElementById(n).checked = false;
	}
}

function paymywayShowList(){
	if ($('.platba:checked').attr('attr')=='paymyway') $('#paymyway_methods').css('display','');
	else  $('#paymyway_methods').css('display','none');
}

function hideBlock(block){
	document.getElementById(block).style.display = 'none';
}

function showBlock(block){
	document.getElementById(block).style.display = 'block';
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	
	if ( endstr == -1 ) endstr = document.cookie.length;
	return(unescape(document.cookie.substring(offset, endstr)));
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while ( i < clen ) {
		var j = i + alen;
		if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
		i = document.cookie.indexOf(" ", i) + 1;
		if ( i == 0 ) break;
	}
	
	return(null);
}

function startAjaxUpload(name){
	  
      $('#'+name+' .progress').css('display','block');
      $('#'+name+' .input').hide();
      return true;
}

function processAjaxUploadForms(){
	
    ajaxMessages();
    
    $('.ajaxinput').each(function(){
       
       id = $(this).attr('id');
       $('#'+id+' .progress').css('display','none');
       $.fsoverlay.hide();
                
       if (getCookie('ajaxupload_success_'+id) == 1){
            path = getCookie('ajaxupload_destination_path_'+id);
			file = getCookie('ajaxupload_filename_'+id);
			
            $('#'+id+' .uploaded').css('display','block');
            $('#'+id+' .input').hide();
            $('#'+id+' .input input').val('');
            
            if (file.match('.jpg') || file.match('.gif') || file.match('.png') || file.match('.bmp') || file.match('.tiff')) $(this).find('.link').html('<a href="'+path+''+file+'" target="_blank" rel="lightbox"><img src="'+path+''+file+'" /></a>');
            else $(this).find('.link').html('<a href="'+path+''+file+'" target="_blank">'+file+'</a>');       
		}
		else {
            $('#'+id+' .input').show();
            $('#'+id+' .input input').val('');
		}
    });
}

function deleteAjaxUploadedFile(id){
	
	$.ajax({
		  url: "index.php?pg=processdata&save_form=deleteajaxuploadedfile&modul=ajaxfileprocessing&id="+id,
		  dataType: "xml",
		  success: function(xml) {
		  	ok = $(xml).find('success').text();
		  	
			  if (ok==1) {
					$('#'+id+' .progress').css('display','none');
    				$('#'+id+' .uploaded').css('display','none');
                    $('#'+id+' .input').css('display','block');
                    $('#'+id+' .input input').val('');
    			} 	
    			else {
    			}		
			}
		});
}

