﻿
/// <reference path="livevalidation_standalone.js" />



// this code works with jquery only
function onlyNumbers(objTextbox, e) {

    $(objTextbox).keypress(function (e) {
        //if the letter is not digit then display error and don't type anything // 32 for space bar

        if (e.which != 8 && e.which != 0 &&  (e.which < 48 || e.which > 57)) {

            //alert('Please enter a valid phone number eg : 097665567763');
            $(objTextbox).css({ "background-color": "red" });
            //$("#" + errDiv).show();
            return false;
        } else {
            $(objTextbox).css({ "background-color": "" });
            //$("#" + errDiv).hide();
            return true;
        }
    });
}


function isValidPhoneno(input) {

    // ignore if text is blanl

    if (input == '' || input == 'null') { return true; }

    if (input.length < 11 || input.length > 11) {
        return false;
    } else {
        return true;
    }

}

function checkQuickForm() {

    var txtPostcode = $('#txtQPostCode1').val();

    if (txtPostcode == '') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide you valid Postcode');
        return false;
    } else {
    window.location = 'getDouble-GlazingQuote.aspx';
    

    }



}



function checkForm1() {

    var txtPostcode = document.getElementById('txtPostcode1').value;
    var txtName = document.getElementById('txtName1').value;
    var txtTelno = document.getElementById('txtTelno1').value;
    var txtEmail = document.getElementById('txtEmail1').value;
    


    if (txtName == '' || txtTelno == '') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide you valid contact details<br><br><b>Name and Phone Number are Mandatory fields</b>');
        return false;
    } else {

        if (isValidPhoneno(txtTelno) == false) {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please enter a valid phone number?</b>');
        return false;
    }/*else if (validateEmailid(txtEmail) == false) {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please enter a valid Email id?</b>');
        return false;

    }*/

    
    var formType = "Qform";
    var datasource;
//    datasource = 'ajaxhandler.ashx?form=' + formType + '&fname=' + txtName + '&phoneno=' + txtTelno + '&email=' + txtEmail + '&postcode=' + txtPostcode + '';

  //  alert(datasource);


    //submitonserver(datasource, '');


    // now submit to quotatis
    var leadtype = 'UPVC Double Glazing';
    var processQuotatisURL = 'process.aspx?form=' + formType + '&fname=' + ''
                        + '&lname=' + txtName + '&email=' + txtEmail + '&phoneno=' + txtTelno
                        + '&postcode=' + txtPostcode + '&mobile=' + '' + '&address='
                        + '' + '&hno=' + '' + '&dur=' + '' + '&leadtype=' + leadtype + '';


    window.location = processQuotatisURL;
     //   alert('Submit form ');
        return true
    }
}


function testleadtype() {
    var leadtype = document.getElementById('leadtype').value;
    alert('Lead Type :' + leadtype);
    return;
}


function checkForm2() {

    var txtPostcode = document.getElementById('txtPostcode2').value;
    var txtName = document.getElementById('txtName2').value;
    var txtTelno = document.getElementById('txtTelno2').value;

    if (txtName == '' || txtTelno == '') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide you valid contact details<br><br><b>Name and Phone Number are Mandatory fields</b>');
        return false;
    } else {
    
    if (isValidPhoneno(txtTelno) == false) {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please enter a valid phone number?</b>');
        return false;
    }
    var formType = "Qform";
    var datasource;
    //datasource = 'ajaxhandler.ashx?form=' + formType + '&fname=' + txtName + '&phoneno=' + txtTelno + '&postcode=' + txtPostcode + '';

   // alert(datasource);


    //submitonserver(datasource, '');


    // now submit to quotatis
    var leadtype = 'UPVC Hardwood Double Glazing';
    var processQuotatisURL = 'process.aspx?form=' + formType + '&fname=' + ''
                        + '&lname=' + txtName + '&email=' + '' + '&phoneno=' + txtTelno
                        + '&postcode=' + txtPostcode + '&mobile=' + '' + '&address='
                        + '' + '&hno=' + '' + '&dur=' + '' + '&leadtype=' + leadtype + '';
                        
    window.location = processQuotatisURL;
    //   alert('Submit form ');
    return true
    }
}


