function SendMail(agt) {
    if (IsEmpty(document.getElementById('firm_name').value)) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter Firm Name.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('firm_name').focus();
        return;
    }
    if (IsEmpty(document.getElementById('contact_name').value)) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter Contact Name.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('contact_name').focus();
        return;
    }
    if (IsEmpty(document.getElementById('address').value)) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter Address.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('address').focus();
        return;
    }    

    if (IsEmpty(document.getElementById('phone').value)) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter Phone.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('phone').focus();
        return;
    }

    if (IsEmpty(document.getElementById('city').value)) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter City, State.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('city').focus();
        return;
    }

    if (validate(document.getElementById('email').value) == false) {
        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please enter valid Email address.</b></div>';
        window.scrollTo(1, 1); // horizontal and vertical scroll increments
        document.getElementById('email').focus();
        return;
    }

    //Type of project
    var typeofproject;
    typeofproject = '';
    var projects = new Array("General online research", "LexisNexis/Westlaw-based research", "Summarization of caselaw and/or legislation", "Drafting brief", "Drafting pleadings", "Presenting data in specified format", "Contract review/analysis");
    for (i = 0; i < 7; i++) {
        if (document.getElementById('check' + (i+1)).checked) {

            typeofproject += projects[i] + "<br />";
        }
        else {
            if (i == 6 && IsEmpty(typeofproject)) {
                document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please select at least one Type of Project.</b></div>';
                window.scrollTo(1, 1); // horizontal and vertical scroll increments
                return;
            }
        }
    }

    var listdocuments;
    var others = '';
    listdocuments = '';
    
    if (IsEmpty(document.getElementById('listothers').value) == false) {
        others = "Others - " + document.getElementById('listothers').value + "<br />";
    }
    var ldocuments = new Array("Description of research requirement", "Casefile", "Material to be summarized", "Contract to be reviewed", "Data to be organized");
    listdocuments = '';
    for (i = 0; i < 5; i++) {
        if (document.getElementById('check' + (i + 8)).checked) {

            listdocuments += ldocuments[i] + "<br />";
        }
        else {
            if (i == 4 && IsEmpty(listdocuments) && IsEmpty(others)) {
                document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please select at least one List Documents.</b></div>';
                window.scrollTo(1, 1); // horizontal and vertical scroll increments
                return;
            }


        }
    }
    listdocuments += others;

    var formatoutput;
    formatoutput = '';
    others = '';
    if (IsEmpty(document.getElementById('documentothers').value) == false) {
        others = "Others - " + document.getElementById('documentothers').value + "<br />";
    }

    var outputformat = new Array("Informal/formal memo (provide format details as appropriate)", "Spreadsheet", "Marked up document");
    formatoutput = '';
    for (i = 0; i < 3; i++) {
        if (document.getElementById('check' + (i + 13)).checked) {

            formatoutput += outputformat[i] + "<br />";
        }
        else {
            if (i == 2 && IsEmpty(formatoutput) && IsEmpty(others)) {
                document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Please select at least one Output Format.</b></div>';
                window.scrollTo(1, 1); // horizontal and vertical scroll increments
                return;
            }
        }
    }
    formatoutput += others;

    document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: green; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Sending please wait...</b></div>';
    $.post("http://greenpointtech.com/services/legal/wp-content/themes/New_GPTS/pilotform.php", { firmname: $('#firm_name').val(), contactname: $('#contact_name').val(), address: $('#address').val(), phone: $('#phone').val(), city: $('#city').val(), email: $('#email').val(), typeofproject: typeofproject, listdocuments: listdocuments, formatoutput: formatoutput, agent: agt, comments: $('#comments').val() }, function(data) {
        //window.location = data;
        if (data == "ok") {
            document.getElementById('firm_name').value = '';
            document.getElementById('contact_name').value = '';
            document.getElementById('address').value = '';
            document.getElementById('phone').value = '';
            document.getElementById('city').value = '';
            document.getElementById('email').value = '';
            document.getElementById('comments').value = '';
            document.getElementById('documentothers').value = '';
            document.getElementById('listothers').value = '';
            
            for (i = 0; i < 15; i++) {
                document.getElementById('check' + (i + 1)).checked = false;
            }
            document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: green; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Your order has been placed. We will get back to your shortly.</b></div>';
        }
        else {
            document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;"><b>Error to send mail. Please try later.</b></div>';
        }
    });

    window.scrollTo(1, 1); // horizontal and vertical scroll increments
}

function ShowListdocumentsOther()
{
    if(document.getElementById('check13').checked)
    {
        document.getElementById('listothers').disabled = false;
        document.getElementById('listothers').focus();
        
    }
    else
    {
        document.getElementById('listothers').value = '';
        document.getElementById('listothers').disabled = true; 
    }
}

