jQuery.fixPlaceHolder = function () {
    // Fallback for HTML5 PlaceHolder feature
    // Use placeholder for any textfield instead of writing js to swap out the text on focus
    if (!Modernizr.input.placeholder) {
        $("[placeholder]").each(function () {
            var $this = $(this);
            if ($this.attr("type") == "password") {
                $this.attr("realType", "password");
            }
        }).focus(function () {
            var $input = $(this);
            if ($input.val() == $input.attr("placeholder")) {
                if ($input.attr("realType") == "password") {
                    try {
                        $input.setAttribute("type", "password");
                    } catch (e) { }
                }
                $input.val("");
                $input.removeClass("placeholder");
            }
        }).blur(function () {
            var $input = $(this);
            if ($input.val() == "" || $input.val() == $input.attr("placeholder")) {
                if ($input.attr("realType") == "password") {
                    try {
                        $input.setAttribute("type", "text");
                    } catch (e) { //if we can't change the type, we need to create a copy and hide/show the different fields
                        var $next = $input.next();
                        if ($next.size() == 0 || $next.attr("isCopy") != "true") {
                            $next = $($input.clone().wrap("<div></div>").parent().html().replace("type=password", "type='text'"));
                            $next.attr("isCopy", "true");
                            $input.after($next);
                            $next.val($input.attr("placeholder"));
                            $next.focus(function () {
                                $input.show();
                                $next.hide();
                                $input.focus();
                            });
                        }
                        $input.hide();
                        $next.show();
                    }
                }
                $input.addClass("placeholder");
                $input.val($input.attr("placeholder"));
            }
        }).blur();
        $("[placeholder]").parents("form").submit(function () {
            $(this).find("[placeholder]").each(function () {
                var $input = $(this);
                if ($input.val() == $input.attr("placeholder")) {
                    $input.val("");
                }
                if ($input.attr("isCopy") == "true") {
                    $input.remove();
                }
                else {
                    $input.show();
                }
            })
        });
    }
};

jQuery.fn.equalHeight = function(resetHeights) {
	if (resetHeights == undefined) {
		resetHeights = false;
	}
	if (resetHeights) {
		this.height("auto");
	}
	var maxHeight = 0;
	this.each(function() {
		if ($(this).height() > maxHeight) {
			maxHeight = $(this).height();
		}
	});
	this.height(maxHeight);
};

jQuery.fn.center = function() {
	this.css("position", "absolute");
	this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
	this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
	return this;
}

jQuery.fn.equalMinHeight = function() {
	var maxHeight = 0;
	this.each(function() {
		if ($(this).height() > maxHeight) {
			maxHeight = $(this).height();
		}
	});
	if ($(".ie6,.ie7").length) {
		this.height(maxHeight);
	}
	else {
		this.css({ 'min-height': maxHeight });
	}
};

jQuery.fn.placeHolder = function () {
    var placeHolderValue = this.attr("data-placeHolder");
    if (placeHolderValue != "") {
        this.focus(function () {
            var $box = $(this);
            if ($box.val() == placeHolderValue) {
                $box.val("");
            }
        });
        this.blur(function () {
            var $box = $(this);
            if ($box.val() == "") {
                $box.val(placeHolderValue);
            }
        });
        this.val(placeHolderValue);
    }
};

// --- Regular expression to check target location of a link// Creating custom :external selector
$.expr[':'].external = function(obj) {
    try {
        return !obj.href.match(/^mailto\:/)
	        && !(obj.href.indexOf("javascript") == 0)
	        && !(obj.href == "#")
            && (obj.hostname != location.hostname);
    }
    catch (exception) {
	//if this runs on a hyperlink like <a href="http://address@server.com">address@server.com</a> it will throw this exception
        if (exception.message = "A security problem occurred.") {
            return false;
        }
        else {
            throw(exception);
        }
    }
};
