var ajaxv = false;

function ajaxvalidate(t) {

$.ajax( 
{
async: false,
cache: false,
type: 'POST',
dataType: 'text',
url: 'captcha/validate.php',
data: {v: t},
success: function(data) {
if(data.length == 1) {
v = parseInt(data);
ajaxv = v == 1 ? true : false;
return ajaxv;
}
else
return false;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
return false;
}
}

);
}

function validSignup(frm) { 
	var message = "";

	// INQUIRY FORM

	if (frm.Action.value == 'inquiry' ) {

		if (frm.FirstName.value.trim().length == 0) { 
			message += "First Name is required\n";
		}
		if (frm.LastName.value.trim().length == 0) { 
			message += "Last Name is required\n";
		}
		if (frm.Phone.value.trim().length == 0) { 
			message += "Phone Number is required\n";
		}
		if (frm.Email.value.trim().length == 0) { 
			message += "Email is required\n";
		}
		else if(!emailCheck(frm.Email, false))    
		  message += 'Please enter valid e-mail address\n';
	}
	
	if (frm.Action.value == 'signup' ) {

		if (frm.YourInformationFirstName.value.trim().length == 0) { 
			message += "First Name is required\n";
		}
		if (frm.YourInformationLastName.value.trim().length == 0) { 
			message += "Last Name is required\n";
		}
		if (frm.email.value.trim().length == 0) { 
			message += "Email is required\n";
		}
		else if(!emailCheck(frm.email, false))    
		  message += 'Please enter valid e-mail address\n';
	}
	
	// validation
	if (frm.validate) {
		if (frm.validate.value.length != 6) { 
			message += "Please enter proper security code\n";
		} else {
			ajaxvalidate(frm.validate.value,frm);
			if (!ajaxv) message += "Security code not accepted, please try again\n";
		}
	}

	if (message != "") {
		alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\nPlease complete or correct the form and submit again.");
		return false;
	}    
	else {
		if (frm.Action.value == 'inquiry' ) { frm.action = "assets/send.php?send=inquiry"; }
		if (frm.Action.value == 'signup' ) { frm.action = "http://enews.hospitalityebusiness.com/m/993Kqwk4aETqtRcy6VF9dB0wbPA"; }
		frm.method = "post";
		//frm.submit();
		return true;
	} 
}

