    /*  Validation functions starts here..... */

    //returns value of a radio button that is checked
	function RadioValue(objForm,strName)
	{
        var val;
		for(i=0; i<objForm.elements.length; i++)
		{
			var name=objForm.elements[i].name;
			var type=objForm.elements[i].type;
			if((type=="radio") && (name.indexOf(strName)!=-1))
			{
                if (objForm.elements[i].checked){
					val = objForm.elements[i].value;
				}
			}
		}
		return val;
	}

    function invalidemail(y)
    {

        var len = y.length;
        if (len < 1)
        {
            return true;
        }
        var i = 0;
        for (i=0; i<len; i++)
        {
            if (!((y.charCodeAt(i) >= 65 && y.charCodeAt(i) <= 90)
              || (y.charCodeAt(i) >= 97 && y.charCodeAt(i) <= 122)
              || (y.charCodeAt(i) >= 48 && y.charCodeAt(i) <= 57)
              || (y.charAt(i) == "@")
              || (y.charAt(i) == "_")
              || (y.charAt(i) == "-")
              || (y.charAt(i) == ".")))
            {
                return true;
            }
        }
        var at = y.indexOf("@");
        if (at < 0)
        {
            return true;
        }
        i = 0;
        var dot;
        dot = y.indexOf(".", at);
        if (!(dot > 1))
        {
            return true;
        }
        return false;
    }

    function isValidURL(strText)
    {
        var bcorrect=true;
        if(bcorrect && isNull(strText))
        {
            return true;
        }
        if(bcorrect && strText.indexOf("/")!=-1)
        {
            strText=strText.substring(0,strText.indexOf("/"));
        }

        var len = strText.length;

        //validate the characters allowed
        if(bcorrect)
        {
            var i = 0;
            for (i=0; i<len; i++)
            {
                if (!((strText.charCodeAt(i) >= 65 && strText.charCodeAt(i) <= 90)
                  || (strText.charCodeAt(i) >= 97 && strText.charCodeAt(i) <= 122)
                  || (strText.charCodeAt(i) >= 48 && strText.charCodeAt(i) <= 57)
                  || (strText.charAt(i) == "-")
                  || (strText.charAt(i) == "_")
                  || (strText.charAt(i) == ".")))
                {
                    bcorrect=false;
                }
            }
        }

        if(bcorrect && strText.indexOf("..")!=-1)
            bcorrect=false;
        if(bcorrect && strText.indexOf("-")==0)
            bcorrect=false;
        if(bcorrect && strText.indexOf("_")==0)
            bcorrect=false;
        if(bcorrect && strText.indexOf(".")==0)
            bcorrect=false;
        if(bcorrect && strText.indexOf(".")==-1)
            bcorrect=false;

        //validate last index of '.' and number of chars next to that
        if(bcorrect)
        {
            var iLastPos=strText.lastIndexOf('.');
            var iMasphar=len - iLastPos;
            if(iMasphar<3 || iMasphar>5)
                bcorrect=false;
        }

        //validate extension
        if(bcorrect)
        {
            var strExtension=strText.substring(strText.lastIndexOf('.')+1);
            if(!isAlphaNumeric(strExtension))
                bcorrect=false;
        }
        return bcorrect;
    }

    function isNotNumeric(n)
    {
        if (n == "")
        {
            return true;
        }
        var len = n.length;
        var i = 0;
        for (i=0; i<len; i++)
        {
            if (!((n.charCodeAt(i) >= 48) && (n.charCodeAt(i) <= 57)))
            {
                return true;
            }
        }
        return false;
    }

    function containsBlank(s)
    {
        var len = s.length;
        for (i=0; i<len; i++)
        {
            if (s.charAt(i) == " ")
            {
                return true;
            }
        }
        return false;
    }

    function isBlank(StrText)
    {
        if (StrText.length < 0)
        {
            return true;
        }
        for (var i=0; i<StrText.length; i++)
        {
            if (StrText.charAt(i) != " ")
            {
                return false;
            }
        }
        return true;
    }

    function getSelectedOption(OItem)
    {
        var optionValue = "";
        for (var i=0; i<OItem.length; i++)
        {
            if (OItem.options[i].selected == true)
            {
                 optionValue = OItem.options[i].value;
                 return optionValue;
            }
        }
    }

    function optionSelected(OItem)
    {
        for (var i=0; i<OItem.length; i++)
        {
            if ((OItem.options[i].selected == true) && (OItem.options[i].value != ""))
            {
                return true;
            }
        }
        return false;
    }

    function isValidDate(iYear, iMonth, iDay)
    {
        if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
        {
          return false;
        }
            var dtNewDate = new Date(iYear, (iMonth-1), iDay);
            if ((parseInt(dtNewDate.getFullYear()) == iYear)
                && (parseInt(dtNewDate.getMonth()) == (iMonth-1))
                && (parseInt(dtNewDate.getDate()) == iDay))
            {
                return true;
            }
        return false;
    }

    //Returns true if "text" is alphanumeric
    function isAlphaNumeric(text)
    {
        var str = new String(text);
        for (var i=0;i<str.length;i++)
        {
            if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
            {
                return false;
            }
         }
        return true;
    }

    // returns true if the given text is Null
    function isNull(text)
    {
        if((trim(text) == "") || (text == null))
        {
            //alert("Must not be Null Sring");
            return true;
        }
        else
        {
            return false;
        }
    }

    // returns true if length of the text is greater than given num.
    function isMaxLength(text,num)
    {
        var strlen;
        var text=new String(text);
        strlen = len(text);
        if (strlen > num)
        {
            //alert(" Must not be greater than maximum " + num + " characters ");
            return true;
        }
        else
        {
            return false;
        }
    }

    // returns true if length of the text is less than given value.
     function isMinLength(text,num)
    {
        var strlen;
        var text=new String(text);
        strlen = len(text);
        if (strlen < num)
        {
            //alert(" Must not be Less than minimum " + num + " characters ");
            return true;
        }
        else
        {
            return false;
        }
    }

    // returns true if the text is Number and false if it is not a number.
    function isNumber(text)
    {
        var ilen;
        var bflagNum=true;
        var text=new String(text);
        if (isNaN(text))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    // returns true if valid Email.
    function isEmail(emailval)
    {
        var tempStr,icount;
        var blnmail,blnperiod;
        var lastoccofperiod,maxthree;
        var ampicount=0;
        var amppos;
        var servername = 1;
        var dots;
        icount=emailval.length;
        blnperiod = 1;
        maxthree = 1;
        specialchar = 0
        lastoccofperiod = 0;
        if (icount==0)
        {
            return true;
        }
        for(i=0;i<icount;i++)
        {
            tempStr = emailval.charAt(i);
            if ((tempStr >='a')&&(tempStr <='z'))
            {
                specialchar=specialchar+1;
            }
            else
            {
                if ((tempStr >='A')&&(tempStr <='Z'))
                {
                    specialchar=specialchar+1;
                }
                else
                {
                    if ((tempStr >= 0)&&(tempStr<=9))
                    {
                        specialchar=specialchar+1;
                    }
                    else
                    {
                        if ((tempStr=='_')||(tempStr=='-')||(tempStr=='.')||(tempStr=='@'))
                        {
                            specialchar=specialchar+1;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
        dots = emailval.indexOf('..');
        if (dots != -1)
        {
            return false;
        }
        espace = emailval.indexOf(' ');
        if (espace != -1)
        {
            return false;
        }
        lastoccofperiod = emailval.lastIndexOf('.');
        if (lastoccofperiod <= 0)
        {
            blnperiod = 0;
        }
        if (((icount - lastoccofperiod) > 4)||((icount - lastoccofperiod) < 3))
        {
            maxthree = 0;
        }
         for(i=0;i<=icount;i++)
        {
            tempStr = emailval.charAt(i)
            if (tempStr=='@')
            ampicount=ampicount + 1;
        }
        amppos = emailval.indexOf('@');
        if (emailval.charAt(amppos+1) == '.')
        servername = 0;
        if(icount - emailval.charAt(amppos)< 5)
        servername = 0;
        if ((ampicount==1)&&(blnperiod==1)&&(maxthree==1)&&(servername==1))
        {
            blnmail=1;
        }
        else
        {
             blnmail=0;
        }
         //return blnmail;
        if (blnmail==0)
        {
            //alert('Please enter a valid email address');
            return false;
        }
        else
        {
            return true;
        }
     }

    //returns true if the text carries only alphabets.
    function isAlphabetic(textval)
    {
        var text=new String(textval);
        var ilen;
        var bflag=true;
        for(ilen=0;ilen<=text.length;ilen++)
        {
            if(text.charCodeAt(ilen) < 65 || text.charCodeAt(ilen) > 90 && text.charCodeAt(ilen) < 97 || text.charCodeAt(ilen) > 122)
            {
                bflag=false;
            }
        }
        return bflag;
    }

    function isCurrency(text)
    {
        var bflag=true;
        if(text != "")
        {
            var k = len(text);
            var i;
            for (i=0; i<k; i++)
            {
                if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == ".")))
                {
                    bflag=false;
                }
            }
        }
        return bflag;
    }
    //isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.()
    function isTelephoneNumber(text)
    {
        var bflag=true;
        if(text != "")
        {
            var k = len(text);
            var i;
            for (i=0; i<k; i++)
            {
                if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == "-")|| (text.charAt(i) == "(")|| (text.charAt(i) == ")") || (text.charAt(i) == "+") || (text.charAt(i) == ".")|| (text.charAt(i) == " ")))
                {
                    bflag=false;
                }
            }
        }
        return bflag;
    }

    //returns true if it is valid date.
    function isDate(date,month,year)
    {
        var bflag=true;
        if (isNaN(year) || isNaN(month) || isNaN(date))
        {
            bflag=false;
        }
        if(bflag)
        {
            var dtnew = new Date(year,month-1,date);
            if ((parseInt(dtnew.getFullYear()) == year) && (parseInt(dtnew.getMonth()) == (month-1)) && (parseInt(dtnew.getDate()) == date))
            {
                bflag=true;
            }
            else
            {
                bflag=false;
            }
        }
        return bflag;
    }

    //returns string by removing whitespaces from both the ends.
    function trim(text)
    {
        var stext = new String(text);
        var sresult = "";
        //Remove leading spaces
        for (var i=0; i<stext.length; i++)
        {
            if (stext.charAt(i) != " ")
            {
                sresult = stext.substr(i, (stext.length - i));
                break;
            }
        }
        stext = sresult;
        //Remove trailing spaces
        for (var j=(stext.length - 1); j>=0; j--)
        {
            if (stext.charAt(j) != " ")
            {
                sresult = stext.substr(0, (j + 1));
                break;
            }
        }
        return sresult;
    }

    // returns length of the text
    function len(text)
    {
        var strText=new String(text);
        return strText.length;
    }

    // selecting & focusing on the element that holds asporrect value
    function selectFocus(element)
    {
        element.select();
        element.focus();
        return true;
    }

    //returns true if a radio button is checked
    function IsRadioChecked(objForm,strName)
    {
        var bcorrect;
        bcorrect=false;
        for(i=0; i<objForm.elements.length; i++)
        {
            var name=objForm.elements[i].name;
            var type=objForm.elements[i].type;
            if((type=="radio") && (name.indexOf(strName)!=-1))
            {
                var val=objForm.elements[i].checked;
                if(val==true)
                {
                    bcorrect=true;
                    break;
                }
            }
        }
        return bcorrect;
    }

    //returns true if atleast one check box is selected
    function IsCheckboxSelected(objForm,strName)
    {
        var bcorrect=false;
        for(var i=0; i<objForm.elements.length; i++)
        {
            var name=objForm.elements[i].name;
            var type=objForm.elements[i].type;
            if((type=="checkbox") && (name.indexOf(strName)!=-1))
            {
                var val=objForm.elements[i].checked;
                if(val==true)
                {
                    bcorrect = true;
                    break;
                }
            }
        }
        return bcorrect;
    }

    /*  Validation functions ends here. */


    /*  HTML Element Validation functions starts here..... */
    //HTML Element "Text box" validations (includes text area also.)
    function ValidateTextBox(strName,obj,bZeroLength,iMaxChars,bAlphabet,bNumeric,bAlphanumeric,bEmail,bTelNumber,bURL,bFile,strFileType,bCurrency)
    {
        var bCorrect=true;

        //Zerolength validation is optional, if bZeroLength is true then textbox value is checked for zerolength.
        if(bCorrect && bZeroLength)
        {
            if(isNull(obj.value))
            {
                bCorrect=false;
                alert(strName + " is blank.");
                selectFocus(obj);
            }
        }

        //MaxLength is not optional
        if(bCorrect)
        {
            if(isMaxLength(obj.value,iMaxChars))
            {
                bCorrect=false;
                alert(strName + " is greater than " + iMaxChars + " characters.");
                selectFocus(obj);
            }
        }

        //Alphabet validation is optional, if bAlphabet is true then textbox value is checked for Alphabets.
        if(bCorrect && bAlphabet)
        {
            if(!isAlphabetic(obj.value))
            {
                bCorrect=false;
                alert(strName + " must have only alphabets.");
                selectFocus(obj);
            }
        }

        //Numeric validation is optional, if bNumeric is true then textbox value is checked for Numeric.
        if(bCorrect && bNumeric)
        {
            if(!isNumber(obj.value))
            {
                bCorrect=false;
                alert(strName + " must have only numbers.");
                selectFocus(obj);
            }
        }

        //Alphanumeric validation is optional, if bAlphanumeric is true then textbox value is checked for Alphanumeric.
        if(bCorrect && bAlphanumeric)
        {
            if(!isAlphaNumeric(obj.value))
            {
                bCorrect=false;
                alert(strName + " must have only alphanumeric characters.");
                selectFocus(obj);
            }
        }

        //Email validation is optional, if bEmail is true then textbox value is checked for Email.
        if(bCorrect && bEmail)
        {
            if(!isEmail(obj.value))
            {
                bCorrect=false;
                alert(strName + " entered is not a valid email address.");
                selectFocus(obj);
            }
        }

        //TelNumber validation is optional, if bTelNumber is true then textbox value is checked for TelNumber.
        if(bCorrect && bTelNumber)
        {
            if(!isTelephoneNumber(obj.value))
            {
                bCorrect=false;
                alert(strName + " is not a valid telephone/fax number.");
                selectFocus(obj);
            }
        }

        //URL validation is optional, if bURL is true then textbox value is checked for URL.
        if(bCorrect && bURL)
        {
            if(!isValidURL(obj.value))
            {
                bCorrect=false;
                alert(strName + " is not a valid URL.");
                selectFocus(obj);
            }
        }
        if(bCorrect && bFile)
        {
            if(!isFile(obj.value,strFileType))
            {
                bCorrect=false;
                alert(strName + " is not a valid File Type.");
                selectFocus(obj);
            }
        }
        if(bCorrect && bCurrency)
        {
            if(!isCurrency(obj.value))
            {
                bCorrect=false;
                alert(strName + " is not a valid number.");
                selectFocus(obj);
            }
        }
        return bCorrect;
    }


    //HTML Element "Drop-down list" validations
    function ValidateDropdownList(strName,obj,bSelect,iMaxChars)
    {
        var bCorrect=true;

        //Select validation is optional, if bSelect is true then textbox value is checked for Selection.
        if(bCorrect && bSelect)
        {
            if(getSelectedOption(obj)=="")
            {
                bCorrect=false;
                alert(strName + " is not selected.");
                obj.focus();
            }
        }

        //MaxLength is not optional
        if(bCorrect)
        {
            if(isMaxLength(getSelectedOption(obj),iMaxChars))
            {
                bCorrect=false;
                alert(strName + " is greater than " + iMaxChars + " characters.");
                obj.focus();
            }
        }

        return bCorrect;
    }

    //HTML Element "Radio button" validations
    function ValidateRadioButton(strLabel,strRadioName,objForm,bChecked)
    {
        var bCorrect=true;

        //Radio button validation is optional, if bChecked is true then it is checked for Selection.
        if(bCorrect && bChecked)
        {
            if(!IsRadioChecked(objForm,strRadioName))
            {
                bCorrect=false;
                alert(strLabel + " is not selected.");
            }
        }
        return bCorrect;
    }

    //HTML Element "Check box" validations
    function ValidateCheckBox(strLabel,strCheckBoxName,objForm,bChecked)
    {
        var bCorrect=true;

        //Check box validation is optional, if bChecked is true then it is checked for Selection.
        if(bCorrect && bChecked)
        {
            if(!IsCheckboxSelected(objForm,strCheckBoxName))
            {
                bCorrect=false;
                alert(strLabel + " is not selected.");
            }
        }
        return bCorrect;
    }

    // validate date box.
    function ValidateDateBox(strLabel,obj,iDay,iMonth,iYear,bSelected,bFutureDate,bPastDate)
    {
        var bcorrect=true;
        if(bSelected)
        {
            if(bcorrect && !isDate(iDay,iMonth,iYear))
            {
                bcorrect=false;
                alert("Please select a valid " + strLabel + ".");
                obj.focus();
            }
        }
        if(iDay!="" && iMonth!="" && iYear!="")
        {
            if(bcorrect && !isDate(iDay,iMonth,iYear))
            {
                bcorrect=false;
                alert("Please select a valid " + strLabel + ".");
                obj.focus();
            }
        }
        if (bFutureDate)
        {
            if(bcorrect)
            {
                var dtnew = new Date(iYear,iMonth-1,iDay);
                var dtnow = new Date();
                if(dtnew<dtnow)
                {
                    bcorrect=false;
                    alert("Please select a valid future date.");
                    obj.focus();
                }
            }
        }
        if(bPastDate)
        {
            if(bcorrect)
            {
                var dtnew = new Date(iYear,iMonth-1,iDay);
                var dtnow = new Date();
                if(dtnew>dtnow)
                {
                    bcorrect=false;
                    alert("Please select a valid past date.");
                    obj.focus();
                }
            }
        }
        return bcorrect;
    }


    //select All checkboxes starting with..
    function SelectAllCheckBoxes(strFormName,strSearchChars,strSelectAll)
    {
        var objForm=eval("document." + strFormName);
        for(var i=0; i<objForm.length; i++)
        {
            if(objForm.elements[i].type == "checkbox")
            {
                var strCheckBoxName = new String(objForm.elements[i].name);
                if(strCheckBoxName.indexOf(strSearchChars) != -1)
                {
                    var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
                    if(eval("document." + strFormName + "." + strSelectAll + ".checked")==true)
                        objCheckBox.checked  = true;
                    else
                        objCheckBox.checked = false;
                }
            }
        }
    }

    //unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
    function UnSelectCheckBox(strFormName,strSearchChars,strSelectAll)
    {
        var bcheckbox=true;
        var objForm=eval("document." + strFormName);
        for(var i=0; i<objForm.length; i++)
        {
            if(objForm.elements[i].type == "checkbox")
            {
                var strCheckBoxName = new String(objForm.elements[i].name);
                if(strCheckBoxName.indexOf(strSearchChars) != -1)
                {
                    var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
                    if(objCheckBox.checked==false)
                        bcheckbox=false;
                }
            }
        }
        var objCheckBoxAll=eval("document." + strFormName + "." + strSelectAll);
        if (objCheckBoxAll != null)
        {
            if(bcheckbox)
                objCheckBoxAll.checked=true;
            else
                objCheckBoxAll.checked=false;
        }
    }

    //selected checkbox values are stored in the hidden field with "," as delimiter
    function StoreSelectedCheckBoxes(strFormName,strHiddenName,strSearchChars)
    {
        var objForm=eval("document." + strFormName);
        var objHidden=eval("document." + strFormName + "." + strHiddenName);
        var iLen=strSearchChars.length;
        eval("document." + strFormName + "." + strHiddenName).value="";
        for(var iLoop=0;iLoop<objForm.elements.length;iLoop++)
        {
            if(objForm.elements[iLoop].type=="checkbox")
            {
                var strCheckBoxName=new String(objForm.elements[iLoop].name);
                if(strCheckBoxName.slice(0,iLen)==strSearchChars)
                {
                    if(objForm.elements[iLoop].checked==true)
                    {
                        objHidden.value+=(objHidden.value=="") ? strCheckBoxName.slice(iLen) : ("," + strCheckBoxName.slice(iLen));
                    }
                }
            }
        }
        //alert(objHidden.value);
    }

    //Checks whether file type is ends with specified extension or not

    function isFile(strValue,strFileType)
    {
        var bCorrect=false;
        strImage=new String(strValue);
        var bHtml=false;
        var bAll=false;
        var bImage=false;
        if(strValue.length==0)
        {
            return true;
        }
        if(strFileType.toLowerCase()=="htm" || strFileType.toLowerCase()=="html")
        {
            bHtml=true;
        }
        if(strFileType.toLowerCase()=="all")
        {
            bAll=true;
        }
        if(strFileType.toLowerCase()=="img")
        {
            bImage=true;
        }
        if(strImage.indexOf(".")!=-1)
        {
            iIndex=strImage.indexOf(".");
            if(bAll==true)
            {
                strFile=strImage.substring(iIndex+1);
                if(strFile.length>=2)
                {
                    bCorrect=true;
                    return bCorrect;

                }
                else
                {
                    bCorrect=false;
                    return bCorrect;

                }
            }
            else    if(bImage==true)
            {
                if((strImage.substring(iIndex+1)).toLowerCase()=="gif" || (strImage.substring(iIndex+1)).toLowerCase()=="jpg" || (strImage.substring(iIndex+1)).toLowerCase()=="jpeg" || (strImage.substring(iIndex+1)).toLowerCase()=="bmp")
                {
                    bCorrect=true;
                    return bCorrect;

                }
                else
                {
                    bCorrect=false;
                    return bCorrect;

                }
            }
            else    if(bHtml==true)
            {
                if((strImage.substring(iIndex+1)).toLowerCase()=="htm" || (strImage.substring(iIndex+1)).toLowerCase()=="html")
                {
                    bCorrect=true;
                    return bCorrect;

                }
                else
                {
                    bCorrect=false;
                    return bCorrect;

                }
            }
            else
            {
                if((strImage.substring(iIndex+1)).toLowerCase()==strFileType.toLowerCase())
                {
                    bCorrect=true;
                    return bCorrect;

                }
                else
                {
                    bCorrect=false;
                    return bCorrect;

                }
            }
        }
        else
        {
            bCorrect=false;
            return bCorrect;
        }
    }
    /*  HTML Element Validation functions ends here. */


