function clearText(thefield)
{
    if(thefield.defaultValue==thefield.value)
        thefield.value = "";
} 

function replaceText(thefield)
{
    if (thefield.value=="")
        thefield.value = thefield.defaultValue;
}

function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function ValidateEmail(valor)
{
	if (/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,60}\.[a-zA-Z]{2,4}$/.test(valor))
		return true;
	else
		return false;
}

function HasNumbers(valor) 
{
    if (/[0-9]/.test(valor))
        return true;
    else
        return false;
}

function ValidatePhone(incoming)
{
	var ValidChars = "0123456789.()- ";
	var IsCorrect=true;
	var Char;

	for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	{ 
		Char = incoming.charAt(cont); 
		if (ValidChars.indexOf(Char) == -1) 
			return false;
	}
	return true;
}

function ValidateDataSmall(FirstName, LastName, Email, Comment, contactDate)
{	
	if (contactDate.value != "")
	{
		return false;
	}
	
	if ((trim(FirstName.value) == "") || (FirstName.value == FirstName.defaultValue))
	{
		alert('Please, enter your first name.');
		FirstName.focus();
		return false;
	}
	else
	{
		if(HasNumbers(FirstName.value))
		{
			alert('First name contains numbers, please remove them.');
			FirstName.focus();
			return (false);
		}
	}
	
	if ((trim(LastName.value) == "") || (LastName.value == LastName.defaultValue))
	{
		alert('Please, enter your last name.');
		LastName.focus();
		return false;
	}
	else
	{
		if(HasNumbers(LastName.value))
		{
			alert('Last name contains numbers, please remove them.');
			LastName.focus();
			return (false);
		}
	}	
	
	if ((trim(Email.value) == "") || (Email.value == Email.defaultValue))
	{
		alert('Please, enter your email.');
		Email.focus();
		return false;
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please, check your email.");
			Email.focus();
			return false;
		}
	}

	if ((trim(Comment.value) == "") || (Comment.value == Comment.defaultValue))
	{
		alert('Please, enter your comments.');
		Comment.focus();
		return false;
	}
	
	return true;
}

function getElementSmall(name)
{
	var object = null;
	var tbSmallContact = document.getElementById('tbSmallContact');
	for (var i=0; i<tbSmallContact.rows.length; i++)
    {
        for (var j=0; j<tbSmallContact.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbSmallContact.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbSmallContact.rows[i].cells[j].childNodes[k].id == name)
                {
                    object = tbSmallContact.rows[i].cells[j].childNodes[k];
                    return object;
                }
            }
        }
        
    }    
}

function OnSubmitSmall()
{		
	var txtFirstName = getElementSmall('txtFirstName');
	var txtLastName = getElementSmall('txtLastName');
	var txtEmail = getElementSmall('txtEmail');	
	var txtComments = getElementSmall('txtComments');	
	var contactDate = getElementSmall('contactDate');	
	var hdnContactFormID = getElementSmall('hdnContactFormID');
	var hdnContactFormType = getElementSmall('hdnContactFormType');

	if (ValidateDataSmall(txtFirstName, txtLastName, txtEmail, txtComments, contactDate) == true)
		window.location.href = "/savesmallcontact.aspx?txtFirstName=" + txtFirstName.value +
		"&txtLastName=" + txtLastName.value +
		"&txtEmail=" + txtEmail.value +
		"&txtComments=" + txtComments.value +
		"&hdnContactFormID=" + hdnContactFormID.value +
		"&hdnContactFormType=" + hdnContactFormType.value;
}
