﻿function confirmation()
{
  p = window.confirm('Czy  na pewno usunąć');
  if(p == true) 
   return true;
  else
   return false;
}

	function moveBox(id,side,section)
	{
		$.ajax({
			type:"GET",
			url: url+'site_ajax/boxes_move/' + side + '/' + id+'/'+section,
			cache: false,
			success: function(html){
				$("#fiksacja").html(html);
			},
			error : function(){
				$("#fiksacja").html('Wystąpił błąd');
			}
		});
	}

function delContent(section,id,news_page_id)
{
	p = window.confirm('Czy na pewno usunąć');
	if(p == true)
	{
		$.ajax({
			type:"GET",
			url: url+'site_ajax/del_content_ajax/'+ id + '/' +section,
			cache: false,
			success: function(html){
				location.href= url+'site/index/'+news_page_id;
			},
			error : function(){
				location.href= url+'site/index/'+news_page_id;
			}
		});
	}
	else 
		return false;
}

function changeFlag(id,hidden,uri)
{  
	$.ajax({
		type:"GET",
		url: url+'site_ajax/change_flags/'+ id + '/' +hidden,
		cache: false,
		success: function(html){
			location.href= url+uri;
		},
		error : function(){
			location.href= url+uri;
		}
	});
}

function editContent(section,id)
{  
	$('#overlay_kom').css({'height':$(document).height()}).fadeTo(200,0.6).show();
	$('#edycja_tresc').show();
	$('#edycja').css({'height':($(window).height()-80)+'px','top':'40px','left':(($(document).width()/2)-353)+'px'});
	$.ajax({
		type:"GET",
		url: url+'site_ajax/edit_content_ajax/'+ id + '/' +section,
		cache: false,
		success: function(html){
			$('#edycja_tresc').html(html);
			$('#edycja').fadeIn(200);
		},
		error : function(){
			$('#edycja_tresc').html('Wystąpił błąd');
			$('#edycja').fadeIn(200);
		}
	});
}

function crop(id,uri)
{  
	$('#overlay_kom').css({'height':$(document).height()}).fadeTo(200,0.6).show();
	$('#edycja_tresc').show();
	$('#edycja').css({'height':($(window).height()-80)+'px','top':'40px','width':'810px','left':(($(document).width()/2)-405)+'px'});
	$.ajax({
		type:"GET",
		url: url+'site_ajax/crop_ajax/'+ id,
		cache: false,
		success: function(html){
			$('#edycja_tresc').html(html);
			$('#edycja').fadeIn(200);
		},
		error : function(){
			$('#edycja_tresc').html('Wystąpił błąd');
			$('#edycja').fadeIn(200);
		}
	});
}

function addContent(section,id)
{  
	$('#overlay_kom').css({'height':$(document).height()}).fadeTo(200,0.6).show();
	$('#edycja_tresc').show();
	$('#edycja').css({'height':($(window).height()-80)+'px','top':'40px','left':(($(document).width()/2)-250)+'px'});
	$.ajax({
		type:"GET",
		url: url+'site_ajax/add_content_ajax/'+ id + '/' +section,
		cache: false,
		success: function(html){
			$('#edycja_tresc').html(html);
			$('#edycja').fadeIn(200);
		},
		error : function(){
			$('#edycja_tresc').html('Wystąpił błąd');
			$('#edycja').fadeIn(200);
		}
	});
}

function RetTrue()
 {
	return false; 
	 
 }

function hover(e)
 {
	tmp = e.src;
	tmp2 = e.src.replace(/0/,"1");
	e.src = tmp2;
	return true;
	 }

function unhover(e)
{
	e.src = tmp;
	return true;
	}

function refreshCam()
 {
	  $.ajax({
	  url: url + 'site/getPhoto',
	  cache: false,
	  success: function(html){
	  $("#plac").html(html);
	   }
	  });
  }
