﻿// 退出登录确认
function do_logout()
{
	return confirm('您确定要退出此次登录吗？') ? true : false;
}

// 清空确认
function do_reset() {
	return confirm('您确定要清空吗？') ? true : false;
}

// 取消确认
function do_cancel() {
	return confirm('您确定要取消此次操作吗？') ? true : false;
}

// 删除确认
function do_delete() {
	return confirm('您确定要删除吗？') ? true : false;
}


// 窗口响应方式
$('a[rel="external"]').attr('target', '_blank');
$('a[rel="main"]').attr('target', 'main');
$('a[rel="_top"]').attr('target', '_top');
$('a[rel="_self"]').attr('target', '_self');
$('a[rel="_parent"]').attr('target', '_parent');

$(function() {
	// 退出登录确认
	$('.logout').click(function() {
		return do_logout();				   
	});
	
	// 清空表单确认
	$('.reset').click(function() {
		return do_reset();				   
	});
	
	// 取消操作确认
	$('.cancel').click(function() {
		return do_cancel();				   
	});
	
	// 删除确认
	$('.delete').click(function() {
		return do_delete();				   
	});
	
	// 返回上一页
	$('.back').click(function() {
		window.history.back();
	});
	
	// 关闭本页
	$('.close').click(function() {
		window.close();
	});
	
	// 分页跳转检查
	$('.turnpage').click(function() {
		if($('#page').val() == '') {
			alert('请输入您要转到的页数');
			$('#page').focus();
			return false;
		}
		var re = /^[0-9]{1,6}$/;
		if(!re.exec($('#page').val())) {
			alert('页码必须是6位长度以下的数字');
			$('#page').select();
			return false;
		} 
	});
	
	// 切换验证码
	$('.checkcode').click(function() {
		$(this).attr('src', '/include/image.aspx?' + Math.random());
		return false;
	});
	
	// 主导航栏搜索检查
	$('.search').click(function() {
		var keywords = $('.keywords').val();
		if(keywords == '') {
			alert('请输入产品关键字。');
			$('.keywords').focus();
			return false;
		}
		
		if(keywords == '请输入产品关键字') {
			alert('请输入产品关键字。');
			$('.keywords').select();
			return false;
		}
	});
	
	// 用户登录获取焦点
	$('.user').focus(function() {
		$(this).attr('class', 'user_focus');
	});
	$('.user').blur(function() {
		$(this).attr('class', 'user');
	});
	
	$('.passwd').focus(function() {
		$(this).attr('class', 'passwd_focus');
	});
	$('.passwd').blur(function() {
		$(this).attr('class', 'passwd');
	});
	
	$('.check_code').focus(function() {
		$(this).attr('class', 'check_code_focus');
	});
	$('.check_code').blur(function() {
		$(this).attr('class', 'check_code');
	});
	
	// 主导航中搜索栏获取焦点
	$('.keywords').focus(function() {
		$(this).attr('class', 'keywords_focus');
	});
	$('.keywords').blur(function() {
		$(this).attr('class', 'keywords');
	});
	
	// 登录检查
	$('.submit_login').click(function() {
		var user = $('.user').val();
		var passwd = $('.passwd').val();
		var check_code = $('.check_code').val();
		if(user == '')
		{
			alert('用户名不能为空，请输入。');
			$('.user').focus();
			return false;
		}
		
		if(user != '')
		{
			if(user.length < 4 || user.length > 20)
			{
				alert('用户名的长度不合法，请输入。');
				$('.user').select();
				return false;
			}
		}
		
		if(passwd == '')
		{
			alert('密码不能为空，请输入。');
			$('.passwd').focus();
			return false;
		}
		
		if(passwd != '')
		{
			if(passwd.length < 4 || passwd.length > 20)
			{
				alert('密码的长度不合法，请输入。');
				$('.passwd').select();
				return false;
			}
		}

		if(check_code == '')
		{
			alert('验证码不能为空，请输入。');
			$('.check_code').focus();
			return false;
		}
	});
	
	// 根据勾选的用户级别分别转向个人注册和商家注册页面
	$('.newregister').click(function() {
		if($('#user_type1')[0].checked == true){
			window.location.href = $(this).attr('href');
		} else {
			$(this).attr('href', '#');
			window.location.href = '/user/register.aspx';
		}
	});
	$('.get_pwd').click(function() {
		if($('#user_type1')[0].checked == true){
			window.location.href = $(this).attr('href');
		} else {
			$(this).attr('href', '#');
			window.location.href = '/user/getpassword.aspx';
		}
	});
	
	// 根据勾选的用户级别分别转向个人登录和商家登录页面
	$('.submit_login').click(function() {
		if($('#user_type1')[0].checked != true){
			$('#login_form').attr('action', '/useradmin/deallogin.aspx');
		}
	});
	// 新闻搜索检查
	$('.news_search').click(function() {
		var news_key = $('.news_key').val();
		if(news_key == '') {
			alert('请输入新闻搜索关键字。');
			$('.news_key').focus();
			return false;
		}
	});
	
	// 添加到收藏夹
	$('.addfav').click(function() {
		AddFavorite(window.document.title, window.location.href)
	});
	
	// 设为首页
	$('.sethome').click(function() {
		SetHomepage(window.location.href)
	});
});