﻿
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)
                {
                     alert('您选购的产品已经成功添加到购物车！', '系统提示');
                     $("#cartitems").html(da.Count);
                },"json");
                break;
            }
            case 'No':
            {
                 //alert('您还未登录，不能够执行本操作，请先登录!','系统提示');
                 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; 
            } 
    } 
}

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	
    jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close()
{	
    if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{	
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;
	}
}

$(document).ready(function()
{  
    $('#jsddm > li').bind('mouseover', jsddm_open)
    $('#jsddm > li').bind('mouseout',  jsddm_timer)});
    document.onclick = jsddm_close;
    $('#hAddToCart').css('cursor','hand');

    $(document).ready(function(){
    $("#thumbnail a").mouseover(function(){
	    showImg($(this).attr("href"));
	    //var image = new Image();    
//	    image.src = $(this).attr('href');
//        if (image.complete)              
//            $("#large img").attr({"src": $(this).attr("href")});           
//        else              
//            $("#large img").attr({"src": "/images/indicator.gif"});
//	    //return false;
    });
    $("#large>img").load(function(){$("#large>img:hidden").fadeIn("fast")});
    
//    $('form').submit(function(){	
//	    $('input[type=submit], button[type=submit]').attr('disabled', 'disabled');
//    });
        
//    $('#btnSignin').click(function(){
//        return fnLogin();
//    });

});


function chk_login(obj){
	if(obj.txtUserName.value == ""){
		$("#LoginMessage").html("账号不能为空");
		obj.txtUserName.focus();
		return false;
	}
	if(obj.txtPassword.value == ""){
		$("#LoginMessage").html("密码不能为空");
		obj.txtPassword.focus();
		return false;
	}
}


function fnLogin()
{
    var loginName = $("input[id='txtUserName']").val();
    var password = $("input[id='txtPassword']").val();
         
    if(loginName=="")
    {
        $("#LoginMessage").html("账号不能为空");
        $("#txtUserName").focus();
        return false;
    }
      
    if(password=="")
    {
        $("#LoginMessage").html("密码不能为空");
        $("#txtPassword").focus();
        return false;
    }

    var SaveCookies = false;
    if($("#SaveCookies").attr("checked")==true)
    {
        SaveCookies = true;
    }
    

    $.getJSON("/gh/hdlLogin.ashx?u="+loginName+'&p='+password+'&s='+SaveCookies,function(data,text)
    {
        alert('status:'+text);
        if (text=="success")
        {
            alert('data:'+data.Status);
            if (data.Status == "Yes")
            {
                 alert('aaa');
                 document.location="/signin.aspx";
                 //return false;
            }
            else
            {
                //$("#LoginMessage").html(data.Status);
                jConfirm(data.Status,'系统提示');
                $("#txtUserName").attr("value",'');
                $("#txtPassword").attr("value",'');
                $("#txtUserName").focus();
                return false;
            }
        }
        else
        {
            $("#LoginMessage").html("loading...");
        }

    });
}




		
