function doSub() {
	$().ready(function(){
		$("#subForm").validate({
			submitHandler: function() {
				formSubmit(document.getElementById('subForm'));
			},
			rules : {
				eml: {email: true }
			},
			messages : {
				eml: "Некорректный email"
			}
		});
	});
}
function formSubmit(){
	openAjaxPopup('/subscribe.php?action=subscribe&email='+document.getElementById('eml').value, 300);
	return false;
}
$.setupJMPopups({
	screenLockerBackground: "#e6e6e6",
	screenLockerOpacity: "0.7"
});

function openAjaxPopup(urlc, width) {
	$.openPopupLayer({
		name: "mySecondPopup",
		width: width,
		url: urlc
	});
}
function openStaticPopup() {
	$.openPopupLayer({
		name: "myStaticPopup",
		width: 250,
		target: "myHiddenDiv"
	});
}

function doSend(){
	document.getElementById('error').innerHTML = '';
	var body_mes = document.getElementById('body_mes').value.replace(/(^\s*)|(\s*$)/g, "") ;
	if ( body_mes == '' || body_mes.length<15 ){
		document.getElementById('error').innerHTML = 'Нечего отправлять!';
		return false;
	}
	if ( body_mes.length>1024 ){
		document.getElementById('error').innerHTML = 'Слишком большое сообщение!';
		return false;
	}
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if ( req.responseJS.error != ''  ){
				document.getElementById('error').innerHTML = req.responseJS.error;
			}
			else{
				document.getElementById('result').innerHTML = req.responseJS.result;
			}
		}
	}
	req.open('post', '/send.php', false);
	req.send( { q: document.getElementById('f') } );
}
function personal(){
    document.getElementById('error').innerHTML = '';
    var _user = document.getElementById('rcmloginuser').value.replace(/(^\s*)|(\s*$)/g, "") ;
    var _pass = document.getElementById('rcmloginpwd').value.replace(/(^\s*)|(\s*$)/g, "") ;
    if ( _user == '' || _pass== '' ){
        document.getElementById('error').innerHTML = 'Введите имя и пароль';
        return false;
    }

    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if ( req.responseJS.error != ''  ){
                document.getElementById('error').innerHTML = 'Неверная связка имя/пароль ';
                return false;
            }
            else{
                document.pf.submit();
            }

        }
    }
    req.open('post', '/check.php', false);
    req.send( { q: document.getElementById('pf') } );
}

