﻿<!--
	
function isCharsInBag (s, bag)
{ 
var i;
// Search through string's characters one by one.
// If character is in bag, append to returnString.

for (i = 0; i < s.length; i++)
{ 
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) return false;
}
return true;
}

function isEmpty(s)
{ 
return ((s == null)||(s.length == 0)); 
}
/***********************************
函数名:lTrim(str)
作用:去掉字符串左边的空格
编写时间:2004-01-09
编写人:高骏
************************************/
	
function lTrim(str)
{
if (str.charAt(0) == " ")
{
//如果字串左边第一个字符为空格
str = str.slice(1);//将空格从字串中去掉
//这一句也可改成 str = str.substring(1, str.length);
str = lTrim(str); //递归调用
}
return str;
}
/***********************************
函数名:rTrim(str)
作用:去掉字串右边的空格
编写时间:2004-01-09
编写人:高骏
************************************/

function rTrim(str)
{
var iLength;

iLength = str.length;
if (str.charAt(iLength - 1) == " ")
{
//如果字串右边第一个字符为空格
str = str.slice(0, iLength - 1);//将空格从字串中去掉
//这一句也可改成 str = str.substring(0, iLength - 1);
str = rTrim(str); //递归调用
}
return str;
}
/***********************************
函数名:Trim(str)
作用:去掉字串左边和右边的空格
编写时间:2004-01-09
编写人:高骏
************************************/
function trim(str)
{
return lTrim(rTrim(str));
}
/***********************************
函数名:ismail(mail)
作用:验证email
编写时间:2004-01-09
编写人:高骏
************************************/
function isemail(email)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return true ;
}
//alert("Invalid E-mail Address! Please re-enter.")
return false;
}
/***********************************
函数名:isNum(s)
作用:验证输入是数字
编写时间:2004-01-09
编写人:高骏
************************************/
function isNum(s)
{
if(!isCharsInBag (s, "0123456789")){
//alert("请检查一下您输入的是否为数字！");
return false;
}
return true;
}
/***********************************
函数名:textCounter(field, countfield, maxlimit)
作用:限制textArea输入字数
编写时间:2005-05-11
编写人:高骏
************************************/
function textCounter(field, countfield, maxlimit) { 
// 定义函数，传入3个参数，分别为表单区的名字，表单域元素名，字符限制； 
if (field.value.length > maxlimit) 
//如果元素区字符数大于最大字符数，按照最大字符数截断； 
field.value = field.value.substring(0, maxlimit); 
else 
//在记数区文本框内显示剩余的字符数； 
countfield.value = maxlimit - field.value.length; 
} 
/***********************************
函数名:textCounter(field, countfield, maxlimit)
作用:限制textArea输入字数(对textCounter的简化)
编写时间:2005-08-22
编写人:焦斌
************************************/
function textLimit(field,maxlimit)
{
   if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit); 
}
/***********************************
函数名:ImgResize(o)
作用:使图片适应大小
编写时间:2005-05-13
编写人:高骏
************************************/
/* 判断阅览器类型 */
var ua = window.navigator.userAgent;
var ie = /msie/ig.test(ua);
var ie55up = /msie (5\.5|6)/ig.test(ua);

function ImgResize(o){
   hiddenImg= new Image();
   hiddenImg.src = o.src;
   if (hiddenImg.width>580) {
   	o.width=580;
   } else {
   	o.width=hiddenImg.width;
   }
   //o.style.display='';
}
/***********************************
函数名:copyUrl(content,title)
作用:复制连接到剪切板中
编写时间:2005-05-13
编写人:高骏
************************************/
function copyUrl(content,title){
	content+= '\r\n'+title;
	window.clipboardData.setData("Text",content);
	alert("本文标题和地址已复制到剪贴版!");
}
//-->
/***********************************
函数名:addme(title)
作用:增加到收藏夹
编写时间:2006-02-18
编写人:焦斌
************************************/

function addme(title,url){
	
 url = url;//document.URL;
 title =title;
 if (title=="") title="xblog";
 window.external.AddFavorite(url,title);
}
/***********************************
函数名:showWindow()
作用:增加到收藏夹
编写时间:2006-02-18
编写人:焦斌
************************************/
function showWindow(Url,width,height){
	window.showModelessDialog(Url,this,"unadorned:off;status:off;dialogWidth:"+width+";dialogHeight:"+height);
	
}

function copyRss(content,title){
	content+= '\r\n'+title;
	window.clipboardData.setData("Text",content);
	alert("本个人门户的Rss地址已复制到剪贴版!");
}
function copyTrackBack(content){
	window.clipboardData.setData("Text",content);
	alert("本文的trackBack地址已复制到剪贴版!");
}

//按大图区的尺寸，等比显示图片
function setImgWH(imgurl,imgDispW,imgDispH){
	var imgRect=getImageWidthAndHeight(imgurl);
	if(imgRect.width==0){
	   imgRect.onload=function(){
          showRatio(this);
	   }
	}else{
       showRatio(imgRect);
    }
    function showRatio(imgRect){
      var imgR=imgRect.width/imgRect.height;
      if(imgR>=imgRatio){
       if(imgRect.width>=imgDispW){
          document.getElementById("sk_puff").style.width=imgDispW+"px";
		  document.getElementById("sk_puff").style.height=imgDispW/imgR+"px";
	      }else{
	    document.getElementById("sk_puff").style.width=imgRect.width+"px";
		document.getElementById("sk_puff").style.height=imgRect.height+"px";
	  }
     }else{
       if(imgRect.height>=imgDispH){
        document.getElementById("sk_puff").style.height=imgDispH+"px";  
        document.getElementById("sk_puff").style.width=imgDispH*imgR+"px";
	   }else{
        document.getElementById("sk_puff").style.height=imgRect.height+"px";
        document.getElementById("sk_puff").style.width=imgRect.width+"px";
	   }
     }
   }
}

//获得图片实际大小 
function getImageWidthAndHeight(imgurl) {
var img=new Image();
img.src=imgurl;
return img;
}
//更新认证码
function UpdateCode()
{
	objImg = document.getElementById("rzimg");
	var src = objImg.src;	
	var oRandom = Math.random() * 1000;
	re = /changeId=\d{3}/;
	arr = re.exec(src);
	if(arr == null)
		src += "?changeId=" + oRandom;
	else
		src = src.replace(src.substr(arr.index,13),"changeId=" + oRandom);	
	objImg.src = src;
}
function calculateRealLength(content){
	var reg=/[a-zA-Z0-9]/;
	var chineseString=content;
	while (reg.test(chineseString)) {
		 chineseString=chineseString.replace(reg,"");
	}
	reg=/[^a-zA-Z0-9]+/
	var nonChineseString=content.replace(reg,"");
	var ret=chineseString.length*2+nonChineseString.length;
	return ret;
	
}
//按宽度，等比显示图片
function setImgW(imgId,imgurl,imgDispW){
    var imgRect=getImageWidthAndHeight(imgurl);
	if(imgRect.width==0){
	   imgRect.onload=function(){
          showRatio(this);
	   }
	}else{
       showRatio(imgRect);
    }
    function showRatio(imgRect){
       if(imgRect.width>=imgDispW){
          document.getElementById(imgId).style.width=imgDispW+"px";
	      }else{
	    document.getElementById(imgId).style.width=imgRect.width+"px";
	  }
   }
}


