// JavaScript Document

//


function $(obj){return document.getElementById(obj)}
function $F(obj){return document.getElementById(obj).value}
function $I(obj){return document.getElementById(obj).innerHTML}

function RatImg(Img,Rwidth,Rheight)
{
var i=Img.width;
var j=Img.height; 
blw=Rwidth;
blh=Rheight;
if (i>blw)
{  var zjbl1=blw/i;
   var zjbl2=blh/j;
   if (zjbl1<zjbl2)
   {zjbl=zjbl1;}
   else
   {zjbl=zjbl2;}
   i=i*zjbl;
   j=j*zjbl;}
else
{if (j>blh)
   {zjbl=blh/j;
     j=blh;
     i=i*zjbl;}}
Img.width=i;
Img.height=j;
}

function killErrors() {
return true;
}
//window.onerror = killErrors;


// javascript 操作Cookies
function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 365; //此 cookie 将被保存 365 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var err = "";
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return err;
}

function textLimitCheck(thisArea, maxLength){
  if (thisArea.value.length > maxLength){
    alert(maxLength + ' 个字限制. \r超出的将自动去除.');
    thisArea.value = thisArea.value.substring(0, maxLength);
    thisArea.focus();
  }
    messageCount.innerText = thisArea.value.length;
}


//更改字体大小
var curfontsize=20;
var curlineheight=25;
function fontZoomA(){
  if(curfontsize>8){
    document.getElementById('fontzoom').style.fontSize=(--curfontsize)+'pt';
	document.getElementById('fontzoom').style.lineHeight=(--curlineheight)+'pt';
  }
}
function fontZoomB(){
  if(curfontsize<64){
    document.getElementById('fontzoom').style.fontSize=(++curfontsize)+'pt';
	document.getElementById('fontzoom').style.lineHeight=(++curlineheight)+'pt';
  }
}


//当前时间
function SiteDate(){
 var enable=0; today=new Date();
   var day; var date;
   var time_start = new Date();
   var clock_start = time_start.getTime();
   if(today.getDay()==0)  day="星期日" 
   if(today.getDay()==1)  day="星期一" 
   if(today.getDay()==2)  day="星期二" 
   if(today.getDay()==3)  day="星期三" 
   if(today.getDay()==4)  day="星期四" 
   if(today.getDay()==5)  day="星期五" 
   if(today.getDay()==6)  day="星期六" 
   date=(today.getFullYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 ";
   document.write(date + day);
}
 
function isNumberString (InString,RefString)
{
if(InString.length==0) return (false);
for (Count=0; Count < InString.length; Count++)  {
	TempChar= InString.substring (Count, Count+1);
	if (RefString.indexOf (TempChar, 0)==1)  
	return (false);
}
return (true);
}

function CharMode(iN){
	if (iN>=48 && iN <=57) //数字
		return 1; 
	if (iN>=65 && iN <=90) //大写字母
		return 2;
	if (iN>=97 && iN <=122) //小写
		return 4;
	else
		return 8; //特殊字符
}

function checkStrong(sPW){
	if (sPW.length<=4)
		return 0;  //密码太短
	Modes=0;
	for (i=0;i<sPW.length;i++){
		Modes|=CharMode(sPW.charCodeAt(i));
	}

	return bitTotal(Modes);
	
}	


// 显示无模式对话框
function ShowDialog(url, width, height) {
	var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
}

//居中打开窗口
function openwindow( url, winName, width, height) {
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 )){
xposition = (screen.width - width) / 2;
yposition = (screen.height - height) / 2;}
theproperty= "width=" + width + "," 
+ "height=" + height + "," 
+ "location=0," 
+ "menubar=0,"
+ "resizable=1,"
+ "scrollbars=0,"
+ "status=0," 
+ "titlebar=0,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," //仅适用于Netscape
+ "screeny=" + yposition + "," //仅适用于Netscape
+ "left=" + xposition + "," //IE
+ "top=" + yposition; //IE 
window.open( url,winName,theproperty );
}
	
