﻿// JScript 文件

var useragent	= navigator.userAgent.toLowerCase();
var webtv		= useragent.indexOf('webtv') != -1;
var kon			= useragent.indexOf('konqueror') != -1;
var mac			= useragent.indexOf('mac') != -1;
var saf			= useragent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var opera		= useragent.indexOf('opera') != -1 && opera.version();
var moz			= (navigator.product == 'Gecko' && !saf) && useragent.substr(useragent.indexOf('firefox') + 8, 3);
var ns			= useragent.indexOf('compatible') == -1 && useragent.indexOf('mozilla') != -1 && !opera && !webtv && !saf;
var ie			= (useragent.indexOf('msie') != -1 && !opera && !saf && !webtv) && useragent.substr(useragent.indexOf('msie') + 5, 3);
function htmlencode(str) {
	str = str.replace(/&/g, '&amp;');
	str = str.replace(/</g, '&lt;');
	str = str.replace(/>/g, '&gt;');
	str = str.replace(/(?:\t| |\v|\r)*\n/g, '<br />');
	str = str.replace(/  /g, '&nbsp; ');
	str = str.replace(/\t/g, '&nbsp; &nbsp; ');
	str = str.replace(/\x22/g, '&quot;');
	str = str.replace(/\x27/g, '&#39;');
	return str;
}

