//--------------------------------------------------------------------------------------------------------
//
// Hide email from web spiders
//
//--------------------------------------------------------------------------------------------------------
function writeEmail()
{
	var lhs1 = "sales";
	var rhs1 = "idealsystems.cc";	
   	document.write("<A HREF=\"mailto");
   	document.write(":" + lhs1 + "@");
   	document.write(rhs1);
   	document.write("\">" + lhs1 + "@" + rhs1 + "<\/a>");
}

//--------------------------------------------------------------------------------------------------------
//
// Called from login page
//
//--------------------------------------------------------------------------------------------------------
function validate( form )
{
    var email, regEx;
	email = trim( form.email.value );
	
    if ( trim( form.first.value ) == "" )
	{
	   alert( "Please enter your first name." );
	   return false;
	}

    if ( email == "" )
	{
	   alert( "Please enter your email." );
	   return false;
	}
	
    if ( form.message.value.length > 1000 )
    {
	   alert( "Please limit your message to 1000 characters." );
	   return false;
    }
	
	//Make sure that the email field contains a '@' and a '.'
    regEx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if ( ! regEx.test( email ) )
	{
		alert( "Please enter a valid email. ( ex: yourname@provider.com )" );	
		return false;	
	}	
		
	return true;
}

//--------------------------------------------------------------------------------------------------------
//
// trim spaces from a string. Calls Ltrim and Rtrim.
//
//--------------------------------------------------------------------------------------------------------
function trim( str )
{
	return Rtrim( Ltrim( str ) );
}

//--------------------------------------------------------------------------------------------------------
//
// Left trim a string: 1. We have a string with leading blank( s )... 2. Iterate from the far left of 
// string until we don't have any more whitespace... 3. Get the substring from the first non-whitespace
// character to the end of the string...
//
//--------------------------------------------------------------------------------------------------------
function Ltrim( str )
{
	var whitespace = new String( " \t\n\r" );
	var s = new String( str );

	if ( whitespace.indexOf( s.charAt( 0 ) ) != -1 ) {
 	   	var j=0, i = s.length;
 	   	while ( j < i && whitespace.indexOf( s.charAt( j ) ) != -1 )
			j++;

            s = s.substring( j, i );
        }
	return s;
}

//--------------------------------------------------------------------------------------------------------
//
// Right trim a string: 1. We don't want to trip JUST spaces, but also tabs, line feeds, etc.  Add 
// anything else you want to "trim" here in Whitespace
//
//--------------------------------------------------------------------------------------------------------
function Rtrim( str )
{
	var whitespace = new String( " \t\n\r" );
    var s = new String( str );

	if ( whitespace.indexOf( s.charAt( s.length-1 ) ) != -1 ) {
    var i = s.length - 1;       // Get length of string

    while ( i >= 0 && whitespace.indexOf( s.charAt( i ) ) != -1 )
		i--;
        s = s.substring( 0, i+1 );
    }
    return s;
}