function picsize(obj,MaxWidth,MaxHeight){
  img=new Image();
  img.src=obj.src;
if (img.width>MaxWidth && img.height>MaxHeight){
	if (img.width/img.height>MaxWidth/MaxHeight) {
		obj.height=MaxWidth*img.height/img.width;
		obj.width=MaxWidth;
	}else {
		obj.width=MaxHeight*img.width/img.height;
		obj.height=MaxHeight;
	}
}else if (img.width>MaxWidth) {
	obj.height=MaxWidth*img.height/img.width;
	obj.width=MaxWidth;
}else if (img.height>MaxHeight) {
	obj.width=MaxHeight*img.width/img.height;
	obj.height=MaxHeight;
}else{
		obj.width=img.width;
		obj.height=img.height;
}
}




function  showSign(srcString)
{
	if(srcString != "" && srcString.length>3)
  {
	 	srcString = ubbReplace(srcString, 'abchij');
		document.write('<hr align="center" width="95%" size="0" noshade class="linet">');
	 	document.write(srcString);
	}
}

function showBrief(srcString)
{
	if(srcString != "NOBRIEF " && srcString != " ")
	{
		srcString = htmlReplace(srcString);
	 	srcString = formatReplace(srcString);
	 	document.write(srcString);
	}
}

////////////////////////////////////////////////////
//检查输入值是否为integer,flag表示是否可以包含+-号
function checkInteger(object_value,flag){
    if (object_value.length == 0)return true;
	var decimal_format = ".";
	var check_char;
	check_char = object_value.indexOf(decimal_format);
    if (check_char < 1)
		return checkNumber(object_value,flag);
    else
		return false;
}
////////////////////////////////////////////////////////
//检查输入值是否为数字，flag为1时不允许包含正负号
function checkNumber(object_value,flag){
    if (object_value.length == 0)return true;
	var start_format;
	if (flag == 0)
		start_format = " .+-0123456789";
	else
		start_format = ".0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 0)
	    return false;//decimal = true; Can not be decimal;
	else if (check_char < 1)
		return false;
		else if (check_char <4 && object_value.length == 1)
			return false;
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++){
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1){
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}else if (check_char == 0){
			if (decimal || digits)
				trailing_blank = true;// ignore leading blanks
		}else if (trailing_blank)
			return false;
		else
			digits = true;
	}//All tests passed, so...
    return true;
}

function goStaticpage(formname,allNum,goNum,url)
{

var gopage=new Number(goNum);
var allpage=new Number(allNum);

	if(gopage<=0 || gopage>allpage)
	{
		alert('对不起，您输入的页面超过了有效范围，请重新输入！');
		return false;
	}
	formname.action=url;
	return true;
}

function havePic(id)
{
	if(id%2 != 0)
	{
		document.write("[<font color='#FF0000'>图</font>]");
	}
}

function newopen()
{
	var url_1="/cgi-bin/photo/cgi_show_upload2";
	window.open(url_1,"","scrollbars=no,height=320,width=500");
}

function showAnswerTimes(id)
{
	if(id > 0)
	{
		document.write("<font color='#FF0000'>"+id+"</font>");
	}
	else
	{
		document.write(id);
	}
}

function showVisitTimes(id)
{
	if(id > 100)
	{
		document.write("<font color='#FF0000'>"+id+"</font>");
	}
	else
	{
		document.write(id);
	}
}

var INT_MAX_LENGTH = 14;

////////////////////////////////////////////////
//校验输入的特殊字符
function validateSpe(value){
	for (var i = 0; i < value.length; i++){
	  	if (//(value.charAt (i) == '\"')
	     	//|| (value.charAt (i) == '^')
	   	((value.charAt(i)>'&')&&(value.charAt(i)<'('))   //"'"
	     	//||((value.charAt(i)>'[')&&(value.charAt(i)<']')) //"\"
	     	//|| (value.charAt (i) == '/')
	     	//|| (value.charAt (i) == '&')
	     	//|| (value.charAt (i) == '#')
	     	//|| (value.charAt (i) == '$')
	     	//|| (value.charAt (i) == '%')
	     	//|| (value.charAt (i) == '|')
	     	//|| (value.charAt (i) == '+')
	     	//|| (value.charAt (i) == '*')
	     	|| (value.charAt (i) == '<')
	     	|| (value.charAt (i) == '>')
	     	)
  		return false;
 	}
 	return true;
}