//表单提交
function Ctlent(){
//ctrl + Enter
if(event.ctrlKey && window.event.keyCode==13){
  if(ClcKcntr()){
    this.document.addform.submit();
  }
}
//ctrl + s
if(event.ctrlKey && window.event.keyCode==83){
  if(ClcKcntr()){
    this.document.addform.submit();
  }
}
}
clckcnt=0;
function ClcKcntr(){
  clckcnt++;
  if(clckcnt > 1){
    alert('请求已经发出，请等待片刻！\n\n'+'不要重复提交，谢谢！');
	return false;
  }
  return true;
}



//ajax提示框功能
var Obj=''
document.onmouseup=MUp
document.onmousemove=MMove

function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}

function MMove(){
if(Obj!=''){
  document.all(Obj).style.left=event.x-pX;
  document.all(Obj).style.top=event.y-pY;
  }
}

function MUp(){
if(Obj!=''){
  document.all(Obj).releaseCapture();
  Obj='';
  }
}



function showDivInCenter(obj){
	AddTransparentBG();
	
	var sobj=$(obj)
	var w=sobj.style.width.replace("px","");
	var h=sobj.style.height.replace("px","");
	sobj.style.left = (document.body.clientWidth - w) / 2;
	sobj.style.top =((screen.height - h) / 2-80)+document.body.scrollTop+document.documentElement.scrollTop;//屏幕滚动高度 处理高度
	sobj.style.position="absolute";
	sobj.style.background="#FFFFFF";
	sobj.style.FILTER="progid:DXImageTransform.Microsoft.DropShadow()";
	sobj.style.zIndex="10001";
	sobj.style.display="block";
	var titlebarHTML ='<div id="DivTitlebar" onmousedown=MDown(this.parentNode) style="background:#666666; height:20px; font-size:12px;color:#fff;cursor:move;padding:0 0 4px 0"><div style="display:inline; width:200px; position:absolute;padding:3px 0 0 5px;color:#FFFFFF" id=DivTitleText>ddd</div><span onClick="closeWithDiv(this.parentNode.parentNode)" style="float:right; display:inline; cursor:hand;padding:3px 5px 0 0;font-size:12px">关闭</span></div>';
	if (sobj.innerHTML.indexOf("DivTitlebar")<0){sobj.innerHTML = titlebarHTML + sobj.innerHTML}
	$('DivTitleText').innerText=sobj.showtitle
}

//ajax提示框========================================
function openWithDiv(tit,url,w,h,displayContent){
	AddTransparentBG();
	
    if (w=="100%" && h=="100%"){
	massage_box.style.left = massage_box.style.top= massage_box.style.screenx = massage_box.style.screeny ="0";
    massage_box.style.width = document.body.clientWidth-5;
	massage_box.style.height = document.body.clientHeight-80;//"100%";
    var popiframe='<iframe src="'+url+'" width="99%"  height="100%" frameborder=0 scrolling=auto></iframe>';
	}
	else {
	//massage_box.style.top = (screen.height - h) / 2-80  ; 
	massage_box.style.left = (document.body.clientWidth - w) / 2;
	massage_box.style.top=((screen.height - h) / 2-80)+document.body.scrollTop+document.documentElement.scrollTop;//屏幕滚动高度 处理高度
    massage_box.style.screenx = (document.body.clientWidth - w) / 2;//仅适用于Netscape
    massage_box.style.screeny = (screen.height - h) / 2-80;//仅适用于Netscape
    massage_box.style.width = w+"px";
    massage_box.style.height = h+"px";
    var popiframe='<iframe src="'+url+'" width="'+(w-11)+'px"  height="'+(h-36)+'px" frameborder=0 scrolling=auto></iframe>';
	}
    pop_title.innerHTML=tit;
    massage_box.style.display=''
	if (displayContent==''||displayContent==undefined){pop_iframe.innerHTML=popiframe;}
	else {pop_iframe.innerHTML=displayContent;}
	
}
//添加半透明背景
function AddTransparentBG(){
	document.body.style.height="100%";
	var sWidth,sHeight;
	sWidth=document.body.clientWidth;
	sHeight=document.body.scrollHeight;
	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#000000";
	bgObj.style.filter="Alpha(Opacity=30);";
	bgObj.style.left="0";
	//bgObj.style.width=sWidth + "px";
	bgObj.style.width="100%";
	if (sHeight<screen.height){bgObj.style.height="100%"}
	else{bgObj.style.height=sHeight + "px";}
	bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);
}
document.write('<div id="massage_box" style="position:absolute; FILTER: progid:DXImageTransform.Microsoft.DropShadow();z-index:10001;display:none">');
document.write('<div style="border-width:1 1 3 1; width:100%; height:100%; background:#fff; color:#666666; font-size:12px; line-height:150%">');
document.write('<div onmousedown=MDown(massage_box) style="background:#666666; height:20px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;color:#fff;cursor:move;padding:0 0 4px 0">');
document.write('<div style="display:inline; width:200px; position:absolute;padding:3px 0 0 5px" id=pop_title></div>');
document.write('<span onClick="closeWithDiv()" style="float:right; display:inline; cursor:hand;padding:3px 5px 0 0;font-size:12px">关闭</span>');
document.write('</div>');
document.write('<div style="padding:5px" id=pop_iframe></div>');
document.write('</div>');
document.write('</div>');
//ajax提示框功能========================================


