function showHideRow(id) {
	var row = document.getElementById(id);
	if (row){
		if (row.style.display=='none')
			row.style.display=(navigator.userAgent.toLowerCase().indexOf('gecko')!=-1||window.opera)?'table-row':'block';
		else
			row.style.display='none';
	}
}
var photo = null;
var imageLoader = null;
function loadPhoto(src) {
	clearInterval(imageLoader);
	photo = null;
	photo = new Image();
	photo.src=src;
	imageLoader=setInterval('checkPhotoLoaded()',100);
	var li = document.getElementById('loading_indicator');
	if (li) li.style.display='block';
}
function checkPhotoLoaded(){
	if (photo.complete) {
		clearInterval(imageLoader);
		var img = document.getElementById('main_image');
		img.src=photo.src;
		var li = document.getElementById('loading_indicator');
		if (li) li.style.display='none';
	} 
}

function checkEmail(mail){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z0-9]{2,6}(?:\.[a-z]{2})?)$/i
	return filter.test(mail);
}


function saveObjectAndGo(go){
	var values = new Array();
	values['go']=go;
	post(values,"object_form")
}

function imagePos(direction,id){
	var values = new Array();
	values['image_position']=true;
	values['direction']=direction;
	values['image_id']=id;
	post(values);
}

function imageDelete(id){
if (confirm("Czy na pewno chcesz usunać to zdjęcie?")){
	var values = new Array();
	values['image_delete']=true;
	values['image_id']=id;
	post(values);
	}
}

function changeVisibility(id,visible){
	var values = new Array();
	values['change_visibility']=true;
	values['id']=id;
	if (!visible) {
		text = prompt("Podaj powód ukrycia obiektu");
		if (!text||text=="") return;
		values['text']=text;
	}
	values['visible']=(visible)?1:0;
	post(values);
}

function objectDelete(id){
if (confirm("Czy na pewno chcesz usunać obiekt?")){
	var values = new Array();
	values['object_delete']=true;
	values['id']=id;
	post(values);
	}
}

function objectUnDelete(id){
if (confirm("Czy na pewno chcesz przywrócić obiekt?")){
	var values = new Array();
	values['object_undelete']=true;
	values['id']=id;
	post(values);
	}
}


function post(values_array, form_id, action){
	var form;
	if (form_id){
		form = document.getElementById(form_id);
		if (!form) return;

	} else {
		form = document.createElement('form');
		document.body.appendChild(form);
	}
	if (action) form.action = action;
	form.method="post";
	for(var j in values_array){
		var input = document.createElement('input');
		input.type= "hidden";
		input.name = j;
		input.value = values_array[j];
		form.appendChild(input);
	}
	form.submit();
}

function validDate(year,month,day){
	var monthsMax = {1 : 31, 2 : 29, 3 : 31, 4 : 30, 5 : 31, 6 : 30, 7 : 31, 8 : 31, 9 : 30, 10 : 31, 11 : 30, 12 : 31};
	if (year<1902||year>2036|month<1||month>12||day<1||(month==2&&!(year%4==0&&(year%100!=0||year%400==0))&&day>28)||(month>=1&&month<=12&&day>monthsMax[month])) return false;
	return true;
}

function checkDate(date){
	if (!/^([1-2]{1}[0-9]{3})-([01][0-9])-([0-3][0-9])$/.test(date)) return false;
	return validDate(RegExp.$1,RegExp.$2,RegExp.$3);
}


function doOnEnter(to_do,e) {
	if (e.keyCode==13) eval(to_do);
}


function checkNip(nip){
	var filter=/^([0-9]){2,3}(-){0,1}([0-9]){2,3}(-){0,1}([0-9]){2,3}(-){0,1}([0-9]){2,3}$/i
	return filter.test(nip);
}


function setSelectValue(select,elem){
	if (select.length){
	for(var i=0; i<select.length; i++){

		if(select[i].value==elem){
			select[i].selected=true;
			break;
		}
	}
	}
}

function setGroupValue(group, elem){
	if (group.length)
	for(var i=0; i<group.length; i++){
		if(group[i].value==elem){
			group[i].checked=true;
			break;
		}
	} else if (group&&group.value){
		if(group.value==elem){
			group.checked=true;
		}
	}
}

function groupValue(group){
	if (group.length)
	for(var i=0; i<group.length; i++){
		if(group[i].checked){
			return group[i].value;
			break;
		}
	} else if (group&& group.value){
		if(group.checked){
			return group.value;
		}
	}
	return "";
}



function trim(string){
	return string.replace(/\s+/g,' ').replace(/^\s+/g,'').replace(/\s+$/g,'');
}

function popup(url) {
	var w = 550;
	var h = 435;
	
	var win_width = screen.availWidth;
	var win_height = screen.availHeight;
	
	var	pop_top = parseInt(win_height/2-h/2);
	var	pop_left = parseInt(win_width/2-w/2);
	
	
	window.open(url,'','width='+w+', height='+h+', left='+pop_left+', top='+pop_top,  'scrollbars=no,menubar=0,resizable=0').focus()
}