////////////////////////////////////////////////////
//检查输入值是否为integer,flag表示是否可以包含+-号
function checkInteger(object_value,flag){
    if (object_value.length == 0)return true;
	var decimal_format = ".";
	var check_char;
	check_char = object_value.indexOf(decimal_format);
    if (check_char < 1)
		return checkNumber(object_value,flag);
    else
		return false;
}
////////////////////////////////////////////////////////
//检查输入值是否为数字，flag为1时不允许包含正负号
function checkNumber(object_value,flag){
    if (object_value.length == 0)return true;
	var start_format;
	if (flag == 0)
		start_format = " .+-0123456789";
	else
		start_format = ".0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 0)
	    return false;//decimal = true; Can not be decimal;
	else if (check_char < 1)
		return false;
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++){
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1){
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}else if (check_char == 0){
			if (decimal || digits)
				trailing_blank = true;// ignore leading blanks
		}else if (trailing_blank)
			return false;
		else
			digits = true;
	}//All tests passed, so...
    return true;
}

/////////////////////////////////////////
// check mail address format
function isMailAddress(address){
	var j=0;
	if(address == '')return false;
	if(address.length < 3)return false;//only: a@b
	if(hasBlank(address))return false;
	if(address.indexOf('@') >= 1){
		for(var i=0; i<address.length; i++){
			if(address.charAt(i)=='@')j++;
		}
		if(j>1)return false;
		if( (address.charAt(0)=='@') || (address.charAt(address.length-1)=='@') ){
			return false;//leading and last character cannot be @
		}else{
			if(!validateSpe(address)){
				return false;
			}
			return true;
		}
	}else{
		return false;
	}
	return true;
}


/////////////////////////////////////
//检查输入值中是否有空格
function hasBlank(value){
	var i = 0;
	for(var j=0; j<value.length; j++){
		if(value.charAt(j)==' ')i++;
	}
	if(i==0){
		return false;//no blank
	}
	return true;//blank
}

