form_validate = function()
{
valid = true;
var oForm = document.forms["content_form"];
var business_name = oForm.business_name.value;
var address_line_1 = oForm.address_line_1.value;
var address_line_2 = oForm.address_line_2.value;
var town = oForm.town.value;
var telephone = oForm.telephone.value;
var mobile = oForm.mobile.value;
var email_listing = oForm.email_listing.value;
var description = oForm.description.value;
var chks = document.getElementsByName('languages[]');
var tlcs = oForm.tlcs.value;
var subcategories = oForm.subcategories.value;
var user_file = oForm.user_file.value;
var name = oForm.name.value;
var username = oForm.username.value;
var password = oForm.password.value;
var confirm_password = oForm.confirm_password.value;
var id = oForm.id.value;
var email_user = oForm.email_user.value;
var alertMsg = "
Errors were found, please correct them and try again
\n";
var l_Msg = alertMsg.length;
if (business_name == '')
{
alertMsg += "- Please enter a business name
\n";
valid = false;
}
if(business_name.length > 36)
{
alertMsg += "- Business name must be 36 characters or less
";
valid = false;
}
if (email_listing != '')
{
var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
var email_test = re.test(email_listing)
if (email_test != true)
{
alertMsg += "- Please enter a valid LISTING e-mail address
\n";
valid = false;
}
}
if ( ((address_line_1 == '') && (address_line_2 == '')) && (telephone == '') && (mobile == '') && (email_listing == ''))
{
alertMsg += "- Please enter either a physical address, telephone Nº, mobile Nº or an e-mail address
\n";
valid = false;
}
if((telephone != '') && (mobile != ''))
{
if(telephone == mobile)
{
alertMsg += "- Please do not enter the same telephone/mobile number twice
\n";
valid = false;
}
}
if ( ((address_line_1 != '') || (address_line_2 != '')) && (town == '') )
{
alertMsg += "- Please enter a town or city when entering an address
\n";
valid = false;
}
if (description == '')
{
alertMsg += "- Description is a required field
\n";
valid = false;
}
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (!hasChecked)
{
alertMsg += "- Please select at least one language
\n";
valid = false;
}
if (tlcs == '')
{
alertMsg += "- Please select a category
\n";
valid = false;
}
if (subcategories == '')
{
alertMsg += "- Please select a sub category
\n";
valid = false;
}
if(user_file != '')
{
var re = /\.(gif|jpg|jpeg)$/i
var user_file_test = re.test(user_file)
if(user_file_test != true)
{
alertMsg += "- Only JPG, JPEG and GIF files may be uploaded
\n";
valid = false;
}
}
if (name == '')
{
alertMsg += "- Your name is a required field
\n";
valid = false;
}
if (username == '')
{
alertMsg += "- Username is a required field
\n";
valid = false;
}
if (username != '')
{
if(username.length < 6)
{
alertMsg += "- Username must be 6 characters or more
";
valid = false;
}
if(username.length > 20)
{
alertMsg += "- Username must be 20 characters or less
";
valid = false;
}
/*var re = /^([a-zA-Z0-9_-]+)$/
var username_test = re.test(username)
if(username_test != true)
{
alertMsg += "- Username must be alphanumeric (a-z, A-Z or _)
\n";
valid = false;
}*/
}
if (id == '') /* then this is a new listing */
{
if(password == '')
{
alertMsg += "- Password is a required field
";
valid = false;
}
if(password != '')
{
if(password.length < 6)
{
alertMsg += "- Password must be 6 characters or more
";
valid = false;
}
if(password.length > 20)
{
alertMsg += "- Password must be 20 characters or less
";
valid = false;
}
if(confirm_password == '')
{
alertMsg += "- Confirmation password is a required field
";
valid = false;
}
if(confirm_password != '')
{
if(confirm_password != password)
{
alertMsg += "- Your confirmation password does not match
";
valid = false;
}
}
}
}
if ((id != '') && (password != '')) /* then this is an update listing who wants to update their password*/
{
if(password.length < 6)
{
alertMsg += "- Password must be 6 characters or more
";
valid = false;
}
if(password.length > 20)
{
alertMsg += "- Password must be 20 characters or less
";
valid = false;
}
if(confirm_password == '')
{
alertMsg += "- Confirmation password is a required field
";
valid = false;
}
if(confirm_password != '')
{
if(confirm_password != password)
{
alertMsg += "- Your confirmation password does not match
";
valid = false;
}
}
}
if (email_user == '')
{
alertMsg += "- Please enter an ACCOUNT e-mail address
\n";
valid = false;
}
if (email_user != '')
{
var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
var email_test = re.test(email_user)
if (email_test != true)
{
alertMsg += "- Please enter a valid ACCOUNT e-mail address
\n";
valid = false;
}
}
if(typeof oForm.tos != 'undefined')
{
var tos = oForm.tos.checked;
if (!tos)
{
alertMsg += "- Your must agree to our terms of service to add a listing
\n";
valid = false;
}
}
if (id == '') /* then this is a new listing */
{
if(typeof oForm.image_code != 'undefined')
{
var image_code = oForm.image_code.value;
if (image_code == '')
{
alertMsg += "- Please enter the access code shown above the submit button
\n";
valid = false;
}
}
}
if (alertMsg.length == l_Msg)
{
submitonce(oForm);
if(user_file != '')
{
showProgressWindow('image_show_progress.php',300,75);
}
return true;
}
else
{
document.getElementById('stop').style.display = "none";
document.getElementById('errors').style.padding = "1em";
document.getElementById('errors').innerHTML = alertMsg + "
"
/*alert(alertMsg);*/
window.scrollTo(0,0);
return false;
}
return valid;
}
// Confirm delete required
function confirm_delete(val)
{
if (val == 'delete')
{
if(window.confirm("Are you sure you want to FULLY DELETE this listing?") != true)
{
document.getElementById('delete_listing').selectedIndex = 0;
}
else
{
alert('Click the Submit button to FULLY DELETE this property');
}
}
}