/*
----------------------------------------------------------
Author  	    	:Khalique Manyar (m_khalique@hotmail.com)
Module          	:SCM
Description     	:Generic javascript validation file 
Date of Written 	:01/07/2003
Date of Last Modified : 26/08/2003
History :
24/12/2003 : Rajesh Purohit : GUI change for Displaying Messages
----------------------------------------------------------*/

var finMesg = "Please correct following errors...\n";
var finCount = 0;
var finGotErr = "N";
var varControl;

function notGreterThanToday(sDate) {
    var today = new Date();   // todayes date
    var toyy = today.getFullYear();   // year YYYY
    var tomm = (today.getMonth()) + 1;  // Month
    var todayday = today.getDate();

    var sysdate = sDate;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = sysdateArr[2];
    var sysdateMM = sysdateArr[1];
    var sysdateDay = sysdateArr[0];

    if (sysdateYY == toyy) {
        if (sysdateMM > tomm) {
            return false;
        }
        else if (sysdateMM == tomm) {
            if (sysdateDay > todayday) {
                return false;
            }
        }
    }
    else if (sysdateYY > toyy) {
        return false;
    }
    return true;
}

function istodaysDate(sDate) {
    var today = new Date();   // todayes date
    var toyy = today.getFullYear();   // year YYYY
    var tomm = (today.getMonth()) + 1; // Month
    var todayday = today.getDate();

    var sysdate = sDate;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = sysdateArr[2];
    var sysdateMM = sysdateArr[1];
    var sysdateDay = sysdateArr[0];

    if (sysdateYY == toyy) {
        if (sysdateMM != tomm) {
            return false;
        }
        else if (sysdateMM == tomm) {
            if (sysdateDay == todayday) {
                return true;
            }
            else {
                return false;
            }
        }
    }
    else {
        return false;
    }
}
function isEqualDate(sDate, Sdate1)// both date hould be MM/DD/yyyy Formate
{
    var sysdate = sDate;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = sysdateArr[2];
    var sysdateMM = sysdateArr[1];
    var sysdateDay = sysdateArr[0];

    var sDate1 = Sdate1;
    var sDate1Arr = new Array(3);  // making arr
    sDate1Arr = sDate1.split("/");

    var toyy = sDate1Arr[2];
    var todayday = sDate1Arr[0];
    var tomm = sDate1Arr[1];



    if (sysdateYY == toyy) {

        if (sysdateMM != tomm) {

            return false;
        }
        else if (sysdateMM == tomm) {
            if (sysdateDay == todayday) {
                return true;
            }
            else {
                return false;
            }
        }
    }
    else {
        return false;
    }
}
function notSmallerThanToday(sDate) {
    var today = new Date();  // todayes date
    var toyy = today.getFullYear();   // year YYYY
    var tomm = (today.getMonth()) + 1;  // Month
    var todayday = today.getDate();

    var sysdate = sDate;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = sysdateArr[2];
    var sysdateMM = sysdateArr[1];
    var sysdateDay = sysdateArr[0];
    if (sysdateYY == toyy) {
        if (sysdateMM < tomm) {
            return false;
        }
        else if (sysdateMM == tomm) {
            if (sysdateDay < todayday) {
                return false;
            }
        }
    }
    else if (sysdateYY < toyy) {
        return false;
    }
    return true;
}
// ***************End of function*************************
// Milindkumar Kolte
//	Fuction work for taking two date input and compairing the sDateTwo 
// DateTwo must be greater or equal to DateOne
function CompareDates(sDateOne, sDateTwo) // Date 1 And Date two Must be in dd/mm/yyyy Formate
{
    var fixArr = new Array(3);
    fixArr = sDateOne.split("/");
    var toyy = parseFloat(fixArr[2]); //Year
    var tomm = parseFloat(fixArr[1]); // Month
    var today = parseFloat(fixArr[0]); //Date

    var sysdate = sDateTwo;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = parseFloat(sysdateArr[2]);
    var sysdateMM = parseFloat(sysdateArr[1]);
    var sysdateDay = parseFloat(sysdateArr[0]);


    if (sysdateYY == toyy) {
        if (sysdateMM < tomm) {

            return false;    //if sDateTwo Month is greater than FixDate Month then return false..
        }
        else if (sysdateMM == tomm) {

            if (sysdateDay < today)  // IF Date(Moynh (day) is greater then return false
            {
                return false;
            }
        }
    }
    else if (sysdateYY < toyy) /// IF year is greater then return the false
    {
        return false;
    }
    return true;
}
//**************************** End    Of Function******************************/	
function isvalidCurrency(Currency) // function to validate currency
{
    Currency = Math.round(parseFloat(Currency) * 100);
    Currency = Currency / 100;
    if (Currency == "0") {
        return false;
    }
    Currency = Currency.toString();

    invalidchrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\{\}\/\'\:\)\(\,\=\+\-\_\~\`\!\@\#\$\%\^\&\*\;\>\<\]\[ ";

    if (IsInCharacterSet(invalidchrs, Currency)) {
        return false;
    }
    atpos = Currency.indexOf(".", 0);
    if (atpos == 0 || Currency.indexOf("..", atpos) != -1)
        return false;

    if (Currency.indexOf(".", atpos + 1) != -1)
        return false;
    dotpos = Currency.indexOf(".", atpos);
    if (dotpos != -1) {
        if (dotpos + 2 < Currency.length - 1)
            return false;
    }
    return true;
}

function checkSelectBox(boxName, valueToCheck) {
    var idx = boxName.selectedIndex;
    var val = boxName[idx].value;
    if (val == valueToCheck) return false;
    else return true;
}
function checkPassword(elements) {
    if (elements[0] == elements[1]) return true;
    else return false;
}
/******* Function to check Time ***********/
function IsValidTime(timeStr) {
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
    var matchArray = timeStr.match(timePat);

    if (matchArray == null) {
        return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second == "") {
        second = null;
    }
    if (ampm == "") {
        ampm = null;
    }

    if (hour < 0 || hour > 23) {
        return false;
    }
    if (hour <= 12 && ampm == null) {
        return false;
    }
    if (hour > 12 && ampm != null) {
        return false;
    }
    if (minute < 0 || minute > 59) {
        return false;
    }
    if (second != null && (second < 0 || second > 59)) {
        return false;
    }
    return true;
}
//  End -->
/******FUNCTION TO CHECK DATE*********/

function checkDate(datearr) //to validate the date
{
    for (a = 0; a < datearr.length; a++) {
        var myday = datearr[a][0];
        var mymonth = datearr[a][1];
        var myyear = datearr[a][2];

        var i = myday.selectedIndex;
        var intday = myday[i].value;

        var j = mymonth.selectedIndex;
        var intMonth = mymonth[j].value;

        var k = myyear.selectedIndex;
        var intyear = myyear[k].value;

        if (intyear.length == 4 && Math.abs(intyear) <= 1800) {
            return false;
        }
        if (intday != 0 || intMonth != 0 || eval(intyear) != 0) {
            if (intday > 31 || intMonth > 12 || intday < 1 || intMonth < 1 || intyear < 1) {
                alert("invalid date");
                return false;
            }
            else if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31)) {
                alert("invalid day according to month");
                return false;
            }
            else if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30)) {
                alert("invalid day according to month");
                return false;
            }
            else if (intMonth == 2) {
                if (LeapYear(intyear) == true) {
                    if (intday > 29) {
                        alert("invalid day");
                        return false;
                    }
                }
                else {
                    if (intday > 28) {
                        alert("invalid day");
                        return false;
                    }
                }
            }
        }
    }
    return true;
}

