var generalcheckUrl	= 'http://www.168software.com/check';
function getDwSize() {
	return {
		dHeight   : $(document).height(),
		wWidth    : $(window).width(),
		wHeight   : $(window).height(),
		wScrollTop: $(window).scrollTop()
	};
}

;(function($) {
	$.fn.extend({
		p: function() {
			var olStyle = 'filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity:0.5;';
			olStyle += ' position:absolute; background:gray; top:0; left:0; z-index:1000; display:none';
			
			if ($('#ol').length > 0) {
				$('#ol').remove();
			}
			
			$('body').append($('<div id="ol" style="' + olStyle + '"></div>'));

			var $p = this, $pHide = $('.pHide', this), $ol = $('#ol'), s = getDwSize();
			
			$ol.css({
				height: s.dHeight,
				width : s.wWidth
			}).show();
			
			$p.css({
				top     : s.wScrollTop + (s.wHeight - $p.height()) / 2,
				left    : (s.wWidth - $p.width()) / 2,
				position: 'absolute',
				zIndex  : 1001
			}).show();
			
			function scrollResize(){
				var s = getDwSize();

				$p.stop(true, false).animate({
					top : s.wScrollTop + (s.wHeight - $p.height()) / 2,
					left: (s.wWidth - $p.width()) / 2
				});
			}
			
			$(window).scroll(function(){
				scrollResize();
			}).resize(function(){
				scrollResize();
			});
			
			$pHide.click(function() {
				$p.hide();
				$ol.remove();
			});
		}
	});
})(jQuery);

$(function() {
	$('#loginclk').click(function() {
		$('#logpop').p();
	});
});

/** QQ登录 **/
var childWindow;
/*function toQzoneLogin()
{
	childWindow = window.open("http://www.168software.com/multilogin/qq?callback=","TencentLogin","width=450,height=320,menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
}*/
function toQzoneLogin()
{
	var $back	= arguments[0];
	var $tourl  = '';
	
	if($back === undefined){
		$back = '';
	}else{
		if($back == 'tgmweb'){
			$tourl = 'http://www.168software.com/tgm/tgmweb.php';
		}
		if($back.indexOf('http://') != -1){
			$tourl = $back;
		}
	}
	
	childWindow = window.open("http://www.168software.com/multilogin/qq?callback=&tourl="+$tourl,"TencentLogin","width=450,height=320,menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
	
}
function QQCallback(url)
{
	childWindow.close();
	window.location.href=url;
}

//用户登录验证
function formcheck()
{
	$type	= arguments[0];

	if ($type=='poplog')
	{
		var $popusername	= $.trim($("#popupusername").val());
		var $poppassword	= $("#popuppassword").val();
		var $popcode		= $("#popupcode").val();

		if ($popusername=='')
		{
			$("#popup_form_msg").text("账户不能为空").show();
			return false;
		}

		if ($poppassword=='')
		{
			$("#popup_form_msg").text("密码不能为空").show();
			return false;
		}

		if ($popcode == '')
		{
			$("#popup_form_msg").text("验证码不能为空").show();
			return false;
		}
	}
	else if ($type=='log')
	{
		var $username	= $.trim($("#username").val());
		var $password	= $("#password").val();
		var $code		= $("#code").val();

		if ($username=='')
		{
			$("#form_msg").text("账户不能为空").show();
			return false;
		}

		if ($password=='')
		{
			$("#form_msg").text("密码不能为空").show();
			return false;
		}

		if ($code == '')
		{
			$("#form_msg").text("验证码不能为空").show();
			return false;
		}
	}
	else
	{
		return false;
	}

	return true;
}

//邮箱修改验证
function checkform()
{
	var temparg		= arguments[0] ? arguments[0] : '';
	var emailRegStr = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
	var emailReg	= new RegExp(emailRegStr);

	if (temparg=='email')
	{
		var email = $('#email').val();
		if(email.search(emailReg) == -1)
		{
			//alert('邮箱地址格式必须为xxx@xxx.xxx，且不能为空');
			return false;
		}
		return true;
	}
	else if (temparg=='pwd')
	{
		var pwd = $('#pwd').val();
		if(pwd == "")
		{
			//alert('请输入密码');
			return false;
		}
		return true;
	}
	else
	{
		var pwd		= $('#pwd').val();
		var email	= $('#email').val();
		var send_ok = false;

		if(email.search(emailReg) == -1)
		{
			alert('邮箱地址格式必须为xxx@xxx.xxx，且不能为空');
			return false;
		}

		if(pwd == "")
		{
			alert('请输入密码');
			return false;
		}
		
		return true;
	}
}

//更换验证码
function newverifypic()
{
	$tempurl	= arguments[0];
	$tempid		= arguments[1];
	var timenow = new Date().getTime();
	$tempurl += timenow;
	document.getElementById($tempid).src=$tempurl;
}
