// Error indicator
var has_error;
var error_count;
var errormsg;

var ERROR_BACKGROUND_COLOR = "#E5ABAB";
var DEFAULT_BACKGROUND_COLOR = "#FFFFFF";

var FORM_DROPDOWN = "DROPDOWN";
var FORM_PASSWORD = "PASSWORD";
var FORM_PASSWORD_MATCH = "PASSWORD_MATCH";
var FORM_DATETIME = "DATETIME";
var FORM_DATE = "DATE";
var FORM_EMAIL = "EMAIL";
var FORM_LIST = "LIST";
var FORM_TIME = "TIME";
var FORM_INTEGER = "INTEGER";
var FORM_CHECKBOX = "CHECKBOX";
var FORM_CHECKBOXES = "CHECKBOXES";
var FORM_CURRENCY = "CURRENCY";
//for a group of checkboxes, at least one must be checked, define on the first checkbox is enough
var FORM_TEXT = "TEXT";
var FORM_INTEGER_COMMA = "INTEGER_COMMA";
var FORM_USER_UNIQUE = "USER_UNIQUE";

// whitespace characters
var whitespace = " \t\n\r";


// charInString (CHARACTER c, STRING s)
//
// Returns true if single character c (actually a string)
// is contained within string s.

function setErrorBackgroundColor(jvarColor)
    {
    ERROR_BACKGROUND_COLOR = jvarColor;
    }

function charInString(c, s)
    {
    for (i = 0; i < s.length; i++)
        {
        if (s.charAt(i) == c) return true;
        }
    return false
    }

function reset_error(HeaderMsg)
    {
    has_error = false;
    error_count = 0;
    errormsg = HeaderMsg + '\n_____________________________\n\n';
    }


// Check whether string s is empty.

function isEmpty(s)
    {
    return((s == null) || (s.length == 0))
    }


// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace(s)
    {
    var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
        {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
        }

    // All characters are whitespace.
    return true;
    }


// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripInitialWhitespace(s)
    {
    var i = 0;
    while ((i < s.length) && charInString(s.charAt(i), whitespace))
        i++;
    return s.substring(i, s.length);
    }

function Trim(sInString)
    {
    sInString = sInString.replace(/^\s+/g, "");
    return sInString.replace(/\s+$/g, "");
    }


//-----------------------------------DATE VALIDATION---------------------------

// Declaring valid date character, minimum year and maximum year
var dtCh = "-";
var minYear = 2000;
var maxYear = 2100;
var tmCh = ":"


function isInteger(s)
    {
    var i;
    for (i = 0; i < s.length; i++)
        {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
        }
    // All characters are numbers.
    return true;
    }
function isIntegerComma(s)
    {
    var tempString = stripCharsInBag(s, ",");
    var flag = false;

    //if(tempString.length > 0)
    flag = isInteger(tempString);

    return flag;
    }

function isNumber(s, minval, maxval)
    {
    var i;
    for (i = 0; i < s.length; i++)
        {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
        }
    if (s < minval | s > maxval)
        return false;

    // All characters are numbers.
    return true;
    }

function validateNum_Key(s, minval, maxval)
    {
    if (isNumber(s.value, minval, maxval) == false)
        {
        //alert("Please Enter valid range from  "+minval+" to "+maxval);
        //s.focus();
        s.value = maxval;

        }
    }

function validateNum(s, minval, maxval)
    {

    if (isNumber(s.value) == false)
        {

        s.focus();
        s.value = maxval;
        }
    }


function validateNum_Blur(s)
    {

    if (isNumber(s.value) == false)
        {
        s.value = 0;
        }
    }


function validateInt_Comma(s)
    {
    if (isIntegerComma(s.value) == false)
        {
        s.value = "";
        }
    }


function stripCharsInBag(s, bag)
    {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
        {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
        }
    return returnString;
    }

