var BROWSER = {};
browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','maxthon':'','mozilla':'','webkit':''});
function browserVersion(types) {
	var userAgent = navigator.userAgent.toLowerCase();
	var other = 1;
	for(i in types) {
		var v = types[i] ? types[i] : i;
		if(userAgent.indexOf(v) != -1) {
			var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
			var matches = re.exec(userAgent);
			var ver = matches != null ? matches[2] : 0;
			other = ver !== 0 ? 0 : other;
		}
		else {
			var ver = 0;
		}
		eval('BROWSER.' + i + '= ver');
	}
	BROWSER.other = other;
	if (BROWSER.safari) {BROWSER.firefox = true;}
	BROWSER.opera = BROWSER.opera ? opera.version() : 0;
}

var titleTip=function(){
	jQuery("body").append('<style type="text/css">#titleTip{font-size: 12px;background: #F7F5D1;border: 1px solid #333;color:#333;display:none;margin-top:0;padding: 4px 5px 2px 5px;position:absolute;white-space:nowrap;z-index:100000;}</style>');
	var xOffset=-21,yOffset=-3,actObj=jQuery(".mainNav a");
	actObj.hover(function(A){
		if (this.title == ''||this.title == undefined) return;
		this.t=this.title;this.title='';
		jQuery("body").append("<p id='titleTip'>"+this.t+"</p>");
		jQuery("#titleTip").css("top",(A.pageY-xOffset)+"px").css("left",(A.pageX+yOffset)+"px").fadeIn("fast")
	},function(){if (this.t == ''||this.t == undefined) return;this.title=this.t;jQuery("#titleTip").remove();});
	actObj.mousemove(function(A){jQuery("#titleTip").css("top",(A.pageY-xOffset)+"px").css("left",(A.pageX+yOffset)+"px")});
};
//$(document).ready(function(){titleTip()});

function correctPNG() {
	if (parseInt(BROWSER.ie) > 6) return;
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			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;
			i = i-1;
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", correctPNG);

/**
 * 添加收藏夹
 */
function addFavorite(sUrl, sTitle){
	try{
		window.external.addFavorite(sUrl, sTitle);
	}catch (e){
		try{
			window.external.addToFavoritesBar(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("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将 [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 getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset,endstr));
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i= 0;
	while (i<clen) {
		var j = i+alen;
		if (document.cookie.substring(i,j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ",i)+1;
		if(i==0) break;
	}
	return null;
}

function setCookie(name,value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var today = new Date();
	var expires = new Date(today.getTime()+99864000);
	var path = "/";
	var domain = (4<argc)?argv[4]:null;
	var secure = (5<argc)?argv[5]:null;
	document.cookie = name+"="+escape(value)+((expires == null)?" ":(";expires ="+expires.toGMTString()))+((path == null)?"   ":(";path = "+path))+((domain == null)?" ":(";domain =" +domain)) +((secure==true)?";secure":" ");
}

function updateSeccode() {
	jQuery.ajax({
		type: "GET",
		url: '/ajax.php?action=updateseccode',
		success: function(html){
			$('#seccodeHtml').html(html);
		}
	});
}

/**
 * 生成flash代码
 */
function showFlash(src, width, height){
	var type = src.substring(src.length-3);
    var $html = '';
	if (type == 'swf') {
		$html += '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="'+width+'" height="'+height+'">';
		$html += '<param name="movie" value="'+src+'">';
		$html += '<param name="quality" value="high"> ';
		$html += '<param name="wmode" value="transparent"> ';
		$html += '<param name="menu" value="false"> ';
		$html += '<embed src="'+src+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="'+width+'" height="'+height+'" quality="High" wmode="transparent">';
		$html += '</embed>';
		$html += '</object>';
	}
	else if (type == 'gif') {
		$html += '<img src="'+src+'" width="'+width+'" height="'+height+'" />';
	}
    document.write($html);
}

//首页下半部招聘处Tab切换
function changeTab(obj, id, checked) {
	$("#changeTab"+id).addClass(checked).siblings("#"+obj+" .changeTab").removeClass(checked);
	$("#changeTabS"+id).css('display','block').siblings("#"+obj+" .changeTabS").css('display', 'none');
}
