﻿
$(function () {
    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                     //class of the element that will become your tab
        pathToTabImage: 'images/spotlight.png', //path to the image for the tab //Optionally can be set using css
        imageHeight: '160px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '43px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        //topPos: '150px',//                          //position from the top/ use if tabLocation is left or right
        topPos: '10px',
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
    });

});





function validateQuote() {
    txtName = document.forms["frmQuote"].txtName;
    txtEmail = document.forms["frmQuote"].txtEmail;
    txtPhone = document.forms["frmQuote"].txtPhone;
    txtQuestion = document.forms["frmQuote"].txtQuestion;

    msg = "Please fill following field(s):\n"

    if (txtName.value == "") {

        msg = msg + "Name\n";
    }
    if (txtEmail.value == "") {
        msg = msg + "Email\n";
    }
    if (txtPhone.value == "") {
        msg = msg + "Phone\n";
    }
    if (txtQuestion.value == "") {
        msg = msg + "Question\n";
    }
    if (txtEmail.value != "") {
        var v = validateEmail(txtEmail.value);
        if (v == false) {
            msg = msg + "Please enter valid email address\n"
        }
    }

    if (txtPhone.value != "") {
        var v = IsPhoneNumber(txtPhone.value);
       
        if (v == false) {
            msg = msg + "Please enter valid phone number\n"
        }
    }

    if (txtName.value.length > 50) {
        msg = msg + "Maximum limit of name is 50 characters\n"

    }
    if (txtEmail.value.length > 50) {
        msg = msg + "Maximum limit of email is 50 characters\n"

    }

    if (txtPhone.value.length > 15) {
        msg = msg + "Maximum limit of phone is 15 characters\n"

    }

    if (txtQuestion.value.length > 500) {
        msg = msg + "Maximum limit of question is 500 characters\n"

    }

    var isValid = 0;
    if (msg != "Please fill following field(s):\n") {
        alert(msg);
        isValid = 0;

    }
    else {
        isValid = 1;
    }

    if (txtQuestion.value == "") {
        txtQuestion.focus();
    }
    if (txtPhone.value == "") {
        txtPhone.focus();
    }
    if (txtEmail.value == "") {
        txtEmail.focus();
    }
    if (txtName.value == "") {

        txtName.focus();
    }


    if (isValid == 0) {
        return false;
    }
    else {

        return true;
    }
}


function validateEmail(emailtext) {
    var x = emailtext;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {

        return false;
    }
    else {
        return true;
    }
}

function IsPhoneNumber(strFieldValue) {
    if (strFieldValue.length < 9) {
        return false;
    }
    var plus = 0;
    var minus = 0;
    var lb = 0;
    var rb = 0;
    var validChars = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "(", ")", "+", "-");
    for (var i = 0; i < strFieldValue.length; i++) {
        if (strFieldValue.charAt(i) == "+") {
            plus++;
        }
        if (strFieldValue.charAt(i) == "-") {
            minus++;
        }
        if (strFieldValue.charAt(i) == "(") {
            lb++;
        }
        if (strFieldValue.charAt(i) == ")") {
            rb++;
        }


        var b = false;
            for (var j = 0; j < validChars.length; j++) {
               
                if (strFieldValue.charAt(i) == validChars[j]) {
                    b = true;
                }
            }
            if (b == false) {
                return false;
            }

    }
    if (plus > 1 || minus > 3 || lb > 1 || rb > 1) {

        return false;
    }
    return true;

}