function isValidCreditCard(strValue)
{
    var b_correct = true;
    if(b_correct)
    {
        if(isNotNumeric(strValue))
        {
            b_correct = false;
        }
    }
    if(b_correct)
    {
        var str_len=strValue.length;
        var b=0;
        var a=1;
        for(var i=str_len;i>=1;i--)
        {
            if(a%2!=0)
            {
                b=b+parseInt(strValue.substring(i-1,i));
            }
            else
            {
                var j;
                j=strValue.substring(i-1,i)*2;
                if(j.toString().length>1)
                {
                    for(var s=0;s<=1;s++)
                    {
                        b=b+parseInt((j.toString()).substring(s,s+1));
                    }
                }
                else
                {
                    b=b+j;
                }
            }
            a=a+1;
        }
        if(b%10==0)
        {
            b_correct=true;
        }
        else
        {
            b_correct=false;
        }
    }
    return b_correct;
}


//************** DD/MM/YYYY DATE VALIDATION STARTS HERE *******************************//
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 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
}

function is_ddmmyyyy(dtStr)
{
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=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)
    }
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1)
    {
        alert("The date format should be : dd/mm/yyyy")
        return false
    }
    if (strMonth.length<1 || month<1 || month>12)
    {
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
    {
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
    {
        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
    {
        alert("Please enter a valid date")
        return false
    }
    return true
}

 //************** DD/MM/YYYY DATE VALIDATION  ENDS HERE********************************//



//************** HH:MM:SS AM/PM format VALIDATION STARTS HERE********************************//
    function IsValidTime(timeStr)
    {
        // Checks if time is in HH:MM:SS AM/PM format.
        // The seconds and AM/PM are optional.
        var b_correct=true;

        if(!isNull(timeStr))
        {
            var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

            var matchArray = timeStr.match(timePat);
            if (b_correct && matchArray == null)
            {
                alert("Time is not in a valid format.");
                b_correct = false;
            }

            if(b_correct)
            {
                hour = matchArray[1];
                minute = matchArray[2];
                second = matchArray[4];
                ampm = matchArray[6];

                if (second=="") { second = null; }
                if (ampm=="") { ampm = null }
            }

            if (b_correct && hour < 0  || hour > 23)
            {
                alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
                b_correct = false;
            }
            if (b_correct && hour <= 12 && ampm == null)
            {
                //if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time"))
                //{
                    alert("You must specify AM or PM.");
                    b_correct = false;
               //}
            }
            if  (b_correct && hour > 12 && ampm != null)
            {
                alert("You can't specify AM or PM for military time.");
                b_correct = false;
            }
            if (b_correct && minute<0 || minute > 59)
            {
                alert ("Minute must be between 0 and 59.");
                b_correct = false;
            }
            if (b_correct && second != null && (second < 0 || second > 59))
            {
                alert ("Second must be between 0 and 59.");
                b_correct = false;
            }
        }

        return b_correct;
    }
//************** HH:MM:SS AM/PM format VALIDATION ENDS HERE********************************//

function getLength(str)
{
    while (str.substr(str.length-1)==" ")
    {
        str = str.substring(0,str.length-1);
    }
    return str.length
}
function isValidDateshort(iYear, iMonth, iDay)
{
    if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
    {
      return false;
    }

        var dtNewDate = new Date(iYear, (iMonth-1), iDay);
        if ((parseInt(dtNewDate.getYear()) == iYear)
            && (parseInt(dtNewDate.getMonth()) == (iMonth-1))
            && (parseInt(dtNewDate.getDate()) == iDay))
        {
            return true;
        }
    return false;
}
function timevalidateshort(curtime)
{
    bcorrect = 1;
    if (getLength(curtime)!=5)
    {
        bcorrect = 0;
    }
    if (curtime.slice(2,3)!=":")
    {
        bcorrect = 0;
    }
    if(isNumber(curtime.slice(0,2)))
    {
        if((curtime.slice(0,2)<0) || (curtime.slice(0,2)>23))
        {
            bcorrect = 0;
        }
    }else{
        bcorrect = 0;
    }
    if(isNumber(curtime.slice(3,5)))
    {
        if((curtime.slice(3,5)<0) || (curtime.slice(3,5)>59))
        {
            bcorrect = 0;
        }
    }else{
        bcorrect = 0;
    }

    return bcorrect;
}

function timevalidatelong(curtime)
{
    bcorrect = 1;
    if (getLength(curtime)!=8)
    {
        bcorrect = 0;
    }
    if (curtime.slice(2,3)!=":")
    {
        bcorrect = 0;
    }
    if (curtime.slice(5,6)!=":")
    {
        bcorrect = 0;
    }
    if(isNumber(curtime.slice(0,2)))
    {
        if((curtime.slice(0,2)<0) || (curtime.slice(0,2)>23))
        {
            bcorrect = 0;
        }
    }else{
        bcorrect = 0;
    }
    //check minutes
    if(isNumber(curtime.slice(3,5)))
    {
        if((curtime.slice(3,5)<0) || (curtime.slice(3,5)>59))
        {
            bcorrect = 0;
        }
    }else{
        bcorrect = 0;
    }
    //check seconds
    if(isNumber(curtime.slice(6,8)))
    {
        if((curtime.slice(6,8)<0) || (curtime.slice(6,8)>59))
        {
            bcorrect = 0;
        }
    }else{
        bcorrect = 0;
    }

    return bcorrect;
}

//-->