function InitAjax(){
var ajax=false; 
try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); } 
catch (e) { try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { ajax = false; } }
if (!ajax && typeof XMLHttpRequest!='undefined') { ajax = new XMLHttpRequest(); } 
return ajax;}

//公用ajax
function DoAjax(url,Post,returnDiv){
	if (url!=""){
		var getinfo = "";
		var ajax = InitAjax();
		ajax.open("POST", url, true); 
		ajax.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded; charset=GB2312"); 
		ajax.send(Post);
	    ajax.onreadystatechange = function(){
		  if (ajax.readyState == 4){getinfo = ajax.responseText;}
	      $(returnDiv).innerHTML = getinfo;
		  }
	}
}

function DoGetAjax(url,Post,returnDiv){
	if (url!="" && $(returnDiv)!=null){
		var getinfo = "";
		var ajax = InitAjax();
		ajax.open("GET", url, true); 
		ajax.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded; charset=GB2312"); 
		ajax.send(Post);
	    ajax.onreadystatechange = function(){
		  if (ajax.readyState == 4){
			  getinfo = ajax.responseText;
		   }
		   if (getinfo!=""&&$(returnDiv).innerHTML!=getinfo){
	      $(returnDiv).innerHTML = getinfo;}
		  }
	}
}

// 在屏幕中央显示信息,带延时
function ShowTimeMessage(showHTML,showtime)
  {
	if (document.getElementById("ToShowMessagebox") == null)
	{var mesDivObj=document.createElement("div");
	mesDivObj.setAttribute('id','ToShowMessagebox');
	mesDivObj.style.position="absolute";
	mesDivObj.style.border="1px solid #333333";
	mesDivObj.style.background="#eeeeee";
	mesDivObj.style.filter="Alpha(Opacity=80);";
	mesDivObj.style.padding="4px 10px 4px 10px";
    document.body.appendChild(mesDivObj);}
	else
	{mesDivObj = document.getElementById('ToShowMessagebox')}
	mesDivObj.style.left="0";
	mesDivObj.style.top="0";
	mesDivObj.style.display="block";
	mesDivObj.innerHTML = showHTML
	mesDivObj.style.left = (document.body.clientWidth - mesDivObj.style.width) / 2;
	mesDivObj.style.top=((document.body.clientHeight - mesDivObj.style.height) / 2)+document.documentElement.scrollTop;//+document.body.scrollTop屏幕滚动高度 处理高度
	;
	if (parseInt(showtime)>0){setTimeout("document.getElementById('ToShowMessagebox').style.display='none';",parseInt(showtime));}
	
 }
//复制文本到剪贴板并显示信息提示
function CopyTextToClipBoard(CopyText){
	window.clipboardData.setData("Text",CopyText);
	ShowTimeMessage(CopyText+"已经复制到剪贴板!",1200)
}