function FormatOther() {
    if (document.getElementById('check17').checked) {
        //document.getElementById('formatother').style.display = "block";
        document.getElementById('documentothers').disabled = false;
        document.getElementById('documentothers').focus();
    }
    else {
        //document.getElementById('formatother').style.display = "none";
        document.getElementById('documentothers').value = '';
        document.getElementById('documentothers').disabled = true; 
    }
}

function ValidatePhone(strPhone) {
    var regPhone = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
    if (strPhone.match(regPhone)) {
        return true;
    }
    else {
        return false;
    }
}
function validate(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email;
    if (reg.test(address) == false) {
        return false;
    }
    else {
        return true;
    }
}

function IsEmpty(aTextvalue) {
    if ((aTextvalue.length == 0) ||
   (aTextvalue == null)) {
        return true;
    }
    else { return false; }
}

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
//function SendMail(agt) {
//    var errormessage;
//    errormessage = '';
//    if (IsEmpty(document.getElementById('firm_name').value)) {
//        errormessage = 'Please enter Firm Name. <br />';
//    }
//    if (IsEmpty(document.getElementById('contact_name').value)) {
//        errormessage += 'Please enter Contact Name. <br />';
//    }
//    if (IsEmpty(document.getElementById('address').value)) {
//        errormessage += 'Please enter Address. <br />';
//    }

//    if (IsEmpty(document.getElementById('phone').value)) {
//        errormessage += 'Please enter Phone. <br />';
//    }

//    if (IsEmpty(document.getElementById('city').value)) {
//        errormessage += 'Please enter City, State. <br />';
//    }

//    if (validate(document.getElementById('email').value) == false) {
//        errormessage += 'Please enter valid Email address. <br />';
//    }

//    //Type of project
//    var typeofproject;
//    typeofproject = '';
//    var projects = new Array("General on-line research", "Lexis/Westlaw-based research", "Summarization of caselaw and/or legislation", "Drafting brief", "Drafting pleadings", "Presenting data in specified format", "Contract review/analysis");
//    for (i = 0; i < 7; i++) {
//        if (document.getElementById('check' + (i + 1)).checked) {

//            typeofproject += projects[i] + "<br />";
//        }
//        else {
//            if (i == 6 && IsEmpty(typeofproject)) {
//                errormessage += 'Please select at least one Type of Project. <br />';
//            }


//        }
//    }

//    var listdocuments;
//    listdocuments = '';
//    var ldocuments = new Array("Description of research requirement", "Casefile", "Material to be summarized", "Contract to be reviewed", "Data to be organized");

//    for (i = 0; i < 6; i++) {
//        if (document.getElementById('check' + (i + 8)).checked) {

//            listdocuments += ldocuments[i] + "<br />";
//        }
//        else {
//            if (i == 5 && IsEmpty(listdocuments)) {
//                errormessage += 'Please select at least one List Documents. <br />';
//            }


//        }
//    }


//    var formatoutput;
//    formatoutput = '';
//    var outputformat = new Array("Informal/formal memo (provide format details as appropriate)", "Spreadsheet", "Marked up document");

//    for (i = 0; i < 3; i++) {
//        if (document.getElementById('check' + (i + 13)).checked) {

//            formatoutput += outputformat[i] + "<br />";
//        }
//        else {
//            if (i == 2 && IsEmpty(formatoutput)) {
//                errormessage += 'Please select at least one Output Format. <br />';
//            }


//        }
//    }


//    if (IsEmpty(errormessage)) {
//        $.post("http://greenpointtech.com/services/legal/wp-content/themes/New_GPTS/pilotform.php", { firmname: $('#firm_name').val(), contactname: $('#contact_name').val(), address: $('#address').val(), phone: $('#phone').val(), city: $('#city').val(), email: $('#email').val(), typeofproject: typeofproject, listdocuments: listdocuments, formatoutput: formatoutput, agent: agt }, function(data) {
//            //window.location = data;
//            if (data == "ok") {
//                document.getElementById('firm_name').value = '';
//                document.getElementById('contact_name').value = '';
//                document.getElementById('address').value = '';
//                document.getElementById('phone').value = '';
//                document.getElementById('city').value = '';
//                document.getElementById('email').value = '';

//                for (i = 0; i < 15; i++) {
//                    document.getElementById('check' + (i + 1)).checked = false;
//                }


//                document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: green; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">Thanks for your quote. Your message was received. We will get back to your shortly.</div>'
//            }
//            else {
//                document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">Error to send mail. Please try later.</div>'
//            }
//        });
//    }
//    else {
//        document.getElementById('errormesage').innerHTML = '<div  style="border: 1px solid red; color: red; padding-left: 5px; padding-top: 5px; padding-bottom: 5px;">' + errormessage + '</div>';
//    }
//    window.scrollTo(1, 1); // horizontal and vertical scroll increments
//}