﻿// JScript File

function getKeyCode(e)
{
    if (window.event)
       return window.event.keyCode;
    else if (e)
       return e.which;
    else
       return null;
}

function keyRestrict(e, validchars) 
{
    var key='', keychar='';
    key = getKeyCode(e);
    
    if (key == null) 
        return true;
        
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    validchars = validchars.toLowerCase();
    
    if (validchars.indexOf(keychar) != -1)
        return true;
        
    if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
        return true;
        
    return false;
}

function CountryVisibility()
{
    document.getElementById('ctl00_car_ddlCountry').value = '0';
    document.getElementById('ctl00_car_ddlCity').value='0';
    if(document.getElementById('ctl00_car_DDLResidentialStatus').value=="1")
    {
        document.getElementById('divCountry').style.display='inline';
    }
    else if(document.getElementById('ctl00_car_DDLResidentialStatus').value=="0")
    {
        document.getElementById('divCountry').style.display='none';
        document.getElementById('ctl00_car_ddlCity').style.display='inline';
        document.getElementById('divCitybr').style.display = 'none';
        document.getElementById('divCityOther').style.display = 'none';
    }
    CityVisibility_Country();
}

function CityVisibility_Country()
{
    document.getElementById('ctl00_car_ddlCity').value='0';
    document.getElementById('ctl00_car_txtCityName').value = "";
    if(document.getElementById('divCountry').style.display=="inline")
    {
        if(document.getElementById('ctl00_car_ddlCountry').value=="101")
        {
            document.getElementById('ctl00_car_ddlCity.ClientID').style.display='inline';
            document.getElementById('divCitybr').style.display = 'none';
            document.getElementById('divCityOther').style.display = 'none';
        }
        else
        {
            document.getElementById('ctl00_car_ddlCity.ClientID').style.display='none';
            document.getElementById('divCitybr').style.display = 'none';
            document.getElementById('divCityOther').style.display = 'inline';
        }
    }
}

function CityVisibility_City()
{
    document.getElementById('ctl00_car_txtCityName').value = "";
    if(document.getElementById('ctl00_car_ddlCity').value=="OtherCity")
    {
        document.getElementById('divCitybr').style.display = 'inline';
        document.getElementById('divCityOther').style.display = 'inline';
    }
    else
    {
        document.getElementById('divCitybr').style.display = 'none';
        document.getElementById('divCityOther').style.display = 'none';
    }
}

function CompanyTurnoverVisibility()
{
    document.getElementById('ctl00_car_txtCompanyTurnOver').value = "";
    if(document.getElementById('ctl00_car_DDLEmploymentStatus').value=="0")
        document.getElementById('divCompanyTurnOver').style.display = 'inline';
    else
        document.getElementById('divCompanyTurnOver').style.display = 'none';
}

function Validate_AcceptPrinciples(oSrc, args)
{
    args.IsValid=document.getElementById("ctl00_car_ChkTermsConditions").checked;
}

function Validate_DOB(oSrc, args)
{
    if(document.getElementById("ctl00_car_DDL_DOBDay").value=="0" &&
        document.getElementById("ctl00_car_DDL_DOBMonth").value=="0" &&
        document.getElementById("ctl00_car_DDL_DOBYear").value=="0")
            args.IsValid=false;
    else
    {
        var CurrDate=new Date();
        var UserDate=new Date(document.getElementById("ctl00_car_DDL_DOBMonth").value + "/" +
                document.getElementById("ctl00_car_DDL_DOBDay").value + "/" +
                document.getElementById("ctl00_car_DDL_DOBYear").value);
                
        if(document.getElementById("ctl00_car_DDL_DOBDay").value!="0" &&
            document.getElementById("ctl00_car_DDL_DOBMonth").value!="0" &&
            document.getElementById("ctl00_car_DDL_DOBYear").value!="0")
        {
            if(UserDate>CurrDate)
                    args.IsValid=false;
            else if(document.getElementById("ctl00_car_DDL_DOBMonth").value=="4" ||
                document.getElementById("ctl00_car_DDL_DOBMonth").value=="6" ||
                document.getElementById("ctl00_car_DDL_DOBMonth").value=="9" ||
                document.getElementById("ctl00_car_DDL_DOBMonth").value=="11")
            {
                if(document.getElementById("ctl00_car_DDL_DOBDay").value=="31")
                    args.IsValid=false;
                else
                    args.IsValid=true;
            }
            else if(document.getElementById("ctl00_car_DDL_DOBMonth").value=="2")
            {
                if(parseInt(document.getElementById("ctl00_car_DDL_DOBYear").value)%4==0)
                {
                    if(parseInt(document.getElementById("ctl00_car_DDL_DOBDay").value)>29)
                        args.IsValid=false;
                    else
                        args.IsValid=true;
                }
                else
                {
                    if(parseInt(document.getElementById("ctl00_car_DDL_DOBDay").value)>28)
                        args.IsValid=false;
                    else
                        args.IsValid=true;
                }
            }
            else
                args.IsValid=true;
        }
        else
            args.IsValid=false;
    }
}

function Validate_PhoneNumber(oSrc, args)
{
    if(document.getElementById("ctl00_car_txtHomeNumber").value=="" && document.getElementById("ctl00_car_txtMobileNumber").value=="")
        args.IsValid=false;
    else
        args.IsValid=true;
}

function Validate_Country(oSrc, args)
{
    if(document.getElementById("ctl00_car_DDLResidentialStatus").value == "1" )
    {
        if(document.getElementById("ctl00_car_ddlCountry").value == '0')
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else
        args.IsValid = true;
}

function Validate_DDLCity(oSrc, args)
{
    if (document.getElementById('ctl00_car_DDLResidentialStatus').value == "1" 
            && document.getElementById('ctl00_car_ddlCountry').value == "101")
    {
        if (document.getElementById('ctl00_car_ddlCity').value == "0")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else if (document.getElementById('ctl00_car_DDLResidentialStatus').value == "0")
    {
        if (document.getElementById('ctl00_car_ddlCity').value == "0")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else
        args.IsValid = true;
}

function Validate_txtCity(oSrc, args)
{
    if (document.getElementById('ctl00_car_DDLResidentialStatus').value == "1" 
            && document.getElementById('ctl00_car_ddlCountry').value != "101")
    {
        if (document.getElementById('ctl00_car_txtCityName').value == "")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else if (document.getElementById('ctl00_car_DDLResidentialStatus').value == "1" 
                && document.getElementById('ctl00_car_ddlCountry').value == "101" 
                && document.getElementById('ctl00_car_ddlCity').value == "OtherCity")
    {
        if (document.getElementById('ctl00_car_txtCityName').value == "")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else if (document.getElementById('ctl00_car_DDLResidentialStatus').value == "0" 
                && document.getElementById('ctl00_car_ddlCity').value == "OtherCity")
    {
        if (document.getElementById('ctl00_car_txtCityName').value == "")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else
        args.IsValid = true;
}