function daysInFebruary(year)
    {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return(((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }
function DaysArray(n)
    {
    for (var i = 1; i <= n; i++)
        {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11)
            {
            this[i] = 30
            }
        if (i == 2)
            {
            this[i] = 29
            }
        }
    return this
    }

//
// only takes dd/mm/yyyy or yyyy/mm/dd
//
function isDate(dtStr, format, seperator, s)
    {
    var daysInMonth = DaysArray(12)

    if (format == "dd-mm-yyyy")
        {
        var pos1 = dtStr.indexOf(seperator)
        var pos2 = dtStr.indexOf(seperator, pos1 + 1)

        var strDay = dtStr.substring(0, pos1)
        var strMonth = dtStr.substring(pos1 + 1, pos2)
        var strYear = dtStr.substring(pos2 + 1)
        }
    else
        {
        var pos1 = dtStr.indexOf(seperator)
        var pos2 = dtStr.indexOf(seperator, pos1 + 1)

        var strYear = dtStr.substring(0, pos1)
        var strMonth = dtStr.substring(pos1 + 1, pos2)
        var strDay = dtStr.substring(pos2 + 1)
        }

    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1)
        strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1)
        strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++)
        {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
        }
    year = parseInt(strYr)
    month = parseInt(strMonth)
    day = parseInt(strDay)

    if (pos1 == -1 || pos2 == -1)
        {
        if (error_count <= 10)
            errormsg += s + '- The date format should be : ' + format + '\n';
        has_error = true;
        error_count++;
        return false
        }
    if (month < 1 || month > 12)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid month\n';
        has_error = true;
        error_count++;
        return false
        }
    if (day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid day\n';
        has_error = true;
        return false
        }

    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid 4 digit year between ' + minYear + ' and ' + maxYear + '\n';
        has_error = true;
        error_count++;
        return false
        }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, "-")) == false)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid date\n';
        has_error = true;
        error_count++;
        return false
        }
    return true
    }

function isTime(dtStr, s)
    {
    var strHour = dtStr.substring(0, 2)
    var strMinute = dtStr.substring(3, 5)

    hour = parseInt(strHour)
    minute = parseInt(strMinute)

    if (dtStr.charAt(2) != ":")
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a time (hh:mm) \n';
        has_error = true;
        error_count++;
        return false
        }

    if (hour < 0 || hour > 23)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid hour\n';
        has_error = true;
        error_count++;
        return false
        }

    if (minute < 0 || minute > 59)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid minute\n';
        has_error = true;
        error_count++;
        return false
        }

    return true
    }

function isDateTime(dtStr, s)
    {
    var daysInMonth = DaysArray(12)

    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var pos3 = dtStr.indexOf(" ", pos2 + 1)
    var pos4 = dtStr.indexOf(tmCh, pos3 + 1)

    var strYear = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strDay = dtStr.substring(pos2 + 1, pos3)

    var strHour = dtStr.substring(pos3 + 1, pos4)
    var strMinute = dtStr.substring(pos4 + 1)

    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1)
        strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++)
        {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
        }
    year = parseInt(strYr)
    month = parseInt(strMonth)
    day = parseInt(strDay)
    hour = parseInt(strHour)
    minute = parseInt(strMinute)

    if (pos1 == -1 || pos2 == -1)
        {
        if (error_count <= 10)
            errormsg += s + '- The date format should be : yyyy-mm-dd hh:mm\n';
        has_error = true;
        error_count++;
        return false
        }
    if (month < 1 || month > 12)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid month\n';
        has_error = true;
        error_count++;
        return false
        }
    if (day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid day\n';
        has_error = true;
        error_count++;
        return false
        }
    if (hour < 0 || hour > 23)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid hour\n';
        has_error = true;
        error_count++;
        return false
        }
    if (minute < 0 || minute > 59)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid minute\n';
        has_error = true;
        error_count++;
        return false
        }

    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid 4 digit year between ' + minYear + ' and ' + maxYear + '\n';
        has_error = true;
        error_count++;
        return false
        }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, "-: ")) == false)
        {
        if (error_count <= 10)
            errormsg += s + ' - Please enter a valid date\n';
        has_error = true;
        error_count++;
        return false
        }
    return true
    }


function emailCheck(emailStr, s)
    {
    /* The following pattern is used to check if the entered e-mail address
 fits the user@domain format.  It also is used to separate the username
 from the domain. */
    var emailPat = /^(.+)@(.+)$/
    /* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ]    */
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed. */
    var validChars = "\[^\\s" + specialChars + "\]"
    /* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
    var quotedUser = "(\"[^\"]*\")"
    /* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* The following string represents an atom (basically a series of
  non-special characters.) */
    var atom = validChars + '+'
    /* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
    var word = "(" + atom + "|" + quotedUser + ")"
    // The following pattern describes the structure of the user
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
    /* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$")


    /* Finally, let's start trying to figure out if the supplied address is
   valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
    var matchArray = emailStr.match(emailPat)
    if (matchArray == null)
        {
        /* Too many/few @'s or something; basically, this address doesn't
           even fit the general mould of a valid e-mail address. */
        if (error_count <= 10)
            errormsg += s + " - Email address seems incorrect (check @ and .'s)\n";
        has_error = true;
        error_count++;
        return false
        }
    var user = matchArray[1]
    var domain = matchArray[2]

    // See if "user" is valid
    if (user.match(userPat) == null)
        {
        // user is not valid
        if (error_count <= 10)
            errormsg += s + " - The username doesn't seem to be valid.\n";
        has_error = true;
        error_count++;
        return false
        }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
    var IPArray = domain.match(ipDomainPat)
    if (IPArray != null)
        {
        // this is an IP address
        for (var i = 1; i <= 4; i++)
            {
            if (IPArray[i] > 255)
                {
                if (error_count <= 10)
                    errormsg += s + " - Destination IP address is invalid!\n";
                has_error = true;
                error_count++;
                return false
                }
            }
        return true
        }

    // Domain is symbolic name
    var domainArray = domain.match(domainPat)
    if (domainArray == null)
        {
        if (error_count <= 10)
            errormsg += s + " - The domain name doesn't seem to be valid.\n";
        has_error = true;
        error_count++;
        return false
        }

    /* domain name seems valid, but now make sure that it ends in a
three-letter word (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

    /* Now we need to break up the domain to get a count of how many atoms
 it consists of. */

    var atomPat = new RegExp(atom, "g")
    var domArr = domain.match(atomPat)
    var len = domArr.length