function htmldecode(str) {
	str = str.replace(/&amp;/gi, '&');
	str = str.replace(/&nbsp;/gi, ' ');
	str = str.replace(/&quot;/gi, '"');
	str = str.replace(/&#39;/g, "'");
	str = str.replace(/&lt;/gi, '<');
	str = str.replace(/&gt;/gi, '>');
	str = str.replace(/<br[^>]*>(?:(\r\n)|\r|\n)?/gi, '\n');
	return str;
}

function textencode(str) {
	str = str.replace(/&amp;/gi, '&');
	str = str.replace(/</g, '&lt;');
	str = str.replace(/>/g, '&gt;');
	return str;
}

function textdecode(str) {
	str = str.replace(/&amp;/gi, '&');
	str = str.replace(/&lt;/gi, '<');
	str = str.replace(/&gt;/gi, '>');
	return str;
}
function getOffset(el) {
	var point = { x: el.offsetLeft, y: el.offsetTop };
	//Recursion
	if (el.offsetParent) {
		var parentPoint = getOffset(el.offsetParent);
		point.x += parentPoint.x;
		point.y += parentPoint.y;
	}
	return point;
}

function getScrollOffset() {
	var point;
	if (document.body.scrollTop != 0) {
		point = { x : document.body.scrollLeft, y : document.body.scrollTop };
	} else {
		point = { x : document.documentElement.scrollLeft, y : document.documentElement.scrollTop };
	}
	return point;
}
//var tooltip;
//document.write("<div id='js_tooltip' style='position:absolute; z-index:1000; visibility:hidden'></div>");
//function popLayer(e) {
//	var el = e.srcElement ? e.srcElement : e.target;
//	if (!el) {
//		return;
//	}
//	if (el.alt != null && el.alt != '') {
//		el.tooltip = el.alt;
//		el.alt = '';
//	}
//	if (el.title != null && el.title != '') {
//		el.tooltip = el.title;
//		el.title = '';
//	}
//	if (el.tooltip != tooltip) {
//		tooltip = el.tooltip;
//		var container = document.getElementById('js_tooltip');
//		if (tooltip == null || tooltip == '') {
//			container.style.display = 'none';
//			container.style.width = "0px";
//			container.style.visibility = 'hidden';
//		} else {
//			container.style.display = '';
//			container.style.width = "auto";
//			container.innerHTML = tooltip;
//			//.replace("<br>", '<br>');
//			if (container.clientWidth > 280) {
//				container.style.width = "280px";
//			}
//			var mouse = { x : e.clientX, y : e.clientY };
//			var scrollOffset = getScrollOffset();
//			var size = { w : container.clientWidth, h : container.clientHeight };
//			var adjustLeft  = mouse.x + 12 + size.w > document.body.clientWidth ?  - size.w - 12 : 12;
//			var adjustRight = mouse.y + 12 + size.h > document.body.clientHeight ? - size.h - 12 : 12;
//			container.style.left = (mouse.x + scrollOffset.x + adjustLeft) + 'px';
//			container.style.top  = (mouse.y + scrollOffset.y + adjustRight) + 'px';
//			container.style.visibility = 'visible';
//		}
//	}
//}
//document.onmouseover = function(e) {
//	if (typeof popLayer == "function") {
//		popLayer(ie ? event : e);
//	}
//}


function run(){}
 
function ShowTime() 
{
    d = new Date();
    document.write(d.getFullYear() +'年');
	document.write((d.getMonth()+1) + '月');
	document.write(d.getDate() + '日');
	document.write(d.getHours() +'时');
	document.write(d.getMinutes()+'分');
}
function Welcome()
{
    now = new Date(),hour = now.getHours()
	if ( parseInt(hour)<6) {document.write("凌晨好！")}
	else if (parseInt(hour)<8) {document.write("早上好！")}
	else if (parseInt(hour)<12) {document.write("上午好！")}
	else if (parseInt(hour)<14) {document.write("中午好！")}
	else if (parseInt(hour)<17) {document.write("下午好！")}
	else if (parseInt(hour)<22) {document.write("晚上好！")}
	else {document.write("夜里好！")}

}
 
String.prototype.isEmail = function()
{
	var email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return email.test(this);
}
 
String.prototype.isUrl = function(){
	var url = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	
	return url.test(this);
}
 
String.prototype.isInteger = function()
{
 
	var _i = /^[-\+]?\d+$/;
	return _i.test(this);
}
String.prototype.isFloat = function()
{
 
	var _i = /^[-\+]?\d+\.\d+$/;
	var isfloat  = _i.test(this);
	return isfloat;
}
String.prototype.isNumeric = function()
{
 
	var _i = /^[-\+]?\d+\.\d+$/;
	var isfloat  = _i.test(this);
	if ( this.isInteger())
	{
	  return true;
	}
	else if (isfloat)
	{
	  return true;
	}
	return false;
}
String.prototype.isUserID = function()

{
 
   var userid=/^\s*[A-Za-z0-9_-]{6,20}\s*$/;
   return userid.test(this);
}
 String.prototype.isPassword = function()
{
 
   //var userid=/^\s*[.A-Za-z0-9_-]{3,20}\s*$/;
   var userid=/^\s*[.A-Za-z0-9_-]{6,20}\s*$/;
   return userid.test(this);
}
String.prototype.isWhiteWpace=function()
{
  var whitespace = " \t\n\r";
  var i;
  for (i = 0; i < this.length; i++){ 
  var c = this.charAt(i);
  if (whitespace.indexOf(c) >= 0) {
  return true;
  }
  }
  return false;
}
String.prototype.ltrim=new Function("return   this.replace(/^\\s+/,'')");  
String.prototype.rtrim=new Function("return   this.replace(/\\s+$/,'')");
String.prototype.trim = function()
{
  return this.ltrim().rtrim();
}
String.prototype.isEmpty = function()
{
  return (this.trim()=='');
  
}

/* add 2007/09/22 */
function isEmpty( obj )
{
   return obj.value.trim().isEmpty() ;
}
function isUrl( obj )
{
  return obj.value.trim().isUrl() ;
}
function isFloat( obj )
{
  return obj.value.trim().isFloat() ;
}
function isNumeric( obj )
{
  return obj.value.trim().isNumeric() ;
}
function isInt( obj )
{
  
  if (obj.value.trim() =='0')
  {
   return true ;
  }
  else
  {
     return obj.value.trim().isInteger() ;
     }
}
function isEmail( obj )
{
     return obj.value.trim().isEmail() ;
}
function isPassword( obj )
{
     return obj.value.trim().isPassword() ;
}
function isUserID( obj )
{
     return obj.value.trim().isUserID() ;
}
function InputRestrict(textareaID,inputID,num)
{
  var textarea = document.getElementById(textareaID);
  if (textarea==null) return;
  var input = document.getElementById(inputID);
  input.value = num - textarea.value.length ;
  textarea.onkeypress = function()
  { 
     
   
     if (textarea.value.length>num)
     {
       textarea.value = textarea.value.substring(0,num);
     }
     else
     {
       input.value = num - textarea.value.length ;
     }
  }
  textarea.onkeyup = function()
  { 
     
   
     if (textarea.value.length>num)
     {
       textarea.value = textarea.value.substring(0,num);
     }
     else
     {
       input.value = num - textarea.value.length ;
     }
  }
  textarea.onmouseup = function()
  { 
     
   
     if (textarea.value.length>num)
     {
       textarea.value = textarea.value.substring(0,num);
     }
     else
     {
       input.value = num - textarea.value.length ;
     }
  }
  
}


function winOpen(Url,width,height)
{
	ow = width;
	oh = height;
	 
	var xposition=0; 
	var yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ))
	{
	xposition = (screen.width - width) / 2;
	yposition = (screen.height - height-25) / 2;
	}
	window.open (Url,"","width ="+ow+",height="+oh+",toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no,left="+xposition+",top="+yposition );
}



