// Miniball 2 Javascript

// vars
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

function advertise () {
	var path = document.advertiseForm;
	mandatoryfields = new Array (path.fName, path.lName, path.cName, path.cUrl, path.email);
	for (i=0; i<=mandatoryfields.length-1; i++) {
		if (mandatoryfields[i].value == "") 	{
			alert("You must fill out all fields marked with a ' * '   ");
			return;
		}
	}
	validEmail(document.advertiseForm);
}

function ConvertToAscii(str)
{
var str		= str.toLowerCase();
var convert	= "";

for (var i=0; i<str.length; i++)
{
convert		+= str.charCodeAt(i);
}

return convert;
}

function TrimString(str)
{
str 		= this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function IsEmpty(TmpString)
{

if (!TmpString)
{
return true;	
}

TmpString	= TrimString(TmpString);

if (TmpString.length <= 0)
{
return true;
}

return false;
}

function contactUs ()
{
var path = document.contact;

if (path.name.value=="")
{
alert('You must fill out the name field');
return;
}

else if ((path.SecurityImage) && (IsEmpty(path.SecurityImage.value)))
{
alert("Please enter the security code");
return;
}

else if ((path.SecurityImage) && (!IsEmpty(path.SecurityImage.value)))
{
TmpSecurityCode	= ConvertToAscii(path.SecurityImage.value);

if (TmpSecurityCode != path.SockVar.value)
{
alert("The security code does not match");
return;
}

}

validEmail (path);

}

function validEmail (form) {
	valid = handleEmailValidation(form.email.value);
	if (form.email2) {
		valid = handleEmailValidation(form.email2.value);
	}
	if (valid) {
		form.submit();
	}
}

function handleEmailValidation (email) {
	if (email == "") {
		alert('Please fill out all fields   ');
		return false
	} else if (filter.test(email)) {
		return true;
	} else { 
		alert ("'" + email + "' is not a valid email address    ");
		return false
	}
}	
