﻿function showAlert(msg, url) {
    alert(msg);
    if (url != '') {
        redirectURL(url);
    }
}

function redirectURL(url) {
    if (navigator.appName == 'Microsoft Internet Explorer') {
        window.location.href(url);
    } else if (navigator.appName == 'Netscape') {
    window.open(url, '_parent', 1);
    window.close();       
    }
}

function deleteRecord(url) {
    if (confirm("Want to delete clicked record?")) {
        redirectURL(url);
    }
}

function ValideEmailID(val) {
    var tempEmail = val;
    var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check = /@[\w\-]+\./;
    var checkend = /\.[a-zA-Z]{2,3}$/;
    if (val != "") {
        if (tempEmail.search(exclude) != -1 || tempEmail.search(check) == -1 || tempEmail.search(checkend) == -1) {
            return false;
        }
        else {
            return true;
        }
    }
    else {
        return false;
    }
}

function timer(obj) {
    var t = setTimeout("document.getElementById('" + obj + "').style.display = 'none'", 3000);
}

function Trim(str) {
    while (str.charAt(0) == (" ")) {
        str = str.substring(1);
    }
    while (str.charAt(str.length - 1) == " ") {
        str = str.substring(0, str.length - 1);
    }
    return str;
}

function OpenPopupCenter(pageURL, title, w, h, scroll) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + scroll + ', resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}

function IsNumeric(strString) {
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function focuscontrol(obj, text, type) {
    if (type == 'onfocus') {
        if (document.getElementById(obj).value == text) {
            document.getElementById(obj).value = "";
            document.getElementById(obj).focus();
        }
    } else if (type == 'onblur') {
        if (document.getElementById(obj).value == "") {
            document.getElementById(obj).value = text;
        }
    }
}
