//general scripts
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 displayProductImage(url)
{
	var Win = window.open(url,rand_value(),'width=1, height=1, resizable=no, scrollbars=no, menubar=no, status=no, toolbar=no');
}

function WindowResize(width, height)
{
	window.resizeTo(width + 50, height + 80);
	self.focus();
}

//single form
function checkSearch()
{
	if (document.search.search_value.value.length < 3)
	{
		alert (lang_labels[0]);
		return false;
	}
}

function checkSearch_adv()
{
	if (document.search_adv.search_value.value.length < 3)
	{
		alert (lang_labels[0]);
		return false;
	}
}

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 (lang_labels[1]);
		return false;
	}
}

function check_send_error()
{
	if (document.send_error.message.value.length < 5)
	{
		alert(lang_labels[2]);
		return false;
	}
}

//group form
function checkSend_mail_subject()
{
	if (document.send_email.subject.value.length < 8)
	{
		formMessage = lang_labels[3];
		return true;
	}
}

function checkSend_mail_name()
{
	if (document.send_email.name.value.length < 8)
	{
		formMessage = lang_labels[4];
		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 = lang_labels[1];
		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 = lang_labels[5];
			return true; 
		}
	}
}

function checkSend_mail_message()
{
	if (document.send_email.message.value.length < 20)
	{
		formMessage = lang_labels[6];
		return true;
	}
}

function checkSend_mail_code()
{
	if (document.send_email.code.value.length < 6)
	{
		formMessage = lang_labels[7];
		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_registration_name()
{
	if (document.registration.name.value.length < 5)
	{
		formMessage = lang_labels[8];
		return true;
	}
}
function check_registration_street()
{
	if (document.registration.street.value.length < 2)
	{
		formMessage = lang_labels[9];
		return true;
	}
}
function check_registration_post_code()
{
	sample=RegExp("^[0-9]{2,}-[0-9]{2,}$");
	if (!sample.test(document.registration.post_code.value))  
	{ 
		formMessage = lang_labels[10] + '\n' + lang_labels[11];
		return true; 
	} 
}
function check_registration_city()
{
	if (document.registration.city.value.length < 3)
	{
		formMessage = lang_labels[12];
		return true;
	}
}
function check_registration_nip()
{
	if (document.registration.nip.value.length > 0)
	{
		sample=RegExp("^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$");
		if (!sample.test(document.registration.nip.value))  
		{ 
			formMessage = lang_labels[13] + '\n' + lang_labels[14];
			return true; 
		} 
	}
}
function check_registration_phone()
{
	if (document.registration.phone.value.length > 0)
	{
		sample=RegExp("^[0-9-+() ]{8,}$");
		if (!sample.test(document.registration.phone.value))  
		{ 
			formMessage = lang_labels[15] + '\n' + lang_labels[16] + '\n' + lang_labels[17];
			return true; 
		} 
	}
}
function check_registration_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.registration.email.value))  
	{ 
		formMessage = lang_labels[18];
		return true; 
	} 
}
function check_registration_login()
{
	if ((document.registration.login.value.length < 4) || (document.registration.login.value.length > 20))
	{
		formMessage = lang_labels[19];
		return true;
	}
}
function check_registration_password_match()
{
	if (document.registration.password.value != document.registration.password_retype.value)
	{
		formMessage = lang_labels[20] + '\n' + lang_labels[21];
		return true;
	}
}
function check_registration_password()
{
	if ((document.registration.password.value.length < 6) || (document.registration.password.value.length > 20) || (document.registration.password_retype.value.length < 6) || (document.registration.password_retype.value.length > 20))
	{
		formMessage = lang_labels[22];
		return true;
	}
}
function check_registration_code()
{
	sample=RegExp("^[0-9]{6}$");
	if (!sample.test(document.registration.code.value))  
	{ 
		formMessage = lang_labels[23] + '\n' + lang_labels[24];
		return true; 
	} 
}
function check_registration_agreement()
{
	if (!document.registration.agreement.checked) 
	{
		formMessage = lang_labels[25];
		return true;
	}
}
function check_registration_form()
{
	if ( (check_registration_name()) || (check_registration_street()) || (check_registration_post_code()) || (check_registration_city()) || (check_registration_nip()) || (check_registration_phone()) || (check_registration_email()) || (check_registration_login()) || (check_registration_password_match()) || (check_registration_password()) || (check_registration_code()) || (check_registration_agreement()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_order_name()
{
	if (document.order.name.value.length < 5)
	{
		formMessage = lang_labels[8];
		return true;
	}
}
function check_order_street()
{
	if (document.order.street.value.length < 2)
	{
		formMessage = lang_labels[9];
		return true;
	}
}
function check_order_post_code()
{
	sample=RegExp("^[0-9]{2,}-[0-9]{2,}$");
	if (!sample.test(document.order.post_code.value))  
	{ 
		formMessage = lang_labels[10] + '\n' + lang_labels[11];
		return true; 
	} 
}
function check_order_city()
{
	if (document.order.city.value.length < 3)
	{
		formMessage = lang_labels[12];
		return true;
	}
}
function check_order_nip()
{
	if (document.order.nip.value.length > 0)
	{
		sample=RegExp("^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$");
		if (!sample.test(document.order.nip.value))  
		{ 
			formMessage = lang_labels[13] + '\n' + lang_labels[14];
			return true; 
		} 
	}
}
function check_order_phone()
{
	if (document.order.phone.value.length > 0)
	{
		sample=RegExp("^[0-9-+() ]{8,}$");
		if (!sample.test(document.order.phone.value))  
		{ 
			formMessage = lang_labels[15] + '\n' + lang_labels[16] + '\n' + lang_labels[17];
			return true; 
		} 
	}
}
function check_order_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.order.email.value))  
	{ 
		formMessage = lang_labels[18];
		return true; 
	} 
}

