﻿$(function() {
    //    $(window).scroll(function() {
    //        var dTop = $(document).scrollTop();
    //        var topOffset = "0px";
    //        topOffset = (dTop - 130) + "px";
    //        $(".order_wrap").animate({ top: topOffset }, { duration: 500, queue: false, complete: function() { } });
//    });
$("input[id$=tbPhone]").bind("keyup", function() {
    if (this.value.length > 20) {
        this.value = this.value.substring(0, this.value.length - (this.value.length - 20));
    }
    var reg = /[^0-9-() +]/;
    if (this.value.match(reg)) {
        this.value = this.value.toLowerCase().replaceAll(reg, "");
    }
});
$("input[id$=tbPhone]").bind("blur", function() {
    if (this.value.length > 20) {
        this.value = this.value.substring(0, this.value.length - (this.value.length - 20));
    }
    var reg = /[^0-9-() +]/;
    if (this.value.match(reg)) {
        this.value = this.value.toLowerCase().replaceAll(reg, "");
    }
});

    $("input[id$=btnSubmit]").click(function() {
        var hasErrors = false;
        $("input[id$=tbName]").removeClass("errBorder");
        $("input[id$=tbPhone]").removeClass("errBorder");
        $("input[id$=tbAddress]").removeClass("errBorder");
        if ($("input[id$=tbName]").val().replaceAll(" ", "") == "") {
            $("input[id$=tbName]").addClass("errBorder");
            hasErrors = true;
        }
        if ($("input[id$=tbPhone]").val().replaceAll(" ", "") == "") {
            $("input[id$=tbPhone]").addClass("errBorder");
            hasErrors = true;
        }
        if ($("input[id$=tbAddress]").val().replaceAll(" ", "") == "") {
            $("input[id$=tbAddress]").addClass("errBorder");
            hasErrors = true;
        }

        if (hasErrors) {
            return false;
        }
    });


    $("#buy_button").click(function() {        
        $("body").append("<iframe id='TB_HideSelect'></iframe>");
        $('#TB_HideSelect').hide();
        $('#TB_HideSelect').show();
        $('.order_wrap').show();        
        return false;
    });
    $("#aClose").click(function() {
        $("#TB_HideSelect").remove();
        $('.order_wrap').hide();
        return false;        
    });
});

String.prototype.replaceAll = function(search, replace) {
    return this.split(search).join(replace);
}
