/*---------------------------------------------------------

	标准的JScript头文件：std.js
	常用的标准函数
	
---------------------------------------------------------*/

 
//标准的超级链接
//-------------------------------------------------------B

//鼠标移在链接上，增加下划线和字体变成蓝色
function MouseOver(pthis)
{
	pthis.style.textDecorationUnderline = true;
	pthis.style.color = "blue";
}

//鼠标移出链接，去掉下划线和字体变成蓝色
function MouseOut(pthis)
{
	pthis.style.textDecorationUnderline = false;
	pthis.style.color = "blue";
}

//-------------------------------------------------------E


//字符替换常用函数
//-------------------------------------------------------B

//替换掉为编码而替换的符号，对&ebsp;和&nbsp;特殊处理
function ReplaceSpecial(str)
{	
	do{
	strold=str;
	str=str.replace("&lt;","<");
	str=str.replace("&gt;",">");
	//str=str.replace("&ebsp;","\r\n");
	str=str.replace("&ebsp;","<br>");
	//str=str.replace("&nbsp;"," ");
	str=str.replace("&quot;","\"");
	str=str.replace("&amp;","&");
	}while(str!=strold)
	return str;
}

//替换掉为编码而替换的符号
function ReplaceAll(str)
{	
	do{
	strold=str;
	str=str.replace("&lt;","<");
	str=str.replace("&gt;",">");
	str=str.replace("&ebsp;","\r\n");
	str=str.replace("&nbsp;"," ");
	str=str.replace("&quot;","\"");
	str=str.replace("&amp;","&");
	}while(str!=strold)
	return str;
}

//-------------------------------------------------------E


//数据检测使用函数
//-------------------------------------------------------B

//是否为EMAIL
function IsEmail(x,fShow)	
{
	var sEmail, bEmail
	var nAtLoc
	
	sEmail = KillSpace(x);
	nAtLoc=sEmail.indexOf("@")
	bEmail=true
	
	if(!((nAtLoc>1) && (sEmail.lastIndexOf(".")>nAtLoc+1)))
	{		
		bEmail=false			
	}
	if(sEmail.indexOf("@",nAtLoc+1)!=-1)
	{	
		bEmail=false
	}
	if(sEmail.charAt(nAtLoc+1)==".")
	{	
		bEmail=false
	}
	if(sEmail.length - sEmail.lastIndexOf(".")<2)
	{	
		bEmail=false
	}	
	if(!bEmail && fShow)
		alert("\n请检查您的Email是否正确！")
	return bEmail		
}

//判断是否是数字
function IsNumber(s, n)
{
	if(((s.length>n) && (n!=0)) || (s.length==0)){
		return false;
	}
	var i=0;
	var ch;
	while(i<s.length){
		ch=s.charAt(i);
		if((ch>'9')||(ch<'0'))
			return false;
		i++;
	}
	return true;
}

