var the_code = "";
var email_syntax = "oops";
function scramble(){
the_code = "";

var email_address = document.the_email.your_email.value;
check_email(email_address);
if(email_syntax == "oops"){alert("Please Enter A Valid Email Address");return false;}
var link_text = document.the_email.your_text.value;
if(link_text == ""){alert("Please Provide Link Text");return false;}


var mail_subject = document.the_email.your_subject.value;
var mail_body = document.the_email.your_body.value;
var no_script = document.the_email.noscript.value;

var re= /\@/gi; //replace @
email_address = email_address.replace(re,'_at_');

var re= /\./gi; //replace .
email_address = email_address.replace(re,'_dot_');

if(mail_body.length >= 255){alert('Sorry Body text is more than 255 characters');return false;} 
if(mail_subject.length >= 64){alert('Sorry Subject text is more than 64 characters');return false;}

mail_subject = escape(mail_subject);
mail_body = escape(mail_body);

var edress = email_address;

the_code += '<script language="JavaScript" type="text/javascript">\n'; 
the_code += "<!-- \n";
the_code += "var edress = '" +email_address+"';\n"; 
the_code += 'function get_edress(){\n';
//the_code += 
//the_code += 

the_code += 'var re= /_at_/gi;\n';
the_code += "edress = edress.replace(re,'@');\n";
the_code += 'var re= /_dot_/gi;\n';
the_code += "edress = edress.replace(re,'.');\n";

the_code += 'var the_link="mai" + "lto" +":"+edress+"' +'?subject='+ mail_subject +'&body='+ mail_body +'" ;\n';
the_code += 'window.location=the_link;\n';
the_code += '\n}\n';

the_code += "\n// --> \n<\/script>\n";
the_code += "\n<!-- http://webgear.datacreek.net/ -->\n\n\n";

the_code += "<!-- make the link using this -->\n";
the_code += "<!-- xxx cut xxx -->\n";
the_code += '<script language="JavaScript" type="text/javascript">\n'; 
the_code += "<!-- \n";
the_code += 'document.write("<a href=\'#\' onClick=\'get_edress();return false;\'>'+ link_text +'</a>");\n';
the_code += "// --> \n<\/script>\n";
the_code += "<noscript>"+ no_script +"<\/noscript>\n";
the_code += "<!-- xxx end cut xxx -->\n";







document.the_email.new_email.value = the_code;

}


function scramble_preview() {
if(the_code == ""){alert("Nothing to preview");return false}
	msg=open("","","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=444,height=200");
msg.document.write('<html><head><title>test page</title><style type=text/css>body,TD{font : 8pt verdana, sans-serif;}</style></head><body bgcolor=white><b>This is how your email link will appear in a browser.</b><table bgcolor="#fffff5" border="1" width="95%" align="center"><tr><td>'+the_code+'<br><br>click on the link to test it</td></tr></table><div align="right"><A href="javascript:window.close()">Close Window</A></div>');
msg.document.write('</body></html>');
return false;
}



//#################################################################	
//email address
function check_email(theaddress){

		var re=/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
		if (theaddress.match(re)) {
		email_syntax = "ok";
		}
		else
		{
		email_syntax = "oops";
		}

}
//END email address
//#################################################################



