
var rewinJSON_isIE = (document.all) ? true : false;
function isIE(){
	var navigatorName = "Microsoft Internet Explorer";   
	var isIE = false;   
	if(window.navigator.userAgent.indexOf("MSIE")>=1){   
	   isIE = true;       
	}
	return isIE;
}

rewinjson.tool.loadJS = function (jsFilePath,callback){
	new rewinjson.rewinAjax(jsFilePath,
				new rewinjson.tool.parameter("style","","","1=1"),
				function(repText,divID){eval(repText);if(callback)callback();},
				"POST",
				"rewinjson"
			);
}

rewinjson.tool.isIE = function (){
	var navigatorName = "Microsoft Internet Explorer";   
	var isIE = false;   
	if(window.navigator.userAgent.indexOf("MSIE")>=1){   
	   isIE = true;       
	}
	return isIE;
}
function rewinJSON_$(flag){
	if(!isIE()){//firefox
		return eval('document.getElementById("'+flag+'")');
	}else if(navigator.appName == "Microsoft Internet Explorer"){//IE
		return eval('document.all.'+flag);
	}
}
rewinjson.tool.$ = function(flag){
	if(!isIE()){//firefox
		return eval('document.getElementById("'+flag+'")');
	}else if(navigator.appName == "Microsoft Internet Explorer"){//IE
		return eval('document.all.'+flag); 
	}
}
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
　　-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
　　-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
　　-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
　　52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
　　-1,　0,　1,　2,　3,  4,　5,　6,　7,　8,　9, 10, 11, 12, 13, 14,
　　15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
　　-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
　　41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
//base64的编码方法；
rewinjson.tool.base64encode = function(str) {
　　var out, i, len;
　　var c1, c2, c3;
　　len = str.length;
　　i = 0;
　　out = "";
　　while(i < len) {
	 c1 = str.charCodeAt(i++) & 0xff;
	 if(i == len)
	 {
	　　 out += base64EncodeChars.charAt(c1 >> 2);
	　　 out += base64EncodeChars.charAt((c1 & 0x3) << 4);
	　　 out += "==";
	　　 break;
	 }
	 c2 = str.charCodeAt(i++);
	 if(i == len)
	 {
	　　 out += base64EncodeChars.charAt(c1 >> 2);
	　　 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
	　　 out += base64EncodeChars.charAt((c2 & 0xF) << 2);
	　　 out += "=";
	　　 break;
	 }
	 c3 = str.charCodeAt(i++);
	 out += base64EncodeChars.charAt(c1 >> 2);
	 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
	 out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
	 out += base64EncodeChars.charAt(c3 & 0x3F);
　　}
　　return out;
}
//base64 的解码方法
rewinjson.tool.base64decode = function(str) {
　　var c1, c2, c3, c4;
　　var i, len, out;
　　len = str.length;
　　i = 0;
　　out = "";
　　while(i < len) {
 /* c1 */
 do {
　　 c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
 } while(i < len && c1 == -1);
 if(c1 == -1)
　　 break;
 /* c2 */
 do {
　　 c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
 } while(i < len && c2 == -1);
 if(c2 == -1)
　　 break;
 out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
 /* c3 */
 do {
　　 c3 = str.charCodeAt(i++) & 0xff;
　　 if(c3 == 61)
　return out;
　　 c3 = base64DecodeChars[c3];
 } while(i < len && c3 == -1);
 if(c3 == -1)
　　 break;
 out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
 /* c4 */
 do {
　　 c4 = str.charCodeAt(i++) & 0xff;
　　 if(c4 == 61)
　return out;
　　 c4 = base64DecodeChars[c4];
 } while(i < len && c4 == -1);
 if(c4 == -1)
　　 break;
 out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
　　}
　　return out;
}

rewinjson.tool.utf16to8 = function (str) {
　　var out, i, len, c;
　　out = "";
　　len = str.length;
　　for(i = 0; i < len; i++) {
 c = str.charCodeAt(i);
 if ((c >= 0x0001) && (c <= 0x007F)) {
　　 out += str.charAt(i);
 } else if (c > 0x07FF) {
　　 out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
　　 out += String.fromCharCode(0x80 | ((c >>　6) & 0x3F));
　　 out += String.fromCharCode(0x80 | ((c >>　0) & 0x3F));
 } else {
　　 out += String.fromCharCode(0xC0 | ((c >>　6) & 0x1F));
　　 out += String.fromCharCode(0x80 | ((c >>　0) & 0x3F));
 }
　　}
　　return out;
}
rewinjson.tool.utf8to16 = function (str) {
　　var out, i, len, c;
　　var char2, char3;
　　out = "";
　　len = str.length;
　　i = 0;
　　while(i < len) {
 c = str.charCodeAt(i++);
 switch(c >> 4)
 {
　 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
　　 // 0xxxxxxx
　　 out += str.charAt(i-1);
　　 break;
　 case 12: case 13:
　　 // 110x xxxx　 10xx xxxx
　　 char2 = str.charCodeAt(i++);
　　 out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
　　 break;
　 case 14:
　　 // 1110 xxxx　10xx xxxx　10xx xxxx
　　 char2 = str.charCodeAt(i++);
　　 char3 = str.charCodeAt(i++);
　　 out += String.fromCharCode(((c & 0x0F) << 12) |
　　　　((char2 & 0x3F) << 6) |
　　　　((char3 & 0x3F) << 0));
　　 break;
 }
　　}
　　return out;
}