//检测字符或字是否是全角。
function IsHalfWord(charWord)
{
	var tempWord = charWord;
	tempWord = tempWord.toLowerCase();
	switch  (tempWord)
	{
		case "0":
			return true;
		case "1":
			return true;
		case "2":
			return true;
		case "3":
			return true;
		case "4":
			return true;
		case "5":
			return true;
		case "6":
			return true;
		case "7":
			return true;
		case "8":
			return true;
		case "9":
			return true;
		case "0":
			return true;
		case "a":
			return true;
		case "b":
			return true;
		case "c":
			return true;
		case "d":
			return true;
		case "e":
			return true;
		case "f":
			return true;
		case "f":
			return true;
		case "g":
			return true;
		case "h":
			return true;
		case "i":
			return true;
		case "j":
			return true;
		case "k":
			return true;
		case "l":
			return true;
		case "m":
			return true;
		case "n":
			return true;
		case "o":
			return true;
		case "p":
			return true;
		case "q":
			return true;
		case "r":
			return true;
		case "1":
			return true;
		case "s":
			return true;
		case "t":
			return true;
		case "u":
			return true;
		case "v":
			return true;
		case "w":
			return true;
		case "x":
			return true;
		case "y":
			return true;
		case "z":
			return true;
		case "`":
			return true;
		case "~":
			return true;
		case "!":
			return true;
		case "@":
			return true;
		case "#":
			return true;
		case "$":
			return true;
		case "%":
			return true;
		case "^":
			return true;
		case "&":
			return true;
		case "*":
			return true;
		case "(":
			return true;
		case ")":
			return true;
		case "-":
			return true;
		case "_":
			return true;
		case "=":
			return true;
		case "+":
			return true;
		case "{":
			return true;
		case "[":
			return true;
		case "}":
			return true;
		case "]":
			return true;
		case "\\":
			return true;
		case "|":
			return true;
		case ";":
			return true;
		case ":":
			return true;
		case "'":
			return true;
		case "\"":
			return true;
		case ",":
			return true;
		case "<":
			return true;
		case "/":
			return true;
		case "?":
			return true;
		case ">":
			return true;
		case ".":
			return true;
		case " ":
			return true;
			
		//小键盘上的字符
		case "/":
			return true;
		case "*":
			return true;
		case "-":
			return true;
		case "+":
			return true;
		
		//判断是否有回车和换行，在其它模块中处理部分处理
		
		default:
			return false;
	}
	return false;	
}

//是否是日期
function IsDate(str)
{
	try
	{
		symbol1Postion = str.indexOf("/");
		symbol2Postion = str.indexOf("-");
		if(symbol1Postion != "-1" && symbol2Postion != "-1")
			return false;
	
		if(symbol1Postion != "-1")
		{
			strYear = str.substring(0, symbol1Postion);
			strYear = parseInt(strYear);
			if(strYear > 9999 || strYear < 1753)
				return false;
			symbolPostion2 = str.indexOf("/", symbol1Postion+1);
			strMonth = str.substring(symbol1Postion+1, symbolPostion2);
			strMonth = parseInt(strMonth);
			if(strMonth>12 || strMonth<1)
				return false;
			strDay = str.substring(symbolPostion2+1, str.length);
			strDay = parseInt(strDay);
			if(strDay>31 || strDay<1)
				return false;
		}
		else if(symbol2Postion != "-1")
		{
			strYear = str.substring(0, symbol2Postion);
			strYear = parseInt(strYear);
			if(strYear > 9999 || strYear < 1753)
				return false;
			symbolPostion1 = str.indexOf("-", symbol2Postion+1);
			strMonth = str.substring(symbol2Postion+1, symbolPostion1);
			strMonth = parseInt(strMonth);
			if(strMonth>12 || strMonth<1)
				return false;
			strDay = str.substring(symbolPostion1+1, str.length);
			strDay = parseInt(strDay);
			if(strDay>31 || strDay<1)
				return false;
		}
		else 
			return false;
		return true;
	}
	catch (e)
	{
		return false;
	}
}

//是否是时间
function IsTime(str)
{
	try
	{
		symbolPostion1 = str.indexOf(":");
		symbolPostion2 = str.indexOf(":", symbolPostion1+1);
	
		if(symbolPostion1 != "-1" && symbolPostion2 != "-1")
		{
			strHour = str.substring(0, symbolPostion1);
			strHour = parseInt(strHour);
			if(strHour > 23 || strHour < 0)
				return false;
			strMinute = str.substring(symbolPostion1+1, symbolPostion2);
			strMinute = parseInt(strMinute);
			if(strMinute>59 || strMinute<0)
				return false;
			strSecond = str.substring(symbolPostion2+1, str.length);
			strSecond = parseInt(strSecond);
			if(strSecond>59 || strSecond<0)
				return false;
		}
		else if(symbolPostion1 != "-1" && symbolPostion2 == "-1")
		{
			strHour = str.substring(0, symbolPostion1);
			strHour = parseInt(strHour);
			if(strHour > 23 || strHour < 0)
				return false;
			strMinute = str.substring(symbolPostion1+1, str.length);
			strMinute = parseInt(strMinute);
			if(strMinute>59 || strMinute<0)
				return false;
		}
		else 
			return false;
		return true;
	}
	catch (e)
	{
		return false;
	}
}

