nn4=(document.layers) ? true : false;
ie4=(document.all) ? true : false;Nowe=null;

function setHidden(me) {
	me.style.visibility='hidden';
}

function ri(w,s,zmienne) {
		if (Nowe) {
			if (ie4) Nowe.close();
			else if (nn4) Nowe.closed;
			Nowe=null
		};
		Nowe=window.open("ri.php?"+zmienne, "popUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=s,height=w,screenX=150,screenY=150,top=150,left=150");
		Nowe.resizeTo(w,s);
		Nowe.focus();
	}
	
function oblicz_cene(w,s,zmienne) {
	if (Nowe) {
		if (ie4) Nowe.close();
		else if (nn4) Nowe.closed;
		Nowe=null
	};
	Nowe=window.open("oblicz_cene.php?"+zmienne, "popUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=s,height=w,screenX=150,screenY=150,top=150,left=150");
	Nowe.resizeTo(w,s);
	Nowe.focus();
}
function otworz_popup(w,s,src) {
            if (Nowe) {
                if (ie4) Nowe.close();
            	else if (nn4) Nowe.closed;
                Nowe=null
            };
            Nowe=window.open("popup_image.php?p="+src, "popUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=50,left=50");                
            Nowe.focus();
        }


function otworz_popup_mapa(ido, lang) {
            if (Nowe) {
                if (ie4) Nowe.close();
            	else if (nn4) Nowe.closed;
                Nowe=null
            };
            Nowe=window.open("gmapka.php?ido="+ido+"&lang="+lang, "popUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=620,height=505,screenX=150,screenY=150,top=50,left=50");                
            Nowe.focus();
        }
        
function dymek(tekst, wersjaKolorystyczna) {
    return overlib( tekst,
//                    BGCOLOR,'#F37B00',
//                    BGCOLOR,'#FFFFFF',
//                    FGCOLOR,'#13557e',
//                    TEXTCOLOR,'#ffffff',
                    BGCOLOR,'#000000',
                    FGCOLOR,'#FFFFFF',
                    TEXTCOLOR,'#000000',
                    HAUTO,
                    VAUTO);    
}

function NewWindow(mypage,myname,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  	settings = 'height=' +h+',width=' +w+',top=' +TopPosition+',left=' +LeftPosition+',scrollbars=' +scroll+ ',resizable';
	win = window.open(mypage,myname,settings)
	if(win.window.focus) {
		win.window.focus();
	}
}

function makeLink(){
	var url = window.prompt("podaj adres URL", "http://");
	var link = window.prompt("podaj tekst linku");
	var newWindow = window.confirm("czy otiwerac link w nowym oknie?");
	return '<a href="'+url+'" '+(newWindow ? 'target="_top"' : '')+' >'+link+'</a>';
}

var d = document;

function hideC(id) {	
	id = (id?id:"kpconsole");	
	var layer = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	layer.style.display = 'none';
}

function showC(id) {
	id = (id?id:"kpconsole");
	var layer = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	layer.style.display = 'block';
}

function anulowanie(sValue, sKod, isAdmin, isLastMinute) {
	
	if((/^s0[^0]+/.test(sValue) || sValue == 's00' || /^[0-6]/.test(sValue)) && !/^s04w/.test(sValue)) {
		
		var iCheckedValue = 0;
		var sReason5 = "";
		
		if(/^[0-6]/.test(sValue))
			iCheckedValue = sValue;
		if(test = new RegExp('5:(.*)').exec(sValue)) {			
			iCheckedValue = 5;
			sReason5 = test[1];
		}

		$('a' + sKod).childNodes[0].innerHTML = '';
		oRow = $('a' + sKod).childNodes[0];		
		oRow.innerHTML += '<p class="acenter separated"><strong>WYBIERZ POWÓD ANULOWANIA REZERWACJI</strong></p>';
		if(isLastMinute)
			oRow.innerHTML += '<p><input type="radio" class="radio" name="powod[' + sKod + ']" id="p1' + sKod + '" value="1"' + (iCheckedValue == 1 ? ' checked="checked"' : "") + ' /><label for="p1' + sKod + '"> klient nie potwierdził rezerwacji telefonicznie</label></p>';
		oRow.innerHTML += '<p><input type="radio" class="radio" name="powod[' + sKod + ']" id="p2' + sKod + '" value="2"' + (iCheckedValue == 2 ? ' checked="checked"' : "") + ' /><label for="p2' + sKod + '"> klient odwołał rezerwację</label></p>';
		oRow.innerHTML += '<p><input type="radio" class="radio" name="powod[' + sKod + ']" id="p3' + sKod + '" value="3"' + (iCheckedValue == 3 ? ' checked="checked"' : "") + ' /><label for="p3' + sKod + '"> klient nie pojawił się na miejscu</label></p>';
		oRow.innerHTML += '<p><input type="radio" class="radio" name="powod[' + sKod + ']" id="p4' + sKod + '" value="4"' + (iCheckedValue == 4 ? ' checked="checked"' : "") + ' /><label for="p4' + sKod + '"> właściciel na życzenie klienta przeniósł rezerwację do innego swojego obiektu</label></p>';
		if(isAdmin)
			oRow.innerHTML += '<p><input type="radio" class="radio" name="powod[' + sKod + ']" id="p6' + sKod + '" value="6"' + (iCheckedValue == 6 ? ' checked="checked"' : "") + ' /><label for="p6' + sKod + '"> inna przyczyna (np. rezerwacja testowa, żart)</label></p>';
		oRow.innerHTML += '<p class="opt5"><input type="radio" class="radio" name="powod[' + sKod + ']" id="p5' + sKod + '" value="5"' + (iCheckedValue == 5 ? ' checked="checked"' : "") + ' /><label for="p5' + sKod + '"> właściciel nie może przyjąć rezerwacji, bo: </label><textarea onfocus="$(\'p5' + sKod + '\').checked = true;" name="powod5bo[' + sKod + ']" id="p5y' + sKod + '">' + sReason5 + '</textarea></p>';
		oRow.innerHTML += '<p class="separated">&nbsp;</p>';
		oRow.innerHTML += '<p class="acenter separated"><input type="button" onclick="checkAndSubmit(\'' + sKod + '\')" value="ANULUJ REZERWACJĘ" id="submit' + sKod + '" /> &nbsp&nbsp;&nbsp; <input type="button" onclick="anulujAnulowanie(\'' + sKod + '\')" value="ZAMKNIJ BEZ ZMIAN" /></p>';
		if(navigator.appName == 'Microsoft Internet Explorer') {
			
			$('a' + sKod).style.display = 'block';
			$('p5' + sKod).style.width = '80px';
			
		} else
			$('a' + sKod).style.display = 'table-row';
//		$('submitButton').style.visibility = 'hidden';
		
		if(iCheckedValue)
			$('submit' + sKod).value = 'ZAPISZ';
		
	} else {
		
		$('a' + sKod).childNodes[0].innerHTML = '';
		$('a' + sKod).style.display = 'none';
//		$('submitButton').style.visibility = 'visible';
		

	}
	

	
}

