$(function (){
	if ( $(".tabMenu").attr("rel") != 'no'){
		$(".tabMenu li").on("click", function() {
			$(".tabMenu li").each(function(){
				$(this).removeClass("selected");
				$("#"+ $(this).attr("rel")).css("display","none");
			});

			$(this).addClass("selected");
			$("#"+ $(this).attr("rel")).css("display","");

			WindowHeight(0);setTimeout("WindowHeight(-1)",500);
		});
	}


	// 点击单元格td，打钩checkbox
	$(".selCheckbox").on("click", function () {
		var chkbox = $(this).find("input[type='checkbox']");
		if (chkbox.is(":checked")) {
			// chkbox.removeAttr("checked");
			chkbox.prop("checked",false);
		} else {
			chkbox.prop("checked",true);
		}
	});
	// 修复点击checkbox标签无反应问题
	$(".selCheckbox input[type='checkbox']").on("click", function(){
		this.checked = !this.checked;
	});

});


// 获取元素id
function $id(str){
	return document.getElementById(str);
}

// 获取元素name
function $name(str){
	return document.getElementsByName(str);
}

// 获取元素id的值，如没获取到返回def信息
function $getId(str,def){
	if ($id(str)){
		return $id(str).value;
	}else{
		return def;
	}
}

// 获取元素name的单选值
function $getName(str){
	for (var i=0;i<$name(str).length;i++){
		if ($name(str)[i].checked){
			return $name(str)[i].value;
		}
	}
}


// 文字水印参数，默认关闭 isWatermark=font&watermarkPos=centerMiddle&watermarkPadding=6&watermarkFontContent=网钛科技&watermarkFontSize=14&watermarkFontColor=black
// 图片水印参数，默认关闭 isWatermark=img&watermarkPath=upFile/water.gif&watermarkPos=centerMiddle&watermarkPadding=6
// 其他参数 otherPara
// 区域模式 areaMode=
// 上传模式 upMode：more批量上传，其他单文件上传
// 打开上传载入图片窗口
function OT_OpenUpImg(fileMode,fileFormName,fileDir,otherPara){
	var winWidth = 870;
	var winHeight = 520;
	var arr = window.open('info_upImg.php?mudi=selectFile&fileMode='+ fileMode +'&fileFormName='+ fileFormName +'&upPath='+ fileDir +'&upFileType=images'+ otherPara,'','top=150, left='+ ((window.screen.width-winWidth)/2) +', width='+ winWidth +'px, height='+ winHeight +'px,menubar=no,scrollbars=yes,status=no,resizable=yes');
//	if (arr != null){
//		OT_InsertImg(arr);
//	}
}

// 打开上传文件窗口
function OT_OpenUpFile(fileMode,fileFormName,fileDir,otherPara){
	var winWidth = 870;
	var winHeight = 520;
	var arr = window.open('info_upFile.php?mudi=selectFile&fileMode='+ fileMode +'&fileFormName='+ fileFormName +'&upPath='+ fileDir + otherPara,'','top=150,left='+ ((window.screen.width-winWidth)/2) +',width='+ winWidth +',height='+ winHeight +',menubar=no,scrollbars=yes,status=no,resizable=yes');
//	if (arr != null){
//		OT_InsertImg(arr);
//	}
}

// 打开上传大文件窗口
function OT_OpenUpBigFile(fileMode,fileFormName,fileDir,upMode,otherPara){
	var winWidth = 870;
	var winHeight = 520;
	var arr = window.open('info_upBigFile.php?mudi=selectFile&fileMode='+ fileMode +'&fileFormName='+ fileFormName +'&upPath='+ fileDir +'&upMode='+ upMode + otherPara,'','top=150,left='+ ((window.screen.width-winWidth)/2) +',width='+ winWidth +',height='+ winHeight +',menubar=no,scrollbars=yes,status=no,resizable=yes');
//	if (arr != null){
//		OT_InsertImg(arr);
//	}
}

// 打开在线拍照框
function OT_OpenUpFace(fileMode,fileFormName,fileDir,otherPara){
	var winWidth = 870;
	var winHeight = 340;
//	var arr = showModalDialog('info_upFace.php?mudi=selectFile&fileMode='+ fileMode +'&fileFormName='+ fileFormName +'&upPath='+ fileDir + otherPara,'','dialogWidth:750px; dialogHeight:400px; status:0; help:0;');
	var arr = window.open('info_upFace.php?mudi=selectFile&openMode=face&fileMode='+ fileMode +'&fileFormName='+ fileFormName +'&upPath='+ fileDir + otherPara,'','top=150,left='+ ((window.screen.width-winWidth)/2) +',width='+ winWidth +'px,height='+ winHeight +'px,menubar=no,scrollbars=yes,status=no,resizable=yes');
}

// 打开颜色框
function OT_OpenColor(retMode,inputName,input2Name){
	var arr = MiniWinOpen('info_setColor.htm?retMode='+ retMode +'&inputName='+ inputName +'&input2Name='+ input2Name,'',350,300);	// showModalDialog dialogWidth:350px; dialogHeight:300px; status:0; help:0
	if (arr != null){
		if (retMode=="input"){
			document.getElementById(inputName).value = arr;
			document.getElementById(input2Name).style.color = arr;
		}else if (retMode=="function"){
			DealColorBox(arr);
		}
	}
}

