// jQuery Validation Scripts

$(document).ready(function() {
	// List the Form IDs for all forms that need to be validated
	$("#contactUs").validate();
	$("#esignup").validate();

	// phone validation - DO NOT CHANGE
	$.validator.addMethod("phone", function(phone_number, element) {
	var digits = "0123456789";
	var phoneNumberDelimiters = "()- ext.";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	var minDigitsInIPhoneNumber = 10;
	s=stripCharsInBag(phone_number,validWorldPhoneChars);
	return this.optional(element) || isInteger(s) && s.length >= minDigitsInIPhoneNumber;
	}, "Please enter a valid phone number");
	function isInteger(s)
	{ var i;
	for (i = 0; i < s.length; i++)
	{
	// Check that current character is number.
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
	}
	function stripCharsInBag(s, bag)
	{ var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{
	// Check that current character isn't whitespace.
	var c = s.charAt(i);
	if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
	}

	// default value validation - DO NOT CHANGE
	$.validator.addMethod("defaultInvalid", function(value, element) {
	if (this.value == '') {
	 return value != element.defaultValue;
	}
    return value != element.defaultValue;

}, "This field is required."); 

	$('input[type="text"]').focus(function() {
	    if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('input[type="text"]').blur(function() {
        if ($.trim(this.value) == ''){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}			
    });
	$('textarea').focus(function() {
	    if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('textarea').blur(function() {
        if ($.trim(this.value) == ''){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}			
    });
});	