﻿
function Submit()
{
    if (form1.key.value=='')
    {
        alert("请输入您要搜索的物品名称！");
        form1.key.focus();
        return false;
    }
}

function AddFavorite(sURL, sTitle)
{
   try
   {
       window.external.addFavorite(sURL, sTitle);
   }
   catch (e)
   {
       try
       {
           window.sidebar.addPanel(sTitle, sURL, "");
       }
       catch (e)
       {
           alert("加入收藏失败，请使用Ctrl+D进行添加");
       }
   }
}

function SetHome(obj,vrl)
{
   try
   {
           obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
   }
   catch(e){
           if(window.netscape) {
                   try {
                           netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                   }  
                   catch (e)  { 
                           alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");  
                   }
                   var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                   prefs.setCharPref('browser.startup.homepage',vrl);
            }
   }
}


function showImg(src){
	var $img = $("#myImgs");
	$img.loadthumb({
		"src": src ,
		"imgId":"myImgs",
		"parentId":"CRviewer"
	});
}

function fnAddCart(pid)
{
    $.post("/gh/hdlAddToCart.ashx",{Action:"post",ProductID:pid},function(data, textStatus)
    {	 
        switch(data.Status)
        {
            case 'Yes':
            {
                $.post("/gh/hdlCartItem.ashx",{Action:"post",ProductID:pid},function(da, ts)
                {
                     jAlert('您选购的产品已经成功添加到购物车！', '系统提示');
                     $("#cartitems").html(da.Count);
                },"json");
                break;
            }
            case 'No':
            {
                 jConfirm('您还未登录，不能够执行本操作，请先登录!','系统提示');
                 break;
            }
            case 'Not.':
            {
                alert('系统提示：添加购物车失败，原因：'+data.Status+'，请与网站管理员联系！');
                break;
            }
        }
        
    },"json");
}

function fnUpdate(t,pid)
{
    var timestamp = (new Date()).valueOf();
    $.getJSON("/gh/hdlUpdate.ashx?tm="+timestamp+'&t='+t+'&pid='+pid,function(data){
        if (data.Status=='success')
        {
            $.getJSON("/gh/hdlGetCount.ashx?tm="+timestamp+'&pid='+pid,function(data){
                $("#ReadCount").html(data.ReadCount);
                $("#GoodCount").html(data.GoodCount);
                $("#FavCount").html(data.FavCount);
                switch(t)
                {
                    case 1:
                    {
                        alert('您成功赞扬了本产品，谢谢您的支持！');
                        break;
                    }
                    case 2:
                    {
                        AddFavorite(document.URL,document.title);
                        break;
                    }
                }
            });
        }
    });
}

function chk_login(obj){
	if(obj.key.value == ""){
		alert("请输入要搜索的物品名称！！");
		obj.username.focus();
		return false;
	}
}

function selectall(objname)
{ 
            for(i=1;i <window.document.form1.elements.length;i++)
            { 
                    var e=window.document.form1.elements[i]; 
                    if(e.type== "checkbox")
                    { 
                        if(document.all[objname].checked)
                        {     
                           if(e.disabled !=true)e.checked=true; 
                        } 
                        else e.checked=false; 
            } 
    } 
} 




		
