var pixelGif='/style/imgs/pixel.gif';
function getMilliseconds(s1){
   var d, s=0;
   d = new Date();
   s += d.getUTCHours() * 3600000;
   s += d.getUTCMinutes() * 60000;
   s += d.getUTCSeconds() *1000;
   s += d.getUTCMilliseconds();
	 if (s1) {
		 //showMsg({txt:s-s1});
		 document.title=s-s1;
	 }
   return s;
}

var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
function quit () {
	$.get('/bbs/login.php?action=quit&_='+Math.random(),function(){
		window.location.href='/';
	});
}
//计数器:返回数组
function Count(){
	var c=jQuery.cookie('count');
	var a=[];
	for (var i=0;i<6-c.length;i++) {
		a.push(0);
	}
	for (var i=0;i<c.length ;i++ ) {
		a.push(c.charAt(i));
	}
	return a;
}
function ajax_login(obj) {
	if (!document.cookie) {
		alert('您的浏览器Cookie关闭了\n页面需要运行浏览器存储Cookie\n请您开启浏览器的Cookie');
		return false;
	}
	obj = $(obj);
	$.post('/bbs/pw_ajax.php?action=login',obj.formSerialize(),function(xmlDOC){
		if (!$.isXMLDoc(xmlDOC)) {
			alert('通讯失败,请再试试!');return;
		}
		var txt=is_ie ?xmlDOC.xml.split('CDATA[')[1].split(']]')[0]:xmlDOC.documentElement.textContent;
		if(txt.length<100){
			showMsg({txt:txt,img:'/bbs/images/important.gif'});
			$('.yzm').attr('src','/bbs/ck.php?_='+Math.random());
			return;
		}
		window.location.href=window.location.href;
	},'xml');
	return false;
}
function showMsg (opt) {
	if (null==opt){
		clear();
		return;
	}
	if (showMsg.time){
		clearTimeout(showMsg.time);
		showMsg.time=false;
		clear();
	}
	var txt=opt.txt,img=opt.img,ajax=opt.ajax;
	img=img||'/style/imgs/ajax-loader.gif';
	var o = create();
	o.innerHTML  = '<div>'+txt+'</div>';
	o.style.top  = (ietruebody().scrollTop + 170) + 'px';
	o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + ietruebody().scrollLeft + 'px';
	if (!ajax)
		showMsg.time = setTimeout("showMsg();",3000);
	function ietruebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}
	function clear(){
		var o=document.getElementById('ajax_showMsg');
		if (o) document.body.removeChild(o);
	}
	function create () {
		var tag=document.getElementById('ajax_showMsg');
		if(!tag){
			var o = document.createElement('div');
			o.style.cssText = 'border:#EFEF9D 1px solid;background:url('+img+') no-repeat .5em center #DAF3E3;font:bold 14px Helvetica;text-align:center;padding:1em 1.5em 1em 4.5em;position:absolute;z-index:3005;';
			o.id  = 'ajax_showMsg';
			document.body.appendChild(o);
		} else{
			var o = document.getElementById('ajax_showMsg');
		}
		return o;
	}
}
function getMilliseconds(s1){
 var d, s=0;
 d = new Date();
 s += d.getUTCHours()* 3600000;
 s += d.getUTCMinutes()* 60000;
 s += d.getUTCSeconds()*1000;
 s += d.getUTCMilliseconds();
 if (s1){
	document.title=s-s1;
 }
 return s;
}
function Log(){
	for (var i=0;i<arguments.length ;i++ ){
		var o=arguments[i];
		if (window.console && window.console.log && window.console.dir){
			if (typeof o=='object') window.console.dir(o);
			else window.console.log(o);
		}//else alert(o);
	}
}
function loadbody () {
	if(window.location.host.slice(0,4)=='bbs.'){
		window.location.href='http://www.'+window.location.host.slice(4)+'/bbs/';
		return;
	}
	$('body').empty();
	//showMsg({txt:'正在加载页面...',ajax:true});
	var txt,a,par;
	par=window.location.search.slice(1);

	$.post('/in.php',par,function(v){
		txt=v;
		try {
			a=eval('('+txt+')');
		}catch (e) {
			showMsg(txt);
			return;
		}
//		Log(a);
		if (a.html) {
			$.get(a.html,par+'&_='+Math.random(),function(v1){
				txt=v1;
				setTimeout(out,0);
			});
		}
	});
	function addstyle (txt) {
		var reg=/<link(?:(?!>).)+>/gi,css,i,a,head;
		a=reg.exec(txt);
		head=$('head');
		while(a){
			i=a[0].indexOf('href');
			if (i>0){ 
				i=a[0].indexOf('.css',i)+4;
				if (i>0){ 
					css=a[0].slice(0,i)+'?'+Math.random()+a[0].slice(i);
					head.append(css);
				}
			}
			a=reg.exec(txt);
		}
		return txt.replace(reg,'');
	}
	function out(){
		var b,e;
		b=txt.search(/<head/i);if (b<0) return;
		e=txt.search(/<\/head>/i);if (e<0) return;
		var h=txt.slice(b,e+7);
		txt = addstyle(txt);
		b=txt.search(/<body/i);if (b<0) return;
		b=txt.indexOf('>',b);if (b<0) return;
		b++;
		e=txt.search(/<\/body>/i);if (e<0) return;
		txt=txt.slice(b,e);
		txt=jCT(a,txt);
		//txt=$(createElm(txt));
		//txt.find(".abc").abc();
		document.getElementsByTagName('body')[0].innerHTML=txt;//.html();
		//$('body').html(txt);
		$(".abc").abc();
		$('.yzm').attr('src','/bbs/ck.php?_='+Math.random());
		$('.yzmYZ').attr('src','/bbs/ck.php?YZ=baoming&_='+Math.random());
		//showMsg(null);
		//var h=$("#midden").get(0).scrollHeight;
//		$('#left').height(h);
//		$('#right').height(h);
		$(".abca").abc();
		var menu=$("#midden a:contains('党政机构')").append('>>').parent();
		if(menu.length && window.menudzlj){
			var lj=$('<div/>').addClass('popmenu');
			$.each(window.menudzlj,function(){
				lj.append('<div><a target="_blank" href="'+this.siteurl+'">'+this.c_name+'</a></div>');
			});
			menu.append(lj);
			menu.mouseover(function(){
				$('.popmenu',this).show();
			}).mouseout(function(){
				$('.popmenu',this).hide();
			});
		}
		menu=$("#midden a:contains('教学院系')").append('>>').parent();
		if(menu.length && window.menuyxlj){
			var lj=$('<div/>').addClass('popmenu'),sub;
			$.each(window.menuyxlj,function(){
				sub=$('<div><a target="_blank" href="'+this.siteurl+'">'+this.c_name+'</a><div/>')
						.css({position:"relative"})
						.mouseover(function(){
							$('> .popmenu',this).show();
						}).mouseout(function(){ 
							$('> .popmenu',this).hide();
						});
				lj.append(sub);
				sub=$('div',sub).addClass('popmenu');
				$.each(this.sub,function(){
					sub.append('<div><a target="_blank" href="/?H=zuizhong&id='+this.siteurl+'">'+this.c_name+'</a></div>');
				});
				menu.append(lj);
			});
			menu.mouseover(function(){
				$('> .popmenu',this).show();
			}).mouseout(function(){ 
				$('> .popmenu',this).hide();
			});
		}
		var m2=$('#midden #m2');
		if(m2.length && window.menuyxlj){
			var host='http://'+window.location.host+'/';
			$.each(window.menuyxlj,function(){
				if(host!=this.siteurl) return;
				var sub=$('<ul></ul>');
				$.each(this.sub,function(){
					sub.append('<li class="m2li"><a target="_blank" href="/?H=zuizhong&id='+this.siteurl+'"><b>'+this.c_name+'</b></a></li>');
				});
				m2.prepend(sub).prepend('<div class="m6"><span>专业</span></div>');
			});
		}
 }
} 
function createElm (html) {
	if(typeof(html)!='string') html='';
	var div=document.createElement('div');
	div.innerHTML=html;
	return div;
}
function getText(html) {
	if(typeof(html)!='string') html='';
	var div=document.createElement('div');
	div.innerHTML=html;
	return is_ie?div.innerText :div.textContent;
}
/*
 *分页:支持中心算法和普通算法,默认普通算法
 *cnt:记录总数
 *rows:没页记录数
 *o:中心显示当前页方案,rows = o + o + 1
 *pages:显示 页码的数量
 *no:当前显示的页码
 */
