
//
// Function for InitialFOrmatNumberInputs
//
function Initialformatnumberinputs() {
    var numberinputs = $(".numberFormat");
    numberinputs.blur(function() {

        var temp = $(this).val();
        if ((isNaN(temp)) || (temp.indexOf(".") != -1) || (temp.indexOf("-") != -1))
            return false
        if (temp.length > 0) {
            $(this).format({ format: "#,###" });
        }
    });
    numberinputs.focus(function() {
        var temp = $(this).val();
        var tempValue = temp.replace(/,/g, "");
        if ((isNaN(tempValue)) || (tempValue.indexOf(".") != -1) || (tempValue.indexOf("-") != -1))
            return false;
        if (temp.length > 0) {
            $(this).val($(this).parse());
        }

    });
}




//
// Function for Initialtelephonenumberinputs
//
function Initialtelephonenumberinputs() {
    $(".phonenumber").mask("(999) 999-9999", { placeholder: "#" });
}

//-------------------------------------------------------------
// form field hints: initialize hints
//-------------------------------------------------------------
$(document).ready(function() {
    $('input[type="text"], input[type="password"], textarea, select').addClass("idle");
    $('input[type="text"], input[type="password"], textarea, select').focus(function() {
        $(this).removeClass("idle").addClass("focused");
        if ($(this).parent().children(".errors")) {
            $(this).parent().children(".errors").hide();
        }
        if ($(this).parent().children(".ihint")) {
            $(this).parent().children(".ihint").show();
        }
        if (this.value != this.defaultValue) {
            // this.select();  
        }
    });
    $('input[type="text"], input[type="password"], textarea, select, a[class="term"]').blur(function() {
        $(this).removeClass("focused").addClass("idle");
        if ($(this).parent().children(".errors")) {
            $(this).parent().children(".errors").hide();
        }
        if ($(this).parent().children(".ihint")) {
            $(this).parent().children(".ihint").hide();
        }
        if (this.value && $.trim(this.value == '')) {
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });

    //-------------------------------------------------------------
    // special terms: initialize terms
    // adds event on hover
    //-------------------------------------------------------------
    $('span[class="term"]').hover(function() {
        $(this).removeClass("idle").addClass("focused");
        if ($(this).parent().children(".ihint")) {
            $(this).parent().children(".ihint").show();
        } 
    }, function() {
        $(this).removeClass("focused").addClass("idle");
        if ($(this).parent().children(".ihint")) {
            $(this).parent().children(".ihint").hide();
        }
    });



});


$(document).ready(function() {
    $("#dialog").dialog({
        bgiframe: false,
        autoOpen: false,
        modal: true,
        width: 350,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
                $("#ifKeepSession").attr("src", $("#WebSiteURL").val() + "Probe.aspx?timestamp=" + new Date()); //TryKeepSessionState
            }
        }
    });
});
