﻿// JScript 文件
function RndNum(n)
{ 
	var rnd=""; 
	for(var i=0;i<n;i++)
		rnd+=Math.floor(Math.random()*10);
	return rnd;
}
function ChangePic()
{
	var CodeArea=document.getElementById("Refresh"); 
	var rnum=RndNum(10);
	var html = "<IMG id='Image1' style='FILTER: chroma(color:#000000);cursor:hand' alt='点击更换！' onclick=ChangePic(); src='../VerifyNum.aspx?s="+ rnum +"'  Height='20' width='68'>";
	//alert( html );
	//alert( CodeArea.innerHTML );
	CodeArea.innerHTML = html;
} 

	function EditorResize(dir)
	{
		var h = parseInt(document.getElementById("EditorTD").height);
		if( dir == "+" )
		{
			if( h > 1000 )
				return;
			document.getElementById("EditorTD").height = h + 40;
		}
		else if( dir == "-" )
		{
			if( h < 100)
				return;
			document.getElementById("EditorTD").height = h - 40;
		}
	}

var flag=false;
var maxWidht = 600,maxHeight = 450;			
function DrawImage(ImgD)
{
	var image=new Image();
	image.src=ImgD.src;
	
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= maxWidht/maxHeight)
		{
			if(image.width>maxWidht)
			{ 
				ImgD.width=maxWidht;
				ImgD.height=(image.height*maxWidht)/image.width;
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else
		{
			if(image.height>maxHeight)
			{ 
				ImgD.height=maxHeight;
				ImgD.width=(image.width*maxHeight)/image.height; 
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}			
}

function QueryString(fieldName)
{  
		//假设document.location.herf=http://localhost/myweb/default.aspx?info=1&name=2,fiedName=info
	var urlString = document.location.search;//urlString为?info=1&name=2
	if(urlString != null)
	{
		var typeQu = fieldName+"=";
		var urlEnd = urlString.indexOf(typeQu);//寻找info=1位置,为1
		
		if(urlEnd != -1)
		{
			var paramsUrl = urlString.substring(urlEnd+typeQu.length);//paramsUrl=1&name=2
			var isEnd =  paramsUrl.indexOf('&');
			if(isEnd != -1)
			{
				return paramsUrl.substring(0, isEnd);//得到info值为1
			}
			else
			{
				return paramsUrl;//只有一个参数情况
			}
		}
		else 
			return null;//没有找到info=1
	}
	else
		return null; //没有带参数的Url
}



	function doPreview(val)
	{
		//var obj=document.getElementById(objname);
		//if(obj.length==0) return false;
		//var url=obj.value; 
	
		val = val.trim()
		if (val && val.trim() != ""){
			var sExt=val.substr(val.lastIndexOf(".")+1);
			sExt=sExt.toUpperCase();
			var sHTML;
			switch(sExt){
			case "GIF":
			case "JPG":
			case "BMP":
			case "PNG":
				document.all.Form1.imgPreview.src = val;
				//tdPreview.innerHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
				break;
			//case "SWF":
			//	sHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
			//	break;
			default:
				document.all.Form1.imgPreview.src = "";
				break;
			}
			//tdPreview.innerHTML = sHTML;
		}else{
			//document.all.Form1.imgPreview.src = "";
		}
		//DrawImage( document.all.Form1.imgPreview );
	}

function openwindow( url, winName, width, height) 
{
	xposition=0; yposition=0;

	if ((parseInt(navigator.appVersion) >= 4 ))
	{
	xposition = (screen.width - width) / 2;
	yposition = (screen.height - height) / 2;
	}
	theproperty= "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=0,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," //仅适用于Netscape
	+ "screeny=" + yposition + "," //仅适用于Netscape
	+ "left=" + xposition + "," //IE
	+ "top=" + yposition; //IE 
	window.open( url,winName,theproperty );
}
<!--
//检查日期的函数，必须为格式yyyy-M-d
function checkdate(str){ 
	var reg = /^(\d+)-(\d{1,2})-(\d{1,2})$/; 
	var r = str.match(reg); 
	if(r==null)return false; 
	r[2]=r[2]-1; 
	var d= new Date(r[1], r[2],r[3]); 
	if(d.getFullYear()!=r[1])return false; 
	if(d.getMonth()!=r[2])return false; 
	if(d.getDate()!=r[3])return false; 

	return true; 
}

//检查email格式的函数
function isEmail(str){
	var re = /^([a-zA-Z0-9_\.-])+@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+/;//Email的正则表达式
	return re.test(str);
}

//将input的值格式化为数字的函数
//默认返回Float类型，如果第二个参数不为空并且不为0，则返回整数
//调用方法：<input type=text onchange="cnum(this)">
function cnum(obj,bInt){
	var reNum=bInt?/^0*(\d+).*$/:/^0*(\d+(\.\d+)?).*$/;
	if(obj.tagName=="INPUT"){
		var sTemp=obj.value.replace(/[^\d\.]/g,"").replace(reNum,"$1");
		obj.value=(sTemp==""?"0":(sTemp.substr(0,1)=="."?"0" + sTemp: sTemp));	//如果是小数点开头的数字，则在前面加上0
	}
	else var sTemp=obj.replace(/[^\d\.]/g,"").replace(reNum,"$1")
	return bInt?sTemp.toInt():sTemp.toFloat();
}
function ccnum(obj,bInt){
	if(obj.tagName=="INPUT"){
		var sTemp=obj.value.replace(/[^\d\.]/g,"");
	}
	obj.value = sTemp;
}

//给String类型增加toDate方法，作用是将日期格式的字符串转化为对应的日期对象。
//如果格式错误，则返回当天的日期。
String.prototype.toDate=function(){
	var t=this.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/);
	return t?new Date(t[1],parseInt(t[2])-1,t[3]):new Date();
}

//给String类型增加toFloat方法，作用是如果String为空字符串，则返回0，否则返回Float格式的数字
//如果是非数字的字符串，将返回NaN(not a number)。
String.prototype.toFloat=function(){
	return this.length>0?(isNaN(this)?0:parseFloat(Number(this))):0;
}

//给String类型增加toInt方法，作用是如果String为空字符串，则返回0，否则返回Int格式的数字
//如果是非数字的字符串，将返回NaN(not a number)。
String.prototype.toInt=function(){
	return this.length>0?(isNaN(this)?0:parseInt(Number(this))):0;
}

//Add the trim method to the String object.
//This method is to delete blank characters at the left and right part of a string.
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

//Add the left trim and right trim method to the String object.
String.prototype.ltrim = function(){
	return this.replace(/(^\s*)/g, "");
}

String.prototype.rtrim = function(){
	return this.replace(/(\s*$)/g, "");
}

//Function that shows a ModalDialog.
function showmodal(url, diagArg, width, height, statusbar){
	window.showModalDialog(url, diagArg, (width?("Dialogwidth:" + width +"px;"):"") + (height?("Dialogheight:"+height+"px;"):"") + (statusbar?("status:" + statusbar + ";"):"") + "scroll:no;help:no;")
}

//打开窗口的函数，窗口位置是屏幕中间
function openwindowEx(url, width, height, scroll, name, status){
	width=width?width:640;
	height=height?height:480;
	var ileft=(screen.availWidth-width)/2;
	var itop=(screen.availHeight-height)/2;
	var subwin=window.open(url, (name?name:"subwindow"), "left=" + ileft + ",top=" + itop + ",width=" + width + ",height=" + height + ",toolbars=no" + (scroll?(",scrollbars=" + scroll):"") + (status?(",status=" + status):""));
	subwin.focus();
}

//去除两边空白字符的函数，相当于vb的trim
//空白字符包括：空格、tab、垂直tab、回车和form-feed字符
function jtrim(str){
	//使用正则表达式匹配字符串
	//其中\s表示空白字符，\S表示非空白字符，*表示匹配0个或者多个，+表示匹配1个或者多个
	//括号匹配并记录结果，(?:pattern)匹配但不记录结果，$1表示括号内得到的匹配结果
	//使用(\s+\S+)*是因为字符串中间也可能出现空白字符
	//var reg=/^\s*(\S*(?:\s+\S+)*)\s*$/;
	var regLeft=/^\s*/;
	var regRight=/\s*$/;
	return str.replace(regLeft,"").replace(regRight,"");
}

//除法函数，用来得到精确的除法结果
//说明：javascript的除法结果会有误差，在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用：accDiv(arg1,arg2)
//返回值：arg1除以arg2的精确结果
function accDiv(arg1,arg2){
	var t1=0,t2=0,r1,r2;
	try{t1=arg1.toString().split(".")[1].length}catch(e){}
	try{t2=arg2.toString().split(".")[1].length}catch(e){}
	with(Math){
		r1=Number(arg1.toString().replace(".",""))
		r2=Number(arg2.toString().replace(".",""))
		return (r1/r2)*pow(10,t2-t1);
	}
}

//给Number类型增加一个div方法，调用起来更加方便。
Number.prototype.div = function (arg){
	return accDiv(this, arg);
}

//乘法函数，用来得到精确的乘法结果
//说明：javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用：accMul(arg1,arg2)
//返回值：arg1乘以arg2的精确结果
function accMul(arg1,arg2)
{
	arg1=String(arg1);var i=arg1.length-arg1.indexOf(".")-1;i=(i>=arg1.length)?0:i
	arg2=String(arg2);var j=arg2.length-arg2.indexOf(".")-1;j=(j>=arg2.length)?0:j
	return arg1.replace(".","")*arg2.replace(".","")/Math.pow(10,i+j)
}

//给Number类型增加一个mul方法，调用起来更加方便。
Number.prototype.mul = function (arg){
	return accMul(this, arg);
}

//加法函数，用来得到精确的加法结果
//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用：accAdd(arg1,arg2)
//返回值：arg1加上arg2的精确结果
function accAdd(arg1,arg2){
	var r1,r2,m;
	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
	m=Math.pow(10,Math.max(r1,r2))
	return (arg1.mul(m)+arg2.mul(m))/m
}

//给Number类型增加一个add方法，调用起来更加方便。
Number.prototype.add = function (arg){
	return accAdd(this, arg);
}

//方便调用的精确减法
function accMinus(arg1, arg2){
	var r1,r2,m;
	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
	m=Math.pow(10,Math.max(r1,r2));
	return (arg1.mul(m)-arg2.mul(m))/m
}

Number.prototype.minus = function (arg){
	return accMinus(this, arg);
}
//-->