
function loadimg()
{
    $("#safecode").html("<img id='#codeimg' src='inc/code.php?id="+Math.random()+"' />");
}

function search()
{
  
   window.location='/search.php?'+$("#keyword").serialize();
}

function login()
{
    $.ajax({
        type: "POST",
        dataType:"json",
        url: "/ajax.php?act=checklogin",
        data:   $("#login input").serialize(),
        success: function(json){
            if(json.msg!=null)
            {
                alert(json.msg);
            }
            else
            {
                alert("登入成功");
                window.location ="userinfo.php";
            }
                
        },
        error:function(){
            alert('链接出错')
        }

    });
}
function exit()
{
    $.get("/ajax.php?act=exit");
    //alert("注销成功");
    window.location ="index.php";
}
/**
 * 注册用户
 */
function reguser()
{

    $.ajax({
        type: "POST",
        dataType:"json",
        url: "/ajax.php?act=saveuser",
        data:   $("#regtab1 input").serialize(),
        success: function(json){
            if(json.msg!=null)
            {
                alert(json.msg);
            }
            else
            {
                alert("注册成功");
                window.location ="index.php";
            }
                
        },
        error:function(){
            alert('链接出错')
        }

    });
    
}
/**
 * 检查用户名
 */
function checkuser()
{
    $.getJSON(
        "/ajax.php?act=checkuser",
        {
            name: $("#username").val()
            },

        function(json){
            alert(json.msg);
        }
        );
}

function upcom()
{
    if($("#content").val()=='' || $("#name").val()=='')
    {
        $("#commsg").html("姓名或内容不能为空");
        return;
    }
  
    $.ajax({
        beforeSend:function(){          
            $("#commsg").html("正在提交");
            
        },
        type: "post",
        url:"/ajax.php?act=com",
        data:$("#gocom :input").serialize(),
        success: function(comm){
            $("#commsg").html("添加成功,您的咨询可能几小时后或次日有回复!");
            $("#content").val("");
         
        },
        error:function(){
            $("#commsg").html("链接出错");
        }
    });
}

function cartclose()
{
    $("select").css("display","");
    $("#myshopcert").remove();
    $("#myunput").remove();
}


function addtocar()
{
    
    $.get("/ajax.php?act=order", {
        act: "order",
        id: $("#idobj").val(),
        pr_id:$("#price").val()
    },
    function(data)
    {
       window.location="/account.php";
    })
}
function add(couts)
{
    $.getJSON("/ajax.php", {
        act: "add",
        counts: couts
    },
    function(json){
        $("#msg").html(json.msg);
        $("#tr"+couts+" td").eq(3).text(json.count);
        $("#tr"+couts+" td").eq(4).text(json.cprice+" 元");
        $("#allprice").html(json.allprice);
    });
}
function sub(couts)
{
    if ($("#tr"+couts+" td").eq(3).text()!="1")
    {
        $.getJSON("/ajax.php", {
            act: "sub",
            counts: couts
        },
        function(json){
            $("#msg").html(json.msg);
            $("#tr"+couts+" td").eq(3).text(json.count);
            $("#tr"+couts+" td").eq(4).text(json.cprice+" 元");
            $("#allprice").html(json.allprice);
        });
    }
    else
    {
        $("#msg").html("不能在减了");
    }
}
function del(couts)
{
    $("#tr"+couts).remove();
    $.getJSON("/ajax.php", {
        act: "del",
        counts: couts
    },
    function(json){       
        $("#msg").html(json.msg);
        $("#allprice").html(json.allprice);
    });   
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}