﻿function ShowErrorDiv(ControlId, strMessage) {

    var Controlobj = document.getElementById(ControlId);
    var iCurLeftPos = 0;
    var iCurTopPos = 0;
    if (Controlobj.offsetParent) {
        do {
            iCurLeftPos += Controlobj.offsetLeft;
            iCurTopPos += Controlobj.offsetTop;
        } while (Controlobj = Controlobj.offsetParent);
    }
    var divError = document.getElementById("divError");

    if (divError != null) {
        divError.style.display = "block";
        if (strMessage.length > 25) {
            divError.style.left = iCurLeftPos + 30 + "px";
            divError.style.top = iCurTopPos - 45 + "px";
        }
        else {
            divError.style.left = iCurLeftPos + 100 + "px";
            divError.style.top = iCurTopPos - 45 + "px";
        }

        document.getElementById("divErrorMessage").innerHTML = strMessage;
        document.getElementById(ControlId).className = "errorInput";
        for (var i = 0; i < 100; i++) {
            window.scrollTo(iCurLeftPos - i, iCurTopPos - i);
        }

        setTimeout("document.getElementById(\"divError\").style.display=\"none\";", 15000);
    }
    else {
        WarningBoxValidation(strMessage);
    }
}
function CheckEmailIDPopUp(paraEmail) {

    var sEmail = document.getElementById(paraEmail).value;

    var atsym = sEmail.indexOf("@");
    var period = sEmail.lastIndexOf('.');
    var space = sEmail.indexOf(' ');
    var length = sEmail.length - 1;

    if ((atsym < 1) || (period <= atsym + 1) || (period == length) || (space != -1)) {
        ShowErrorDiv(paraEmail, 'Please enter a valid email address !');
        document.getElementById(paraEmail).focus();
        return false;
    }
    return true;
}
function CheckSpecialCharPopUp(vObject, vType) {
    var iChars;
    var AlertMsg;

    if (vType == "String") {

        iChars = "$?%&^~!+_}{“?><*-@()#";
        AlertMsg = "Special characters are not allowed!";
    }
    else if (vType == "Numeric") {
        iChars = "`!@#$%^&*()+=-[]\\\;,./{}|\:<>? ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'''";
        AlertMsg = "Invalid value";

    }
    else if (vType == "AlphaNumeric") {
        iChars = "`!@#$%^&*()+=[]\\\';,./{}|\":<>?";
        AlertMsg = "Special characters are not allowed!";
    }
    else if (vType == "SingleQuote") {
        iChars = "'";
        AlertMsg = "Single quote is not allowed!";
    }
    else if (vType == "Phone") {
        iChars = "~!$%^=\<>?’”;:{}";
        AlertMsg = "Special characters are not allowed!";
    }
    else if (vType == "Email") {
        iChars = "?%&^~|\!%}{“?><()";
        AlertMsg = "Special characters are not allowed!";
    }
    else if (vType == "Company") {
        iChars = "$?%^~}{“?><*#";
        AlertMsg = "Special characters are not allowed!";

    }

    for (var i = 0; i < document.getElementById(vObject).value.length; i++) {
        if (iChars.indexOf(document.getElementById(vObject).value.charAt(i)) != -1) {

            ShowErrorDiv(vObject, AlertMsg);
            document.getElementById(vObject).focus();
            return false;
        }
    }
    return true;
}
