/**
 * Common Library
 */
 
/**
 * 取得唯一数
 */
function getIdNum()
{
	var today,hour,second,minute,year,month,date;
	var strDate ;
	today=new Date();
	year = today.getYear();
	month = today.getMonth()+1;
	date = today.getDate();
	hour = today.getHours();
	minute =today.getMinutes();
	second = today.getSeconds();
	strDate=""+year+month+date+hour+minute+second+parseInt(Math.random()*100);
	return strDate;
}

/**
*	获得指定的对象
*	@param idname 对象ID
*	return Object
*/
 function $(idname){
	if(document.getElementById){ 
		return document.getElementById(idname); 
	}else if(document.all) { 
		return document.all[idname];
	}else if(document.layers) {
		return document.layers[idname];	
	}else{
		return null; 
	}
}


/**
 * 隐藏指定ID的对象
 * 
 * @param string ObjId:对象ID
 */
function hidObj(ObjId)
{
	$(ObjId).style.display="none";
}

/**
 * 显示指定ID的对象
 * 
 * @param string ObjId:对象ID
 */
function showObj(ObjId)
{
	$(ObjId).style.display="";
}


/**
*	判断对象
*	@param value 检测对象
*	return boolen
*/
function is_null(object){
	return (object == "" || object == null || object == "undefined");
}

/**
*	获得客户端区域高度和宽度
*	return Object
*/
function getWinSize() 
{
	var windowWidth, windowHeight;
	if(self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	return {h:windowHeight,w:windowWidth};
}

/**
*	获得URL中指定参数的值
*	@param paramname URL中参数名称
*	return String
*/
function getParam(paramname){
	var tmpArr,QueryString;
	var URL = document.location.toString();
	
	if(URL.lastIndexOf("?")!=-1){
		QueryString= URL.substring(URL.lastIndexOf("?")+1,URL.length);
		tmpArr=QueryString.split("&");
		for (i=0;i<tmpArr.length;i++){
			var re = new RegExp("("+paramname+")=(.*)","ig");
			if(re.exec(tmpArr[i])){
				if (RegExp.$2.length > 0){
					return RegExp.$2;
				}
			}
		}
	}
	return 0;
}

function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str)
{
	return str.replace(/(^\s*)/g, "");
}
function rtrim(str)
{
	return str.replace(/(\s*$)/g, "");
}
/**计算指定的输入框还能输入多少个字
 * 
 */
function writeLeave(formElement, objShow, maxl)
{
	//formElement.value=ltrim(formElement.value);
	if(getStringLen(formElement.value,1) > maxl)
	{
		formElement.value =cutString(formElement.value,maxl,1);
		try
		{
			objShow.value = 0;
		}catch (e){}
		try
		{
			objShow.innerHTML=0;
		}catch (e){}
	}
	else
	{
		try
		{
			objShow.value = maxl - getStringLen(formElement.value,1);
		}catch (e){}
		try
		{
			objShow.innerHTML=maxl - getStringLen(formElement.value,1);
		}catch (e){}

	}
}

/**
 * 字符串截取
 * 
 * 待处理的串str
 * 截取长度 cutLentth
 * 汉字的长度 备用
 * 
 */
function cutString(str,cutLentth,gbkLen)
{
	return str.substring(0,cutLentth);
}

/**
 * 计算给定字符串的长度
 * 
 * str字符串
 * 一个汉字的长度 gbkLen（当前不可用，将来用）
 */
function getStringLen(str,gbkLen)
{
	str = ltrim(str);
	if(2==gbkLen)
	{
		str=str.replace(/[^\x00-\xff]/g,"**");
	}
	return str.length;
}


