String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
var firstTime = true;
function validate()
{
	alertstr = "";
	warning_class = "warning";
	
	
	if($('firstname').value.trim() == "")
	{
		alertstr += " - First Name\n"; $('firstname').value = ""; $('firstname_star').innerHTML = "&nbsp;*";
	}else{ $('firstname_star').innerHTML = ""}
	if($('lastname').value.trim() == "")
	{
		alertstr += " - Last Name\n"; $('lastname').value = ""; $('lastname_star').innerHTML = "&nbsp;*";
	}else{ $('lastname_star').innerHTML = ""}
	if($('email').value.trim() == "")
	{
		alertstr += " - Email\n"; $('email').value = ""; $('email_star').innerHTML = "&nbsp;*";
	}else{ $('email_star').innerHTML = "";}
	if($('company').value.trim() == "")
	{
		alertstr += " - Company\n"; $('company').value = ""; $('company_star').innerHTML = "&nbsp;*";
	}else{ $('company_star').innerHTML = "";}
	if($('country').value == '0')
	{
		alertstr += " - Country\n"; $('country').selectedindex = "0"; $('country_star').innerHTML = "&nbsp;*";
	}else{ $('country_star').innerHTML = "";}
	if($('phone').value.trim() == "")
	{
		alertstr += " - Phone\n"; $('phone').value = ""; $('phone_star').innerHTML = "&nbsp;*";
	}else{ $('phone_star').innerHTML = "";}
	if($('how').value == '0')
	{
		alertstr += " - How did you hear about us?\n"; $('how').selectedindex = "0"; $('how_star').innerHTML = "&nbsp;*";
	}else{ $('how_star').innerHTML = "";}
	if(alertstr != "")
	{
		alert("Please, enter:\n" + alertstr); return;
	}
	
	has_product = 0;
	for(i = 0; i < $('enquiry').elements['products[]'].length; i++)
	{
		if($('enquiry').elements['products[]'][i].checked.toString() == 'true')
			has_product = 1;
	}
	if(has_product == 0)
	{	
		alert("Please, select products!");	
		return;
	}
	has_market = 0;
	for(i = 0; i < $('enquiry').elements['markets[]'].length; i++)
	{

		if($('enquiry').elements['markets[]'][i].checked.toString() == 'true')
			has_market = 1;
	}
	if(has_market == 0)
	{	
		alert("Please, select markets!");	
		return;
	}
	
	if(firstTime)
	{
		$('antispam_div').style.display = 'block';
		firstTime = false;
		return;
	}
	
	function showResponse(request){
		if($('antispam').value == request)
			$('enquiry').submit();
		else
			alert('Please enter the characters you see in the picture into the box below.');
	}

	new Ajax('antispam_check.php',{postBody:'antispam=1234', onComplete: showResponse}).request();
	
	
}

function refresh_image()
{
	var img = new Image();
	img.src = 'antispam.php?rand=' + Math.random();
	img.onload = function () { $('antispam_image').src = this.src; }
}