/*
    if (domArr[domArr.length - 1].length < 2 || domArr[domArr.length - 1].length > 3)
        {
        // the address must end in a two letter or three letter word.
        if (error_count <= 10)
            errormsg += s + ' - The address must end in a three-letter domain, or two letter country.\n';
        has_error = true;
        error_count++;
        return false
        }
*/
    // Make sure there's a host name preceding the domain.
    if (len < 2)
        {
        if (error_count <= 10)
            errormsg += s + ' - This address is missing a hostname!\n';
        has_error = true;
        error_count++;
        return false
        }

    // If we've gotten this far, everything's valid!
    return true;
    }

var _PrimiaryPassword = "";
function PasswordCheck(szPassword, s)
    {
    _PrimiaryPassword = szPassword;
    if (szPassword.length < 6)
        {
        if (error_count <= 10)
            errormsg += s + '\n';
        has_error = true;
        error_count++;
        return false;
        }
    else
        return true;
    }

function PasswordMatchCheck(szPassword, s)
    {
    if (_PrimiaryPassword != szPassword)
        {
        if (error_count <= 10)
            errormsg += s + '\n';
        has_error = true;
        error_count++;
        return false;
        }
    else
        return true;
    }


function UserNameCheck(szUserID, s)
    {
    var userPat = new RegExp("\\W")
        
    if (szUserID.length < 6 || szUserID.match(userPat)!=null)
        {
        if (error_count <= 10)
            errormsg += s + '\n';
        has_error = true;
        error_count++;
        return false;
        }
    else
        {
        try
            {
            if (jsonrpc.JSONRPC_UserBean.isUserIDUnique(szUserID))
                return true;
            else
                {
                if (error_count <= 10)
                    errormsg += s + '\n';
                has_error = true;
                error_count++;
                return false;
                }
            }
        catch (e)
                {
                if (error_count <= 10)
                    errormsg += s + '\n';
                has_error = true;
                error_count++;
                return false;
                }

        }
    }

// ---------------------------------------------VALIDATE FIELD--------------------------------------

