// SETUP FORMS
$(document).ready(function(){
    $('.labelinside').each(function(i){
        if ( $(this).val().length == 0 ) {                    
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }
    });
    
    $('.labelinside').focus(function(e){
        if ( $(this).val() == $(this).attr('title') ) {
            $(this).val('');
            $(this).removeClass("default");
        }                
    });
    
    $('.labelinside').blur(function(e){
        if ( $(this).val() == '' ) {
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }             
    });
});

function FormHelper(selector) {
     $(selector + ' .labelinside').each(function(i){
        if ( $(this).val().length == 0 ) {                    
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }
    });
    
    $(selector + ' .labelinside').focus(function(e){
        if ( $(this).val() == $(this).attr('title') ) {
            $(this).val('');
            $(this).removeClass("default");
        }                
    });
    
    $(selector + ' .labelinside').blur(function(e){
        if ( $(this).val() == '' ) {
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }             
    });   
}

function is_valid_email(email) {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   
	   return reg.test(email);
	}

	function is_valid_zipcode(zipcode) {  
	    var reg = /^([0-9]{5})$/;
	    
	    return reg.test(zipcode); 
	}

	function is_empty(val) {
		val = jQuery.trim(val);
		if ( val.length == 0 ) {
			return true;
		}
		return false;
	}

	function is_valid_phonenumber(phonenumber) {
	    var trimmed = phonenumber.replace(/[^0-9]/g,'');
		var firstthree = phonenumber.substr(0,3);
		var firstnumber = phonenumber.substr(0,1);
		var secondthree = phonenumber.substr(3,3);
		var lasteight = phonenumber.substr(3,7);
		var completeflush = phonenumber.substr(0,10);
	    if ( trimmed.length != 10 ) {
	        return false;
		}
		if ( firstthree == '888' || firstthree == '887' || firstthree == '886' || firstthree == '883' || firstthree == '881' || firstthree == '877' || firstthree == '866' || firstthree == '800' || firstthree == '900' || firstthree == '555' ) {
			return false;
		}
		if ( secondthree == '555' ) {
			return false;
		}
		if ( lasteight == '8675309' ) {
			return false;
		}
		if ( firstnumber == '1' || firstnumber == '0' ) {
			return false;
		}
		if ( completeflush == '0000000000' || completeflush == '1111111111' || completeflush == '2222222222' || completeflush == '3333333333' || completeflush == '4444444444' || completeflush == '5555555555' || completeflush == '6666666666' || completeflush == '7777777777' || completeflush == '8888888888' || completeflush == '9999999999' ) {
			return false;
		}
		
		return true;
	}

	function is_valid_ssn(ssn) {
	    var reg = /^([0-9]{3})-([0-9]{2})-([0-9]{4})$/;
	    
	    return reg.test(ssn);
	}