function anulujAnulowanie(sKod) {
	
	$('a' + sKod).style.display = 'none';
	$('a' + sKod).childNodes[0].innerHTML = '';
	$('nst_' + sKod).value = '';
//	$('submitButton').style.visibility = 'visible';
	
}

function checkAndSubmit(sKod) {
	
	var bEmpty = true;
	for(var i = 1; i <= 6; i++)
		if($('p' + i + sKod) && $('p' + i + sKod).checked)
				bEmpty = false;
	
	if(bEmpty) {
		
		alert('Proszę wybrać powód anulowania rezerwacji.');
		return false;
		
	}
	
	if($('p5' + sKod).checked && $('p5y' + sKod).value.length < 5) {
		
		alert('Proszę wpisać dlaczego rezerwacja nie mogła zostać przyjęta.');
		return false;
		
	}
	
	document.wyniki_wyszukiwania.submit();
	
}

function dataWyjazdu(bSetHiddenFields) {

	//if(document.getElementById(dataWyjazdu.JACSid).dateReturned) {

		var re = new RegExp(/([\d]{4})-([\d]{2})-([\d]{2})/g);
		var str = $('data_przyjazdu').value;
		var aMatch = re.exec(str);

		if(aMatch !== null) {

			//dziwny bug przy parseInt('08') albo '09' -> daje 0, dla innych, np '07' daje 7
			if(/^0/.test(aMatch[2]))
				aMatch[2] = aMatch[2].replace(/0/, '');
			if(/^0/.test(aMatch[3]))
				aMatch[3] = aMatch[3].replace(/0/, '');

			var oDate = new Date(parseInt(aMatch[1]), parseInt(aMatch[2]), parseInt(aMatch[3]) + 2);

			var re2 = new RegExp(/([\d]{4})-([\d]{2})-([\d]{2})/g);
			var str2 = $('data_wyjazdu').value;
			var aMatch2 = re2.exec(str2);

			var iUTC1 = oDate.getTime();
			var iUTC2 = 0;

			if(aMatch2 !== null) {

				if(/^0/.test(aMatch2[2]))
					aMatch2[2] = aMatch2[2].replace(/0/, '');
				if(/^0/.test(aMatch2[3]))
					aMatch2[3] = aMatch2[3].replace(/0/, '');

				var oDate2 = new Date(parseInt(aMatch2[1]), parseInt(aMatch2[2]), parseInt(aMatch2[3]) + 1);
				iUTC2 = oDate2.getTime();

			} else {

				//...

			}

			//if(iUTC2 <= iUTC1)
			//	$('data_wyjazdu').value = oDate.getFullYear() + "-" + (oDate.getMonth() * 1 < 10 ? "0" : "") + oDate.getMonth() + "-" + (parseInt(oDate.getDate()) < 10 ? "0" : "") + oDate.getDate();

		}
	//}
		
		if(bSetHiddenFields) {
			
			var str3 = $('data_wyjazdu').value;
			
			var re3 = new RegExp(/([\d]{4})-([\d]{2})-([\d]{2})/g);
			var aMatch3 = re3.exec(str3);

			if(aMatch3 !== null) {

				if(/^0/.test(aMatch3[2]))
					aMatch3[2] = aMatch3[2].replace(/0/, '');
				if(/^0/.test(aMatch3[3]))
					aMatch3[3] = aMatch3[3].replace(/0/, '');
				
			}
			
			$('szdp').value = aMatch[3];
			$('szmp').value = aMatch[2];
			if($('szrp') !== null)
				$('szrp').value = aMatch[1];
			$('szdw').value = aMatch3[3];
			$('szmw').value = aMatch3[2];
			if($('szrw') !== null)
				$('szrw').value = aMatch3[1];
					
		}		
}

function dataWyjazduSZ() {

	dataWyjazdu(true);
	
}

function prepareCal() {
	
	posX = (windowWidth() - 200) / 2;
	posY = (windowHeight() - 220) / 2;
	
	
}

function windowWidth() {
	var myWidth = 0;
	if (typeof(window.innerWidth) == 'number')
		myWidth = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		myWidth = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		myWidth = document.body.clientWidth;
	return myWidth;
}

function windowHeight() {
	var myHeight = 0;
	if (typeof(window.innerHeight) == 'number')
		myHeight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		myHeight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		myHeight = document.body.clientHeight;
	return myHeight;
}