//把Unicode转成Ansi和把Ansi转换成Unicode
rewinjson.tool.UnicodeChr = function (){
return '00A4,00A7';
}

rewinjson.tool.AnsicodeChr = function (){
return 'A1E8,A1EC';
}

rewinjson.UnicodeToAnsi = function (chrCode)
{
        var chrHex=chrCode.toString(16);
        chrHex="000"+chrHex.toUpperCase();
        chrHex=chrHex.substr(chrHex.length-4);
        var i=rewinjson.tool.UnicodeChr().indexOf(chrHex);
        if(i!=-1)
        {
                chrHex=rewinjson.tool.AnsicodeChr().substr(i,4);
        }
        return parseInt(chrHex,16)
}

rewinjson.tool.AnsiToUnicode = function (chrCode)
{
        var chrHex=chrCode.toString(16);
        chrHex="000"+chrHex.toUpperCase();
        chrHex=chrHex.substr(chrHex.length-4);
        var i=rewinjson.tool.AnsicodeChr().indexOf(chrHex);
        if(i!=-1)
        {
                chrHex=rewinjson.tool.UnicodeChr().substr(i,4);
        }
        return parseInt(chrHex,16)
}

//将Unicode编码的字符串，转换成Ansi编码的字符串
rewinjson.tool.strUnicode2Ansi = function (asContents)
{
        var len1=asContents.length;
        var temp="";
        for(var i=0;i<len1;i++)
        {
                var varasc=asContents.charCodeAt(i);
                if(varasc<0)
                        varasc+=65536;
                if(varasc>127)
                        varasc=rewinjson.UnicodeToAnsi(varasc);
                if(varasc>255)
                {
                        var varlow=varasc & 65280;
                        varlow=varlow>>8;
                        var varhigh=varasc & 255;
                        temp+=String.fromCharCode(varlow)+String.fromCharCode(varhigh);
                }
                else
                {
                        temp+=String.fromCharCode(varasc);
                }
        }
        return temp;
}

//将Ansi编码的字符串，转换成Unicode编码的字符串
rewinjson.tool.strAnsi2Unicode = function (asContents)
{
        var len1=asContents.length;
        var temp="";
        var chrcode;
        for(var i=0;i<len1;i++)
        {
                var varasc=asContents.charCodeAt(i);
                if(varasc>127)
                {
                        chrcode=rewinjson.tool.AnsiToUnicode((varasc<<8)+asContents.charCodeAt(++i));
                }
                else
                {
                        chrcode=varasc;
                }
                temp+=String.fromCharCode(chrcode);
        }
        return temp;
}

//js格式化数据方法
rewinjson.tool.CheckParam = function (str1,str2){
	try{
		if(str1 == null || str1 == undefined || str1 == NaN || str1 == "" || str1 == "\"\""){
			return str2;
		}else{
			return str1;
		}
	}catch(e){
	}
}

//获得请示的代码参数；
var request = { 
	QueryString : function(val){ 
		var uri = window.location.search; 
		var re = new RegExp("" +val+ "=([^&?]*)", "ig"); 
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null); 
	}
}

//用来实现replaceAll的JS方法
String.prototype.replaceAll  = function(s1,s2){    
	return this.replace(new RegExp(s1,"gm"),s2);    
}
//封装了一个转换一此特殊字符的方法；
rewinjson.tool.replaceChart = function (StringParam){
		////<^>%'"&?@\|+$#
		StringParam = StringParam.trim();
		StringParam = StringParam.replaceAll("<","");
		StringParam = StringParam.replaceAll("\\^","");
		StringParam = StringParam.replaceAll("\\\\","");
		StringParam = StringParam.replaceAll(">","");
		StringParam = StringParam.replaceAll("%","");
		StringParam = StringParam.replaceAll("\'","");
		StringParam = StringParam.replaceAll("&","");
		StringParam = StringParam.replaceAll("\\?","");
		StringParam = StringParam.replaceAll("@","");
		StringParam = StringParam.replaceAll('"',"");
		StringParam = StringParam.replaceAll("\\|","");
		StringParam = StringParam.replaceAll("\\+","");
		StringParam = StringParam.replaceAll("\\$","");
		StringParam = StringParam.replaceAll("#","");
		return StringParam;
}
//去掉字符串中HTML代码
rewinjson.tool.formatData = function (param){
	return param.replace(/<[^>]*>/g, "").replace(/\r\n/g, "<br />")
}

