/**
 * Ahthor:welsonla
 * Date:2011-03-20
 * $Id: common.js 249 2011-07-04 09:40:09Z wyc $
 */

$(function(){
    $(".positive").click(function(){
        if($.trim($("#user_name").val()).length==0||$.trim($("#user_password").val()).length==0)
        {
            alert("请填写完整");	
        }else{
            $name=$("#user_name").val();
            $pass=$("#user_password").val();
            $.ajax({
               
                url:'index.php?c=main&a=login',
                dataType:'json',
                type:'POST',
                data:{
                    name:$name,
                    pass:$pass
                },
                beforeSend:function(){
                    $("#signinfo").text("请稍候……").css({
                        "color":"#3399ff"
                    });
                },
                success:function(data){
                    if(data.msg=="fail"){
                        $("#signinfo").text("用户名或密码错误").css({
                            "color":"red"
                        });
                    }else{						
                        location.href=data.msg;
                    }
                }				
            });	
        }
    });
	
	
	
	
    /************category****************/
	
    /**ADD**/
    $("#addcatbtn").live('click',function(){
        if($.trim($("#catname").val()).length==0){
            alert("请输入分类名称");
            return false;
        }
		
		
        $pid=$("#catsel option:selected").attr("id");//parentid
        $catname=$("#catname").val();//catname
        $cattype=$("#cattype").val();
        $.ajax({
            url:'index.php/category/inscat',
            type:'POST',
            dataType:'json',
            data:{
                'pid':$pid,
                'catname':$catname,
                'cattype':$cattype
            },
            success:function(data){
                if(data.msg=='succ'){
                    alert('添加成功');
                }else if(data.msg=='error'){
                    alert('发生错误');
                }else if(data.msg=='fail'){
                    alert('更新失败');
                }
            }
        });	
    });
    /**END ADD**/
	
        
    $("#eliteProduct .products:gt(0)").hide();
    $("#prev").live("click",function(event){
        event.preventDefault();
        if($(".products:first").is(":visible"))
        {
            $(".products:first").hide();
            $("#eliteProduct .products:last").fadeIn()
        }else{
            $("#eliteProduct .products:visible").hide().prev(".products").fadeIn();
        }

    });
    
    $("#next").live("click",function(event){
        event.preventDefault();
        if($(".products:last").is(":visible"))
        {
            $(".products:last").hide();
            $("#eliteProduct .products:eq(0)").fadeIn()
        }else{
            $("#eliteProduct .products:visible").hide().next(".products").fadeIn();
        }

    });
	
	
	//提交反馈表单
	$("#sub_feedback").click(function(){
		$type=$("input[type=radio]:checked").val();
		$customorg=$("#customorg").val();
		$linkman=$("#linkman").val();
		$mobile=$("#mobile").val();
		$tel=$("#tel").val();
		$mail=$("#mail").val();
		$QQ=$("#QQ").val();
		$area=$("#area1").val()+$("#area2").val()+$("#area3").val();
		$message=$("#message").val();
		if(!$mobile.match(/\d{10,11}/)){
			alert("手机号必须是数字,并且不少于11位");
			$("手机号必须是数字").append("#mobile");
			return;
		}else{
			
		}
		$.ajax({
			url:"index.php?c=service&a=getFeed",
			dataType:"json",
			data:{
				type:$type,
				customorg:$customorg,
				linkman:$linkman,
				mobile:$mobile,
				tel:$tel,
				mail:$mail,
				QQ:$QQ,
				area:$area,
				message:$message},
			type:'POST',
			success:function(data){
					alert(data.msg);
					if(data.status=='true'){
						location.href="index.php?c=main";
					}
			}
		
		}); 
		
		
	});
	
	
});

/*scroll*/
$(function(){
    var _wrap=$('#newslist ul');
    var _interval=2000;
    var _moving;
    _wrap.hover(function(){
        clearInterval(_moving);
    },function(){
        _moving=setInterval(function(){
            var _field=_wrap.find('li:first');
            var _h=_field.height();
            _field.animate({
                marginTop:-_h+'px'
            },100,function(){
                _field.css('marginTop',0).appendTo(_wrap); 
            })
        },_interval)
    }).trigger('mouseleave');
});