function toPage (page) {
	var s,e,p,n,ps;
	page.cnt=page.cnt || 0;
	if (page.o>0) {
		page.rows = page.o + page.o + 1;
	}else{
		page.o = 0;
		if (!page.rows || page.rows<3) page.rows = 3;
	}
	if (!page.pages || page.pages<3) page.pages=3;
	if (!page.no || page.no<1) page.no=1;
	if (page.o)
		s = page.no - page.o;
	else{
		s = page.no - Math.floor(page.pages / 2);
	}
	if (s<1) s = 1;
	e = s + page.pages - 1;
	ps = Math.ceil(page.cnt/page.rows);
	if (e>ps) e = ps;
	if (e-s<page.pages) {
		s=e-page.pages+1;
	}
	if (s<1) s = 1;
	p = (page.no - 1) || 1;
	n = page.no + 1;
	if (n>ps) n = ps;
	return {begin:s,end:e,prev:p,next:n,cnt:page.cnt,pages:ps,no:page.no};
}
function check_baoming (f) {
	if (!document.cookie) {
		alert('您的浏览器Cookie关闭了\n页面需要运行浏览器存储Cookie\n请您开启浏览器的Cookie');
		return false;
	}
	var els=f.elements;
	for (var i=0; i<els.length; i++) {
		if (els[i].type!='reset' && els[i].type!='submit' && els[i].type!='hidden' && els[i].value=='') {
			els[i].focus();
			alert('请填写或选择:'+els[i].title);
			return false;
		}
	}
	$(f).ajaxForm({
		url:'/login/web_adm.php',
		type:'POST',
		dataType:'text/html',
		success:function(txt){
			if (txt=='check_error') {
				alert('验证码错误:你可以点击刷新验证码图片再试试!');
			}else if(txt=='submit_ok') {
				alert('您的报名已经成功!请等候我们的消息.');
				window.location.href='/';
			}else {
				alert('数据保存错误:你可以点击刷新验证码图片再试试!或者检查一下您的数据.');
			}
		}
	});
	return false;
}

