function strltrim() 
{
    //Match spaces at beginning of text and replace with a null string
    return this.replace(/^\s+/,'');
}
function strrtrim() 
{
    //Match spaces at end of text and replace with a null string
    return this.replace(/\s+$/,'');
}
function strtrim() 
{
	//Match spaces at beginning and end of text and replace
	//with null strings
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
function boolIsEmail() {
if (this.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
else
    return false;
}
function boolIsPhone() {
if( this.match(/[^0-9\s().-]+/g) )
	return false;
else
	return true;
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;
String.prototype.isEmail = boolIsEmail;
String.prototype.isPhone = boolIsPhone;

function cleanTextField( value )
{
	value = value.trim();
	value = value.replace(/[<>]+/g,'');
	return value;
}

function cleanInput( obj )
{
	obj.value = cleanTextField(obj.value);
}

function cleanTextarea512( value )
{
	value = cleanTextField(value);
	if( value.length > 512 )
		value = value.substring(0,512);
	return value;
}

function checkGroup(inputName, length)
{
	for( var i=1; i<=length; i++ )
	{
		if( document.getElementById(inputName+"_"+i).checked )
			return true;
	}
	return false;
}

function isCleanedBlank( value )
{
	return (value == "");
}

function isBlank( obj )
{
	obj.value = cleanTextField( obj.value );
	return (obj.value == "");
}

function AdditionalFormField()
{
	var name = null;
	var text = null;
	var type = null;
}

function checkRegistrationFormByIDs(formObjs, boolAlertErrorMsg)
{
	var errors = "";
	var reqMsg = " is a required field\n\r";
	var invalidMsg = " is not a valid format\n\r";
	//var form = document.getElementById(formId);
	
	//var topic = document.getElementById(containerId + "_ddlTopics");
	//if (topic.options[topic.selectedIndex].value == "")
		//errors += "Topic" + reqMsg;
	
	if( isBlank(document.getElementById(formObjs.vetFirstName)) )
		errors += "First Name" + reqMsg;

	if( isBlank(document.getElementById(formObjs.vetLastName)) )
		errors += "Last Name" + reqMsg;
		
	var vetProffession = document.getElementById(formObjs.vetProffession);
	if( vetProffession.options[vetProffession.selectedIndex].value == "" )
		errors += "Profession" + reqMsg;
		
	//cleanInput(document.getElementById(containerId+"_rfdDegree"));
	//cleanInput(document.getElementById(containerId+"_rfdTitle"));
	
	if( isBlank(document.getElementById(formObjs.vetPrimaryAffiliation)) )
		errors += "Primary Affiliation" + reqMsg;
			
	var vetSpecialty = document.getElementById(formObjs.vetSpecialty);
	if( vetSpecialty.options[vetSpecialty.selectedIndex].value == "" || vetSpecialty.options[vetSpecialty.selectedIndex].value == "0")
		errors += "Specialty" + reqMsg;
				
	if( isBlank(document.getElementById(formObjs.vetAddress1)) )
		errors += "Primary Affiliation Address 1" + reqMsg;
		
	cleanInput(document.getElementById(formObjs.vetAddress1));
		
	if( isBlank(document.getElementById(formObjs.vetCity)) )
		errors += "Affiliation City" + reqMsg;

    var vetStates = document.getElementById(formObjs.vetState);
	if( vetStates.options[vetStates.selectedIndex].value == "" )
		errors += "Affiliation State" + reqMsg;		
		
	if( isBlank(document.getElementById(formObjs.vetZipcode)) )
		errors += "Affiliation Zip Code" + reqMsg;
		
	var vetCountry = document.getElementById(formObjs.vetCountry);
	if( vetCountry.options[vetCountry.selectedIndex].value == "" )
		errors += "Country" + reqMsg;
		
	//if( isBlank(document.getElementById(containerId+"_rfdPhone")) )
	//	errors += "Phone" + reqMsg;
	//else if( !document.getElementById(containerId+"_rfdPhone").value.isPhone() )
	//	errors += "Phone" + invalidMsg;
		
	cleanInput(document.getElementById(formObjs.vetFax ));
	if( !document.getElementById(formObjs.vetFax).value.isPhone() )
		errors += "Fax" + invalidMsg;
		
	if( isBlank(document.getElementById(formObjs.vetEmail)) )
		errors += "E-mail" + reqMsg;
	else if( !document.getElementById(formObjs.vetEmail).value.isEmail() )
	    errors += "E-mail" + invalidMsg;

	if ($(formObjs.checkboxSendSMS).is(':checked')) {
	    if (isBlank(document.getElementById(formObjs.vetMobilePhone)))
	        errors += "Mobile Phone" + reqMsg;
	}
	if ($(formObjs.checkboxAllCorrect).length > 0) {
	    if (!$(formObjs.checkboxAllCorrect).is(':checked')) {
	        errors += "All this information is correct" + reqMsg;
	    }
	}

	if( boolAlertErrorMsg == true )
	{
		if( errors != "" )
		{
			alert("Please correct the following errors:\n\r\n\r" + errors);
			return false;
		}
		else
		{
			return true;
		}
	}
	else return errors;		
}




