/**
 * @author     Wynn Chen <wynn.chen.cn@gmail.com>
 * @version    $Id: common.js 277 2009-09-25 01:34:09Z bob $
 */

window.addEvent('domready', function() {
	pmform = new Element('form', {
			'action': '/pm-send/job-frombox/',
			'method': 'post',
			'id': 'pm_form_'
		}).adopt(
			new Element('h1', {'text': '短消息'}),
			msg = new Element('p'),
			new Element('div').adopt( 
				new Element('label', {'text': '发送给:', 'for': 'pmusername'}),
				new Element('input', {'name': 'pmusername', 'id': 'pmusername'})
			),
			new Element('div').adopt(
				new Element('label', {'text': '　标题:', 'for': 'pmtitle'}),
				new Element('input', {'name': 'pmtitle', 'id': 'pmtitle'})
			),
			new Element('div').adopt(
				new Element('label', {'text': '　内容:', 'for': 'pmcontent'}),
				new Element('textarea', {'name': 'pmcontent', 'id': 'pmcontent'})
			),
			
			new Element('div').adopt(
				
				new Element('input', {'type': 'submit', 'value': '发送', 'class': 'input_submit__'})
			)
		).set('send', {
			onComplete: function(result){
				result = JSON.decode(result);
				if(result !== true){
					msg.error(result);
				}
				else{
					msg.success('短消息发送成功!');
					pmform.reset();
					(function(){window.location.reload();}).delay(1500);
				}
			}
		}).addEvent('submit', function(e){
			e.stop();
			this.send();
		});
		$extend(msg.set('slide', {duration: 'short', transition: 'linear'}).slide('hide'), {
			error : function(text){
				this.addClass('error').set('text', text).slide('in');
				return this;
			},
			success : function(text){
				this.addClass('success').set('text', text).slide('in');
				return this;
			},
			cleanup : function(text){
				this.erase('text').slide('out');
				return this;
			}
		});
		
		pmBox = new Box({
			title: '短消息',
			content: pmform,
			height:350
		});
		
	$$('.pmanchor a').forEach(function(item){
		item.addEvent('click',function(e){
			e.stop();
			$('pmusername').value = item.title;
			pmBox.show();
		})
	});	
		
		
	if(loginLink = $('login_link')){
		form = new Element('form', {
			'action': '/user-login/',
			'method': 'post',
			'id': 'login_form_'
		}).adopt(
			new Element('h1', {'text': '会员登录'}),
			msg = new Element('p'),
			new Element('div').adopt( 
				new Element('label', {'text': '用户名:', 'for': 'username'}),
				new Element('input', {'name': 'username', 'id': 'username'})
			),
			new Element('div').adopt(
				new Element('label', {'text': '　密码:', 'for': 'password'}),
				new Element('input', {'name': 'password', 'id': 'password', 'type': 'password'})
			),
			new Element('div').adopt(
				new Element('input', {'name': 'auto', 'type': 'checkbox', 'value': '1', 'checked': 'checked', 'id': 'auto_login', 'class': 'input_checkbox__'}),
				new Element('label', {'text': '以后自动登录', 'for': 'auto_login'})
			),
			new Element('div').adopt(
				new Element('input', {'name': 'mode', 'type': 'hidden', 'value': 'remote'}),
				new Element('input', {'type': 'submit', 'value': '登录', 'class': 'input_submit__'})
			),
			new Element('div', {'class': 'no_account'}).adopt(
//				new Element('a', {'href': 'hidden', 'text': '忘记密码？', 'class': 'login_form_link'}),
				new Element('a', {'href': '/user-register/?forward='+location.href, 'text': '没有账号？', 'class': 'login_form_link'})
			)
		).set('send', {
			onComplete: function(result){
				result = JSON.decode(result);
				if(result !== true){
					msg.error(result);
				}
				else{
					window.location.reload();
				}
			}
		}).addEvent('submit', function(e){
			e.stop();
			this.send();
		});
		$extend(msg.set('slide', {duration: 'short', transition: 'linear'}).slide('hide'), {
			error : function(text){
				this.addClass('error').set('text', text).slide('in');
				return this;
			},
			success : function(text){
				this.addClass('success').set('text', text).slide('in');
				return this;
			},
			cleanup : function(text){
				this.erase('text').slide('out');
				return this;
			}
		});
		
		loginBox = new Box({
			title: '会员登录',
			content: form
		});
		
		loginLink.addEvent('click', function(e){
			e.stop();
			loginBox.show();
		});
	}
	

});
function showPmForm(to)
{
	$('pmusername').value = to;
	pmBox.show();

}