function setPage()
{
	this.commTplCallBack="";
	/**
	 * 获取翻页结果
	 * 
	 * @param integer $total:一共多少页
	 * @param integer $pagesize:每页显示的记录数
	 * @param integer $page:当前是第几页
	 * @param integer $showPages:翻页条显示多少个页 默认比如说 1、2、3、4、5、6、7、8、9、10
	 * @param integer $bigMoveStep:快速移动的步长：比如说前10页
	 * 
	 */
	this.init=function(total,pagesize,page,showPages,bigMoveStep)
	{
		total=parseInt(total);
		pagesize=parseInt(pagesize);
		page=parseInt(page);
		if(page<=0)
		{
			page=1;
		}
		showPages=parseInt(showPages);
		bigMoveStep=parseInt(bigMoveStep);
		this.returnpage=new pageAttr();
		var totalpage=1;
	    if (total%pagesize)
	    {
	        totalpage = parseInt(total/pagesize) + 1;
	    }
	    else
	    {
	        totalpage = parseInt(total/pagesize);
	    }
	    if (page >= totalpage)
	    {
	        page = totalpage;
	    }
	    var firstPage=1;
	    var lastPage=totalpage;
	    var prePage = page -1;
	    var showPrePage=true;
	    if (prePage <= 0)
	    {
	        showPrePage=false;
	    }
	    var nextPage = page +1;
	    var showNextPage=true;
	    if (nextPage > totalpage)
	    {
	        showNextPage=false;
	    }
	    
	    var bigPrePage=page-bigMoveStep;
	    var showBigPrePage=true;
	    if(bigPrePage<= 0)
	    {
	        showBigPrePage=false;
	    }
	    var BigNextPage = page +bigMoveStep;
	    var showBigNextPage=true;
	    if (BigNextPage > totalpage)
	    {
	        showBigNextPage=false;
	    }
	    var beginMove=0;
	    var endMove=0;
	    if(showPages%2)
	    {
	        beginMove=parseInt(showPages/2)-1;
	        endMove=parseInt(showPages/2);
	    }
	    else
	    {
	        beginMove=parseInt(showPages/2);
	        endMove=parseInt(showPages/2);
	    }
	
	    var beginPage=page-beginMove;
	    var endPage=page+endMove;
	    if (beginPage <= 0)
	    {
	        beginPage=1;
	        if(endPage+(beginMove-page)<= totalpage)
	        {
	        	endPage=endPage+(beginMove-page);
	        }
	    }
	    if (endPage > totalpage)
	    {
	        endPage=totalpage;
	        if(beginPage-(endPage-totalpage)>=0)
	        {
	        	beginPage=beginPage-(endPage-totalpage);
	        }
	    }
		    	    
	    this.returnpage.firstPage=firstPage;  //第一页
	    this.returnpage.lastPage=lastPage; //最后页
	    this.returnpage.prePage=prePage;//上一页
	    this.returnpage.nextPage=nextPage;//下一页
	    this.returnpage.showPrePage=showPrePage;//是否显示上一页
	    this.returnpage.showNextPage=showNextPage;//是否显示下一页
	    this.returnpage.bigPrePage=bigPrePage;//前N页
	    this.returnpage.showBigPrePage=showBigPrePage;//是否显示前N页
	    this.returnpage.BigNextPage=BigNextPage;//后N页
	    this.returnpage.showBigNextPage=showBigNextPage;//是否显示后N页
	    this.returnpage.page=page;
	    this.returnpage.beginPage=beginPage;
	    this.returnpage.endPage=endPage;
	    this.returnpage.totalpage=totalpage;
	    
	    /*
	    pagestr="";
	    pagestr+=firstPage+"\n";
	    pagestr+=lastPage+"\n";
	    pagestr+=prePage+"\n";
	    pagestr+=nextPage+"\n";
	    pagestr+=showPrePage+"\n";
	    pagestr+=showNextPage+"\n";
	    pagestr+=bigPrePage+"\n";
	    pagestr+=showBigPrePage+"\n";
	    pagestr+=BigNextPage+"\n";
	    pagestr+=showBigNextPage+"\n";
	    pagestr+=page+"\n";
	    pagestr+=beginPage+"\n";
	    pagestr+=endPage+"\n";
	    */
	}

	this.setTplCallBack=function(callbackName)
	{
		this.commTplCallBack=callbackName;
	}
	this.show=function()
	{

		if(""!=this.commTplCallBack)
		{
			strjs=this.commTplCallBack+"(this.returnpage);";
			eval(strjs);
		}
	}
}

function filterPage(page,totalpage)
{
	try
	{
		page=parseInt(page);
	}
	catch (e)
	{
		page=1;
	}
	if(isNaN(page)||page<=0)
	{
		page=1;
	}
   if(page>totalpage&&totalpage>0)
	{
		page=totalpage;
	}

	return page;
}

function pageAttr()
{
	this.firstPage="";
	this.lastPage="";
	this.prePage="";
	this.nextPage="";
	this.showPrePage="";
	this.showNextPage="";
	this.bigPrePage="";
	this.showBigPrePage="";
	this.BigNextPage="";
	this.showBigNextPage="";
	this.page="";
	this.beginPage="";
	this.endPage="";
	this.totalpage="";
}

/**
 * 获取同一个className的所有object
 */
