// 基本信息检测，异步
function check(act){

	url = 'userinfo_ajax.php?action=check' + act + '&' + act + '=' + $.trim($('#' + act).val());
	$.get(url, function(result){
		if(result != 'succeed'){
			$('#check'+ act).html('<img src="images/userinfo/check_error.gif"> ' + result);
		} else {
			$('#check' + act).html('');
		}});
}

// 表单提交检测
function formsubmit(act){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=check' + act + '&' + act + '=' + $.trim($('#' + act).val());

	check = ajax_submit(act, url, data);

	return check;
}

// 表单ajax提交，同步
function ajax_submit(act, ajax_url, ajax_data){

	var issuccess;
	$.ajax({
		url     : ajax_url,
		data    : ajax_data,
		async   : false,
		success : function(result){
			if(result != 'succeed'){
				$('#check'+ act).html('<img src="images/userinfo/check_error.gif"> ' + result);
				issuccess = 0;
			} else{
				$('#check' + act).html('');
				issuccess = 1;
			}
		}
	});

	return issuccess;
}

// 检测旧密码
function check_old_password(id){

	var check=1;
	var oldpassword = $("#oldpassword").val();
	var password    = $("#password").val();
	var password2   = $("#password2").val();

	if( oldpassword || password || password2 ){
		var url  = 'userinfo_ajax.php';
		var data = 'action=checkoldpassword&oldpassword=' + $("#oldpassword").val() + '&id=' + id;

		check = ajax_submit('oldpassword', url, data);
	}

	return check;
}

// 检查二次输入的密码
function check_pwd_again(obj1, obj2){
	var pwd1 = $("#" + obj1).val();
	var pwd2 = $("#" + obj2).val();
	var issuccess;

	if( pwd1 != pwd2 ){
		$("#check" + obj2).html('<img src="images/userinfo/check_error.gif"> 二次输入的密码不一致！');
		issuccess = 0;
	} else {
		$("#check" + obj2).html('');
		issuccess = 1;
	}

	return issuccess;
}

// 检测联系方式
function check_relation(mobile, phone){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=checkrelation&mobile=' + $.trim($("#" + mobile).val()) + '&phone=' + $.trim($("#" + phone).val());

	check = ajax_submit('relation', url, data);

	return check;
}

// 检查email是否合法
function check_email(obj){
	var email = $.trim($("#" + obj).val());

	illegalemail = !(/^[\-\.\w]+@[\.\-\w]+(\.\w+)+$/.test(email));

	if( illegalemail ){
		alert('Email不合法，请重新输入！');
		$("#" + obj).focus();
		return false;
	}
}

// checkbox全选
function select_all(name, id){

	$("input[@name='" + name + "']").each(function() {
		if( $("#" + id).attr('checked') == true )
        	$(this).attr("checked", true);
        else
        	$(this).attr("checked", false);
    });
}

// 批量取消
function cancel_all(name, form){
	var isselect;

	$("input[@name='" + name + "']").each(function() {
		if( $(this).attr('checked') == true ){

			if( confirm('是否确认取消？') ){
				$("#type").val('cancel_all');
				$('#' + form).submit();
			}

			isselect = true;
			return false;
		}
    });

    if( isselect != true )
    	alert('请选择要取消项！');
    return;
}

// 批量删除
function delete_all(name, form){
	var isselect;

	$("input[@name='" + name + "']").each(function() {
		if( $(this).attr('checked') == true ){

			if( confirm('是否确认删除？') ){
				$("#type").val('delete_all');
				$('#' + form).submit();
			}

			isselect = true;
			return false;
		}
    });

    if( isselect != true )
    	alert('请选择要删除项！');
    return;
}

// 区域变灰
function block_show(id, show){
	$("#" + id).css({display: show});
}

//个人中心的好友推荐
function friends()
{
	url = 'ajax_my.php?type=1';
	$.get(url, function(result)
	{
		$('#friendinfo').html(result);
	}
	);
}

//个人中心的博客评论
function blogcomments(uid,username,regdate)
{
	url = 'ajax_my.php?type=2&uid='+uid+'&username='+username+"&regdate="+regdate;
	$.get(url, function(result)
	{
		$('#blogcomment').html(result);
	}
	);
}

