
//下拉菜单的定位
function setMenuPosition(ShowID){
	var offset = $('#' + ShowID).offset();
	var divheight = $('#' + ShowID).innerHeight();
	var leftpadd=0
	if (ShowID == 'newspecialtmp') {ShowID='newspecial';}
	if (ShowID == 'BoardDiv') {leftpadd=10;}
	
	$('#' + ShowID +'_menu').css({
		'left':offset.left - leftpadd,
		'top':offset.top + divheight,
		'position':'absolute'
	}).show();
}

//显示或隐藏层

function MenuDivShow(showdiv){
	$('#' + showdiv + '_menu').mouseover(function () { $(this).show(); });
	$('#' + showdiv + '_menu').mouseout(function () { $(this).hide(); });
}

//同版面的版面列表下拉菜单
function ClassListDiv(ClassID,CDivID){
	$('#'+ CDivID +'_menu').remove();
	$('<div id="'+ CDivID +'_menu"></div>').appendTo('body');
	
	$.ajax({
		url: "/ajaxTemplates/Boardinfo.asp",
		cache: true,
		data: 'ClassID='+ ClassID,
		beforeSend: function(XMLHttpRequest){
			Loadingstr=ShowLoading();
			$('#'+ CDivID +'_menu').html(Loadingstr);
		},
		success: function(html){
			$('#'+ CDivID +'_menu').html(html);
		},
		complete: function(){
			$('#loading').remove();
		},
		error: function(){
			$('#'+ CDivID +'_menu').html('加载失败...');
		}
	}); 
	
	setMenuPosition(CDivID);
	MenuDivShow(CDivID);
		
	$('#' + CDivID).mouseout(function () { $('#' + this.id + '_menu').hide(); });
}

//去其他版面
function BoardListShow(BTID,ForumID){
	$("div > a").removeClass('O_navtitlelistStrong');
	$('#n_'+BTID).addClass('O_navtitlelistStrong');
	
	$.ajax({
			  url: "/ajaxTemplates/OtherBoardAjax.asp",
			  cache: false,
			  data: 'ForumID='+ ForumID +'&BTID='+ BTID,
			  beforeSend: function(XMLHttpRequest){
				//ShowLoading();
				Loadingstr=ShowLoading();
				$('#O_navajax').html(Loadingstr);
			  },
			  success: function(html){
				$('#O_navajax').html(html);
			  },
			  complete: function(){
				 $('#loading').remove();
			  },
			  error: function(){
				$('#O_navajax').html('加载失败...');
			  }
		}); 
}


//帖子转移
function MoveboardAjax(FBoardAjurl,boardlistID,waiterrorID){
	$('#boardlist').html('');
	if (!waiterrorID) waiterrorID=boardlistID;
	$.ajax({
			  url: FBoardAjurl,
			  cache: false,
			  beforeSend: function(XMLHttpRequest){
				Loadingstr=ShowLoading();
				$('#'+waiterrorID).html(Loadingstr);
			  },
			  success: function(html){
				$('#'+boardlistID).html(html);
			  },
			  complete: function(){
				 $('#loading').remove();
			  },
			  error: function(){
				$('#'+waiterrorID).html('加载失败...');
			  }
		}); 
}



var proMaxHeight = 500;
var proMaxWidth = 700;
function proDownImage(ImgD){ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
		var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
		if(rate <= 1){			
			ImgD.width = image.width*rate;
			ImgD.height =image.height*rate;
		}else {
			ImgD.width = image.width;
			ImgD.height =image.height;
		}
    } 
}

function ajaxpost_bbs(theform){
	var ajaxframeid = 'ajaxframe';
	var ajaxifrm = document.getElementById(ajaxframeid); 

	if(ajaxifrm == null) {
		html='<iframe name="'+ajaxframeid+'" id="'+ajaxframeid+'" style="display: none" src="javascript:void(0)"></iframe>';
		$(document.body).append(html);
	}
	theform.target = ajaxframeid;
	return false;
}

var copytoclip=1;
function copyToClipboard(text,alertmsg) {		
	
	if (navigator.appVersion.match(/\bMSIE\b/)){
		clipboardData.setData('Text', text);
		if(alertmsg) {
			alert(alertmsg);
		}
	}else{
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
	}
}

	//======记录缓存
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + ";path=/";
}

////=====控制显示次数
// the popup displays each time thie page reload or only once at the first time page loaded.
	// once / eachTime
	
function LoginTimes()
{
	var displayMode = "once";
	var cookieName="instrument_login_time";
 	var n=readCookie(cookieName);	
	
	if (displayMode=="eachTime") 
		LoginDiv();
	else {
		var tm=new Date().getTime();
		if (n==null || tm>n) {
			LoginDiv();
			writeCookie(cookieName, document.lastModified);
		}
	}
}

//ajax function
// RqUrl 请求响应的路径 Ajax_Div显示结果页面必须的参数 RqPar 查询的字符串

function Ajax_Get(Ajax_Div,RqUrl,RqPar){

	if (!Ajax_Div){ alert("error");return false;}
	if (!RqPar){ alert("error");return false;}
	if (!RqUrl) $('#'+ Ajax_Div +'_menu').html('加载失败... 请刷新页面重试');
	
	$.ajax({
		url: RqUrl,
		cache: false,
		data: RqPar,
		beforeSend: function(XMLHttpRequest){
			Loadingstr=ShowLoading();
			$('#'+ Ajax_Div +'_menu').html(Loadingstr);
		},
		success: function(html){
			$('#'+ Ajax_Div +'_menu').html(html);
		},
		complete: function(){
			$('#loading').remove();
		},
		error: function(){
			$('#'+ Ajax_Div +'_menu').html('加载失败...');
		}
	}); 
}

function BoardListDiv(ClassID,CDivID){
	$('#'+ CDivID +'_menu').remove();
	$('<div id="'+ CDivID +'_menu"></div>').appendTo('body');
	
	aurl="/ajaxTemplates/BoardList.asp";
	aPar='ClassID=0';
	
	Ajax_Get(CDivID,aurl,aPar);
	
	setMenuPosition(CDivID);
	MenuDivShow(CDivID);
	
}

function BTabs(tabid,n,m) {
  var tabsNumber = m;
  for (i = 1; i <= tabsNumber; i++) {
      if (i == n) {
          document.getElementById(tabid + "_1_" + i).style.display = "block";
      } else {
          document.getElementById(tabid + "_1_" + i).style.display = "none";
      }
  }
}