﻿String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.replaceFirst = function(s1, s2)
{
	var firstposition = this.indexOf(s1);
	if (firstposition == -1) {
		return;
	}
	var output;
	output = this.substring(0, firstposition);
	output += s2;
	output += this.substring(firstposition + s1.length);
	return output;
}
try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}
function resize(that)
{
	try{
	var height = that.scrollHeight+20;
	if (height<200)
	{
		height = 200;
	}
	that.style.height = height;
	}catch(e){}
}
function text_format(that)
{
	var body = "\n"+that.value;
	body = body.replace(/ |　/ig,"");
	body = body.replace(/\r\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n/ig,"\n\n");
	body = body.replace("\n\n","");
	that.value=body;
}
function getCookie(namex)
{
	var cookies = document.cookie;
	var cookieHeader = namex + "=";
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}
function setCookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000;
	}
	var expires_date = new Date( today.getTime() + (expires) );  
	document.cookie = name + '=' + escape( value ) +   
	( ( expires ) ? ';expires=' + expires_date.toGMTString() : '' ) + //expires.toGMTString()   
	( ( path ) ? ';path=' + path : '' ) +      
	( ( domain ) ? ';domain=' + domain : '' ) +    
	( ( secure ) ? ';secure' : '' ); 
} 
function clogin()
{
	if (getCookie("x_username")!=""&&getCookie("x_password")!="")
	{
		return true;
	}
	return false;
}
function not()
{
	return true;
}
function removejs(obj)
{
	var childs = obj.childNodes;
	for (i=0;i<childs.length;i++)
	{
		var tagname = childs[i].tagName;
		if (tagname!=null&&childs[i]!=obj)
		{
			childs[i].onabort = new Function("not()");
			childs[i].oninput = new Function("not()");
			childs[i].onblur = new Function("not()");
			childs[i].onchange = new Function("not()");
			childs[i].onclick = new Function("not()");
			childs[i].ondblclick = new Function("not()");
			childs[i].onerror = new Function("not()");
			childs[i].onfocus = new Function("not()");
			childs[i].ondblclick = new Function("not()");
			childs[i].onkeydown = new Function("not()");
			childs[i].onkeypress = new Function("not()");
			childs[i].onkeyup = new Function("not()");
			childs[i].onload = new Function("not()");
			childs[i].onmousedown = new Function("not()");
			childs[i].onmousemove = new Function("not()");
			childs[i].onmouseout = new Function("not()");
			childs[i].onmouseover = new Function("not()");
			childs[i].onmouseup = new Function("not()");
			childs[i].onreset = new Function("not()");
			childs[i].onresize = new Function("not()");
			childs[i].onselect = new Function("not()");
			childs[i].onsubmit = new Function("not()");
			childs[i].onunload = new Function("not()");
			childs[i].onpropertychange = new Function("not()");		
			removejs(childs[i]);	
		}
	}
}
function getDate()
{
	var d = new Date()
	var vYear = d.getFullYear()
	var vMon = d.getMonth() + 1
	var vDay = d.getDate()
	var sb = "";
	sb += (vYear)
	sb += ("-")
	sb += (vMon<10 ? "0" + vMon : vMon)
	sb += ("-")
	sb += (vDay<10 ?  "0"+ vDay : vDay )
	return sb;
}
function getDateTime()
{
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var vHour = d.getHours();
	var vMinute = d.getMinutes();
	var vSecond = d.getSeconds();
	var sb = "";
	sb += (vYear);
	sb += ("-");
	sb += (vMon<10 ? "0" + vMon : vMon);
	sb += ("-");
	sb += (vDay<10 ?  "0"+ vDay : vDay );
	sb += (" ");
	sb += (vHour<10 ?  "0"+ vHour : vHour );
	sb += (":");
	sb += (vMinute<10 ?  "0"+ vMinute : vMinute );
	sb += (":");
	sb += (vSecond<10 ?  "0"+ vSecond : vSecond );
	return sb;
}
function getSmallDateTime()
{
	var d = new Date();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var vHour = d.getHours();
	var vMinute = d.getMinutes();
	var sb = "";
	sb += (vMon<10 ? "0" + vMon : vMon);
	sb += ("-");
	sb += (vDay<10 ?  "0"+ vDay : vDay );
	sb += (" ");
	sb += (vHour<10 ?  "0"+ vHour : vHour );
	sb += (":");
	sb += (vMinute<10 ?  "0"+ vMinute : vMinute );
	return sb;
}
function setAd2(ad)
{
	try
	{
		document.getElementById(ad).appendChild ( document.getElementById(ad+"s") );
		document.getElementById(ad+"s").style.display = "";
	}
	catch(e)
	{}
}
function setAd(ad)
{
	try
	{
		document.getElementById(ad).innerHTML = document.getElementById(ad+"s").innerHTML;
	}
	catch(e)
	{}
}
function str_len(txt)
{
	txt = txt.replace(/(<.*?>)/ig,'');
	txt = txt.replace(/([\u0391-\uFFE5])/ig,'11');
	var count = txt.length/2;
	return count;
}
function fcDecode(str)
{
	return decodeURIComponent(str);
}
function loadHtml(f, method, url)
{
	var http;
	try
	{
		http = new XMLHttpRequest();
	}
	catch(e)
	{
		http = new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	try
	{
		http.open(method, url, true);
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.onreadystatechange = function () 
		{
			if (http.readyState == 4)
			{
				if(http.status==200||http.status==302)
				{
					var text = http.responseText.trim();
					f(text);
					text = null;
				}
				else
				{
				}
				http = null;
			}
		}
		http.send('');
	}
	catch(e)
	{
		window.status = e.message;
	}
}
function getPosLeft(obj) 
{ 
	var l = obj.offsetLeft; 
	while(obj = obj.offsetParent) 
	{ 
		l += obj.offsetLeft; 
	} 
	return l; 
}
function getPosTop(obj) 
{ 
	var l = obj.offsetTop; 
	while(obj = obj.offsetParent) 
	{ 
		l += obj.offsetTop; 
	} 
	return l; 
}
function clearAuthenticationCache(page) 
{
	if (document.all)
	{
		document.execCommand("ClearAuthenticationCache");
		document.location.href = page;
	}
	else
	{
		var f = function(txt) 
		{
			document.location.href = page;
		}
		loadHtml(f, "GET", "https://logout:logout@"+document.location.host);
	}
}
Function.prototype.bindNode=function(oNode){  
    var foo=this,iNodeItem  
    if(window.__bindNodes==null)  
        __bindNodes=[]  
    __bindNodes.push(oNode)  
    iNodeItem=__bindNodes.length-1  
    oNode=null  
    return function(e){  
        foo.call(__bindNodes[iNodeItem],e||event)  
    }  
}  
function bind(object, event, callback)
{
	if (document.all)
	{
		object.attachEvent("on"+event, callback.bindNode(object));
	}
	else
	{
		object.addEventListener(event, callback.bindNode(object), false);
	}
}
function unbind(object, event)
{
	eval("object.on"+event+"='';");
}
function find_count(str, s1) {
	var count = 0;
	var fromindex = -1;
	while ((fromindex = str.indexOf(s1, fromindex + 1)) > -1) {
		count++;
	}
	return count;
}
function loadJs(url, callback, params)
{
	var script = document.createElement("script");
	script.src = url;
	if (callback)
	{
		if (script.readyState)
		{  //IE   
			script.onreadystatechange = function()
			{   
				if (script.readyState == "loaded" || script.readyState == "complete")
				{   
					if (params)
					{
						eval("callback("+params+");");   
					}
					else
					{
						callback();
					}
					script.parentNode.removeChild(script);
					script = null;
				}   
			};   
	    } else {  //Others   
			script.onload = function()
			{  
				if (params)
				{
					eval("callback("+params+");");   
				}
				else
				{
					callback();
				}
				script.parentNode.removeChild(script);
				script = null;
			};   
		} 
	}  
	document.getElementsByTagName('head')[0].appendChild(script);
}

var CCookie = {};

/*
	<summary>读取指定Cookie</summary>
	<params>
		<name>保存Cookie的变量名</name>
	</params>
	<return>返回指定变量的Cookie值</return>
*/
CCookie.get = function( name ){
	if( !( name = name.trim() ) ){
		return null;
	}
	var allCookies = document.cookie;
	var pos = allCookies.indexOf( name + "=" );
	if( pos != -1 ){
		var start = pos + name.length + 1;
		var end = allCookies.indexOf( ";", start );
		if( end == -1 )
			end = allCookies.length;
		var value = allCookies.substring( start, end );
		value = unescape( value );
		return value;
	}else{
		return "";
	}
};


/*
	<summary>移除指定cookie</summary>
	<params>
		<name>需要移除的cookie变量名称</name>
		<path>需要移除的cookie的作用路径</path>
		<domain>cookie的作用域</domain>
	</params>
	<return>指定cookie的值</return>
*/
CCookie.remove = function( name, path, domain ){
	var cookie;
	name = escape( name.trim() );
	path = path.trim();
	domain = domain.trim();
	cookie = name + "=";
	if( path != "" ){
		cookie += "; path=" + path;
	}
	if( domain != "" ){
		cookie += "; domain=" + domain;
	}
	cookie += "; expires=Fri, 02-Jan-1970 00:00:00 GMT";
	document.cookie = cookie;
};

/*
	<summary>创建cookie</summary>
	<params>
		<name>保存Cookie的变量名</name>
		<value>设置cookie的值</value>
		<expireHours>Cookie有效时间，以小时为单位</expireHours>
		<path>cookie的生效路径</path>
		<domain>cookie的作用域</domain>
	</params>
*/
CCookie.set = function( name, value, expireHours, path, domain ){
	path = path.trim();
	if( path == "" ){
		path = "/";
	}
	domain = domain.trim();
	name = escape( name );
	value = escape( value );
	var cookie = name + "=" + value;
	var expires = new Date( ( new Date() ).getTime() + expireHours*3600000 );
	cookie += "; expires=" + expires.toGMTString();
	if( path != "" ){
		cookie += "; path=" + path;
	}
	if( domain != "" ){
		cookie += "; domain=" + domain;
	}
	document.cookie = cookie;
};

//波的工具类
var CToolset = {};

//根据对象ID获取元素控制句柄
CToolset.getElement = function( objectID ){
	try{
		return document.getElementById( objectID );
	}catch( e ){
	}
};

