﻿
 //---导航搜索-------------------------------------------------------------------------------------
 function search_key_focus(obj)
{
    if(obj.value=="请输入商品名称,支持拼音搜索") obj.value = "" ;
}
function search_key_blur(obj)
{
    if(obj.value=="") obj.value = "请输入商品名称,支持拼音搜索" ;
}

function search_submit()
{
    var obj = document.getElementById("search_key");
    if(obj.value=="请输入商品名称,支持拼音搜索" || obj.value =="")
    {
        alert("请输入搜索关键词");
        obj.focus();
        return false;
    }
    return true;
}
function findValue(li) {
	if( li == null ) return alert("No match!");


	if( !!li.extra ) var sValue = li.extra[0];

	
	else var sValue = li.selectValue;

	//alert("The value you selected was: " + sValue);
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0] ;
}

function lookupAjax(){
	var oSuggest = $("#search_key")[0].autocompleter;

	oSuggest.findValue();

	return false;
}
//---收藏------------------------------------------------------------------------------
function collectGoodsFun(goodsId)
{
    var param = {goodsId:goodsId};
	$.post("/goods/collectGoods_NP.do",param,function(data){
		
		if(data==1)
		    alert("收藏成功！");
		else if(data==-3)
		    alert("收藏的商品不存在！");
		else if(data==-2)
		    gotoLogin("你还没有登录，无法收藏！现在就去登录吗？");
		else if(data==-1)
		    alert("已收藏！");
		else
		    alert("收藏失败！错误代号：【"+data+"】");
	});
}

//---评论------------------------------------------------------------------------------	
function CommentGoodsFun(goodsId)
{
    var param = {goodsId:goodsId};
	$.post("/goods/commentGoods_NP.do",param,function(data){
		
		if(data==-2)
		    gotoLogin("您还没有登录，无法发表评论！现在就去登录吗？");
		else if(data==-1)
		    alert("您还没有购买该商品，不能发表评论！");
		else if(data==0)
		    alert("您已经发表过评论了，不能重复发表评论！");    
		else
		    window.location="/my/writeComment.do?goodsId="+goodsId;
	});
}
//---邀请------------------------------------------------------------------------------
function showInvite()
{
    $("#divInvite").show();
}

function hideInvite()
{
    $("#divInvite").hide();
}
//---公用函数------------------------------------------------------------------------------
function gotoLogin(msg)
{
    if(confirm(msg))
    {
        var currentUrl = encodeURIComponent(window.location.href);
        window.location="/user/reg.do?backUrl="+currentUrl;
    }  
}
function DrawImage(ImgD,FitWidth,FitHeight)
{
    try
    {
	    var image=new Image();
	    image.src=ImgD.src;


		if(image.width>0 && image.height>0){
			if(image.width/image.height>= FitWidth/FitHeight){
				if(image.width>FitWidth){
					ImgD.width=FitWidth;
					ImgD.height=(image.height*FitWidth)/image.width;
				}else{
					ImgD.width=image.width;
					ImgD.height=image.height;
				}
			} else{
				if(image.height>FitHeight){
					ImgD.height=FitHeight;
					ImgD.width=(image.width*FitHeight)/image.height;
				}else{
					ImgD.width=image.width;
					ImgD.height=image.height;
				}
			}
		}

	
     }
     catch(e){}
}
function copyIt(textit) 
{
      if(textit == "" )
      {
        alert("您的邀请链接为空!");
        return;
      }
      if (window.clipboardData) {
        window.clipboardData.setData("Text",textit);
        alert("地址:"+textit+"已被复制\r\n您可以粘贴该地址发送给您的朋友！");
      } 
      else 
      {
         alert("暂时不支持非IE浏览器,您可以手工复制链接地址发送给您的朋友");
      }
}
//*********************************************************
