/*
This contains a set of functions that help protect email addresses
from spam-bots. Instead of using the email address directly, the 
encoded value is stored in the html and decoded when required.

Ralph Arvesen
Vertigo Software
*/

// open the client email with the specified address
function sendEmail(encodedEmail)
{
	// do the mailto: link
	location.href = "mailto:" + decodeEmail(encodedEmail);
}

// display the email address in the statusbar
function displayStatus(encodedEmail)
{
	window.status = "mailto:" + decodeEmail(encodedEmail);
}

// clear the statusbar message
function clearStatus()
{
	window.status = "";
}

// clear the statusbar message
function writeStatus(text)
{
	window.status = text;
}

// return the decoded email address
function decodeEmail(encodedEmail)
{
	// The encodedEmail is a string that contains the email address.
	// Each character in the email address has been converted into 
	// a two digit number (hex / base16). This function converts the
	// series of numbers back into the real email address.

	// holds the decoded email address
	var email = "";

	// go through and decode the email address
	for (i=0; i < encodedEmail.length;)
	{
		// holds each letter (2 digits)
		var letter = "";
		letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)

		// build the real email address
		email += String.fromCharCode(parseInt(letter,16));
		i += 2;
	}
		
	return email;
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function emailcheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