/*++++++++++++++++++++++++++++ UBB Function +++++++++++++++++++++++++++++++++++*/
var ubbtexta, ubbtextb, ubbtextc;
function ubbtietu(contentObj)
{
	ubbtexta = prompt("请输入图片的地址","http://");
  if(ubbtexta == null)
		return;
	ubbtextb = "[img]"+ubbtexta+"[\/img]";
	contentObj = eval(contentObj);
	contentObj.value += ubbtextb;
	//diary_form.content.value += ubbtextb;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}

function ubbfont(ftype, obj)
{
	ubbtexta = prompt("请输入文字","");
  if(ubbtexta == null || ubbtexta=="" || ubbtexta == '')
		return;
	ubbtextb = "["+ftype+"]"+ubbtexta+"[\/"+ftype+"]";
	obj=eval(obj);
	obj.value += ubbtextb;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}
function ubbselectfont(ftype,objselect, objconnect)
{
	ubbtexta = prompt("请输入文字","");
	if(ubbtexta == null || ubbtexta == "" || ubbtexta == '')
		return;
	objselect=eval(objselect);
	objconnect=eval(objconnect);
	ubbtextb=objselect.value;
	if(ftype == "face")
	{
		ubbtextb="[ftf="+ubbtextb+"]"+ubbtexta+"[/ft]"
	}
	else if(ftype == "size")
	{
		ubbtextb="[fts="+ubbtextb+"]"+ubbtexta+"[/ft]"
	}
	else if(ftype == "color")
	{
		ubbtextb="[ftc="+ubbtextb+"]"+ubbtexta+"[/ft]"
	}
	else
	{
		return;
	}
	objconnect.value += ubbtextb;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}

function ubbhyperlink(obj)
{
	ubbtexta = prompt("请输入链接要显示的文字,只能包含中文,英文字母,或中英文混合","请点击这里");
	ubbtextb = prompt("请输入URL地址","http://");
  if(ubbtextb == null)
		return;
	if(ubbtexta == null || ubbtexta == "" || ubbtexta == '')
	{
		ubbtextc = "[url]"+ubbtextb+"[\/url]";
	}
	else
	{
		ubbtextc = "[url="+ubbtexta+"]"+ubbtextb+"[\/url]";
	}
	obj=eval(obj);
	obj.value += ubbtextc;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}
function ubbemail(obj)
{
	ubbtexta = prompt("请输入链接要显示的文字,只能包含中文,英文字母,或中英文混合","请发email给我");
 	ubbtextb = prompt("请输入email地址","abc@abc.com");
	if(ubbtextb == "abc@abc.com" || ubbtextb == null || !isMailAddress(ubbtextb))
	{
		return;
	}
	else
	{
		if(ubbtexta == null || ubbtexta == "" || ubbtexta == '')
		{
			ubbtextc = "[email]" + ubbtextb + "[/email]";
	  }
		else
		{
			ubbtextc = "[email="+ubbtexta+"]" + ubbtextb + "[/email]";
		}
	}
	obj=eval(obj);
	obj.value += ubbtextc;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}

function ubbflash(obj)
{
	ubbtexta = prompt("请输入Flash的URL地址","http://");
	ubbtextb = prompt("请输入Flash高度和宽度","350,200");
  if(ubbtexta == null)
		return;
	ubbtextb = "[flash,"+ubbtextb+"]"+ubbtexta+"[\/flash]";
	obj=eval(obj);
	obj.value += ubbtextb;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}
function ubbquote(obj)
{
	obj=eval(obj);
	ubbtexta = obj.value;
	ubbtextb = "[quote]"+ubbtexta+"[/quote]";
	diary_form.content.value = ubbtextb;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}
function ubbvideo(obj)
{
	var autostart = "true";
	ubbtexta = prompt("请输入视频文件地址","");
	if(ubbtexta == null || ubbtexta == "" || ubbtexta == '')
		return;
	ubbtextb = prompt("请输入视频文件显示大小","350,200");
	if(ubbtextb == null || ubbtextb == "" || ubbtextb == '')
	{
		ubbtextb = "350,200";
	}
	ubbtextc = prompt("请输入是否自动播放,默认为自动播放(yes自动，no不自动播放）","yes");
	{
		if(ubbtextc != "yes")
			autostart = "false";
	}
	var strvideo = "[embed,"+ubbtextb+","+autostart+"]"+ubbtexta+"[/embed]";
	obj=eval(obj);
	obj.value += strvideo;
	ubbtexta = ""; ubbtextb = ""; ubbtextc = "";
}

function ubbvideom(obj)
{
	var str;
	var surl, size, vheight, vwidth, vauto, vloop;
	obj=eval(obj);
	var val= showModalDialog("UbbHtml/video.htm", "", "dialogWidth:360px;dialogHeight:225px;status:no;help:no");
		if(!val)
			return;
	surl = val[0], size=val[1], vheight=val[2], vwidth=val[3],vauto=val[4], vloop=val[5];
	if(vauto != 'true')
		vauto = 'false';
	if(vloop != 'true')
		vloop = 'false';
	if(surl == null || surl == '' || surl == undefined)
		return;
	if(size == 'auto')
	{
		str = "[video,"+vauto+","+vloop+"]"+surl+"[/video]";
		obj.value += str;
	}
	else if(size == 'define')
	{
		if(!checkInteger(vheight,1) || !checkInteger(vwidth,1))
			return;
		str = "[video,"+vwidth+","+vheight+","+vauto+","+vloop+"]"+surl+"[/video]";
		obj.value += str;
	}
	else
	{
		return;
	}
}

function ubbflashm(obj)
{
	var str;
	var surl, size, vheight, vwidth, tflash, tleft,ttop;
	obj=eval(obj);
	var val= showModalDialog("UbbHtml/flash.htm", "", "dialogWidth:360px;dialogHeight:250px;status:no;help:no");
		if(!val)
			return;
	surl = val[0], size=val[1], vheight=val[2], vwidth=val[3], tflash=val[4], tleft=val[5], ttop=val[6];
	if(surl == null || surl == '' || surl == undefined)
		return;
	if(tflash == false)
	{
		if(size == 'auto')
		{
			str = "[flash]"+surl+"[/flash]";
			obj.value += str;
		}
		else if(size == 'define')
		{
			if(!checkInteger(vheight,1) || !checkInteger(vwidth,1) || !(vheight) || !(vwidth))
				return;
			str = "[flash,"+vwidth+","+vheight+"]"+surl+"[/flash]";
			obj.value += str;
		}
	}
	else
	{
		if(!checkInteger(tleft,1) || !checkInteger(ttop,1) || !(ttop) || !(tleft))
				return;
		if(size == 'auto')
		{
			str = "[flasht,350,300,"+tleft+","+ttop+"]"+surl+"[/flasht]";
			obj.value += str;
		}
		else if(size == 'define')
		{
			if(!checkInteger(vheight,1) || !checkInteger(vwidth,1) || !(vheight) || !(vwidth))
				return;
			str = "[flasht,"+vwidth+","+vheight+","+tleft+","+ttop+"]"+surl+"[/flasht]";
			obj.value += str;
		}
	}
	return;
	
}
function ubbaudiom(obj)
{
	var str;
	var surl, vauto, vloop, vshow;
	obj=eval(obj);
	var val= showModalDialog("UbbHtml/audio.htm", "", "dialogWidth:360px;dialogHeight:190px;status:no;help:no");
		if(!val)
			return;
	surl = val[0], vauto=val[1], vloop=val[2]; vshow=val[3];
	if(vauto != 'true')
		vauto = 'false';
	if(vloop != 'true')
		vloop = 'false';
	if(vshow != 'true')
		vshow = 'invisible';
	else
		vshow = 'visible';

	if(surl == null || surl == '' || surl == undefined)
		return;
	str = "[audio,"+vauto+","+vloop+","+vshow+"]"+surl+"[/audio]";
	obj.value += str;
}

function ubbfacem(obj)
{
	var str;
	obj=eval(obj);
	var val= showModalDialog("UbbHtml/Face.htm", "", "dialogWidth:360px;dialogHeight:190px;status:no;help:no");
		if(!val)
			return;
		val = "[em]e"+val+"[/em]";
	obj.value += val;
}

function ubbpicturem(obj)
{
	var str;
	var val= showModalDialog("UbbHtml/picture_inc.htm", obj, "dialogWidth:380px;dialogHeight:210px;status:no;help:no");
		if(!val)
			return;
		val = "[img]"+val+"[/img]";
	obj.value += val;
}

function ubbcolorm(obj)
{
	var str, ffg;
	obj=eval(obj);
	var val= showModalDialog("UbbHtml/color.htm", "", "dialogWidth:360px;dialogHeight:150px;status:no;help:no");
	if(!val)
		return;
	ubbtexta = prompt("请输入文字","");
	if(ubbtexta == null || ubbtexta == "" || ubbtexta == '')
		return;
	str = val[0], ffg = val[1];
	if(ffg == true)
		str = "[ffg,#"+str+",#FFFFFF]"+ubbtexta+"[/ft]";
	else
		str = "[ftc=#"+str+"]"+ubbtexta+"[/ft]";
	obj.value += str;
}

function openUserSpaceDiary(sUin, sUrl)
{
	var openUrl = "http://q-zone.qq.com/client/?uin="+sUin+"&url="+escape(sUrl);
    if (getCookie("clientver") == "")
        window.open(openUrl, "space", "width=925,height=655,scrollbars=yes");
    else
        window.top.location=openUrl;
}// common.js

function contheight (sName){
	if (parent.document.all[sName]!=null) {
		parent.document.all[sName].style.height = document.body.scrollHeight;
	}
}

function openUserSpace(uin)
{
	var openUrl = "index.asp?Jauid="+uin;
	//if (parseInt(uin)==10)
	//{
	//	alert("该用户使用了隐身草道具，真实身份已被隐藏");
	//	return;
	//}    
	if (getCookie("clientver") == "")
        window.open(openUrl, "space", "width=925,height=655");
    else
        window.top.location=openUrl;

}

function setFileCookie(name,value){
	var expires=new Date();
	expires.setTime(expires.getTime()+10*12*30*24*3600*1000);
	document.cookie = name + "=" + value + ";expires="+expires.toGMTString()+"; path=/; domain=qq.com";
}
function setCookie(name,value)
{
	document.cookie = name + "=" + value + "; path=/; domain=qq.com";
}
function getCookie(name){
	var search;
	search = name + "=";
	offset = document.cookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		end = document.cookie.indexOf(";", offset);
		if (end == -1)
			end = document.cookie.length;
		return unescape(document.cookie.substring(offset, end));
	}
	else
		return "";
}
function deleteCookie(name){
  setCookie(name, "");
}
function GetHistoryUrl(){
	var str = "";
	str += window.location;
	var url;
	if (str.lastIndexOf("?") == str.length -1){
		url = str.slice(0, -1);
	}else{
		url = str;
	}
	return url;
}
function Click(){
	window.event.returnValue = false;
}
/**判断是否是ASCII字符
*/
function IsAscii(ch){
	if(ch > 0 && ch <= 255){
		return true;
	}else{
		return false;
	}
}
/**字符串长度，返回的是字符的长度。一个汉字的长度为2
*/
function StrLenOfAscii(str){
	var str_len;
	str_len = 0;
	for(var i=0;i<str.length;i++){
		if(IsAscii(str.charCodeAt(i))){
			str_len += 1;
		}else{
			str_len += 2;
		}
	}
	return str_len;
}
/**根据需要的长度将字符串截断
	input : str要截断的字符串 length要截断的长度
	output: 截断后的字符串。
	如果截断后字符串长度比要求的大一，则末尾为一个英文字母加一个汉字的形式，将后面的汉字截掉
	如...d号＝＝》...d ，以保证长度不超长
*/
function TruncateStr(str,length){
	var len,idx;
	len = 0;
	idx = 0;
	if(length>=StrLenOfAscii(str)) return str;
	var str_result = "";
	length=length-1;
	while (len < length){
		str_result += str.charAt(idx);
		if(IsAscii(str.charCodeAt(idx))){
			len += 1;
		}else{
			len += 2;
		}
		idx += 1;
	}
	if(len > length){
		str_result = str_result.substr(0,str_result.length-1);
	}
return str_result+".";
}
function replaceVal(sHtml, sName, sValue){
	var aParamName;
	var sParamValue;
	var aSplit;
	var length;
	var i;
	var reg = new RegExp("{"+sName+"(.[0-9]+){0,1}}", "g");
	aParamName= sHtml.match(reg);
	if (aParamName == null){
		return sHtml;
	}
	for (i=0; i<aParamName.length; i++){
		aSplit = aParamName[i].split(".");
		if (aSplit.length > 1) {
			// 需要截断到指定长度的
			length = new Number(aSplit[1].replace("}",""));
			sParamValue = TruncateStr(sValue,length);
		}else{
			// 显示全部
			sParamValue = sValue;
		}
		sHtml= sHtml.replace(aParamName[i], sParamValue);
	}
	return sHtml;
}
//功能：扩展日期函数，支持YYYY-MM-DD或YYYY-MMDD hh:mm:ss字符串格式
//返回：如果正确，则返回javascript中支持UTC日期格式，如果错误，则返回false
//举例： var myDate = Date_Ex("2004-12-21 23:01:00"); //返回正确的日期
//       var myDate = Date_Ex("2004-12-21");     //返回正确的日期
//       var myDate = Date_Ex("2004-23-12 12:60:29");//返回false，且提示日期或时间超出有效范围
function Date_Ex(value1){
	var strDate = value1;
	if (strDate.length == 0)
		return false;
	//先判断是否为短日期格式：YYYY-MM-DD，如果是，将其后面加上00:00:00，转换为YYYY-MM-DD hh:mm:ss格式
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/;   //短日期格式的正则表达式
	var r = strDate.match(reg);
	if (r != null)   //说明strDate是短日期格式，改造成长日期格式
		strDate = strDate + " 00:00:00";
	reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})/;
	r = strDate.match(reg);
	if (r == null){
		alert("你输入的日期格式有误，正确格式为：2004-12-01 或 2004-12-01 12:23:45");
		return false;
	}
	var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
	return d;
}