function validate_field(theField, Type, sErrorMessage)
    {
    var old_error_count = error_count;

    if (Type == FORM_PASSWORD)
        {
        theField.value = Trim(theField.value);
        PasswordCheck(theField.value, sErrorMessage)
        }
    else if (Type == FORM_PASSWORD_MATCH)
        {
        theField.value = Trim(theField.value);
        PasswordMatchCheck(theField.value, sErrorMessage)
        }
    else if (Type == FORM_USER_UNIQUE)
        {
        theField.value = Trim(theField.value);
        UserNameCheck(theField.value, sErrorMessage)
        }
    else if (Type == FORM_DATETIME)
        {
        theField.value = Trim(theField.value);
        isDateTime(theField.value, sErrorMessage)
        }
    else if (Type == FORM_DATE)
        {
        theField.value = Trim(theField.value);
        isDate(theField.value, "dd-mm-yyyy", "-", sErrorMessage)
        }
    else if (Type == FORM_EMAIL)
        {
        theField.value = Trim(theField.value);
        emailCheck(theField.value, sErrorMessage)
        }
    else if (Type == FORM_DROPDOWN)
        {
        if (theField.selectedIndex == 0)
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + '\n';
            has_error = true;
            error_count++;
            }
        }
    else if (Type == FORM_LIST)
        {
        var foundlist = false;
        for (i = 0; i < theField.length; i++)
            {
            if (theField.options[i].selected == true)
                {
                foundlist = true;
                break;
                }
            }
        if (foundlist == false)
            {

            /*if (error_count <= 10){
                   alert(sErrorMessage);
                   errormsg+= sErrorMessage + '\n';
               }*/
            has_error = true;
            error_count++;
            }
        }
    else if (Type == FORM_TIME)
        {
        theField.value = Trim(theField.value);
        isTime(theField.value, sErrorMessage)
        }
    else if (Type == FORM_INTEGER)
        {
        if (isInteger(theField.value) == false)
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + ' * Invalid input\n';

            has_error = true;
            error_count++;
            }
        }
    else if (Type == FORM_INTEGER_COMMA)
        {
        if (isIntegerComma(theField.value) == false)
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + ' * Invalid input\n';

            has_error = true;
            error_count++;
            }
        }
    else if (Type == FORM_CURRENCY)
        {
        if (isCurrency(theField.value) == false)
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + ' * Invalid input\n';
            has_error = true;
            error_count++;
            }
        }
    else if (Type == FORM_CHECKBOX)
        {
        if (theField.checked == false)
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + '\n';
            has_error = true;
            error_count++;
            }
        }

    else if (Type == FORM_CHECKBOXES)
        {
        var foundlist = false;
        var parentForm = "";
        var objForm = null;
        var parent = "";
        var fieldName = theField.getAttribute("name");
        var i = 0;
        // to prevent endless loop.

        while (parentForm != "FORM")
            {
            parentForm = eval("theField" + parent + ".nodeName");
            objForm = eval("theField" + parent);
            parent += ".parentNode";

            i++;
            if (i > 100)
                {
                objForm = null;
                break;
                }
            }

        if (objForm != null)
            {
            for (var i = 0; i < objForm.elements.length; i++)
                {
                if (objForm.elements[i].getAttribute("name") == fieldName)
                    {
                    if (objForm.elements[i].checked == true)
                        {
                        foundlist = true;
                        }
                    objForm.elements[i].style.backgroundColor = DEFAULT_BACKGROUND_COLOR;
                    }
                }
            }

        if (foundlist == false)
            {
            for (var i = 0; i < objForm.elements.length; i++)
                {
                if (objForm.elements[i].getAttribute("name") == fieldName)
                    {
                    objForm.elements[i].style.backgroundColor = ERROR_BACKGROUND_COLOR;
                    }
                }

            if (error_count <= 10)
                {
                errormsg += sErrorMessage + '\n';
                }
            has_error = true;
            error_count++;
            }
        }
    else
        {
        if (isWhitespace(theField.value))
            {
            if (error_count <= 10)
                errormsg += sErrorMessage + '\n';
            has_error = true;
            error_count++;
            //theField.focus();
            }        
        }
    if (error_count > old_error_count)
        return(false);
    else
        return(true);
    }

function textCounter(field, length)
    {
    if (length == 0)
        return;

    if (field.value.length > length)
        {
        field.value = field.value.substring(0, length);
        }
    field.document.getElementsByName(field.name + '_Len')[0].value = length - field.value.length;
    }

function setCounter(FieldName, length)
    {
    textCounter(document.getElementsByName(FieldName)[0], length);
    }


function ValidateAllFields(HeaderMgs)
    {
    reset_error(HeaderMgs);

    for (i = 0; i < document.forms.length; ++i)
        {
        for (j = 0; j < document.forms[i].elements.length; ++j)
            {
            var MandatoryValue;

            if (document.forms[i].elements[j].getAttribute("Mandatory") != null)
                MandatoryValue = document.forms[i].elements[j].getAttribute("Mandatory");
            else
                MandatoryValue = document.forms[i].elements[j].getAttribute("mandatory");

            if (MandatoryValue != null)
                {
                if (MandatoryValue.length > 0)
                    {
                    document.forms[i].elements[j].style.backgroundColor = "#FFFFFF";

                    var ErrorNameValue;

                    if (document.forms[i].elements[j].getAttribute("ErrorName") != null)
                        ErrorNameValue = document.forms[i].elements[j].getAttribute("ErrorName");
                    else
                        ErrorNameValue = document.forms[i].elements[j].getAttribute("errorname");

                    if (validate_field(document.forms[i].elements[j], MandatoryValue, ErrorNameValue) == false)
                        {
                        document.forms[i].elements[j].style.backgroundColor = ERROR_BACKGROUND_COLOR;
                        }
                    }
                }
            }
        }


    if (!has_error)
        {
        return(true);
        }
    else
        {
        alert(errormsg);
        return(false);
        }
    }


