// forgot password validation
function ValidateForgotPassword(){
	var x = document.ForgotPassword;
	
	if (!(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(x.email.value))){
		alert('Please enter the valid email address used to sign up.');
		x.email.focus();
		return false;
	}
}

<!-- Takes three parameters: this, 'focus' or 'blur', 'default field value' -->
function SwapFocus(obj, state, msg){
	if(state == 'focus'){
		if(obj.value == msg){
			obj.value = '';
		}
	} else if(state == 'blur') {
		if(obj.value == ''){
			obj.value = msg;
		}
	}
}

/*
	Search Functions
	These are here for previous version compatability. 
*/

<!-- Takes five parameters: 'name of form being submitted', 'name of input with search text', 'base action url', 'default input field value', 'the value of the input field (F U IE)' -->
function ValidateSearch(formName, inputName, url, msg, theVal) {
	var x = document.getElementById(formName);
	var y = document.getElementById(inputName);
	
	if(theVal == "" || theVal == msg) {
		y.value = "";
		y.focus();
		return false;
	} else if(theVal.length < 4) {
		alert('Search terms must be at least 4 characters long.');
		y.focus();
		return false;
	} else {
		x.action = url + '/' + inputName + '/' + theVal + '/';
		return true;
	}
}

<!-- Takes five parameters: 'name of form being submitted', 'name of input with search text', 'base action url', 'default input field value', 'the value of the input field (F U IE)' -->
function ValidatePESearch(formName, inputName, url, msg, theVal) {
	var x = document.getElementById(formName);
	var y = document.getElementById(inputName);
	
	if(theVal == "" || theVal == msg) {
		y.value = "";
		y.focus();
		return false;
	} else if(theVal.length < 4) {
		alert('Search terms must be at least 4 characters long.');
		y.focus();
		return false;
	} else {
		x.action = url + '/' + inputName + '/' + theVal + '/';
		return true;
	}
}


<!-- Takes six parameters: 'name of for being submitted', 'name of element to update to', 'name of input with search text', 'base action url', 'default input field value', 'detail attribute' -->
function ClassesSearch(formName, toUpdate, inputName, url, msg, detail, theVal) {
	var x = document.getElementById(formName);
	var y = document.getElementById(inputName);
	
	if(theVal == "" || theVal == msg) {
		y.value = "";
		y.focus();
		return false;
	} else if(theVal.length < 4) {
		alert('Search terms must be at least 4 characters long.');
		y.focus();
		return false;
	} else {
		var theAction = url + '/' + inputName + '/' + theVal + '/Update/' + toUpdate + '/Detail/' + detail + '/';
		 
		new Ajax(theAction, {
			method: 'get',
			update: $(toUpdate)
		}).request();
		
		return false;
	}
}

window.addEvent( 'load', function(){
	
	if( $('id_username') ) 
	{
		$('id_username').addEvent( 'focus', function(){ 
			$('id_username').style.border = '2px solid #db683f';
		});
		$('id_username').addEvent( 'blur', function(){
			if( $('content_right') )
				$('id_username').style.border = '1px solid #db683f';
			else
				$('id_username').style.border = 'none';
		});
	}
	if( $('id_password') )
	{
		$('id_password').addEvent( 'focus', function(){ 
			$('id_password').style.border = '2px solid #db683f';
		});
		$('id_password').addEvent( 'blur', function(){
			if( $('content_right') )
				$('id_password').style.border = '1px solid #db683f';
			else
				$('id_password').style.border = 'none';
		});
	}
	
});
								  

function validateFindListing() {
	if($('retailer_zip').value == "") {
		alert('Please enter the 5 digit zip code for your retail location.');
		$('retailer_zip').focus();
	} else {		
		$('parent_register').submit();
	}	
}

function validateClaimListing() {
	var x = document.parent_register;

	if(x.company_name.value==""){
		alert('Please enter the name of your company.');
		x.company_name.focus();
	} else if(x.first_name.value=="") {
		alert('Please enter your first name.');
		x.last_name.focus();
	} else if(x.last_name.value=="") {
		alert('Please enter your last name.');
		x.last_name.focus();
	} else if(!(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(x.email.value))){
		alert('Please enter a valid email address.');
		x.email.focus();
	} else if(x.email.value != x.email_confirm.value ) {
		alert('The e-mail address you entered does not match the confirmation e-mail address.');
		x.email_confirm.focus();
	} else if(x.phone.value=="") {
		alert('Please enter your business telephone number.');
		x.phone.focus();
	} else if(x.address.value=="") {
		alert('Please enter your business address.');
		x.address.focus();
	} else if(x.city.value=="") {
		alert('Please enter your business city.');
		x.city.focus();
	} else if(x.state.value=="") {
		alert('Please enter your business state.');
		x.state.focus();
	} else if(x.zip_postal_code.value == "") {
		alert('Please enter your business 5 digit postal zip code.');
		x.zip_postal_code.focus();
	/*
	} else if(x.description.value == "") {
		alert('Please enter a brief description about your business.');
		x.description.focus();
	*/
	} else {
		x.submit();
	}
}

function ValidateVerificationEmail() {
	x = document.verification_email;
	
	if(!(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(x.UserEM.value))){
		alert('Please enter a valid email address.');
		x.UserEM.focus();
	}
	else
		x.submit();
}

function validateUpgradeListing() {
	var x = document.parent_register;
	
	x.submit();
}

function ValidateClassSubmission( x ) {
	if( x.Title.value == '' ) {
		alert( 'Please enter a Title for your class.' );
		x.Title.focus();
		return false;
	} else if( x.Category.value == '0' ) {
		alert( 'Please choose a Category for your class.' );
		x.Category.focus();
		return false;
	} else if( x.Description.value == '' ) {
		alert( 'Please enter a Description for your class.' );
		x.Description.focus();
		return false;
	} else if( x.Type[0].checked && x.YouTube.value == '' ) {
		alert( 'Please enter a YouTube Link for your class.' );
		x.YouTube.focus();
		return false;
	} else if(x.theImage.value == '' ) {
		alert( 'Please choose a Photo to upload for your class.' );
		x.theImage.focus();
		return false;
	} else if( x.theDocument.value == '' ) {
		alert( 'Please upload a PDF or Word document with instructions on completing your class.' );
		x.theDocument.focus();
		return false;
	} else {
		return true;
	}	
}

function ValidateProjectSubmission( x ) {
	if( x.Class.value == '' ) {
		alert( 'Please choose which class project you just completed.' );
		x.Class.focus();
		return false;
	} else if(x.theImage.value == '' ) {
		alert( 'Please choose a Photo to upload of your completed project.' );
		x.theImage.focus();
		return false;
	} else {
		return true;
	}	
}