function flashembed(root, userParams, flashvars) {
	
	if (typeof root == 'string') root = document.getElementById(root);
	
	// setup params
	var params = {
		
		// very common params
		src: '#',
		width: '100%',
		height: '100%',		
		
		// flashembed specific options
		version:null,  
		loadEvent:null,
		onFail:null,
		expressInstall:null,  
		
		// flashembed defaults
		allowfullscreen: true,
		allowscriptaccess: 'always',
		quality: 'high',
		bgcolor: '#ffffff',
		type: 'application/x-shockwave-flash',
		pluginspage: 'http://www.adobe.com/go/getflashplayer'
	};
	
	extend(params, userParams);	

	var evt = params.loadEvent;
	params.loadEvent = null;
		
	// setup "lazy loading"
	if (evt) {
		root['on' + evt] = function() {
			return load();
		}; 
		
	// normal loading upon startup. handle to the generated flash object is returned
	} else {
		return load();		
	}
	
	// override extend params function 
	function extend(to, from) {
		if (from) {
			for (key in from) {
				to[key] = from[key];	
			}
		}
	}	
 
	function load() {
		
		var version = getVersion(); 
		var required = params.version; 
		var express = params.expressInstall;		 
		
		if (!root) return;
		
		// is supported
		if (!required || isSupported(required)) {
			params.onFail = params.version = params.expressInstall = null; 
			root.innerHTML = getHTML();	
			
			// return our
			return root.firstChild;
			
		// custom fail event
		} else if (params.onFail) {
			var ret = params.onFail.call(params, getVersion(), flashvars);
			if (ret) root.innerHTML = ret;		
			

		// express install
		} else if (required && express && isSupported([6,0,65])) {
			
			extend(params, {src: express});
			
			flashvars =   {
				MMredirectURL: location.href,
				MMplayerType: 'PlugIn',
				MMdoctitle: document.title
			};
			
			root.innerHTML = getHTML();	
			
		// not supported
		} else {

			// minor bug fixed here 08.04.2008 (thanks JRodman)
			if (root.innerHTML != '') {
				// custom content was supplied
			
			} else {
				root.innerHTML = 
					"<h2>Flash version " + required + " or greater is required</h2>" + 
					"<h3>" + (version[0] > 0 ? 
						"Your version is " + version : "You have no flash plugin installed") +
					"</h3>" + 
					"<p>Download latest version from <a href='" + params.pluginspage + "'>here</a></p>"
				;
			}
		} 
		root['on' + evt] = null; 
		
	}
	
	
	function isSupported(version) {
		var now = getVersion();
		return now[0] >= version[0] && now[1] >= version[1] && (now[2] == null || now[2] >= version[2]);				 
	}
	
	
	function getHTML() {
		
		var html = "";
		if (typeof flashvars == 'function') flashvars = flashvars();
		
		
		// mozilla
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {  

			html = '<embed type="application/x-shockwave-flash" ';

			extend(params, {name:params.id});
			
			for(var key in params) { 
				if (params[key] != null) 
					html += [key] + '="' +params[key]+ '"\n\t'; 
			}  
			
			if (flashvars) {
				html += 'flashvars=\'';
				for(var key in flashvars) { 
					html += [key] + '=' + asString(flashvars[key]) + '&'; 
				}			
				html += '\'';
			}
			
			html += '/>';
			
		// ie
		} else { 

			html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
			html += 'width="' + params.width + '" height="' + params.height + '"'; 
			
			// IE Hack: setup pseudo id for IE 6. otherwise we cannot return our embedded Flash object
			if (document.all && parseInt(navigator.appVersion) <= 6) {
				params.id = "_" + ("" + Math.random()).substring(5);
			} 
			if (params.id) html += ' id="' + params.id + '"'; 
			
			html += '>';  
			html += '\n\t<param name="movie" value="'+ params.src +'" />';
			
			params.id = params.src = params.width = params.height = null;
			
			for (var key in params) {
				if (params[key] != null) 
					html += '\n\t<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			
			if (flashvars) {
				html += '\n\t<param name="flashvars" value=\'';
				for(var key in flashvars) { 
					html += [key] + '=' + asString(flashvars[key]) + '&'; 
				}			
				html += '\' />';
			}
			 
			html += "</object>"; 
		}

		return html;
	}
	

	// arr[major, minor, fix]
	function getVersion() {

		var version = [0, 0];
		
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			var _d = navigator.plugins["Shockwave Flash"].description;
			if (typeof _d != "undefined") {
				_d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
				var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
				var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
				version = [_m, _r];
			}
			
		} else if (window.ActiveXObject) {
			
			try { // avoid fp 6 crashes
				var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				
			} catch(e) {
				try { 
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					version = [6, 0];
					_a.AllowScriptAccess = "always"; // throws if fp < 6.47 
					
				} catch(e) {
					if (version[0] == 6) return;
				}
				try {
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				} catch(e) {
				
				}
				
			}
			
			if (typeof _a == "object") {
				var _d = _a.GetVariable("$version"); // bugs in fp 6.21 / 6.23
				if (typeof _d != "undefined") {
					_d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
					version = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
				}
			}
		} 
		
		return version;
	}
	
	
	// JSON.asString() function
	function asString(obj) {
		
		switch (typeOf(obj)){
			case 'string':
				return '"'+obj.replace(new RegExp('(["\\\\])', 'g'), '\\$1')+'"';
			case 'array':
				
				return '['+ map(obj, function(el) {
					return asString(el);
				}).join(',') +']';
				
				
			case 'object':
				var str = [];
				for (var property in obj) {
					
					str.push('"'+property+'":'+ asString(obj[property])); 
				}
				return '{'+str.join(',')+'}';
		}
		
		// replace ' --> "  and remove spaces
		return String(obj)
			.replace(/\s/g, " ")
			.replace(/\'/g, "\"");
	}
	
	
	// private functions
	function typeOf(obj){
		if (obj === null || obj === undefined) return false;
		var type = typeof obj;
		return (type == 'object' && obj.push) ? 'array' : type;
	}
	
	
	// version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
	if (window.attachEvent) {
		window.attachEvent("onbeforeunload", function(){
			__flash_unloadHandler = function() {};
			__flash_savedUnloadHandler = function() {};
		});
	}
	
	function map(arr, func) {
	  var newArr = []; 
	  for (var i in arr) {
		 newArr[i] = func(arr[i]);
	  }
	  return newArr;
	}
	
	// expose as static method
	flashembed.getVersion = getVersion;
	flashembed.isSupported = isSupported; 

	return root;
}

// setup jquery support
if (typeof jQuery == 'function') {
	(function($) { 
		$.fn.extend({
			flashembed: function(params, flashvars) {  
				return this.each(function() { 
					new flashembed(this, params, flashvars);
				});
			}		
		}); 
	})(jQuery);
}