var Skillopedia_Material = new function()
{
/*	this.PasteOpen = false;
	this.PresentOpen = false;

    this.link = function(material)
    {
        email = prompt("Пожалуйста введите e-mail друга");

        if ( !email )
        {
            return;
        }

        JsHttpRequest.query(
            '/material/send_link.php',
            {
                'material': material,
                'reciptient': email
            },
            function(result, data)
            {
                if (result !== false)
                {
                    alert('Ссылка успешно отправлена');
                }
                else alert('Что-то не вышло');
            },
            false
        );
    }	
	
	this.showPaste = function()
	{
	    this.PasteOpen = true;
	
	    document.getElementById('blog-paste').style.display = 'block';
	}
	
	this.showPresent = function(user)
	{
	    if ( !User.ID )
	    {
	        alert('Пожалуйста войдите или зарегистрируйтесь');
	        return;
	    }
	    if ( user == User.ID )
	    {
	        alert('Это ваш урок');
	        return;
	    }
	
	    this.PresentOpen = true;
	
	    document.getElementById('present-money').style.display = 'block';
	}*/
	
	this.hide = function()
	{	
/*	    
	    if ( Material_Clouds.PasteOpen )
	    {
	        Material_Clouds.PasteOpen = false;
	
	        document.getElementById('present-money').style.display = 'none';
	
	        return;
	    }
	    else if ( Material_Clouds.PresentOpen )
	    {
	        Material_Clouds.PresentOpen = false;
	
	        document.getElementById('blog-paste').style.display = 'none';
	
	        return;
	    }
	
	    document.getElementById('present-money').style.display = 'none';
	    document.getElementById('blog-paste').style.display = 'none';
*/	    
	}
	
	this.postLJ = function(title)
	{
	    login    = document.getElementById('lj-user').value;
	    password = document.getElementById('lj-password').value;
	
	    if ( !login || !password )
	    {
	        alert('Пустые логин или пароль');
	        return;
	    }
	
	    data = document.getElementById('post-data').value;
	
	    JsHttpRequest.query(
	        '/material/poster/lj.php',
	        {
	            'login': login,
	            'password': password,
	            'data': data,
	            'title': title
	        },
	        function(result, data)
	        {
	            if ( result != 0 )
	            {
	                if ( result.faultCode == 100 )
	                {
	                    alert('Пользователь не найден');
	                }
	                else if ( result.faultCode == 101 )
	                {
	                    alert('Пароль не подошёл');
	                }
	                else if ( result.faultCode == 402 )
	                {
	                    alert('Слишком много попыток, придётся немного подождать');
	                }
	                else
	                {
	                    alert('Ошибка ЖЖ:'+result.faultString);
	                }
	            }
	            else alert('Успешно размещено в вашем ЖЖ');
	        },
	        false
	    );
	}
	
	this.showPresent = function()
	{
	    document.getElementById('pay').style.display = 'block';
	    document.getElementById('pay-cancel').style.display = 'block';
	    document.getElementById('pay-submit').style.display = 'none';
	}
	
	this.hidePresent = function()
	{
	    document.getElementById('pay').style.display = 'none';
	    document.getElementById('pay-cancel').style.display = 'none';
	    document.getElementById('pay-submit').style.display = 'block';
	}
	
	this.payPresent = function(to)
	{
	    JsHttpRequest.query(
	        '/material/present.php',
	        {
	            'id': to,
	            'fund': document.getElementById('present').value
	        },
	        function(result, data)
	        {
	            if (result === false)
	            {
	                alert(data);
	
	                return;
	            }
	
	            alert('Деньги успешно перечислены');
	            
	            document.getElementById('present').value = '';
	            
	            Skillopedia_Material.hidePresent();
	        },
	        true
	    );
	}   
	
	this.switchInvite = function(section, material)
	{
	    JsHttpRequest.query(
	        '/material/invite.php',
	        {
	            'section': section,
	            'material': material
	        },
	        function(result, data)
	        {
	            document.getElementById('invites').innerHTML = result;
	        },
	        true
	    );
	}
	
	this.markInvites = function(value)
	{
	    var i = 0;
	    var element = null;
	    
	    while ( element = document.getElementById('invite-'+i) )
	    {
	        element.checked = value;
	        
	        i++;
	    }
	}
	
	this.loginGmail = function()
	{
	    var l = document.getElementById('glogin');
	    var p = document.getElementById('gpass');
	    
	    if ( !l.value )
	    {
	        l.style.border = '1px solid red';
	        
	        return;
	    }
	    else 
	    {
	        l.style.border = '1px solid gray';
	    }
	    
	    if ( !p.value )
	    {
	        p.style.border = '1px solid red';
	        
	        return;
	    }
	    else 
	    {
	        p.style.border = '1px solid gray';
	    }
	    
	    var data = document.getElementById('gmail');
	    
	    JsHttpRequest.query(
	        '/material/invite/gmail_login.php',
	        {
	            'data': data
	        },
	        function(result, data)
	        {
	            if ( result )
	            {
	               document.getElementById('invites').innerHTML = result;
	            }
	            else
	            {
	                l.style.border = '1px solid red';
	                p.style.border = '1px solid red';
	            }
	        },
	        true
	    );
	}
	
	this.loginVkontakte = function()
	{
	    var l = document.getElementById('vlogin');
	    var p = document.getElementById('vpass');
	    
	    if ( !l.value )
	    {
	        l.style.border = '1px solid red';
	        
	        return;
	    }
	    else 
	    {
	        l.style.border = '1px solid gray';
	    }
	    
	    if ( !p.value )
	    {
	        p.style.border = '1px solid red';
	        
	        return;
	    }
	    else 
	    {
	        p.style.border = '1px solid gray';
	    }
	    
	    data = document.getElementById('vkontakte');
	    
	    JsHttpRequest.query(
	        '/material/invite/vkontakte_login.php',
	        {
	            'data': data
	        },
	        function(result, data)
	        {
	            if ( result )
	            {
	               document.getElementById('invites').innerHTML = result;
	            }
	            else
	            {
	                l.style.border = '1px solid red';
	                p.style.border = '1px solid red';
	            }
	        },
	        true
	    );
	}
	
	this.invite = function(id, section)
	{
	    if ( !section )
	    {
    	    inv = document.getElementById('invitations');
    	    
    	    if ( !inv.value )
    	    {
    	        alert('Пожалуйста введите адреса друзей');
    	        return;
    	    }
	    }
	    
        document.getElementById('send-invites').style.display = 'none';
        document.getElementById('send-invites-wait').style.display = 'block';
	    
	    JsHttpRequest.query(
	        '/material/invite/emails_send.php',
	        {
	            'id': id,
	            'section': section,
	            'data': inv.value
	        },
	        function(result, data)
	        {
	            if ( result )
	            {
	               alert('Отправлено писем: '+result);
	               inv.value = '';
	            }
	            
                document.getElementById('send-invites').style.display = 'block';
                document.getElementById('send-invites-wait').style.display = 'none';
	        },
	        true
	    );
	}
	
	this.inviteGmail = function(id, section)
	{    
        var data = document.getElementById('gmail');
	    
	    JsHttpRequest.query(
	        '/material/invite/gmail_send.php',
	        {
	            'data': data
	        },
	        function(result, data)
	        {
	            if ( result )
	            {
	               alert('Отправлено писем: '+result);
	               inv.value = '';
	            }
	        },
	        true
	    );
	}

	this.inviteVkontakte = function(id, section)
	{    
        var data = document.getElementById('vkontakte');
	    
	    JsHttpRequest.query(
	        '/material/invite/vkontakte_send.php',
	        {
	            'data': data
	        },
	        function(result, data)
	        {
	            alert(data);
	            
	            if ( result )
	            {
	               alert('Отправлено писем: '+result);
	               inv.value = '';
	            }
	        },
	        true
	    );
	}
	
	
	this.showSameAuthor = function()
	{
	    document.getElementById('same_category_title').style.display = 'none';
	    document.getElementById('same_author_title').style.display = 'block';
	    document.getElementById('same_category').style.display = 'none';
	    document.getElementById('same_author').style.display = 'block';
	}
	
	this.showSameCategory = function()
	{
	    document.getElementById('same_category_title').style.display = 'block';
	    document.getElementById('same_author_title').style.display = 'none';
	    document.getElementById('same_category').style.display = 'block';
	    document.getElementById('same_author').style.display = 'none';
	}	

	document.getElementById('body').onclick = this.hide;
}

