﻿
function getWorkTypesForContactForm()
{
   try   
   {
       
        //Attach a timestamp to prevent caching
        var timestamp = new Date().getTime();
        $.get("AJAX/GetWorkTypes.aspx", { time: timestamp },
                                      function(data){
                                        eval(data)
                                        getWorkTypesForContactFormCallback(jsonResult);
                                      });
                                      
       
  }
  catch(ex)
  {
    alert("Error");
  }
}

function getWorkTypesForContactFormCallback(data)
{
    try
    {
        var dropDownHtml = "";
        var items = data.worktypes.length;
        for(var i=0; i < items; i++)
        {
            var option = document.createElement('option');
            option.text = data.worktypes[i].name;
            option.value = data.worktypes[i].id;
            
            try
            {
                document.getElementById('cboLegalService').add(option);
            }
            catch(e)
            {
                document.getElementById('cboLegalService').add(option, null);
            }
            
        }
        
    }
    catch(ex)
    {
        getWorkTypesForContactForm();
    }
}

document.onload = getWorkTypesForContactForm();


function startQuickContact()
{
    var fName = document.getElementById("txt_Quick_fName").value;
    var sName = document.getElementById("txt_Quick_sName").value;
    var pCode = document.getElementById("txt_Quick_pCode").value;
    var telNo = document.getElementById("txt_Quick_telNo").value;
    var emailAddr = document.getElementById("txt_Quick_emailAddr").value;
    
    if(fName != "" && sName != "" && pCode != "" && telNo != "" && emailAddr != "")
    {
        var workType = document.getElementById("cboLegalService").selectedIndex;
        if(workType != 0)
        {
            document.getElementById("contactSubmitButton").innerHTML = "<img src='images/loadAnim.gif' alt='Sending...'/>"
        
            var workTypeValue = document.getElementById("cboLegalService").value;
            //Attach a timestamp to prevent caching
            var timestamp = new Date().getTime();
            $.get("AJAX/QuickContact.aspx", { _fname_: fName, _sname_: sName, _pcode_: pCode, _telno_: telNo, _emailaddr_: emailAddr, _wt_: workTypeValue },
                                          function(data){
                                            startQuickContactCallback(data);
                                          });
        }
        else
        {
            alert("Please select an area of law in the quick contact form.");
        }
    }
    else
    {
        alert("Please ensure you completely fill out the quick contact form before clicking submit.");
    }
}

function startQuickContactCallback(data)
{
    if(data == "OK")
    {
        window.location = "ContactUsConfirmation.aspx?success=true";
    }
}