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+([-.]\w+)*/.test(valor))
	    return true;
    else
	    return false;
}
function trim(myString)
{
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}


function ValidateDataSmall(Name, Email, Comment, contactDate)
{

	Name.value=trim(Name.value);
	Email.value=trim(Email.value);
	Comment.value=trim(Comment.value);    
	if (contactDate.value != "")		
		return false;
	
	if ((Name.value == "") || (Name.value == Name.defaultValue))
	{
		alert('Please, enter your name.');
		Name.focus();
		return false;
	}
	else
	{
		if(HasNumbers(Name.value))
		{
			alert('Your name contains numbers, please remove them.');
			FName.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;
		}
	}
		
	if ((Comment.value == "") || (Comment.value ==Comment.defaultValue ))
	{
		alert('Please, enter your comment.');
		Comment.focus();
		return false;
	}
	
	return true;
}

function OnSubmit()
{
    var Name = getElement('txtFullName');
	var Email = getElement('txtEmail');
	var Comment = getElement('txtComments');	
	var contactDate = getElement('contactDate');
	var hdnContactFormID=getElement('hdnContactFormID');
	var hdnContactFormType=getElement('hdnContactFormType');
	
	if (ValidateDataSmall(Name, Email, Comment, contactDate) == true)
		window.location.href = "savesmallform.aspx?txtFullName=" + Name.value + "&txtEmail=" + Email.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;
}