function clearText(thefield)
{
  if (thefield.defaultValue == thefield.value)
    thefield.value = ""
} 

function replaceText(thefield)
{
  if (thefield.value == "")
    thefield.value = thefield.defaultValue
}

function ValidateEmail(valor) 
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	    return true;
    else
	    return false;
}

function trim(myString)
{
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

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, Phone, Email, contactDate)
{

    FirstName.value=trim(FirstName.value);
    LastName.value=trim(LastName.value);
    Phone.value=trim(Phone.value); 
    Email.value=trim(Email.value);
    
	if (contactDate.value != "")		
		return false;
	
	if ((FirstName.value == "") || (FirstName.value == FirstName.defaultValue))
	{
		alert('Please, enter your first name.');
		FirstName.focus();
		return false;
	}
	else
	{
		if(HasNumbers(FirstName.value))
		{
			alert('Your name contains numbers, please remove them.');
			FirstName.focus();
			return (false);
		}
	}
	
	if ((LastName.value == "") || (LastName.value == LastName.defaultValue))
	{
		alert('Please, enter your last name.');
		LastName.focus();
		return false;
	}
	else
	{
		if(HasNumbers(LastName.value))
		{
			alert('Your name contains numbers, please remove them.');
			LastName.focus();
			return (false);
		}
	}
	
    if ((Phone.value == "")  || (Phone.value == Phone.defaultValue))
    {
        alert('Please, enter your phone.');
        Phone.focus();
        return (false);
    }
    else
    {
        if(!ValidatePhone(Phone.value))
        {
            alert("Please check your phone.");
            Phone.focus();
            return false;
        }
    }
	
	if ((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;
		}
	}		
	
	return true;
}

function OnSubmit()
{
    var FirstName = document.getElementById('txtFirstName');
    var LastName = document.getElementById('txtLastName');
	var Email = document.getElementById('txtEmail');
	var Phone = document.getElementById('txtPhone');
	var Comment = document.getElementById('txtComments');
	var contactDate = document.getElementById('contactDate');
	var hdnContactFormID=document.getElementById('hdnContactFormID');
	var hdnContactFormType=document.getElementById('hdnContactFormType');
	
	if (ValidateDataSmall(FirstName, LastName, Phone, Email, contactDate) == true)
		window.location.href = "savesmallform.aspx?txtFirstName=" + FirstName.value + "&txtLastName=" + LastName.value + "&txtEmail=" + Email.value + "&txtPhone=" + Phone.value + "&txtComments=" + Comment.value + "&hdnContactFormID=" + hdnContactFormID.value + "&hdnContactFormType=" + hdnContactFormType.value;
}

function getElement(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 HasNumbers(valor) 
{
	if (/[0-9]/.test(valor))
			return true;
	else
			return false;
}