//Added for removal of Special Characters on KeyPress
function validateSpChar_Key(val)
    {

    var letters = /[$\\@\\\#%\^\&\*\(\)\[\]\+\{\}\`\~\=\|]/;
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    if (lchar.search(letters) != -1)
        {
        var tst = val.value.substring(0, (strLength) - 1);
        val.value = tst;
        }
    }

function validateSpChar_NoQuotes(val)
    {
    var letters = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|""]/;
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    if (lchar.search(letters) != -1)
        {
        var tst = val.value.substring(0, (strLength) - 1);
        val.value = tst;
        }

    }
// function to check for URL specialcharacters
function validateSpChar_URL(val)
    {
    var letters = /[$\\\#\^\*\(\)\[\]\{\}\`\~\|""]/;
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    if (lchar.search(letters) != -1)
        {
        var tst = val.value.substring(0, (strLength) - 1);
        val.value = tst;
        }

    }
//Added for validating the maxmimum length of  field
function limitlength(obj, length)
    {
    var maxlength = length
    if (obj.value.length > maxlength)
        obj.value = obj.value.substring(0, maxlength)
    }
function isCurrency(str)
    {
    numdecs = 0;
    for (i = 0; i < str.length; i++)
        {
        mychar = str.charAt(i);
        if ((mychar >= "0" && mychar <= "9") || mychar == ".")
            {
            if (mychar == ".")
                numdecs++;
            }
        else
            return false;
        }
    if (numdecs > 1)
        return false;
    return true;
    }


//Added for  validation of Special Characters
function verifySpChar_Part(n)
    {
    var letters = "/[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/";
    var temp ;
    var x = n.length;
    for (var i = 0; i < x; i++)
        {
        temp = n.substring(i, i + 1);
        if (letters.indexOf(temp) != -1)
            {
            alert("Special Characters Not Allowed");
            return false;

            }
        }

    return true;
    }
function ValidateFormFields(HeaderMgs,formObject)
    {
    reset_error(HeaderMgs);
        for (j = 0; j < formObject.elements.length; ++j)
            {
            var MandatoryValue;

            if (formObject.elements[j].getAttribute("Mandatory") != null)
                MandatoryValue = formObject.elements[j].getAttribute("Mandatory");
            else
                MandatoryValue = formObject.elements[j].getAttribute("mandatory");

            if (MandatoryValue != null)
                {
                if (MandatoryValue.length > 0)
                    {
                    formObject.elements[j].style.backgroundColor = "#FFFFFF";

                    var ErrorNameValue;

                    if (formObject.elements[j].getAttribute("ErrorName") != null)
                        ErrorNameValue = formObject.elements[j].getAttribute("ErrorName");
                    else
                        ErrorNameValue = formObject.elements[j].getAttribute("errorname");

                    if (validate_field(formObject.elements[j], MandatoryValue, ErrorNameValue) == false)
                        {
                         formObject.elements[j].style.backgroundColor = ERROR_BACKGROUND_COLOR;
                        }
                    }
                }
            }
 
    if (!has_error)
        {
        return(true);
        }
    else
        {
        alert(errormsg);
        return(false);
        }
    }

function isEnglishCharacters(jvarEnTextBox) 
{
   if(!/^[A-zC,N~QA`A'E`E'I'I`I"O'O`U'U`U"1234567890 @+-=()*/<>#$%&?]*$/i.test(jvarEnTextBox.value)){
	   return false;
    }
    return true; 
}


function charStrip (StripChars)
	{
	var code;
	if (!e) 
		var e = window.event;		
	if (e.keyCode) 
		code = e.keyCode;
	else if (e.which) 
		code = e.which;
	key=code;
	
	if(StripChars=="STRING_LITE")
		ignore=(key < 16 || (key > 16 && key < 32 ) || key ==60 || key == 62);
	else if(StripChars=="STRING_TIGHT")
		ignore=(key < 16 || (key > 16 && key < 32 ) || key ==60 || key == 62 || key==124 || key==34 || key==44 || key==92 ||  key==39 ||  key==38 ||  key==35);
	else if(StripChars=="STRING_AGGRESSIVE")
		ignore=(key < 16 || (key > 16 && key < 32 ) || key ==60 || key == 62 || key==124 || key==34 || key==44 || key==92 ||  key==39 ||  key==38 ||  key==35 ||  key==59 ||  key==36 ||  key==37 ||  key==64 ||  key==40 ||  key==41 ||  key==43);
	else if(StripChars=="STRING_INTEGER")
		ignore=(key < 48 || key > 57);
	else if(StripChars=="STRING_NUMBER")
		ignore=(key < 46 || (key > 46 && key < 48) || key > 57);
	else
		ignore=false;
	
	return(!ignore);
	}


