function HtmlEncode( text ) {
	//return text.replace(/&/g,'&amp').replace(/\"/g,   '&quot;').replace(/</g,   '&lt;').replace(/>/g,   '&gt;');
	var ret = "";
	if ( typeof(text) != "string" ) return ret;
	var arr = text.split('');
	for ( var i=0; i<arr.length; i++ ) {
		var s = arr[i];
		switch ( s ) {
			case "<" : ret += "&lt;"; break;
			case ">" : ret += "&gt;"; break;
			case "&" : ret += "&amp;"; break;
			case 13 : ret += "<br>"; break;
			case " " : ret += "&nbsp;"; break;
			default : ret += s;
		}
	}
	return ret;
}

getCookie = function (sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

function getQueryString(sArgName, sHref) {
	if ( sHref == undefined ) sHref = window.location.href;
	var args = sHref.split("?"); 
	var retval = ""; 
	if(args[0] == sHref) /*参数为空*/ 
	{ 
		return retval; /*无需做任何处理*/ 
	} 
	var str = args[1]; 
	args = str.split("&"); 
	for(var i = 0; i < args.length; i ++) 
	{ 
		str = args[i]; 
		var arg = str.split("="); 
		if(arg.length <= 1) continue; 
		if(arg[0] == sArgName) retval = arg[1]; 
	} 
	return retval; 
	//return (new RegExp("([^(&amp;|\?)]*)" + key + "=([^(&amp;|#)]*)").test(location.href+"#")) ? RegExp.$2 : null;
}

var isShortDate = function( sDate ) {
    var r = sDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
    if ( r == null ) return false;
    try {
        var myDate = new Date( r[1], r[3], r[4] );
    } catch( e ) {
        return false;
    }
    return true; 
}

//Str(时间字符串)
//包含时间(true:包含, false:不包含)
var formatDateTimeFromDateStr = function( Str, IncludeTime ) {
    var objDate = new Date( Str );
    var ret = objDate.getFullYear() + "-"
        + (objDate.getMonth()+1) + "-"
        + objDate.getDate();
    if ( IncludeTime ) {
        ret += " "
            + objDate.getHours() + ":"
            + ((objDate.getMinutes()<10)?"0"+objDate.getMinutes():objDate.getMinutes()) + ":"
            + ((objDate.getSeconds()<10)?"0"+objDate.getSeconds():objDate.getSeconds());
    }
    return ret;
}
var formatDateTimeFromBigDateStr = function( Str, IncludeTime ) {
    var objDate = new Date( Str );
    var ret = objDate.getFullYear() + "年"
        + (objDate.getMonth()+1) + "月"
        + objDate.getDate()+"日 ";
    if ( IncludeTime ) {
        ret += " "
            + objDate.getHours() + ":"
            + ((objDate.getMinutes()<10)?"0"+objDate.getMinutes():objDate.getMinutes()) + ":"
            + ((objDate.getSeconds()<10)?"0"+objDate.getSeconds():objDate.getSeconds());
    }
    return ret;
}
function formatToMoney( Number, Dollars )
{
	if ( Dollars == 1 ) Dollars = 1; else Dollars = 0;
	function outputDollars( Number )
	{
		if ( Number.length <= 3 || Dollars == 0 )
			return ( Number == '' ? '0' : Number );
        else
        {
			var mod = Number.length % 3;
            var output = (mod == 0 ? '' : (Number.substring(0,mod)));
            for (i=0 ; i< Math.floor(Number.length/3) ; i++)
            {
				if ((mod ==0) && (i ==0))
					output+= Number.substring(mod+3*i,mod+3*i+3);
				else
					output+= ',' + Number.substring(mod+3*i,mod+3*i+3);
            }
			return (output);
        }
    }
    function outputCents(amount) {
       amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
       return (amount<10 ? '.0' + amount : '.' + amount);
    }
	if( Number < 0 )
		return '-'+outputDollars(Math.floor(Math.abs(Number)-0) + '') + outputCents(Math.abs(Number) - 0);
	else
		return outputDollars(Math.floor(Number-0) + '') + outputCents(Number - 0);
}

//function trimString(bfTitleCharsSource, bfTitleLen)
//{
//    if(bfTitleCharsSource.replace(/[^\x00-\xff]/g,"xx").length <= bfTitleLen)
//    {
//        return bfTitleCharsSource;
//    }

//    var str = "";
//    var l = 0;
//    var bfTitleChars;
//    for(var i=0; bfTitleChars=bfTitleCharsSource.charAt(i); i++)
//    {
//        str += bfTitleChars;
//        l += (bfTitleChars.match(/[^\x00-\xff]/) != null ? 2 : 1);
//        if(l >= bfTitleLen)
//        {
//            str += "...";
//            break;
//        }
//    }
//    return str;
//}
//截取字符串
function cutString(bfTitleCharsSource, bfTitleLen,showDot)
{
    if(bfTitleCharsSource.replace(/[^\x00-\xff]/g,"xx").length <= bfTitleLen)
    {
        return bfTitleCharsSource;
    }

    var str = "";
    var l = 0;
    var bfTitleChars;
    for(var i=0; bfTitleChars=bfTitleCharsSource.charAt(i); i++)
    {
        str += bfTitleChars;
        l += (bfTitleChars.match(/[^\x00-\xff]/) != null ? 2 : 1);
        if(l >= bfTitleLen)
        {
            if (showDot==null)
                str += "...";            
            break;
        }
    }
    return str;
}
function formatMoneyToFloat( Str )
{
	var Number = "";
	Str += "";
	for ( var i=0; i<Str.length; i++ )
		if ( Str.substr(i, 1) != "," ) Number += Str.substr(i, 1);
	return parseFloat( Number );
}

Date.prototype.Format = function(formatStr) 
{ 
	var str = formatStr; 
	//var Week = ['日','一','二','三','四','五','六'];
	str=str.replace(/yyyy|YYYY/,this.getFullYear());
	str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
	str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());
	str=str.replace(/M/g,this.getMonth());
	//str=str.replace(/w|W/g,Week[this.getDay()]);
	str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
	str=str.replace(/d|D/g,this.getDate());
	str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
	str=str.replace(/h|H/g,this.getHours());
	str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
	str=str.replace(/m/g,this.getMinutes());
	str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
	str=str.replace(/s|S/g,this.getSeconds());
	return str; 
} 