function printContents()
{
	iWidth = window.screen.width;
	iHeight = window.screen.height;
    wt = 720;
    ht = 550;
    lt = (iWidth - wt) / 2;
    tp = (iHeight - ht) / 2;
    window.open("print.php", '', 'height='+ht+',width='+wt+',top='+tp+',left='+lt+',toolbar=no,resizable=no,scrollbars=yes'); 
}

function printContentsPDF(name)
{
	iWidth = window.screen.width;
	iHeight = window.screen.height;
    wt = 100;
    ht = 100;
    lt = (iWidth - wt) / 2;
    tp = (iHeight - ht) / 2;
    window.open("pdf.php?name="+name, '', 'height='+ht+',width='+wt+',top='+tp+',left='+lt+',toolbar=no,resizable=no,scrollbars=yes'); 
}

function printContentsPDF_attachment(name,ids)
{
	var myJSONObject = {};
	var re = /<img[^>]*?>/gi;
	myJSONObject['data'] = $('#'+ids).html().replace(re,"");
	$.post("pdf.php", { name: name, stream: 'false', data: encodeURIComponent(JSON.stringify(myJSONObject))}, function(data){
		window.open("getfile.php?del=true&file="+data, '', 'height=100,width=100,top=50,left=50,toolbar=no,resizable=no,scrollbars=yes');
	});
}

