// JavaScript Document

	var SEND_TEMP_STR = '';

function show_div(div_ic, yn_show)
{
	if (yn_show)
		document.getElementById(div_ic).style.visibility = 'visible';
	else
		document.getElementById(div_ic).style.visibility = 'hidden';
}

function form_validate()
{
	var validOK = true;

	if (document.form_send_link.my_name.value.length==0) {
		error_out('my_name',true);
		validOK = false;
	}  else error_out('my_name',false);

	if (document.form_send_link.message.value.length==0) {
		error_out('message',true);
		validOK = false;
	}  else error_out('message',false);
	
	if (document.form_send_link.my_eml.value.length==0) {
		error_out('my_eml',true);
		validOK = false;
	}
	else if (!valid_email(document.form_send_link.my_eml.value)) {
		error_out('my_eml',true);
		validOK = false;
	}  else error_out('my_eml',false);

	if (document.form_send_link.recipient_eml.value.length==0) {
		error_out('recipient_eml',true);
		validOK = false;
	}
	else if (!valid_email(document.form_send_link.recipient_eml.value)) {
		error_out('recipient_eml',true);
		validOK = false;
	}  else error_out('recipient_eml',false);

	if (validOK) {
		SEND_TEMP_STR = document.getElementById("send_form_loading").innerHTML;	//save div html
		document.getElementById("send_form_loading").innerHTML = '<img src="images/ajax-loader.gif" width="32" height="32">';
		fw_postFormReturnText(document.form_send_link, callback_form_link);
	}
	
}
function error_out(itemName,highLight)
{
	if (highLight) bg = '#fdd'; else bg = '#fff';
	document.getElementById(itemName).style.background = bg;
}

function callback_form_link(messagex)
{
	if (messagex == 'ok') {
		document.getElementById("send_form_loading").innerHTML = '<b>MESSAGE SENT</b>';
	} else {
		document.getElementById("send_form_loading").innerHTML = messagex;
		setTimeout("restore_send_area2()",6000);
	}		
}
function restore_send_area2()
{
	document.getElementById("send_form_loading").innerHTML = SEND_TEMP_STR;
}


	function valid_email(str) 
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
	
		var tested = true;
		
		if (str.indexOf(at)==-1)
		   tested = false;
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		   tested = false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		   tested = false;
		 if (str.indexOf(at,(lat+1))!=-1)
		   tested = false;
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		   tested = false;
		 if (str.indexOf(dot,(lat+2))==-1)
		   tested = false;
		 if (str.indexOf(" ")!=-1)
		   tested = false;
	
		if ( !tested )
			return false;
		else
			return true;
	
	}
