// calculate the ASCII code of the given character
function CalcKeyCode(aChar)
{
    var character = aChar.substring(0,1);
    var code = aChar.charCodeAt(0);
    return code;
}
//Check the length of the mobile number

function checkMobileNumberForBD(val)
{
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);

    /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

    if (cCode < 48 || cCode > 57)
    {
        var myNumber = val.value.substring(0, (strLength) - 1);
        val.value = myNumber;
    }

    if(strLength > 9)
    {
        var myNumberlength = val.value.substring(0, (strLength) - 1);
        val.value = myNumberlength;
    }

    return false;
}


function checkMobileNumber(val, mobileNumberlength)
{
    val.value = val.value.replace(/\D/gi, "" ).substr(0, mobileNumberlength);
}

//Check the length of the verification id & verification mobile number
function checkVerificationMobileNumber(val)
{
    val.value = val.value.replace(/\D/gi, "" );
    return false;
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);

    /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

    if (cCode < 48 || cCode > 57 ) {
        var myNumber = val.value.substring(0, (strLength) - 1);
        val.value = myNumber;
    }
    return false;
}

//validate the Recharge information form for submission
function validateRechargeForm(formObject)
{
    var mobileNumberValue = formObject.mobileNumber.value;
    var mobileNumberLength = mobileNumberValue.length;

    var rechargeTypePrePaid = formObject.rechargeType[0].checked;
    var rechargeTypePrePost = formObject.rechargeType[1].checked;

    var amountIndex = formObject.amount.selectedIndex;
  
    var confirmationNumberValue = formObject.confirmationNumber.value;
    var confirmationNumberLength = confirmationNumberValue.length;


    if(rechargeTypePrePaid == false && rechargeTypePrePost == false)
    {
        alert("Please Select Connection Type!!");
        formObject.rechargeType.focus();
        return false;
    }
    else if(mobileNumberLength < 8) 
    {
        //alert("Mobile false");
        alert("Please Insert 8 Digit Mobile Number!!");
        formObject.mobileNumber.focus();
        return false;
    }
    else if(amountIndex == 0)
    {
        alert("Please Select Amount to Recharge!!");
        formObject.amount.focus();
        return false;
    }
    else if(confirmationNumberLength == 0)
    {
        //alert("Confirmation false");
        alert("Please Insert Confirmation Number!!");
        formObject.confirmationNumber.focus();
        return false;
    }
    else
    {
        //alert("true");
        formObject.submit();
        return true;
    }
  
  
}

//validate the Verification form for submission
function validateVerificationForm(formObject)
{
    var verificationIdValue = formObject.verificationId.value;
    var verificationIdLength = verificationIdValue.length;

    var mobileNumberValue = formObject.mobileNo.value;
    var mobileNumberLength = mobileNumberValue.length;

    if(verificationIdLength == 0)
    {
        //alert("Confirmation false");
        //alert("Please Insert Verification Id!!");
        document.getElementById('error').innerHTML="Please Insert Verification Id";
        document.getElementById('error').className="error";
        formObject.verificationId.focus();
        return false;
    } 
    else if(mobileNumberLength == 0)
    {
        //alert("Confirmation false");
        //alert("Please Insert Mobile Number!!");
        document.getElementById('error').innerHTML="Please Insert Mobile Number";
        document.getElementById('error').className="error";
        formObject.mobileNo.focus();
        return false;
    } else
    {
        formObject.submit();
        return true; 
    }

}

//Check the length of the confirmation mobile number
function checkConfirmationNumber(val)
{
    var strPass = val.value;
    var strLength = strPass.length;
    var lchar = val.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);
    //alert(cCode);

    /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

    if (cCode < 43 || (cCode > 43 && cCode < 48) || cCode > 57)
    {
        var myNumber = val.value.substring(0, (strLength) - 1);
        val.value = myNumber;
    }
    if(cCode == 43 && strLength !=1)
    {
        var myNumberplus = val.value.substring(0, (strLength) - 1);
        val.value = myNumberplus;
    }

    return false;
}

function onlyNumber(val)
{
    val.value = val.value.replace(/\D/gi, "" );
}
