/**
 * 判断变量v是否为空
 * @param v
 * @return
 */
function isEmpty(v){
	return (typeof(v) == 'undefined') || (v == 'null') || (v == 'undefined') || (v == 'NaN') || (v == '');
}
/**
 * 全球艺搜
 */
$(document).ready(function(){
	var forwardAction=["SoAuction.aspx","SoNews.aspx","SoGoods.aspx","SoArtist.aspx"];
	$("#txtSearchKey").bind("focus",function(event){this.value=this.value=="按关键字搜索"?"":this.value;});
	$("#searchForm").bind("submit",function(event){
		var vSearchKey = $("#txtSearchKey").val();
		if (vSearchKey == null || vSearchKey == "" || vSearchKey.replace("按关键字搜索", "") == ""){
	        alert("请输入查询关键字！");
	        return false;
	    }
		this.action="http://so.artnet.cn/"+forwardAction[$("#hdSort").val()];
	});
});
/**
 * Tab切换及事件绑定，在document装入时运行。
 * _divClass:包含ul li的div的css样式
 * nav_on_class:Tab选中时的css样式
 * nav_on_class:Tab未选中时的css样式
 */
function bindTabChange(_divClass,nav_on_class,nav_off_class){
	$("."+_divClass+" > ul > li").each(function(){
		$(this).bind("mouseover",function(){
			$(this).siblings().each(function(){
				$(this).removeClass(nav_on_class).addClass(nav_off_class);
				$("#"+$(this).attr("ref")).css("display","none");
			});
			$(this).removeClass(nav_off_class).addClass(nav_on_class);
			$("#"+$(this).attr("ref")).css("display","block");
		});
	});
}
/**
 * 加入收藏
 */
function addBookMark(url,name){
	if (document.all){//IE
       window.external.addFavorite(url,name);
    }else if (window.sidebar){//ff
       window.sidebar.addPanel(name,url,"");
 	}else{
 		alert("你的浏览器不支持此事件！");
 	}
}
/**
 * 设为首页
 */
function setHomepage(url){
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
  		document.body.setHomePage(url);
	}else if (window.sidebar){
    	if(window.netscape){
			try{  
            	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         	}catch (e){  
    			alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );  
         	}
    	}else{
    		alert("你的浏览器不支持此事件！");
    	}
	    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
	    prefs.setCharPref('browser.startup.homepage',url);
	}else{
		alert("你的浏览器不支持此事件！");
	}
}
/**
 * 复制Url
 * @return
 */
function copy_code(){
 	var copyText=window.document.location.href;  
     if (window.clipboardData){
        window.clipboardData.setData("Text", copyText);
     }else{
         var flashcopier = 'flashcopier';
         if(!document.getElementById(flashcopier)){              
        	 var divholder = document.createElement('div');
        	 divholder.id = flashcopier;
        	 document.body.appendChild(divholder);
         }
         document.getElementById(flashcopier).innerHTML = '';
         var divinfo = '<embed src="/images/_clipboard.swf" FlashVars="clipboard='+copyText+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
         document.getElementById(flashcopier).innerHTML = divinfo;          
     }
     alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友!");
 }

/**
 * 根据条件获取相应select型列表
 * @param keyword
 * @param method
 * @param position
 * @param withSelect
 * @return
 */
function loadSelectList(keyword,method,position,withSelect){
	keyword = isEmpty(keyword)?"0":keyword;
	$.getJSON("commonService!"+method+"?jsoncallback=?",{"pId":keyword},function(data){
		var selectVal=$('#hidden_'+position).val();
		var item;
		if(withSelect==true){
			item = "<option value=''>--所有--</option>";
		}
		var selected="";
		$(data).each(function(){
			selected=this.id==selectVal?" selected='selected'":"";
			item += "<option value='"+this.id+"'"+selected+">"+this.name+"</option>";
		});
		$('#'+position).html(item);
	});
}

function resizeimg(ImgD, iwidth, iheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height; 
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height; 
        }
    } 
}
