/// <reference path="jquery-1.3.2-vsdoc2.js" />
function SetRollOvers(){
	// usage: add the class 'rollover' to image elements
	jQuery("input[type=image].rollover, a.rollover img, img.rollover").hover(function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/(\.[^.]+)$/, 'Hi$1'));
	    },function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/Hi(\.[^.]+)$/, '$1'));
	});
}

function SetEnterSubmit(){
	// usage: add the class 'submit-on-enter' to any element
	$(".submit-on-enter input[type=text], .submit-on-enter textarea").keydown(function(ev){
        //$(".submit-on-enter").append(ev.keyCode);
        if(ev.keyCode == 13)
        {
            ev.preventDefault();
            ev.stopPropagation();
             //$(".submit-on-enter").append("==submitting");    
             $(this).parents(".submit-on-enter").children("input[type=image], input[type=button]").click();
             return false;
        }
    });
}

function SetExternalLinks(){
	/* Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window */
	$('a[rel=external]').click(function() { window.open(this.href); return false; });
}
/*
// Plugin to put tips into input boxes.
// author: http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
jQuery.fn.hint = function() {
    return this.each(function() {
        // get jQuery version of 'this'
        var t = jQuery(this);
        // get it once since it won't change
        var title = t.attr('title');
        // only apply logic if the element has the attribute
        if (title) {
            // on blur, set value to title attr if text is blank
            t.blur(function() {
                if (t.val() == '') {
                    t.val(title);
                    t.addClass('blur');
                }
            });
            // on focus, set value to blank if current value 
            // matches title attr
            t.focus(function() {
                if (t.val() == title) {
                    t.val('');
                    t.removeClass('blur');
                }
            });

            // clear the pre-defined text when form is submitted
            t.parents('form:first()').submit(function() {
                if (t.val() == title) {
                    t.val('');
                    t.removeClass('blur');
                }
            });

            // now change all inputs to title
            t.blur();
        }
    });
   }
*/
// Version 1.0 - October 19, 2007
// Requires http://jquery.com version 1.2.1
// usage example:  $(".clickable").biggerlink();
(function($) { $.fn.biggerlink = function(a) { var b = { hoverclass: 'hover', clickableclass: 'hot', follow: true }; if (a) { $.extend(b, a) } $(this).filter(function() { return $('a', this).length > 0 }).addClass(b.clickableclass).each(function(i) { $(this).attr('title', $('a[title]:first', this).attr('title')); $(this).mouseover(function() { window.status = $('a:first', this).attr('href'); $(this).addClass(b.hoverclass) }).mouseout(function() { window.status = ''; $(this).removeClass(b.hoverclass) }).bind('click', function() { $(this).find('a:first').trigger('click') }).find('a').bind('focus', function() { $(this).parents('.' + b.clickableclass).addClass(b.hoverclass) }).bind('blur', function() { $(this).parents('.' + b.clickableclass).removeClass(b.hoverclass) }).end().find('a:first').bind('click', function(e) { if (b.follow == true) { window.location = this.href } e.stopPropagation() }).end().find('a', this).not(':first').bind('click', function() { $(this).parents('.' + b.clickableclass).find('a:first').trigger('click'); return false }) }); return this } })(jQuery);

/***** Password Strength *********************************************/
// Password strength meter and match verifier http://www.thecreativeoutfit.com

jQuery.fn.passroids = function(o) {
	var o = jQuery.extend({ main: '#password', verify: null, button: null, minimum: 0 }, o); jQuery(o.main).after('<div id="psr-score"></div>'); if (o.verify != null) { jQuery(o.verify).after('<div id="psr-verify"></div>'); }
	if (o.button != null) { jQuery(o.button).parent().append('<div id="psr-strength-notice"></div>'); }
	//if (o.button != null) { jQuery(o.button).attr('disabled', 'true'); }
	function testPass(v) {
		var s = 0
		if (v.length < 5) { s = (s + 3); }
		else if (v.length > 4 && v.length < 8) { s = (s + 10); }
		else if (v.length > 7 && v.length < 16) { s = (s + 12); }
		else if (v.length > 15) { s = (s + 18); }
		if (v.match(/[a-z]/)) { s = (s + 1); }
		if (v.match(/[A-Z]/)) { s = (s + 5); }
		if (v.match(/\d+/)) { s = (s + 5); }
		if (v.match(/(.*[0-9].*[0-9].*[0-9])/)) { s = (s + 5); }
		if (v.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) { s = (s + 5); }
		if (v.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { s = (s + 5); }
		if (v.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { s = (s + 4); }
		if (v.match(/([a-zA-Z])/) && v.match(/([0-9])/)) { s = (s + 4); }
		if (v.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) { s = (s + 7); }
		return s;
	}
	function evalScore(s) {
		var strength = 0; switch (true) { case s <= 13: strength = 0; break; case s >= 14 && s <= 27: strength = 1; break; case s >= 28 && s <= 40: strength = 2; break; case s >= 41: strength = 3; break; }
		return strength;
	}
	function changeButtonState(v) {
		var val = jQuery(o.main).val(); var s = testPass(val); var strength = evalScore(s); if (o.button != null) {
			if (v == 1 && strength >= o.minimum) { jQuery(o.button).attr('disabled', ''); jQuery('#psr-strength-notice').html(''); }
			else { jQuery(o.button).attr('disabled', 'true'); if (strength < o.minimum) { jQuery('#psr-strength-notice').html('<span class="field-error">Please choose a stronger password.</span>') } }
		}
	}
	return this.each(function() {
		jQuery(o.main).keyup(function() {
			var val = jQuery(o.main).val(); var s = 0; if (val != '') { var s = testPass(val); }
			var levels = new Array(); levels[0] = "Weak"; levels[1] = "Medium"; levels[2] = "Strong"; levels[3] = "Excellent"; var strength = evalScore(s); jQuery('#psr-score').html('<p class=psr-' + levels[strength].toLowerCase() + '>Password strength: <span class="psr-level">' + levels[strength] + '</span><span class="psr-bar"></span></p>');
		}); if (o.verify != null) { jQuery(o.verify).keyup(function() { var main = jQuery(o.main).val(); var verify = jQuery(o.verify).val(); if (main == verify) { jQuery('#psr-verify').html(''); changeButtonState(1); } }); jQuery(o.verify).blur(function() { var main = jQuery(o.main).val(); var verify = jQuery(o.verify).val(); if (main != verify) { jQuery('#psr-verify').html('<span class="field-error">Passwords do not match</span>'); changeButtonState(0); } }); }
	});
};

/***** / Password Strength ******************************************/