function LeapYear(intyear) // to check if it is leap year or not
{
    if (intyear % 100 == 0) {
        if (intyear % 400 == 0) { return true; }
    }
    else {
        if ((intyear % 4) == 0) { return true; }
    }
    return false;
}

function checktxtDate(myDate, pattern) //to validate the date from text field
{
    var monthArr = new Array(13);
    monthArr[0] = " ";
    monthArr[1] = "JAN";
    monthArr[2] = "FEB";
    monthArr[3] = "MAR";
    monthArr[4] = "APR";
    monthArr[5] = "MAY";
    monthArr[6] = "JUN";
    monthArr[7] = "JUL";
    monthArr[8] = "AUG";
    monthArr[9] = "SEP";
    monthArr[10] = "OCT";
    monthArr[11] = "NOV";
    monthArr[12] = "DEC";
    var validSeparators = new Array("-", " ", "/", ".");
    var patternArr = "notMatching";
    //alert();
    for (vs = 0; vs < validSeparators.length; vs++) {
        if (myDate.value.indexOf(validSeparators[vs]) != -1) {
            patternArr = myDate.value.split(validSeparators[vs]);
            break;
        }
    }
    if (patternArr == "notMatching" || patternArr.length != 3) {
        return false;
    }
    else if (pattern == "dd/mm/yy" || pattern == "dd/mm/yyyy" || pattern == "dd-mm-yyyy" || pattern == "dd-mm-yy" || pattern == "dd.mm.yy" || pattern == "dd.mm.yyyy") {
        intday = patternArr[0];
        intMonth = patternArr[1];
        intyear = patternArr[2];

        //---- added on 26-08-2003 by khalique			
        if (intyear.length == 3 || intyear.length == 1) {
            return false;
        }
        //-----

        //---- added on 15-01-2005 by Ajay			
        if (intyear.length == 4 && Math.abs(intyear) <= 1800) {
            return false;
        }
        if (intyear.length != 4 && pattern == "dd/mm/yyyy") {
            return false;
        }
        //-----			
        if (isNaN(intMonth)) {
            var isMonthFound = false;
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    isMonthFound = true;
                    break;
                }
            }
            if (!isMonthFound) {
                return false;
            }
        }
    }
    else if (pattern == "mm/dd/yy" || pattern == "mm/dd/yyyy" || pattern == "mm-dd-yy" || pattern == "mm-dd-yyyy" || pattern == "mm.dd.yy" || pattern == "mm.dd.yyyy") {
        intday = patternArr[1];
        intMonth = patternArr[0];
        intyear = patternArr[2];
        if (isNaN(intMonth)) {
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    break;
                }
            }
        }
    }
    else if (pattern == "yy/mm/dd" || pattern == "yyyy/mm/dd" || pattern == "yy-mm-dd" || pattern == "yyyy-mm-dd" || pattern == "yy.mm.dd" || pattern == "yyyy.mm.dd") {
        intday = patternArr[2];
        intMonth = patternArr[1];
        intyear = patternArr[0];
        if (isNaN(intMonth)) {
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    break;
                }
            }
        }
    }
    //--------------------------
    //---- added on 06-Mar-2004 by Zubair (approved by khalique Sir)
    //checking whether day and year part are valid integer or not
    if (isNaN(intday) || isNaN(intyear)) {
        return false;
    }
    //--------------------------

    if (eval(intday) != 0 || eval(intMonth) != 0 || eval(intyear) != 0) {
        if (intday > 31 || intMonth > 12 || intday < 1 || intMonth < 1 || intyear < 1) {
            return false;
        }
        else if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31)) {
            return false;
        }
        else if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30)) {
            return false;
        }
        else if (intMonth == 2) {
            if (LeapYear(intyear)) {
                if (intday > 29) {
                    return false;
                }
            }
            else {
                if (intday > 28) {
                    return false;
                }
            }
        }
    }
    else {
        return false;
    }
    return true;
}

function IsValidTime(timeStr) {
    // Checks if time is in HH:MM:SS format.
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

    var matchArray = timeStr.match(timePat);
    if (matchArray == null) {
        //	alert("Time is not in a valid format.");
        return false;
    }

    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second == "") { second = null; }
    if (ampm == "") { ampm = null }

    if (hour < 0 || hour > 12) {
        //	alert("Hour must be between 1 and 12.");
        return false;
    }

    if (minute < 0 || minute > 59) {
        //	alert ("Minute must be between 0 and 59.");
        return false;
    }

    if (second != null && (second < 0 || second > 59)) {
        //	alert ("Second must be between 0 and 59.");
        return false;
    }
    if (hour <= 12 && ampm == null) {
        return false;
    }
    return true;
}

/*Function To Calculate Age from Date of Birth */
function getAge(dateString, dateType) {
    /*
    function getAge
    parameters: dateString dateType
    returns: boolean

   dateString is a date passed as a string in the following
    formats:

   type 1 : 19970529
    type 2 : 970529
    type 3 : 29/05/1997
    type 4 : 29/05/97

   dateType is a numeric integer from 1 to 4, representing
    the type of dateString passed, as defined above.

   Returns string containing the age in years, months and days
    in the format yyy years mm months dd days.
    Returns empty string if dateType is not one of the expected
    values.
    */

    var now = new Date();
    var today = new Date(now.getYear(), now.getMonth(), now.getDate());

    var yearNow = now.getYear();
    var monthNow = now.getMonth();
    var dateNow = now.getDate();
    //alert(dateType);
    if (dateType == 1)
        var dob = new Date(dateString.substring(0, 4),
                            dateString.substring(4, 6) - 1,
                            dateString.substring(6, 8));
    else if (dateType == 2)
        var dob = new Date(dateString.substring(0, 2),
                            dateString.substring(2, 4) - 1,
                            dateString.substring(4, 6));
    else if (dateType == 3)
        var dob = new Date(dateString.substring(6, 10),
                            dateString.substring(3, 5) - 1,
                            dateString.substring(0, 2));
    else if (dateType == 4)
        var dob = new Date(dateString.substring(6, 8),
                            dateString.substring(3, 5) - 1,
                            dateString.substring(0, 2));
    else
        return '';

    var yearDob = dob.getYear();
    yearDob = yearDob.toString();
    if (yearDob.length == 2) {
        yearDob = "19" + yearDob;
    }
    //---- added on 15-01-2005 by Ajay			
    if (yearDob.length == 4 && Math.abs(yearDob) <= 1800) {
        return '';
    }
    //-----		

    var monthDob = dob.getMonth();
    var dateDob = dob.getDate();

    yearAge = yearNow - yearDob;
    if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
    else {
        yearAge--;
        var monthAge = 12 + monthNow - monthDob;
    }

    if (dateNow >= dateDob)
        var dateAge = dateNow - dateDob;
    else {
        monthAge--;
        var dateAge = 31 + dateNow - dateDob;

        if (monthAge < 0) {
            monthAge = 11;
            yearAge--;
        }
    }
    return yearAge + '.' + monthAge;
}

