﻿var m_strDefaultNameValue = '';
var m_strDefaultPhoneValue = '';
$(document).ready(function () {
    var m_strDefaultSearchValue = $('#SearchInput').val();
    $('#SearchInput').focus(function () {
        if (this.value == m_strDefaultSearchValue) {
            this.value = '';
        }
        this.style.color = '#000000';
    });
    $('#SearchInput').blur(function () {
        if (this.value == '') {
            this.value = m_strDefaultSearchValue;
        }
        this.style.color = '';
    });
    m_strDefaultNameValue = $('#tbCallMeName').val();
    m_strDefaultPhoneValue = $('#tbCallMePhone').val();
    $('#tbCallMeName').focus(function () {
        if (this.value == m_strDefaultNameValue) {
            this.value = '';
        }
        this.style.color = '#000000';
    });
    $('#tbCallMeName').blur(function () {
        if (this.value == '') {
            this.value = m_strDefaultNameValue;
        }
        this.style.color = '';
    });
    $('#tbCallMePhone').focus(function () {
        if (this.value == m_strDefaultPhoneValue) {
            this.value = '';
        }
        this.style.color = '#000000';
    });
    $('#tbCallMePhone').blur(function () {
        if (this.value == '') {
            this.value = m_strDefaultPhoneValue;
        }
        this.style.color = '';
    });
});

function ShowContainer(p_strId) {
    if ($('#' + p_strId).height() == '0') {
        var intHeight = Math.abs($('#' + p_strId + 'Inner').height()) + 170;
        $('#' + p_strId).animate({ height: intHeight + "px" }, 800);
        $('#' + p_strId).fadeTo(800, 1);
    } else {
        $('#' + p_strId).fadeTo(800, 0);
        $('#' + p_strId).animate({ height: "0px" }, 800);
    }
}

function CheckCallMeBack() {
    var l_blnReturn = true;

    $('#divCallMeNameStart').attr('class', 'divTextBoxStart');
    $('#divCallMeNameEnd').attr('class', 'divTextBoxEnd');
    $('#divCallMePhoneStart').attr('class', 'divTextBoxStart');
    $('#divCallMePhoneEnd').attr('class', 'divTextBoxEnd');
    
    if ($.trim($("#tbCallMeName").val()).length < 2 || $.trim($("#tbCallMeName").val()) == m_strDefaultNameValue) {
        l_blnReturn = false;
        $('#divCallMeNameStart').attr('class', 'divTextBoxStartError');
        $('#divCallMeNameEnd').attr('class', 'divTextBoxEndError');
    }

    if ($.trim($("#tbCallMePhone").val()).length < 10 || $.trim($("#tbCallMePhone").val()) == m_strDefaultPhoneValue) {
        l_blnReturn = false;
        $('#divCallMePhoneStart').attr('class', 'divTextBoxStartError');
        $('#divCallMePhoneEnd').attr('class', 'divTextBoxEndError');
    }
    if (l_blnReturn) {
        $("#btnShowCallMeBack").removeAttr("onclick");
        var l_strResult = $.ajax({
            url: "/Ajax/CallMeBack.aspx?Name=" + $("#tbCallMeName").val() + "&Phone=" + $("#tbCallMePhone").val(),
            type: "GET",
            dataType: "html",
            async: false
        }).responseText;
        if (l_strResult == "OK") {
            $("#divCallMeBack").fadeTo(800, 0);
            $("#divCallMeBackResponse").css("display", "block");
            $("#divCallMeBackResponse").fadeTo(800, 1);
        } else {
            $("#divCallMeBack").fadeTo(800, 0);
            $("#divCallMeBackResponse").css("display", "block");
            $("#divCallMeBackResponse").fadeTo(800, 1);
            $("#divCallMeBackResponse").html(l_strResult);
        }
    }
}

function HideCallMeBackResponse() {
    $("#divCallMeBackResponse").fadeTo(800, 0);
    $("#divCallMeBack").animate({ height: "0px" }, 800);
    //$("#divCallMeBackResponse").animate({ height: "0px" }, 800);
    setTimeout('$("#divCallMeBackResponse").remove(); $("#divCallMeBack").remove();', 1000);
}

function SubmitOnEnter(myfield, e, p_strId) {
    var keycode;
    if (window.event) { keycode = window.event.keyCode; }
    else if (e) { keycode = e.which; }
    else { return true; }

    if (keycode == 13) {
        document.getElementById(p_strId).click();
    }
}

function SubmitForm(p_strId) {
    document.getElementById(p_strId).submit();
    return false;
}