//个人中心的关注面板
function userpanels(uid,username,blog_dir,housenum)
{
	url = 'ajax_my.php?type=3&uid='+uid+'&username='+username+'&house_num='+housenum+'&blog_dir='+blog_dir;
	$.get(url, function(result)
	{
		$('#userpanel').html(result);
	}
	);
}

// 返回
function goto_url(url){

	window.top.location = url;
}

// 登录判断
function login_submit(type, user, pwd){

	var check;

	$.ajax({
		url     : 'userinfo_ajax.php',
		data    : 'action=checklogin&login_type=' + type + '&user=' + user + '&pwd=' + pwd,
		async   : false,
		success : function(result){
			if(result != 'succeed'){
				$('#checklogin').html("<font color='red'>" + result + "</font>");
				check = 0;
			} else{
				$('#checklogin').html('');
				check = 1;
			}
		}
	});

	return check;
}

// 判断是否有选中的
function is_select(name){

	var isselect = false;

	$("input[@name='" + name + "']").each(function(){
		if( $(this).attr("checked") == true )
			isselect = true;
	});

	return isselect;
}

// 检测绑定卡
function checkbindcard(cardid, password){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=checkbindcard&cardid=' + cardid + '&password=' + password;

	check = ajax_submit('bindcard', url, data);

	return check;
}

// 检测绑定用户
function checkbinduser(username, password){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=checkbinduser&username=' + username + '&password=' + password;

	check = ajax_submit('binduser', url, data);

	return check;
}

// thickbox弹层
function thickbox_pop_show(url) {
	document.write('');

	window.location.replace(url);

	return;
//	$(this).attr("href", url);
//
//	var t = this.title || this.name || null;
//	var a = this.href || this.alt;
//	var g = this.rel || false;
//
//	tb_show(t,a,g);
//	$(this).blur();
//	return false;
}

// 修改收货地址
function update_address(id, cardid, uid, address_id){

	url = 'userinfo_ajax.php?action=update_address&cardid=' + cardid + '&uid=' + uid + '&address_id=' + address_id;
	$.get(url, function(result){
		$('#' + id).html(result);
	});
}

// 修改某件商品总价
function update_product_cast(id, cast, number){

	url = 'userinfo_ajax.php?action=update_pcast&cast=' + cast + '&number=' + number;
	$.get(url, function(result){
		$('#' + id).html('￥'+ result);
	});
}

// 异步检测商城省市
function check_shop_city(){

	url = 'userinfo_ajax.php?action=checkshop_city&city_id=' + $.trim($('#city_id').val()) + '&area_id=' + $.trim($('#area_id').val());
	$.get(url, function(result){
		if(result != 'succeed'){
			$('#checkcity_id').html('<img src="images/userinfo/check_error.gif"> ' + result);
		} else {
			$('#checkcity_id').html('');
		}});
}

// 同步步检测商城省市
function async_check_shop_city(){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=checkshop_city&city_id=' + $.trim($('#city_id').val()) + '&area_id=' + $.trim($('#area_id').val());

	check = ajax_submit('city_id', url, data);

	return check;
}

// 申请优惠券
function reward_petition(uid, pcardid, cardid, name){

	var check;

	var url  = 'userinfo_ajax.php';
	var data = 'action=checkpetition&uid=' + uid + '&pcardid=' + pcardid + '&cardid=' + cardid + '&name=' + encodeURIComponent(name);

	check = ajax_submit('petition', url, data);

	return check;
}

// 检测使用优惠券
function check_coupon(coupon_number, coupon_code, count){

	$.ajax({
		url     : ajax_url  = 'userinfo_ajax.php',
		data    : ajax_data = 'action=checkcoupon&type=2&coupon_number=' + coupon_number + '&coupon_code=' + coupon_code + '&count=' + count,
		async   : false,
		success : function(result){
			if(result.substr(0,4) != '<TR>'){
				$('#checkcoupon').html('<img src="images/userinfo/check_error.gif"> ' + result);
				issuccess = 0;
			} else{
				$('#checkcoupon').html('');
				$("#table_coupon").append(result);
				issuccess = 1;
			}
		}
	});

	return issuccess;
}