var email_form_height = 1;
var email_textarea_height = 1;
var email_field_cache = '';

function changeColor(td, to_wich)
{
	if (to_wich == 1){
		td.style.backgroundColor = "#E6E6E6";
		td.style.color = "#000000";
	}else if (to_wich == 2){
		td.style.backgroundColor = "#C22A15";
		td.style.color = "#FFFFFF";
	}else{
		td.style.backgroundColor = "#FFFFFF";
		td.style.color = "#000000";
	}
}

function setCookie(c_name, c_value)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + 1000);
	document.cookie = c_name + "=" + escape(c_value) + ";expires=" + exdate.toGMTString();
}

function changeLang(language)
{
	setCookie('lang', language);
	window.location.reload();
}

function load_page(go_to_url)
{
	document.location.href = go_to_url;
}

function load_gallery_image(image_locaiton)
{
	var view_large = document.getElementsByName('view_large');
	view_large[0].src = image_locaiton;
}

function email_link()
{
	// do you like the protection against email spam - I thought it myself
	var part1 = '@';
	document.location.href = 'mailto'+':info'+part1+'vir2002'+'.'+'com';
}

function email_body(on_focus)
{
	// get both elements
	var textarea = document.getElementById('message');
	
	if (on_focus == 1){
		email_textarea_height = textarea.style.height;
		textarea.style.height = '250px';
	}else{
		textarea.style.height = email_textarea_height;
	}
}

function test_mail(data){
	var regex = new RegExp("^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$");
	return regex.test(data);
}

function send_email()
{
	// check if the fields are properly filled up
	var address = document.getElementById('address');
	var message = document.getElementById('message');
	
	if (address.value == ''){
		// invalid
		alert(error_empty_email);
		return;
	}else if (!test_mail(address.value)){
		// invalid
		alert(error_inproper_email);
		return;
	}else if (message.value == ''){
		// invalid
		alert(error_empty_message);
		return;
	}
	
	// show sending message
	var email_form = document.getElementById('email_form');
	email_field_cache = email_form.innerHTML;
	email_form.innerHTML = email_form_sending;
	
	// create sending form
	var new_form = document.createElement('iframe');
	new_form.setAttribute('name', 'email_submit_form');	
	
	var new_div = document.createElement('div');
	
	new_div.innerHTML = '<form id="send_mail_form" method="post" action="send_mail.php" target="email_submit_form"><input type="hidden" name="address" value="' + address.value + '" /><input type="hidden" name="message" value="' + message.value + '" /><input type="hidden" name="email_key" value="' + send_mail_key + '" /></form>';
	
	email_form.appendChild(new_form);
	email_form.appendChild(new_div);
	
	var send_form = document.getElementById('send_mail_form');
	send_form.submit();
}

function send_email_success()
{
	var email_form = document.getElementById('email_form');
	email_form.innerHTML = email_form_sent;
}

function print_contacts(print_address)
{
	var new_div = document.createElement('div');
	
	new_div.innerHTML = '<form id="print_form" method="post" action="'+print_address+'" target="_new"><input type="hidden" name="print" value="1" /></form>';
	document.body.appendChild(new_div);
	
	var print_form = document.getElementById('print_form');
	print_form.submit();
}

function toggle_print_popup(will_show)
{
	var print_div = document.getElementById('print_caption');
	
	if (will_show == 1){
		print_div.innerHTML = print_popup_html;
	}else{
		print_div.innerHTML = '';
	}
}