﻿// Public.js 文件
function Request(strName) {
    var url = location.search;
    var reg = new RegExp("(^|&)" + strName + "=([^&]*)(&|$)");
    var r = url.substr(url.indexOf("?") + 1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

function GetRandNumber(Number) {
    return Math.ceil(Math.random() * Number);
}

//增加 trim(),ltrim(),rtrim() 四个函数
String.prototype.ltrim = function() { return ltrim(this); }
String.prototype.rtrim = function() { return rtrim(this); }
String.prototype.rtrimWithReturn = function() { return rtrimWithReturn(this); }
String.prototype.trim = function() { return trim(this); }

//此处为独立函数
function ltrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if ((str.charAt(i) != " ") && (str.charAt(i) != " ") && (str.charAt(i).charCodeAt() != 13) && (str.charAt(i).charCodeAt() != 10) && (str.charAt(i).charCodeAt() != 32))
            break;
    }
    str = str.substring(i, str.length);
    return str;
}

function rtrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if ((str.charAt(i) != " ") && (str.charAt(i) != " ") && (str.charAt(i).charCodeAt() != 13) && (str.charAt(i).charCodeAt() != 10) && (str.charAt(i).charCodeAt() != 32))
            break;
    }
    str = str.substring(0, i + 1);
    return str;
}

function rtrimWithReturn(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " " && str.charAt(i) != "\n")
            break;
    }
    str = str.substring(0, i + 1);
    return str;
}

function trim(str) {
    return ltrim(rtrim(str));
}

function DateToString(datetime) {
    return datetime.getYear() + "-" + (datetime.getMonth() + 1) + "-" + datetime.getDate() + " " + datetime.getHours() + ":" + datetime.getMinutes() + ":" + datetime.getSeconds();
}

function StrToInt(str) {
    str = str.trim();
    if (str == "")
        return 0;

    var i = parseInt(str, 10);
    if (isNaN(i))
        return 0;

    return i;
}

function StrToFloat(str) {
    var NewStr = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charAt(i) != "," && str.charAt(i) != " ")
            NewStr += str.charAt(i);
    }

    if (NewStr == "")
        return 0;

    var f = parseFloat(NewStr);
    if (isNaN(f))
        return 0;

    return f;
}

function Round(Num, Len) {
    var temp = 1;
    for (var i = 0; i < Len; i++)
        temp *= 10;

    return Math.round(Num * temp) / 100;
}

document.onkeydown = function()
{
    if (event.keyCode == 116) {
        event.keyCode = 0;
        event.cancelBubble = true;
        return false;
    }
}

//function document.oncontextmenu()//关右键菜单
//{
//	return false;
//}

function CheckMoneyOnPress() {
    if (window.event.keyCode < 48 || window.event.keyCode > 57) {
        return false;
    }

    return true;
}

function CheckMoneyOnPressDecimal(sender) {
    //if(sender.value.search(/[0-9]{1,}.[0-9]{1,}/) != 0)
    if (sender.value.search(/[0|1].[0-9]{1,}/) != 0) {
        sender.value = "";
        sender.focus();
    }
}

function $Id(id)
{
    return document.getElementById(id);
}

var JsLoader= new Object();
JsLoader.Load=function(js,callback)
{
    js = allcaijsfilepath + js + "?r=" + Math.random();
    var script = document.createElement("script");
    script.type = "text/javascript";

    script.onreadystatechange = function()
    {
        if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
        {
            return;
        }
        if (callback)
        {
            callback();
        }
    };
    script.src = js;
    var head = document.getElementsByTagName('head').item(0);
    head.appendChild (script);
}
function ExchangeDivMenu(ObjPrefix, Num, NumCount) {
    for (var i = 1; i <= parseInt(NumCount); i++) {
        var TmpObjself = eval(ObjPrefix + i);
        var TmpObj = eval(ObjPrefix + i + "_1");
        if (i == Num.toString()) {
            TmpObjself.className = ObjPrefix + "Index";
            TmpObj.style.display = '';
        }
        else {
            TmpObjself.className = ObjPrefix + "Other";
            TmpObj.style.display = 'none';
        }
    }
}
function ExchangeDiv(ObjPrefix, Num, NumCount) {
    for (var i = 1; i <= parseInt(NumCount); i++) {
        var TmpObjself = eval(ObjPrefix + i);
        var TmpObj = eval(ObjPrefix + i + "_1");
        if (i == Num.toString()) {
            TmpObjself.className = ObjPrefix + "Index";
            TmpObj.style.display = '';
        }
        else {
            TmpObjself.className = ObjPrefix + "Other";
            TmpObj.style.display = 'none';
        }
    }

    ScrollInit();
}
function BrowserType() {
    this.ver = navigator.appVersion;
    this.agent = navigator.userAgent;
    this.dom = document.getElementById ? 1 : 0;
    this.opera5 = this.agent.indexOf("Opera 5") > -1;
    this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom && !this.opera5) ? 1 : 0;
    this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom && !this.opera5) ? 1 : 0;
    this.ie4 = (document.all && !this.dom && !this.opera5) ? 1 : 0;
    this.ie = this.ie4 || this.ie5 || this.ie6
    this.mac = this.agent.indexOf("Mac") > -1
    this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
    this.ns4 = (document.layers && !this.dom) ? 1 : 0;
    this.bwt = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)

    return this;
}
var bwt = new BrowserType();

