/* Print-PopUp */

/* Attributes for PopUp */
var attribPopUpPrint="location=no,menubar=no,toolbar=no,status=yes";
attribPopUpPrint+=",resizable=yes,scrollbars=yes,width=595,height=768";

var attribPopUpRemark="location=no,menubar=no,toolbar=no,status=yes";
attribPopUpRemark+=",resizable=yes,scrollbars=yes,width=690,height=768";


/* init variables, which later point to the window object */
var subwindow=0;

/* This function closes  (if open) the popup window */
function ClosePopUp()
{
	if (!subwindow)          /* if not jet opened */
		return;                /* cancel */
	if (subwindow.closed)    /* if already closed */
		return;                /* cancel */
	subwindow.close();       /* close */
}

function PopUpPrint()
{
	ClosePopUp()             /* close, if already opened */

	/* CE_print.html open with name "popup" and remenber window object */
	subwindow=window.open("/utils/printview.php?id="+window.parent.document.location.pathname.substr(1),"popup",attribPopUpPrint);

	/* move window to left top */
	subwindow.moveTo(10,50);
}

function PopUpRemark()
{
	ClosePopUp()             /* close, if already opened */

	/* CE_print.html open with name "popup" and remenber window object */
	subwindow=window.open("/zglos_uwage/"+window.parent.$('.footer p').attr('title'),"popup",attribPopUpRemark);

	/* move window to left top */
	subwindow.moveTo(10,50);
}

/* Rozciąganie wysokości div'a z treścią */
function calculateContentMiddle() {
	/*
	var centerdivheight = $("#content #middle").height();
	var rightdivheight 	= $("#content #right").height();

	if ((rightdivheight-80) > centerdivheight)
		$("#middle").css('height',(rightdivheight-80)+'px');
	*/
		
}

/**
 * wysylanie uwagi do dokumentu
 */ 
function sendRemark(){
  if($('#sremark').val().length > 0){
    $.post('/ajax.php', {scontroller: 'remark', 
                        saction: 'send', 
                        iddocumentremark: $('#iddocumentremark').val(), 
                        sremark: $('#sremark').val(), 
                        semail: $('#semail').val()
                        }, 
                        function(sdata){
                          $('#middle').html(sdata); 
                        });
  }else{
    alert('Proszę wypełnić formularz');
  }
}

$(document).ready(function() {
	//calculateContentMiddle();
	
	if ($('#send_remark').length > 0) {
		$('#send_remark').click(function() {
			sendRemark();
			return false;
		});
	}
	/*
	// Odpal konwersję proceduralną plików img
	var is_webkit = navigator.userAgent.toLowerCase().indexOf('applewebkit') > -1;

	if (!is_webkit) {
		grayscale($('img'));
	}
	*/
});

function createCookie(name,value,days,domain) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}