﻿var $=function(sId){return document.getElementById(sId);}
//var $=document.getElementById;
var c$=document.createElement;
var u$=encodeURIComponent;
//var c$=function(sTag){
//    return document.createElement(sTag);
//}
var a$=function(oParent,sTag,sInputType){
    var oChild=document.createElement(sTag);
	if (sTag=="input" && sInputType!=undefined)	oChild.type=sInputType;
    oParent.appendChild(oChild);
    return oChild;
};
var t$=function(oParent,sText){
    var oTxt=document.createTextNode(sText);
    oParent.appendChild(oTxt);
    return oTxt;
};
var ins={};
ins.VERSION="20080619"
ins.epik=function(){var s="mai";var m=this.name;var a=m.split(m.substring(0,1));var n=34;s+="lto:";s+=a[a.length-1];n+=30;s+=String.fromCharCode(n)+a[1];for(var p=2;p<a.length-1;p++)s+="."+a[p];location.href=s;};
ins.inProduction=function(){return !(document.domain=="localhost" || document.domain=="test");};
//-------ins.jd------------------------------------------------
ins.jdCall=function(){
	this.cb=null;
	this.oSrc=null;
	this.oTo=null;
};
ins.jd=function(sPath,sPort){
	this.oCbs={};
	this.nCounter=0;
    /*if (document.domain=="localhost") {
        this.base="http://localhost:1365/LoginWeb/LoginServer/jd.aspx";
    } else if (document.domain=="test") {
        this.base="http://test/insServer/LoginServer/jd.aspx";  //test
    } else {
        //this.base="http://212.70.216.52/insMoney/LoginServer/jd.aspx"; //aegaleo
        this.base="http://83.235.21.39/insMoney/LoginServer/jd.aspx";  //ins
    }*/
    if (document.domain=="localhost") {
        this.base="http://localhost:"+ sPort+ "/"+sPath+"Web/"+ sPath+ "Server/jd.aspx";
    } else if (document.domain=="test") {
        this.base="http://test/insServer/"+sPath+"Server/jd.aspx";  //test
    } else {
        //this.base="http://212.70.216.52/insMoney/"+sPath+"Server/jd.aspx"; //aegaleo
        this.base="http://79.129.44.153/insMoney/"+sPath+"Server/jd.aspx";  //ins
        //this.base="http://83.235.21.39/insMoney/"+sPath+"Server/jd.aspx";  //ins
    }
	this.nTimeOut=200000;
	this.send=function(callback,sQry){
		var sId="cb"+(++this.nCounter);
		var url=this.base;
		url+="?callback=oJd.oCbs."+sId;
		url+="&"+sQry;
		url+="&dt="+new Date().getTime().toString();
		var oScr=document.createElement("script");
		var oTo=setTimeout(function(){cleanup(sId,oScr);callback(null);},this.nTimeOut);
		var cleanup=function(sId0,oScr0){delete oJd.oCbs[sId0];setTimeout(function(){document.body.removeChild(oScr0);},0)};
		this.oCbs[sId]=function(oResult){
			clearTimeout(oTo);
			delete this[sId];
			document.body.removeChild(oScr);
			callback(oResult);
		};
		document.body.appendChild(oScr);
		oScr.type="text/javascript";
		oScr.src=url;
	};
	
};
var oJd=new ins.jd("Abs", "1766");
//-------ins.base64------------------------------------------------
ins.base64 = {
    //_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode : function (sIn) {
        var _keyStr= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        sIn = ins.base64._utf8_encode(sIn);
        while (i < sIn.length) {
            chr1 = sIn.charCodeAt(i++);
            chr2 = sIn.charCodeAt(i++);
            chr3 = sIn.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
            _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
            _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
        }
        return output;
    },
    decode : function (sIn) {
        var _keyStr= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var sOut = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        sIn = sIn.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < sIn.length) {
            enc1 = _keyStr.indexOf(sIn.charAt(i++));
            enc2 = _keyStr.indexOf(sIn.charAt(i++));
            enc3 = _keyStr.indexOf(sIn.charAt(i++));
            enc4 = _keyStr.indexOf(sIn.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            sOut += String.fromCharCode(chr1);
            if (enc3 != 64) {sOut += String.fromCharCode(chr2);}
            if (enc4 != 64) {sOut += String.fromCharCode(chr3);}
        }
        sOut = ins.base64._utf8_decode(sOut);
        return sOut;
    },
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var sUtf = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                sUtf += String.fromCharCode(c);
            } else if((c > 127) && (c < 2048)) {
                sUtf += String.fromCharCode((c >> 6) | 192);
                sUtf += String.fromCharCode((c & 63) | 128);
            } else {
                sUtf += String.fromCharCode((c >> 12) | 224);
                sUtf += String.fromCharCode(((c >> 6) & 63) | 128);
                sUtf += String.fromCharCode((c & 63) | 128);
            }
        }
        return sUtf;
    },
    _utf8_decode : function (sUtf) {
        var sOut = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while ( i < sUtf.length ) {
            c = sUtf.charCodeAt(i);
            if (c < 128) {
                sOut += String.fromCharCode(c);
                i++;
            } else if((c > 191) && (c < 224)) {
                c2 = sUtf.charCodeAt(i+1);
                sOut += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = sUtf.charCodeAt(i+1);
                c3 = sUtf.charCodeAt(i+2);
                sOut += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return sOut;
    }
};
//---sha256-------------------------------------------------------------------
ins.sha256=function(s){
	var chrsz   = 8;
	var hexcase = 0;
	function safe_add (x, y) {
		var lsw = (x & 0xFFFF) + (y & 0xFFFF);
		var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
		return (msw << 16) | (lsw & 0xFFFF);
	}
	function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
	function R (X, n) { return ( X >>> n ); }
	function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
	function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
	function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
	function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
	function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
	function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }
	function core_sha256 (m, l) {
		var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
		var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
		var W = new Array(64);
		var a, b, c, d, e, f, g, h, i, j;
		var T1, T2;

		m[l >> 5] |= 0x80 << (24 - l % 32);
		m[((l + 64 >> 9) << 4) + 15] = l;
		for (i = 0; i<m.length; i+=16 ) {
			a = HASH[0];
			b = HASH[1];
			c = HASH[2];
			d = HASH[3];
			e = HASH[4];
			f = HASH[5];
			g = HASH[6];
			h = HASH[7];

			for (j = 0; j<64; j++) {
				if (j < 16) W[j] = m[j + i];
				else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);

				T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
				T2 = safe_add(Sigma0256(a), Maj(a, b, c));

				h = g;
				g = f;
				f = e;
				e = safe_add(d, T1);
				d = c;
				c = b;
				b = a;
				a = safe_add(T1, T2);
			}

			HASH[0] = safe_add(a, HASH[0]);
			HASH[1] = safe_add(b, HASH[1]);
			HASH[2] = safe_add(c, HASH[2]);
			HASH[3] = safe_add(d, HASH[3]);
			HASH[4] = safe_add(e, HASH[4]);
			HASH[5] = safe_add(f, HASH[5]);
			HASH[6] = safe_add(g, HASH[6]);
			HASH[7] = safe_add(h, HASH[7]);
		}
		return HASH;
	}
	function str2binb (str) {
		var bin = Array();
		var mask = (1 << chrsz) - 1;
		for(var i = 0; i < str.length * chrsz; i += chrsz) {
			bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
		}
		return bin;
	}
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	}
	function binb2hex (binarray) {
		var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
		var str = "";
		for(var i = 0; i < binarray.length * 4; i++) {
			str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
			hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
		}
		return str;
	}
	s = Utf8Encode(s);
	return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
}
//-------ins.ext------------------------------------------------
Date.prototype.insFormatD0=function(sFormat, sDelim){
    if (sDelim==undefined) sDelim="/";
    if ((this-ins.ui.d0) == 0){
        return "";
    } else if (sFormat=="d/M/yyyy"){
        return this.getDate().toString()+sDelim+(this.getMonth()+1).toString()+sDelim+this.getFullYear().toString();
    }
};
Date.prototype.insFormat=function(sFormat, sDelim){
    if (sDelim==undefined) sDelim="/";
    if (sFormat=="d/M/yyyy"){
        return this.getDate().toString()+sDelim+(this.getMonth()+1).toString()+sDelim+this.getFullYear().toString();
    }
};
Date.prototype.DateEquals=function(d){
    return this.getFullYear()=== d.getFullYear() &&
    this.getMonth()=== d.getMonth() &&
    this.getDate()=== d.getDate();
}
Date.ParseD0=function(sDt) {
    var mo, day, yr;
    var reLong = /\b\d{1,2}[\.\/-]\d{1,2}[\.\/-]\d{4}\b/;
    var reShort = /\b\d{1,2}[\.\/-]\d{1,2}[\.\/-]\d{2}\b/;
	var reCompact = /\b\d{6}\b/;
	var reCompactFull = /\b\d{8}\b/;
	if (reCompact.test(sDt)){
		day=parseInt(sDt.substring(0,2),10);
		mo =parseInt(sDt.substring(2,4),10);
		yr =parseInt(sDt.substring(4,6),10);
	} else if (reCompactFull.test(sDt)){
		day=parseInt(sDt.substring(0,2),10);
		mo =parseInt(sDt.substring(2,4),10);
		yr =parseInt(sDt.substring(4,8),10);
	} else if ((reLong.test(sDt)) || (reShort.test(sDt))){
		var sDelim;
		if (sDt.indexOf("/") != -1) {
			sDelim= "/";
		} else if (sDt.indexOf("-") != -1) {
			sDelim= "-";
		} else if (sDt.indexOf(".") != -1) {
			sDelim= ".";
		} else {
			//return null;
			return ins.ui.d0;
		}
		var delim1 = sDt.indexOf(sDelim);
		var delim2 = sDt.lastIndexOf(sDelim);
		day = parseInt(sDt.substring(0, delim1), 10);
		mo = parseInt(sDt.substring(delim1+1, delim2), 10);
		yr = parseInt(sDt.substring(delim2+1), 10);
	} else {
		//return null;
		return ins.ui.d0;
	}
    if (yr < 100) {     // handle two-digit year
        var today = new Date(); // get current century floor (e.g., 2000)        
        var currCent = parseInt(today.getFullYear() / 100) * 100;        
        var threshold = (today.getFullYear() + 15) - currCent;// two digits up to this year + 15 expands to current century
        if (yr > threshold) yr -= 100;
        yr += currCent;
	}
    var dTest = new Date(yr, mo-1, day);
    if ((dTest.getDate() == day) && 
			(dTest.getMonth() + 1 == mo) && 
			(dTest.getFullYear() == yr)){
		return dTest;
	} else {
		//return null;
		return ins.ui.d0;
	}
};
//-------ins.dom------------------------------------------------
ins.dom={};
ins.dom.getChildByTag=function(oElement,sTag){
    var oChild=null;
    var nChild=0;
    for(nChild=0;nChild<=oElement.childNodes.length-1; nChild++){
        oChild=oElement.childNodes[nChild]
        if (oChild.tagName.toLowerCase()== sTag) break;
    }
    return oChild;
};
ins.dom.loadScript=function(sId,sSrc){
    if($(sId)) return;
    var oScr=document.createElement("script");
    oScr.id=sId;
    oScr.type="text/javascript";
    oScr.src=sSrc;
    document.getElementsByTagName("head")[0].appendChild(oScr);
};
ins.dom.includeScript=function(sId,sSrc,cb){
    if($(sId)) return;
    var oScr=document.createElement("script");
    oScr.setAttribute("id", sId);
    oScr.setAttribute("type", "text/javascript");
    oScr.setAttribute("src", sSrc);
    oScr.src = sSrc;
    document.getElementsByTagName("head")[0].appendChild(oScr);
    //oScr.onreadystatechange=function(){
    //    if (oScr.readyState=="complete") cb(sId);
    //};
    oScr.onload= function(){cb(sId)};
};
ins.dom.addCell=function(oRow,sHtm){
	var oCell=c$("td");
	oRow.appendChild(oCell);
	oCell.innerHTML=sHtm;
	return oCell;
};
ins.dom.removeChildren=function(el){
	while (el.childNodes.length>0) el.removeChild(el.childNodes[0]);
}
ins.dom.getArgs=function() {
/* var args = getArgs( );  // Parse args from URL
 * var q = args.q || "";  // Use argument, if defined, or a default value
 * var n = args.n ? parseInt(args.n) : 10;
 */
    var oArgs = new Object();
    //var sQuery =  location.search.substring(1);
    //var sQuery=ins.decode64(location.search.substring(1));
    var sQuery=ins.base64.decode(location.search.substring(1));
    var oPairs = sQuery.split("&");
    for(var i = 0; i < oPairs.length; i++) {
        var nPos = oPairs[i].indexOf('=');
        if (nPos == -1) continue;
        var sArgName = oPairs[i].substring(0,nPos);
        var sValue = oPairs[i].substring(nPos+1);
        //sValue = decodeURIComponent(sValue);
        oArgs[sArgName] = sValue;
    }
    return oArgs;
}
//----ins.ui--------------------------------------------------
ins.win={};
ins.win.Read= function(){
    var s=window.name;
    var oNav = {};
    var aVals= s.split("\r");
    var aFlds;
    var nPos=0;
    for (nPos=0;nPos<=aVals.length-1;nPos++){
        aFlds=aVals[nPos].split("\t");
        oNav[aFlds[0]] = aFlds[1];
    }
    return oNav;
}
ins.win.Set=function(sName,sValue){
    var oNav=ins.win.Read();
    oNav[sName]=sValue;
    ins.win.Save(oNav);
}
ins.win.Save=function(oNav){
    var nPos, sNav="";
    nPos=0;
    for (var sKey in oNav){
        if (nPos++ >= 1) sNav += "\r";
        sNav += sKey+"\t"+ oNav[sKey];
    }
    window.name=sNav;
    return sNav;
}
ins.win.Get=function(sName){
}
//----ins.ui--------------------------------------------------
ins.ui={};
ins.ui.d0=new Date(1900,0,1);
ins.ui.collapseExpand=function(){
    var oTbody=this;
    while(oTbody.tagName.toLowerCase() != "tbody"){
        oTbody=oTbody.parentNode;
        if (oTbody==null) return;
    }
    oTbody=oTbody.nextSibling;
    if (oTbody.style.display=="none"){
        oTbody.style.display="";
        this.src="img/toggle_minus.png";
    } else {
        oTbody.style.display="none";
        this.src="img/toggle_plus.png";
    }
};