function Trim(s)//Triming of String 
{
    if (s != "") {
        // Remove leading spaces and carriage returns
        while ((s.substring(0, 1) == ' ') || (s.substring(0, 1) == '\n') || (s.substring(0, 1) == '\r')) {
            s = s.substring(1, s.length);
        }
        // Remove trailing spaces and carriage returns
        while ((s.substring(s.length - 1, s.length) == ' ') || (s.substring(s.length - 1, s.length) == '\n') || (s.substring(s.length - 1, s.length) == '\r')) {
            s = s.substring(0, s.length - 1);
        }
    }
    return s;
}
function checkFile(fileName)//Check file with specific extentions (eg. '.jpg','.gif','.bmp') 
{
    var ext = fileName;
    ext = ext.substring(ext.length - 3, ext.length);
    ext = ext.toLowerCase();
    if (ext == 'jpg' || ext == 'gif' || ext == 'bmp') {
        return true;
    }
}
function checkDateFormat(myDate, pattern) //to validate the date from text field
{
    var monthArr = new Array(13);
    monthArr[0] = " ";
    monthArr[1] = "JAN";
    monthArr[2] = "FEB";
    monthArr[3] = "MAR";
    monthArr[4] = "APR";
    monthArr[5] = "MAY";
    monthArr[6] = "JUN";
    monthArr[7] = "JUL";
    monthArr[8] = "AUG";
    monthArr[9] = "SEP";
    monthArr[10] = "OCT";
    monthArr[11] = "NOV";
    monthArr[12] = "DEC";
    var validSeparators = new Array("-", " ", "/", ".");
    var patternArr = "notMatching";
    for (vs = 0; vs < validSeparators.length; vs++) {
        if (myDate.value.indexOf(validSeparators[vs]) != -1) {
            patternArr = myDate.value.split(validSeparators[vs]);
            break;
        }
    }
    if (patternArr == "notMatching" || patternArr.length != 3) {
        return false;
    }
    else if (pattern == "dd/mm/yyyy" || pattern == "dd-mm-yyyy" || pattern == "dd.mm.yyyy") {
        intday = patternArr[0];
        intMonth = patternArr[1];
        intyear = patternArr[2];
        if (intyear.length == 3 || intyear.length == 1 || intyear.length == 2) {
            return false;
        }
        if (intyear < 1800) {
            return false;
        }

        if (isNaN(intMonth)) {
            var isMonthFound = false;
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    isMonthFound = true;
                    break;
                }
            }
            if (!isMonthFound) {
                return false;
            }
        }
    }
    else if (pattern == "mm/dd/yyyy" || pattern == "mm-dd-yyyy" || pattern == "mm.dd.yyyy") {
        intday = patternArr[1];
        intMonth = patternArr[0];
        intyear = patternArr[2];
        if (isNaN(intMonth)) {
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    break;
                }
            }
        }
    }
    else if (pattern == "yyyy/mm/dd" || pattern == "yyyy-mm-dd" || pattern == "yyyy.mm.dd") {
        intday = patternArr[2];
        intMonth = patternArr[1];
        intyear = patternArr[0];
        if (isNaN(intMonth)) {
            for (month = 1; month < monthArr.length; month++) {
                if (monthArr[month] == intMonth.toUpperCase()) {
                    intMonth = month;
                    break;
                }
            }
        }
    }
    //--------------------------
    //---- added on 06-Mar-2004 by Zubair (approved by khalique Sir)
    //checking whether day and year part are valid integer or not
    if (isNaN(intday) || isNaN(intyear)) {
        return false;
    }
    //--------------------------

    if (eval(intday) != 0 || eval(intMonth) != 0 || eval(intyear) != 0) {
        if (intday > 31 || intMonth > 12 || intday < 1 || intMonth < 1 || intyear < 1) {
            return false;
        }
        else if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31)) {
            return false;
        }
        else if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30)) {
            return false;
        }
        else if (intMonth == 2) {
            if (LeapYear(intyear)) {
                if (intday > 29) {
                    return false;
                }
            }
            else {
                if (intday > 28) {
                    return false;
                }
            }
        }
    }
    else {
        return false;
    }
    return true;
}
function ValidTime(timeStr) {
    // Checks if time is in HH:MM:SS format.
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

    var matchArray = timeStr.match(timePat);
    if (matchArray == null) {
        return false;
    }

    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second == "") { second = null; }
    if (ampm == "") { ampm = null }

    if (hour < 0 || hour > 12) {
        //	alert("Hour must be between 1 and 12.");
        return false;
    }

    if (minute < 0 || minute > 59) {
        //	alert ("Minute must be between 0 and 59.");
        return false;
    }

    if (second != null && (second < 0 || second > 59)) {
        //	alert ("Second must be between 0 and 59.");
        return false;
    }
    if (hour <= 12 && ampm == null) {
        return false;
    }
    return true;
}

