/*该js文件是基于jquery框架之下运行 所以引入该文件之前必须先引入jquery文件*/
$(function(){
	d_width = $(document).width();
	if($(".piczoom").length > 0){
		var off_width = 230;
		var box_width = 350;
		var offset_top = Math.round(box_width / 2 - off_width / 2);
		$(".piczoom").hover(function(){
			var p=$(this).offset();
			var aoff_left = p.left + off_width + box_width;
			var off_left = p.left + off_width;
			if (aoff_left > d_width) off_left = p.left - box_width;
			$("<div></div>").addClass("ui-tx-pic-zoom").css({left:off_left,top:(p.top-offset_top)}).appendTo("body").html("<img src='"+pic_loading_path+"' class='jq_pic_zoom' rel='"+$(this).attr("id")+"' />").show('slow');
			LoadImage($(".jq_pic_zoom"),$(".jq_pic_zoom").attr("rel"),350);
			return false;
		},function(){
			$("div.ui-tx-pic-zoom").hide();
			$("div.ui-tx-pic-zoom").remove();
		});
	}
});


/**********************
图片loading效果+自动按比例缩放+支持单图和图片列表
@imgid:jquery 对象
@w:图片缩放的最大尺寸
***********************/
function get_pic_size(ob,w)
{
	var sizes=new Array(0,0);
	if(ob.height>0&&ob.width>0)
	{
		if(ob.width/ob.height>= 1){ 
			if(ob.width>w)
			{
				sizes[0]=w; 
				sizes[1]=(ob.height*w)/ob.width; 
			}
			else
			{ 
				sizes[0]=ob.width;
				sizes[1]=ob.height; 
			} 
		} 
		else
		{ 
			if(ob.height>w)
			{
				sizes[1]=w; 
				sizes[0]=(ob.width*w)/ob.height; 
			}
			else
			{ 
				sizes[0]=ob.width;
				sizes[1]=ob.height; 
			} 
		}
	}
	return sizes;
}
function LoadImage(imgid,val,w){ 
	if(val==""||val=="\/")
	{
		imgid.attr({src: onerror_pic_path, width: 50, height: 38});
		return ;
	}
	
	var img=new Image();
	if(img.complete)
	{
		var img_size=get_pic_size(img,w);
		imgid.attr({src: val, width: img_size[0], height: img_size[1]});
	}
	img.onload=function(){
		var img_size=get_pic_size(img,w);
		imgid.attr({src: val, width: img_size[0], height: img_size[1]});
	}
	img.onerror=function(){imgid.attr({src: onerror_pic_path, width: 50, height: 38});}
	img.src=val;
}

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("您的浏览器拒绝设置主页");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		 }
	}
}

//购物

function is_numeric(v)
{
	var patrn=/^[1-9]+[0-9]*$/; 
	if (!patrn.exec(v))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CloseUi()
{
	unhiAlert();
	return ;
}

/**
 * 获取验证码
 * @param  string
 * @return  void
 */
function get_validate_code(tid) { 
	var code_url =js_root_path+'common/get_validate_code';  
	if (document.getElementById(tid))
	{
		document.getElementById(tid).innerHTML = '<img src="'+code_url+'"/>';
	}
}

function subForm(f,e)
{
	if( ! Validator.Validate(f,3)) return;
	e.value = '数据处理中..';
	e.disabled = true;
	f.submit();
}

function fontZoom(size)
{
	document.getElementById('ui-tx-content').style.fontSize=size+'px'
}

function js_copy(txt)
{
	if(window.clipboardData) 
	{    
		window.clipboardData.clearData();    
		window.clipboardData.setData("Text", txt);    
	}
	else if(navigator.userAgent.indexOf("Opera") != -1)
	{    
		window.location = txt;   
	} 
	else if (window.netscape) 
	{    
		try {    
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
		} catch (e) {    
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");  
		}    
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);    
		if (!clip)    
		return;   
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);    
		if (!trans)    
		return;    
		trans.addDataFlavor('text/unicode');    
		var str = new Object();    
		var len = new Object();    
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);    
		var copytext = txt;    
		str.data = copytext;    
		trans.setTransferData("text/unicode",str,copytext.length*2);    
		var clipid = Components.interfaces.nsIClipboard;    
		if (!clip)    
		return false;    
		clip.setData(trans,null,clipid.kGlobalClipboard);    
	} 
	alert("链接已经成功拷贝，您可以粘贴到旺旺,QQ,MSN或者邮件发给好友了");    
}