function check_mail()
{
	Wzor=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	OK=(Wzor.test(document.email.email.value)==true);
	if (!OK)
	{
		alert ("Niepoprawny adres e-mail!");
		return false;
	}
}

function checkCalcForm()
{
	if (document.calc.calc_value.value.length > 0)
	{
		allow=RegExp("^[0-9]{1,20}$");
		if (!allow.test(document.calc.calc_value.value))
		{ 
			alert ("Wartość do przeliczenia może zawierać tylko cyfry!");
			return false;
		}
	}
	else
	{
		alert ("Proszę podać wartość do przeliczenia!");
		return false;
	}
}

function checkGuestBook_name()
{
	if (document.guest_book.name.value.length < 5)
	{
		formMessage = "Twoje imię / nick powinno zawierać co najmniej 5 znaków!";
		return true;
	}
}

function checkGuestBook_essence()
{
	if (document.guest_book.essence.value.length < 5)
	{
		formMessage = "Treść wpisu powinna składać się z co najmniej 5 znaków!";
		return true;
	}
}

function checkGuestBook()
{
	if ( (checkGuestBook_name()) || (checkGuestBook_essence()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function checkSearch()
{
	if (document.search.search_string.value.length < 3)
	{
		alert ("Wyszukiwana fraza musi zawierać co najmniej 3 znaki!");
		return false;
	}
	else
	{
		return true;
	}
}

function checkSearch_ext()
{
	if (document.search_ext.search_string.value.length < 3)
	{
		alert ("Wyszukiwana fraza musi zawierać co najmniej 3 znaki!");
		return false;
	}
	else
	{
		return true;
	}
}

function rand_value()
{
	var rand_value = Math.round(Math.random() * 10000000000000000);
	return rand_value;
}

function displayImage(url,width,height)
{
	newWindow=window.open(url,rand_value(),'width=' + width + ',height='+ height + ', resizable=no, scrollbars=no, menubar=no, status=no, toolbar=no');
	newWindow.focus();
}

function displayWindow(url, width, height)
{
	var Win = window.open(url,rand_value(),'width=' + width + ',height=' + height + ', resizable=no, scrollbars=yes, menubar=no, status=no, toolbar=no');
}

function displayPopup(url)
{
	var Win = window.open(url,rand_value(),'width=1, height=1, resizable=no, scrollbars=yes, menubar=no, status=no, toolbar=no');
}

function pedigree(pedigree_id)
{
	newWindow = window.open('pedigree.php?id='+ pedigree_id,rand_value(),'width=680, height=500, resizable=no, scrollbars=no, menubar=no, status=no, toolbar=no');
	newWindow.focus();
}

function WindowResize(width, height)
{
	var i=0;
	if (navigator.appName == 'Netscape')
	{
		i=10;
	}
	window.resizeTo(width + 30, height + 60 - i);
	self.focus();
}

function checkSend_mail_subject()
{
	if (document.send_email.subject.value.length < 5)
	{
		formMessage = "Proszę podać temat wiadomości!";
		return true;
	}
}

function checkSend_mail_name()
{
	if (document.send_email.name.value.length < 8)
	{
		formMessage = "Proszę podać imię lub nazwiako!";
		return true;
	}
}

function checkSend_mail_email()
{
	Wzor=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	OK=(Wzor.test(document.send_email.email.value)==true);
	if (!OK)
	{
		formMessage = "Niepoprawny adres e-mail!";
		return true;
	}
}

function checkSend_mail_phone()
{
	if (document.send_email.phone.value.length > 0)
	{
		Wzor=RegExp("^[0-9-+() ]{8,}$");
		OK=(Wzor.test(document.send_email.phone.value)==true); 
		if (!OK)  
		{ 
			formMessage = "Niepoprawny numer telefonu!";
			return true; 
		}
	}
}

function checkSend_mail_message()
{
	if (document.send_email.message.value.length < 20)
	{
		formMessage = "Treść pytania powinna składać się z co najmniej 20 znaków!";
		return true;
	}
}

function checkSend_mail_code()
{
	if (document.send_email.code.value.length < 6)
	{
		formMessage = "Brak kodu potwierdzającego lub jego wartość jest za krótka!";
		return true;
	}
}

function checkSend_mail()
{
	if ( (checkSend_mail_subject()) || (checkSend_mail_name()) || (checkSend_mail_email()) || (checkSend_mail_phone()) || (checkSend_mail_message()) || (checkSend_mail_code()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_reservation_name()
{
	if (document.reservation.name.value.length < 7)
	{
		formMessage = "Proszę podać imię i nazwisko!";
		return true;
	}
}

function check_reservation_phone()
{
	Wzor=RegExp("^[0-9-() ]{8,}$");
	OK=(Wzor.test(document.reservation.phone.value)==true); 
	if (!OK)  
	{ 
		formMessage = "Niepoprawny lub brak numeru telefonu!\nNumer telefonu najlepiej podać w formacie:\nStacjonarny +48 74 111 11 11\nKomórki +48 501 11 11 11";
		return true; 
	}
}

function check_reservation_mail()
{
	Wzor=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	OK=(Wzor.test(document.reservation.email.value)==true);
	if (!OK)
	{
		formMessage = "Brak lub niepoprawny adres e-mail!";
		return true;
	}
}

function check_reservation_from()
{
	Wzor=RegExp("^[0-9-./]{10,10}$");
	OK=(Wzor.test(document.reservation.from_date.value)==true); 
	if (!OK)  
	{ 
		formMessage = "Proszę określić termin rozpoczęcia pobytu!\nData w formacie dd-mm-rrrr";
		return true; 
	}
}

function check_reservation_to()
{
	Wzor=RegExp("^[0-9-./]{10,10}$");
	OK=(Wzor.test(document.reservation.to_date.value)==true); 
	if (!OK)  
	{ 
		formMessage = "Proszę określić termin zakończenia pobytu!\nData w formacie dd-mm-rrrr";
		return true; 
	}
}

function check_reservation_room()
{
	if (document.reservation.room.value.length < 5)
	{
		formMessage = "Proszę określić rodzaj pokoju do rezerwacji!";
		return true;
	}
}

function check_reservation_persons()
{
	Wzor=RegExp("^[0-9]{1,3}$");
	OK=(Wzor.test(document.reservation.persons.value)==true); 
	if (!OK)  
	{ 
		formMessage = "Proszę podać liczbę osób, tylko cyfry!";
		return true; 
	}
}
function check_reservation_code()
{
	sample=RegExp("^[0-9]{6}$");
	if (!sample.test(document.reservation.code.value))
	{ 
		formMessage = "Przepisz kod z obrazka!\nKod zabezpieczający powinien zawierać 6 cyfr.";
		return true;
	} 
}
function check_reservation()
{
	if ( (check_reservation_name()) || (check_reservation_phone()) || (check_reservation_mail()) || (check_reservation_from()) || (check_reservation_to()) || (check_reservation_room()) || (check_reservation_persons()) || (check_reservation_code()))
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_phone()
{
	if (document.sms.phone.value.length > 0)
	{
		Wzor=RegExp("^[0-9+]{12}$");
		OK=(Wzor.test(document.sms.phone.value)==true); 
		if (!OK)  
		{ 
			alert("Niepoprawny numer telefonu!\nFormat poprawnego numeru: +48601223344");
			return false;
		}
	}
}

function timer()
{
	date = new Date();
	date.setTime(date.getTime()-servertime_difference);
	hours = date.getHours();
	minutes = date.getMinutes(); minutes = minutes<10? '0' + minutes : minutes;
	secounds = date.getSeconds(); secounds = secounds<10? '0' + secounds : secounds;
	document.getElementById('clock').innerHTML=+ hours + ':' + minutes + ':' + secounds;
	setTimeout('timer()', 1000);
}

function mailto_us(account)
{
	email_account = (account==undefined)? 'cukierniaaga' : account;
	email_domain_1 = 'data';
	email_domain_2 = 'pl';
	window.location = 'mailto:'+email_account+'@'+email_domain_1+'.'+email_domain_2;
}

function swapportfolio(image_url)
{
	document.portfolio_image.src = image_url;
}