//截取字符串中的指定字符长度的串；
rewinjson.tool.cutString = function (str,len){
	if(str != undefined){
		str_cut = rewinjson.tool.formatData(str);
		if(str_cut.length > len){
			var temp_str_cut = str_cut.substring(0,len)+"...";
			return str.replace(str_cut,temp_str_cut);
		}else{
			return str;
		}
	}else{
		return "";
	}
}

//正则匹配方法
rewinjson.tool.testReg = function (reg,str){ 
  return reg.test(str); 
}

//目前是支持将2008-05-12 09:13:27.0转换成Date类型
rewinjson.tool.strToTime = function (strTime){
	if(strTime != undefined){
		var arys= new Array();
		var myDate = null;
		var reg = /^\d{4}-\d{1,2}-\d{1,2}$/;
		var reg1 = /^\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}$/;
		var reg2 = /^\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}.\d{1,4}$/;
		try{
			if(rewinjson.tool.testReg(reg,strTime)){//2008-05-12
				arys = strTime.split('-');
				myDate = new Date(arys[0],parseInt(arys[1])-1,arys[2]);
				return myDate;
			}else if(rewinjson.tool.testReg(reg1,strTime)){//2008-05-12 09:13:27
				arys = strTime.split(' ');
				var arys_0 = arys[0].split('-');
				var arys_1 = arys[1].split(':');
				myDate = new Date(arys_0[0],parseInt(arys_0[1])-1,arys_0[2],arys_1[0],arys_1[1],arys_1[2]);
				return myDate;
			}else if(rewinjson.tool.testReg(reg2,strTime)){//2008-05-12 09:13:27.232
				arys = strTime.split(' ');
				var arys_0 = arys[0].split('-');
				var arys_1 = arys[1].split(':');
				var arys_2 = arys_1[2].split('.');
				myDate = new Date(arys_0[0],parseInt(arys_0[1])-1,arys_0[2],arys_1[0],arys_1[1],arys_2[0],arys_2[1]);
				return myDate;
			}
		}catch(e){
			return new Date();//返回当前时间；
		}
	}else{
		return new Date();//返回当前时间；
	}
}
/**计算天数差的函数，通用  说明前大后小返回大于0的数。**/
rewinjson.tool.showDiff = function (sDate1, sDate2){
	var firstDate, secDate, iDays ;
	if(sDate2 == undefined || sDate2 == NaN || sDate2 == "" || sDate2 == null){
		firstDate = rewinjson.tool.strToTime(sDate1);
		iDays = parseInt((firstDate - new Date()) / 1000 / 60 / 60 /24) ;//把相差的毫秒数转换为天数
	}else{
		firstDate = rewinjson.tool.strToTime(sDate1);
		secDate = rewinjson.tool.strToTime(sDate2);
		iDays = parseInt((firstDate - secDate) / 1000 / 60 / 60 /24) ;//把相差的毫秒数转换为天数 
	}
	return iDays ;
}
/**
格式化日期参数是
	inTimeStr:格式为2008-05-12 09:13:27.0的时间串
	formatStr:格式化的串如:
	yyyy-MM-dd hh:mm:ss
	yy-MM-dd
**/
rewinjson.tool.dateFormat = function(dateStr,format)
{
	var dateObj = rewinjson.tool.strToTime(dateStr);
	var o = {
	"M+" : dateObj.getMonth()+1, //month

	"d+" : dateObj.getDate(), //day

	"h+" : dateObj.getHours(), //hour

	"m+" : dateObj.getMinutes(), //minute

	"s+" : dateObj.getSeconds(), //second

	"q+" : Math.floor((dateObj.getMonth()+3)/3), //quarter

	"S" : dateObj.getMilliseconds() //millisecond

	}
	if(/(y+)/.test(format))
	format=format.replace(RegExp.$1,(dateObj.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
	if(new RegExp("("+ k +")").test(format))
	format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
	return format;
}
/**
 构造请求参数对象
    param1: 请求类型；
	param2: 请求参数串；
	param3: 请求返回值的URL连接；（上、下）行传递会以base64编码方式传递
	param4: 请求时的查询条件；（上、下）行传递会以base64编码方式传递
 **/
rewinjson.tool.parameter  = function (param1,param2,param3,param4){
	this.type = param1;
	this.parameter = param2;
	this.hrefURL = param3;
	this.filter = param4;
}