function printer(site,item) {
	if(!item) item=0;
	if(item != 0) {
		if(site=='page')
		{
			printwindow = window.open('http://www.margomedia.home.pl/carvalet/print_page.php?id='+item, 'printer', config='height=650,width=650,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
		}
		if(site=='news')
		{
			printwindow = window.open('http://www.margomedia.home.pl/carvalet/print_news.php?id='+item, 'printer', config='height=650,width=650,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
		}
	}
	if(!printwindow.closed)
		printwindow.focus();
}
function klikik(txt)
{
	$('#komunikat').css({
		'top':'40px',
		'left':(($(document).width()/2)-250)+'px'
	});
	$('#overlay_kom').css({
		'height':$(document).height()
	}).fadeTo(200,0.6).show();
	$('#komunikat_tresc').html(txt);
	$('#komunikat').fadeIn(200);
};
$(document).ready(function(){
	$('#save_thumb').click(function() {
		var x1 = $('#x1').val();
		var y1 = $('#y1').val();
		var w = $('#w').val();
		var h = $('#h').val();
		if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
			alert("Proszę zaznaczyć obrazek do wycięcia");
			return false;
		}else{
			return true;
		}
	});
	$("#wyslij").click(function(){
		$("#wyslij_div").slideToggle(500);
	});
	$(".single_news2").mouseover(function(){
		$("#"+this.id+"_button").show();
		$(".crop").show();
		$("#"+this.id).css('border','1px solid #a4b4bd');
	});
	$(".single_news2").mouseout(function(){
		$("#"+this.id+"_button").hide();
		$(".crop").hide();
		$("#"+this.id).css('border','0px');
	});
	$(".flaha").mouseover(function(){
		$("#"+this.id+"_podpis").show();
	});
	$(".flaha").mouseout(function(){
		$("#"+this.id+"_podpis").hide();
	});
	$('#komunikat_close').click(function()
    {
		$('#komunikat').fadeOut(200);
		$('#overlay_kom').fadeOut(200);
	});
	
	$('#edycja_close').click(function()
    {
		$('#edycja').fadeOut(200);
		$('#overlay_kom').fadeOut(200);
		$(".imgareaselect-selection").parent().fadeOut(200);
		$('.imgareaselect-selection').fadeOut(200);
		$('.imgareaselect-handle').fadeOut(200);
		$('.imgareaselect-outer').fadeOut(200);
		$('.imgareaselect-border1').fadeOut(200);
		$('.imgareaselect-border2').fadeOut(200);
		$('.imgareaselect-border3').fadeOut(200);
		$('.imgareaselect-border4').fadeOut(200);
	});
	//$('.date_pick').datePicker({startDate:'01/01/1996'});
   setInterval('refreshCam()',10000);					   
   $('#print_img').click(function()
						{
							var print_win = window.open('','Drukowanie','menubar=yes, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no,width=650,height=500');
							print_win.document.open();
							print_win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Drukowanie...</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" type="text/css" href="http://www.margomedia.home.pl/carvalet/css/carvalet_print.css" media="screen" /></head><body onload="setTimeout(function(){this.print();},1500)">' + $('#main_index').html() +'</body></html>');
							print_win.document.close();
							//setTimeout(function(){print_win.close();},2500);
						});
	
	$('.event').hover(
		function(e)
		{
			$('.output').hide();
			var selector = $(this).attr('id');
			//getting height and width of the message box
			//var height = $('#calendar').height();
			//var width  = $('#calendar').width();
	  
			//calculating offset for displaying popup message
			//leftVal =(e.pageX-150)+"px";
			//topVal  =(e.pageY-260)+"px";
	   
			$('#' + selector + ' .output').fadeIn(200);
		},
		function()
		{
			$('.output').hide();
		}	
	);
	// Reset Font Size
  var $cookie_name = 'oidonFontSize';
  var originalFontSize = $('body').css('font-size');
  var originalHeadFontSize = $('.title').css('font-size');
    $(".resetFont").click(function(){
    $('body').css('font-size', originalFontSize);
	$('.wzorek').css('font-size', originalFontSize);
	$('.odpowiedz').css('font-size', originalFontSize);
	$('.laba').css('font-size', originalFontSize);
	$('.procent').css('font-size', originalFontSize);
	$('.breads').css('font-size', originalFontSize);
	$('.data').css('font-size', originalFontSize);
	$('.title').css('font-size', originalHeadFontSize);
	$('.title_a').css('font-size', originalHeadFontSize);
  });
 
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('body').css('font-size');
	var originalHeadFontSize = $('.title').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var currentFontSizeNumHead = parseFloat(originalHeadFontSize, 10);
    var newFontSize = currentFontSizeNum+1;
    var newFontSizeHead = currentFontSizeNumHead+1;
	if(newFontSize > 20) newFontSize = 20;
	if(newFontSizeHead > 32) newFontSizeHead = 32;
    $('body').css('font-size', newFontSize);
	$('.wzorek').css('font-size', newFontSize);
	$('.odpowiedz').css('font-size', newFontSize);
	$('.laba').css('font-size', newFontSize);
	$('.procent').css('font-size', newFontSize);
	$('.breads').css('font-size', newFontSize);
	$('.data').css('font-size', newFontSize);
	$('.title').css('font-size', newFontSizeHead);
	$('.title_a').css('font-size', newFontSizeHead);
    return false;
  });

  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('body').css('font-size');
	var originalHeadFontSize = $('.title').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var currentFontSizeNumHead = parseFloat(originalHeadFontSize, 10);
    var newFontSize = currentFontSizeNum-1;
    var newFontSizeHead = currentFontSizeNumHead-1;
	if(newFontSize < 10) newFontSize = 10;
	if(newFontSizeHead < 14) newFontSizeHead = 14;
    $('body').css('font-size', newFontSize);
	$('.wzorek').css('font-size', newFontSize);
	$('.odpowiedz').css('font-size', newFontSize);
	$('.laba').css('font-size', newFontSize);
	$('.procent').css('font-size', newFontSize);
	$('.breads').css('font-size', newFontSize);
	$('.data').css('font-size', newFontSize);
	$('.title').css('font-size', newFontSizeHead);
	$('.title_a').css('font-size', newFontSizeHead);
    return false;
  });
});
