﻿/// This is for validation and processing of web design only

/// <reference path="ajax_methods.js" />


function checkstep1() {
    var txtpostcode = document.getElementById('txtPostcode_search');
    var pmsg = document.getElementById('pmessage1');

    if (txtpostcode.value == "") {

        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please enter a valid postode</b>');
        return false;
    } else {

        // show next div and message

        // changespantext('pmessage1', 'Website Design Quotes are \navailable in ' + txtpostcode.value);
        $('#pmessage1').text('Insulation Grants are\navailable in ' + txtpostcode.value)
        toggledivs('ins_div1', 'ins_div2');

        return false; // to avoid post back
    }
}

function checkstep2() {


    var ddLoft = document.getElementById('ddLoft');
    var ddWall = document.getElementById('ddWall');

    if (ddLoft.value == 'Select') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please choose the types of insulation you require..</b>');
        return false;
    } else if (ddWall.value == 'Select') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please choose the types of insulation you require..</b>');
        return false;
    } else {
        toggledivs('ins_div2', 'ins_div3');
        return true;
    }

}



function checkstep3() {

    toggledivs('ins_div3', 'ins_div4');
    return true;    

}


function submitForm() {

    var fname, lname, houseno, emailid, phoneno, mobileno, postcode, address;
    fname = document.getElementById('txtFname').value;
    lname = document.getElementById('txtLname').value;
    houseno = document.getElementById('txtHouseno').value;
    address = document.getElementById('txtAddress').value;
    postcode = document.getElementById('txtpostcode2').value;

    emailid = document.getElementById('txtEmail').value;

    phoneno = document.getElementById('txtTelephone').value;
    mobileno = document.getElementById('txtMobile').value;

    
    var chkReceivedgquotes = document.getElementById('chkdgQuote').checked;

    var ddLoft = document.getElementById('ddLoft');
    var ddWall = document.getElementById('ddWall');

    var ddPersonalinfo = document.getElementById('ddPersonalinfo');
    var ddPersonalinfo2 = document.getElementById('ddPersonalinfo2');
    var ddlandlordinfo = document.getElementById('ddlandlordinfo');
    var ddstatus = document.getElementById('ddstatus');

    var propEnquire='';

    if (ddlandlordinfo.style.display == 'none') {
        propEnquire = ddlandlordinfo.value;
    }



    if (fname == '' || lname == '' || emailid == '' || phoneno == '' || postcode == '' ) {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide us with your details. If you give us incorrect details then we will be unable to provide you with access to the best Grant Funds.<br><br>The Mandatory fields are <b> Name, Phone No, House No and Post Code</b>.<br><br>Your information will be kept safe and will not be passed onto any company without your permission.');
        return false;
    } else {



        // hide button to avoid double click
        document.getElementById('imgSubmit').style.display = 'none';
        document.getElementById('divprocessing').style.display = 'block';


        var formType = "insForm";
        var datasource;
        datasource = 'process.aspx?form=' + formType + '&fname=' + fname + '&lname=' + lname + '&email=' + emailid
                    + '&hno=' + houseno + '&phoneno=' + phoneno + '&postcode=' + postcode + '&loft=' + ddLoft.value
                    + '&mob=' + mobileno  + '&wall=' + ddWall.value + '&dgquote=' + chkReceivedgquotes + '&user=' + ddPersonalinfo.value
                    + '&enqprop=' + propEnquire + '&stat=' + ddstatus.value + '&pi2=' + ddPersonalinfo2.value + '';

        //alert(datasource);
        //submitonserver(datasource, '');

        //var dialog_submit = new pop_dialog();
        //dialog_submit.show_message('Sucess', 'Your request has been sucesfully submitted <br><b>We will get back to you with quotes from 4 companies </b> <br>Thanks for your interest in our website quote service');
        //parent.window.location = datasource;


        // make ajax call
        getAjaxCall(datasource, 'confirmInsulationrequest.aspx');

        

        return true;
    }

}


