
var filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@(([^-]\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([^-][a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;


// registration
function reg_validate(lang)
{
	the_form = document.forms.register;

	if(the_form.name.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашето име!');
		}
		else
		{
			alert('Please enter your name!');
		}
		the_form.name.focus();
		return;
	}

	if(the_form.email.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашият имейл адрес');
		}
		else
		{
			alert('Please enter your email address!');
		}
		the_form.email.focus();
		return;
	}

	if (!the_form.email.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес не е валиден');
		}
		else
		{
			alert('The email address is not valid!');
		}
		the_form.email.focus();
		return;
	}

	if(the_form.pass.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашата парола');
		}
		else
		{
			alert('Please enter your password!');
		}
		the_form.pass.focus();
		return;
	}

	if(the_form.pass2.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля повторете вашата парола');
		}
		else
		{
			alert('Please repeat your password!');
		}
		the_form.pass2.focus();
		return;
	}

	if(the_form.pass.value != the_form.pass2.value)
	{
		if(lang == 'bg')
		{
			alert('Въведените пароли не са еднакви!');
		}
		else
		{
			alert('The paswords are not equal!');
		}
		the_form.pass.focus();
		return;
	}

	if(!the_form.terms.checked)
	{
		if(lang == 'bg')
		{
			alert('Трябва да се съгласите с условията за ползване на сайта!');
		}
		else
		{
			alert('You must accept our terms and conditions!');
		}
		the_form.pass.focus();
		return;
	}


	the_form.submit();
}// end function

function promo_reg_validate(lang)
{
	the_form = document.forms.promo_register;

	if(the_form.name.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашето име!');
		}
		else
		{
			alert('Please enter your name!');
		}
		the_form.name.focus();
		return;
	}
	
	if(the_form.uname.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете потребителско име!');
		}
		else
		{
			alert('Please enter username!');
		}
		the_form.uname.focus();
		return;
	}

	if(the_form.email.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашият имейл адрес');
		}
		else
		{
			alert('Please enter your email address!');
		}
		the_form.email.focus();
		return;
	}

	if (!the_form.email.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес не е валиден');
		}
		else
		{
			alert('The email address is not valid!');
		}
		the_form.email.focus();
		return;
	}

	if(the_form.pass.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашата парола');
		}
		else
		{
			alert('Please enter your password!');
		}
		the_form.pass.focus();
		return;
	}

	if(the_form.pass2.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля повторете вашата парола');
		}
		else
		{
			alert('Please repeat your password!');
		}
		the_form.pass2.focus();
		return;
	}

	if(the_form.pass.value != the_form.pass2.value)
	{
		if(lang == 'bg')
		{
			alert('Въведените пароли не са еднакви!');
		}
		else
		{
			alert('The paswords are not equal!');
		}
		the_form.pass.focus();
		return;
	}

	if(!the_form.terms.checked)
	{
		if(lang == 'bg')
		{
			alert('Трябва да се съгласите с условията за ползване на сайта!');
		}
		else
		{
			alert('You must accept our terms and conditions!');
		}
		the_form.pass.focus();
		return;
	}


	the_form.submit();
}// end function

// registration
function profile_validate(lang)
{
	the_form = document.forms.profile;

	if(the_form.name.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашето име!');
		}
		else
		{
			alert('Please enter your name!');
		}
		the_form.name.focus();
		return;
	}

	if(the_form.email.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашият имейл адрес');
		}
		else
		{
			alert('Please enter your email address!');
		}
		the_form.email.focus();
		return;
	}

	if (!the_form.email.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес не е валиден');
		}
		else
		{
			alert('The email address is not valid!');
		}
		the_form.email.focus();
		return;
	}


	if((the_form.pass.value != '' || the_form.pass2.value != '') && (the_form.pass.value != the_form.pass2.value))
	{
		if(lang == 'bg')
		{
			alert('Въведените пароли не са еднакви!');
		}
		else
		{
			alert('The paswords are not equal!');
		}
		the_form.pass.focus();
		return;
	}

	the_form.submit();
}// end function


// send forgotten passsword
function send_pass(lang)
{
	the_form = document.forms.forgotten;
	if(the_form.email.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашият имейл адрес');
		}
		else
		{
			alert('Please enter your email address!');
		}
		the_form.email.focus();
		return;
	}

	if (!the_form.email.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес не е валиден');
		}
		else
		{
			alert('The email address is not valid!');
		}
		the_form.email.focus();
		return;
	}

	the_form.submit();
}// end function


// validate calculator
function submit_calculator()
{
	obj = document.forms.calculator;

	obj.submit();
}// end function


// change product status (selected)
function ch_stat(id)
{
	var text_input = document.getElementById('count_' + id);
	var ch_box = document.getElementById('product_' + id);

	if(ch_box.checked)
	{
		text_input.disabled = false;
		text_input. value = 1;
	}
	else
	{
		text_input.disabled = 'disabled';
		text_input. value = '';
	}
}// end function


function go_to_menu(url){
	location.href = url + "organiser.php?persons=" + document.forms.organise.persons.value;
}// end function