function preview(file, desc, width, height)
{
	if (desc == null) {
		desc = '';
	}
	
	var left = (screen.width - width) / 2;
	var top = (screen.height - height + 20) / 2;
	window.open("preview.php?file="+file+"&desc="+desc, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
}

function openwindow(file, width, height)
{
    var left = (screen.width - width) / 2;
    var top = (screen.height - height + 20) / 2;
    window.open(file, "", "width="+width+",height="+height+",top="+top+",left="+left);
}

/* PRINTR */
function printr_show(val) {
	Okienko=window.open('','','scrollbars=yes,resizable=yes,width=400,height=400,left=100,top=50');
	Okienko.document.open();
	Okienko.document.write ("<HTML><HEAD><TITLE>printr</TITLE></HEAD><BODY TOPMARGIN='10' LEFTMARTIN='0'>"+val+"</BODY></HTML>");
	Okienko.document.close();
	Okienko.focus();		
}

function printr(val) {
	switch (typeof val) {
        case ("object"):
			if (val.lenght) {
				var o=array2String(val,0);
			} else {
				var o=object2String(val,0);
			}
			printr_show(o);
            break;
        default:
			printr_show(val);
	}	
}	

function ftab(i){
	var temp = '';
	for (var j=1;j<=i;j++) temp += "&nbsp;&nbsp;&nbsp;&nbsp;";	
	return temp;
}

function object2String(obj,j) {
    var val, output = "";
	++j;
    if (obj) {    
        output += "<b>object{</b><br>";
		var tab = ftab(j);
        for (var i in obj) {
			val = obj[i];
			if (val != null){
				switch (typeof val) {
	                case ("object"):
						if (val.lenght) {
							output += tab + i + " => " + array2String(val,j) + "<br>";
	                    } else {
	                        output += tab + i + " => " + object2String(val,j) + "<br>";
	                    }
	                    break;
	                case ("string"):
	                    output += tab + i + " => '" + escape(val) + "'<br>";
	                    break;
	                default:
	                    output += tab + i + " => " + val + "<br>";
	            }
			} else {
				break;
			}
        }
        output = output.substring(0, output.length) + tab + "<b>}</b>";
    }
    return output;
}

function array2String(array,k) {
    var output = "";
	++k;
    if (array) {
        output += "<b>array[</b><br>";
		var tab = ftab(k);
        for (var i in array) {
            val = array[i];
            switch (typeof val) {
                case ("object"):
                    if (val[0]) {
                        output += tab + array2String(val,k) + "<br>";
                    } else {
                        output += tab + object2String(val,k) + "<br>";
                    }
                    break;
                case ("string"):
                    output += tab+"'" + escape(val) + "'<br>";
                    break;
                default:
                    output += tab + val + "<br>";
            }
        }
        output = output.substring(0, output.length) + tab + "<b>]</b>";
    }
    return output;
}


function string2Object(string) {
    eval("var result = " + string);
    return result;
}

function string2Array(string) {
    eval("var result = " + string);
    return result;
}
/* PRINTR */

function mask(string,textbox,location,delim){
	var loc = location.split(',');
	for (var i = 0; i <= location.length; i++){
		for (var k = 0; k <= string.length; k++) {
			if (k == location[i]) {
				if (string.substring(k, k + 1) != delim) {
					string = string.substring(0, k) + delim + string.substring(k, string.length)
				}
			}
		}
	}
	textbox.value = string;
}

	
function showInterview(id){
	document.getElementById("contents").style.height = 'auto';
	
	var temp_id = interview_ids.split(",");
	for(var i = 0; i < temp_id.length; i++){
		if(temp_id[i] != id && temp_id[i].length != 0){
			$(temp_id[i]).hide();
		}else{
	  		if(temp_id[i].length != 0){
	  			$(id).toggle();
			}
	  	}
	}
	
	var left = document.getElementById("left");
	var right = document.getElementById("subpage");
	var contents = document.getElementById("contents");
	var roznica = right.offsetHeight-contents.offsetHeight-11;
	
	if(left.offsetHeight > right.offsetHeight){
		contents.style.height = (left.offsetHeight-roznica)+"px";
	}else{
		document.getElementById("contents").style.height = 'auto';
	}
}

function showCitation(){
	document.getElementById('citation').style.display = document.getElementById('citation').style.display=='block' ? 'none' : 'block';
}

function showMethods(){
	var temp_id = recruitmen_ids.split(",");
	for(var i = 0; i < temp_id.length; i++){
		if(temp_id[i].length != 0)	document.getElementById(temp_id[i]).style.display = 'none';
	}
	
	document.getElementById('methods').style.display = 'block';
}

function closeMethods(){
	document.getElementById('methods').style.display = 'none';
}	

function showRecruitmen(id){
	document.getElementById('methods').style.display = 'none';
	var temp_id = recruitmen_ids.split(",");
	for(var i = 0; i < temp_id.length; i++){
		if(temp_id[i].length != 0 && temp_id[i] != id){
			document.getElementById(temp_id[i]).style.display = 'none';
		}
	}
	document.getElementById(id).style.display = 'block';
	dragDrop.initElement(document.getElementById(id));
}

function closeRecruitmen(id){
	document.getElementById(id).style.display = 'none';
}

function showRecipe(id){
	var temp_id = recipe_ids.split(",");
	for(var i = 0; i < temp_id.length; i++){
		if(temp_id[i].length != 0 && temp_id[i] != id){
			document.getElementById(temp_id[i]).style.display = 'none';
		}
	}
	document.getElementById(id).style.display = 'block';
	dragDrop.initElement(document.getElementById(id));
}

function closeRecipe(id){
	document.getElementById(id).style.display = 'none';
}

$(document).ready(function() {
	$.datepicker.setDefaults({
        dateFormat: 'yy-mm-dd',
        monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
        monthNamesShort: ['Sty','Lut','Mar','Kwi','Maj','Cze','Lip','Sie','Wrz','Paz','Lis','Gru'], 
        dayNames: ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'],
        dayNamesMin: ['Ni', 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'So'],
        firstDay: 1,
        showOn: 'both',
        buttonImage: '../images/icons/callendar.png', 
        buttonImageOnly: true
	});
});

function showRecruitmen(id){
	$('#methods').hide();
	var temp_id = recruitmen_ids.split(",");
	for(var i = 0; i < temp_id.length; i++){
		if(temp_id[i].length != 0 && temp_id[i] != id){
			$('#'+temp_id[i]).hide();
		}
	}
	document.getElementById(id).style.display = 'block';
}


	function tryAttachEventBodyHeight(id){
	    var h = $(document).height();
	    try {
	        if (h > 0) {
	           parent.document.getElementById(id).height = h+'px';
	           return true;
	        }
	    } catch (error) {}

	    setTimeout(function(){tryAttachEventBodyHeight()}, 100);
	    return false;
	}