//当前光标处插入字符
function insertTxtTo(toOBJ,toInsText){
	document.getElementById(toOBJ).focus();
	with(document.selection.createRange()) 
	{text = toInsText; collapse(); select();} 
}
//元素上添加css类
function addClass(target, classValue)
{
var pattern = new RegExp("(^| )" + classValue + "( |$)");
  if (!pattern.test(target.className))
  {if (target.className == ""){target.className = classValue;}
  else{target.className += " " + classValue;}}
return true;
}
//元素上去掉css类
function removeClass(target, classValue)
{
  var removedClass = target.className;
  var pattern = new RegExp("(^| )" + classValue + "( |$)");
  removedClass = removedClass.replace(pattern, "$1");
  removedClass = removedClass.replace(/ $/, "");
  target.className = removedClass;
  return true;
}
//切换Tab
function cTab(tabId,tabsIds,contentIds,tabNum){
for(var i=1; i<tabNum+1; i++){
		removeClass($(tabsIds + i), "sel");
		addClass($(contentIds + i), "hidden");
	}	
	addClass($(tabsIds+ tabId), "sel");
	removeClass($(contentIds + tabId), "hidden");
}

//给元素添加事件
function addEvent(oElement,sEvent,func){
if (oElement.attachEvent){
        oElement.attachEvent(sEvent,func);
    }
    else{
        sEvent=sEvent.substring(2,sEvent.length);
        oElement.addEventListener(sEvent,func,false);
    }
}
function batchAddEvent(obj)
{	
	var el=GetChildElement(obj, 'li');

	for (var i=0;i<el.length;i++){
		addEvent(el[i],"onclick",cTab());
		//alert(el[i])
	}
}
// 得到子元素
function GetChildElement(obj, sTag){
	var el;
	el=obj.getElementsByTagName(sTag);
	//el.length
	return el
}
// 关闭弹出层
function closeWithDiv(obj){
	if (obj==null){massage_box.style.display="none";}
	else {obj.style.display="none";}
	document.getElementById("bgDiv").style.display="none";
	document.body.removeChild(document.getElementById("bgDiv"));
}



//检测链接如果是目标为jpg图片,则图片数组添加自定义打开窗口的事件
var theOpenImg,UrlimgObj;
function ImgOpenInWinInt(){
	for(i=0;i<document.getElementsByTagName("A").length;i++){
		if(document.getElementsByTagName("A")[i].target=='_blank'&&document.getElementsByTagName("A")[i].nameProp.toLowerCase().indexOf("jpg")>-1){
			theOpenImgUrl = document.getElementsByTagName("A")[i].href;
			eval("document.getElementsByTagName('A')[i].attachEvent('onclick', function(){OpenFullSizeWindow('"+theOpenImgUrl+"','','');return false;});");
		}
	}
}
function checkImg(theURL,winName){
  if (typeof(imgObj) == "object"){
    // 是否已取得了图像的高度和宽度
    if ((imgObj.width != 0) && (imgObj.height != 0))
      // 根据取得的图像高度和宽度设置弹出窗口的高度与宽度，并打开该窗口
      // 其中的增量 20 和 30 是设置的窗口边框与图片间的间隔量
      OpenFullSizeWindow(theURL,winName, ",width=" + (imgObj.width+30) + ",height=" + (imgObj.height+30));
    else
      // 因为通过 Image 对象动态装载图片，不可能立即得到图片的宽度和高度，所以每隔100毫秒重复调用检查
      setTimeout("checkImg('" + theURL + "','" + winName + "')", 100)
  }
}

function OpenFullSizeWindow(theURL,winName,features) {
  var aNewWin, sBaseCmd;
  sBaseCmd = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,";
  // 调用是否来自 checkImg 
  if (features == null || features == ""){
    imgObj = new Image();
    imgObj.src = theURL;
    checkImg(theURL, winName)
  }
  else{
    aNewWin = window.open('inc_newslistshow.asp?action=getImg&image='+theURL,winName, sBaseCmd + features);
    aNewWin.focus();
  }
}