// validate apply form
function validate_career()
{
	var the_form = document.forms["apply"];
	/*if(document.getElementById("pos_1").checked == false && document.getElementById("pos_2").checked == false)
	{
		alert("Моля изберете предпочитаната позиция!");
		return;
	}*/
	if(the_form.name.value == '')
	{
		alert("Моля попълнете вашето име!");
		the_form.name.focus();
		return;
	}
	if(the_form.surname.value == '')
	{
		alert("Моля попълнете вашето презиме!");
		the_form.surname.focus();
		return;
	}
	if(the_form.family.value == '')
	{
		alert("Моля попълнете вашата фамилия!");
		the_form.family.focus();
		return;
	}
	/*if(the_form.birth_data.value == '')
	{
	alert("Моля попълнете мястото и датата на раждане!");
	the_form.birth_data.focus();
	return;
	}*/
	if(the_form.address.value == '')
	{
		alert("Моля попълнете Вашият адрес!");
		the_form.address.focus();
		return;
	}
	if(the_form.phone.value == '')
	{
		alert("Моля попълнете Вашият телефонен номер!");
		the_form.phone.focus();
		return;
	}
	/*if(the_form.education.value == '')
	{
	alert("Моля попълнете Вашето образование!");
	the_form.education.focus();
	return;
	}*/
	if(document.getElementById("c_edu_y").checked == false && document.getElementById("c_edu_n").checked == false)
	{
		alert("Моля посочете дали продължавате образованието си!");
		return;
	}
	if(the_form.experience.value == '')
	{
		alert("Моля попълнете Вашият трудов стаж!");
		the_form.experience.focus();
		return;
	}
	if(document.getElementById("time_1").checked == false
	&& document.getElementById("time_2").checked == false
	&& document.getElementById("time_3").checked == false
	)
	{
		alert("Моля изберете предпочитаното от вас работно време!");
		return;
	}
	//alert(the_form.birth_data.value);
	the_form.submit();
}// end function


function playVideo(path){
	var player = new SWFObject("images/flash/video.swf", "menu_large", "400", "395", "7");
	player.addVariable("flvPath", path);
	player.write("lightbox");
	document.getElementById('lightbox_holder').style.display = "block";
}


function closeVideo(){
	document.getElementById('lightbox').innerHTML = "";
	document.getElementById('lightbox_holder').style.display = "none";
}


function load_restaurants(town, lg)
{
	new Ajax.Updater('restaurants_info', 'aj.php', {
  	parameters: { town_id: town, lg: lg}
	});
}// end function

function show_info(prod_id)
{
//	if($(prod_id).style.display == 'block')
	if($(prod_id).className == 'product_fatcs')
	{
		//$(prod_id).style.display = 'none';
		$(prod_id).className = 'product_fatcs_hov';
	}
//	else if($(prod_id).style.display == 'none')
	else if($(prod_id).className == 'product_fatcs_hov')
	{
//		$(prod_id).style.display = 'block';
		$(prod_id).className = 'product_fatcs';
	}
}

// registration
function christmas_validate(lang, action)
{
	the_form = document.forms.christmas;

	if(the_form.pname.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашето име!');
		}
		else
		{
			alert('Please enter your name!');
		}
		the_form.pname.focus();
		return;
	}

	if(the_form.pmail.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашият имейл адрес');
		}
		else
		{
			alert('Please enter your email address!');
		}
		the_form.pmail.focus();
		return;
	}

	if (!the_form.pmail.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес не е валиден');
		}
		else
		{
			alert('The email address is not valid!');
		}
		the_form.pmail.focus();
		return;
	}
	
	if(the_form.uname.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете вашето име!');
		}
		else
		{
			alert('Please enter your name!');
		}
		the_form.uname.focus();
		return;
	}

	if(the_form.umail.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля попълнете имейл адрес на получателя');
		}
		else
		{
			alert('Please enter recipient email address!');
		}
		the_form.umail.focus();
		return;
	}

	if (!the_form.umail.value.match(filter))
	{
		if(lang == 'bg')
		{
			alert('Въведеният имейл адрес на получателя не е валиден');
		}
		else
		{
			alert('The email address of recipient is not valid!');
		}
		the_form.umail.focus();
		return;
	}
	
	if(the_form.wishText.value == '')
	{
		if(lang == 'bg')
		{
			alert('Моля въведете поздравителен текст!');
		}
		else
		{
			alert('Please enter greetings text!');
		}
		the_form.wishText.focus();
		return;
	}

	if(action == 'submit') {
		the_form.submit();
	} else {
		var wishtxt = the_form.wishText.value;
		
		new Ajax.Updater('flash_container', 'christmas_card_flash.php', {
			method:'get',
			evalScripts:true,
			parameters: {'wishText' : wishtxt},
			onComplete: function(){
				
			}
		});
		
	}
}// end function

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else
	{
		cntfield.value = maxlimit - field.value.length;
	}
}

function checkLoginRights( lang, filename, is_logged )
{
	is_logged = 2;
	if( is_logged == null )
	{
		is_logged = 2;
		//is_logged = 0;
	}
	if ( is_logged == 2)
	{
		//window.location.href = 'http://jungle:443/kfc/' + lang + '/promo_login.php?file=' + filename;
		window.location.href = 'http://www.kfc.bg/' + lang + '/promo_login.php?file=' + filename;
		
	} else {
		if(lang == 'bg')
		{
			alert("Трябва да сте логнат, за да може да свалите този файл!");
		} else
		{
			alert('You must be logged in to download this file!');
		}
	}
}