﻿// JScript File
//Custom Check Box Validation

//Account Access Info Page
function ValidateTermsAndConditions(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_AAI_chConditions').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  function ValidatePrivacyPolicy(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_AAI_chPrivacy').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
//End

//PIN Reset Page

function ValidateRestPIN(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_RS_chReset').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  
//End

//Account Activation

function ActValidateTermsAndConditions(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_M_chConditions').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  function ActValidatePrivacyPolicy(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_M_chPrivacy').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  
//End

//Account Registration

function RegValidateTermsAndConditions(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_M_chConditions').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  function RegValidatePrivacyPolicy(sender, args)
  {
    if(document.getElementById('_ctl0_MiddlePLHDR_M_chPrivacy').checked)
        args.IsValid = true;
    else
       args.IsValid = false;
  }
  
//End

//Grid Item Selection
function ValidateGridItemSelection()
{
    var frm = document.forms(0);                              
    for(i=0;i< frm.length;i++)                                 
    {                                                           
        var e=frm.elements[i];
        if((e.type=='radio') && (e.name.indexOf('rdSelect') != -1))
        {
            if(e.checked)
                return true ; 
        }
    }
    return false;
}

//UID Item Selection
function EnDis(removable, activatable, currentLoggedUID, selectedUID)
{
if(removable == "False")
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnRemove').disabled = true;
else
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnRemove').disabled = false;

if(activatable == "False")
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnVerify').disabled = true;
else
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnVerify').disabled = false;
    

document.getElementById('_ctl0_MiddlePLHDR_UL_btnResetPIN').disabled = false
document.getElementById('_ctl0_MiddlePLHDR_UL_btnChangePIN').disabled = false

if(currentLoggedUID == selectedUID)
{
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnRemove').disabled = true;
    document.getElementById('_ctl0_MiddlePLHDR_UL_btnResetPIN').disabled = true
}

}

//Supp Account List
function SuppEnDis(accountStatus, lang)
{
//Account Status: 1 - Suspended
//                4 - Closed 
if(accountStatus == 1)
{
    if(lang == 'EN')
        document.getElementById('_ctl0_MiddlePLHDR_SL_btnSusAcc').value = 'Reactivate';
    else
        document.getElementById('_ctl0_MiddlePLHDR_SL_btnSusAcc').value = 'تشغيل';
}
else
{
    if(lang == 'EN')
        document.getElementById('_ctl0_MiddlePLHDR_SL_btnSusAcc').value = 'Suspend';
    else
        document.getElementById('_ctl0_MiddlePLHDR_SL_btnSusAcc').value = 'ايقاف';
}

if(accountStatus == 4)
    document.getElementById('_ctl0_MiddlePLHDR_SL_btnClose').disabled = true;
else
    document.getElementById('_ctl0_MiddlePLHDR_SL_btnClose').disabled = false;    
    
if(accountStatus == 1 || accountStatus == 4)
    document.getElementById('_ctl0_MiddlePLHDR_SL_btnFund').disabled = true;
else
    document.getElementById('_ctl0_MiddlePLHDR_SL_btnFund').disabled = false;          
    
document.getElementById('_ctl0_MiddlePLHDR_SL_btnViewInfo').disabled = false;
document.getElementById('_ctl0_MiddlePLHDR_SL_btnSusAcc').disabled = false;    

}

//Date of Birth Validation
function IsValidDate(sender, args) {
var dateStr = document.getElementById('_ctl0_MiddlePLHDR_ES_lstMonth').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_ES_lstDay').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_ES_lstYear').value; 
if(dateStr == '-1/-1/-1')
    args.IsValid = true;
else
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) 
        args.IsValid = false;
    month = matchArray[1];
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) 
        args.IsValid = false;
    if (day < 1 || day > 31) 
        args.IsValid = false;
    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
        args.IsValid = false;
    if (month == 2) 
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) 
            args.IsValid = false;
    }
}
return true;
}

function IsEIValidDate(sender, args) {
var dateStr = document.getElementById('_ctl0_MiddlePLHDR_EI_lstMonth').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_EI_lstDay').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_EI_lstYear').value; 
if(dateStr == '-1/-1/-1')
    args.IsValid = true;
else
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) 
        args.IsValid = false;
    month = matchArray[1];
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) 
        args.IsValid = false;
    if (day < 1 || day > 31) 
        args.IsValid = false;
    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
        args.IsValid = false;
    if (month == 2) 
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) 
            args.IsValid = false;
    }
}
return true;
}

function IsPDValidDate(sender, args) {
var dateStr = document.getElementById('_ctl0_MiddlePLHDR_PD_lstMonth').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_PD_lstDay').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_PD_lstYear').value; 
if(dateStr == '-1/-1/-1')
    args.IsValid = true;
else
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) 
        args.IsValid = false;
    month = matchArray[1];
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) 
        args.IsValid = false;
    if (day < 1 || day > 31) 
        args.IsValid = false;
    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
        args.IsValid = false;
    if (month == 2) 
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) 
            args.IsValid = false;
    }
}
return true;
}

