//***********************************
//  validateForm()
//  - Performs client-side validations against 
//    tell a friend form 
//***********************************
function validateForm(form)
{
    //Check that required sender first name was entered
    if(!checkName(document.getElementById("senderFirstName").value,1))
    {
        document.getElementById("senderFirstName").focus();
        document.getElementById("senderFirstName").select();
        return false;
    }
    
    //Check that required sender last name was entered
    if(!checkName(document.getElementById("senderLastName").value,2))
    {
        document.getElementById("senderLastName").focus();
        document.getElementById("senderLastName").select();
        return false;
    }
    
    //TODO: Check sender email address
    
        
    
        //Check that recipient first name was entered
    if(!checkName(document.getElementById("friendFirstName").value,3))
    {
        document.getElementById("friendFirstName").focus();
        document.getElementById("friendFirstName").select();
        return false;
    }
    
    //Check that recipient last name was entered
    if(!checkName(document.getElementById("friendLastName").value,4))
    {
        document.getElementById("friendLastName").focus();
        document.getElementById("friendLastName").select();
        return false;
    }

    //TODO: Check recipient email address

    //TODO: Check that CAPTCHA value was passed
}


function checkName(name, nameType) 
{
    var value = trim(name);
    
    if ( !check_len(value,0) )
    {
    	if ( nameType == 1 ) {
    		alert("Please enter a value for your first name.");
    	}
    	else if ( nameType == 2 ) {
    		alert("Please enter a value for your last name.");
    	}
    	else if ( nameType == 3 ) {
    		alert("Please enter a value for the recipient's first name.");
    	}
    	else {
    		alert("Please enter a value for the recipient's last name.");
    	}
    	
    	return false;
    }
    	
    //check there are no invalid characters
    if (!string_charset_check(value,CS_NAME, ""))
    {
    	if ( nameType == 1 ) {
    		alert("Your first name includes invalid character(s)");
    	}
    	else if ( nameType == 2 ) {
    		alert("Your last name includes invalid character(s)");
    	}
    	else if (nameType == 3 ) {
    	    alert("The recipient's first name invalid character(s).");
    	}
    	else {
    	    alert("The recipient's last name includes invalid character(s).");
    	}    	
    	return false;
    }
    
    return true;
}	