function addfavorite(url,text)
{
     if (document.all)
     {
     window.external.addFavorite(url,text);
     }
     else if (window.sidebar)
     {
     window.sidebar.addPanel(text,url, "");
     }
} 
function sethomepage(obj,vrl){
if (confirm('确认要将' + vrl + '设置为首页?'))
{
       try{
               obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
       }
       catch(e){
               if(window.netscape) {
                       try {
                               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                       }  
                       catch (e)  { 
                               alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");  
                       }
                       var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                       prefs.setCharPref('browser.startup.homepage',vrl);
                }
       }
}
}
//<![CDATA[
var tips; 
var theTop = 1;/*这是默认高度,越大越往下*/;
var old = theTop;
function initFloatTips() {
  tips = document.getElementById('loadinfo');
 
  moveTips();
};
function moveTips() {
  var tt=50;
  if (window.innerHeight) {
    pos = window.pageYOffset
  }
  else if (document.documentElement && document.documentElement.scrollTop) {
    pos = document.documentElement.scrollTop
  }
  else if (document.body) {
    pos = document.body.scrollTop;
  }
  pos=pos-tips.offsetTop+theTop;
  pos=tips.offsetTop+pos/10;
  if (pos < theTop) pos = theTop;
  if (pos != old) {
    tips.style.top = pos+"px";
    tt=10;
  }
  old = pos;
  setTimeout(moveTips,tt);
}
//!]]>
function folder(img, element)
{
	if ($(element).style.display == '')
	{
		img.src = img.src.replace('folder_open', 'folder_close');
		img.alt = '展开';
		$(element).style.display = 'none';
		var cookievalue = getCookie('closedfolder');
		cookievalue += element + '&';
		setCookie('closedfolder', cookievalue);
	}
	else
	{
		img.src = img.src.replace('folder_close', 'folder_open');
		img.alt = '收缩';
		$(element).style.display = '';
		var cookievalue = getCookie('closedfolder');
		cookievalue = cookievalue.replace(element + '&', '');
		setCookie('closedfolder', cookievalue);
	}
} 
function form(f) {
	switch (typeof f) {
		default:
		case null:
		case '':
		case 'undefined':
			return document.forms[0];
		case 'string':
		case 'number':
			return document.forms[f];
		case 'object':
			return f;
	}	
}
function undefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}
function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}
function inarray(obj, arr) {
	if(typeof obj == 'string') {
		for(var i in arr) {
			if(arr[i] == obj) {
					return true;
			}
		}
	}
	return false;
}
function getFileSize(uploader)
{
	try   
	{
		var fso, file; 
		fso = new ActiveXObject("Scripting.FileSystemObject"); 
		file =fso.GetFile(uploader.value); 
		return file.size;
	}   
	catch(e)   
	{
		return  -1;   
	}   
}
function isimg(src)
{
	var ext = ['.gif', '.jpg', '.jpeg', '.png'];
	var s = src.toLowerCase();
	var r = false;
	for(var i = 0; i < ext.length; i++)
	{
		if (s.indexOf(ext[i]) > 0)
		{
			r = true;
			break;
		}
	}	
	return r;
}
function jump(obj)
{
  location.href="board.aspx?boardid=" + obj.value;
}
function preview(value)
{
  testwin = open("");
  testwin.document.open();
  testwin.document.write(value);
  testwin.document.close();
}
function checkbyvalue(c, v)
{	
	if (!undefined(c.options))
	{
			
		for (var i = 0; i < c.options.length; i++)
		{
			if (c.options[i].value == v)
			{
				c.options[i].selected = true;
				break;
			}
		}
	}
	
}