// calculator form
function checkForm3() {

    var txtPostcode = document.getElementById('txtPostcode3').value;
    var txtName = document.getElementById('txtName3').value;
    var txtTelno = document.getElementById('txtTelno3').value;
    var txtEmail = document.getElementById('txtEmail3').value;

    if (txtName == '' || txtTelno == '') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide you valid contact details<br><br><b>Name and Phone Number are Mandatory fields</b>');
        return false;
    } else {

        if (isValidPhoneno(txtTelno) == false) {
            var dialog = new pop_dialog();
            dialog.show_message('Error', '<b>Please enter a valid phone number?</b>');
            return false;
        } /*else if (validateEmailid(txtEmail) == false) {
            var dialog = new pop_dialog();
            dialog.show_message('Error', '<b>Please enter a valid Email id?</b>');
            return false;
        
        }*/

        var formType = "Qform";
        var datasource;
        //datasource = 'ajaxhandler.ashx?form=' + formType + '&fname=' + txtName + '&phoneno=' + txtTelno + '&postcode=' + txtPostcode + '';

        // alert(datasource);


        //submitonserver(datasource, '');


        // now submit to quotatis
        var leadtype = 'Instant Price Double Glazing';
        var processQuotatisURL = 'process.aspx?form=' + formType + '&fname=' + ''
                        + '&lname=' + txtName + '&email=' + txtEmail + '&phoneno=' + txtTelno
                        + '&postcode=' + txtPostcode + '&mobile=' + '' + '&address='
                        + '' + '&hno=' + '' + '&dur=' + '' + '&leadtype=' + leadtype + '';

        window.location = processQuotatisURL;
        //   alert('Submit form ');
        return true
    }
}




function submitForm() {

    var fname, lname, emailid, phoneno, postcode, mobile, address, houseno, duration;
    fname = document.getElementById('txtFirstname').value;
    lname = document.getElementById('txtSurname').value;
    emailid = document.getElementById('txtEmail').value;
    phoneno = document.getElementById('txtPhoneno').value;
    postcode = document.getElementById('txtPostcode').value;
    mobile = document.getElementById('txtMobile').value;

    address = document.getElementById('txtAddress').value;
    houseno = document.getElementById('txtHouseno').value;

    duration = '';
    var leadtype = document.getElementById('leadtype').value;

    if (fname == '' || lname == '' || emailid == '' || phoneno == '' || postcode == '' || address == '' || houseno == '') {
        var dialog = new pop_dialog();
        dialog.show_message('Error', 'Please provide you valid contact details<br><br><b>Name,Postcode,Emailid , Phone , House no are Mandatory fields</b>');

        //alert('Please provide us with valid contact details\nto help us get a quote for you.');
        return false;
    } else if (validateEmailid(emailid) == false) {

    var dialog = new pop_dialog();
        dialog.show_message('Error', '<br><b>Invalid Emailid </b>');
        return false;
    } else {

    if (isValidPhoneno(phoneno) == false) {
        var dialog = new pop_dialog();
        dialog.show_message('Error', '<b>Please enter a valid phone number?</b>');
        return false;
    }

    var formType = "dgForm";
        var datasource;
        datasource = 'ajaxhandler.ashx?form=' + formType + '&fname=' + fname
                    + '&lname=' + lname + '&email=' + emailid + '&phoneno=' + phoneno
                    + '&postcode=' + postcode + '&mobile=' + mobile + '&address=' 
                    + address + '&hno=' + houseno + '&dur=' + duration + '&leadtype=' + leadtype + '';
                        

        var processQuotatisURL = 'process.aspx?form=' + formType + '&fname=' + fname
                        + '&lname=' + lname + '&email=' + emailid + '&phoneno=' + phoneno
                        + '&postcode=' + postcode + '&mobile=' + mobile + '&address='
                        + address + '&hno=' + houseno + '&dur=' + duration + '&leadtype=' + leadtype + '';


        //alert(processQuotatisURL);
        //window.location = 'thankyou.aspx';
        window.location = processQuotatisURL;
        return true;
    }

}



