if (typeof Main == 'undefined') {
	Main = function() {
	};
}

Main.Content = function(options) {
	this.action = '';
	this.controller = '';
	this.init(options);
};

Main.Content.prototype.init = function(options) {
	for ( var i in options)
		this[i] = options[i];
};

Main.Content.prototype.submitGost = function( menu_id ) {
	$('#error_name').html();
	$('#error_email').html();
	$('#error_message').html();
	$('#error_captcha').html();
	$('#error_db').html();
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/submitGost/',
		   data: $('#gost_form').serialize(),
		   dataType: 'json',
		   success: function(data) {
				if ( data.error.name != undefined || data.error.email != undefined || data.error.message != undefined || data.error.captcha != undefined || data.error.db != undefined ) {
					if ( data.error.name != undefined )
						$('#error_name').html(data.error.name);
					if ( data.error.email != undefined )
						$('#error_email').html(data.error.email);
					if ( data.error.message != undefined )
						$('#error_message').html(data.error.message);
					if ( data.error.captcha != undefined )
						$('#error_captcha').html(data.error.captcha);
					if ( data.error.db != undefined )
						$('#error_db').html(data.error.db);
				}
				else
					obSelf.listGost( menu_id );
		   }
	});
};

Main.Content.prototype.listGost = function( menu_id ) {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/listGost/',
		   data: 'menu_id=' + menu_id,
		   dataType: 'html',
		   success: function(data) {
				$('#gost_div').html(data);
		   }
	});
};

Main.Content.prototype.listDocs = function( menu_id ) {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/listDocs/',
		   data: 'menu_id=' + menu_id,
		   dataType: 'html',
		   success: function(data) {
				$('#docs_div').html(data);
		   }
	});
};

Main.Content.prototype.listGaler = function( menu_id ) {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/listGaler/',
		   data: 'menu_id=' + menu_id,
		   dataType: 'html',
		   success: function(data) {
				$('#galer_div').html(data);
		   }
	});
};

Main.Content.prototype.sendMes = function() {
	var obSelf = this;
	$.ajax({
		type: "POST",
		data: $("#mail_form").serialize(),
		url: "/main/send_mail/rand/" + Math.random(),
		dataType: 'json',
		success: function( data ){
			if ( data.error )
    			alert( data.error );
			else if ( data.success )
    			alert( data.success );
		},
		error: function(){
			alert("Проблемы с отправкой почты...");
		}
	});
};

Main.Content.prototype.loadHomeNews = function() {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/loadListNews/',
		   dataType: 'html',
		   success: function(data) {
				$('#list_news').html(data);
		   }
	});
};

Main.Content.prototype.loadListNews = function( menu_id ) {
	var obSelf = this;
	$.ajax({
			type : "POST",
			data: 'menu_id=' + menu_id,
			url: '/main/loadListNews/',
		   dataType: 'html',
		   success: function(data) {
				$('#list_news').html(data);
		   }
	});
};

Main.Content.prototype.showFormRestorePass = function() {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/restorePassDiv/',
		   dataType: 'html',
		   success: function(data) {
				$('#popup').html(data);
				$('#popup').togglePopup();
				$('#popup_bug').show('slow');
		   }
	});
};

Main.Content.prototype.restorePass = function() {
	var obSelf = this;
	$.ajax({
			type : "POST",
			data: $('#form_restor').serialize(),
			url: '/main/restorePass/',
		   dataType: 'html',
		   success: function(data) {
				obSelf.messageUI(data);
		   }
	});
};

Main.Content.prototype.loginExist = function() {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/loginExist/',
		   data: 'login=' + $('#parentForm input#login').val(),
		   dataType: 'html',
		   success: function(data) {
				if ( data == 1 ) {
					$('#parentForm #loginexist_t').html('<font color="red">' + merrors['loginexist'] + '</font>');
					error = true;
				}
		   }
	});
};

Main.Content.prototype.submitPass = function() {
	var obSelf = this;
	$.ajax({
			type : "POST",
			url: '/main/submitPass/',
		   data: $('#form_restore').serialize(),
		   dataType: 'html',
		   success: function(data) {
				if ( data == 1 ){
					document.location = '/';
					obSelf.messageUI('Пароль был изменён');
				}
				else
					obSelf.messageUI(data);
		   }
	});
};

Main.Content.prototype.messageUI = function( mesag ) {
	$.blockUI({ 
		message: mesag,
		css: {
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5,
        color: '#fff'
    } }); 
	setTimeout($.unblockUI, 2000);
};