//是否是日期时间
function IsDatetime(str)
{
	
	strlen = parseInt(str.length);
	if(str.length<8)
		return false;
		
	var i;
	var tempChar;
	for(i = 0; i< str.length; i++)
	{
		tempChar = str.charAt(i);
		switch (tempChar)
		{
			case "0":
				break;				
			case "1":
				break;
			case "2":
				break;
			case "3":
				break;
			case "4":
				break;
			case "5":
				break;
			case "6":
				break;
			case "7":
				break;
			case "8":
				break;
			case "9":
				break;
			case "/":
				break;
			case " ":
				break;
			case ":":
				break;
			case "-":
				break;
			default:
				return false;
		}
	}
	
	spacePostion = str.indexOf(" ");
	if(spacePostion == "-1")	//只有日期
	{
		return IsDate(str);
	}
	else	//含日期和时间
	{
		strDate = str.substring(0, spacePostion);
		strTime = str.substring(spacePostion+1, strlen);
		if(IsDate(strDate) == true && IsTime(strTime) == true)
			return true;
		else 
			return false;
	}
	return false;
}

//-------------------------------------------------------E



//根据图片的高度计算文字的个数Begin
//-------------------------------------------------------B

//计算该区域能够填充字符或字的个数。
function GetTopWordsPosition(content, PicHeight, PicWidth, TableWidth, WordHeight, WordWidth, LetterSpace, LineHeight)
{
	var LWidth, LHeight, TempStr, WordHeight, WordWidth;
	var CharOrWordNums, LineNums, ContentLength, WordNums;
	//WordHeight = 14.7;
	//WordWidth = 14.7;
	//LWidth = 587 - 5 - PicWidth;
	WordHeight = parseFloat(WordHeight);
	WordWidth = parseFloat(WordWidth);
	LWidth = parseInt(TableWidth) - PicWidth;
	LHeight = PicHeight;
	LineHeight = parseFloat(LineHeight);
	LineNums = parseInt(LHeight/LineHeight);
	TempStr = content;
	ContentLength = TempStr.length;
	var CharCounter, LineCounter, LineWidthCounter;
	WordNums = 0;
	CharCounter = 0;
	LineCounter = 1;
	LineWidthCounter = 0.0;
	//alert(ContentLength);
	
	//alert(LineNums);
	while(CharCounter<ContentLength&&LineCounter<=LineNums)
	{
		TempChar = TempStr.charAt(CharCounter);
		if (TempChar == "\r")	//检验是否是段落结束，回车和换行
		{
			temp = TempStr.substring(CharCounter, CharCounter+2);
			if(temp == "\r\n")
			{
				LineCounter++;
				LineWidthCounter = 0.0;
				CharCounter = CharCounter + 2;
			}
			else
			{
				CharCounter++;
			}
		}
		else 
		{
			if (IsHalfWord(TempChar) == true)
				LineWidthCounter = LineWidthCounter + WordWidth/2.0;
			else
				LineWidthCounter = LineWidthCounter + WordWidth;
			CharCounter++;
		}
		LineWidthCounter = LineWidthCounter + LetterSpace;
		if(LineWidthCounter >= LWidth)
		{
			LineCounter++;
			LineWidthCounter = 0.0;
		}
	}
	return CharCounter;
}

//-------------------------------------------------------E


//数据处理函数
//-------------------------------------------------------B

//除去前后的空格
function KillSpace(x)
{
	while((x.length>0) && (x.charAt(0)==' '))
		x = x.substring(1,x.length)
	while((x.length>0) && (x.charAt(x.length-1)==' '))
		x = x.substring(0,x.length-1)
	return x
}

//除去前缀0
function KillZero(s)
{
	var i=0;
	var ch;
	var nFlag;
	nFlag=false;
	var str;
	str="";
	while(i<s.length)
	{
		ch=s.charAt(i);
		if(ch!='0'||nFlag==true)
		{
			nFlag=true;
			str+=ch;
		}
		i++;
	}
	return str;
}

//-------------------------------------------------------E