function check_order_form()
{
	if ( (check_order_name()) || (check_order_street()) || (check_order_post_code()) || (check_order_city()) || (check_order_nip()) || (check_order_phone()) || (check_order_email()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_account_name()
{
	if (document.account.name.value.length < 5)
	{
		formMessage = lang_labels[8];
		return true;
	}
}
function check_account_street()
{
	if (document.account.street.value.length < 2)
	{
		formMessage = lang_labels[9];
		return true;
	}
}
function check_account_post_code()
{
	sample=RegExp("^[0-9]{2,}-[0-9]{2,}$");
	if (!sample.test(document.account.post_code.value))  
	{ 
		formMessage = lang_labels[10] + '\n' + lang_labels[11];
		return true; 
	} 
}
function check_account_city()
{
	if (document.account.city.value.length < 3)
	{
		formMessage = lang_labels[12];
		return true;
	}
}
function check_account_nip()
{
	if (document.account.nip.value.length > 0)
	{
		sample=RegExp("^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$");
		if (!sample.test(document.account.nip.value))  
		{ 
			formMessage = lang_labels[13] + '\n' + lang_labels[14];
			return true; 
		} 
	}
}
function check_account_phone()
{
	if (document.account.phone.value.length > 0)
	{
		sample=RegExp("^[0-9-+() ]{8,}$");
		if (!sample.test(document.account.phone.value))  
		{ 
			formMessage = lang_labels[15] + '\n' + lang_labels[16] + '\n' + lang_labels[17];
			return true; 
		} 
	}
}
function check_account_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.account.email.value))  
	{ 
		formMessage = lang_labels[18];
		return true; 
	} 
}
function check_account_code()
{
	sample=RegExp("^[0-9]{6}$");
	if (!sample.test(document.account.code.value))  
	{ 
		formMessage = lang_labels[23] + '\n' + lang_labels[24];
		return true; 
	} 
}
function check_account_form()
{
	if ( (check_account_name()) || (check_account_street()) || (check_account_post_code()) || (check_account_city()) || (check_account_nip()) || (check_account_phone()) || (check_account_email()) || (check_account_code()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_account_password_old()
{
	if ((document.change_password.password_old.value.length < 6) || (document.change_password.password_old.value.length > 20))
	{
		formMessage = lang_labels[26];
		return true;
	}
}
function check_account_password_match()
{
	if (document.change_password.password.value != document.change_password.password_retype.value)
	{
		formMessage = lang_labels[20] + '\n' + lang_labels[21];
		return true;
	}
}
function check_account_new_password()
{
	if ((document.change_password.password.value.length < 6) || (document.change_password.password.value.length > 20) || (document.change_password.password_retype.value.length < 6) || (document.change_password.password_retype.value.length > 20))
	{
		formMessage = lang_labels[22];
		return true;
	}
}
function check_account_code()
{
	sample=RegExp("^[0-9]{6}$");
	if (!sample.test(document.change_password.code.value))  
	{ 
		formMessage = lang_labels[23] + '\n' + lang_labels[24];
		return true; 
	} 
}
function check_account_password()
{
	if ( (check_account_password_old()) || (check_account_password_match()) || (check_account_new_password()) || (check_account_code()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_login_login()
{
	if ((document.login.login.value.length < 4) || (document.login.login.value.length > 20))
	{
		formMessage = lang_labels[27];
		return true;
	}
}
function check_login_password()
{
	if ((document.login.password.value.length < 6) || (document.login.password.value.length > 20))
	{
		formMessage = lang_labels[28];
		return true;
	}
}
function check_login_form()
{
	if ( (check_login_login()) || (check_login_password()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_reset_account_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.reset_account.email.value))
	{
		alert (lang_labels[18]);
		return false;
	}
}

function check_send_recommend_to_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.send_recommend.to_email.value))
	{
		formMessage = lang_labels[29];
		return true;
	}
}
function check_send_recommend_sender_email()
{
	sample=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
	if (!sample.test(document.send_recommend.sender_email.value))
	{
		formMessage = lang_labels[30];
		return true;
	}
}
function check_send_recommend_sender_name()
{
	if (document.send_recommend.sender_name.value.length < 3)
	{
		formMessage = lang_labels[31];
		return true;
	}
}
function check_send_recommend()
{
	if ( (check_send_recommend_to_email()) || (check_send_recommend_sender_email()) || (check_send_recommend_sender_name()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function check_send_comment_author()
{
	if (document.send_comment.author.value.length < 3)
	{
		formMessage = lang_labels[31];
		return true;
	}
}
function check_send_comment_comment()
{
	if (document.send_comment.comment.value.length < 10)
	{
		formMessage = lang_labels[32];
		return true;
	}
}
function check_send_comment()
{
	if ( (check_send_comment_author()) || (check_send_comment_comment()) )
	{
		alert(formMessage);
		return false;
	}
	else
	{
		return true;
	}
}

