//--------------------------------------------------------------------------------------------------------
//
// Validate the search textbox in the top.html page.
//
//--------------------------------------------------------------------------------------------------------
function validateSearch( form )
{
	if ( trim( form.searchstring.value ) == "" )
	{
		alert( "Please enter a search string." );
		return false;
	}
	return true;
}

function validate( form )
{
	if ( trim( form.Name.value ) == "" )
	{
		alert( "Please enter your name." );
		return false;
	}
	
	if ( trim( form.Email.value ) == "" )
	{
		alert( "Please enter your email." );
		return false;
	}
	
	if ( trim( form.Subject.value ) == "" )
	{
		alert( "Please enter the subject." );
		return false;
	}
	
	if ( trim( form.MessageText.value ) == "" )
	{
		alert( "Please enter your message." );
		return false;
	}	
	return true;	
}

function validate2( form )
{
	if ( trim( form.Name.value ) == "" )
	{
		alert( "Please enter your name." );
		return false;
	}
	
	if ( trim( form.Email.value ) == "" )
	{
		alert( "Please enter your email." );
		return false;
	}
	
	if ( trim( form.MessageText.value ) == "" )
	{
		alert( "Please enter your message." );
		return false;
	}	
	return true;	
}

//--------------------------------------------------------------------------------------------------------
//
// Add gift cert to cart.
//
//--------------------------------------------------------------------------------------------------------
function addGiftCert( )
{
	alert( "When checking out your order, be sure to state who the certificate is from, who it is for & where to be mailed! Use the Notes box at the bottom of the checkout page!");
	document.location = "cart/viewcart.asp?add=1&partno=" + document.giftcerts.giftcert.value;
}

//--------------------------------------------------------------------------------------------------------
//
// 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;
}