$class = function(className, parentElement) 
{
  var children = ($(parentElement) || document).getElementsByTagName('*');
  var ret =[];
  for (var i=0;i<children.length;i++)
  {
      if (children[i].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
      {
          ret.push(children[i]);
      }
  }
  return ret;
}
/*
 * Cookie的操作
 * 在ie和moz中可运行
 */
function Cookie(tran){
  this.tran=tran;
  this.setValue=function(name,value,hours,path,domain,secure){
    var str=new String();
    var nextTime=new Date();
    nextTime.setHours(nextTime.getHours()+hours);
    var val=this.tran==true?escape(value):value;
    str=name+"="+val;
    if(hours){
      str+=";expires="+nextTime.toGMTString();}
    if(path){
      str+=";path="+path;}
    if(domain){
      str+=";domain="+domain;}
    if(secure){
      str+=";secure";}
    document.cookie=str;
  };
  this.getValue=function(name){
    var rs=new RegExp("(^|)"+name+"=([^;]*)(;|$)","gi").exec(document.cookie),tmp;
    if(tmp=rs){
      return this.tran==true?unescape(tmp[2]):(tmp[2]);}
    return null;
  }
}


function getConfrmStr(strMsg)
{
	var confirmDialog="";
	confirmDialog+="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
	confirmDialog+="<html xmlns=\"http://www.w3.org/1999/xhtml\">";
	confirmDialog+="<head>";
	confirmDialog+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />";
	confirmDialog+="<link rel=\"stylesheet\" type=\"text/css\" href=\"http://image2.sina.com.cn/vblog/css/vplay0322/vplay.css\" />";
	confirmDialog+="<title>播客提示</title>";
	confirmDialog+="<style>";
	confirmDialog+=".v_ceng_top{ height:42px; padding-left:7px; position:absolute; top:45px;}";
	confirmDialog+=".v_ceng_top li{ float:left; }";
	confirmDialog+=".v_ceng_top li a{ text-align:center; display:block; height:42px; line-height:42px; float:left; overflow:hidden}";
	confirmDialog+=".v_ceng_top .li1{ width:109px; overflow:hidden}";
	confirmDialog+=".v_ceng_top .li2{ width:90px; overflow:hidden}";
	confirmDialog+=".v_ceng_top .li1 a:link{ width:109px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit1.gif) no-repeat center top}";
	confirmDialog+=".v_ceng_top .li1 a:visited{ width:109px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit1.gif) no-repeat center top;}";
	confirmDialog+=".v_ceng_top .li1 a:hover,";
	confirmDialog+=".v_ceng_top .li1 .a1:link,";
	confirmDialog+=".v_ceng_top .li1 .a1:visited,";
	confirmDialog+=".v_ceng_top .li1 .a1:hover,";
	confirmDialog+=".v_ceng_top .li1 .a1:active";
	confirmDialog+=".v_ceng_top .li1 .a1{ width:109px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit11.gif) no-repeat center 3px; color:#8f8f8f;}";
	confirmDialog+=".v_ceng_top .li1 a:active{ width:109px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit11.gif) no-repeat center 3px;}";
	confirmDialog+=".v_ceng_top .li2 a:link{ width:90px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit2.gif) no-repeat left bottom}";
	confirmDialog+=".v_ceng_top .li2 a:visited{ width:90px;background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit2.gif) no-repeat left bottom}";
	confirmDialog+=".v_ceng_top .li2 a:hover,";
	confirmDialog+=".v_ceng_top .li2 .a2:link,";
	confirmDialog+=".v_ceng_top .li2 .a2:visited,";
	confirmDialog+=".v_ceng_top .li2 .a2:hover,";
	confirmDialog+=".v_ceng_top .li2 .a2:active{ width:90px;background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit22.gif) no-repeat left top; color:#565656;}";
	confirmDialog+=".v_ceng_top .li2 a:active{ width:90px;background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_tit22.gif) no-repeat left top}";
	confirmDialog+=".v_ceng{ background:#EFEFEF;  border:3px solid #E3E3E3;}";
	confirmDialog+=".v_ceng .bg{ background:#EFEFEF url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_bg.gif) repeat-x left top; border:1px solid #6D6D6D;  padding:22px 21px;}";
	confirmDialog+=".v_ceng .line{ height:2px; background:url(http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_line.gif) repeat-x left top; width:100%; margin:0px auto; overflow:hidden;}";
	confirmDialog+=".v_ceng .tit{ font-size:14px; font-weight:600; color:#565656; height:20px;}";
	confirmDialog+=".v_ceng .tit1{ color:#565656; height:14px; padding-top:10px;}";
	confirmDialog+=".v_ceng .fc1{ color:#565656;}";
	confirmDialog+=".v_ceng .fc2{ color:#565656;}";
	confirmDialog+=".v_ceng .txt{  background:#fff; border:1px solid #969CC2; height:17px; line-height:17px; padding:2px 2px 0px;color:#8F8F8F;}";
	confirmDialog+=".v_ceng .txt1{ background:#fff; border:1px solid #969CC2; line-height:18px; padding:3px;color:#8F8F8F;font-size:12px; }";
	confirmDialog+=".v_ceng .txt2{height:12px; line-height:11px; width:20px; border:1px solid #9D9D9D; overflow:hidden; font-size:9px; font-family:Verdana; color:#565656; background:#fff; }";
	confirmDialog+=".v_ceng_fenye{ width:96%; height:15px; padding-top:10px; text-align:right; margin:0px auto; clear:both;}";
	confirmDialog+=".v_ceng_fenye{ vertical-align:baseline}";
	
	confirmDialog+="#v_ceng_sp{width:293px;}";
	confirmDialog+="#v_ceng_sp .bg{ padding:22px 12px;}";
	confirmDialog+="#v_ceng_sp .line{ margin:2px 0px 5px;}";
	confirmDialog+="#v_ceng_sp .list li{ height:22px; line-height:22px;}";
	confirmDialog+="#v_ceng_sp .list .li1{ float:left; width:206px; overflow:hidden; text-overflow:ellipsis;white-space:nowrap;}";
	confirmDialog+="#v_ceng_sp .list .li1 a:link,";
	confirmDialog+="#v_ceng_sp .list .li1 a:visited{ color:#565656;}";
	confirmDialog+="#v_ceng_sp .list .li1 input{ vertical-align:text-bottom; margin-right:3px;}";
	confirmDialog+="#v_ceng_sp .list .li2{ float:right; width:45px; white-space:nowrap; padding-top:0px !important;*+padding-top:4px;*padding-top:5px;height:14px; color:#000; }";
	confirmDialog+="#v_ceng_sp .list .li2 img{ vertical-align:middle;}";
	confirmDialog+="#v_ceng_sp .space5{ height:10px;}";
	
	confirmDialog+="#v_ceng_jubao { width:367px;}";
	
	confirmDialog+="#v_ceng_tishi { width:312px;}";
	confirmDialog+="#v_ceng_tishi .bg{ height:125px;}";
	
	confirmDialog+="#v_ceng_share { width:470px;}";
	confirmDialog+="#v_ceng_share .bg{ height:auto;}";
	confirmDialog+="#v_ceng_share table { width:100%}";
	confirmDialog+="#v_ceng_share table .td1{height:20px;}";
	confirmDialog+="#v_ceng_share table  img{ vertical-align:top}";
	confirmDialog+="#v_ceng_share .fc1{ color:#565656;}";
	confirmDialog+="#v_ceng_share .fc2{ color:#565656; padding-top:3px;}";
	confirmDialog+="#v_ceng_share .txt{  background:#fff; border:1px solid #969CC2; width:355px;height:17px; line-height:17px; padding:2px 2px 0px;color:#8F8F8F;}";
	confirmDialog+="#v_ceng_share .txt1{ background:#fff; border:1px solid #969CC2; width:355px; line-height:18px; padding:3px;color:#8F8F8F;font-size:12px; }";
	
	
	confirmDialog+="#v_ceng_shipin{width:293px;}";
	confirmDialog+="#v_ceng_shipin .bg{ padding:22px 10px 0px;}";
	confirmDialog+="#v_ceng_shipin .list1{ height:372px; width:100%; }";
	confirmDialog+="#v_ceng_shipin .list1 ul{padding:12px 0px 0px 6px;   overflow:hidden; clear:both; height:66px;}";
	confirmDialog+="#v_ceng_shipin .list1 li{ float:left; }";
	confirmDialog+="#v_ceng_shipin .list1 .li1 .add{  position:absolute;  z-index:20; width:16px;height:16px; }";
	confirmDialog+="#v_ceng_shipin .list1 .li1 .add img{ padding:2px; /* visibility:hidden; */}";
	confirmDialog+="#v_ceng_shipin .list1 .li2 .bg{}";
	
	confirmDialog+="#v_ceng_shipin .list1 .li3{width:176px; overflow:hidden;}";
	confirmDialog+="#v_ceng_shipin .list1 .li3 .p1{ height:16px; line-height:16px; width:100%;overflow:hidden; /* text-overflow:ellipsis;white-space:nowrap; */ margin-top:12px; padding-left:3px;}";
	confirmDialog+="#v_ceng_shipin .list1 .li3 .p2{ height:15px; line-height:16px; overflow:hidden; font-size:10px; font-family:Arial; padding:1px 0px 2px 3px;}";
	confirmDialog+="#v_ceng_shipin .list1 .li3 .p3{  padding:0px 0px 0px 3px;}";
	confirmDialog+="#v_ceng_shipin .list1_fenye{ width:96%; height:17px; padding-top:3px; text-align:right; border-top:1px solid #DADADA; margin:0px auto; clear:both; }";
	
	confirmDialog+="</style>";
	confirmDialog+="</head>";
	
	confirmDialog+="<body>";
	
	confirmDialog+="<!-- 温馨提示 -->";
	confirmDialog+="<div id=\"v_ceng_tishi\" class=\"v_ceng\">";
	confirmDialog+="	<div class=\"bg\">";
	confirmDialog+="	  <div class=\"info\">";
	confirmDialog+="			<div class=\"tit\">温馨提示</div>";
	confirmDialog+="			<div class=\"line\"></div>";
	confirmDialog+="	        <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	confirmDialog+="              <tr>";
	confirmDialog+="                <td height=\"30\">&nbsp;</td>";
	confirmDialog+="              </tr>";
	confirmDialog+="              <tr>";
	confirmDialog+="                <td align=\"center\">"+strMsg+"</td>";
	confirmDialog+="              </tr>";
	confirmDialog+="              <tr>";
	confirmDialog+="                <td height=\"30\">&nbsp;</td>";
	confirmDialog+="              </tr>";
	confirmDialog+="              <tr>";
	confirmDialog+="                <td align=\"center\"><input type=\"image\" onclick=\"parent.vDialog.reset();return false\" src=\"http://image2.sina.com.cn/vblog/images/vplay0322/e_ceng_btn_ok.gif\" align=\"absmiddle\"/></td>";
	confirmDialog+="              </tr>";
	confirmDialog+="            </table>";
	confirmDialog+="	  </div>";
	confirmDialog+="	</div>";
	confirmDialog+="</div>";
	
	confirmDialog+="</body>";
	confirmDialog+="</html>";
	
	return confirmDialog;
	
}

/**
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

 /**
 *压缩换行
 *参数s:要处理的字符串
 *参数n:保留的空格数
 *返回结果：处理后的字符串;
 */
 function compressNL(s,n){
	var c="\r\n";
	s=compressChar(c,s,n);
    s=s.replace(/(\r\n)$/g,"");
    return s;
 }
 
 /**
 *压缩空格
 *参数s:要处理的字符串
 *参数n:保留的空格数
 *参数m:超过n个后压缩保留的空格数
 *返回结果：处理后的字符串;
 */
 function compressSpace(s,n,m){
	if(trim(s)==""){
		return "";
	}
    n=parseInt(n);
    m=parseInt(m);
	var c=' ';
    var tn=n+1,re;
	var cm=mkstring(c,m);
	re=eval("/([ |　]{"+tn+",})/g");
	s = s.replace(re,cm);

	var cn=mkstring(c,n);
	re=eval("/([ |　]{"+n+"})/g");
	s = s.replace(re,cn);
    return s;
 }
function mkstring(c,m){
    var r="";
    for(var i=0;i<m;i++){
        r+=c;
    }
    return r;
}
 /**
 *压缩字符或字符串
 *参数c:要压缩的字符或字符串
 *参数s:要处理的字符串
 *参数n:保留的空格数
 *参数m:超过n个后压缩保留的数们
 *返回结果：处理后的字符串;
 */
 function compressChar(c,s,n,m){
    n=parseInt(n);
    if(n==0){    
    	return s.replace(/(\r\n)/mg, "");
    }
	var r='',k=0;
	ss = s.split(c);	
	for(var i=0;i<ss.length;i++)
	{
		j=i+1;
		var ch=ss[i];
		if(ss[i]==""){
			k++;
			if(k>=n){
				r+=ch;
			}else{
			r+=ch+c;
			}
		}else{
			if(ss[j]!=undefined){d=c;}else{d="";}
			r+=ch+d;
			k=0;
		}

	}
	return r;
 }

 
 function space2nbsp(s){
	return s.replace(/([ |　]{2})/g," &nbsp;");

 }

 function nl2br(s){
	return s.replace(/([\n])/g,"<br>");

 }