function IsTDValidDate(sender, args) {
var dateStr = document.getElementById('_ctl0_MiddlePLHDR_TD_lstMonth').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_TD_lstDay').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_TD_lstYear').value; 
if(dateStr == '-1/-1/-1')
    args.IsValid = true;
else
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) 
        args.IsValid = false;
    month = matchArray[1];
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) 
        args.IsValid = false;
    if (day < 1 || day > 31) 
        args.IsValid = false;
    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
        args.IsValid = false;
    if (month == 2) 
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) 
            args.IsValid = false;
    }
}
return true;
}

function IsUAValidDate(sender, args) {
var dateStr = document.getElementById('_ctl0_MiddlePLHDR_UA_lstMonth').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_UA_lstDay').value + '/' + document.getElementById('_ctl0_MiddlePLHDR_UA_lstYear').value; 
if(dateStr == '-1/-1/-1')
    args.IsValid = true;
else
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null) 
        args.IsValid = false;
    month = matchArray[1];
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) 
        args.IsValid = false;
    if (day < 1 || day > 31) 
        args.IsValid = false;
    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
        args.IsValid = false;
    if (month == 2) 
    {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) 
            args.IsValid = false;
    }
}
return true;
}

//Notification Management
function ValidateNotificationSelection(sender, args) {
if(!document.getElementById('_ctl0_MiddlePLHDR_NM_chSuccessEvent').checked && !document.getElementById('_ctl0_MiddlePLHDR_NM_chFailureEvent').checked)
    args.IsValid = false;
else
    args.IsValid = true;

}

//PIN Validate
function PINValidate(sender, args)
{
var entry = document.getElementById('_ctl0_MiddlePLHDR_AAI_txtPIN').value;

//if not 6 entries, return false
if(entry.length != 6)
    args.IsValid = false;

//if any of the 6 entries is not an integer, return false
for(i=0; i<entry.length; i++)
{
    if(isNaN(entry.charAt(i)))
        args.IsValid = false;
}


//if any digit is repeated more than 2 times, return false 
var alreadyMaxRepeated = false;
for(i=0; i<entry.length; i++)
{
    var count = 0;
    var tempItem = entry.charAt(i);
    for(i=0; i<entry.length; i++)
    {
        if(entry.charAt(i) == tempItem)
            count += 1;
    }
    
    if(count > 2)
        args.IsValid = false;
}

return true;

}

//Sup Acc Activation PIN Validate
function PINSuppAccValidate(sender, args)
{
var entry = document.getElementById('_ctl0_MiddlePLHDR_M_txtPIN').value;

//if not 6 entries, return false
if(entry.length != 6)
    args.IsValid = false;

//if any of the 6 entries is not an integer, return false
for(i=0; i<entry.length; i++)
{
    if(isNaN(entry.charAt(i)))
        args.IsValid = false;
}


//if any digit is repeated more than 2 times, return false 
var alreadyMaxRepeated = false;
for(i=0; i<entry.length; i++)
{
    var count = 0;
    var tempItem = entry.charAt(i);
    for(i=0; i<entry.length; i++)
    {
        if(entry.charAt(i) == tempItem)
            count += 1;
    }
    
    if(count > 2)
        args.IsValid = false;
}

return true;

}

//Verify UID Pin Validation
function VerifyUIDPINValidate(sender, args)
{
var entry = document.getElementById('_ctl0_MiddlePLHDR_VU_txtNewPin').value;

//if not 6 entries, return false
if(entry.length != 6)
    args.IsValid = false;

//if any of the 6 entries is not an integer, return false
for(i=0; i<entry.length; i++)
{
    if(isNaN(entry.charAt(i)))
        args.IsValid = false;
}


//if any digit is repeated more than 2 times, return false 
var alreadyMaxRepeated = false;
for(i=0; i<entry.length; i++)
{
    var count = 0;
    var tempItem = entry.charAt(i);
    for(i=0; i<entry.length; i++)
    {
        if(entry.charAt(i) == tempItem)
            count += 1;
    }
    
    if(count > 2)
        args.IsValid = false;
}

return true;

}

//Change PIN Validation 
function ChangePINValidate(sender, args)
{
var entry = document.getElementById('_ctl0_MiddlePLHDR_CP_txtNewPin').value;

//if not 6 entries, return false
if(entry.length != 6)
    args.IsValid = false;

//if any of the 6 entries is not an integer, return false
for(i=0; i<entry.length; i++)
{
    if(isNaN(entry.charAt(i)))
        args.IsValid = false;
}


//if any digit is repeated more than 2 times, return false 
var alreadyMaxRepeated = false;
for(i=0; i<entry.length; i++)
{
    var count = 0;
    var tempItem = entry.charAt(i);
    for(i=0; i<entry.length; i++)
    {
        if(entry.charAt(i) == tempItem)
            count += 1;
    }
    
    if(count > 2)
        args.IsValid = false;
}

return true;

}

//Validate required captcha in subscription
function ValidateRequiredCaptcha(sender, args)
{
    if(document.getElementById('txtCaptcha').value == '')
        args.IsValid = false;
    else
        args.IsValid = true;
        
}