// 开启插件平台升级系统
function OT_OpenAppShopUpdate(appId, otherStr){
	var winWidth = 900;
	var winHeight = 470;
	var a=window.open('appShop.php?mudi=update&nohrefStr=close&appID='+ appId + otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, left='+ ((window.screen.width-winWidth)/2) +', top=120');
//	var arr = showModalDialog('appShop.php?mudi=update&nohrefStr=close&appID='+ appId + otherStr,'','dialogWidth:650px; dialogHeight:380px; status:0; help:0');
//	if (arr != null){

//	}
}

// 开启用户积分管理
function OT_OpenUserScore(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('userMoney.php?mudi=miniManage&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 开启用户财务管理
function OT_OpenUserMoney(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('moneyRecord.php?mudi=userManage&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 开启财务信息
function OT_OpenMoneyRecord(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('moneyRecord.php?mudi=miniRefer&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 开启单条财务信息
function OT_OpenMoneyRecordDet(dataID){
	var winWidth = 500;
	var winHeight = 400;
	var a=window.open('moneyRecord.php?mudi=show&nohrefStr=close&dataID='+ dataID, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 开启推广提现记录
function OT_OpenGainMoney(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('gainMoney.php?mudi=miniRefer&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

function OpenShowAlert(str,color){
	try{
		parent.ShowAlert(str,color);
	}catch (e){
		ShowAlert(str,color);
	}
}

// 弹出框google Chrome执行的是open
function MiniWinOpen(url, args, width, height) {
	var retStr = null;
	if (navigator.userAgent.indexOf("Chrome") > 0) {
		var params = 'height=' + height + ', width=' + width + ', top=' + (((window.screen.height - height) / 2) - 50) +
		',left=' + ((window.screen.width - width) / 2) + ',toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no';
		if (url.indexOf('?') == -1){ url += '?isRet=1' }else{ url += '&isRet=1' }
		window.open(url, "newwindow", params);
	}else{
		var params = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;status:no;dialogLeft:'
		+ ((window.screen.width - width) / 2) + 'px;dialogTop:' + (((window.screen.height - height) / 2) - 50) + 'px;';
		if (url.indexOf('?') == -1){ url += '?isRet=0' }else{ url += '&isRet=0' }
		retStr = window.showModalDialog(url, args, params);
	}
	return retStr;
}


// 点击弹出浮层
var djt;
function ShowMengceng(str, sec){
	if (sec > 0){
		var djSec = 0;
		// djt = window.setInterval("djSecFunc()",1000); 
		djt = window.setInterval(function(){
				djSec += 1;
				$("#floatSec").html('&ensp;'+ djSec +'s');
				if (djSec > sec){
					window.clearInterval(djt);
					HiddenMengceng();
				}
			},1000); 
	}
	//清除之前的样式
	$("#fullScreen,#floatLayer").remove();
	$("body").append(
		//占据整个屏幕Div
		"<div id='fullScreen'></div>"+
		//浮层区
		"<div id='floatLayer'>"+ str +"<span id='floatSec'></span></div>"
	);
}

// 隐藏浮层
function HiddenMengceng(){
	window.clearInterval(djt);
	$("#fullScreen,#floatLayer").remove();
}


// 显示浮层警示框  ShowAlert('操作成功！','')
function ShowAlert(str,color){
	if (color=='red'){
		$id('divAlert').style.backgroundColor="#db0340";
	}

	$id('divAlert').innerHTML=str;
	$id('divAlert').style.display="";
	setTimeout("CloseAlert()",2000);
}

// 关闭浮层警示框
function CloseAlert(){
	$id('divAlert').innerHTML='';
	$id('divAlert').style.display="none";
}


// 及时检测用户名的合法性
function CheckUsername(id,val){
	$id(id +"Str").innerHTML="检测中...";
	$.ajaxSetup({cache:false});
	$.get("readDeal2.php?mudi=checkUsername&method=write&username="+ encodeURIComponent(val), function(result){
		$id(id +"Str").innerHTML=result;
		if (result.lastIndexOf('green')>=0){
			$id(id +"IsOk").innerHTML="<img src='images/img_yes.gif' />";
		}else{
			$id(id +"IsOk").innerHTML="<img src='images/img_err.gif' />";
		}
	});

}


// 获取关键词(标签)
function GetKeyWord(type){
	themeStr = $id('theme').value;
	contentStr = FiltHtmlTag(GetEditorText('content'));

	if (themeStr==""){
		alert("获取关键词(标签)，标题不能为空.");return false;
	}

	$id('onloadThemeKey').innerHTML = "<img src='../inc_img/onload.gif' style='margin-right:5px;' />请稍等，关键词获取中...</center>";

	$.ajaxSetup({cache:false});
	$.post("read.php?mudi=getKeyWord&type="+ type,"theme="+ encodeURIComponent(themeStr) +"&content="+ encodeURIComponent(contentStr), function(result){
		$id('onloadThemeKey').innerHTML = "";
		if (result=="0"){ alert("获取不到关键词(标签)，请手动添加。");return false; }
		$id('themeKey').value = result;
	});
	return false;

}


// 保存sysParam参数信息
function RevSysParam(idName, idVal){
	AjaxGetDeal('readDeal2.php?mudi=updateSysParam&idName='+ idName +'&idVal='+ encodeURIComponent(idVal));
}


// 检测用户名并反馈信息
function CheckUserInfo(username,other){
	if (username.length < 1){
		$id("usernameRes").innerHTML="";
	}else{
		$id("usernameRes").innerHTML="检测中...";
		$.ajaxSetup({cache:false});
		$.get("readDeal2.php?mudi=checkUserInfo&method=write&username="+ encodeURIComponent(username) +"&outId=usernameRes"+ other, function(result){
			$id("usernameRes").innerHTML=result;
		});
	}
}


// 开启用户查询框 outId：结果反馈到ID栏；outField：结果下拉value值；outMode：模块名称
function OpenSelUserBox(outId, outField, outMode){
	if ($id('selUserBox').style.display == ''){
		$id('selUserBox').style.display = 'none';
	}else{
		$id('selUserBox').style.display = '';
		if ($id('selUserBox').innerHTML.length < 50){
			AjaxGetDealToId('read.php?mudi=selUserBox&outId='+ outId +'&outField='+ outField +'&outMode='+ outMode, 'selUserBox');
		}
	}
}

// 检查用户查询表单
function CheckSelUserForm(){
	if ($id('selUsername').value=="" && $id('selRealname').value=="" && $id('selQq').value=="" && $id('selWw').value==""){ alert("用户名、昵称、QQ、旺旺 四者至少填一个。");$id('selUsername').focus();return false; }
	AjaxGetDeal('readDeal2.php?mudi=loadUsersInfo&username='+ $id('selUsername').value +'&realname='+ $id('selRealname').value +'&qq='+ $id('selQq').value +'&ww='+ $id('selWw').value +'&outId='+ $id('outId').value +'&outField='+ $id('outField').value +'&outMode='+ $id('outMode').value);
}

// 用户查询结果表单
function SetSelUserRes(){
	$id($id('outId').value).value = $id('selUserRes').value;
	var text = SelectGetText('selUserRes');
	$id('selUserResText').value = text;
	if ($id('outMode').value == 'vpsProUsers'){
		$id('usernameRes').innerHTML = '<input type="hidden" id="isUserExist" name="isUserExist" value="1" /><span style="color:green;">'+ GetSignStr(text,'（','）',true,true) +'</span>';
	}
}

// 开启用户临时创建框
function OpenCreateUserBox(outId, outField, outMode){
	if ($id('createUserBox').style.display == ''){
		$id('createUserBox').style.display = 'none';
	}else{
		$id('createUserBox').style.display = '';
		if ($id('createUserBox').innerHTML.length < 50 || $id('createUserBox').innerHTML.indexOf('<input')==-1){
			AjaxGetDealToId('read.php?mudi=createUserBox&outId='+ outId +'&outField='+ outField +'&outMode='+ outMode, 'createUserBox');
		}
	}
}

// 检查用户临时创建表单
function CheckCreateUserForm(){
	if ($id('newUsername').value==""){ alert("用户名不能为空。");$id('newUsername').focus();return false; }
	if ($id('newRealname').value=="" && $id('newMail').value=="" && $id('newQq').value=="" && $id('newWw').value=="" && $id('newPhone').value==""){
		alert("昵称、邮箱、QQ、旺旺、手机号 五项至少填一个。");$id('newRealname').focus();return false;
	}
	AjaxGetDeal('readDeal2.php?mudi=createUsersInfo&username='+ $id('newUsername').value +'&realname='+ $id('newRealname').value +'&mail='+ $id('newMail').value +'&qq='+ $id('newQq').value +'&ww='+ $id('newWw').value +'&phone='+ $id('newPhone').value +'&outId='+ $id('outId').value +'&outField='+ $id('outField').value +'&outMode='+ $id('outMode').value);
}

// 用户临时创建表单 使用QQ邮箱
function CreateUserQQmail(){
	if ($id('newQq').value == ""){alert("请先输入QQ，再点击该按钮");$id('newQq').focus();return false}
	$id('newMail').value = $id('newQq').value +"@qq.com";
}

// 用户临时创建结果表单
function SetCreateUserRes(){
	$id($id('outId').value).value = $id('createUserRes').value;
	var text = SelectGetText('createUserRes');
	$id('createUserResText').value = text;
	if ($id('outMode').value == 'vpsProUsers'){
		$id('usernameRes').innerHTML = '<input type="hidden" id="isUserExist" name="isUserExist" value="1" /><span style="color:green;">'+ GetSignStr(text,'（','）',true,true) +'</span>';
	}
}

// 检查是否选中 显示/隐藏区
function CheckedShowHidden(chkId,idStr){
	if ($id(chkId).checked){
		$id(idStr).style.display = '';
	}else{
		$id(idStr).style.display = 'none';
	}
	try {
		WindowHeight(0);
	}catch (e) {}
}

// 点击id标签开启隐藏区，再点击隐藏
function ClickShowHidden(idStr){
	if ($id(idStr).style.display == ''){
		$id(idStr).style.display = 'none';
	}else{
		$id(idStr).style.display = '';
	}
	try {
		WindowHeight(0);
	}catch (e) {}
}

// 点击class标签开启隐藏区，再点击隐藏
function ClassShowHidden(idStr){
	if ($id(idStr).style.display != 'none'){
		$id(idStr).style.display = 'none'
		$('.'+ idStr).css('display','');
	}else{
		$id(idStr).style.display = ''
		$('.'+ idStr).css('display','none');
	}
	try {
		WindowHeight(0);
	}catch (e) {}
}

// 点击开启明码/暗码
function PwdTextBtn(textId,btnId){
	if ($id(textId).type == 'password'){
		$id(textId).type = 'text';
		$id(textId +'Btn').value = '暗码';
	}else{
		$id(textId).type = 'password';
		$id(textId +'Btn').value = '明码';
	}
}

// 点击开启修改时间框
function TimeBoxRev(idStr){
	if ($id(idStr).checked){
		$id(idStr.replace('Jud','Txt')).style.display = 'none';
		$id(idStr.replace('Jud','')).style.display = '';
	}else{
		$id(idStr.replace('Jud','Txt')).style.display = '';
		$id(idStr.replace('Jud','')).style.display = 'none';
	}
}

// 检测远程链接是否正常
function CheckCollUrl(str){
	AjaxGetDealToAlert("read.php?mudi=checkCollUrl&urlMode="+ str)
}


// 更新缓存文件
function UpdateWebCache(){
	AjaxGetDeal("readDeal.php?mudi=updateWebCache");
}

// 清空页面缓存
function ClearWebCache(modeStr){
	AjaxGetDeal("readDeal.php?mudi=clearWebCache&mode="+ modeStr);
}


// 更新缓存文件、清空页面缓存、更新皮肤样式
function UpdateAllCache(){
	$.ajaxSetup({cache:false});
	$.get("readDeal.php?mudi=updateWebCache", function(result){
		alertStr1 = result.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,"").replace(/(<meta[^>]*>|<\/meta>)/gi,"").replace("alert(\"","").replace("\");","");
		$.get("readDeal.php?mudi=clearWebCache&mode=", function(result){
			alertStr2 = result.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,"").replace(/(<meta[^>]*>|<\/meta>)/gi,"").replace("alert(\"","").replace("\");","");
			alert("1、"+ alertStr1.replace(/[\r\n\t]/g,"") +"\r\n2、"+ alertStr2.replace(/[\r\n\t]/g,""));
		});
	});

}


// if(isNaN(value))execCommand('undo');

// 过滤特殊符号
// 应用例子 onkeyup="if (this.value!=FiltVarStr(this.value)){this.value=FiltVarStr(this.value)}"
// 应用例子 onkeyup="this.value=FiltVarStr(this.value)"
function FiltVarStr(str){
	return str.replace(/[^\w\u4E00-\u9FA5]/g,'')
}

// 过滤特殊符号(不过滤空格)
// 应用例子 onkeyup="if (this.value!=FiltVarStr(this.value)){this.value=FiltVarStr(this.value)}"
// 应用例子 onkeyup="this.value=FiltVarStr(this.value)"
function FiltVarStr2(str){
	return str.replace(/[^\w \u4E00-\u9FA5]/g,'')
}

// 过滤小数
// 应用例子 onkeyup="if (this.value!=FiltDecimal(this.value)){this.value=FiltDecimal(this.value)}"
// 应用例子 onkeyup="this.value=FiltDecimal(this.value)"
function FiltDecimal(str){
	return str.replace(/[^\d*\.?\d{0,2}$]/g,'')
}

// 过滤小数保留2位小数
// 应用例子 onkeyup="if (this.value!=FiltDecimal2(this.value)){this.value=FiltDecimal2(this.value)}"
// 应用例子 onkeyup="this.value=FiltDecimal2(this.value)"
function FiltDecimal2(str){
	return str.replace(/(^\d*\.?\d{0,2}).*/g,'$1')
}

// 过滤整数
// 应用例子 onkeyup="if (this.value!=FiltInt(this.value)){this.value=FiltInt(this.value)}"
// 应用例子 onkeyup="this.value=FiltInt(this.value)"
function FiltInt(str){
	return str.replace(/\D/g,'')
}

// 过滤非数字、字母
// 应用例子 onkeyup="if (this.value!=FiltABCNum(this.value)){this.value=FiltABCNum(this.value)}"
// 应用例子 onkeyup="this.value=FiltABCNum(this.value)"
function FiltABCNum(str){
	return str.replace(/[^A-Za-z0-9]/ig,'')
}

// 过滤非数字、字母、下划线
// 应用例子 onkeyup="if (this.value!=FiltAbcNum_(this.value)){this.value=FiltAbcNum_(this.value)}"
// 应用例子 onkeyup="this.value=FiltAbcNum_(this.value)"
function FiltAbcNum_(str){
	return str.replace(/[^A-Za-z0-9_]/ig,'')
}

// 过滤非数字、字母、下划线和点符号
// 应用例子 onkeyup="if (this.value!=FiltAbcNum_d(this.value)){this.value=FiltAbcNum_d(this.value)}"
// 应用例子 onkeyup="this.value=FiltAbcNum_d(this.value)"
function FiltAbcNum_d(str){
	return str.replace(/[^A-Za-z0-9_\.]/ig,'')
}

// 过滤数字
// 应用例子 onkeyup="if (this.value!=FiltNumber(this.value)){this.value=FiltNumber(this.value)}"
// 应用例子 onkeyup="this.value=FiltNumber(this.value)"
function FiltNumber(str) {
	var newStr="";
	if(str.substring(0,1)=="-"){ newStr="-"; }
	var newStr2=(str.replace(/[^0-9.]/g,'')).replace(/[.][0-9]*[.]/, '.');

	if (newStr2.substring(0,1)=="."){ newStr2="0"+ newStr2; }
	newStr = newStr + newStr2
	return newStr;
	/*
	if (/^(\+|-)?\d+($|\.\d+$)/.test( str )) {
	}else {
		execCommand('undo');
	}
	*/
}

// 过滤掉HTML标签和空格、换行、制表符
function FiltHtmlTag(str) {
	str = str.replace(/<\/?[^>]*>/g,'');			// 去除HTML tag
	str = str.replace(/(\t|\r|\n| |\&nbsp;|\&ensp;|\&ldquo;|\&rdquo;)/g,'');	// 去除空格、换行、制表符
	return str;
}

// 把Option的text值覆盖toID文本框
// 应用例子 onchange="OptionTextTo('labItemID','labItemName');"
function OptionTextTo(sourceID,toID){
	document.getElementById(toID).value=document.getElementById(sourceID).options[document.getElementById(sourceID).selectedIndex].text;
}


// 判断是否含特殊符号
function Str_IsSign(str){
	var txt=new RegExp("[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\?,\\|,\\:,\\.,\\<,\\>,\\{,\\},\\(,\\),\\',\\;,\\=,\"]");
	//特殊字符正则表达式
	if (txt.test(str)){
		return true;
	}else{
		return false;
	}
}


// 计算字符串的字节数
function Str_Byte(str){
	var newStr = 0;
//	newStr=str.replace(/[^\u7F51\u949B\u5DE5\u4F5C\u5BA4]/g, '***');
	newStr=str.replace(/[^\u0000-\u00ff]/g, '***');
	return newStr.length;
}

// 检测邮箱的合法性。不合法，返回-1
function IsMail(str){
	if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1){
		return true;
	}else{
		return false;
	}
}

// 检测手机号的合法性。
function IsPhone(str){
	if (str.search(/^\d{11}$/)!=-1){
		return true;
	}else{
		return false;
	}
}

// 检测文件框是否为图片文件
function IsImgFile(fileValue){
	var re = new RegExp("\.(gif|jpg|jpeg|png|bmp)","ig");
	return re.test(fileValue);
}

// 检测是否为http、https协议网址
function IsHttpUrl(urlStr){
	if (urlStr.substr(0,7).toLowerCase()=="http://" || urlStr.substr(0,8).toLowerCase()=="https://"){
		return true;
	}else{
		return false;
	}
}

function IsAbsUrl(urlStr){
	if (urlStr.substr(0,7).toLowerCase()=="http://" || urlStr.substr(0,8).toLowerCase()=="https://" || urlStr.substr(0,1)=="/"){
		return true;
	}else{
		return false;
	}
}


// 生成随机数
// num：生成个数
function RndNum(num) {
	var a = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "Z", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
	var b = "", c;
	for(i=1; i<=num; i++){
		c = Math.floor(Math.random() * a.length);
		b = b + a[c];
		// a = a.del(c);
	}
	return b;
}

// 生成随机数
// num：生成个数；type：num数字，abc小写字母，ABC大写字母
function RndNum2(num,type) {
	var a;
	if (type == 'num'){
		a = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9");
	}else if (type == 'abc'){
		a = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
	}else if (type == 'ABC'){
		a = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "Z", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
	}else{
		a = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "Z", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
	}
	var b = "", c;
	for(i=1; i<=num; i++){
		c = Math.floor(Math.random() * a.length);
		b = b + a[c];
	}
	return b;
}

// idc随机密码
function IdcRndPwd(type){
	return RndNum2(4,'ABC') + RndNum2(4,'num');
}

function RndNumSort(num) {
	var a = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
	var b = "", c;
	for(i=1; i<=num; i++){
		c = Math.floor(Math.random() * a.length);
		b = b + a[c];
//		a = a.del(c);
	}
	return b;
}


function ToGetStr(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return unescape(r[2]); return '';
}

function ToGetPara(str,name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = (str +'').match(reg);
	if(r!=null)return unescape(r[2]); return '';
}

function ToInt(str){
	var newInt = parseInt(str);
	if(isNaN(newInt)) { newInt = 0; }
	return newInt;
}

function ToFloat(str){
	var newFloat = parseFloat(str);
	if(isNaN(newFloat)) { newFloat = 0; }
	return newFloat;
}

function IsRadioChecked(idName){
	var checkedJud=false;
	for (var i=0; i<$name(idName).length; i++){
		if ($name(idName)[i].checked){ checkedJud=true;break; }
	}
	return checkedJud;
}

function JsToHtml(contentStr){
	//contentStr = contentStr.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,"");
	contentStr = contentStr.replace("<script language='javascript' type='text/javascript'>",'');
	contentStr = contentStr.replace('<script language="javascript" type="text/javascript">','');
	contentStr = contentStr.replace('<'+'/scr'+'ipt>','');
	contentStr = contentStr.replace(/document\.writeln\(\"/gi,'').replace(/\"\);/gi,'');
	contentStr = contentStr.replace(/\\\"/gi,"\"");
	contentStr = contentStr.replace(/\\\'/gi,"'");
	contentStr = contentStr.replace(/\\\//gi,"/");
	contentStr = contentStr.replace(/\\\\/gi,"\\");
	return contentStr;
}

function ToPinYinId(fromId,toId,mode,space){
	if ($id(fromId).value == ''){
		alert('中文内容不能为空.');$id(fromId).focus();return false;
	}
	//var a=window.open('../read.php?mudi=pinyin&str='+ $id(fromId).value +'&mode='+ mode +'&space='+ space);
	return AjaxGetDealToInput('../read.php?mudi=pinyin&str='+ $id(fromId).value +'&mode='+ mode +'&space='+ space, toId, 'base64');
}

// 使用AJAX异步无刷新
function UseAjax(urlStr){
	$.ajaxSetup({cache:false});
	$.get(urlStr, function(result){
		eval(result);
	});
}


// 复制内容
function StrToCopy(copy){
	if (window.clipboardData){
		window.clipboardData.setData("Text", copy);
	}else if(navigator.userAgent.indexOf("Opera") != -1){
		window.location = copy;
	}else if(window.netscape){
		try {
			netscape.security.PrivilegeManager
					.enablePrivilege("UniversalXPConnect");
		}catch (e){
			alert("你使用的FireFox浏览器,复制功能被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车。\n然后将“signed.applets.codebase_principal_support”双击，设置为“true”");
			return;
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1']
				.createInstance(Components.interfaces.nsIClipboard);
		if (!clip)
			return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1']
				.createInstance(Components.interfaces.nsITransferable);
		if (!trans)
			return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"]
				.createInstance(Components.interfaces.nsISupportsString);
		str.data = copy;
		trans.setTransferData("text/unicode", str, copy.length * 2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip)
			return false;
		clip.setData(trans, null, clipid.kGlobalClipboard);
	}else{
		alert("你的浏览器不支持一键复制功能");
		return;
	}
	OpenShowAlert('复制成功！','');
	return false;
}


// 复制内容(获取ID所在的value)
function ValueToCopy(id){
	copy = $id(id).value
	if (window.clipboardData){
		window.clipboardData.setData("Text", copy);
	}else if(navigator.userAgent.indexOf("Opera") != -1){
		window.location = copy;
	}else if(window.netscape){
		try {
			netscape.security.PrivilegeManager
					.enablePrivilege("UniversalXPConnect");
		}catch (e){
			alert("你使用的FireFox浏览器,复制功能被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车。\n然后将“signed.applets.codebase_principal_support”双击，设置为“true”");
			return;
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1']
				.createInstance(Components.interfaces.nsIClipboard);
		if (!clip)
			return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1']
				.createInstance(Components.interfaces.nsITransferable);
		if (!trans)
			return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"]
				.createInstance(Components.interfaces.nsISupportsString);
		str.data = copy;
		trans.setTransferData("text/unicode", str, copy.length * 2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip)
			return false;
		clip.setData(trans, null, clipid.kGlobalClipboard);
	}else{
		//alert("你的浏览器不支持一键复制功能，请手动复制。");
		OpenShowAlert('复制失败，请手动复制','red');
		try{
			$id(id).style.display = '';
			$id(id).focus();
			$id(id).select();
		}catch (e){}
		try{ WindowHeight(0); }catch (e){}
		return;
	}
	OpenShowAlert('复制成功！','');
	return false;
}



// 确定提示框并跳转
function ConfirmHref(str, urlStr, waitStr){
	if (confirm(str)==false){
		return false;
	}else{
		if (waitStr.lenght > 0){
			ShowMengceng(waitStr,300);
		}

		document.location.href = urlStr;
	}
}


// 数组变量获取下拉框全部选项
function SelectOptionArr(selectName){
	var SelectOptionArray = new Array();

	for (soi=0; soi<document.getElementById(selectName).options.length; soi++){
		SelectOptionArray['OT'+ document.getElementById(selectName).options[soi].value] = document.getElementById(selectName).options[soi].text;
	}
	return SelectOptionArray;
}


// 下拉框内容检索
function SetOptionData(selectName,arrObj){
	document.getElementById(selectName).options.length=0;
	for (var key in arrObj){
		newKey = key.substr(0,2);
		if (newKey == "OT"){ newKey = key.substr(2); }else{ newKey = key; }
		document.getElementById(selectName).options.add(new Option(arrObj[key],newKey));
	}
}

// 下拉框内容检索
function SelectOptionSearch(sourceID,selectName,arrObj){
	document.getElementById(selectName).options.length=0;
	for (var key in arrObj){
		newKey = key.substr(0,2);
		if (newKey == "OT"){ newKey = key.substr(2); }else{ newKey = key; }
		if (arrObj[key].lastIndexOf(document.getElementById(sourceID).value)>=0){
			document.getElementById(selectName).options.add(new Option(arrObj[key],newKey));
		}
	}
}

// 清理下拉框内容
function SelectOptionClear(selectName,defText){
	document.getElementById(selectName).options.length=0; 
	document.getElementById(selectName).options.add(new Option(defText,""));
	document.getElementById(selectName).value = "";
}

// 增加下拉框选项
function SelectOptionAdd(selectName,defText,defValue){
	document.getElementById(selectName).options.add(new Option(defText, defValue));
}

// 获取下拉框的文本
function SelectGetText(selectName){
	return document.getElementById(selectName).options[document.getElementById(selectName).options.selectedIndex].text;
}

// 获取下拉框的值
function SelectGetVaule(selectName){
	return document.getElementById(selectName).options[document.getElementById(selectName).options.selectedIndex].value;
}



// 加载城市数据
function LoadCityData(idName,prov){
	AjaxGetDeal('../read.php?mudi=getCityData&idName='+ idName +'&prov='+ prov);
}

// 缩略图路径
function ImgThumbPath(imgStr){
	if (imgStr.indexOf('/')!=-1){
		headPart = imgStr.substring(0,imgStr.lastIndexOf("/")+1);
		return imgStr.replace(headPart,headPart +"thumb_");
	}else{
		return "thumb_"+ imgStr;
	}
}

// 获取缩略图名
function GetImgName(imgStr){
	if (imgStr.indexOf('/')!=-1){
		return imgStr.substring(imgStr.lastIndexOf("/")+1);
	}else{
		return imgStr;
	}
}



// 截取字符串部分内容
function GetSignStr(contentStr, startCode, endCode, incStart, incEnd){
	if (contentStr.length == 0){	//  || startCode.length == 0 || endCode.length == 0
		return "";
	}
	var contentTemp="";
	var startPos=-9, endPos=-9;
	/* contentTemp = contentStr.toLowerCase();
	startCode = startCode.toLowerCase();
	endCode = endCode.toLowerCase(); */
	contentTemp = contentStr;
	if (startCode == ""){
		startPos = 0;
	}else{
		startPos = contentTemp.indexOf(startCode);
		if (startPos < 0){
			return "";
		}else{
			if (incStart == false)
			{
				startPos += startCode.length;
			}
		}
	}
	if (endCode == ""){
		return contentStr.substr(startPos);
	}else{
		endPos = contentTemp.substr(startPos).indexOf(endCode);
		if (endPos >= 0) { endPos += startPos; }
		if (endPos <= 0 || endPos <= startPos)
		{
			return "";
		}
		else
		{
			if (incEnd == true)
			{
				endPos += endCode.length;
			}
		}
		return contentStr.substr(startPos, endPos - startPos);
	}
}


// 截取字符串部分内容从后面匹配
function GetSignStrEnd(contentStr, startCode, endCode, incStart, incEnd){
	if (contentStr.length == 0){	//  || startCode.length == 0 || endCode.length == 0
		return "";
	}
	var contentTemp="";
	var startPos=-9, endPos=-9;
	/* contentTemp = contentStr.toLowerCase();
	startCode = startCode.toLowerCase();
	endCode = endCode.toLowerCase(); */
	contentTemp = contentStr;
	if (startCode == ""){
		startPos = 0;
	}else{
		startPos = contentTemp.lastIndexOf(startCode);
		if (startPos < 0){
			return "";
		}else{
			if (incStart == false)
			{
				startPos += startCode.length;
			}
		}
	}
	if (endCode == ""){
		return contentStr.substr(startPos);
	}else{
		endPos = contentTemp.substr(startPos).indexOf(endCode);
		if (endPos >= 0) { endPos += startPos; }
		if (endPos <= 0 || endPos <= startPos)
		{
			return "";
		}
		else
		{
			if (incEnd == true)
			{
				endPos += endCode.length;
			}
		}
		return contentStr.substr(startPos, endPos - startPos);
	}
}


function FocusAddText(inputId,str){
	var idObj=document.getElementById(inputId);
	var strLen=idObj.value.length;
	idObj.focus();
	if(typeof document.selection !="undefined"){
		document.selection.createRange().text=str;  
	}else{
		idObj.value=idObj.value.substr(0,idObj.selectionStart)+str+idObj.value.substring(idObj.selectionStart,strLen);
	}
}

function InputAddText(inputId,str){
	document.getElementById(inputId).value=document.getElementById(inputId).value+str;
}

function InputToText(inputId,str){
	document.getElementById(inputId).value=str;
}

function InputToInput(inputId,inputId2){
	document.getElementById(inputId).value=document.getElementById(inputId2).value;
}

function IsChecked(inputId){
	if (document.getElementById(inputId).checked){
		return 1;
	}else{
		return 0;
	}
}


function StyleInput(inputId,toId,type){
	if (type == "b"){
		if ($id(inputId).checked){
			$id(toId).style.fontWeight = "bold";
		}else{
			$id(toId).style.fontWeight = "normal";
		}
	}
}

// 获取当前时间
function GetCurrTime(){
	var date = new Date();	// 当前时间
	var month = ('0'+ (date.getMonth() + 1)).slice(-2);	// 月
	var day = ('0'+ date.getDate()).slice(-2);			// 日
	var hour = ('0'+ date.getHours()).slice(-2);		// 时
	var minute = ('0'+ date.getMinutes()).slice(-2);	// 分
	var second = ('0'+ date.getSeconds()).slice(-2);	// 秒
	var curTime = date.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

	return curTime;
}
 

// date 可以是时间对象也可以是字符串，如果是后者，形式必须为: yyyy-mm-dd hh:mm:ss 其中分隔符不定。"2006年12月29日 16点01分23秒" 也是合法的
function DateAdd(interval,number,date){
	number = parseInt(number);
	if (date.indexOf(":") != -1){
		type = "datetime"
	}else{
		type = "date"
	}

	if (typeof(date)=="string"){
		date = date.split(/\D/);
		--date[1];
		eval("var date = new Date("+date.join(",")+")");
	}
	if (typeof(date)=="object"){
		var date = date
	}
	switch(interval){
		case "y": date.setFullYear(date.getFullYear()+number); break;
		case "m": date.setMonth(date.getMonth()+number); break;
		case "d": date.setDate(date.getDate()+number); break;
		case "w": date.setDate(date.getDate()+7*number); break;
		case "h": date.setHours(date.getHours()+number); break;
		case "n": date.setMinutes(date.getMinutes()+number); break;
		case "s": date.setSeconds(date.getSeconds()+number); break;
		case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
	}
	month = '0'+ (date.getMonth()+1);
	month = month.substring(month.length-2)
	day = '0'+ date.getDate();
	day = day.substring(day.length-2)
	if (type == "datetime"){
		hour = '0'+ date.getHours();
		hour = hour.substring(hour.length-2)
		min = '0'+ date.getMinutes();
		min = min.substring(min.length-2)
		sec = '0'+ date.getSeconds();
		sec = sec.substring(sec.length-2)
		return date.getFullYear() +"-"+ month +"-"+ day +" "+ hour +":"+ min +":"+ sec;
	}else{
		return date.getFullYear() +"-"+ month +"-"+ day;
	}
}


function EncPwdData(pwdName){
	if ($id(pwdName).value == $id('pwdEnc').value){ return false; }
	$.ajaxSetup({cache:false, async:false});
	$.get("../read.php?mudi=encPwd&str="+ base64encode($id(pwdName).value) +"&exp=35", function(result){
		var strArr = (result +'||||').split("|");
		if (strArr[3].length > 3){
			$id('pwdMode').value = strArr[1];
			$id('pwdKey').value = strArr[2];
			$id('pwdEnc').value = strArr[3];
			$id(pwdName).value = strArr[3];
			try{
				$id(pwdName +'2').value = strArr[3];
			}catch (e){ }
		}
		// alert($id('pwdMode').value +'|'+ $id('pwdKey').value +'|'+ $id(pwdName).value);
	});

}


	ajaxDealStr = "数据处理中...";
	ajaxLoadStr = "数据读取中...";

// POST表单AJAX处理
function AjaxPostDeal(formName){
	try {
		document.getElementById("loadingStr").innerHTML = "<span style='font-size:14px;'><img src='images/onload.gif' style='margin-right:5px;' />"+ ajaxDealStr +"</span>";
	}catch (e) {}

	formNameObj = document.getElementById(formName);
	var formNameUrl = formNameObj.getAttribute("action"), formNameContent = formValueToStr(formNameObj);
	$.post(formNameUrl,formNameContent,function(result){
		try {
			document.getElementById("loadingStr").innerHTML = "";
		}catch (e) {}
		eval(result.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,"").replace(/(<meta[^>]*>|<\/meta>)/gi,""));
	});
	return false;
}


// POST提交AJAX处理
function AjaxPostDealToId(formName,outputID){
	try {
		document.getElementById("loadingStr").innerHTML = "<span style='font-size:14px;'><img src='images/onload.gif' style='margin-right:5px;' />"+ ajaxDealStr +"</span>";
	}catch (e) {}
	formNameObj = document.getElementById(formName);
	var formNameUrl = formNameObj.getAttribute("action"), formNameContent = formValueToStr(formNameObj);
	$.post(formNameUrl,formNameContent,function(result){
		try {
			document.getElementById("loadingStr").innerHTML = "";
		}catch (e) {}
		document.getElementById(outputID).innerHTML = result;
	});
	return false;
}


// 通过表单name获取该表单所有元素并组成GET字符串
function formValueToStr(formObj) {
	var qstr = "", and = "", elem, value;
	for(var i = 0; i< formObj.length; ++i) {
		elem = formObj[i];
		if (elem.name!='') {
			value=undefined;
			switch(elem.type) {
				case "select-one":
					if(elem.selectedIndex > -1) {
						value = elem.options[elem.selectedIndex].value;
					}
					else {
						value = "";
					}
					break;
				case"select-multiple":
					var selMul=elem.options;
					for(var w=0;w<selMul.length;++w){
						if(selMul[w].selected){
							qstr += and+elem.name+"="+ encodeURIComponent(selMul[w].value);
							and = "&";
						}
					}
					break;
				case "checkbox":
				case "radio":
					if (elem.checked == true) {
						value = elem.value;
					}
					break;
				default:
					value = elem.value;
			}
			if(value!=undefined){
				value = encodeURIComponent(value);
				qstr += and + elem.name + "=" + value;
				and = "&";
			}
		}
	}
	return qstr;
}


// GET提交AJAX处理
function AjaxGetDeal(urlStr){
	try {
		document.getElementById("loadingStr").innerHTML = "<span style='font-size:14px;'><img src='images/onload.gif' style='margin-right:5px;' />"+ ajaxDealStr +"</span>";
	}catch (e) {}

	$.ajaxSetup({cache:false});
	$.get(urlStr, function(result){
		try {
			document.getElementById("loadingStr").innerHTML = "";
		}catch (e) {}
		eval(result.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,"").replace(/(<meta[^>]*>|<\/meta>)/gi,""));
	});
	return false;
}


// GET提交AJAX处理
function AjaxGetDealToAlert(urlStr){
	$.ajaxSetup({cache:false});
	$.get(urlStr, function(result){
		alert(result.replace(/<(script[^>]*?)>/gi,"").replace(/<\/script.*?>/gi,""));
	});
	return false;
}


// GET提交AJAX处理
function AjaxGetDealToId(urlStr,outputID){
	$.ajaxSetup({cache:false});
	$.get(urlStr, function(result){
		document.getElementById(outputID).innerHTML = result;
		try{
			WindowHeight(0);
		}catch (e){}
	});
	return false;
}


// GET提交AJAX处理
function AjaxGetDealToInput(urlStr, outputID, dealMode){
	$.ajaxSetup({cache:false});
	$.get(urlStr, function(result){
		if (dealMode == 'base64'){ result = base64decode(result); }
		document.getElementById(outputID).value = result;
		try{
			WindowHeight(0);
		}catch (e){}
	});
	return false;
}

/* JS版base64编解码算法。示例:
 * b64 = base64encode(data);
 * data = base64decode(b64);
 */
var base64EncodeChars = [
	"A", "B", "C", "D", "E", "F", "G", "H",
	"I", "J", "K", "L", "M", "N", "O", "P",
	"Q", "R", "S", "T", "U", "V", "W", "X",
	"Y", "Z", "a", "b", "c", "d", "e", "f",
	"g", "h", "i", "j", "k", "l", "m", "n",
	"o", "p", "q", "r", "s", "t", "u", "v",
	"w", "x", "y", "z", "0", "1", "2", "3",
	"4", "5", "6", "7", "8", "9", "+", "/"
];

var base64DecodeChars = [
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
	52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
	-1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
	15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
	-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
	41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
];

function base64encode(str) {
	var out, i, j, len;
	var c1, c2, c3;

	len = str.length;
	i = j = 0;
	out = [];
	while (i < len) {
		c1 = str.charCodeAt(i++) & 0xff;
		if (i == len)
		{
			out[j++] = base64EncodeChars[c1 >> 2];
			out[j++] = base64EncodeChars[(c1 & 0x3) << 4];
			out[j++] = "==";
			break;
		}
		c2 = str.charCodeAt(i++) & 0xff;
		if (i == len)
		{
			out[j++] = base64EncodeChars[c1 >> 2];
			out[j++] = base64EncodeChars[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];
			out[j++] = base64EncodeChars[(c2 & 0x0f) << 2];
			out[j++] = "=";
			break;
		}
		c3 = str.charCodeAt(i++) & 0xff;
		out[j++] = base64EncodeChars[c1 >> 2];
		out[j++] = base64EncodeChars[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];
		out[j++] = base64EncodeChars[((c2 & 0x0f) << 2) | ((c3 & 0xc0) >> 6)];
		out[j++] = base64EncodeChars[c3 & 0x3f];
	}
	return out.join('');
}

function base64decode(str) {
	var c1, c2, c3, c4;
	var i, j, len, out;

	len = str.length;
	i = j = 0;
	out = [];
	while (i < len) {
		/* c1 */
		do {
			c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		} while (i < len && c1 == -1);
		if (c1 == -1) break;

		/* c2 */
		do {
			c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		} while (i < len && c2 == -1);
		if (c2 == -1) break;

		out[j++] = String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

		/* c3 */
		do {
			c3 = str.charCodeAt(i++) & 0xff;
			if (c3 == 61) return out.join('');
			c3 = base64DecodeChars[c3];
		} while (i < len && c3 == -1);
		if (c3 == -1) break;

		out[j++] = String.fromCharCode(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2));

		/* c4 */
		do {
			c4 = str.charCodeAt(i++) & 0xff;
			if (c4 == 61) return out.join('');
			c4 = base64DecodeChars[c4];
		} while (i < len && c4 == -1);
		if (c4 == -1) break;
		out[j++] = String.fromCharCode(((c3 & 0x03) << 6) | c4);
	}
	return out.join('');
}

// 新窗口打开按钮 测试网址是否正常访问
function OpenInputWin(inputStr,str){
	if ($id(inputStr).value.length < 8){
		alert("左侧框内容不能低于8字符.");$id(inputStr).focus();return false;
	}
	var a = window.open($id(inputStr).value + str);
}

// 网址变二维码浮窗显示
function UrlQrcodeJs(){
	$('.urlQrcode').on('mouseover', function (){
		$(this).find('.urlQrcodeSpan').css({"display":""})
		$(this).on("mouseenter", function (){
			
		}).on("mouseleave",function (){
			$(this).find('.urlQrcodeSpan').css({"display":"none"})
		});
	});
}


// 编辑器载入模式根据后缀名加载不同html
function ExtIcoHtml(fileDir, title, fileUrl, fileExt){
	switch (fileExt){
		case "bmp": case "jpg": case "jpeg": case "gif": case "png":
			retStr = "<img src='"+ fileUrl +"' border='0'>";
			break;

		case "swf": case "doc": case "xls": case "ppt": case "pdf": case "txt": case "docx": case "xlsx": case "pptx": case "rar": case "zip": case "iso": case "js": case "mdb": case "psd": case "xml":
			retStr = "<div><a href='"+ fileUrl +"' target='_blank'><img src='"+ fileDir + fileExt +".gif' border='0' alt='"+ fileExt +"类型' title='"+ fileExt +"类型'>"+ title +"</a></div>";
			break;

		case "avi": case "mpeg": case "mpg": case "ra": case "rm": case "rmvb": case "mov": case "qt": case "asf": case "wmv": case "mp3": case "wma": case "wav": case "mod": case "cd": case "md": case "aac": case "mid": case "ogg": case "m4a":
			retStr = "<div><a href='"+ fileUrl +"' target='_blank'><img src='"+ fileDir +"mov.gif' border='0' alt='视频音频类型' title='视频音频类型'>"+ title +"</a></div>";
			break;

		default:
			retStr = "<div><a href='"+ fileUrl +"' target='_blank'><img src='"+ fileDir +"file.gif' border='0' alt='"+ fileExt +"类型' title='"+ fileExt +"类型'>"+ title +"</a></div>";

	}
	return retStr;
}

// 打开上级渠道商信息
function OT_OpenCompanyImg(companyID){
	var winWidth = 450;
	var winHeight = 300;
	var arr = window.open('vpsCompany.php?mudi=show&dataID='+ companyID,'','top=150, left='+ ((window.screen.width-winWidth)/2) +', width='+ winWidth +'px, height='+ winHeight +'px,menubar=no,scrollbars=yes,status=no,resizable=yes');
}

// 打开上家名单信息
function OT_OpenDealerImg(dealerID){
	var winWidth = 450;
	var winHeight = 300;
	var arr = window.open('vpsDealerList.php?mudi=show&dataID='+ dealerID,'','top=150, left='+ ((window.screen.width-winWidth)/2) +', width='+ winWidth +'px, height='+ winHeight +'px,menubar=no,scrollbars=yes,status=no,resizable=yes');
}

// VPS状态
function VpsStateCN(num){
	switch (ToInt(num)){
		case 15:	return '续费中';
		case 12:	return '试用中';
		case 10:	return '正常';
		case 9:		return '已退款';
		case 8:		return '退款中';
		case 6:		return '开通失败';
		case 5:		return '开通中';
		case 3:		return '待开通';
		case 0:		return '停止';
		default :	return '['+ num +']';
	}
}

// 开启IDC用户财务信息
function OT_OpenIdcUserMoney(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('idcMoneyData.php?mudi=userManage&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 开启IDC财务信息
function OT_OpenIdcMoneyRecord(otherStr){
	var winWidth = 800;
	var winHeight = 500;
	var a=window.open('idcMoneyData.php?mudi=miniRefer&nohrefStr=close&1=1'+ otherStr, '', 'width='+ winWidth +'px, height='+ winHeight +'px, location=0, menubar=0, toolbar=0, scrollbars=yes, status=no, resizable=yes, left='+ ((window.screen.width-winWidth)/2) +', top=120');
}

// 检查IDC用户查询表单
function CheckSelIdcUserForm(){
	// if ($id('selUsername').value=="" && $id('selRealname').value==""){ alert("用户名、昵称 二者至少填一个。");$id('selUsername').focus();return false; }
	AjaxGetDeal('readDeal2.php?mudi=loadIdcUsersInfo&username='+ $id('selUsername').value +'&realname='+ $id('selRealname').value +'&outId='+ $id('outId').value +'&outField='+ $id('outField').value +'&outMode='+ $id('outMode').value);
}

// 检测IDC用户名并反馈信息
function CheckIdcUserInfo(username,other){
	if (username.length < 1){
		$id("usernameRes").innerHTML="";
	}else{
		$id("usernameRes").innerHTML="检测中...";
		$.ajaxSetup({cache:false});
		$.get("readDeal2.php?mudi=checkIdcUserInfo&method=write&username="+ encodeURIComponent(username) +"&outId=usernameRes"+ other, function(result){
			$id("usernameRes").innerHTML=result;
		});
	}
}

// 开启IDC用户查询框 outId：结果反馈到ID栏；outField：结果下拉value值；outMode：模块名称
function OpenSelIdcUserBox(outId, outField, outMode){
	if ($id('selUserBox').style.display == ''){
		$id('selUserBox').style.display = 'none';
	}else{
		$id('selUserBox').style.display = '';
		if ($id('selUserBox').innerHTML.length < 50){
			AjaxGetDealToId('read.php?mudi=selIdcUserBox&outId='+ outId +'&outField='+ outField +'&outMode='+ outMode, 'selUserBox');
		}
	}
}
