﻿// JavaScript Document
function getLanguage(){
	var en = $.cookie("EN");
	en = (en == null)?"false":en;
	return en;
}

//<a onclick="AddFavorite(window.location,document.title)">加入收藏</a> 
function AddFavorite(sURL, sTitle){try{window.external.addFavorite(sURL, sTitle);}catch (e){try{window.sidebar.addPanel(sTitle, sURL, "");}catch (e){alert("加入收藏失败，请使用Ctrl+D进行添加");}}}

//<a onclick="SetHome(this,window.location)">设为首页</a> 
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);}}}


//处理PNG图片，让它可以正常显示
function png(o)
{
	if (!isIE)
		return;
	if (o.src.toLowerCase().indexOf	(".png", 0) == -1)
		return;
	var img = o;
	var imgID = (img.id) ? "id='" + img.id + "' " : "";
	var imgClass = (img.className) ? "class='" + img.className + "' " : "";
	var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
	var imgStyle = "display:inline-block;" + img.style.cssText;
	if (img.align == "left") imgStyle = "float:left;" + imgStyle;
	if (img.align == "right") imgStyle = "float:right;" + imgStyle;
	if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
	var strNewHTML = "<span " + imgID + imgClass + imgTitle
	+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	+ "(src='" + img.src + "', sizingMethod='scale');\"></span>";
	img.outerHTML = strNewHTML;
}

function limitSize(arr, obj){
	var per = obj.width / obj.height;
	$.each(arr, function(i, v){
		var o = $(v);
		o.load(function(evt){
			var ww = hh = wh = 0;
			var othis = $(this);
			ww = this.width;
			hh = this.height;
			wh = ww / hh;
			if (per >= wh){
				othis.width(wh * obj.height);
				othis.height(obj.height);
			}else{
				othis.width(obj.width);
				othis.height(obj.width / wh);
				//设置
				othis.css("margin-top", Math.floor((obj.height - othis.height()) / 2) + "px");
				othis.css("margin-bottom", (obj.height - Math.floor((obj.height - othis.height()) / 2) - othis.height()) + "px");
				//alert(obj.height - ((obj.height - othis.height()) / 2) - othis.height());
				//alert(othis.attr("src") + ";" + othis.css("margin-top") + ";" + othis.css("margin-bottom") + ";" + othis.height());
				if (isIE){
					othis.css("margin-bottom", (obj.height - Math.floor((obj.height - othis.height()) / 2) - othis.height() - 4) + "px");
				}
			}
		});
		o.attr("src", o.attr("src"));
	});
}


function resetPicMaxSize(o){
	o = $(o);
	var maxWidth = o.width();
	o.removeAttr("width");
	var normalWidth = o.width();
	if (maxWidth < normalWidth)
	{
		o.width(maxWidth);
	}
}

/*检测浏览器/操作系统类型
-----------------------------start-------------------------------------*/
var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);
//检测是否Opera浏览器
//var isOpera = (sUserAgent.indexOf("Opera")>-1);
//检测是否Safari
var isKHTML = sUserAgent.indexOf("KHTML")>-1
                || sUserAgent.indexOf("Konqueror")>-1
                || sUserAgent.indexOf("AppleWebKit")>-1;
//检测IE
var isIE = sUserAgent.indexOf("compatible") > -1
            &&sUserAgent.indexOf("MSIE") > -1;// && !isOpera;
//检测Firfox
var isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML;
//检测Mozilla
var isMoz = sUserAgent.indexOf("Gecko")>-1&&!isKHTML;
var isNS4 = !isIE&&!isOpera&&!isMoz&&!isKHTML
            &&(sUserAgent.indexOf("Mozilla")==0)
            &&(navigator.appName == "Netscape")
            &&(fAppVersion >= 4.0 && fAppVersion <5.0);
//检测操作系统
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC")
            || (navigator.platform == "Macintosh");

var isUnix = (navigator.platform == "X11" && !isWin && !isMac);
/*
----------------------------- end -------------------------------------*/