function CompareUserDates(sDateOne, sDateTwo) // Date 1 And Date two Must be in dd/mm/yyyy Formate
{
    var fixArr = new Array(3);
    fixArr = sDateOne.split("/");
    var toyy = fixArr[2]; //Year
    var tomm = fixArr[1]; // Month
    var today = fixArr[0]; //Date

    var sysdate = sDateTwo;
    var sysdateArr = new Array(3);  // making arr
    sysdateArr = sysdate.split("/");
    var sysdateYY = sysdateArr[2];
    var sysdateMM = sysdateArr[1];
    var sysdateDay = sysdateArr[0];

    if (sysdateYY == toyy) {
        if (sysdateMM < tomm) {
            return false;    //if sDateTwo Month is greater than FixDate Month then return false..
        }
        else if (sysdateMM == tomm) {

            if (sysdateDay < today)  // IF Date(Moynh (day) is greater then return false
            {
                return false;
            }
        }
    }
    else if (sysdateYY < toyy) /// IF year is greater then return the false
    {
        return false;
    }
    return true;
}
//
// Added on May 8, 2008 by Gurpreet.
//Functions Added for Changes as per New CD related Modules
//
function validateMe(Arr, DialogHeight, CallingControl) {
    finMesg = "";

    var count = finCount;
    var message = finMesg;
    var gotErr = finGotErr;

    var passcount = 0;
    var PassArray = new Array(2);

    for (k = 0; k < Arr.length; k++) {
        var myElement = Arr[k][0];
        var whatToDo = Arr[k][1];
        var myMessage = Arr[k][2];
        var elementType = Arr[k][3];
        if (elementType == "CompareDates") {
            var myElement1;
            var DateOne;
            var DateTwo;
            myElement1 = myElement.split("|");
            DateOne = myElement1[0];
            DateTwo = myElement1[1];
            if ((DateOne.length) != 0 && (DateTwo.length) != 0) {
                //---- added on 15-01-2005 by Ajay	
                var sysdateArr = new Array(3);
                sysdateArr = DateOne.split("/");
                var sysdateYY = sysdateArr[2];

                if (sysdateYY.length == 4 && Math.abs(sysdateYY) <= 1800) {
                    message = message + '<li>' + "Year of the date should be greater than 1800" + "<br/>";
                    gotErr = "Y";
                }
                else {
                    sysdateArr = DateTwo.split("/");
                    var sysdateYY = sysdateArr[2];

                    if (sysdateYY.length == 4 && Math.abs(sysdateYY) <= 1800) {
                        message = message + '<li>' + "Year of the date should be greater than 1800" + "<br/>";
                        gotErr = "Y";
                    }
                    else {
                        //-----
                        if (!CompareDates(DateOne, DateTwo)) {
                            message = message + '<li>' + myMessage + "<br/>";
                            gotErr = "Y";
                        }
                    }
                }
            }
        }
        //--------------------------
        else if (elementType == "CompareValues") {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0];
            ValTwo = myElement1[1];

            if ((!isNaN(ValOne)) && (!isNaN(ValTwo))) {
                if (Math.abs(ValOne) > Math.abs(ValTwo)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "GreaterThanOREqual") //Val One should be Greater than or equal to ValTwo
        {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0];
            ValTwo = myElement1[1];
            if ((!isNaN(ValOne)) && (!isNaN(ValTwo))) {
                if (Math.abs(ValOne) < Math.abs(ValTwo)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "CompareValuesWithNotAllowEqual") //Val One should be less than ValTwo
        {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0];
            ValTwo = myElement1[1];
            if ((!isNaN(ValOne)) && (!isNaN(ValTwo))) {
                if (!(Math.abs(ValOne) < Math.abs(ValTwo))) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "GreaterThan") //Val One should be Greater than ValTwo
        {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0];
            ValTwo = myElement1[1];
            if ((!isNaN(ValOne)) && (!isNaN(ValTwo))) {
                if (!(Math.abs(ValOne) > Math.abs(ValTwo))) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "GreaterThanZero") //Value should be greater than zero
        {

            var ValOne;
            ValOne = myElement;
            if ((!isNaN(ValOne))) {
                if (!(ValOne > 0)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "GreaterEqualThanZero") //Value should be greater than or equal to zero
        {

            var ValOne;
            ValOne = myElement;
            if ((!isNaN(ValOne))) {
                if (!(ValOne >= 0)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "EqualValues") //ValOne & ValTwo should be equal
        {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0];
            ValTwo = myElement1[1];

            if ((!isNaN(ValOne)) && (!isNaN(ValTwo))) {
                if (Math.abs(ValOne) != Math.abs(ValTwo)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "PasswordConPassword") //ValOne & ValTwo should be equal
        {
            var myElement1;
            var ValOne;
            var ValTwo;
            myElement1 = myElement.split("|");
            ValOne = myElement1[0].value;
            ValTwo = myElement1[1].value;
            if (ValOne != ValTwo) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        else if (elementType == "file") {
            if (Trim(myElement.value) != "") {
                if (!checkFile(myElement.value)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "PrimaryKey") {
            var myElement1;
            myElement1 = myElement.split("|");

            for (z = 0; z < myElement1.length; z++) {
                myValue = eval(myElement1[z]).value;
                if (!IsEmpty(myValue)) {
                    var invalidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\{\}\/\'\:\)\(\,\=\+\_\~\`\!\@\#\$\%\^\&\*\;\>\<\.\]\[ ";
                    if (IsInCharacterSet(invalidChars, myValue)) {
                        gotErr = "Y";
                        break;
                    }
                }
                else {
                    gotErr = "Y";
                    break;
                }

            } //end for
            if (gotErr == "Y") {
                Arr[0][0] = eval(myElement1[0]);
                message = message + '<li>' + myMessage + "<br/>";
            }
        }
        else if (elementType == "date") {
            if (myElement.value.length != 0) {
                if (!checktxtDate(myElement, whatToDo)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        // How to use:
        // myArr[0]= new Array(document.frm.txtareaname,"maxlength(number)","Validation Text: can not be more than maxlength character","textarea");
        else if (elementType == "textarea") //Checks if maxlength of textarea 
        {
            var myLength = myElement.value.length;
            if (myLength > whatToDo) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        // How to use:
        // myArr[0]= new Array(document.frm.txtareaname,"maxlength(number)","Validation Text: can not be more than maxlength character or empty","textarea/Empty");
        else if (elementType == "textarea/Empty") //Checks if maxlength of textarea 
        {
            var myLength = myElement.value.length;
            if (IsEmpty(myElement.value)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
            else if (myLength > whatToDo) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        // end 
        else if (elementType == "date/Empty") {
            if (IsEmpty(myElement.value)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
            else if (!checktxtDate(myElement, whatToDo)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        else if (elementType == "password") {
            PassArray[passcount] = myElement.value;
            if (passcount == 1 && !checkPassword(PassArray)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
            ++passcount;
        }
        /*Added by Pallavi Deshmukh on 29 December 2006 to check if the deaulft values of the Names Text boxex has been changed*/
        else if (elementType == "Names") {
            var myValue = (myElement.value).toUpperCase();
            if (myValue == whatToDo) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        else if (elementType == "text") {
            var myValue = myElement.value;
            var myLength = myValue.length;
            if (whatToDo == "Alpha") {
                if (!IsAlphabetic(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                    break;
                }
            }
            else if (whatToDo == "Time/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsValidTime(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            //===================Added by Gurpeet on - 24 June 2010 ========================
            else if (whatToDo == "Decimal/Empty")   // validates to disallow characters as well as empty
            {									    
                if (myValue.length != 0) {
                    var invalidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\{\}\/\'\:\)\-\(\,\=\+\_\~\`\!\@\#\$\%\^\&\*\;\>\<\]\[\" ";
                    for (l = 0; l < invalidChars.length; l++) {
                        if (myValue.indexOf(invalidChars.charAt(l)) > -1) {
                            message = message + '<li>' + myMessage + "<br/>";
                            gotErr = "Y";
                            break;
                        }
                        else
                            var arrNumbers = myValue.split(".");
                        if (arrNumbers.length > 2) {
                            message = message + '<li>' + myMessage + "<br/>";
                            gotErr = "Y";
                            break;
                        }
                    }
                }
                else {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            //==================================================================================
            else if (whatToDo == "NoGreaterDate/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";

                }
                else {
                    var sysdateArr = new Array();  // making arr
                    sysdateArr = myValue.split("/");
                    if (sysdateArr.length == 3) {
                        var sysdateYY = sysdateArr[2];

                        if (sysdateYY.length == 4 && Math.abs(sysdateYY) <= 1800) {
                            message = message + '<li>' + "Year of the date should be greater than 1800" + "<br/>";
                            gotErr = "Y";
                        }
                        else {
                            if (!notGreterThanToday(myValue)) {
                                message = message + '<li>' + myMessage + "<br/>";
                                gotErr = "Y";
                            }
                        }
                    }
                }
            }
            else if (whatToDo == "NoGreaterDate") {
                var sysdateArr = new Array();

                sysdateArr = myValue.split("/");
                if (sysdateArr.length == 3) {
                    var sysdateYY = sysdateArr[2];

                    if (sysdateYY.length == 4 && Math.abs(sysdateYY) <= 1800) {
                        message = message + '<li>' + "Year of the date should be greater than 1800" + "<br/>";
                        gotErr = "Y";
                    }
                    else {
                        if (!notGreterThanToday(myValue)) {
                            message = message + '<li>' + myMessage + "<br/>";
                            gotErr = "Y";
                        }
                    }
                }

            }
            else if (whatToDo == "NoSmallerDate/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";

                }
                else {
                    if (!notSmallerThanToday(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "AlphaNumericOnly") // validates to disallow characters
            {
                if (!IsAlphaNumeric(myValue)) {
                    message = message + (++count) + ". " + myMessage + "\n";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "ContainsNumerichyphen") {
                var invalidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\{\}\/\'\:\)\(\,\\=\+\_\~\`\"\!\@\#\$\%\^\&\*\;\>\<\]\[\?";
                if (IsInCharacterSet(invalidChars, myValue)) {
                    message = message + (++count) + ". " + myMessage + "\n";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "AlphaNumericOnly/Empty") // validates to disallow characters
            {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphaNumeric(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Alpha/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphabetic(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                        break;
                    }
                }
            }
            else if (whatToDo == "AlphaOnly/Empty/NoSpace") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphabetic(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "AlphaOnly/Empty/SingleSpace") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphabetic(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                    if (myValue.indexOf('  ') > -1) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "AlphaOnly/SingleSpace") {
                if (!IsAlphabetic(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                //
                //|| myValue.charAt(myValue.length -1) == ' ')	 Commented on 13/05/2008 By Deepti to validate single spaces in textboxes.						
                //
                if (myValue.indexOf('  ') > -1 || myValue.charAt(0) == ' ') {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            //Added by Zarin for allowing speacail Characters on 31/05/2010 
            else if (whatToDo == "AlphaNumericAllowSpecial/Empty") // validates to disallow characters
            {

                if (myValue == "" || myValue.charAt(0) == " ") {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    var invalidChars = "\{\}\:\)\(\,\-\=\+\_\~\"\!\@\#\$\%\^\&\*\;\>\<\]\[\?";

                    for (l = 0; l < invalidChars.length; l++) {
                        if (myValue.indexOf(invalidChars.charAt(l)) > -1) {
                            message = message + '<li>' + myMessage + "<br/>";
                            gotErr = "Y";
                            break;
                        }
                    }
                }

            }
            else if (whatToDo == "URL") {
                if (myLength != 0) {
                    var substr = myValue.substring(0, 4);
                    var myPos = myValue.indexOf("..");
                    var myLastPos = myValue.lastIndexOf(".");
                    if (substr != "www." || myPos > 1 || myLastPos >= myLength - 1) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Empty") // validates to disallow empty input
            {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "NumericOnlyRoleMembers") // Added by Gurpreet to accept "", -, NA and Numbers
            {
                if (myValue != "NA" && myValue != "na" && myValue != "-") {
                    if (!IsNumeric(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "NumericOnly") // validates to disallow characters
            {
                if (!IsNumeric(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "NumericOnly/Empty") // validates to disallow characters
            {									// as well as empty
                if (!IsEmpty(myValue)) {
                    if (!IsNumeric(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
                else {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "IntegerOnly") {
                if (!IsEmpty(myValue)) {
                    if (!IsInteger(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }

            }
            else if (whatToDo == "IntegerOnly/Empty") // validates to disallow characters
            {									// as well as empty
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsInteger(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Email") {
                if (!IsEmpty(myValue)) {
                    if (!IsValidEmail(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Currency") {
                if (!IsEmpty(myValue)) {
                    myValue = Math.round(parseFloat(myValue) * 100);
                    myValue = myValue / 100;

                    if (!isvalidCurrency(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Currency/Empty")// validates to disallow characters
            {								// as well as empty
                if (!IsEmpty(myValue)) {
                    myValue = Math.round(parseFloat(myValue) * 100);
                    myValue = myValue / 100;

                    if (!isvalidCurrency(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
                else {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "Time") {
                if (!IsEmpty(myValue)) {
                    if (!IsValidTime(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "NoSpace") // validates to disallow spaces in between
            {						  // input by the user
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (IsInCharacterSet(' ', myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "AlphaNumeric") {
                if (!IsAlphaNumeric(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "AlphaOnly/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphabetic(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "Grade/Empty") 
            {
                if (IsEmpty(myValue)) 
                {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else 
                {
                    if (IsAlphabeticGrade(myValue)) 
                    {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    } 
                }  
            }
            
            else if (whatToDo == "AlphaOnly_Native/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphabetic_Native(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
           
            else if (whatToDo == "AlphaOnly") 
            {
                if (!IsAlphabetic(myValue)) 
                {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "SpecialCharacters") {
                var invalidChars = "{\}\:\=\+\_\~\`\!\@\#\$\%\^\&\*\;\>\<";
                if (IsInCharacterSet(invalidChars, myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
            else if (whatToDo == "AlphaOnlyWithAdd/Empty") {
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    var invalidChars = "1234567890\{\}\:\=\_\~\`\!\@\#\$\%\^\&\*\;\>\<\]\[";
                    if (IsInCharacterSet(invalidChars, myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "AlphaNumeric/Empty") // validates to disallow extra characters 
            {							   // other than 0-9 and a-z	
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphaNumeric(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "ValidateAdmData/Empty") // validates to disallow extra characters 
            {							   // other than 0-9 and a-z	
                if (IsEmpty(myValue)) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    if (!IsAlphaNumeric(myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
            else if (whatToDo == "SchoolName/Empty")  // For School name which allows some special characters
            {
                if (myValue == "" || myValue.charAt(0) == " ") {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
                else {
                    var invalidChars = "\{\}\/\)\(\=\+\_\~\`\!\@\#\$\%\^\*\>\<\]\[\'\"\\";
                    if (IsInCharacterSet(invalidChars, myValue)) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                    }
                }
            }
        }
        else if (elementType == "AtleastOne") //Neeraj Add 'else' in place of 'If' 12 DEC 09
        {
            if (whatToDo == "AtLeastOneRequired") {
                var elements = myElement;
                var lName = elements[0].value;
                var fName = elements[1].value;
                var mName = elements[2].value;

                if ((lName == "" || lName == "Last Name") && (fName == "" || fName == "First Name") && (mName == "" || mName == "Middle Name")) {
                    message = message + '<li>' + myMessage + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "Empty/Date/BirthDate") {
            var elements = myElement;
            //
            //The date from which the birth date should be greater than 14 years
            //
            var dChkDate = elements[0].value;
            var TxtDOB = elements[1].value;
            var Err = "N";

            if (TxtDOB == "" || TxtDOB.charAt(0) == " ") {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
                Err = "Y";
            }
            else if (!checktxtDate(elements[1], whatToDo)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
                Err = "Y";
            }
            else if (Err != "Y") {
                var oChkdate = new Array(3);  // making arr
                oChkdate = dChkDate.split("/");
                var AdmYY = eval(oChkdate[2]);
                var AdmMM = eval(oChkdate[1] - 1);
                var AdmDD = eval(oChkdate[0]);

                var odateBir = new Array(3);  // making arr
                odateBir = TxtDOB.split("/");
                var BirYY = eval(odateBir[2]);
                var BirMM = eval(odateBir[1] - 1);
                var BirDD = eval(odateBir[0]);

                var myDate = new Date();
                myDate.setFullYear(AdmYY);
                myDate.setDate(AdmDD);
                myDate.setMonth(AdmMM);
                var MyDOB = new Date();
                MyDOB.setFullYear(BirYY);
                MyDOB.setDate(BirDD);
                MyDOB.setMonth(BirMM);

                if (myDate > MyDOB) {
                    var minutes = 1000 * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var diffYears = ((myDate.getTime() - MyDOB.getTime()) / years);

                    if (diffYears <= 14.009) {
                        var odateArr = new Array(3);  // making arr
                        odateArr = dChkDate.split("/");
                        var ChkDateYY = odateArr[2];
                        var BirthYY = ChkDateYY - 14;

                        message = message + '<li>' + myMessage + '<br/>Birth Date  should be less than or equal to ' + odateArr[0] + '/' + odateArr[1] + '/' + BirthYY + '.' + "<br/>";
                        gotErr = "Y";
                    }
                }
                else {
                    message = message + '<li>' + myMessage + '<br/>Birth Date should be less than admission date.' + "<br/>";
                    gotErr = "Y";
                }
            }
        }
        else if (elementType == "Empty/date/NoGreaterDate/WithinAcademicYear") {
            var elements = myElement;
            //
            //The date from which the birth date should be greater than 14 years
            //
            var dChkDate = elements[0].value;
            var dStartDate = elements[1].value;
            var dEndate = elements[2].value;
            var Err = "N";
            var Errgreatertoday = "N";

            if (IsEmpty(dChkDate)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
                Err = "Y";
            }
            else if (!checktxtDate(elements[0], whatToDo)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
                Err = "Y";
            }
            else if (Err != "Y") {
                var sysdateArr = new Array();  // making arr

                sysdateArr = dChkDate.split("/");
                if (sysdateArr.length == 3) {
                    var sysdateYY = sysdateArr[2];

                    if (sysdateYY.length == 4 && Math.abs(sysdateYY) <= 1800) {
                        message = message + '<li>' + myMessage + "<br/>";
                        gotErr = "Y";
                        Errgreatertoday = "Y";
                    }
                    else {
                        if (!notGreterThanToday(dChkDate)) {
                            message = message + '<li>' + myMessage + "<br/>Admission Date should not be greter than todays date<br/>";
                            gotErr = "Y";
                            Errgreatertoday = "Y";
                        }
                        else {
                            if (CompareDates(dChkDate, dEndate)) {
                                if (!CompareDates(dStartDate, dChkDate)) {
                                    var StartArr = new Array(3);  // making arr
                                    StartArr = dStartDate.split("/");
                                    var StartDateYY = StartArr[2];

                                    var EndArr = new Array(3);  // making arr
                                    EndArr = dEndate.split("/");
                                    var EndDateYY = EndArr[2];

                                    message = message + '<li>' + myMessage + '<br/>Admission Date should be greater than or equal to ' + dStartDate + " for current academic year " + StartDateYY + "-" + EndDateYY + "<br/>";
                                    gotErr = "Y";
                                }
                            }
                            else {
                                message = message + '<li>' + myMessage + '<br/>Admission Date should be less than or equal to ' + dEndate + "<br/>";
                                gotErr = "Y";
                            }
                        }
                    }
                }
            }
        }
        else if (elementType == "select") //Validations if form element type is List box
        {
            if (!checkSelectBox(myElement, whatToDo)) {
                message = message + '<li>' + myMessage + "<br/>";
                gotErr = "Y";
            }
        }
        //Added by Husain
        else if (elementType == "RegularExpression/NonEmpty") {
            if (myElement.type == "text") {
                var re = new RegExp(whatToDo);
                var val = myElement.value;
                if (val.match(re) == null) {
                    gotErr = 'Y';
                    message = message + '<li>' + myMessage + "<br/>";
                }
            }
        }
        //Added by Husain
        else if (elementType == "RegularExpression/Empty") {
            if (myElement.type == "text") {
                var re = new RegExp(whatToDo);
                var val = myElement.value;
                if (val == null || val == "") {
                    return true;
                }
                else {
                    if (val.match(re) == null) {
                        gotErr = 'Y';
                        message = message + '<li>' + myMessage + "<br/>";
                    }
                }
            }
        }
    }
    if (gotErr == "Y") {
        showValidationSummary(myElement, message);
        return false;
    }
    return true;
}
function showValidationSummary(myElement, message) {
    var mesg = "";
    if (document.getElementById('popupTable')) {
        document.getElementById('popupTable').parentNode.removeChild(document.getElementById('popupTable'));
    }
    if (message.indexOf("<li>") > -1) {
        mesg = "<div style='text-align:center;'><div style='min-height:100px;text-align:center;'><ol style='text-align:left;'>" + message + "</ol></div><div style='width:100%;vertical-align:bottom;padding-left:100px;text-align:left'><input type='button' class='clAlertBut' value='OK' onclick='closeValidator();'></div></div>"
    }
    else {
        mesg = "<div style='text-align:center;'><div style='min-height:100px;text-align:center;'><ol style='text-align:left;'>" + message + "</ol></div><div style='width:100%;vertical-align:bottom;padding-left:100px;text-align:left'><input type='button' class='clAlertBut' value='OK' onclick='closeValidator();'></div></div>"
    }

    var popupTable = document.createElement("table");
    var popupTableBody = document.createElement("tbody");
    var warningIconImage = document.createElement("div");
    var closeImage = document.createElement("div");

    var popupTableRow = document.createElement("tr");
    var iconCell = document.createElement("td");
    var errorMessageCell = document.createElement("td");
    var closeCell = document.createElement("td");

    var popupTableRow2 = document.createElement("tr");
    var iconCell2 = document.createElement("td");
    var errorMessageCell2 = document.createElement("td");
    var closeCell2 = document.createElement("td");

    //
    // popupTable
    //    
    popupTable.cellPadding = 0;
    popupTable.cellSpacing = 0;
    popupTable.className = 'clPopupTable';
    //
    // popupTableRow
    //
    popupTableRow.vAlign = 'top';
    popupTableRow.style.height = "100%";
    //
    // iconCell
    //
    iconCell.className = 'clPopupIcon';
    iconCell2.className = 'clPopupIcon2';
    //
    // _warningIconImage
    //
    warningIconImage.className = 'clAlertImage';
    //
    // _errorMessageCell
    //
    errorMessageCell.className = 'clPopupMessage';
    errorMessageCell2.innerHTML = mesg;
    errorMessageCell2.className = 'clPopupMessage2';
    //
    // closeCell
    //
    closeCell.className = 'clPopupClose';
    closeCell2.className = 'clPopupClose2';
    //
    // closeImage
    //            
    closeImage.className = 'clCloseImage';
    closeImage.innerHTML = '&nbsp;';
    closeImage.onclick = closeValidator;
    //
    // Create the DOM tree
    //          
    var div = document.createElement("div");
    div.id = "popupTable";
    div.className = 'clPopupTableHolder';

    document.body.appendChild(div);
    div.appendChild(popupTable);
    popupTable.appendChild(popupTableBody);
    popupTableBody.appendChild(popupTableRow);

    popupTableRow.appendChild(iconCell);
    iconCell.appendChild(warningIconImage);
    errorMessageCell.innerHTML = "<strong>Please correct following errors...</strong>";
    popupTableRow.appendChild(errorMessageCell);
    popupTableRow.appendChild(closeCell);
    closeCell.appendChild(closeImage);

    popupTableBody.appendChild(popupTableRow2);
    iconCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(iconCell2);
    popupTableRow2.appendChild(errorMessageCell2);
    closeCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(closeCell2);

    popupTable.style.left = (getBrowserWidth() - ((document.documentElement.scrollLeft + popupTable.offsetWidth) / 2)) / 2 + 'px';
    popupTable.style.top = (getBrowserHeight() - (popupTable.offsetHeight)) / 2 + 'px';
}

function getBrowserWidth() { if (window.innerWidth) return window.innerWidth; else if (document.body.clientWidth) return document.body.clientWidth; else return -1; }
function getBrowserHeight() { return (window.innerHeight ? window.innerHeight : document.documentElement.clientHeight); }
function getBodyHeight() { if (document.body.clientHeight) return document.body.clientHeight; else return -1; }

function ShowConfirm(myElement, message) {
    varControl = myElement;

    message = "<div style='text-align:center;'><div style='min-height:100px;text-align:center;'><ol style='text-align:left;margin-left:0px;'>" + message + "</ol></div><div style='width:100%;vertical-align:bottom;padding-left:55px;text-align:left'><input type='button' class='clAlertBut' value='Yes' onclick='SetOkClick(varControl);'> &nbsp; <input type='button' class='clAlertBut' value='No' onclick='closeValidator();'></div></div>";

    if (document.getElementById('popupTable')) {
        document.getElementById('popupTable').parentNode.removeChild(document.getElementById('popupTable'));
    }

    var popupTable = document.createElement("table");
    var popupTableBody = document.createElement("tbody");
    var warningIconImage = document.createElement("div");
    var closeImage = document.createElement("div");

    var popupTableRow = document.createElement("tr");
    var iconCell = document.createElement("td");
    var errorMessageCell = document.createElement("td");
    var closeCell = document.createElement("td");

    var popupTableRow2 = document.createElement("tr");
    var iconCell2 = document.createElement("td");
    var errorMessageCell2 = document.createElement("td");
    var closeCell2 = document.createElement("td");

    //
    // popupTable
    //    
    popupTable.cellPadding = 0;
    popupTable.cellSpacing = 0;
    popupTable.className = 'clPopupTable';
    //
    // popupTableRow
    //
    popupTableRow.vAlign = 'top';
    popupTableRow.style.height = "100%";
    //
    // iconCell
    //
    iconCell.className = 'clPopupIcon';
    iconCell2.className = 'clPopupIcon2';
    //
    // _warningIconImage
    //
    warningIconImage.className = 'clAlertImage';

    //
    // _errorMessageCell
    //
    errorMessageCell.className = 'clPopupMessage';
    errorMessageCell2.innerHTML = message;
    errorMessageCell2.className = 'clPopupMessage2';
    //
    // closeCell
    //
    closeCell.className = 'clPopupClose';
    closeCell2.className = 'clPopupClose2';
    //
    // closeImage
    //            
    closeImage.className = 'clCloseImage';
    closeImage.onclick = closeValidator;
    //
    // Create the DOM tree
    //          
    var div = document.createElement("div");
    div.id = "popupTable";
    div.className = 'clPopupTableHolder';

    document.body.appendChild(div);
    div.appendChild(popupTable);
    popupTable.appendChild(popupTableBody);
    popupTableBody.appendChild(popupTableRow);

    popupTableRow.appendChild(iconCell);
    iconCell.appendChild(warningIconImage);
    errorMessageCell.innerHTML = "<strong>Confirm</strong>";
    popupTableRow.appendChild(errorMessageCell);
    popupTableRow.appendChild(closeCell);
    closeCell.appendChild(closeImage);

    popupTableBody.appendChild(popupTableRow2);
    iconCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(iconCell2);
    popupTableRow2.appendChild(errorMessageCell2);
    closeCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(closeCell2);

    popupTable.style.left = (getBrowserWidth() - ((document.documentElement.scrollLeft + popupTable.offsetWidth) / 2)) / 2 + 'px';
    popupTable.style.top = (getBrowserHeight() - (popupTable.offsetHeight)) / 2 + 'px';
}
// Function to set hidden variable Flag on Click of OK button // Added by jyotsna on 17/04/2008 
function SetOkClick(ControlName) {
    closeValidator();
    varResult = "Y";
    __doPostBack(ControlName);
}
function showValidator(myElement, message) {

    if (document.getElementById('popupTable')) {
        document.getElementById('popupTable').parentNode.removeChild(document.getElementById('popupTable'));
    }
    var popupTableBody = document.createElement("tbody");
    var popupTableRow = document.createElement("tr");
    var calloutCell = document.createElement("td");
    var calloutTable = document.createElement("table");
    var calloutTableBody = document.createElement("tbody");
    var calloutTableRow = document.createElement("tr");
    var iconCell = document.createElement("td");
    var closeCell = document.createElement("td");
    var popupTable = document.createElement("table");
    var calloutArrowCell = document.createElement("td");
    var ArrowIconImage = document.createElement("div");
    var warningIconImage = document.createElement("div");
    var closeImage = document.createElement("div");
    var errorMessageCell = document.createElement("td");
    //
    // popupTable
    //
    popupTable.id = "popupTable";
    popupTable.cellPadding = 0;
    popupTable.cellSpacing = 0;
    popupTable.border = 0;
    popupTable.width = "200px";
    popupTable.style.zIndex = '1001';
    popupTable.style.position = 'absolute';
    /////////////////////////////////////////////////////
    var nLeftPos = myElement.offsetLeft;          // initialize var to store calculations
    var eParElement = myElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null) {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }

    var nTopPos = myElement.offsetTop;
    var eParElement = myElement.offsetParent;
    while (eParElement != null) {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    /////////////////////////////////////////////////////
    popupTable.style.left = nLeftPos + myElement.offsetWidth;
    popupTable.style.top = nTopPos;
    //
    // popupTableRow
    //
    popupTableRow.vAlign = 'top';
    popupTableRow.style.height = "100%";
    //
    // calloutCell
    //
    calloutCell.width = 20;
    calloutCell.align = "right";
    calloutCell.style.height = "100%";
    calloutCell.style.verticalAlign = "top";
    //
    // calloutTable
    //
    calloutTable.cellPadding = 0;
    calloutTable.cellSpacing = 0;
    calloutTable.border = 0;
    calloutTable.style.height = "100%";
    //
    // calloutArrowCell
    //
    calloutArrowCell.align = "right";
    calloutArrowCell.vAlign = "top";
    calloutArrowCell.style.fontSize = "1px";
    calloutArrowCell.style.paddingTop = "8px";
    //
    // ArrowIconImage
    //
    ArrowIconImage.border = 0;
    ArrowIconImage.className = 'clArrowImage'; //.src = '/images/arrow.PNG';
    //
    // iconCell
    //
    iconCell.width = 20;
    iconCell.style.borderTop = "1px solid black";
    iconCell.style.borderLeft = "1px solid black";
    iconCell.style.borderBottom = "1px solid black";
    iconCell.style.padding = "5px";
    iconCell.style.backgroundColor = 'LemonChiffon';
    //
    // _warningIconImage
    //
    warningIconImage.className = 'clAlertImage';
    //
    // _errorMessageCell
    //
    errorMessageCell.style.backgroundColor = 'LemonChiffon';
    errorMessageCell.style.fontFamily = 'verdana';
    errorMessageCell.style.fontSize = '10px';
    errorMessageCell.style.padding = "5px";
    errorMessageCell.style.borderTop = "1px solid black";
    errorMessageCell.style.borderBottom = "1px solid black";
    errorMessageCell.width = '100%';
    errorMessageCell.innerHTML = message;
    //
    // closeCell
    //
    closeCell.style.borderTop = "1px solid black";
    closeCell.style.borderRight = "1px solid black";
    closeCell.style.borderBottom = "1px solid black";
    closeCell.style.backgroundColor = 'lemonchiffon';
    closeCell.style.verticalAlign = 'top';
    closeCell.style.textAlign = 'right';
    closeCell.style.padding = '2px';
    //
    // closeImage
    //            
    closeImage.className = 'clCloseImage';
    closeImage.onclick = closeValidator;
    //
    // Create the DOM tree
    //            
    myElement.parentNode.appendChild(popupTable);
    popupTable.appendChild(popupTableBody);
    popupTableBody.appendChild(popupTableRow);
    popupTableRow.appendChild(calloutCell);
    calloutCell.appendChild(calloutTable);
    calloutTable.appendChild(calloutTableBody);
    calloutTableBody.appendChild(calloutTableRow);
    calloutTableRow.appendChild(calloutArrowCell);
    calloutArrowCell.appendChild(ArrowIconImage);
    popupTableRow.appendChild(iconCell);
    iconCell.appendChild(warningIconImage);
    popupTableRow.appendChild(errorMessageCell);
    popupTableRow.appendChild(closeCell);
    closeCell.appendChild(closeImage);
}

function closeValidator() {
    document.getElementById('popupTable').parentNode.removeChild(document.getElementById('popupTable'));

}

function showAlert(message) {
    var mesg = "";
    if (document.getElementById('popupTable')) {
        document.getElementById('popupTable').parentNode.removeChild(document.getElementById('popupTable'));
    }
    if (message.indexOf("<li>") > -1) {
        mesg = "<div style='text-align:center;'><div style='min-height:100px;text-align:center;'><ol style='text-align:left;'>" + message + "</ol></div><div style='width:100%;vertical-align:bottom;padding-left:100px;text-align:left'><input type='button' class='clAlertBut' value='OK' onclick='closeValidator();'></div></div>"
    }
    else {
        mesg = "<div style='text-align:center;'><div style='min-height:100px;text-align:center;'><ol style='text-align:left;'>" + message + "</ol></div><div style='width:100%;vertical-align:bottom;padding-left:100px;text-align:left'><input type='button' class='clAlertBut' value='OK' onclick='closeValidator();'></div></div>"
    }

    var popupTable = document.createElement("table");
    var popupTableBody = document.createElement("tbody");
    var warningIconImage = document.createElement("div");
    var closeImage = document.createElement("div");

    var popupTableRow = document.createElement("tr");
    var iconCell = document.createElement("td");
    var errorMessageCell = document.createElement("td");
    var closeCell = document.createElement("td");

    var popupTableRow2 = document.createElement("tr");
    var iconCell2 = document.createElement("td");
    var errorMessageCell2 = document.createElement("td");
    var closeCell2 = document.createElement("td");

    //
    // popupTable
    //    
    popupTable.cellPadding = 0;
    popupTable.cellSpacing = 0;
    popupTable.className = 'clPopupTable';
    //
    // popupTableRow
    //
    popupTableRow.vAlign = 'top';
    popupTableRow.style.height = "100%";
    //
    // iconCell
    //
    iconCell.className = 'clPopupIcon';
    iconCell2.className = 'clPopupIcon2';
    //
    // _warningIconImage
    //
    warningIconImage.className = 'clAlertImage';
    //
    // _errorMessageCell
    //
    errorMessageCell.className = 'clPopupMessage';
    errorMessageCell2.innerHTML = mesg;
    errorMessageCell2.className = 'clPopupMessage2';
    //
    // closeCell
    //
    closeCell.className = 'clPopupClose';
    closeCell2.className = 'clPopupClose2';
    //
    // closeImage
    //                
    closeImage.className = 'clCloseImage';
    closeImage.onclick = closeValidator;
    //
    // Create the DOM tree
    //          
    var div = document.createElement("div");
    div.id = "popupTable";
    div.className = 'clPopupTableHolder';

    document.body.appendChild(div);
    div.appendChild(popupTable);
    popupTable.appendChild(popupTableBody);
    popupTableBody.appendChild(popupTableRow);

    popupTableRow.appendChild(iconCell);
    iconCell.appendChild(warningIconImage);
    errorMessageCell.innerHTML = "<strong>Alert</strong>";
    popupTableRow.appendChild(errorMessageCell);
    popupTableRow.appendChild(closeCell);
    closeCell.appendChild(closeImage);

    popupTableBody.appendChild(popupTableRow2);
    iconCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(iconCell2);
    popupTableRow2.appendChild(errorMessageCell2);
    closeCell2.innerHTML = "&nbsp;";
    popupTableRow2.appendChild(closeCell2);

    popupTable.style.left = (getBrowserWidth() - ((document.documentElement.scrollLeft + popupTable.offsetWidth) / 2)) / 2 + 'px';
    popupTable.style.top = (getBrowserHeight() - (popupTable.offsetHeight)) / 2 + 'px';
}
//----------End of Changes as per New CD--------------

/***************BEGIN: FUNCTIONS WITH REGULER EXPRESSIONS 
****************Name : Neeraj Choudhary
****************Date : 15 DEC 2009
*********************************************************/

function IsEmpty(myValue) {
    var reg = new RegExp(/\S/g);
    myValue = myValue.replace(/^\s+|\s+$/g, "");
    return !reg.test(myValue);
}
function IsAlphabetic(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/^[a-zA-Z\-\(\)\.\,\?\|\\~\\\\ ]+$/);
    return reg.test(myValue);

}

function IsAlphabeticGrade(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/[0-9\-\(\)\.\,\?\|\$\\~\\\\ ]$/);
    return reg.test(myValue);

}


function IsAlphabetic_Native(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/[^0-9\{\}\:\=\+\_\~\`\!\@\#\$\%\^\&\*\;\>\<\]\[]+/);
    return reg.test(myValue);
    
}
function IsAlphaNumeric(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/^[a-zA-Z0-9\-\(\)\.\,\?\|\\~\\\\ ]+$/);
    return reg.test(myValue);
}
function IsInteger(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/^[0-9]+$/);
    return reg.test(myValue);
}
function IsNumeric(myValue) {
    if (IsEmpty(myValue)) return true;

    var reg = new RegExp(/^[0-9.]+$/);
    return reg.test(myValue);
}
function IsInCharacterSet(charSet, myValue) {
    var bul = false;
    for (l = 0; l < charSet.length; l++) {
        if (myValue.indexOf(charSet.charAt(l)) > -1) {
            bul = true;
            break;
        }
    }
    return bul;
}
function IsValidEmail(myValue) {
    var pattern = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    var reg = new RegExp(pattern);
    return reg.test(myValue);
}


/*********************************END: FUNCTIONS WITH REGULER EXPRESSIONS ******************************/

