
remove_default_values_on_blur = function(form_id_attribute){
	$(form_id_attribute).find('input[type=text]').focus(function() {
		if (this.value == this.defaultValue){
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$(form_id_attribute).find('input[type=text]').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
}

remove_default_values_on_submit = function(form_id_attribute){
	$(form_id_attribute).submit(function(){
		$(this).find('input[type=text]').each(function(){
			if (this.value == this.defaultValue){
				this.value = '';
			}
		});
	});
}

reset_default_values = function(form_id_attribute){
	$(form_id_attribute).find('input[type=text]').each(function() {
		if( this.value == ''){
			this.value = this.defaultValue;
		}
	});
}

element_check_toggle = function(input, container, animation){
	if ($(input).is(":checked")){
		$(container).each(function(){
			(animation) ?	$(this).show("fast") : $(this).show();
		});
	} else {
		$(container).each(function(){
			(animation) ?	$(this).hide("fast") : $(this).hide();
			$(this).find("input[type=text]").val('');
			$(this).find("input[type=checkbox]").attr('checked', false);
			$(this).find("input[type=radio]").attr('checked', false);
			$(this).find("textarea").val('');
		});
	}
}

element_regex_toggle = function(input, container, regex, animation){
	if( regex.test($(input).val()) ){
		$(container).each(function(){
			(animation) ?	$(this).show("fast") : $(this).show();
		});
	} else {
		$(container).each(function(){
			(animation) ?	$(this).hide("fast") : $(this).hide();
			$(this).find("input[type=text]").val('');
			$(this).find("input[type=checkbox]").attr('checked', false);
			$(this).find("input[type=radio]").attr('checked', false);
			$(this).find("textarea").val('');
		});
	}
}

valid_ssn_or_cin = function(nr){
	if( /^\d{6}-?\d{4}$/.test(nr) ) {
		nr = nr.replace("-", "");
		if( nr.length == 10 ){
			l = "";
			n = 0;
			for( i = 0 ; i<nr.length-1 ; i++ ) {
				l += (nr.substr(i, 1)* ( ((i%2)==0) ? 2 : 1  ) );
			}
			for( i = 0 ; i<l.length ; i++) {
				n = n + parseInt(l.substr(i, 1));
			}
			if( n%10==0 ) {
				return ( nr.substr(9, 1) == (n%10) ) ? true : false; 
			} else {
				return ( nr.substr(9, 1) == (10-(n%10)) ) ? true : false; 
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}