function o_validate_r(field,req)
{
	with (field)
	{
		if ((value == null || value == "") && req)
		{
			alert('a field must be filled out');
			return false;
		}
		else if (/<|>/.test(value))
		{
			alert('a field contains illegal characters');
			return false;
		}
			return true;
	}
}

function o_validate_e(field)
{
	with (field)
	{
		var emailFilter = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

		if (!(emailFilter.test(value)) && value != '')
		{
			alert('not a valid e-mail address');
			return false;
		}
		else 
			return true;
	}
}

function o_validate_h(field)
{
	with (field)
	{
		var homepageFiler = /^http:\/\/+([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

		if (!homepageFiler.test(value) && value != '' && value != 'http://')
		{
			alert('not a valid homepage. did you forget http://?');
			return false;
		}
		else 
			return true;
	}
}

function o_validate(thisform)
{
	with (thisform)
	{
		if (!o_validate_r(name,true))
  		{
			name.focus();
			return false;
		}
		if (!o_validate_r(place,false))
  		{
			place.focus();
			return false;
		}
		if (!o_validate_e(email))
		{
			email.focus();
			return false;
		}
		if (!o_validate_h(homepage))
		{
			homepage.focus();
			return false;
		}
		if (!o_validate_r(reaction,true))
  		{
			reaction.focus();
			return false;
		}
		
		return true;
	}
}

function o_show(loc)
{
	document.getElementById('shoutbox').innerHTML = '<br /><div style="text-align: center"><img class="icon" src="images/common/edit.png" alt="" /> <span class="myLink" onclick="o_write(\'' + loc + '\')">write an opinion</span></div><div id="shoutbox-area"></div><iframe src="" name="shoutframe" width="0" height="0" frameborder="0">noframes</iframe></div>';
	include('shoutbox-area','src/opinions.php?r_to=' + loc);
}

function o_write(loc)
{
	document.getElementById('b_popup').innerHTML = '<div class="box o_box"><form id="shoutform" method="post" action="src/opinions.php" target="shoutframe"><input type="hidden" name="r_ax" value="insert"><input type="hidden" name="r_to" value="' + loc + '"><input type="text" name="name" style="width: 150px" maxlength="128"> <img class="icon" src="images/common/user.png" alt="" /> name*<br /><input type="text" name="place" style="width: 150px" maxlength="128"> <img class="icon" src="images/common/loc.png" alt="" /> your location<br /><input type="text" name="email" style="width: 150px" maxlength="128"> <img class="icon" src="images/common/mail.png" alt="" /> email<br /><input type="text" name="homepage" value="http://" style="width: 150px" maxlength="128"> <img class="icon" src="images/common/home.png" alt="" /> homepage<br /><textarea name="reaction" style="width: 340px" rows="4" wrap="VIRTUAL"></textarea> <img class="icon" src="images/common/comment.png" alt="" /> opinion*<br /><br /> *required</form><br /><div class="hr"></div><div style="text-align: right">( <span class="myLink" onclick="b_close()">cancel</span> | <span class="myLink" onclick="o_insert(\'' + loc + '\')">send</span> )</div>';
	document.getElementById('b_popup').style.display = '';
}

function o_insert(loc)
{
	if (o_validate(document.getElementById('shoutform')))
	{
		document.getElementById('shoutform').submit();		
		setTimeout('o_show(\'' + loc + '\')', 1500);
		b_close();
	}
}