function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
 
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

function Trim(str){return RTrim(LTrim(str));}

function XMLEncode(str){
	str=Trim(str);
	str=str.replace("&","&amp;");
	str=str.replace("<","&lt;");
	str=str.replace(">","&gt;");
	str=str.replace("'","&apos;");
	str=str.replace("\"","&quot;");
	return str;
}

function cn2num(str){
	var s;
	var numeral;
	var entries;
	var tenNum;
	s=str;
	s=s.replace(/一/g,'1');
	s=s.replace(/二/g,'2');
	s=s.replace(/三/g,'3');
	s=s.replace(/四/g,'4');
	s=s.replace(/五/g,'5');
	s=s.replace(/六/g,'6');
	s=s.replace(/七/g,'7');
	s=s.replace(/八/g,'8');
	s=s.replace(/九/g,'9');
	s=s.replace(/零/g,'0');
	s=s.replace(/○/g,'0');
	if(s.indexOf('十')>=0){
	tenNum = regExpGet(s, '([0-9]*十)');
	entries= s.substr(s.indexOf('十')+1, s.length-s.indexOf('十')-1);
	if(tenNum=='十'){tenNum=10}
	else(tenNum = regExpGet(tenNum, "([1-9]+)") + '0')
	numeral = new Number(tenNum)+new Number(entries);
	}else{numeral=s}
	return(numeral);
}

function OpenWindow(Url){
	window.open(Url,'','top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
}

function compareDate(strDate1,strDate2) {
	var tmp1=strDate1.split('-');
	var tmp2=strDate2.split('-');
	var date1=eval('new Date('+tmp1[0]+','+tmp1[1]+','+tmp1[2]+')');
	var date2=eval('new Date('+tmp2[0]+','+tmp2[1]+','+tmp2[2]+')');
	//if ((date2.valueOf()-date1.valueOf())>=20*24*60*60*1000)
	if ((date2.valueOf()-date1.valueOf())>=0)	{return true;}
	else{return false;}
}


/*
   Open popup widows of (mostly) predetermined types.

   windowURL -- The URL to load in the new browser window.
   type -- The (predetermined) type of window to launch.
           acceptable values for type:
           1: a help window
           2: a 400x400 window
           3: Issuezilla assignable users popup window
           ... and you can hard code others yourself inside the function.
   atts -- (optional) If the window you wish to create is unique and you do
           not want to set up a "type" for it, or if you want to pass
           additional attributes for a certain "type", you can pass its
           attributes directly to the function via this parameter.
*/
var tigrisPopupCounter = 0;
function launch(windowURL, type, atts) {
  tigrisPopupCounter += 1;

  var windowName = 'SourceCast' + type;
  if (atts) {windowName += tigrisPopupCounter;}

  var winAtts;
  if (type == 1) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=485,width=724,status=1,scrollbars=1,toolbar=1,menubar=1,location=1';}
  else if (type == 2) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=400,width=400';}
  else if (type == 3) {winAtts = 'resizable=1,left=10,top=10,screenX=12,screenY=12,height=440,width=600,scrollbars=1';}
  if (atts) {winAtts += ',' + atts;}

  var windowObj = window.open(windowURL, windowName, winAtts);

  if (windowObj) {return false;}
  else {return true;}
}

/*----------------------------------------------------------------------------*/
/**
 * 转换阿拉伯数字为汉字数码
 * @author fpeez
 * @author fpeez@163.com
 * @version 1.0
 * 主体函数, 实现转换
 * @param inString    (String)输入的阿拉伯数字字符串(如: "13800138000")
 * @param isUpcase    (boolean)输出汉字数码大小写指示(如: false)
 * @param times       (String)阶数(如: "个万亿兆...")
 * @param errorCode   (String)错误时(溢出,空值,...)归零显示(如: "E")
 * @return ~errorCode
 * @return ~OUT       (String)转换后的汉字数码(如: "一百三十八亿〇一十三万八千")
 * eg. changeDigitToHZ("13800138000",false,"个万亿兆","E")
*/
function changeDigitToHZ(inString, isUpcase, times, errorCode) {
	/** 输入字符串预处理, 亦可放到函数外执行 **/
	inString=formatedDigit(inString);
	/** 变量定义 **/
	var base,digit;                           // times: 阶数("个万亿兆...")
	if(isUpcase) {
		base="个拾佰仟";                      // base: 位数
		digit="零壹贰叁肆伍陆柒捌玖";         // digit: 汉字数码串(大写)
	} else {
		base="个十百千";
		digit="〇一二三四五六七八九";
	}

	var sLen,b,t,bLen;
	sLen=inString.length;                     // 输入字符串的长度
	bLen=base.length;                         // 位数的长度
	if(sLen>bLen*times.length || sLen<1) return errorCode;      // 溢出归零
	b=(sLen-1)%bLen;                          // 当前数码在base中的位置
	t=Math.floor((sLen-1)/bLen);              // 当前数码在times中的位置
	var i,at,zero;
	i=0;                                      // at某个位上的数码, i循环计数
	zero="";                                  // 保存数字中的0值
	var OUT="";                                   // 输出汉字数码

	/** 开始 **/
	at=inString.charCodeAt(i)-48;             // 处理"一十二"为"十二", 此时i=0
	if(at==1 && b==1){
		OUT+=base.charAt(b--);
		i+=1;                                 // 此时, i=1
	}
	while(i<sLen) {
		at=inString.charCodeAt(i++)-48;
		if(b!=0) {
			if(at!=0) {
				OUT+=zero;
				zero="";
				OUT+=digit.charAt(at);
				OUT+=base.charAt(b);
			} else zero=digit.charAt(0);         // 此时, zero="零"或"〇"
			b--;
		} else {
			if(at!=0) {
				OUT+=zero;
				OUT+=digit.charAt(at);
			}
			zero="";
			if(t!=0) OUT+=times.charAt(t--);
			b=bLen-1;
		}
	}

  return OUT;  
}


