﻿function ChangeDlFromDropdown() 
{
    if (document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").selectedIndex > document.getElementById(LightboxContactForm_UserControlName + "_DlTo").selectedIndex) {
        if (document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").selectedIndex == 10) {
            document.getElementById(LightboxContactForm_UserControlName + "_DlTo").selectedIndex = 9;
        }
        else {
            document.getElementById(LightboxContactForm_UserControlName + "_DlTo").selectedIndex = document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").selectedIndex;
        }
    }
}

function ChangeDlToDropdown() 
{
    if (document.getElementById(LightboxContactForm_UserControlName + "_DlTo").selectedIndex < document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").selectedIndex) 
    {
        document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").selectedIndex = document.getElementById(LightboxContactForm_UserControlName + "_DlTo").selectedIndex;
    }
}

function ContactFrmSubmit()
{
    var errorFlag = 0;
    
    if (document.getElementById(LightboxContactForm_UserControlName + "_TxtFirstName").value == "")
    {
        alert("You must enter your First Name");
        errorFlag = 1;
    }

    if (document.getElementById(LightboxContactForm_UserControlName + "_TxtSurname").value == "")
    {
        alert("You must enter your Surname");
        errorFlag = 1;
    }

    if (document.getElementById(LightboxContactForm_UserControlName + "_TxtEmail").value == "")
    {
        alert("You must enter your Email Address");
        errorFlag = 1;
    }

    if (document.getElementById(LightboxContactForm_UserControlName + "_TxtTelephone").value == "") {
        alert("You must enter your Telephone number");
        errorFlag = 1;
    }

    if (document.getElementById(LightboxContactForm_UserControlName + "_TxtPostcode").value == "")
    {
        alert("You must enter your Postcode");
        errorFlag = 1;
    }

    if (document.getElementById(LightboxContactForm_UserControlName + "_DlCallMy").value == "2" && trimAll(document.getElementById(LightboxContactForm_UserControlName + "_TxtMobile").value) == "") {
        alert("To be contacted on your mobile telephone you must enter that telephone number\n");
        errorFlag = 1;
    }
    
    if (errorFlag == 0)
    {
        document.getElementById(LightboxContactForm_UserControlName + "_ContactLightBoxSubt").value = "1";
        document.getElementById(LightboxContactForm_UserControlName + "_Button_OK").click();
        document.aspnetForm.submit();
    }
    else
    {
        return false;
    }
}

function ChangeCallMeState(_Enabled)
{
    document.getElementById(LightboxContactForm_UserControlName + "_DlCallMy").disabled = !_Enabled;
    document.getElementById(LightboxContactForm_UserControlName + "_DlCallOn").disabled = !_Enabled;
    document.getElementById(LightboxContactForm_UserControlName + "_DlFrom").disabled = !_Enabled;
    document.getElementById(LightboxContactForm_UserControlName + "_DlTo").disabled = !_Enabled;
}