function checkradiobyvalue(c, v)
{
	if (!undefined(c.item))
	{
		for (var i = 0; i < c.item.length; i++)
		{
			if (c.item(i).value == v)
			{
				c.item(i).checked = true;
				break;
			}
		}
	}
	
}
function limitContent(contentid,width)
{
   var elments = $(contentid).getElementsByTagName("*");
   for(var i=0;i<elments.length;i++)
  {
    if (parseInt(elments[i].getAttribute("width"))>width)
    {
       elments[i].setAttribute("width",width -1) ;
    }
    if (elments[i].style.width)
    {
        if (parseInt(elments[i].style.width)>width)
        {
           elments[i].style.width = width -1 ;
        }
    }
  }
 
}
function setfocus(objid)
{
    if (document.getElementById(objid))
    {
        document.getElementById(objid).focus();
    }
}
function select(objid)
{
    if (document.getElementById(objid))
    {
        document.getElementById(objid).focus();
        document.getElementById(objid).select();
    }
}
function breakWords(objid,width)
{
 
    var obj = document.getElementById(objid);
    var content =obj.innerHTML ;
   
    if ( content.length<=width)
    {
        obj.innerHTML  = content;
    }
    else
    {
        var str = '' ;
        
            for(var i=0;i<content.length;i++)
            {
                if (i % width !=0)
                {
                    str+=content.substr(i,1);
                    
                }
                else
                {
                   if(i!=0)
                   {
                    str+="<br/>" + content.substr(i,1);
                   }
                }
            }
      
         obj.innerHTML=str;
    }
}

 
function openWindow2(msg,width,height)
{	
    var sClientWidth = parent ? parent.document.documentElement.clientWidth : document.documentElement.clientWidth;
			var sClientHeight = parent ? parent.document.documentElement.clientHeight : document.documentElement.clientHeight;
			var sScrollTop = parent ? parent.document.documentElement.scrollTop : document.documentElement.scrollTop;
    if (!$("cardshow"))
	{
		if (!$("cardshowshadow"))
		{
			var divshtml = "<DIV id='cardshowshadow' style='background:#cccccc;filter: alpha(opacity=40);opacity: .4;width:" + width + "px;height:" + (height+15) + "px;'> </div>" ;
			var divs = document.createElement("div") ;
			document.body.appendChild(divs);
			divs.innerHTML = divshtml ;
			divs.style.display = "" ;
			divs.style.position = "absolute";
			divs.style.position = "absolute";
		divs.style.left = "50%";
		divs.style.top = "50%";
		divs.style.marginLeft = 0-width/2+"px";
		divs.style.marginTop = 0-height/2+document.documentElement.scrollTop+"px";
		}
		var divhtml = "<DIV id='cardshow'  style='background:#fcfcfc;width:" + width + "px;height:" + (height+20) + "px;border:1px solid #999999;'><div id='cardshowtitle'   onselectstart='return false;' style='background:url(/images/cardtitlebk.gif) repeat-x;-moz-user-select: none;width:"+ width + "px;height:10px;text-align:right;'><img src='/images/x1.gif' alt='关闭' style='cursor:pointer;' onmouseover='this.src=\"/images/x2.gif\";' onmouseout='this.src=\"/images/x1.gif\";' onclick='$(\"cardshow\").style.display=\"none\";$(\"cardshowshadow\").style.display=\"none\";'></div><div id='cardshowhtml'  style='width:"+ width + ";height:" + height + "px'><img src='../images/loadingred.gif'> 正在加载..</div></DIV>";
		var div = document.createElement("div") ;
		document.body.appendChild(div);
		div.innerHTML = divhtml ;
		div.style.display = "" ;
		div.style.position = "absolute";
		div.style.left = "50%";
		div.style.top = "50%";
		div.style.marginLeft = 0-width/2-6+"px";
		div.style.marginTop = 0-height/2-10+document.documentElement.scrollTop+"px";
	}
	$("cardshowhtml").innerHTML = "<img src='/images/loadingb.gif'> " + msg ;
	$("cardshow").style.display =""; 
	$("cardshowshadow").style.display =""; 
	   
}
function ItemOut(obj)
{            
    if(objbeforeItem)
    {
        objbeforeItem.style.backgroundColor=objbeforeItembackgroundColor;
    }    
}
function ItemOver(obj)
{
    objbeforeItembackgroundColor=obj.style.backgroundColor;
    obj.style.backgroundColor="#E0E0E0";                                        
    objbeforeItem=obj;
}
