﻿//************** 公用JS代码 **************
// Copyright (C)2007 CUTE.HK
// Powered by DengJianCheng | XSTYLE.CN
// Update: 2007-07-16
//****************************************


//--------------------------------
//确认提示
//使用: <a href="demo.asp?act=del" onclick="return ConfirmYorN('确认要删除吗?\n\n提示：数据被删除后将无法恢复！')">
function ConfirmYorN(string) {
	if (confirm(string))
		return true;
	else
		return false;
}
//--------------------------------
//判断用户名是否符合要求(字母、数字、下划线组成，并以字母或数字开头,4-16字符)
function usernamecheck(string){
	//if((string.length<4)||(string.length>16)){return false;}
	//var re;
	//re=new RegExp("^[a-z|A-Z|0-9][a-z|A-Z|0-9|_]+$");
	var re=/^[a-zA-Z0-9]\w{3,15}$/;
	return re.test(string);
}
//--------------------------------
//判断电子邮箱是否符合规范
function emailcheck(string){
	var re;
	re=new RegExp("^[\\w-_\\.]+@([a-z|0-9|-]+\\.)+[a-z]{2,5}$");
	return re.test(string.toLowerCase());
}
//--------------------------------
//判断日期是否符合规范
function datecheck(string){
	if((string.length<1)||(string.length>10)){return false;}
	var ymd1=string.split("-");
	var month1=ymd1[1]-1
	var Date1 = new Date(ymd1[0],month1,ymd1[2]);
	if (Date1.getMonth()+1!=ymd1[1]||Date1.getDate()!=ymd1[2]||Date1.getFullYear()!=ymd1[0]||ymd1[0].length!=4)
	{return false;}
	else {return true;}
}
//--------------------------------
//鼠标移到TR时,变背景色
//使用: <tr onMouseOver="inStyleBG(this,'#F5F5F5')" onMouseOut="outStyleBG(this)" style="background:#FFFFFF">
var old_StyleBG="";
function inStyleBG(obj,BGcolor){
	if (BGcolor==""){BGcolor="#F6F6F6";}
	old_StyleBG=obj.style.background;
	obj.style.background=BGcolor;
}
function outStyleBG(obj){ obj.style.background=old_StyleBG; }
//--------------------------------
//全选/全不选
//使用: <input name="selectall" type="checkbox" onClick="selectAll(this.form,this)">
function selectAll(form, obj){
	for(i=0;i<form.length;i++){
		if(obj.checked) form[i].checked=true;
		else form[i].checked=false;
	}
}
//--------------------------------
//检测列表中是否已选择最少一项
function CheckSelected(obj,rCount){
	var i=0;
	var bSel=0;

	if (rCount==1){
		if(obj.checked==true){bSel=1;}
	}
	else{
		while(obj(i)!=null){
			if(obj(i).checked==true){bSel=1;}
			i=i+1;
		}
	}
	return bSel;
}
//--------------------------------
//只能输入数字
function OnlyInputNum()
{
	//var k = window.event.keyCode;
	//if (k < 48 || k > 57){ window.event.keyCode = 0 ;}
	if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 13))){ window.event.keyCode = 0 ;}
}
//--------------------------------
//收藏指定页面
function addBookmark(title,url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
//--------------------------------
//检测字符数(中文字算2个字符)
function TextCount(str){
	sl1=str.length;
	strLen=0;
	for(i=0;i<sl1;i++){
		if(str.charCodeAt(i)>255) strLen+=2;
	 else strLen++;
	}
	return strLen;
}
//--------------------------------
//检测和提示，限制输入的字符数
function ConfineTextNum(obj,num,tips){
	StrLen1 = TextCount(obj.value);
	n = num - StrLen1;
	if (StrLen1>num) { document.getElementById(tips).innerHTML="已超出限制的字数！请删除部分文字。"; }
	else { document.getElementById(tips).innerHTML="还可输入 "+n+" 个字符"; }
}
//--------------------------------
//点提交后自动锁定指定的秒数(防止重复提交)
var LockSubmitBtn_Num = 0;
function LockSubmitBtn(Secs,ID,LockT,UnlockT)	//(秒数,按钮,锁定时文字,解锁后文字)
{
	LockSubmitBtn_Num = LockSubmitBtn_Num+1
	if (LockSubmitBtn_Num==Secs) {
		LockSubmitBtn_Num = 0;
		document.getElementById(ID).disabled = false;
		document.getElementById(ID).value = UnlockT;
	}
	else {
		document.getElementById(ID).disabled = true;
		document.getElementById(ID).value = LockT;
		if (Secs!=0){window.setTimeout("LockSubmitBtn("+Secs+",'"+ID+"','"+LockT+"','"+UnlockT+"')", 1000);}
	}
}
//--------------------------------
//点击显示/隐藏   onclick="TurnObj('IDname')"
function TurnObj(objId) {
	document.getElementById(objId).style.display=(document.getElementById(objId).style.display=='none')?'':'none';
}
//--------------------------------
//输入项是否有效
function TurnInputObj(checkObj,inputObj) { 
	if(checkObj.checked) { inputObj.disabled=false; } 
	else { inputObj.disabled=true; } 
}

//--------------------------------
//打开对话框窗口
function OpenModalDialog(url,dWidth,dHeight) { 
	if (dWidth==""){dWidth=600;}
	if (dHeight==""){dWidth=400;}
	if (document.all) {
		var strItem = window.showModalDialog(url,window,"Help=no;status:no;dialogWidth="+dWidth+"px;dialogHeight="+dHeight+"px;resizable=yes;scroll=auto;");
		if(strItem)
		window.location.reload();
	}
	else {
		var strItem = window.open(url,null,"width="+dWidth+",height="+dHeight+",menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,status=no");
	}
}
//--------------------------------
//查找网页内宽度太大的图片进行缩放以及PNG纠正
function ReImgSize(){
	for (i=0;i<document.images.length;i++){
		if (document.all){
			if (document.images[i].width>550){
				document.images[i].width="550"
				try{
					document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
				}catch(e){}
			}
		}
		else{
			if (document.images[i].width>550){
				document.images[i].width="550";
				document.images[i].title="在新窗口打开图片";
				document.images[i].style.cursor="pointer";
				document.images[i].onclick=function(e){window.open(this.src)}
			}
		}
	}
}
//--------------------------------
//判断是否是IE
function isIE(){
	if (navigator.appName!="Microsoft Internet Explorer") {return false}
	return true
}
//--------------------------------
//打开新窗口
function popnew(url,title,width,height){
    var w = 1024;
    var h = 768;
    if (document.all || document.layers){
        w = screen.availWidth;
        h = screen.availHeight;
    }
    var leftPos = (w/2-width/2);
    var topPos = (h/2.3-height/2.3);
    window.open(url,title,"width="+width+",height="+height+",top="+topPos+",left="+leftPos+",scrollbars=no,resizable=no,status=no")
}
//--------------------------------
//复制代码
function doCopy(ID) { 
	if (document.all){
		 textRange = document.getElementById(ID).createTextRange(); 
		 textRange.execCommand("Copy"); 
	}
	else{
		 alert("此功能只能在IE上有效")
	}
}
//--------------------------------
//设置字体大小
function SetFont(size){	document.getElementById("logPanel").style.fontSize=size }
//--------------------------------
//写入Flash文件
function WriteFlash(Path,Width,Height,Transparent){
	 var Temp,T=""
	 Temp='<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="FlashH" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="'+Width+'" height="'+Height+'">'
	 Temp+='<param name="movie" value="'+Path+'"/>'
	 Temp+='<param name="quality" value="High"/>'
	 Temp+='<param name="scale" value="ExactFit"/>'
	 if (Transparent) {Temp+=' <param name="wmode" value="transparent"/>';T='wmode="transparent"'}
	 Temp+='<embed src="'+Path+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="FlashH" width="'+Width+'" height="'+Height+'" quality="High"'+T+' scale="ExactFit"/>'
	 Temp+='</object>'
	 write(Temp);
	 //document.getElementById("FlashHead").innerHTML=Temp
}




