﻿//fgh 2011-12-15 add
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
//fgh 2011-12-15 add

function TextIsNumeric(txt) {
if (txt.search("^-?\\d+$") != 0) { return false; }
else { return true; }
} 
function TextIsSignlessNumeric(txt) {
    if (txt.search("\\d+$") != 0) { return false; }
    else { return true; }
}
function forceInputTextCharSignlessNumeric(obj) {
    var vv = obj.value;
    while (TextIsSignlessNumeric(vv) == false && vv.length > 0) {
        vv = vv.substr(0, vv.length - 1);
    }
    obj.value = vv;
}
function validateEmail(elementValue) { var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(elementValue); }

//fgh 2012-01-19 add
function ischeckInfoMail(txt) {
    if (txt.toLowerCase()=="info@bestlinknetware.com") {
        return false;
    }
    else {
        return true;
    }
}

function AlertTip(msgContent, msgTitle, msgWidth, msgHeight, msgtime) {
var msgw, msgh, msgt, msgtm, bordercolor;
if (msgtime) { msgtm = msgtime * 1000; } else { msgtm = 1500; }
if (msgTitle) { msgt = msgTitle; } else { msgt = "Bestlink Netware"; }
if (msgWidth) { msgw = msgWidth; } else { msgw = 350; }
if (msgHeight) { msgh = msgHeight; } else { msgh = 80; }  titleheight = 25
bordercolor = "#336699"; titlecolor = "#99CCFF"; var sWidth, sHeight; sWidth = document.body.offsetWidth; sHeight = document.body.offsetHeight; var bgObj = document.createElement("div"); bgObj.setAttribute('id', 'alertbgDiv'); bgObj.style.position = "absolute"; bgObj.style.top = "0"; bgObj.style.background = "#E8E8E8";
bgObj.style.opacity = "0.6";
bgObj.style.left = "0"; bgObj.style.width = sWidth + "px"; bgObj.style.height = sHeight + "px"; bgObj.style.zIndex = "10000"; document.body.appendChild(bgObj); var msgObj = document.createElement("div")
 msgObj.setAttribute("id", "alertmsgDiv");
 msgObj.style.background = "white"; msgObj.style.border = "1px solid " + bordercolor;
 msgObj.style.position = "fixed";  
 msgObj.style.left = ($(window).width() / 2.0) - msgw / 2.0 + "px";
 msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
 msgObj.style.top = ($(window).height() / 2.0) - msgh + "px"; msgObj.style.width = msgw + "px"; 
    msgObj.style.height = msgh + "px"; msgObj.style.textAlign = "center"; msgObj.style.lineHeight = "25px";
    msgObj.style.zIndex = "10001"; document.body.appendChild(msgObj);
 var title = document.createElement("h4"); title.setAttribute("id", "alertmsgTitle");
 title.setAttribute("align", "left"); title.style.margin = "0"; title.style.padding = "3px";
 title.style.background = bordercolor;
 title.style.opacity = "0.75";
 title.style.border = "1px solid " + bordercolor; title.style.height = "18px"; title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
 title.style.color = "white"; title.innerHTML = msgTitle;
 document.getElementById("alertmsgDiv").appendChild(title);
 var txt = document.createElement("p"); txt.setAttribute("id", "msgTxt"); 
 txt.style.margin = "16px 0"; txt.innerHTML = msgContent; document.getElementById("alertmsgDiv").appendChild(txt); 
  window.setTimeout("closewin()", 1000); 
}
function closewin() { document.body.removeChild(document.getElementById("alertbgDiv")); document.getElementById("alertmsgDiv").removeChild(document.getElementById("alertmsgTitle")); document.body.removeChild(document.getElementById("alertmsgDiv")); }
function isCanadaZip(str) {
    var zipPat = /^([A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9])$/;
    var matchArray = str.match(zipPat);
    if (matchArray == null) {
        return false;
    }

    return true;
}

function rTrim(str) {
    var result = str;
    while (result.charAt(result.length - 1) == ' ')
        result = result.substring(0, result.length - 1);
    return result;
}

var isNN = (navigator.appName.indexOf("Netscape") != -1);
function autoTab(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
    }
    return true;
}

function containsElement(arr, ele) {
    var found = false, index = 0;
    while (!found && index < arr.length)
        if (arr[index] == ele)
            found = true;
        else
            index++;
    return found;
}

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input) index = i;
        else i++;
    return index;
}

function isNumber(inputVal) {
    var inputStr = inputVal.toString();
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9") {
            return false;
        }
    }
    return true;
}

function isDecimal(inputVal) {
    var oneDecimal = false;
    var inputStr = inputVal.toString();
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i);

        if (oneChar == "." && !oneDecimal) {
            oneDecimal = true;
            continue;
        }

        if (oneChar < "0" || oneChar > "9") {
            return false;
        }
    }
    return true;
}

function isDate(inputVal) {
    var len = inputVal.length;
    var yyyy = parseInt(inputVal.substring(0, 4), 10);
    var mm = parseInt(inputVal.substring(4, 6), 10);
    var dd = parseInt(inputVal.substring(6, 8), 10);

    if (len != 4 && len != 6 && len != 8) {
        return false;
    }

    if (len > 4) {
        if (mm < 1 || mm > 12) {
            return false;
        }
    }
    if (len > 6) {
        if (dd < 1 || dd > 31) {
            return false;
        }
        if (!checkMonthLength(mm, dd)) {
            return false;
        }
        if (mm == 2) {
            if (dd > 29) {
                return false;
            }
            if (!checkLeapMonth(mm, dd, yyyy)) {
                return false;
            }
        }
    }
    return true;
}

function checkMonthLength(mm, dd) {
    if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
        return false;
    }
    return true;
}

function checkLeapMonth(mm, dd, yyyy) {
    if (yyyy % 4 > 0 && dd > 28) {
        return false;
    }
    return true;
}


function IsAlphaNumeric(sString) {
    var inputStr = sString.toString();
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charCodeAt(i);
        if (!((oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123) || (oneChar > 64 && oneChar < 91) || oneChar == 32)) {
            return false;
        }
    }
    return true;
}

function isZIPCode(s) {
    if (!isNumber(s)) {
        return false;
    }
    if (s.length != 5 && s.length != 9) {
        return false;
    }
    return true;
}

function space_replace(sString) {
    var i;
    var str = "";
    var s = sString;
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (c == " ") {
            str += "%20";
        } else {
            str += c;
        }
    }
    sString = str;
    return sString;
}

function plus_replace(sString) {
    var i;
    var str = "";
    var s = sString;
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (c == "+") {
            str += "%2B";
        } else {
            str += c;
        }
    }
    sString = str;
    return sString;
}
function string_realLength(str) {
    r = str.match(/\n/g);
    val = str.length;
    if (r != null) {
        val = val + r.length;
    }
    return val;
}
