﻿//操作提示
function GP_popupConfirmMsg(msg) { //v1.0
    document.MM_returnValue = confirm(msg);
}

function GP_popupConfirmMsgSel(msg, sel) { //v1.0
    if (!confirm(msg)) {
        return false;
    }
    else {
        SelAction(sel);
    }
}

function ConfirmMsg(msg) { //v1.0
    return confirm(msg);
}

function callbox(msg, type, url) {
    alert(msg);
    if (type != null) {
        if (type == 0) {
            history.back();
        }
        else if (type == 1) {
            location.href = url;
        }
    }
}

function submitform(action, method, target, type) {

    if (action != null) {
        $('form:first').attr('action', action);
    }

    if (method != null) {
        $('form:first').attr('method', method);
    }
    else {
        $('form:first').attr('method', 'post');
    }
    if (target != null) {
        $('form:first').attr('target', target);
    }
    else {
        $('form:first').attr('target', '_self');
    }
    if (type != null) {
        if (type == 'file') {
            $('form:first').attr('enctype', 'multipart/form-data');
            $('form:first').attr('encoding', 'multipart/form-data');
        }
    }

    $('form:first').submit();
}

function Xion() {
    this.querystring = QueryString;
    this.querystringall = QueryStringAll;
    this.querystringelse = QueryStringElse;
    this.pagename = PageName;
    this.geturl = GetUrl;
    this.geturlelse = GetUrlElse;
    this.geturlelsewithnew = GetUrlElseWithNew;
    this.Xvali = Xvali;
    this.copy = Copy;
}

function Copy(msg) {
    window.clipboardData.setData('text', msg);
}

function QueryString(fieldName) {
    var urlString = document.location.search;
    if (urlString != null) {
        var typeQu = fieldName + "=";
        var urlEnd = urlString.indexOf(typeQu);
        if (urlEnd != -1) {
            var paramsUrl = urlString.substring(urlEnd + typeQu.length);
            var isEnd = paramsUrl.indexOf('&');
            if (isEnd != -1) {
                return paramsUrl.substring(0, isEnd);
            }
            else {
                return paramsUrl;
            }
        }
        else
            return null;
    }
    else
        return null;
}

function QueryStringAll() {
    var url = document.location.search;
    if (url.indexOf("?") != -1) {
        strs = url.split("?");
        return strs[1];
    }
    return null;
}

function QueryStringElse(thiselse) {
    var newstr = '';
    if (QueryStringAll() != null) {
        strs = QueryStringAll().split('&');
        for (var i = 0; i < strs.length; i++) {
            if (strs[i].indexOf(thiselse + '=') == -1) {
                if (newstr != '') { newstr += '&'; }
                newstr += strs[i];
            }
        }
    }
    if (newstr != '') return newstr;
    return null;
}

function GetUrl() {
    var url = document.location.search;
    return PageName() + url;
}

function GetUrlElse(thiselse) {
    //var url = GetUrl();
    if (QueryStringElse(thiselse) != null) {
        return PageName() + '?' + QueryStringElse(thiselse);
    }
    return PageName();
}

function GetUrlElseWithNew(thiselse,thisnew) {
    var url = GetUrlElse(thiselse);
    if (url.indexOf('?') != -1) {
        return url + '&' + thisnew;
    }
    return url + '?' + thisnew;
}

function PageName() {
    var sSeparator = "/";

    if (location.protocol.indexOf("file ") > -1) {
        sSeparator = "\\";
    }
    var url = document.URL;
    var ar = url.split(sSeparator);
    var FileName = ar[ar.length - 1];
    var PageName = FileName.replace(/^(.*)\..*/, "$1");
    FileName = FileName.replace(/\?.*$/, " ");

    FileName = FileName.replace(" ", "");
    return FileName;
    //return   [PageName,FileName];
}

function htmlReplace(msg) {
    return msg.replace(/\<br\>/g, "\n").replace(/\&nbsp\;/g, " ").replace(/\<BR\>/g, "\n").replace(/\<BR \/\>/g, "\n").replace(/\<br \/\>/g, "\n");
}

function FormatDate(date) {
    date = date.substring(0, date.indexOf("."));
    date = date.substring(0, date.lastIndexOf(":"));
    date = date.replace(/-/g, ".");
    date = date.replace("T", " ");
    return date;
}


String.prototype.Trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
String.prototype.LTrim = function () { return this.replace(/(^\s*)/g, ""); }
String.prototype.RTrim = function () { return this.replace(/(\s*$)/g, ""); } 

