﻿function encPass(obj,key) {
    var md5 = new MD5Class();
    var tmp = obj.value.substring(0, 1)
    var pwd = md5.getStr(obj.value);
    if ($chkid('isone')) {
        var one = $id('isone'); one.value = 0;
    }
    var str = pwd.substring(0, 16); str = md5.getStr(key + str);
    obj.value = (str.substring(0, 16)) + (pwd.substring(16, 32));
}
function GetUserId(u) {
    var m = '0123456789abcdefghijklmnopqrstuvwxyz';
    var x = 10;
    var s, i, l, n, v, d;
    v = 0; s = (u.substring(0, x)).toLowerCase(); l = s.length; n = m.length;
    for (i = 0; i < l; i++) {
        v *= n; d = m.indexOf(s.substring(i, i + 1), 0); v += d;
    }
    return v
}
function GetIdUser(l) {
    var m = '0123456789abcdefghijklmnopqrstuvwxyz';
    var x = 10;
    var s = '', d = 0, n, i, v = l, n = m.length;
    for (i = 0; i < x; i++) {
        d = v % n; alert(v + '|' + d + '|' + n); v -= d; v = Math.floor(v / n); s = m.substring(d, d + 1) + s;
        if (v == 0) break;
    }
    return s;
}
function GetCurrentStyle(obj) {
    if (!obj) { return null; }
    if (obj.currentStyle) {
        return obj.currentStyle;
    }
    else if (window.getComputedStyle) {
        return document.defaultView.getComputedStyle(obj, null);
    }
    return null;
}
function getselvalue(o,v)
{
    for(var i=0;i<o.options.length;i++){
	    if(o.options[i].value==v){
		    document.write(o.options[i].text);
		    return;
	    }
    }
    document.write(v);
}
function chkInput(str){if(window.event.keyCode == 13){ eval('try{'+str+'}catch(e){}'); event.returnValue = false; }}
function toShow(str){
	return (repShowtag(str)).replace(/\=\"\#\//g,'="'+hrefroot+site_root);
}
function toSave(str){
    var s = str;
    eval("s = s.replace(/\\=\\\""+(hrefroot+site_root).replace(/\//g,'\\/')+"/g,'=\"#/');");
    s = s.replace(/<A href/g,'<A target=_blank href'); 
    s = chgSavetag(s);
	return s;
}
function chgSavetag(o)
{
    var s = o.replace(/\{\\\}/g,'');
	s = s.replace(/\{\/\}/g,'');
	s = s.replace(/\{\-\}/g,'');
	s = s.replace(/\{\=\}/g,'');
	s = s.replace(/\{\(\}/g,'');
	s = s.replace(/\{\)\}/g,'');
	s = s.replace(/\{/g,'{\}');
	s = s.replace(/\}/g,'{/}');
	s = s.replace(/\'/g,'{-}');
	s = s.replace(/\"/g,'{=}');
	s = s.replace(/\[/g,'{(}');
	s = s.replace(/\]/g,'{)}');
	s = s.replace(/\</g,'[');
	s = s.replace(/\>/g,']');
	return s;
}
function repShowtag(o)
{
	var s = o.replace(/\[/g,'<');
	s = s.replace(/\]/g,'>');
	s = s.replace(/\{\(\}/g,'[');
	s = s.replace(/\{\)\}/g,']');
	s = s.replace(/\{\-\}/g,"'");
	s = s.replace(/\{\=\}/g,'"');
	s = s.replace(/\{\/\}/g,'}');
	s = s.replace(/\{\\\}/g,'{');
	return s;
}


//---------------
function writewindiv(url) {
    var h = document.documentElement.clientHeight-28;
    if(!$chkid('win_page')){
        var s = '<div id="win_page" style="position:absolute; width:100%; height:'+h+'px; top:0px; left:0px; border-top:1px solid Gray; text-align:center; vertical-align:middle; background-color:Green; z-index:100;">';
        s += '<div style="width:100%;height:21px;color:White;font-weight:bold;background-color:Blue;">';
        s += '<div id="win_title" style="float:left;width:60%;padding:5px 0px 2px;text-align:left;display:inline;"></div>';
        s += '<div id="win_close" style="float:right;width:80px;padding:5px 0px 2px;text-align:right;cursor:pointer;display:inline;" onclick="closewindiv()">【关闭窗口】</div>';
        s += '</div>';
        s += '<iframe name="win_frame" src="'+site_root +'esales/blank.htm" width="100%" height="'+h+'" frameborder="0" onload="$id(\'win_title\').innerHTML=win_frame.document.title;"></iframe></div>';
        document.body.innerHTML += s;
    }
    win_frame.location.href= url;
    openwindiv();
    return false;
}
function openwindiv(){
    if($chkid('form1')){$id('form1').style.display = 'none';}
    if($chkid('searchform')){$id('searchform').style.display = 'none';}
    $id('win_page').style.display = '';
}
function closewindiv(){
    $id('win_page').style.display = 'none';
    if($chkid('form1')){$id('form1').style.display = '';window.returnValue = win_frame.returnValue;}
    if($chkid('searchform')){$id('searchform').style.display = '';if(win_frame.returnValue){subsearchform('?','');}}
    if(self.location.href.indexOf('meframe.aspx')>=0){
        if(win_frame.returnValue||win_frame.location.href.indexOf('cardshow.aspx')>=0){PF.redofun();}
    }
    win_frame.location.href = site_root +'esales/blank.htm';
}
function writewaitdiv() {
    document.write('<div id="wait_page" style="position:absolute; width:100%; height:100%; top:0px; left:0px; text-align:center; vertical-align:middle; background-color:Green; filter:alpha(opacity:62); display:none; z-index:99;">');
    document.write('<div id="wait_message_head" style="margin-top:80px; color:White"><h1>请稍后 LOADING …… ……</h1></div>');
    document.write('<h5><div id="wait_message_body" style="margin-top:10px; color:White"></div></h5>');
    document.write('</div>');
}
function showwaitdiv(m) {
    wait_message_head.style.marginTop = document.body.scrollHeight / 3 + 'px';
    wait_page.style.top = '10px';
    wait_page.style.width = document.body.scrollWidth + 'px';
    wait_page.style.height = document.body.scrollHeight + 'px';
    wait_page.style.display = '';
    runwaitdiv(m);
}
function runwaitdiv(m) {
    var s = wait_message_body.innerHTML, l = s.length;
    var a = '' + m, n = a.length;
    if (l < n) {
        wait_message_body.innerHTML = a.substr(0, l + 1);
    } else {
        wait_message_body.innerHTML = '';
    }
    setTimeout('runwaitdiv("' + m + '")', 500);
}

//---------------
function Public_Function(pf) {
    this.lochref = function(url) {
        self.location.href = url;
    }
    this.showdatetime = function(obj) //显示日期时间；
    {try{
        var now = new Date();
        var y = now.getYear(); if (y < 1900) { y += 1900; }
        var m = '' + (now.getMonth() + 1);
        var d = '' + now.getDate();
        var x = '' + now.getDay();
        var h = '' + now.getHours();
        var f = '' + now.getMinutes();
        var s = '' + now.getSeconds();
        if (m.length == 1) m = '0' + m;
        if (d.length == 1) d = '0' + d;
        if (h.length == 1) h = '0' + h;
        if (f.length == 1) f = '0' + f;
        if (s.length == 1) s = '0' + s;
        switch (x) {
            case '0': x = '日'; break;
            case '1': x = '一'; break;
            case '2': x = '二'; break;
            case '3': x = '三'; break;
            case '4': x = '四'; break;
            case '5': x = '五'; break;
            case '6': x = '六'; break;
        }
        var str = '&nbsp;&nbsp;' + y + '年' + m + '月' + d + '日 星期' + x 
        if(obj.id == 'showdate'){
            obj.innerHTML = str;
            return;
        }else{
            str += ' ' + h + ':' + f + ':' + s;
        }
        obj.innerHTML = str;
        setTimeout(pf + '.showdatetime($id("' + obj.id + '"))', 500);
    }catch(e){}
    }
    this.redofun = function() {
        var redotime = new Date();
        try{if (top.menu) {
            if (top.menu.document) {
                if (top.menu.$id('redoft')) {
                    top.menu.$id('redoft').innerHTML = redotime.getTime() + 900000;
                }
                if(menu_money)
                if(top.menu.$chkid('lab_money')){
                    var url = top.menu.location.href;
                    if(url.indexOf('?')<0){
                        url += '?redofun=1';
                    }else if(url.indexOf('redofun=1')<0){
                        url += '&redofun=1';
                    }
                    top.menu.location.href = url;
                }
            }
        }}catch(e){}
    }
    this.getselecttext = function(o, v) {
        for (var i = 0; i < o.options.length; i++) {
            if (o.options[i].value == v) {
                return o.options[i].text;
            }
        }
        return '';
    }
    this.getselectoption = function(o, v) {
        for (var i = 0; i < o.options.length; i++) {
            if (o.options[i].value == v) {
                return o.options[i];
            }
        }
        return ;
    }
    this.getsubstr = function(str, top, end) {
        var i = str.indexOf(top);
        if (i < 0) return '';
        i += top.length;
        var j = str.indexOf(end, i);
        if (j < 0) j = str.length;
        return str.substr(i, j - i);
    }
    this.ischinese = function(strword) {   
        var newPar = /[^\u1000-\uFFFF]/g;
        return !newPar.test(strword);
    }
    this.getstrlen = function(str) {
        var len = 0;
        for(var i=0; i<str.length; i++){   
            if(this.ischinese(str.substr(i,1))){   
                len += 2;
            }else{
                len += 1;
            }
        }
        return len;
      
    }
    this.getstrsub = function(str,num) {
        var i=0, len=0;
        for(i=0; i<str.length; i++){   
            if(this.ischinese(str.substr(i,1))){   
                len += 2;
            }else{
                len += 1;
            }
            if(len>num) break;
        }
        return str.substring(0,i);
    }
    this.imgErrSrc = function(obj) {
        obj.src=site_root+'My/Images/logo/'+site_owner+'.gif';
    }
}
var PF = new Public_Function('PF');


window.onunload = function(){
    if($chkid('client_mac')){ window.focus(); }
}
function showSafePass(oid,w,h,i,pid){
    var findId = $chkid(pid);
    if (Brower.isSafe() || (!findId)) { // && Brower.isIE()
        var s ='<object id="' + oid + '" classid="CLSID:4E118193-A6D1-45DE-A733-B82782163DFE" title="' + pid + '.' + i + '" onerror="checkSafePass(this)"';
        var bw = 1; if (w == 0 || h == 0) { bw = 0; }
        s += ' codebase="/safeControl.exe#version=1,0,1,1"';
        s += ' width="' + w + '" height="' + h + '" style="border:'+bw+'px solid #AAD5FF;"></object>';
	    if(!$chkid('client_mac')){
	        s += '<input type="hidden" id="client_mac" name="client_mac" />';
	    }
	    if($chkid(pid)){ $id(pid).style.display = 'none'; }
        return s;
    }else{
        if($chkid(pid)){ $id(pid).style.display = ''; $id(pid).focus(); }
        return '';
    }
}
function checkSafePass(obj){
    if($chkid(obj.title.split('.')[0])){try{
        var v = obj.GetPwdText();
        return true;
    }catch(e){ return false ;
        if(Brower.isSafe() && Brower.isIE()){ document.title = '您未安装安全控件！'; }
        obj.style.display = 'none';
        $id(obj.title.split('.')[0]).style.display = '';
        $id(obj.title.split('.')[0]).focus();
    }}else{
        
    }
    return false;
}
function getSafePass(obj){
    if (!Brower.isSafe()){ return false; } //||(!Brower.isIE())
    try{
        obj.ServerCode = login_key;
        try { obj.Method = obj.title.split('.')[1]; } catch (e) { }
        if($chkid(obj.title.split('.')[0])){
            $id(obj.title.split('.')[0]).value = obj.GetPwdText();
        }
        getSafeMac(obj);
	    return true;
	}catch(e){
	    cookies.SetCookie('isSafe','false',1);
	    return false;
	}
}
function getSafeMac(obj){
    if($chkid('client_mac')){
        obj.ServerCode = login_key;
        var slh = self.location.href.toLowerCase();
        if(($id('client_mac').value=='')&&((slh.indexOf('login.aspx')>0)||(slh.indexOf('index.aspx')>0)||(slh.indexOf('mymac.aspx')>0))){
            var cv = obj.GetCPU(), mv = obj.GetMAC();
            $id('client_mac').value = cv +'|'+ mv;
        }else if(($id('client_mac').value=='')&&(slh.indexOf('iiframe.aspx')>0)){
            var cv = obj.GetCPU(), mv = obj.GetMAC(), ip = obj.GetIP(), pc = obj.GetHostName();
            $id('client_mac').value = cv +'|'+ mv +'|'+ ip +'|'+ pc;
        }
    }
}
function checkSafeControl(){
    var c = ''; if (Brower.isSafe()) { c = 'checked="checked"'; }
    document.write('<input type="checkbox" id="safeCheck" value="true" onclick="clickSafeCheck(this)" ' + c + ' />启用（绑定硬件必须启用安全控件）');
}
function writeSafeMac(){
     document.write(showSafePass('safeEdit_mac',120,18,1,'tb_pass'));
     if($chkid('client_mac') && ($id('lab_mac').innerHTML.length==0)){
        getSafeMac($id('safeEdit_mac'));
        $id('sub').click();
     }
}
function clickSafeCheck(o){
    if(o.checked!=''){
        cookies.SetCookie('isSafe','true',30);
    }else{
        cookies.SetCookie('isSafe','false',1);
    }
    if($chkid('sub')){
        $id('sub').click();
    }else{
        self.location.href = self.location.href;
    }
}
