String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll  = function(s1,s2){
	return this.replace(new RegExp(s1,"gm"),s2);   
}  

function log_out(url){
	ht = top.document.getElementsByTagName("body");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('您确定要退出登陆吗？')){
		ht[0].style.filter = "";
		top.location.href="/Program/login.php?do=logout&referer="+url;
	}else{
		ht[0].style.filter = "";
	}
}

function setCWinHeight(obj){
  var cwin=document.getElementById(obj);
  if (document.getElementById)  {
    if (cwin && !window.opera)    {
      if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
        cwin.height = cwin.contentDocument.body.offsetHeight; 
      else if(cwin.Document && cwin.Document.body.scrollHeight)
        cwin.height = cwin.Document.body.scrollHeight;
    }
  }
}

function ifres_resize(ifr){
	$(ifr).height($(window).height()-50);
}


function IsDigit(e){
	var key = window.event ? e.keyCode : e.which;
	return ((key >= 46) && (key <= 57));
}

function IsEmail(varEmail)
{
	if(varEmail == "") return false;
	if(varEmail.indexOf("@") < 0 || varEmail.indexOf(".") < 0) return false;
	return true;
}

function IsNumeric(n){
	return isNaN(n) ? false : true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
/* 参数定义：
	datas 要排序的数组，其中每个元素是一个JSON对象{}
	field 要排序的元素的字段名，将使用该字段进行排序
	type  排序类型，如果为"down"则为降序排序,否则升序
*/
function SortData(datas, field, type) {
	SortFun.field = field;
	datas.sort(SortFun);
	if (type == "down") {
		datas.reverse();
	}
}
function SortFun(data1, data2) {
	if (data1[SortFun.field] > data2[SortFun.field]) {
		return 1;
	}
	else if (data1[SortFun.field] < data2[SortFun.field]) {
		return -1;
	}
	return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////
// 导航栏搜索
function search_box(x){
	for(var i=1;i<=7;i++){
		if(i==x){
			$("#search_box_tab"+i).removeClass();
			$("#search_box_tab"+i).addClass("tab_selected");
			$(".search_box_body").html($("#search_box_"+i).html());
		}else{
			$("#search_box_tab"+i).removeClass();
			$("#search_box_tab"+i).addClass("tab_blank");
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////
// js页码函数
/** 参数定义：
	total:总记录数
	page:当前页数
	pagenum:每页数量
	func:使用函数
	argc:func使用的参数
*/
function pagenav(total,page,pagenum,func){
	if(page==0) page=15;
	var totalpage = Math.ceil(total/pagenum);
	var startnum = (page-1)*pagenum;
	var endnum = page*pagenum;
	if(endnum>total) endnum = total;
	s = "显示第 "+startnum+"-"+endnum+" 条记录 共 "+total+" 条记录 ";
	if(page==1 && totalpage>page){
		s += "首页 上一页 <a href=\"javascript://\" onclick=\""+func+"("+(page+1)+")\">下一页</a> <a href=\"javascript://\" onclick=\""+func+"("+totalpage+")\">尾页</a>";
	}else if(page==1){
		s += "";
	}else if(page>=totalpage){
		s += "<a href=\"javascript://\" onclick=\""+func+"(1)\">首页</a> <a href=\"javascript://\" onclick=\""+func+"("+(page-1)+")\">上一页</a> 下一页 尾页";
	}else{
		s += "<a href=\"javascript://\" onclick=\""+func+"(1)\">首页</a> <a href=\"javascript://\" onclick=\""+func+"("+(page-1)+")\">上一页</a> <a href=\"javascript://\" onclick=\""+func+"("+(page+1)+")\">下一页</a> <a href=\"javascript://\" onclick=\""+func+"("+totalpage+")\">尾页</a>";
	}
	
	if(totalpage > 1){
		if(totalpage > 100){
			s += " 到第 <input name=\"go_page\" id=\"go_page\" type=\"text\" value=\""+page+"\" maxlength=\"5\" style=\"width:35px;\" /> 页 ";
			s += "<input type=\"submit\" name=\"go_button\" id=\"go_button\" value=\"GO\" onclick=\"" + func + "('go_page')\" />";
		}else{
			s += " 到第 <select onchange=\""+func+"(this.value)\">";
			for(i=1; i<=totalpage; i++){
				s += "<option value=\""+i+"\""+(page==i ? " selected" : "")+">"+i+"</option>";
			}
			s += "</select> 页";
		}
	}
	s += " 共 " + totalpage + " 页 ";
	return s;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////
// 在json中查找
function find_json_value(json,field,val,t){
	if(typeof(t)=="undefined") t = "title";
	for(z=0; z<json.length; z++){
		if(json[z][field] == val){
			return json[z][t];
		}
	}
	return null;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////
// 显示或联系Loading信息
function show_loading(t){
	$("#loading-mask").css("display", t ? "block" : "none");
	$("#loading-dialog").css("display", t ? "block" : "none");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////
// 标签切换
function change_tab(divid,id,totalnum){
	for(i=0;i<=totalnum;i++){
		if(document.getElementById("tab_" + divid + "_a_" + i) == null) continue;
		if(i == id){
			$("#tab_" + divid + "_a_" + i).removeClass("tab_unselected");
			$("#tab_" + divid + "_a_" + i).addClass("tab_selected");
			$("#tab_" + divid + "_b_" + i).css("display", "");
		}else{
			$("#tab_" + divid + "_a_" + i).removeClass("tab_selected");
			$("#tab_" + divid + "_a_" + i).addClass("tab_unselected");
			$("#tab_" + divid + "_b_" + i).css("display", "none");
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////
// 播放FLV
function play_flv(div, url, title, autostart, width, height){
//	参数说明 默认值 
//	vcastr_file 方法2传递影片flv文件地址参数，多个使用|分开 空 
//	vcastr_title 影片标题参数，多个使用|分开，与方法2配合使用 空 
//	vcastr_xml 方法3 传递影片flv文件地址参数，样板参考 (根目录下的vcastr.xml 文件)
//	IsAutoPlay 影片自动播放参数：0表示不自动播放，1表示自动播放 0 
//	IsContinue 影片连续播放参数：0表示不连续播放，1表示连续循环播 1 
//	IsRandom 影片随机播放参数：0表示不随机播放，1表示随机播放 0 
//	DefaultVolume 默认音量参数 ：0-100 的数值，设置影片开始默认音量大小 100 
//	BarPosition 控制栏位置参数 ：0表示在影片上浮动显示，1表示在影片下方显示 0 
//	IsShowBar 控制栏显示参数 ：0表示不显示；1表示一直显示；2表示鼠标悬停时显示；3表示开始不显示，鼠标悬停后显示 2 
//	BarColor 播放控制栏颜色，颜色都以0x开始16进制数字表示 0x000033 
//	BarTransparent 播放控制栏透明度 60 
//	GlowColor 按键图标颜色，颜色都以0x开始16进制数字表示 0x66ff00 
//	IconColor 鼠标悬停时光晕颜色，颜色都以0x开始16进制数字表示 0xFFFFFF
//	TextColor 播放器文字颜色，颜色都以0x开始16进制数字表示 0xFFFFFF
//	LogoText 可以添加自己网站名称等信息(英文) 空
//	LogoUrl 可以从外部读取logo图片,注意自己调整logo大小,支持图片格式和swf格式 空
//	EndSwf 影片播放结束后,从外部读取swf文件，可以添加相关影片信息，影片分享等信息，需自己制作 空
//	BeginSwf 影片开始播放之前,从外部读取swf文件，可以添加广告，或者网站信息，需自己制作 空
//	IsShowTime 是否显示时间 : 0表示不显示时间，1表示显示时间 1
//	BufferTime 影片缓冲时间，单位（秒） 2
	if(typeof(autostart)=="undefined") autostart = 1;
	if(typeof(width)=="undefined") width = 342;
	if(typeof(height)=="undefined") height = 240;
	var args = "vcastr_file="+url+"&vcastr_title="+title+"&IsAutoPlay="+autostart+"&BarPosition=1&DefaultVolume=80";
	var s = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,32,18\" width=\""+width+"\" height=\""+height+"\">";
	s += "<param name=\"movie\" value=\"/skin/www/default/images/flv.swf\">";
	s += "<param name=\"quality\" value=\"High\">";
	s += "<param name=\"allowFullScreen\" value=\"true\" />";
	s += "<param name=\"FlashVars\" value=\""+args+"\" />";
	s += "<embed src=\"/skin/www/default/images/flv.swf\" allowFullScreen=\"true\" FlashVars=\""+args+"\" quality=\"High\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\"></embed>";
	s += "</object>";
	document.getElementById(div).innerHTML = s;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 显示flash
function show_flash(url,w,h){
	var s = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,32,18\" width=\"" + w + "\" height=\"" + h + "\">";
	s += "   <param name=\"movie\" value=\"" + url + "\">";
	s += "    <param name=\"quality\" value=\"high\">";
	s += "    <embed src=\""+url+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + w + "\" height=\"" + h + "\"></embed>";
	s += "  </object>";
	document.write(s);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////
function sleep(numberMillis) { 
   var now = new Date();
   var exitTime = now.getTime() + numberMillis;  
   while (true) { 
       now = new Date(); 
       if (now.getTime() > exitTime)    return;
    }
} 
//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 收藏本页
function addFavorite(){
	var isIE=(document.all&&document.getElementById&&!window.opera)?true:false; 
	var isMozilla=(!document.all&&document.getElementById&&!window.opera)?true:false; 
	var isOpera=(window.opera)?true:false;
	var seturl='url(#default#homepage)';
	var weburl=window.location.href;
	var webname=document.title;
	if(isMozilla){
		if (document.all){ window.external.addFavorite(weburl,webname);}
		else if (window.sidebar){ window.sidebar.addPanel(webname, weburl,"");}
	}
	if(isIE){window.external.AddFavorite(weburl, webname);} 
}

// 复制本页地址分享
function copyToClipBoard(){ 
	var clipBoardContent=""; 
	clipBoardContent+=document.title; 
	clipBoardContent+=""; 
	clipBoardContent+=this.location.href; 
	window.clipboardData.setData("Text",clipBoardContent); 
	alert("复制成功，您可以将其粘贴到QQ/MSN上的好友啦！"); 
}

// 字体调整
function doZoom(id,size){
	document.getElementById(id).style.fontSize = size + 'px'
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

// 检查跳转
function check_redirect(){
	var strHref = window.document.location.href;
	var intPos = strHref.indexOf("?");
	if(intPos != -1){
		var strArgc = strHref.substr(intPos + 1);
		intPos = strArgc.indexOf("=");
		if(intPos != -1){
			if(strArgc.substr(0, intPos) == "redirect"){
				var id= strArgc.substr(intPos + 1);
				window.location.replace("/redirect/"+id);
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////
// 将文本内的超连接文本替换成有效的连接
function replaceURLWithHTMLLinks(text) { 
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
	return text.replace(exp,"<a href='$1'>$1</a>"); 
}
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// 用户中心 - 收藏夹 - 增加到收藏夹，必需用到jQuery
function uc_favorites_add(nsort, id){
	addFavorite();return;
	$.ajax({
		type: "GET",
		url: "/uc/favorites/add.js",
		dataType: "html",
		cache: false,
		success: function(str){
			$("#favorites_add").html(str);
		}
	});
}
//////////////////////////////////////////////////////////////////////////
function json2str(o) {
	var arr = [];
	var fmt = function(s) {
		if (typeof s == 'object' && s != null) return json2str(s);
		return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
	}
	for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
	return '{' + arr.join(',') + '}';
}

//////////////////////////////////////////////////////////////////////////
