	$(document).ready(function(){
		setoverlay();
		$('#cnt1').click(function(){
			//if ($('#cnt1in iframe').length<1){
				$('#cnt1in').html('<iframe src="http://piala.rglservice.kz/activate_kz.php?'+Math.random()+'" frameborder="0"></iframe>');
			//}
			$('#cnt1in').show();
			$('#cnt2in').hide();
			$('#cnt1').addClass('curr');
			$('#cnt2').removeClass('curr');
		});
		$('#cnt2').click(function(){
			//if ($('#cnt2in iframe').length<1){
				$('#cnt2in').html('<iframe src="http://piala.rglservice.kz/activate_kg.php?'+Math.random()+'" frameborder="0"></iframe>');
			//}
			$('#cnt1in').hide();
			$('#cnt2in').show();
			$('#cnt2').addClass('curr');
			$('#cnt1').removeClass('curr');
		});
		$('#button, .regbutton').click(function(){
			$('#overlay').fadeTo(300, 0.75);
			$('#overlaybox').fadeIn(800);
			$('#cnt1').click();
		});
		$('#close, #overlay').click(function(){
			$('#overlay').fadeOut(300);
			$('#overlaybox').fadeOut(500);
		});
		$('.faqtoggle').click(function(){
			tid = $(this).attr('toid');
			if ($(this).hasClass('faqtoggled')) {
				$('#'+tid).slideUp(300);
				$(this).removeClass('faqtoggled');
			}else{
				$('.faqtoggle').removeClass('faqtoggled');
				$('.faqhide').slideUp(300);
				$('#'+tid).slideDown(300);
				$(this).addClass('faqtoggled');
			}
		});
		$('.inputbox input.tx').focus(function(){
			if ($(this).val()==this.defaultValue && !$(this).hasClass('normal')){
				$(this).val('');
				$(this).addClass('normal');
			}
		});
		$('.inputbox input.tx').blur(function(){
			if ($(this).val()==''){
				$(this).val(this.defaultValue);
				$(this).removeClass('normal');
			}
		});
		$('.inputbox input.pw').focus(function(){
			if ($(this).val()==this.defaultValue){
				$(this).val('');
				this.type = 'password';
				$(this).addClass('normal');
			}
		});
		$('.inputbox input.pw').blur(function(){
			if ($(this).val()==''){
				$(this).val(this.defaultValue);
				this.type = 'text';
				$(this).removeClass('normal');
			}
		});
		$('.inputbox inpur.pw').keyup(function(){
			if ($('#cpass').length) {
				if ($('#pass').val()!=$('#cpass').val()){
					$('#passerr').html('<b>Пароль и подтверждение пароля не совпадают</b>');
				}else{
					$('#passerr').html('OK');
				}
			}
		});
		$('#reg').submit(function(){
			$('#t_err').html('');
			if ($('#i_login').val() == '' || $('#i_login').val() == 'Логин') {
				$('#t_err').html('Введите логин<br/>');
				return false;
			}
			if ($('#i_title').val() == '' || $('#i_title').val() == 'Ваше настоящее имя') {
				$('#t_err').html('Введите имя<br/>');
				return false;
			}
			if ($('#i_phone').val() == '' || $('#i_phone').val() == 'Контактный телефон') {
				$('#t_err').html('Введите телефон<br/>');
				return false;
			}
			if (!isValidEmailAddress($('#i_email').val())) {
				$('#t_err').html('Неверно введён email<br/>');
				return false;
			}
			if ($('#pass').val() == '' || $('#pass').val()!=$('#cpass').val()) {
				$('#t_err').html('Введите пароль<br/>');
				return false;
			}
		});
	});
	$(document).resize(function(){setoverlay();});
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	};
	function setoverlay(){
		$('#overlay').width($(document).width());
		$('#overlay').height($(document).height());
	}