var speed = 30;

var loop, timer;

var ScrollContent = false;

var oScroll;
function makeObj(obj, nest) {
    nest = (!nest) ? "" : 'document.' + nest + '.';
    this.el = bwt.dom ? document.getElementById(obj) : bwt.ie4 ? document.all[obj] : bwt.ns4 ? eval(nest + 'document.' + obj) : 0;
    this.style = bwt.dom ? document.getElementById(obj).style : bwt.ie4 ? document.all[obj].style : bwt.ns4 ? eval(nest + 'document.' + obj) : 0;
    this.scrollHeight = bwt.ns4 ? this.style.document.height : this.el.offsetHeight;
    this.clipHeight = bwt.ns4 ? this.style.clip.height : this.el.offsetHeight;
    this.up = goUp; this.down = goDown;
    this.moveIt = moveIt; this.x = 0; this.y = 0;
    this.obj = obj + "Object";
    eval(this.obj + "=this")
    return this
}

function makeObj(obj, nest) {
    nest = (!nest) ? "" : 'document.' + nest + '.';
    this.el = bwt.dom ? document.getElementById(obj) : bwt.ie4 ? document.all[obj] : bwt.ns4 ? eval(nest + 'document.' + obj) : 0;
    this.style = bwt.dom ? document.getElementById(obj).style : bwt.ie4 ? document.all[obj].style : bwt.ns4 ? eval(nest + 'document.' + obj) : 0;
    this.scrollHeight = bwt.ns4 ? this.style.document.height : this.el.offsetHeight;
    this.clipHeight = bwt.ns4 ? this.style.clip.height : this.el.offsetHeight;
    this.up = goUp; this.down = goDown;
    this.moveIt = moveIt; this.x = 0; this.y = 0;
    this.obj = obj + "Object";
    eval(this.obj + "=this");
    return this
}

var px = bwt.ns4 || window.opera ? "" : "px";

function moveIt(x, y) {
    this.x = x;
    this.y = y;
    this.style.left = this.x + px;
    this.style.top = this.y + px;
}

function goDown(move) {
    if (this.y > -this.scrollHeight + oCont.clipHeight) {
        this.moveIt(0, this.y - move);
        if (loop) setTimeout(this.obj + ".down(" + move + ")", speed);
    }
}

function goUp(move) {
    if (this.y < 0) {
        this.moveIt(0, this.y - move);
        if (loop) setTimeout(this.obj + ".up(" + move + ")", speed);
    }
}

function ScrollMove(speed) {
    if (!oScroll) {
        oCont = new makeObj('divScrollContent');
        oScroll = new makeObj('divScrollContentSon', 'divScrollContent');
        oScroll.moveIt(0, 0);
        ScrollContent = true;
    }

    if (ScrollContent) {
        loop = true;
        if (speed > 0) {
            oScroll.down(speed);
        }
        else {
            oScroll.up(speed);
        }
    }
}

function noScroll() {
    loop = false
    if (timer) {
        clearTimeout(timer);
    }
}

function ScrollInit() {
    oCont = new makeObj('divScrollContent');
    oScroll = new makeObj('divScrollContentSon', 'divScrollContent');
    oScroll.moveIt(0, 0);
    ScrollContent = true;
}
function ShowFlash(Obj, Url, Width, Height) {
    Obj.document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + Width + '" height="' + Height + '">');
    Obj.document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="' + Url + '"> <param name="quality" value="high">');
    Obj.document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
    Obj.document.write('<embed src="' + Url + '" wmode="opaque" />');
    Obj.document.write('</object>');
}
//浏览器检测
function checkExplorerAndTip() {
    var browser = navigator.appName
    if (browser != 'Microsoft Internet Explorer') {
        alert('尊敬的用户您好，由于您当前使用浏览器不支持网银操作，请使用以IE为核心的浏览器,双核浏览器请切换到IE内核');
    }

}
checkExplorerAndTip();
