function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true
}
function add_comment(pid, hash) {
	var old = $('#commentlist').html();
	if($('#username').val().length==0) {
	alert('Ошибка: Вы не указали свое имя!');
	return false;
	}
	if($('#usermail').val().length==0) {
	alert('Ошибка: Вы не указали свой E-mail!');
	return false;
	}
	if($('#usercomment').val().length==0) {
	alert('Ошибка: Вы не ввели комментарий!');
	return false;
	}
	if(!echeck($('#usermail').val())) {
	alert('Ошибка: Вы неверно указали свой E-mail!');
	return false;
	}
	var author = $('#username').val();
	var author_email = $('#usermail').val();
	var author_url = $('#usersite').val();
	var content = $('#usercomment').val();
	var info = '<div class="message-box comment-info">Ваш комментарий успешно добавлен и после проверки администратором появится здесь.</div>';
   	$('#commentlist').html('<center><img src="/images/template/loader.gif" alt="Загрузка"></center>' + old);
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT become responseJS).
            $('#commentlist').html(req.responseText + old);
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php', true);
    // Send data to backend.
    req.send( { action: 'comment_add', pid: pid, hash: hash, author: author, author_email: author_email, author_url: author_url, content: content } );
}
function rate(id, rating, table) {
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT become responseJS).
            document.getElementById('unit_long'+id+'').innerHTML = req.responseText;
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php', true);
    // Send data to backend.
    req.send( { id: id, rating: rating, table: table, action: 'rate' } );
}

function subscribe() {
    var email = $('#sub_mail').val();
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.
	$('#subscribe_info').show();
	$('#subscribe_info').html('<center><img src="/images/template/loader.gif" alt="Загрузка"></center>');
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT become responseJS).
            document.getElementById('subscribe_info').innerHTML = req.responseText;
			$('#subscribe_info').animate({opacity: 1.0}, 3000).hide("slow");
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php', true);
    // Send data to backend.
    req.send( { email: email, action: 'subscribe' } );
}
function unsubscribe() {
    var email = $('#sub_mail').val();
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.
	$('#subscribe_info').show();
	$('#subscribe_info').html('<center><img src="/images/template/loader.gif" alt="Загрузка"></center>');
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT become responseJS).
            document.getElementById('subscribe_info').innerHTML = req.responseText;
			$('#subscribe_info').animate({opacity: 1.0}, 3000).hide("slow");
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php', true);
    // Send data to backend.
    req.send( { email: email, action: 'unsubscribe' } );
}
/**
 *
 * @access public
 * @return void
 **/
function panel(id){
	for(var i=1; i<6; i++) {
	$('#panel_' + i).hide();
	$('#panel_' + id + '').show('fast');
	}
}
/**
 *
 * @access public
 * @return void
 **/
function  setmail() {
	$.cookie("shop_email", document.getElementById('shop_email').value, { path: '/shop', expires: 365 });
}