﻿
Websajt.Form.GlobalActions = function() {

	/*
	---------------------------------------------
	Adds a class name on all types of input boxes
	when the user have that field focused.
	---------------------------------------------
	*/
	$('input[type=text],input[type=password],textarea').focus(function() {
		$(this).addClass("focus");
	});

	$('input[type=text],input[type=password],textarea').blur(function() {
		$(this).removeClass("focus");
	});

	/*
	---------------------------------------------
	Watermark on all input forms that have rel
	"watermark"
	---------------------------------------------
	*/
	$('input[rel=watermark]').focus(function() {
	if ($(this).val() == this.defaultValue)
			$(this).val('');
		else if ($(this).val() == '')
			$(this).val(this.defaultValue);
	});

	$('input[rel=watermark]').blur(function() {
		if ($(this).val() == this.defaultValue)
			$(this).val('');
		else if ($(this).val() == '')
			$(this).val(this.defaultValue);
    });

    /*
    ---------------------------------------------
    Prevents auto submit with "enter".
    ---------------------------------------------
    */
    $("input").keypress(function(e) {
        try {
            if (e.keyCode == 13) {
                e.returnValue = false;
                e.cancel = true;
                e.preventDefault();
                e.stopPropagation();
            }
        }
        catch (exp) { }
    });

    /*
    ---------------------------------------------
    If user hits enter this function simulates 
    a button click.
    ---------------------------------------------
    */
    $('#txtSearchProduct').keypress(function(e) {
        if (e.keyCode == 13) {
            $('#btnSearchProduct').click();
            return false;
        }
    });

    $('#txtPassword').keypress(function(e) {
        if (e.keyCode == 13) {
            $('#btnLogin').click();
            return false;
        }
    });


}