$(document).ready(function(){
	if($('#spComments').size() > 0){
		$('#spComments').after('<div id="textAreaCount">Characters: <span id="count">0</span> of '+strCommentsMaxLen+'</div><div id="textAreaErrMsg"></div>');
		$('#spComments').siblings('#textAreaCount').children('#count').html($('#spComments').val().length);
		$('#spComments').keyup(function(){
			$(this).siblings('#textAreaCount').children('#count').html($(this).val().length);
			if($('#spComments').val().length > strCommentsMaxLen){
				$('input[type=image]').unbind('click');
				$('input[type=image]').click(function(){
					alert('Please address the character limit in the Additional Comments field prior to submitting this form.');
					return false;
				});
				$(this).siblings('#textAreaErrMsg').css({ "display":"block"});
				$(this).siblings('#textAreaErrMsg').html('***You have exceeded the maximum allowable character input.  Please adjust accordingly.');
			}else{
				$('input[type=image]').unbind('click');
				$('input[type=image]').attr("disabled","");
				$(this).siblings('#textAreaErrMsg').css({ "display":"none"});
				$(this).siblings('#textAreaErrMsg').html('');
			}
		});
	}

});

///VALIDATION
function fIsText(strText){//VALIDATE TEXT.
	//alert(strText);
	var txt = /[a-z A-Z]/;
	if(txt.test(strText)){
		return true;
	} else{
		return false;
	}
}

function fVerifyEmail(strEmail) {//VALIDATE EMAIL
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	if (re.test(strEmail)) {
		return true;
	} else {
		return false;
	}
}

function fVerifyEmpty(strTxt){//VALIDATE Not empty
	if(strTxt == ""){
		return false;
	} else{
		return true;
	}
}

/*
Function to determine if it is a valid us zip code
@param aZip the zipcode to test
@param shouldAllowNineDigits a boolean which will pass a zipcode such as "06001-1234" if passed as true
*/
function fIsValidUsZip(aZip, shouldAllowNineDigits) {
	var objRegExp;
	var boolShouldAllowNineDigits = shouldAllowNineDigits;
	if(shouldAllowNineDigits == null || shouldAllowNineDigits == undefined) {
		boolShouldAllowNineDigits = true;	//	Allow nine digit format by default
	}
	if(boolShouldAllowNineDigits) {
		objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	} else {
		objRegExp = /(^\d{5}$)/;
	}
	//alert("objRegExp.test(\"" + aZip + "\") = " + objRegExp.test(aZip) + "\n");
	return objRegExp.test(aZip);
}

function checkEuroPhone(str)
{
	var phone2 = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
	if (str.match(phone2)) {
   		return true;
 	} else {
 		return false;
 	}
}


function fIsValidPhone(strP){//VALIDATE US CAN Phone
	var phoneUsCan = /^(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$/;
	if(phoneUsCan.test(strP)){
		return true;
	} else {
		return false;
	}

}

function fIsValideCheck(checkClass){//VALIDATE THAT at least one of is checked
	var strChecked = false;
		$('.'+checkClass).each(function(){
			if($(this).attr('checked')){
				strChecked = true;
			}
		});
		return strChecked;
}


function fIsValideDropDown(dropID){

	var drop = "";
	//alert(dropID);
		$(''+dropID+'').each(function(){
      drop =  $("OPTION:selected", this).val();
    });
    if(drop == ""){
    	return false;
    } else {
    	return true;
    }

}

function validUrl(strUrl){
	var pattern = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/;
	if(pattern.test(strUrl)){
		return true;
	}else {
		return false;
	}
}

