function validate_name(name, is_blank)
{
	var the_exp = /[^a-zA-Z'\-\. ]+/;
	if(is_blank == 0 || (is_blank == 1 && name != ""))
	{
		if(the_exp.test(name) || name == "")
		{
			return false;
		}
	}
	return true;
}
         
function validate_company(company, is_blank)
{
	var the_exp = /[^a-zA-Z0-9'\- ]+/;
	if(is_blank == 0 || (is_blank == 1 && company != ""))
	{
		if(the_exp.test(company) || company == "")
		{
			return false;				
		}
	}
	return true;
}

function validate_address(address, is_blank)
{
	var the_exp = /[^a-zA-Z0-9'\-\. ]+/;
	if(is_blank == 0 || (is_blank == 1 && address != ''))
	{
		if(the_exp.test(address) || address == '')
		{
			return false;				
		}
	}
	return true;
}

/* 
 * Modified by Steve Woodson on 7-12-2011 to valdate entered zipcodes to selected states
 * 
 * Use the new function 'validate_zip' below if the state isn't sent with the function 
 * call (old manual forms gneerally) and 'validate_zipstate' if it is sent (form builder 
 * forms). If state doesn't exist or is empty it will send an empty variable.
 * The commented 'validate_zip' function below is what was replaced on 7-12-2011
 */
 
/* 
	function validate_zip(zip, is_blank)
	{
		var the_exp = /^\d{5}$|^\d{5}-\d{4}$/;
		if(is_blank == 0 || (is_blank == 1 && zip != ""))
		{
			if(!the_exp.test(zip))
			{
				return false;				
			}
		}
		return true;
	}
 */

function validate_zip(zip, is_blank)
{	
	if (typeof jQuery != 'undefined') {
		if ( $('#state').val() != "" )
		{	var state = $('#state').val();	}
		else if ( $('#State').val() != "" )
		{	var state = $('#State').val();	}
		else
		{	var state = "";	}
	}
	else
	{	var state = "";	}
		
	return validate_zipstate(zip, state, is_blank);
}

function validate_zipstate(zip, state, is_blank)
{	
	var the_exp = /^\d{5}$|^\d{5}-\d{4}$/;
	//var the_exp_state = /^[a-zA-Z]{2}$/;
	if(is_blank == 0 || (is_blank == 1 && zip != ""))
	{
		if(!the_exp.test(zip))
		{	return false;	}
		if( state != "" )
		{	var response = ""
			$.ajax({
				type: "POST",
				dataType: "text",
				async: false,
				url: "/server_calls/colleges/get_zipcode_state_validation.php",
				data: "zip=" + zip + "&state=" + state,
				success: function(data) {
					response = data;
				}
			});	
			
			if ( response !== '1' )
			{	alert( "The provided zipcode " + zip + " does not belong in " + state );
				return false;	}
			else {	return true;	}
		}
		else {	return true;	}
	}
	else {	return true;	}
}

function validate_email(email, is_blank)
{
	var the_exp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
	if(is_blank == 0 || (is_blank == 1 && email != ""))
	{
		if(!the_exp.test(email) || email == "")
		{
			return false;				
		}
	}
	return true;
}

function validate_phone(phone, is_blank)
{
	var the_exp = /^\D?([2-9]{1}\d{2})\D?\D?(\d{3})\D?(\d{4})$/;

	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				
		}
	}
	return true;
}

function validate_area_code(phone, is_blank)
{
	var the_exp = /^[2-9][0-9]{2}/;
	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				
		}
	}
	return true;
}

function validate_phone_area_code(phone, is_blank)
{
	var the_exp = /^[2-9][0-9]{2}/;
	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				
		}
	}
	return true;
}

function validate_phone_prefix(phone, is_blank)
{
	var the_exp = /^[2-9][0-9]{2}/;
	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				
		}
	}
	return true;
}

function validate_phone_suffix(phone, is_blank)
{
	var the_exp = /^[0-9]{4}/;
	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				 
		}
	}
	return true;
}

function validate_short_phone(phone, is_blank)
{
	var the_exp = /^[2-9][0-9]{2}[ -]{0,1}[0-9]{4}/;
	if(is_blank == 0 || (is_blank == 1 && phone != ""))
	{
		if(!the_exp.test(phone))
		{
			return false;				
		}
	}
	return true;
}

function validate_date(date, is_blank)
{
	var the_exp = /^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])/;
	if(is_blank == 0 || (is_blank == 1 && date != ""))
	{
		if(!the_exp.test(date))
		{
			return false;				
		}
	}
	return true;
}

function validate_gpa(gpa, is_blank)
{
	var the_exp = /^[0]|[0-3]\.(\d?\d?)|[4].[0]$/;
	if(is_blank == 0 || (is_blank == 1 && gpa != ""))
	{
		if(!the_exp.test(gpa))
		{
			return false;				
		}
	}
	return true;
}


function validate_act(act, is_blank)
{
	var the_exp = /^([0-9]{1})$|^([1]{1}[0-9]{1})$|^([2]{1}[0-9]{1})$|^([3]{1}[0-6]{1})$/;
	if(is_blank == 0 || (is_blank == 1 && act != ""))
	{
		if(!the_exp.test(act))
		{
			return false;				
		}
	}
	return true;
}

function valildate_sat(sat, is_blank)
{
	var the_exp = /^[4-9]{1}\d{2}$|^[1-2]{1}\d{3}$/;
	if(is_blank == 0 || (is_blank == 1 && sat != ""))
	{
		if(!the_exp.test(sat))
		{
			return false;				
		}
	}
	return true;
}
